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