From b0354ec59640a23c3be544d904400e38be8ff51d Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Fri, 26 Sep 2014 09:28:12 +0000 Subject: tests: usb: Move uhci port test code to libqos/usb.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move code necessary for testing uhci port into library so it could be used by other USB tests. Signed-off-by: Igor Mammedov Reviewed-by: Paolo Bonzini Signed-off-by: Andreas Färber --- tests/libqos/usb.c | 37 +++++++++++++++++++++++++++++++++++++ tests/libqos/usb.h | 14 ++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/libqos/usb.c create mode 100644 tests/libqos/usb.h (limited to 'tests/libqos') diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c new file mode 100644 index 0000000..54865b4 --- /dev/null +++ b/tests/libqos/usb.c @@ -0,0 +1,37 @@ +/* + * common code shared by usb tests + * + * Copyright (c) 2014 Red Hat, Inc + * + * Authors: + * Gerd Hoffmann + * John Snow + * Igor Mammedov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include +#include +#include "libqtest.h" +#include "qemu/osdep.h" +#include "hw/usb/uhci-regs.h" +#include "libqos/usb.h" + +void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, uint32_t devfn, int bar) +{ + hc->dev = qpci_device_find(pcibus, devfn); + g_assert(hc->dev != NULL); + qpci_device_enable(hc->dev); + hc->base = qpci_iomap(hc->dev, bar, NULL); + g_assert(hc->base != NULL); +} + +void uhci_port_test(struct qhc *hc, int port, uint16_t expect) +{ + void *addr = hc->base + 0x10 + 2 * port; + uint16_t value = qpci_io_readw(hc->dev, addr); + uint16_t mask = ~(UHCI_PORT_WRITE_CLEAR | UHCI_PORT_RSVD1); + + g_assert((value & mask) == (expect & mask)); +} diff --git a/tests/libqos/usb.h b/tests/libqos/usb.h new file mode 100644 index 0000000..7fcd669 --- /dev/null +++ b/tests/libqos/usb.h @@ -0,0 +1,14 @@ +#ifndef LIBQOS_USB_H +#define LIBQOS_USB_H + +#include "libqos/pci-pc.h" + +struct qhc { + QPCIDevice *dev; + void *base; +}; + +void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, + uint32_t devfn, int bar); +void uhci_port_test(struct qhc *hc, int port, uint16_t expect); +#endif -- cgit v1.1