]> git.proxmox.com Git - mirror_qemu.git/blame - tests/pcnet-test.c
Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2019-06-24' into staging
[mirror_qemu.git] / tests / pcnet-test.c
CommitLineData
85f68d55
AF
1/*
2 * QTest testcase for PC-Net NIC
3 *
4 * Copyright (c) 2013-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"
85f68d55 11#include "libqtest.h"
0b8fa32f 12#include "qemu/module.h"
96900e16
EGE
13#include "libqos/qgraph.h"
14#include "libqos/pci.h"
85f68d55 15
96900e16
EGE
16typedef struct QPCNet QPCNet;
17
18struct QPCNet {
19 QOSGraphObject obj;
20 QPCIDevice dev;
21};
22
23static void *pcnet_get_driver(void *obj, const char *interface)
85f68d55 24{
96900e16
EGE
25 QPCNet *pcnet = obj;
26
27 if (!g_strcmp0(interface, "pci-device")) {
28 return &pcnet->dev;
29 }
30
31 fprintf(stderr, "%s not present in pcnet\n", interface);
32 g_assert_not_reached();
85f68d55
AF
33}
34
96900e16 35static void *pcnet_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
85f68d55 36{
96900e16
EGE
37 QPCNet *pcnet = g_new0(QPCNet, 1);
38 QPCIBus *bus = pci_bus;
85f68d55 39
96900e16
EGE
40 qpci_device_init(&pcnet->dev, bus, addr);
41 pcnet->obj.get_driver = pcnet_get_driver;
85f68d55 42
96900e16
EGE
43 return &pcnet->obj;
44}
85f68d55 45
96900e16
EGE
46static void pcnet_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) });
85f68d55 52
96900e16
EGE
53 qos_node_create_driver("pcnet", pcnet_create);
54 qos_node_consumes("pcnet", "pci-bus", &opts);
55 qos_node_produces("pcnet", "pci-device");
85f68d55 56}
96900e16
EGE
57
58libqos_init(pcnet_register_nodes);