11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * QTest testcase for PC-Net 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 QPCNet QPCNet;
171e8a1faeSThomas Huth
181e8a1faeSThomas Huth struct QPCNet {
191e8a1faeSThomas Huth QOSGraphObject obj;
201e8a1faeSThomas Huth QPCIDevice dev;
211e8a1faeSThomas Huth };
221e8a1faeSThomas Huth
pcnet_get_driver(void * obj,const char * interface)231e8a1faeSThomas Huth static void *pcnet_get_driver(void *obj, const char *interface)
241e8a1faeSThomas Huth {
251e8a1faeSThomas Huth QPCNet *pcnet = obj;
261e8a1faeSThomas Huth
271e8a1faeSThomas Huth if (!g_strcmp0(interface, "pci-device")) {
281e8a1faeSThomas Huth return &pcnet->dev;
291e8a1faeSThomas Huth }
301e8a1faeSThomas Huth
311e8a1faeSThomas Huth fprintf(stderr, "%s not present in pcnet\n", interface);
321e8a1faeSThomas Huth g_assert_not_reached();
331e8a1faeSThomas Huth }
341e8a1faeSThomas Huth
pcnet_create(void * pci_bus,QGuestAllocator * alloc,void * addr)351e8a1faeSThomas Huth static void *pcnet_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
361e8a1faeSThomas Huth {
371e8a1faeSThomas Huth QPCNet *pcnet = g_new0(QPCNet, 1);
381e8a1faeSThomas Huth QPCIBus *bus = pci_bus;
391e8a1faeSThomas Huth
401e8a1faeSThomas Huth qpci_device_init(&pcnet->dev, bus, addr);
411e8a1faeSThomas Huth pcnet->obj.get_driver = pcnet_get_driver;
421e8a1faeSThomas Huth
431e8a1faeSThomas Huth return &pcnet->obj;
441e8a1faeSThomas Huth }
451e8a1faeSThomas Huth
pcnet_register_nodes(void)461e8a1faeSThomas Huth static void pcnet_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("pcnet", pcnet_create);
541e8a1faeSThomas Huth qos_node_consumes("pcnet", "pci-bus", &opts);
551e8a1faeSThomas Huth qos_node_produces("pcnet", "pci-device");
561e8a1faeSThomas Huth }
571e8a1faeSThomas Huth
581e8a1faeSThomas Huth libqos_init(pcnet_register_nodes);
59