]> Git Repo - qemu.git/blob - tests/ne2000-test.c
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2019-03-08' into staging
[qemu.git] / tests / ne2000-test.c
1 /*
2  * QTest testcase for ne2000 NIC
3  *
4  * Copyright (c) 2014 SUSE LINUX Products GmbH
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9
10 #include "qemu/osdep.h"
11 #include "libqtest.h"
12 #include "libqos/qgraph.h"
13 #include "libqos/pci.h"
14
15 typedef struct QNe2k_pci QNe2k_pci;
16
17 struct QNe2k_pci {
18     QOSGraphObject obj;
19     QPCIDevice dev;
20 };
21
22 static void *ne2k_pci_get_driver(void *obj, const char *interface)
23 {
24     QNe2k_pci *ne2k_pci = obj;
25
26     if (!g_strcmp0(interface, "pci-device")) {
27         return &ne2k_pci->dev;
28     }
29
30     fprintf(stderr, "%s not present in ne2k_pci\n", interface);
31     g_assert_not_reached();
32 }
33
34 static void *ne2k_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
35 {
36     QNe2k_pci *ne2k_pci = g_new0(QNe2k_pci, 1);
37     QPCIBus *bus = pci_bus;
38
39     qpci_device_init(&ne2k_pci->dev, bus, addr);
40     ne2k_pci->obj.get_driver = ne2k_pci_get_driver;
41
42     return &ne2k_pci->obj;
43 }
44
45 static void ne2000_register_nodes(void)
46 {
47     QOSGraphEdgeOptions opts = {
48         .extra_device_opts = "addr=04.0",
49     };
50     add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
51
52     qos_node_create_driver("ne2k_pci", ne2k_pci_create);
53     qos_node_consumes("ne2k_pci", "pci-bus", &opts);
54     qos_node_produces("ne2k_pci", "pci-device");
55 }
56
57 libqos_init(ne2000_register_nodes);
This page took 0.027233 seconds and 4 git commands to generate.