From 830cd54fca126f5dab9b34b48a61304f2401e982 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 15 Aug 2014 13:32:36 +0200 Subject: [PATCH 01/17] usb: Fix bootindex for portnr > 9 We identify devices by their Open Firmware device paths. The encoding of the host controller and hub port numbers is incorrect: usb_get_fw_dev_path() formats them in decimal, while SeaBIOS uses hexadecimal. When some port number > 9, SeaBIOS will miss the bootindex (lucky case), or apply it to another device (unlucky case). The relevant spec[*] agrees with SeaBIOS (and OVMF, for that matter). Change %d to %x. Bug can bite only with host controllers or hubs sporting more than ten ports. I'm not aware of any. [*] Open Firmware Recommended Practice: Universal Serial Bus, Version 1, Section 3.2.1 Device Node Address Representation http://www.openfirmware.org/1275/bindings/usb/usb-1_0.ps Signed-off-by: Markus Armbruster Reviewed-by: Laszlo Ersek Note: xhci can be configured with up to 15 ports (default is 4 ports). Signed-off-by: Gerd Hoffmann --- hw/usb/bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 927a47bbff..516fb52993 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -589,11 +589,11 @@ static char *usb_get_fw_dev_path(DeviceState *qdev) nr = strtol(in, &in, 10); if (in[0] == '.') { /* some hub between root port and device */ - pos += snprintf(fw_path + pos, fw_len - pos, "hub@%ld/", nr); + pos += snprintf(fw_path + pos, fw_len - pos, "hub@%lx/", nr); in++; } else { /* the device itself */ - pos += snprintf(fw_path + pos, fw_len - pos, "%s@%ld", + pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx", qdev_fw_name(qdev), nr); break; } From 8c244210d842b71e838c8fc5219b6ab3e4063d71 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Thu, 21 Aug 2014 20:48:58 +0800 Subject: [PATCH 02/17] xhci: fix debug print compiling error after commit 003e15a180373048f0c1f4df0bfe303746eb2676 the DPRINTF will broke compiling, adjust its location. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 58c4b11527..aed8e9f18d 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1380,14 +1380,11 @@ static void xhci_init_epctx(XHCIEPContext *epctx, dequeue = xhci_addr64(ctx[2] & ~0xf, ctx[3]); epctx->type = (ctx[1] >> EP_TYPE_SHIFT) & EP_TYPE_MASK; - DPRINTF("xhci: endpoint %d.%d type is %d\n", epid/2, epid%2, epctx->type); epctx->pctx = pctx; epctx->max_psize = ctx[1]>>16; epctx->max_psize *= 1+((ctx[1]>>8)&0xff); epctx->max_pstreams = (ctx[0] >> 10) & 0xf; epctx->lsa = (ctx[0] >> 15) & 1; - DPRINTF("xhci: endpoint %d.%d max transaction (burst) size is %d\n", - epid/2, epid%2, epctx->max_psize); if (epctx->max_pstreams) { xhci_alloc_streams(epctx, dequeue); } else { @@ -1418,6 +1415,9 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid, slot->eps[epid-1] = epctx; xhci_init_epctx(epctx, pctx, ctx); + DPRINTF("xhci: endpoint %d.%d type is %d, max transaction (burst) " + "size is %d\n", epid/2, epid%2, epctx->type, epctx->max_psize); + epctx->mfindex_last = 0; epctx->state = EP_RUNNING; From cae7f29c47dee0bd0474fa7f1dda28b115a34d33 Mon Sep 17 00:00:00 2001 From: Jack Un Date: Sat, 9 Aug 2014 23:34:36 +0300 Subject: [PATCH 03/17] Fix OHCI ISO TD state never being written back. There appears to be typo in OHCI with isochronous transfers resulting in isoch. transfer descriptor state never being written back. The'put_words' function is in a OR statement hence it is never called. Signed-off-by: Jack Un Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ohci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 13afdf5919..cacf7b054c 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -619,8 +619,8 @@ static inline int ohci_put_td(OHCIState *ohci, static inline int ohci_put_iso_td(OHCIState *ohci, dma_addr_t addr, struct ohci_iso_td *td) { - return put_dwords(ohci, addr, (uint32_t *)td, 4 || - put_words(ohci, addr + 16, td->offset, 8)); + return put_dwords(ohci, addr, (uint32_t *)td, 4) || + put_words(ohci, addr + 16, td->offset, 8); } static inline int ohci_put_hcca(OHCIState *ohci, From 3d80365b5558eb1b0a8374362c41570c37a4aba9 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 28 Aug 2014 10:51:35 +0200 Subject: [PATCH 04/17] xhci: use (1u << i) Signed-off-by: Gerd Hoffmann Reviewed-by: Peter Maydell --- hw/usb/hcd-xhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index aed8e9f18d..f7f9fed737 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1180,7 +1180,7 @@ static int xhci_epmask_to_eps_with_streams(XHCIState *xhci, slot = &xhci->slots[slotid - 1]; for (i = 2, j = 0; i <= 31; i++) { - if (!(epmask & (1 << i))) { + if (!(epmask & (1u << i))) { continue; } @@ -2465,7 +2465,7 @@ static TRBCCode xhci_configure_slot(XHCIState *xhci, unsigned int slotid, res = xhci_alloc_device_streams(xhci, slotid, ictl_ctx[1]); if (res != CC_SUCCESS) { for (i = 2; i <= 31; i++) { - if (ictl_ctx[1] & (1 << i)) { + if (ictl_ctx[1] & (1u << i)) { xhci_disable_ep(xhci, slotid, i); } } From f90e160b502fb5c464eb9417ac075a78f13e9801 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 29 Aug 2014 12:40:55 +0200 Subject: [PATCH 05/17] Revert "xhci: Fix number of streams allocated when using streams" This reverts commit d063c3112c4cd23a479ee18720c2bd119da2d315. "2 << x" is the same as "2 ^ (x + 1)", so the old code is correct. Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index f7f9fed737..88660e85b7 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1151,7 +1151,7 @@ static void xhci_reset_streams(XHCIEPContext *epctx) static void xhci_alloc_streams(XHCIEPContext *epctx, dma_addr_t base) { assert(epctx->pstreams == NULL); - epctx->nr_pstreams = 2 << (epctx->max_pstreams + 1); + epctx->nr_pstreams = 2 << epctx->max_pstreams; epctx->pstreams = xhci_alloc_stream_contexts(epctx->nr_pstreams, base); } From e5a9bece9b5064d0cb0fda68ff68b9361085f400 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:46 +0800 Subject: [PATCH 06/17] usb: add usb_bus_release function add global variables releasing logic when the usb buses were removed or hot-unpluged. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/bus.c | 7 +++++++ include/hw/usb.h | 1 + 2 files changed, 8 insertions(+) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 516fb52993..c7c4dadedd 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -87,6 +87,13 @@ void usb_bus_new(USBBus *bus, size_t bus_size, QTAILQ_INSERT_TAIL(&busses, bus, next); } +void usb_bus_release(USBBus *bus) +{ + assert(next_usb_bus > 0); + + QTAILQ_REMOVE(&busses, bus, next); +} + USBBus *usb_bus_find(int busnr) { USBBus *bus; diff --git a/include/hw/usb.h b/include/hw/usb.h index 223a5aef8f..6b32a3bb70 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -529,6 +529,7 @@ struct USBBusOps { void usb_bus_new(USBBus *bus, size_t bus_size, USBBusOps *ops, DeviceState *host); +void usb_bus_release(USBBus *bus); USBBus *usb_bus_find(int busnr); void usb_legacy_register(const char *typename, const char *usbdevice_name, USBDevice *(*usbdevice_init)(USBBus *bus, From 80be63df5a19816629343f704345b71e83e6d960 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:47 +0800 Subject: [PATCH 07/17] usb-ohci: Fix memory leak for ohci timer Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ohci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index cacf7b054c..5505f0ac53 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1371,8 +1371,10 @@ static int ohci_bus_start(OHCIState *ohci) /* Stop sending SOF tokens on the bus */ static void ohci_bus_stop(OHCIState *ohci) { - if (ohci->eof_timer) + if (ohci->eof_timer) { timer_del(ohci->eof_timer); + timer_free(ohci->eof_timer); + } ohci->eof_timer = NULL; } From 07832c38d3c359f909609c4ab68ccc0d3282d7ee Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:48 +0800 Subject: [PATCH 08/17] usb-ohci: add exit function clean up ohci resource when ohci pci device exit. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ohci.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 5505f0ac53..83bec34185 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1954,6 +1954,24 @@ static int usb_ohci_initfn_pci(PCIDevice *dev) return 0; } +static void usb_ohci_exit(PCIDevice *dev) +{ + OHCIPCIState *ohci = PCI_OHCI(dev); + OHCIState *s = &ohci->state; + + ohci_bus_stop(s); + + if (s->async_td) { + usb_cancel_packet(&s->usb_packet); + s->async_td = 0; + } + ohci_stop_endpoints(s); + + if (!ohci->masterbus) { + usb_bus_release(&s->bus); + } +} + #define TYPE_SYSBUS_OHCI "sysbus-ohci" #define SYSBUS_OHCI(obj) OBJECT_CHECK(OHCISysBusState, (obj), TYPE_SYSBUS_OHCI) @@ -2091,6 +2109,7 @@ static void ohci_pci_class_init(ObjectClass *klass, void *data) PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->init = usb_ohci_initfn_pci; + k->exit = usb_ohci_exit; k->vendor_id = PCI_VENDOR_ID_APPLE; k->device_id = PCI_DEVICE_ID_APPLE_IPID_USB; k->class_id = PCI_CLASS_SERIAL_USB; From 3a3464b000776c21d0b650036cbdfdc45e9eb172 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:49 +0800 Subject: [PATCH 09/17] usb-uhci: clean up uhci resource when pci-uhci exit clean up uhci resource when uhci pci device exit. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-uhci.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index ee5f112d65..220115bc5a 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -1256,6 +1256,27 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev) return usb_uhci_common_initfn(dev); } +static void usb_uhci_exit(PCIDevice *dev) +{ + UHCIState *s = DO_UPCAST(UHCIState, dev, dev); + + if (s->frame_timer) { + timer_del(s->frame_timer); + timer_free(s->frame_timer); + s->frame_timer = NULL; + } + + if (s->bh) { + qemu_bh_delete(s->bh); + } + + uhci_async_cancel_all(s); + + if (!s->masterbus) { + usb_bus_release(&s->bus); + } +} + static Property uhci_properties[] = { DEFINE_PROP_STRING("masterbus", UHCIState, masterbus), DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0), @@ -1272,6 +1293,7 @@ static void uhci_class_init(ObjectClass *klass, void *data) UHCIInfo *info = data; k->init = info->initfn ? info->initfn : usb_uhci_common_initfn; + k->exit = info->unplug ? usb_uhci_exit : NULL; k->vendor_id = info->vendor_id; k->device_id = info->device_id; k->revision = info->revision; From 05a36991c54e32a95d096337fa008938340878d3 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:50 +0800 Subject: [PATCH 10/17] usb-ehci: add vmstate properity for EHCIState since hotunplug the ehci host adapter, we should delete vm_change_state_handler also, so the VMChangeStateEntry should be saved in EHCIState. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci.c | 2 +- hw/usb/hcd-ehci.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 448e0073dd..ef26f36d33 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -2468,7 +2468,7 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp) s->device = dev; qemu_register_reset(ehci_reset, s); - qemu_add_vm_change_state_handler(usb_ehci_vm_state_change, s); + s->vmstate = qemu_add_vm_change_state_handler(usb_ehci_vm_state_change, s); } void usb_ehci_init(EHCIState *s, DeviceState *dev) diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h index 1ad4b96cce..594d9d30e9 100644 --- a/hw/usb/hcd-ehci.h +++ b/hw/usb/hcd-ehci.h @@ -316,6 +316,7 @@ struct EHCIState { uint32_t async_stepdown; uint32_t periodic_sched_active; bool int_req_by_async; + VMChangeStateEntry *vmstate; }; extern const VMStateDescription vmstate_ehci; From 4e130cf6a83193218e357e6db49a7ade24ab9675 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:51 +0800 Subject: [PATCH 11/17] usb-ehci: add ehci unrealize funciton cleanup ehci controller resource, both pci and sysbus if they're necessary. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci.c | 25 +++++++++++++++++++++++++ hw/usb/hcd-ehci.h | 1 + 2 files changed, 26 insertions(+) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index ef26f36d33..2aa06bb18b 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -2471,6 +2471,31 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp) s->vmstate = qemu_add_vm_change_state_handler(usb_ehci_vm_state_change, s); } +void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp) +{ + if (s->frame_timer) { + timer_del(s->frame_timer); + timer_free(s->frame_timer); + s->frame_timer = NULL; + } + if (s->async_bh) { + qemu_bh_delete(s->async_bh); + } + + ehci_queues_rip_all(s, 0); + ehci_queues_rip_all(s, 1); + + memory_region_del_subregion(&s->mem, &s->mem_caps); + memory_region_del_subregion(&s->mem, &s->mem_opreg); + memory_region_del_subregion(&s->mem, &s->mem_ports); + + usb_bus_release(&s->bus); + + if (s->vmstate) { + qemu_del_vm_change_state_handler(s->vmstate); + } +} + void usb_ehci_init(EHCIState *s, DeviceState *dev) { /* 2.2 host controller interface version */ diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h index 594d9d30e9..4858b7e80c 100644 --- a/hw/usb/hcd-ehci.h +++ b/hw/usb/hcd-ehci.h @@ -323,6 +323,7 @@ extern const VMStateDescription vmstate_ehci; void usb_ehci_init(EHCIState *s, DeviceState *dev); void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp); +void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp); #define TYPE_PCI_EHCI "pci-ehci-usb" #define PCI_EHCI(obj) OBJECT_CHECK(EHCIPCIState, (obj), TYPE_PCI_EHCI) From 96e14926c66dc7da99bea80d639a30cce0772991 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:52 +0800 Subject: [PATCH 12/17] usb-ehci: add ehci-pci device exit function clean up ehci resource when ehci pci device exit. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci-pci.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c index 505741a783..289ca3b853 100644 --- a/hw/usb/hcd-ehci-pci.c +++ b/hw/usb/hcd-ehci-pci.c @@ -84,6 +84,19 @@ static void usb_ehci_pci_init(Object *obj) usb_ehci_init(s, DEVICE(obj)); } +static void usb_ehci_pci_exit(PCIDevice *dev) +{ + EHCIPCIState *i = PCI_EHCI(dev); + EHCIState *s = &i->ehci; + + usb_ehci_unrealize(s, DEVICE(dev), NULL); + + if (s->irq) { + g_free(s->irq); + s->irq = NULL; + } +} + static void usb_ehci_pci_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int l) { @@ -121,6 +134,7 @@ static void ehci_class_init(ObjectClass *klass, void *data) PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->init = usb_ehci_pci_initfn; + k->exit = usb_ehci_pci_exit; k->class_id = PCI_CLASS_SERIAL_USB; k->config_write = usb_ehci_pci_write_config; dc->hotpluggable = false; From 53c30545fb34c43c84d62ea1c2b0dc6b53303c34 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:53 +0800 Subject: [PATCH 13/17] usb-xhci: add exit function clean up xhci resource when xhci pci device exit. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 88660e85b7..a9245d8c2a 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3644,6 +3644,41 @@ static int usb_xhci_initfn(struct PCIDevice *dev) return 0; } +static void usb_xhci_exit(PCIDevice *dev) +{ + int i; + XHCIState *xhci = XHCI(dev); + + for (i = 0; i < xhci->numslots; i++) { + xhci_disable_slot(xhci, i + 1); + } + + if (xhci->mfwrap_timer) { + timer_del(xhci->mfwrap_timer); + timer_free(xhci->mfwrap_timer); + xhci->mfwrap_timer = NULL; + } + + memory_region_del_subregion(&xhci->mem, &xhci->mem_cap); + memory_region_del_subregion(&xhci->mem, &xhci->mem_oper); + memory_region_del_subregion(&xhci->mem, &xhci->mem_runtime); + memory_region_del_subregion(&xhci->mem, &xhci->mem_doorbell); + + for (i = 0; i < xhci->numports; i++) { + XHCIPort *port = &xhci->ports[i]; + memory_region_del_subregion(&xhci->mem, &port->mem); + } + + /* destroy msix memory region */ + if (dev->msix_table && dev->msix_pba + && dev->msix_entry_used) { + memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio); + memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio); + } + + usb_bus_release(&xhci->bus); +} + static int usb_xhci_post_load(void *opaque, int version_id) { XHCIState *xhci = opaque; @@ -3836,6 +3871,7 @@ static void xhci_class_init(ObjectClass *klass, void *data) dc->hotpluggable = false; set_bit(DEVICE_CATEGORY_USB, dc->categories); k->init = usb_xhci_initfn; + k->exit = usb_xhci_exit; k->vendor_id = PCI_VENDOR_ID_NEC; k->device_id = PCI_DEVICE_ID_NEC_UPD720200; k->class_id = PCI_CLASS_SERIAL_USB; From d733f74c333184179770e4d5017366da4b449cce Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 4 Jun 2014 16:31:55 +0800 Subject: [PATCH 14/17] usb: add usb host adapters exit trace Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci.c | 2 ++ hw/usb/hcd-uhci.c | 2 ++ hw/usb/hcd-xhci.c | 2 ++ trace-events | 3 +++ 4 files changed, 9 insertions(+) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 2aa06bb18b..bacb7ceac9 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -2473,6 +2473,8 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp) void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp) { + trace_usb_ehci_unrealize(); + if (s->frame_timer) { timer_del(s->frame_timer); timer_free(s->frame_timer); diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index 220115bc5a..3b3ebcda8b 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -1260,6 +1260,8 @@ static void usb_uhci_exit(PCIDevice *dev) { UHCIState *s = DO_UPCAST(UHCIState, dev, dev); + trace_usb_uhci_exit(); + if (s->frame_timer) { timer_del(s->frame_timer); timer_free(s->frame_timer); diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index a9245d8c2a..bbe4c5fb85 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3649,6 +3649,8 @@ static void usb_xhci_exit(PCIDevice *dev) int i; XHCIState *xhci = XHCI(dev); + trace_usb_xhci_exit(); + for (i = 0; i < xhci->numslots; i++) { xhci_disable_slot(xhci, i + 1); } diff --git a/trace-events b/trace-events index 81bc915edd..03ac5d205c 100644 --- a/trace-events +++ b/trace-events @@ -297,6 +297,7 @@ usb_port_release(int bus, const char *port) "bus %d, port %s" # hw/usb/hcd-ehci.c usb_ehci_reset(void) "=== RESET ===" +usb_ehci_unrealize(void) "=== UNREALIZE ===" usb_ehci_opreg_read(uint32_t addr, const char *str, uint32_t val) "rd mmio %04x [%s] = %x" usb_ehci_opreg_write(uint32_t addr, const char *str, uint32_t val) "wr mmio %04x [%s] = %x" usb_ehci_opreg_change(uint32_t addr, const char *str, uint32_t new, uint32_t old) "ch mmio %04x [%s] = %x (old: %x)" @@ -329,6 +330,7 @@ usb_ehci_dma_error(void) "" # hw/usb/hcd-uhci.c usb_uhci_reset(void) "=== RESET ===" +usb_uhci_exit(void) "=== EXIT ===" usb_uhci_schedule_start(void) "" usb_uhci_schedule_stop(void) "" usb_uhci_frame_start(uint32_t num) "nr %d" @@ -358,6 +360,7 @@ usb_uhci_td_complete(uint32_t qh, uint32_t td) "qh 0x%x, td 0x%x" # hw/usb/hcd-xhci.c usb_xhci_reset(void) "=== RESET ===" +usb_xhci_exit(void) "=== EXIT ===" usb_xhci_run(void) "" usb_xhci_stop(void) "" usb_xhci_cap_read(uint32_t off, uint32_t val) "off 0x%04x, ret 0x%08x" From 28edfce0f3e8536b30573343618635f8713d6326 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Mon, 23 Jun 2014 19:53:51 +0800 Subject: [PATCH 15/17] tests: add OHCI qtest Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- MAINTAINERS | 2 +- tests/Makefile | 3 +++ tests/usb-hcd-ohci-test.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/usb-hcd-ohci-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 59940f97ad..a74c04c2a9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -614,7 +614,7 @@ USB M: Gerd Hoffmann S: Maintained F: hw/usb/* -F: tests/usb-hcd-ehci-test.c +F: tests/usb-*-test.c VFIO M: Alex Williamson diff --git a/tests/Makefile b/tests/Makefile index 837e9c89e7..5d67a55610 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -155,6 +155,8 @@ check-qtest-i386-y += tests/i82801b11-test$(EXESUF) gcov-files-i386-y += hw/pci-bridge/i82801b11.c check-qtest-i386-y += tests/ioh3420-test$(EXESUF) gcov-files-i386-y += hw/pci-bridge/ioh3420.c +check-qtest-i386-y += tests/usb-hcd-ohci-test$(EXESUF) +gcov-files-i386-y += hw/usb/hcd-ohci.c check-qtest-i386-y += tests/usb-hcd-ehci-test$(EXESUF) gcov-files-i386-y += hw/usb/hcd-ehci.c gcov-files-i386-y += hw/usb/hcd-uhci.c @@ -335,6 +337,7 @@ tests/ac97-test$(EXESUF): tests/ac97-test.o tests/es1370-test$(EXESUF): tests/es1370-test.o tests/intel-hda-test$(EXESUF): tests/intel-hda-test.o tests/ioh3420-test$(EXESUF): tests/ioh3420-test.o +tests/usb-hcd-ohci-test$(EXESUF): tests/usb-hcd-ohci-test.o tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-pc-obj-y) tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o diff --git a/tests/usb-hcd-ohci-test.c b/tests/usb-hcd-ohci-test.c new file mode 100644 index 0000000000..fbc3ffeebd --- /dev/null +++ b/tests/usb-hcd-ohci-test.c @@ -0,0 +1,35 @@ +/* + * QTest testcase for USB OHCI controller + * + * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO.,LTD. + * + * 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" + + +static void test_ohci_init(void) +{ + qtest_start("-device pci-ohci,id=ohci"); + + qtest_end(); +} + + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/ohci/pci/init", test_ohci_init); + + ret = g_test_run(); + + return ret; +} From 44ced58e3adf1bb16cac9d5b7bb178f75405902f Mon Sep 17 00:00:00 2001 From: Gonglei Date: Mon, 23 Jun 2014 19:53:52 +0800 Subject: [PATCH 16/17] tests: add UHCI qtest Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- tests/Makefile | 4 +++- tests/usb-hcd-uhci-test.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/usb-hcd-uhci-test.c diff --git a/tests/Makefile b/tests/Makefile index 5d67a55610..6eff8cd3c9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -157,9 +157,10 @@ check-qtest-i386-y += tests/ioh3420-test$(EXESUF) gcov-files-i386-y += hw/pci-bridge/ioh3420.c check-qtest-i386-y += tests/usb-hcd-ohci-test$(EXESUF) gcov-files-i386-y += hw/usb/hcd-ohci.c +check-qtest-i386-y += tests/usb-hcd-uhci-test$(EXESUF) +gcov-files-i386-y += hw/usb/hcd-uhci.c check-qtest-i386-y += tests/usb-hcd-ehci-test$(EXESUF) gcov-files-i386-y += hw/usb/hcd-ehci.c -gcov-files-i386-y += hw/usb/hcd-uhci.c gcov-files-i386-y += hw/usb/dev-hid.c gcov-files-i386-y += hw/usb/dev-storage.c check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF) @@ -338,6 +339,7 @@ tests/es1370-test$(EXESUF): tests/es1370-test.o tests/intel-hda-test$(EXESUF): tests/intel-hda-test.o tests/ioh3420-test$(EXESUF): tests/ioh3420-test.o tests/usb-hcd-ohci-test$(EXESUF): tests/usb-hcd-ohci-test.o +tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-pc-obj-y) tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c new file mode 100644 index 0000000000..94e858f4c6 --- /dev/null +++ b/tests/usb-hcd-uhci-test.c @@ -0,0 +1,35 @@ +/* + * QTest testcase for USB UHCI controller + * + * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO.,LTD. + * + * 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" + + +static void test_uhci_init(void) +{ + qtest_start("-device piix3-usb-uhci,id=uhci"); + + qtest_end(); +} + + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/uhci/pci/init", test_uhci_init); + + ret = g_test_run(); + + return ret; +} From 25e89ec5d2c7f8d953cb1ca558afa74974ff8930 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Mon, 23 Jun 2014 19:53:53 +0800 Subject: [PATCH 17/17] tests: add xHCI qtest Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- tests/Makefile | 3 +++ tests/usb-hcd-xhci-test.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/usb-hcd-xhci-test.c diff --git a/tests/Makefile b/tests/Makefile index 6eff8cd3c9..469c0a5e44 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -163,6 +163,8 @@ check-qtest-i386-y += tests/usb-hcd-ehci-test$(EXESUF) gcov-files-i386-y += hw/usb/hcd-ehci.c gcov-files-i386-y += hw/usb/dev-hid.c gcov-files-i386-y += hw/usb/dev-storage.c +check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF) +gcov-files-i386-y += hw/usb/hcd-xhci.c check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c @@ -341,6 +343,7 @@ tests/ioh3420-test$(EXESUF): tests/ioh3420-test.o tests/usb-hcd-ohci-test$(EXESUF): tests/usb-hcd-ohci-test.o tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-pc-obj-y) +tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c new file mode 100644 index 0000000000..743e9798cd --- /dev/null +++ b/tests/usb-hcd-xhci-test.c @@ -0,0 +1,35 @@ +/* + * QTest testcase for USB xHCI controller + * + * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO.,LTD. + * + * 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" + + +static void test_xhci_init(void) +{ + qtest_start("-device nec-usb-xhci,id=xhci"); + + qtest_end(); +} + + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/xhci/pci/init", test_xhci_init); + + ret = g_test_run(); + + return ret; +}