]> git.ipfire.org Git - thirdparty/qemu.git/blame - tests/libqos/ppc64_pseries-machine.c
Include qemu/module.h where needed, drop it from qemu-common.h
[thirdparty/qemu.git] / tests / libqos / ppc64_pseries-machine.c
CommitLineData
7985b582
EGE
1/*
2 * libqos driver framework
3 *
4 * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2 as published by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>
17 */
18
0b8fa32f 19#include "qemu/osdep.h"
7985b582
EGE
20#include "libqtest.h"
21#include "libqos/qgraph.h"
22#include "pci-spapr.h"
0b8fa32f 23#include "qemu/module.h"
7985b582
EGE
24#include "libqos/malloc-spapr.h"
25
26typedef struct QSPAPR_pci_host QSPAPR_pci_host;
27typedef struct Qppc64_pseriesMachine Qppc64_pseriesMachine;
28
29struct QSPAPR_pci_host {
30 QOSGraphObject obj;
31 QPCIBusSPAPR pci;
32};
33
34struct Qppc64_pseriesMachine {
35 QOSGraphObject obj;
36 QGuestAllocator alloc;
37 QSPAPR_pci_host bridge;
38};
39
40/* QSPAPR_pci_host */
41
42static QOSGraphObject *QSPAPR_host_get_device(void *obj, const char *device)
43{
44 QSPAPR_pci_host *host = obj;
45 if (!g_strcmp0(device, "pci-bus-spapr")) {
46 return &host->pci.obj;
47 }
48 fprintf(stderr, "%s not present in QSPAPR_pci_host\n", device);
49 g_assert_not_reached();
50}
51
52static void qos_create_QSPAPR_host(QSPAPR_pci_host *host,
53 QTestState *qts,
54 QGuestAllocator *alloc)
55{
56 host->obj.get_device = QSPAPR_host_get_device;
57 qpci_init_spapr(&host->pci, qts, alloc);
58}
59
60/* ppc64/pseries machine */
61
62static void spapr_destructor(QOSGraphObject *obj)
63{
64 Qppc64_pseriesMachine *machine = (Qppc64_pseriesMachine *) obj;
65 alloc_destroy(&machine->alloc);
66}
67
68static void *spapr_get_driver(void *object, const char *interface)
69{
70 Qppc64_pseriesMachine *machine = object;
71 if (!g_strcmp0(interface, "memory")) {
72 return &machine->alloc;
73 }
74
75 fprintf(stderr, "%s not present in ppc64/pseries\n", interface);
76 g_assert_not_reached();
77}
78
79static QOSGraphObject *spapr_get_device(void *obj, const char *device)
80{
81 Qppc64_pseriesMachine *machine = obj;
82 if (!g_strcmp0(device, "spapr-pci-host-bridge")) {
83 return &machine->bridge.obj;
84 }
85
86 fprintf(stderr, "%s not present in ppc64/pseries\n", device);
87 g_assert_not_reached();
88}
89
90static void *qos_create_machine_spapr(QTestState *qts)
91{
92 Qppc64_pseriesMachine *machine = g_new0(Qppc64_pseriesMachine, 1);
93 machine->obj.get_device = spapr_get_device;
94 machine->obj.get_driver = spapr_get_driver;
95 machine->obj.destructor = spapr_destructor;
96 spapr_alloc_init(&machine->alloc, qts, ALLOC_NO_FLAGS);
97
98 qos_create_QSPAPR_host(&machine->bridge, qts, &machine->alloc);
99
100 return &machine->obj;
101}
102
103static void spapr_machine_register_nodes(void)
104{
105 qos_node_create_machine("ppc64/pseries", qos_create_machine_spapr);
106 qos_node_create_driver("spapr-pci-host-bridge", NULL);
107 qos_node_contains("ppc64/pseries", "spapr-pci-host-bridge", NULL);
108 qos_node_contains("spapr-pci-host-bridge", "pci-bus-spapr", NULL);
109}
110
111libqos_init(spapr_machine_register_nodes);
112