1
2
3
4
5
6
7
8
9
10
11
12
13
14#include "qemu/osdep.h"
15#include "libqtest.h"
16#include "hw/usb/uhci-regs.h"
17#include "libqos/usb.h"
18
19void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, uint32_t devfn, int bar)
20{
21 hc->dev = qpci_device_find(pcibus, devfn);
22 g_assert(hc->dev != NULL);
23 qpci_device_enable(hc->dev);
24 hc->bar = qpci_iomap(hc->dev, bar, NULL);
25}
26
27void uhci_deinit(struct qhc *hc)
28{
29 g_free(hc->dev);
30}
31
32void uhci_port_test(struct qhc *hc, int port, uint16_t expect)
33{
34 uint16_t value = qpci_io_readw(hc->dev, hc->bar, 0x10 + 2 * port);
35 uint16_t mask = ~(UHCI_PORT_WRITE_CLEAR | UHCI_PORT_RSVD1);
36
37 g_assert((value & mask) == (expect & mask));
38}
39
40void usb_test_hotplug(const char *hcd_id, const int port,
41 void (*port_check)(void))
42{
43 char *id = g_strdup_printf("usbdev%d", port);
44
45 qtest_qmp_device_add("usb-tablet", id, "'port': '%d', 'bus': '%s.0'",
46 port, hcd_id);
47
48 if (port_check) {
49 port_check();
50 }
51
52 qtest_qmp_device_del(id);
53
54 g_free(id);
55}
56