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.1 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"
23 #include "qemu/module.h"
24 #include "malloc-pc.h"
26 typedef struct QX86PCMachine QX86PCMachine
;
27 typedef struct i440FX_pcihost i440FX_pcihost
;
28 typedef struct QSDHCI_PCI QSDHCI_PCI
;
30 struct i440FX_pcihost
{
35 struct QX86PCMachine
{
37 QGuestAllocator alloc
;
38 i440FX_pcihost bridge
;
43 static QOSGraphObject
*i440FX_host_get_device(void *obj
, const char *device
)
45 i440FX_pcihost
*host
= obj
;
46 if (!g_strcmp0(device
, "pci-bus-pc")) {
47 return &host
->pci
.obj
;
49 fprintf(stderr
, "%s not present in i440FX-pcihost\n", device
);
50 g_assert_not_reached();
53 static void qos_create_i440FX_host(i440FX_pcihost
*host
,
55 QGuestAllocator
*alloc
)
57 host
->obj
.get_device
= i440FX_host_get_device
;
58 qpci_init_pc(&host
->pci
, qts
, alloc
);
61 /* x86_64/pc machine */
63 static void pc_destructor(QOSGraphObject
*obj
)
65 QX86PCMachine
*machine
= (QX86PCMachine
*) obj
;
66 alloc_destroy(&machine
->alloc
);
69 static void *pc_get_driver(void *object
, const char *interface
)
71 QX86PCMachine
*machine
= object
;
72 if (!g_strcmp0(interface
, "memory")) {
73 return &machine
->alloc
;
76 fprintf(stderr
, "%s not present in x86_64/pc\n", interface
);
77 g_assert_not_reached();
80 static QOSGraphObject
*pc_get_device(void *obj
, const char *device
)
82 QX86PCMachine
*machine
= obj
;
83 if (!g_strcmp0(device
, "i440FX-pcihost")) {
84 return &machine
->bridge
.obj
;
87 fprintf(stderr
, "%s not present in x86_64/pc\n", device
);
88 g_assert_not_reached();
91 static void *qos_create_machine_pc(QTestState
*qts
)
93 QX86PCMachine
*machine
= g_new0(QX86PCMachine
, 1);
94 machine
->obj
.get_device
= pc_get_device
;
95 machine
->obj
.get_driver
= pc_get_driver
;
96 machine
->obj
.destructor
= pc_destructor
;
97 pc_alloc_init(&machine
->alloc
, qts
, ALLOC_NO_FLAGS
);
98 qos_create_i440FX_host(&machine
->bridge
, qts
, &machine
->alloc
);
100 return &machine
->obj
;
103 static void pc_machine_register_nodes(void)
105 qos_node_create_machine("i386/pc", qos_create_machine_pc
);
106 qos_node_contains("i386/pc", "i440FX-pcihost", NULL
);
108 qos_node_create_machine("x86_64/pc", qos_create_machine_pc
);
109 qos_node_contains("x86_64/pc", "i440FX-pcihost", NULL
);
111 qos_node_create_driver("i440FX-pcihost", NULL
);
112 qos_node_contains("i440FX-pcihost", "pci-bus-pc", NULL
);
115 libqos_init(pc_machine_register_nodes
);