xref: /openbmc/qemu/tests/qtest/eepro100-test.c (revision 2e3408b3cc7de4e87a9adafc8c19bfce3abec947)
11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth  * QTest testcase for eepro100 NIC
31e8a1faeSThomas Huth  *
41e8a1faeSThomas Huth  * Copyright (c) 2013-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 QEEPRO100 QEEPRO100;
171e8a1faeSThomas Huth 
181e8a1faeSThomas Huth struct QEEPRO100 {
191e8a1faeSThomas Huth     QOSGraphObject obj;
201e8a1faeSThomas Huth     QPCIDevice dev;
211e8a1faeSThomas Huth };
221e8a1faeSThomas Huth 
231e8a1faeSThomas Huth static const char *models[] = {
241e8a1faeSThomas Huth     "i82550",
251e8a1faeSThomas Huth     "i82551",
261e8a1faeSThomas Huth     "i82557a",
271e8a1faeSThomas Huth     "i82557b",
281e8a1faeSThomas Huth     "i82557c",
291e8a1faeSThomas Huth     "i82558a",
301e8a1faeSThomas Huth     "i82558b",
311e8a1faeSThomas Huth     "i82559a",
321e8a1faeSThomas Huth     "i82559b",
331e8a1faeSThomas Huth     "i82559c",
341e8a1faeSThomas Huth     "i82559er",
351e8a1faeSThomas Huth     "i82562",
361e8a1faeSThomas Huth     "i82801",
371e8a1faeSThomas Huth };
381e8a1faeSThomas Huth 
eepro100_get_driver(void * obj,const char * interface)391e8a1faeSThomas Huth static void *eepro100_get_driver(void *obj, const char *interface)
401e8a1faeSThomas Huth {
411e8a1faeSThomas Huth     QEEPRO100 *eepro100 = obj;
421e8a1faeSThomas Huth 
431e8a1faeSThomas Huth     if (!g_strcmp0(interface, "pci-device")) {
441e8a1faeSThomas Huth         return &eepro100->dev;
451e8a1faeSThomas Huth     }
461e8a1faeSThomas Huth 
471e8a1faeSThomas Huth     fprintf(stderr, "%s not present in eepro100\n", interface);
481e8a1faeSThomas Huth     g_assert_not_reached();
491e8a1faeSThomas Huth }
501e8a1faeSThomas Huth 
eepro100_create(void * pci_bus,QGuestAllocator * alloc,void * addr)511e8a1faeSThomas Huth static void *eepro100_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
521e8a1faeSThomas Huth {
531e8a1faeSThomas Huth     QEEPRO100 *eepro100 = g_new0(QEEPRO100, 1);
541e8a1faeSThomas Huth     QPCIBus *bus = pci_bus;
551e8a1faeSThomas Huth 
561e8a1faeSThomas Huth     qpci_device_init(&eepro100->dev, bus, addr);
571e8a1faeSThomas Huth     eepro100->obj.get_driver = eepro100_get_driver;
581e8a1faeSThomas Huth 
591e8a1faeSThomas Huth     return &eepro100->obj;
601e8a1faeSThomas Huth }
611e8a1faeSThomas Huth 
eepro100_register_nodes(void)621e8a1faeSThomas Huth static void eepro100_register_nodes(void)
631e8a1faeSThomas Huth {
641e8a1faeSThomas Huth     int i;
651e8a1faeSThomas Huth     QOSGraphEdgeOptions opts = {
661e8a1faeSThomas Huth         .extra_device_opts = "addr=04.0",
671e8a1faeSThomas Huth     };
681e8a1faeSThomas Huth 
691e8a1faeSThomas Huth     add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
701e8a1faeSThomas Huth     for (i = 0; i < ARRAY_SIZE(models); i++) {
711e8a1faeSThomas Huth         qos_node_create_driver(models[i], eepro100_create);
721e8a1faeSThomas Huth         qos_node_consumes(models[i], "pci-bus", &opts);
731e8a1faeSThomas Huth         qos_node_produces(models[i], "pci-device");
741e8a1faeSThomas Huth     }
751e8a1faeSThomas Huth }
761e8a1faeSThomas Huth 
771e8a1faeSThomas Huth libqos_init(eepro100_register_nodes);
78