xref: /openbmc/qemu/tests/qtest/libqos/tpci200.c (revision 4921d0a7)
1 /*
2  * QTest testcase for tpci200 PCI-IndustryPack bridge
3  *
4  * Copyright (c) 2014 SUSE LINUX Products GmbH
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "../libqtest.h"
12 #include "qemu/module.h"
13 #include "qgraph.h"
14 #include "pci.h"
15 
16 typedef struct QTpci200 QTpci200;
17 typedef struct QIpack QIpack;
18 
19 struct QIpack {
20 
21 };
22 struct QTpci200 {
23     QOSGraphObject obj;
24     QPCIDevice dev;
25     QIpack ipack;
26 };
27 
28 /* tpci200 */
29 static void *tpci200_get_driver(void *obj, const char *interface)
30 {
31     QTpci200 *tpci200 = obj;
32     if (!g_strcmp0(interface, "ipack")) {
33         return &tpci200->ipack;
34     }
35     if (!g_strcmp0(interface, "pci-device")) {
36         return &tpci200->dev;
37     }
38 
39     fprintf(stderr, "%s not present in tpci200\n", interface);
40     g_assert_not_reached();
41 }
42 
43 static void *tpci200_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
44 {
45     QTpci200 *tpci200 = g_new0(QTpci200, 1);
46     QPCIBus *bus = pci_bus;
47 
48     qpci_device_init(&tpci200->dev, bus, addr);
49     tpci200->obj.get_driver = tpci200_get_driver;
50     return &tpci200->obj;
51 }
52 
53 static void tpci200_register_nodes(void)
54 {
55     QOSGraphEdgeOptions opts = {
56         .extra_device_opts = "addr=04.0,id=ipack0",
57     };
58     add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
59 
60     qos_node_create_driver("tpci200", tpci200_create);
61     qos_node_consumes("tpci200", "pci-bus", &opts);
62     qos_node_produces("tpci200", "ipack");
63     qos_node_produces("tpci200", "pci-device");
64 }
65 
66 libqos_init(tpci200_register_nodes);
67