spapr_pci: Improve error message
[qemu/ar7.git] / tests / libqos / ppc64_pseries-machine.c
blob2f3640010d1271a59284689b6c10b1455e4b931e
1 /*
2 * libqos driver framework
4 * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
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.
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.
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/>
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"
25 typedef struct QSPAPR_pci_host QSPAPR_pci_host;
26 typedef struct Qppc64_pseriesMachine Qppc64_pseriesMachine;
28 struct QSPAPR_pci_host {
29 QOSGraphObject obj;
30 QPCIBusSPAPR pci;
33 struct Qppc64_pseriesMachine {
34 QOSGraphObject obj;
35 QGuestAllocator alloc;
36 QSPAPR_pci_host bridge;
39 /* QSPAPR_pci_host */
41 static QOSGraphObject *QSPAPR_host_get_device(void *obj, const char *device)
43 QSPAPR_pci_host *host = obj;
44 if (!g_strcmp0(device, "pci-bus-spapr")) {
45 return &host->pci.obj;
47 fprintf(stderr, "%s not present in QSPAPR_pci_host\n", device);
48 g_assert_not_reached();
51 static void qos_create_QSPAPR_host(QSPAPR_pci_host *host,
52 QTestState *qts,
53 QGuestAllocator *alloc)
55 host->obj.get_device = QSPAPR_host_get_device;
56 qpci_init_spapr(&host->pci, qts, alloc);
59 /* ppc64/pseries machine */
61 static void spapr_destructor(QOSGraphObject *obj)
63 Qppc64_pseriesMachine *machine = (Qppc64_pseriesMachine *) obj;
64 alloc_destroy(&machine->alloc);
67 static void *spapr_get_driver(void *object, const char *interface)
69 Qppc64_pseriesMachine *machine = object;
70 if (!g_strcmp0(interface, "memory")) {
71 return &machine->alloc;
74 fprintf(stderr, "%s not present in ppc64/pseries\n", interface);
75 g_assert_not_reached();
78 static QOSGraphObject *spapr_get_device(void *obj, const char *device)
80 Qppc64_pseriesMachine *machine = obj;
81 if (!g_strcmp0(device, "spapr-pci-host-bridge")) {
82 return &machine->bridge.obj;
85 fprintf(stderr, "%s not present in ppc64/pseries\n", device);
86 g_assert_not_reached();
89 static void *qos_create_machine_spapr(QTestState *qts)
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);
97 qos_create_QSPAPR_host(&machine->bridge, qts, &machine->alloc);
99 return &machine->obj;
102 static void spapr_machine_register_nodes(void)
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);
110 libqos_init(spapr_machine_register_nodes);