]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qtest/libqos/usb.c
meson: convert tests/qtest to meson
[mirror_qemu.git] / tests / qtest / libqos / usb.c
CommitLineData
b0354ec5
IM
1/*
2 * common code shared by usb tests
3 *
4 * Copyright (c) 2014 Red Hat, Inc
5 *
6 * Authors:
7 * Gerd Hoffmann <kraxel@redhat.com>
8 * John Snow <jsnow@redhat.com>
9 * Igor Mammedov <imammedo@redhat.com>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
13 */
681c28a3 14#include "qemu/osdep.h"
b0354ec5 15#include "libqtest.h"
b0354ec5 16#include "hw/usb/uhci-regs.h"
a2ce7dbd 17#include "usb.h"
b0354ec5
IM
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);
b4ba67d9 24 hc->bar = qpci_iomap(hc->dev, bar, NULL);
b0354ec5
IM
25}
26
62030ed1
MAL
27void uhci_deinit(struct qhc *hc)
28{
29 g_free(hc->dev);
30}
31
b0354ec5
IM
32void uhci_port_test(struct qhc *hc, int port, uint16_t expect)
33{
b4ba67d9 34 uint16_t value = qpci_io_readw(hc->dev, hc->bar, 0x10 + 2 * port);
b0354ec5
IM
35 uint16_t mask = ~(UHCI_PORT_WRITE_CLEAR | UHCI_PORT_RSVD1);
36
37 g_assert((value & mask) == (expect & mask));
38}
b3937683 39
e5758de4 40void usb_test_hotplug(QTestState *qts, const char *hcd_id, const char *port,
b3937683
IM
41 void (*port_check)(void))
42{
82cab70b
MA
43 char *id = g_strdup_printf("usbdev%s", port);
44 char *bus = g_strdup_printf("%s.0", hcd_id);
b3937683 45
e5758de4 46 qtest_qmp_device_add(qts, "usb-tablet", id, "{'port': %s, 'bus': %s}",
82cab70b 47 port, bus);
b3937683
IM
48
49 if (port_check) {
50 port_check();
51 }
52
e5758de4 53 qtest_qmp_device_del(qts, id);
acd80015 54
82cab70b 55 g_free(bus);
acd80015 56 g_free(id);
b3937683 57}