15297ea6fSAndreas Färber /*
25297ea6fSAndreas Färber * QTest testcase for ne2000 NIC
35297ea6fSAndreas Färber *
45297ea6fSAndreas Färber * Copyright (c) 2014 SUSE LINUX Products GmbH
55297ea6fSAndreas Färber *
65297ea6fSAndreas Färber * This work is licensed under the terms of the GNU GPL, version 2 or later.
75297ea6fSAndreas Färber * See the COPYING file in the top-level directory.
85297ea6fSAndreas Färber */
95297ea6fSAndreas Färber
105297ea6fSAndreas Färber #include "qemu/osdep.h"
11*907b5105SMarc-André Lureau #include "libqtest.h"
120b8fa32fSMarkus Armbruster #include "qemu/module.h"
13941e3317SEmanuele Giuseppe Esposito #include "libqos/qgraph.h"
14941e3317SEmanuele Giuseppe Esposito #include "libqos/pci.h"
155297ea6fSAndreas Färber
16941e3317SEmanuele Giuseppe Esposito typedef struct QNe2k_pci QNe2k_pci;
17941e3317SEmanuele Giuseppe Esposito
18941e3317SEmanuele Giuseppe Esposito struct QNe2k_pci {
19941e3317SEmanuele Giuseppe Esposito QOSGraphObject obj;
20941e3317SEmanuele Giuseppe Esposito QPCIDevice dev;
21941e3317SEmanuele Giuseppe Esposito };
22941e3317SEmanuele Giuseppe Esposito
ne2k_pci_get_driver(void * obj,const char * interface)23941e3317SEmanuele Giuseppe Esposito static void *ne2k_pci_get_driver(void *obj, const char *interface)
245297ea6fSAndreas Färber {
25941e3317SEmanuele Giuseppe Esposito QNe2k_pci *ne2k_pci = obj;
26941e3317SEmanuele Giuseppe Esposito
27941e3317SEmanuele Giuseppe Esposito if (!g_strcmp0(interface, "pci-device")) {
28941e3317SEmanuele Giuseppe Esposito return &ne2k_pci->dev;
295297ea6fSAndreas Färber }
305297ea6fSAndreas Färber
31941e3317SEmanuele Giuseppe Esposito fprintf(stderr, "%s not present in ne2k_pci\n", interface);
32941e3317SEmanuele Giuseppe Esposito g_assert_not_reached();
335297ea6fSAndreas Färber }
34941e3317SEmanuele Giuseppe Esposito
ne2k_pci_create(void * pci_bus,QGuestAllocator * alloc,void * addr)35941e3317SEmanuele Giuseppe Esposito static void *ne2k_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
36941e3317SEmanuele Giuseppe Esposito {
37941e3317SEmanuele Giuseppe Esposito QNe2k_pci *ne2k_pci = g_new0(QNe2k_pci, 1);
38941e3317SEmanuele Giuseppe Esposito QPCIBus *bus = pci_bus;
39941e3317SEmanuele Giuseppe Esposito
40941e3317SEmanuele Giuseppe Esposito qpci_device_init(&ne2k_pci->dev, bus, addr);
41941e3317SEmanuele Giuseppe Esposito ne2k_pci->obj.get_driver = ne2k_pci_get_driver;
42941e3317SEmanuele Giuseppe Esposito
43941e3317SEmanuele Giuseppe Esposito return &ne2k_pci->obj;
44941e3317SEmanuele Giuseppe Esposito }
45941e3317SEmanuele Giuseppe Esposito
ne2000_register_nodes(void)46941e3317SEmanuele Giuseppe Esposito static void ne2000_register_nodes(void)
47941e3317SEmanuele Giuseppe Esposito {
48941e3317SEmanuele Giuseppe Esposito QOSGraphEdgeOptions opts = {
49941e3317SEmanuele Giuseppe Esposito .extra_device_opts = "addr=04.0",
50941e3317SEmanuele Giuseppe Esposito };
51941e3317SEmanuele Giuseppe Esposito add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
52941e3317SEmanuele Giuseppe Esposito
53941e3317SEmanuele Giuseppe Esposito qos_node_create_driver("ne2k_pci", ne2k_pci_create);
54941e3317SEmanuele Giuseppe Esposito qos_node_consumes("ne2k_pci", "pci-bus", &opts);
55941e3317SEmanuele Giuseppe Esposito qos_node_produces("ne2k_pci", "pci-device");
56941e3317SEmanuele Giuseppe Esposito }
57941e3317SEmanuele Giuseppe Esposito
58941e3317SEmanuele Giuseppe Esposito libqos_init(ne2000_register_nodes);
59