Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 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 | |
Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 10 | #include "qemu/osdep.h" |
Peter Maydell | 681c28a | 2016-02-08 18:08:51 +0000 | [diff] [blame] | 11 | #include "libqtest.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 12 | #include "qemu/module.h" |
Emanuele Giuseppe Esposito | 96900e1 | 2018-08-17 13:22:12 +0200 | [diff] [blame] | 13 | #include "libqos/qgraph.h" |
| 14 | #include "libqos/pci.h" |
Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 15 | |
Emanuele Giuseppe Esposito | 96900e1 | 2018-08-17 13:22:12 +0200 | [diff] [blame] | 16 | typedef struct QPCNet QPCNet; |
| 17 | |
| 18 | struct QPCNet { |
| 19 | QOSGraphObject obj; |
| 20 | QPCIDevice dev; |
| 21 | }; |
| 22 | |
| 23 | static void *pcnet_get_driver(void *obj, const char *interface) |
Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 24 | { |
Emanuele Giuseppe Esposito | 96900e1 | 2018-08-17 13:22:12 +0200 | [diff] [blame] | 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(); |
Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 33 | } |
| 34 | |
Emanuele Giuseppe Esposito | 96900e1 | 2018-08-17 13:22:12 +0200 | [diff] [blame] | 35 | static void *pcnet_create(void *pci_bus, QGuestAllocator *alloc, void *addr) |
Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 36 | { |
Emanuele Giuseppe Esposito | 96900e1 | 2018-08-17 13:22:12 +0200 | [diff] [blame] | 37 | QPCNet *pcnet = g_new0(QPCNet, 1); |
| 38 | QPCIBus *bus = pci_bus; |
Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 39 | |
Emanuele Giuseppe Esposito | 96900e1 | 2018-08-17 13:22:12 +0200 | [diff] [blame] | 40 | qpci_device_init(&pcnet->dev, bus, addr); |
| 41 | pcnet->obj.get_driver = pcnet_get_driver; |
Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 42 | |
Emanuele Giuseppe Esposito | 96900e1 | 2018-08-17 13:22:12 +0200 | [diff] [blame] | 43 | return &pcnet->obj; |
Andreas Färber | 85f68d5 | 2013-11-07 18:53:28 +0100 | [diff] [blame] | 44 | } |
Emanuele Giuseppe Esposito | 96900e1 | 2018-08-17 13:22:12 +0200 | [diff] [blame] | 45 | |
| 46 | static 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 | |
| 58 | libqos_init(pcnet_register_nodes); |