2
0

pcnet-test.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include "qemu/osdep.h"
  10. #include "libqtest.h"
  11. #include "qemu/module.h"
  12. #include "libqos/qgraph.h"
  13. #include "libqos/pci.h"
  14. typedef struct QPCNet QPCNet;
  15. struct QPCNet {
  16. QOSGraphObject obj;
  17. QPCIDevice dev;
  18. };
  19. static void *pcnet_get_driver(void *obj, const char *interface)
  20. {
  21. QPCNet *pcnet = obj;
  22. if (!g_strcmp0(interface, "pci-device")) {
  23. return &pcnet->dev;
  24. }
  25. fprintf(stderr, "%s not present in pcnet\n", interface);
  26. g_assert_not_reached();
  27. }
  28. static void *pcnet_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
  29. {
  30. QPCNet *pcnet = g_new0(QPCNet, 1);
  31. QPCIBus *bus = pci_bus;
  32. qpci_device_init(&pcnet->dev, bus, addr);
  33. pcnet->obj.get_driver = pcnet_get_driver;
  34. return &pcnet->obj;
  35. }
  36. static void pcnet_register_nodes(void)
  37. {
  38. QOSGraphEdgeOptions opts = {
  39. .extra_device_opts = "addr=04.0",
  40. };
  41. add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
  42. qos_node_create_driver("pcnet", pcnet_create);
  43. qos_node_consumes("pcnet", "pci-bus", &opts);
  44. qos_node_produces("pcnet", "pci-device");
  45. }
  46. libqos_init(pcnet_register_nodes);