blob: 900944fa7e34c220418bca663240be5fde61b3ba [file] [log] [blame]
Andreas Färber85f68d52013-11-07 18:53:28 +01001/*
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
Andreas Färber85f68d52013-11-07 18:53:28 +010010#include "qemu/osdep.h"
Peter Maydell681c28a2016-02-08 18:08:51 +000011#include "libqtest.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020012#include "qemu/module.h"
Emanuele Giuseppe Esposito96900e12018-08-17 13:22:12 +020013#include "libqos/qgraph.h"
14#include "libqos/pci.h"
Andreas Färber85f68d52013-11-07 18:53:28 +010015
Emanuele Giuseppe Esposito96900e12018-08-17 13:22:12 +020016typedef struct QPCNet QPCNet;
17
18struct QPCNet {
19 QOSGraphObject obj;
20 QPCIDevice dev;
21};
22
23static void *pcnet_get_driver(void *obj, const char *interface)
Andreas Färber85f68d52013-11-07 18:53:28 +010024{
Emanuele Giuseppe Esposito96900e12018-08-17 13:22:12 +020025 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();
Andreas Färber85f68d52013-11-07 18:53:28 +010033}
34
Emanuele Giuseppe Esposito96900e12018-08-17 13:22:12 +020035static void *pcnet_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
Andreas Färber85f68d52013-11-07 18:53:28 +010036{
Emanuele Giuseppe Esposito96900e12018-08-17 13:22:12 +020037 QPCNet *pcnet = g_new0(QPCNet, 1);
38 QPCIBus *bus = pci_bus;
Andreas Färber85f68d52013-11-07 18:53:28 +010039
Emanuele Giuseppe Esposito96900e12018-08-17 13:22:12 +020040 qpci_device_init(&pcnet->dev, bus, addr);
41 pcnet->obj.get_driver = pcnet_get_driver;
Andreas Färber85f68d52013-11-07 18:53:28 +010042
Emanuele Giuseppe Esposito96900e12018-08-17 13:22:12 +020043 return &pcnet->obj;
Andreas Färber85f68d52013-11-07 18:53:28 +010044}
Emanuele Giuseppe Esposito96900e12018-08-17 13:22:12 +020045
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) });
52
53 qos_node_create_driver("pcnet", pcnet_create);
54 qos_node_consumes("pcnet", "pci-bus", &opts);
55 qos_node_produces("pcnet", "pci-device");
56}
57
58libqos_init(pcnet_register_nodes);