vnc: Wrap vnc initialization code with CONFIG_VNC
[qemu/ar7.git] / tests / usb-hcd-ehci-test.c
blobeb247ad453ea567b399e4fa02ca83db04ae076d3
1 /*
2 * QTest testcase for USB EHCI
4 * Copyright (c) 2014 SUSE LINUX Products GmbH
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 */
10 #include "qemu/osdep.h"
11 #include "libqtest.h"
12 #include "libqos/pci-pc.h"
13 #include "hw/usb/uhci-regs.h"
14 #include "hw/usb/ehci-regs.h"
15 #include "libqos/usb.h"
17 static QPCIBus *pcibus;
18 static struct qhc uhci1;
19 static struct qhc uhci2;
20 static struct qhc uhci3;
21 static struct qhc ehci1;
23 /* helpers */
25 #if 0
26 static void uhci_port_update(struct qhc *hc, int port,
27 uint16_t set, uint16_t clear)
29 void *addr = hc->base + 0x10 + 2 * port;
30 uint16_t value;
32 value = qpci_io_readw(hc->dev, addr);
33 value |= set;
34 value &= ~clear;
35 qpci_io_writew(hc->dev, addr, value);
37 #endif
39 static void ehci_port_test(struct qhc *hc, int port, uint32_t expect)
41 void *addr = hc->base + 0x64 + 4 * port;
42 uint32_t value = qpci_io_readl(hc->dev, addr);
43 uint16_t mask = ~(PORTSC_CSC | PORTSC_PEDC | PORTSC_OCC);
45 #if 0
46 fprintf(stderr, "%s: %d, have 0x%08x, want 0x%08x\n",
47 __func__, port, value & mask, expect & mask);
48 #endif
49 g_assert((value & mask) == (expect & mask));
52 /* tests */
54 static void pci_init(void)
56 if (pcibus) {
57 return;
59 pcibus = qpci_init_pc();
60 g_assert(pcibus != NULL);
62 qusb_pci_init_one(pcibus, &uhci1, QPCI_DEVFN(0x1d, 0), 4);
63 qusb_pci_init_one(pcibus, &uhci2, QPCI_DEVFN(0x1d, 1), 4);
64 qusb_pci_init_one(pcibus, &uhci3, QPCI_DEVFN(0x1d, 2), 4);
65 qusb_pci_init_one(pcibus, &ehci1, QPCI_DEVFN(0x1d, 7), 0);
68 static void pci_uhci_port_1(void)
70 g_assert(pcibus != NULL);
72 uhci_port_test(&uhci1, 0, UHCI_PORT_CCS); /* usb-tablet */
73 uhci_port_test(&uhci1, 1, UHCI_PORT_CCS); /* usb-storage */
74 uhci_port_test(&uhci2, 0, 0);
75 uhci_port_test(&uhci2, 1, 0);
76 uhci_port_test(&uhci3, 0, 0);
77 uhci_port_test(&uhci3, 1, 0);
80 static void pci_ehci_port_1(void)
82 int i;
84 g_assert(pcibus != NULL);
86 for (i = 0; i < 6; i++) {
87 ehci_port_test(&ehci1, i, PORTSC_POWNER | PORTSC_PPOWER);
91 static void pci_ehci_config(void)
93 /* hands over all ports from companion uhci to ehci */
94 qpci_io_writew(ehci1.dev, ehci1.base + 0x60, 1);
97 static void pci_uhci_port_2(void)
99 g_assert(pcibus != NULL);
101 uhci_port_test(&uhci1, 0, 0); /* usb-tablet, @ehci */
102 uhci_port_test(&uhci1, 1, 0); /* usb-storage, @ehci */
103 uhci_port_test(&uhci2, 0, 0);
104 uhci_port_test(&uhci2, 1, 0);
105 uhci_port_test(&uhci3, 0, 0);
106 uhci_port_test(&uhci3, 1, 0);
109 static void pci_ehci_port_2(void)
111 static uint32_t expect[] = {
112 PORTSC_PPOWER | PORTSC_CONNECT, /* usb-tablet */
113 PORTSC_PPOWER | PORTSC_CONNECT, /* usb-storage */
114 PORTSC_PPOWER,
115 PORTSC_PPOWER,
116 PORTSC_PPOWER,
117 PORTSC_PPOWER,
119 int i;
121 g_assert(pcibus != NULL);
123 for (i = 0; i < 6; i++) {
124 ehci_port_test(&ehci1, i, expect[i]);
128 static void pci_ehci_port_3_hotplug(void)
130 /* check for presence of hotplugged usb-tablet */
131 g_assert(pcibus != NULL);
132 ehci_port_test(&ehci1, 2, PORTSC_PPOWER | PORTSC_CONNECT);
135 static void pci_ehci_port_hotplug(void)
137 usb_test_hotplug("ich9-ehci-1", 3, pci_ehci_port_3_hotplug);
141 int main(int argc, char **argv)
143 int ret;
145 g_test_init(&argc, &argv, NULL);
146 qtest_add_func("/ehci/pci/init", pci_init);
147 qtest_add_func("/ehci/pci/uhci-port-1", pci_uhci_port_1);
148 qtest_add_func("/ehci/pci/ehci-port-1", pci_ehci_port_1);
149 qtest_add_func("/ehci/pci/ehci-config", pci_ehci_config);
150 qtest_add_func("/ehci/pci/uhci-port-2", pci_uhci_port_2);
151 qtest_add_func("/ehci/pci/ehci-port-2", pci_ehci_port_2);
152 qtest_add_func("/ehci/pci/ehci-port-3-hotplug", pci_ehci_port_hotplug);
154 qtest_start("-machine q35 -device ich9-usb-ehci1,bus=pcie.0,addr=1d.7,"
155 "multifunction=on,id=ich9-ehci-1 "
156 "-device ich9-usb-uhci1,bus=pcie.0,addr=1d.0,"
157 "multifunction=on,masterbus=ich9-ehci-1.0,firstport=0 "
158 "-device ich9-usb-uhci2,bus=pcie.0,addr=1d.1,"
159 "multifunction=on,masterbus=ich9-ehci-1.0,firstport=2 "
160 "-device ich9-usb-uhci3,bus=pcie.0,addr=1d.2,"
161 "multifunction=on,masterbus=ich9-ehci-1.0,firstport=4 "
162 "-drive if=none,id=usbcdrom,media=cdrom "
163 "-device usb-tablet,bus=ich9-ehci-1.0,port=1,usb_version=1 "
164 "-device usb-storage,bus=ich9-ehci-1.0,port=2,drive=usbcdrom ");
165 ret = g_test_run();
167 qtest_end();
169 return ret;