1*1e8a1faeSThomas Huth /*
2*1e8a1faeSThomas Huth * QTest testcase for USB OHCI controller
3*1e8a1faeSThomas Huth *
4*1e8a1faeSThomas Huth * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
5*1e8a1faeSThomas Huth *
6*1e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later.
7*1e8a1faeSThomas Huth * See the COPYING file in the top-level directory.
8*1e8a1faeSThomas Huth */
9*1e8a1faeSThomas Huth
10*1e8a1faeSThomas Huth #include "qemu/osdep.h"
11*1e8a1faeSThomas Huth #include "libqtest-single.h"
12*1e8a1faeSThomas Huth #include "qemu/module.h"
13*1e8a1faeSThomas Huth #include "libqos/usb.h"
14*1e8a1faeSThomas Huth #include "libqos/qgraph.h"
15*1e8a1faeSThomas Huth #include "libqos/pci.h"
16*1e8a1faeSThomas Huth
17*1e8a1faeSThomas Huth typedef struct QOHCI_PCI QOHCI_PCI;
18*1e8a1faeSThomas Huth
19*1e8a1faeSThomas Huth struct QOHCI_PCI {
20*1e8a1faeSThomas Huth QOSGraphObject obj;
21*1e8a1faeSThomas Huth QPCIDevice dev;
22*1e8a1faeSThomas Huth };
23*1e8a1faeSThomas Huth
test_ohci_hotplug(void * obj,void * data,QGuestAllocator * alloc)24*1e8a1faeSThomas Huth static void test_ohci_hotplug(void *obj, void *data, QGuestAllocator *alloc)
25*1e8a1faeSThomas Huth {
26*1e8a1faeSThomas Huth usb_test_hotplug(global_qtest, "ohci", "1", NULL);
27*1e8a1faeSThomas Huth }
28*1e8a1faeSThomas Huth
ohci_pci_get_driver(void * obj,const char * interface)29*1e8a1faeSThomas Huth static void *ohci_pci_get_driver(void *obj, const char *interface)
30*1e8a1faeSThomas Huth {
31*1e8a1faeSThomas Huth QOHCI_PCI *ohci_pci = obj;
32*1e8a1faeSThomas Huth
33*1e8a1faeSThomas Huth if (!g_strcmp0(interface, "pci-device")) {
34*1e8a1faeSThomas Huth return &ohci_pci->dev;
35*1e8a1faeSThomas Huth }
36*1e8a1faeSThomas Huth
37*1e8a1faeSThomas Huth fprintf(stderr, "%s not present in pci-ohci\n", interface);
38*1e8a1faeSThomas Huth g_assert_not_reached();
39*1e8a1faeSThomas Huth }
40*1e8a1faeSThomas Huth
ohci_pci_create(void * pci_bus,QGuestAllocator * alloc,void * addr)41*1e8a1faeSThomas Huth static void *ohci_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
42*1e8a1faeSThomas Huth {
43*1e8a1faeSThomas Huth QOHCI_PCI *ohci_pci = g_new0(QOHCI_PCI, 1);
44*1e8a1faeSThomas Huth ohci_pci->obj.get_driver = ohci_pci_get_driver;
45*1e8a1faeSThomas Huth
46*1e8a1faeSThomas Huth return &ohci_pci->obj;
47*1e8a1faeSThomas Huth }
48*1e8a1faeSThomas Huth
ohci_pci_register_nodes(void)49*1e8a1faeSThomas Huth static void ohci_pci_register_nodes(void)
50*1e8a1faeSThomas Huth {
51*1e8a1faeSThomas Huth QOSGraphEdgeOptions opts = {
52*1e8a1faeSThomas Huth .extra_device_opts = "addr=04.0,id=ohci",
53*1e8a1faeSThomas Huth };
54*1e8a1faeSThomas Huth add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
55*1e8a1faeSThomas Huth
56*1e8a1faeSThomas Huth qos_node_create_driver("pci-ohci", ohci_pci_create);
57*1e8a1faeSThomas Huth qos_node_consumes("pci-ohci", "pci-bus", &opts);
58*1e8a1faeSThomas Huth qos_node_produces("pci-ohci", "pci-device");
59*1e8a1faeSThomas Huth }
60*1e8a1faeSThomas Huth
61*1e8a1faeSThomas Huth libqos_init(ohci_pci_register_nodes);
62*1e8a1faeSThomas Huth
register_ohci_pci_test(void)63*1e8a1faeSThomas Huth static void register_ohci_pci_test(void)
64*1e8a1faeSThomas Huth {
65*1e8a1faeSThomas Huth qos_add_test("ohci_pci-test-hotplug", "pci-ohci", test_ohci_hotplug, NULL);
66*1e8a1faeSThomas Huth }
67*1e8a1faeSThomas Huth
68*1e8a1faeSThomas Huth libqos_init(register_ohci_pci_test);
69