xref: /openbmc/qemu/tests/qtest/libqos/tpci200.c (revision 2e3408b3cc7de4e87a9adafc8c19bfce3abec947)
11cf4323eSThomas Huth /*
21cf4323eSThomas Huth  * QTest testcase for tpci200 PCI-IndustryPack bridge
31cf4323eSThomas Huth  *
41cf4323eSThomas Huth  * Copyright (c) 2014 SUSE LINUX Products GmbH
51cf4323eSThomas Huth  *
61cf4323eSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
71cf4323eSThomas Huth  * See the COPYING file in the top-level directory.
81cf4323eSThomas Huth  */
91cf4323eSThomas Huth 
101cf4323eSThomas Huth #include "qemu/osdep.h"
11*907b5105SMarc-André Lureau #include "../libqtest.h"
121cf4323eSThomas Huth #include "qemu/module.h"
13a2ce7dbdSPaolo Bonzini #include "qgraph.h"
14a2ce7dbdSPaolo Bonzini #include "pci.h"
151cf4323eSThomas Huth 
161cf4323eSThomas Huth typedef struct QTpci200 QTpci200;
171cf4323eSThomas Huth typedef struct QIpack QIpack;
181cf4323eSThomas Huth 
191cf4323eSThomas Huth struct QIpack {
201cf4323eSThomas Huth 
211cf4323eSThomas Huth };
221cf4323eSThomas Huth struct QTpci200 {
231cf4323eSThomas Huth     QOSGraphObject obj;
241cf4323eSThomas Huth     QPCIDevice dev;
251cf4323eSThomas Huth     QIpack ipack;
261cf4323eSThomas Huth };
271cf4323eSThomas Huth 
281cf4323eSThomas Huth /* tpci200 */
tpci200_get_driver(void * obj,const char * interface)291cf4323eSThomas Huth static void *tpci200_get_driver(void *obj, const char *interface)
301cf4323eSThomas Huth {
311cf4323eSThomas Huth     QTpci200 *tpci200 = obj;
321cf4323eSThomas Huth     if (!g_strcmp0(interface, "ipack")) {
331cf4323eSThomas Huth         return &tpci200->ipack;
341cf4323eSThomas Huth     }
351cf4323eSThomas Huth     if (!g_strcmp0(interface, "pci-device")) {
361cf4323eSThomas Huth         return &tpci200->dev;
371cf4323eSThomas Huth     }
381cf4323eSThomas Huth 
391cf4323eSThomas Huth     fprintf(stderr, "%s not present in tpci200\n", interface);
401cf4323eSThomas Huth     g_assert_not_reached();
411cf4323eSThomas Huth }
421cf4323eSThomas Huth 
tpci200_create(void * pci_bus,QGuestAllocator * alloc,void * addr)431cf4323eSThomas Huth static void *tpci200_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
441cf4323eSThomas Huth {
451cf4323eSThomas Huth     QTpci200 *tpci200 = g_new0(QTpci200, 1);
461cf4323eSThomas Huth     QPCIBus *bus = pci_bus;
471cf4323eSThomas Huth 
481cf4323eSThomas Huth     qpci_device_init(&tpci200->dev, bus, addr);
491cf4323eSThomas Huth     tpci200->obj.get_driver = tpci200_get_driver;
501cf4323eSThomas Huth     return &tpci200->obj;
511cf4323eSThomas Huth }
521cf4323eSThomas Huth 
tpci200_register_nodes(void)531cf4323eSThomas Huth static void tpci200_register_nodes(void)
541cf4323eSThomas Huth {
551cf4323eSThomas Huth     QOSGraphEdgeOptions opts = {
561cf4323eSThomas Huth         .extra_device_opts = "addr=04.0,id=ipack0",
571cf4323eSThomas Huth     };
581cf4323eSThomas Huth     add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
591cf4323eSThomas Huth 
601cf4323eSThomas Huth     qos_node_create_driver("tpci200", tpci200_create);
611cf4323eSThomas Huth     qos_node_consumes("tpci200", "pci-bus", &opts);
621cf4323eSThomas Huth     qos_node_produces("tpci200", "ipack");
631cf4323eSThomas Huth     qos_node_produces("tpci200", "pci-device");
641cf4323eSThomas Huth }
651cf4323eSThomas Huth 
661cf4323eSThomas Huth libqos_init(tpci200_register_nodes);
67