]>
Commit | Line | Data |
---|---|---|
5297ea6f AF |
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 | ||
681c28a3 | 10 | #include "qemu/osdep.h" |
5297ea6f | 11 | #include "libqtest.h" |
0b8fa32f | 12 | #include "qemu/module.h" |
941e3317 EGE |
13 | #include "libqos/qgraph.h" |
14 | #include "libqos/pci.h" | |
5297ea6f | 15 | |
941e3317 EGE |
16 | typedef struct QNe2k_pci QNe2k_pci; |
17 | ||
18 | struct QNe2k_pci { | |
19 | QOSGraphObject obj; | |
20 | QPCIDevice dev; | |
21 | }; | |
22 | ||
23 | static void *ne2k_pci_get_driver(void *obj, const char *interface) | |
5297ea6f | 24 | { |
941e3317 EGE |
25 | QNe2k_pci *ne2k_pci = obj; |
26 | ||
27 | if (!g_strcmp0(interface, "pci-device")) { | |
28 | return &ne2k_pci->dev; | |
29 | } | |
30 | ||
31 | fprintf(stderr, "%s not present in ne2k_pci\n", interface); | |
32 | g_assert_not_reached(); | |
5297ea6f AF |
33 | } |
34 | ||
941e3317 | 35 | static void *ne2k_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr) |
5297ea6f | 36 | { |
941e3317 EGE |
37 | QNe2k_pci *ne2k_pci = g_new0(QNe2k_pci, 1); |
38 | QPCIBus *bus = pci_bus; | |
5297ea6f | 39 | |
941e3317 EGE |
40 | qpci_device_init(&ne2k_pci->dev, bus, addr); |
41 | ne2k_pci->obj.get_driver = ne2k_pci_get_driver; | |
5297ea6f | 42 | |
941e3317 EGE |
43 | return &ne2k_pci->obj; |
44 | } | |
5297ea6f | 45 | |
941e3317 EGE |
46 | static void ne2000_register_nodes(void) |
47 | { | |
48 | QOSGraphEdgeOptions opts = { | |
49 | .extra_device_opts = "addr=04.0", | |
50 | }; | |
51 | add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); | |
5297ea6f | 52 | |
941e3317 EGE |
53 | qos_node_create_driver("ne2k_pci", ne2k_pci_create); |
54 | qos_node_consumes("ne2k_pci", "pci-bus", &opts); | |
55 | qos_node_produces("ne2k_pci", "pci-device"); | |
5297ea6f | 56 | } |
941e3317 EGE |
57 | |
58 | libqos_init(ne2000_register_nodes); |