1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <ddk/protocol/platform-defs.h>
6
7#include "qemu-test.h"
8#include "qemu-virt.h"
9
10// This file loads four platform device drivers to test the platform bus support
11// for providing platform bus resources to children of platform devices.
12// The "parent" driver runs as a top level platform device (that is,
13// it is a direct child of the platform bus. It binds the "child-1" driver as a
14// child device, and child-1 creates children for the "child-2" and "child-3" drivers.
15// All four of these drivers use the platform device protocol to map a unique MMIO region.
16// Unfortunately we do not have an automated test for this feature yet,
17// but one can manually inspect the boot log in arm64 qemu to verify that all four of these
18// drivers loaded successfully:
19//
20// [00001.420] 02290.02335> qemu_test_bind: qemu-test-parent
21// [00001.440] 02290.02335> qemu_test_bind: qemu-test-child-1
22// [00001.458] 02290.02335> qemu_test_bind: qemu-test-child-2
23// [00001.465] 02290.02335> qemu_test_bind: qemu-test-child-3
24
25static const pbus_mmio_t parent_mmios[] = {
26    {
27        .base = TEST_MMIO_1,
28        .length = TEST_MMIO_1_SIZE,
29    },
30};
31
32static const pbus_mmio_t child_1_mmios[] = {
33    {
34        .base = TEST_MMIO_2,
35        .length = TEST_MMIO_2_SIZE,
36    },
37};
38
39static const pbus_mmio_t child_2_mmios[] = {
40    {
41        .base = TEST_MMIO_3,
42        .length = TEST_MMIO_3_SIZE,
43    },
44};
45
46static const pbus_mmio_t child_3_mmios[] = {
47    {
48        .base = TEST_MMIO_4,
49        .length = TEST_MMIO_4_SIZE,
50    },
51};
52
53static const pbus_bti_t child_1_btis[] = {
54    {
55        .iommu_index = 0,
56        .bti_id = 0xBEEF,
57    },
58};
59
60static const pbus_dev_t child_1_kids[] = {
61    {
62        // Resources for child-2
63        .mmios = child_2_mmios,
64        .mmio_count = countof(child_2_mmios),
65    },
66    {
67        // Resources for child-3
68        .mmios = child_3_mmios,
69        .mmio_count = countof(child_3_mmios),
70    },
71};
72
73static const pbus_dev_t parent_kids[] = {
74    {
75        // Resources for child-1
76        .mmios = child_1_mmios,
77        .mmio_count = countof(child_1_mmios),
78        .btis = child_1_btis,
79        .bti_count = countof(child_1_btis),
80        .children = child_1_kids,
81        .child_count = countof(child_1_kids),
82    },
83};
84
85const pbus_dev_t test_dev = {
86    .name = "qemu-test-parent",
87    .vid = PDEV_VID_QEMU,
88    .pid = PDEV_PID_QEMU,
89    .did = PDEV_DID_QEMU_TEST_PARENT,
90    .mmios = parent_mmios,
91    .mmio_count = countof(parent_mmios),
92    .children = parent_kids,
93    .child_count = countof(parent_kids),
94};
95
96zx_status_t qemu_test_init(platform_bus_protocol_t* pbus) {
97    return pbus_device_add(pbus, &test_dev);
98}
99