128edfce0SGonglei /*
228edfce0SGonglei * QTest testcase for USB OHCI controller
328edfce0SGonglei *
428edfce0SGonglei * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
528edfce0SGonglei *
628edfce0SGonglei * This work is licensed under the terms of the GNU GPL, version 2 or later.
728edfce0SGonglei * See the COPYING file in the top-level directory.
828edfce0SGonglei */
928edfce0SGonglei
1028edfce0SGonglei #include "qemu/osdep.h"
11*dd210749SThomas Huth #include "libqtest-single.h"
120b8fa32fSMarkus Armbruster #include "qemu/module.h"
13b3937683SIgor Mammedov #include "libqos/usb.h"
14fb7e0b48SEmanuele Giuseppe Esposito #include "libqos/qgraph.h"
15fb7e0b48SEmanuele Giuseppe Esposito #include "libqos/pci.h"
1628edfce0SGonglei
17fb7e0b48SEmanuele Giuseppe Esposito typedef struct QOHCI_PCI QOHCI_PCI;
1828edfce0SGonglei
19fb7e0b48SEmanuele Giuseppe Esposito struct QOHCI_PCI {
20fb7e0b48SEmanuele Giuseppe Esposito QOSGraphObject obj;
21fb7e0b48SEmanuele Giuseppe Esposito QPCIDevice dev;
22fb7e0b48SEmanuele Giuseppe Esposito };
2328edfce0SGonglei
test_ohci_hotplug(void * obj,void * data,QGuestAllocator * alloc)24fb7e0b48SEmanuele Giuseppe Esposito static void test_ohci_hotplug(void *obj, void *data, QGuestAllocator *alloc)
25b3937683SIgor Mammedov {
26e5758de4SThomas Huth usb_test_hotplug(global_qtest, "ohci", "1", NULL);
27b3937683SIgor Mammedov }
2828edfce0SGonglei
ohci_pci_get_driver(void * obj,const char * interface)29fb7e0b48SEmanuele Giuseppe Esposito static void *ohci_pci_get_driver(void *obj, const char *interface)
3028edfce0SGonglei {
31fb7e0b48SEmanuele Giuseppe Esposito QOHCI_PCI *ohci_pci = obj;
3228edfce0SGonglei
33fb7e0b48SEmanuele Giuseppe Esposito if (!g_strcmp0(interface, "pci-device")) {
34fb7e0b48SEmanuele Giuseppe Esposito return &ohci_pci->dev;
3528edfce0SGonglei }
36fb7e0b48SEmanuele Giuseppe Esposito
37fb7e0b48SEmanuele Giuseppe Esposito fprintf(stderr, "%s not present in pci-ohci\n", interface);
38fb7e0b48SEmanuele Giuseppe Esposito g_assert_not_reached();
39fb7e0b48SEmanuele Giuseppe Esposito }
40fb7e0b48SEmanuele Giuseppe Esposito
ohci_pci_create(void * pci_bus,QGuestAllocator * alloc,void * addr)41fb7e0b48SEmanuele Giuseppe Esposito static void *ohci_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
42fb7e0b48SEmanuele Giuseppe Esposito {
43fb7e0b48SEmanuele Giuseppe Esposito QOHCI_PCI *ohci_pci = g_new0(QOHCI_PCI, 1);
44fb7e0b48SEmanuele Giuseppe Esposito ohci_pci->obj.get_driver = ohci_pci_get_driver;
45fb7e0b48SEmanuele Giuseppe Esposito
46fb7e0b48SEmanuele Giuseppe Esposito return &ohci_pci->obj;
47fb7e0b48SEmanuele Giuseppe Esposito }
48fb7e0b48SEmanuele Giuseppe Esposito
ohci_pci_register_nodes(void)49fb7e0b48SEmanuele Giuseppe Esposito static void ohci_pci_register_nodes(void)
50fb7e0b48SEmanuele Giuseppe Esposito {
51fb7e0b48SEmanuele Giuseppe Esposito QOSGraphEdgeOptions opts = {
52fb7e0b48SEmanuele Giuseppe Esposito .extra_device_opts = "addr=04.0,id=ohci",
53fb7e0b48SEmanuele Giuseppe Esposito };
54fb7e0b48SEmanuele Giuseppe Esposito add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
55fb7e0b48SEmanuele Giuseppe Esposito
56fb7e0b48SEmanuele Giuseppe Esposito qos_node_create_driver("pci-ohci", ohci_pci_create);
57fb7e0b48SEmanuele Giuseppe Esposito qos_node_consumes("pci-ohci", "pci-bus", &opts);
58fb7e0b48SEmanuele Giuseppe Esposito qos_node_produces("pci-ohci", "pci-device");
59fb7e0b48SEmanuele Giuseppe Esposito }
60fb7e0b48SEmanuele Giuseppe Esposito
61fb7e0b48SEmanuele Giuseppe Esposito libqos_init(ohci_pci_register_nodes);
62fb7e0b48SEmanuele Giuseppe Esposito
register_ohci_pci_test(void)63fb7e0b48SEmanuele Giuseppe Esposito static void register_ohci_pci_test(void)
64fb7e0b48SEmanuele Giuseppe Esposito {
65fb7e0b48SEmanuele Giuseppe Esposito qos_add_test("ohci_pci-test-hotplug", "pci-ohci", test_ohci_hotplug, NULL);
66fb7e0b48SEmanuele Giuseppe Esposito }
67fb7e0b48SEmanuele Giuseppe Esposito
68fb7e0b48SEmanuele Giuseppe Esposito libqos_init(register_ohci_pci_test);
69