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