ne2000-test.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * QTest testcase for ne2000 NIC
  3. *
  4. * Copyright (c) 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 QNe2k_pci QNe2k_pci;
  15. struct QNe2k_pci {
  16. QOSGraphObject obj;
  17. QPCIDevice dev;
  18. };
  19. static void *ne2k_pci_get_driver(void *obj, const char *interface)
  20. {
  21. QNe2k_pci *ne2k_pci = obj;
  22. if (!g_strcmp0(interface, "pci-device")) {
  23. return &ne2k_pci->dev;
  24. }
  25. fprintf(stderr, "%s not present in ne2k_pci\n", interface);
  26. g_assert_not_reached();
  27. }
  28. static void *ne2k_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
  29. {
  30. QNe2k_pci *ne2k_pci = g_new0(QNe2k_pci, 1);
  31. QPCIBus *bus = pci_bus;
  32. qpci_device_init(&ne2k_pci->dev, bus, addr);
  33. ne2k_pci->obj.get_driver = ne2k_pci_get_driver;
  34. return &ne2k_pci->obj;
  35. }
  36. static void ne2000_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("ne2k_pci", ne2k_pci_create);
  43. qos_node_consumes("ne2k_pci", "pci-bus", &opts);
  44. qos_node_produces("ne2k_pci", "pci-device");
  45. }
  46. libqos_init(ne2000_register_nodes);