1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "qemu/osdep.h"
20#include "libqtest.h"
21#include "libqos/qgraph.h"
22#include "pci-spapr.h"
23#include "libqos/malloc-spapr.h"
24
25typedef struct QSPAPR_pci_host QSPAPR_pci_host;
26typedef struct Qppc64_pseriesMachine Qppc64_pseriesMachine;
27
28struct QSPAPR_pci_host {
29 QOSGraphObject obj;
30 QPCIBusSPAPR pci;
31};
32
33struct Qppc64_pseriesMachine {
34 QOSGraphObject obj;
35 QGuestAllocator alloc;
36 QSPAPR_pci_host bridge;
37};
38
39
40
41static QOSGraphObject *QSPAPR_host_get_device(void *obj, const char *device)
42{
43 QSPAPR_pci_host *host = obj;
44 if (!g_strcmp0(device, "pci-bus-spapr")) {
45 return &host->pci.obj;
46 }
47 fprintf(stderr, "%s not present in QSPAPR_pci_host\n", device);
48 g_assert_not_reached();
49}
50
51static void qos_create_QSPAPR_host(QSPAPR_pci_host *host,
52 QTestState *qts,
53 QGuestAllocator *alloc)
54{
55 host->obj.get_device = QSPAPR_host_get_device;
56 qpci_init_spapr(&host->pci, qts, alloc);
57}
58
59
60
61static void spapr_destructor(QOSGraphObject *obj)
62{
63 Qppc64_pseriesMachine *machine = (Qppc64_pseriesMachine *) obj;
64 alloc_destroy(&machine->alloc);
65}
66
67static void *spapr_get_driver(void *object, const char *interface)
68{
69 Qppc64_pseriesMachine *machine = object;
70 if (!g_strcmp0(interface, "memory")) {
71 return &machine->alloc;
72 }
73
74 fprintf(stderr, "%s not present in ppc64/pseries\n", interface);
75 g_assert_not_reached();
76}
77
78static QOSGraphObject *spapr_get_device(void *obj, const char *device)
79{
80 Qppc64_pseriesMachine *machine = obj;
81 if (!g_strcmp0(device, "spapr-pci-host-bridge")) {
82 return &machine->bridge.obj;
83 }
84
85 fprintf(stderr, "%s not present in ppc64/pseries\n", device);
86 g_assert_not_reached();
87}
88
89static void *qos_create_machine_spapr(QTestState *qts)
90{
91 Qppc64_pseriesMachine *machine = g_new0(Qppc64_pseriesMachine, 1);
92 machine->obj.get_device = spapr_get_device;
93 machine->obj.get_driver = spapr_get_driver;
94 machine->obj.destructor = spapr_destructor;
95 spapr_alloc_init(&machine->alloc, qts, ALLOC_NO_FLAGS);
96
97 qos_create_QSPAPR_host(&machine->bridge, qts, &machine->alloc);
98
99 return &machine->obj;
100}
101
102static void spapr_machine_register_nodes(void)
103{
104 qos_node_create_machine("ppc64/pseries", qos_create_machine_spapr);
105 qos_node_create_driver("spapr-pci-host-bridge", NULL);
106 qos_node_contains("ppc64/pseries", "spapr-pci-host-bridge", NULL);
107 qos_node_contains("spapr-pci-host-bridge", "pci-bus-spapr", NULL);
108}
109
110libqos_init(spapr_machine_register_nodes);
111
112