Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 1 | /* |
| 2 | * QTest testcase for USB OHCI controller |
| 3 | * |
Gonglei | fe75270 | 2015-03-26 20:57:43 +0800 | [diff] [blame] | 4 | * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD. |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 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 | |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 10 | #include "qemu/osdep.h" |
Thomas Huth | dd21074 | 2019-09-03 07:50:26 +0200 | [diff] [blame] | 11 | #include "libqtest-single.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 12 | #include "qemu/module.h" |
Igor Mammedov | b393768 | 2014-09-26 09:28:14 +0000 | [diff] [blame] | 13 | #include "libqos/usb.h" |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 14 | #include "libqos/qgraph.h" |
| 15 | #include "libqos/pci.h" |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 16 | |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 17 | typedef struct QOHCI_PCI QOHCI_PCI; |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 18 | |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 19 | struct QOHCI_PCI { |
| 20 | QOSGraphObject obj; |
| 21 | QPCIDevice dev; |
| 22 | }; |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 23 | |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 24 | static void test_ohci_hotplug(void *obj, void *data, QGuestAllocator *alloc) |
Igor Mammedov | b393768 | 2014-09-26 09:28:14 +0000 | [diff] [blame] | 25 | { |
Thomas Huth | e5758de | 2019-07-22 17:10:55 +0200 | [diff] [blame] | 26 | usb_test_hotplug(global_qtest, "ohci", "1", NULL); |
Igor Mammedov | b393768 | 2014-09-26 09:28:14 +0000 | [diff] [blame] | 27 | } |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 28 | |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 29 | static void *ohci_pci_get_driver(void *obj, const char *interface) |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 30 | { |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 31 | QOHCI_PCI *ohci_pci = obj; |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 32 | |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 33 | if (!g_strcmp0(interface, "pci-device")) { |
| 34 | return &ohci_pci->dev; |
| 35 | } |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 36 | |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 37 | fprintf(stderr, "%s not present in pci-ohci\n", interface); |
| 38 | g_assert_not_reached(); |
Gonglei | 28edfce | 2014-06-23 19:53:51 +0800 | [diff] [blame] | 39 | } |
Emanuele Giuseppe Esposito | fb7e0b4 | 2018-08-17 15:47:17 +0200 | [diff] [blame] | 40 | |
| 41 | static 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 | |
| 49 | static 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 | |
| 61 | libqos_init(ohci_pci_register_nodes); |
| 62 | |
| 63 | static void register_ohci_pci_test(void) |
| 64 | { |
| 65 | qos_add_test("ohci_pci-test-hotplug", "pci-ohci", test_ohci_hotplug, NULL); |
| 66 | } |
| 67 | |
| 68 | libqos_init(register_ohci_pci_test); |