blob: 19d760f3fb2d00874e660f80c50553a83eae764f [file] [log] [blame]
Gonglei28edfce2014-06-23 19:53:51 +08001/*
2 * QTest testcase for USB OHCI controller
3 *
Gongleife752702015-03-26 20:57:43 +08004 * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
Gonglei28edfce2014-06-23 19:53:51 +08005 *
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
Gonglei28edfce2014-06-23 19:53:51 +080010#include "qemu/osdep.h"
Thomas Huthdd210742019-09-03 07:50:26 +020011#include "libqtest-single.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020012#include "qemu/module.h"
Igor Mammedovb3937682014-09-26 09:28:14 +000013#include "libqos/usb.h"
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020014#include "libqos/qgraph.h"
15#include "libqos/pci.h"
Gonglei28edfce2014-06-23 19:53:51 +080016
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020017typedef struct QOHCI_PCI QOHCI_PCI;
Gonglei28edfce2014-06-23 19:53:51 +080018
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020019struct QOHCI_PCI {
20 QOSGraphObject obj;
21 QPCIDevice dev;
22};
Gonglei28edfce2014-06-23 19:53:51 +080023
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020024static void test_ohci_hotplug(void *obj, void *data, QGuestAllocator *alloc)
Igor Mammedovb3937682014-09-26 09:28:14 +000025{
Thomas Huthe5758de2019-07-22 17:10:55 +020026 usb_test_hotplug(global_qtest, "ohci", "1", NULL);
Igor Mammedovb3937682014-09-26 09:28:14 +000027}
Gonglei28edfce2014-06-23 19:53:51 +080028
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020029static void *ohci_pci_get_driver(void *obj, const char *interface)
Gonglei28edfce2014-06-23 19:53:51 +080030{
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020031 QOHCI_PCI *ohci_pci = obj;
Gonglei28edfce2014-06-23 19:53:51 +080032
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020033 if (!g_strcmp0(interface, "pci-device")) {
34 return &ohci_pci->dev;
35 }
Gonglei28edfce2014-06-23 19:53:51 +080036
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020037 fprintf(stderr, "%s not present in pci-ohci\n", interface);
38 g_assert_not_reached();
Gonglei28edfce2014-06-23 19:53:51 +080039}
Emanuele Giuseppe Espositofb7e0b42018-08-17 15:47:17 +020040
41static void *ohci_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
42{
43 QOHCI_PCI *ohci_pci = g_new0(QOHCI_PCI, 1);
44 ohci_pci->obj.get_driver = ohci_pci_get_driver;
45
46 return &ohci_pci->obj;
47}
48
49static void ohci_pci_register_nodes(void)
50{
51 QOSGraphEdgeOptions opts = {
52 .extra_device_opts = "addr=04.0,id=ohci",
53 };
54 add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
55
56 qos_node_create_driver("pci-ohci", ohci_pci_create);
57 qos_node_consumes("pci-ohci", "pci-bus", &opts);
58 qos_node_produces("pci-ohci", "pci-device");
59}
60
61libqos_init(ohci_pci_register_nodes);
62
63static void register_ohci_pci_test(void)
64{
65 qos_add_test("ohci_pci-test-hotplug", "pci-ohci", test_ohci_hotplug, NULL);
66}
67
68libqos_init(register_ohci_pci_test);