* [Qemu-devel] [PATCH 1/5] xhci: Init a transfers xhci, slotid and epid member on epctx alloc
@ 2013-09-17 19:44 Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 2/5] xhci: Add xhci_epid_to_usbep helper function Hans de Goede
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Hans de Goede @ 2013-09-17 19:44 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Hans de Goede, qemu-devel
Transfers are part of an epctx, which is part of a slot, which is part of
a xhci. Transfers cannot dynamically be moved from one epctx to another,
so once created their xhci, slotid and epid are constant, so lets set these
up at creation time, rather then re-initializing them with the same
value each time a transfer gets submitted.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
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 6e73ced..120b038 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -1229,6 +1229,9 @@ static XHCIEPContext *xhci_alloc_epctx(XHCIState *xhci,
epctx->epid = epid;
for (i = 0; i < ARRAY_SIZE(epctx->transfers); i++) {
+ epctx->transfers[i].xhci = xhci;
+ epctx->transfers[i].slotid = slotid;
+ epctx->transfers[i].epid = epid;
usb_packet_init(&epctx->transfers[i].packet);
}
epctx->kick_timer = qemu_new_timer_ns(vm_clock, xhci_ep_kick_timer, epctx);
@@ -2044,9 +2047,6 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
for (i = 0; i < length; i++) {
assert(xhci_ring_fetch(xhci, ring, &xfer->trbs[i], NULL));
}
- xfer->xhci = xhci;
- xfer->epid = epid;
- xfer->slotid = slotid;
xfer->streamid = streamid;
if (epid == 1) {
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/5] xhci: Add xhci_epid_to_usbep helper function
2013-09-17 19:44 [Qemu-devel] [PATCH 1/5] xhci: Init a transfers xhci, slotid and epid member on epctx alloc Hans de Goede
@ 2013-09-17 19:44 ` Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 3/5] xhci: Fix memory leak on xhci_disable_ep Hans de Goede
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2013-09-17 19:44 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Hans de Goede, qemu-devel
And use it instead of prying the USBEndpoint out of the packet struct
in various places.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/usb/hcd-xhci.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 120b038..c209228 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -501,6 +501,8 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
unsigned int epid);
static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v);
static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v);
+static USBEndpoint *xhci_epid_to_usbep(XHCIState *xhci,
+ unsigned int slotid, unsigned int epid);
static const char *TRBType_names[] = {
[TRB_RESERVED] = "TRB_RESERVED",
@@ -1345,13 +1347,12 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
xferi = epctx->next_xfer;
for (i = 0; i < TD_QUEUE; i++) {
- if (epctx->transfers[xferi].packet.ep) {
- ep = epctx->transfers[xferi].packet.ep;
- }
killed += xhci_ep_nuke_one_xfer(&epctx->transfers[xferi]);
epctx->transfers[xferi].packet.ep = NULL;
xferi = (xferi + 1) % TD_QUEUE;
}
+
+ ep = xhci_epid_to_usbep(xhci, slotid, epid);
if (ep) {
usb_device_ep_stopped(ep->dev, ep);
}
@@ -1683,7 +1684,6 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer,
static int xhci_setup_packet(XHCITransfer *xfer)
{
XHCIState *xhci = xfer->xhci;
- USBDevice *dev;
USBEndpoint *ep;
int dir;
@@ -1691,15 +1691,13 @@ static int xhci_setup_packet(XHCITransfer *xfer)
if (xfer->packet.ep) {
ep = xfer->packet.ep;
- dev = ep->dev;
} else {
- if (!xhci->slots[xfer->slotid-1].uport) {
+ ep = xhci_epid_to_usbep(xhci, xfer->slotid, xfer->epid);
+ if (!ep) {
fprintf(stderr, "xhci: slot %d has no device\n",
xfer->slotid);
return -1;
}
- dev = xhci->slots[xfer->slotid-1].uport->dev;
- ep = usb_ep_get(dev, dir, xfer->epid >> 1);
}
xhci_xfer_create_sgl(xfer, dir == USB_TOKEN_IN); /* Also sets int_req */
@@ -1707,7 +1705,7 @@ static int xhci_setup_packet(XHCITransfer *xfer)
xfer->trbs[0].addr, false, xfer->int_req);
usb_packet_map(&xfer->packet, &xfer->sgl);
DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n",
- xfer->packet.pid, dev->addr, ep->nr);
+ xfer->packet.pid, ep->dev->addr, ep->nr);
return 0;
}
@@ -2059,7 +2057,6 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
} else {
if (xhci_fire_transfer(xhci, xfer, epctx) >= 0) {
epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
- ep = xfer->packet.ep;
} else {
if (!xfer->timed_xfer) {
fprintf(stderr, "xhci: error firing data transfer\n");
@@ -2076,6 +2073,8 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
break;
}
}
+
+ ep = xhci_epid_to_usbep(xhci, slotid, epid);
if (ep) {
usb_device_flush_ep_queue(ep->dev, ep);
}
@@ -3303,6 +3302,19 @@ static int xhci_find_epid(USBEndpoint *ep)
}
}
+static USBEndpoint *xhci_epid_to_usbep(XHCIState *xhci,
+ unsigned int slotid, unsigned int epid)
+{
+ assert(slotid >= 1 && slotid <= xhci->numslots);
+
+ if (!xhci->slots[slotid - 1].uport) {
+ return NULL;
+ }
+
+ return usb_ep_get(xhci->slots[slotid - 1].uport->dev,
+ (epid & 1) ? USB_TOKEN_IN : USB_TOKEN_OUT, epid >> 1);
+}
+
static void xhci_wakeup_endpoint(USBBus *bus, USBEndpoint *ep,
unsigned int stream)
{
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 3/5] xhci: Fix memory leak on xhci_disable_ep
2013-09-17 19:44 [Qemu-devel] [PATCH 1/5] xhci: Init a transfers xhci, slotid and epid member on epctx alloc Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 2/5] xhci: Add xhci_epid_to_usbep helper function Hans de Goede
@ 2013-09-17 19:44 ` Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 4/5] usb: Fix iovec memleak on combined-packet free Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 5/5] usb: Also reset max_packet_size on ep_reset Hans de Goede
3 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2013-09-17 19:44 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Hans de Goede, qemu-devel
The USBPacket-s in the transfers need to be cleaned up so that the memory
allocated by the iovec in there gets freed.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/usb/hcd-xhci.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index c209228..18d2e13 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -1364,6 +1364,7 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
{
XHCISlot *slot;
XHCIEPContext *epctx;
+ int i;
trace_usb_xhci_ep_disable(slotid, epid);
assert(slotid >= 1 && slotid <= xhci->numslots);
@@ -1384,6 +1385,10 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
xhci_free_streams(epctx);
}
+ for (i = 0; i < ARRAY_SIZE(epctx->transfers); i++) {
+ usb_packet_cleanup(&epctx->transfers[i].packet);
+ }
+
xhci_set_ep_state(xhci, epctx, NULL, EP_DISABLED);
qemu_free_timer(epctx->kick_timer);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 4/5] usb: Fix iovec memleak on combined-packet free
2013-09-17 19:44 [Qemu-devel] [PATCH 1/5] xhci: Init a transfers xhci, slotid and epid member on epctx alloc Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 2/5] xhci: Add xhci_epid_to_usbep helper function Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 3/5] xhci: Fix memory leak on xhci_disable_ep Hans de Goede
@ 2013-09-17 19:44 ` Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 5/5] usb: Also reset max_packet_size on ep_reset Hans de Goede
3 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2013-09-17 19:44 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Hans de Goede, qemu-devel
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/usb/combined-packet.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/usb/combined-packet.c b/hw/usb/combined-packet.c
index 13f6602..ad77705 100644
--- a/hw/usb/combined-packet.c
+++ b/hw/usb/combined-packet.c
@@ -39,6 +39,7 @@ static void usb_combined_packet_remove(USBCombinedPacket *combined,
p->combined = NULL;
QTAILQ_REMOVE(&combined->packets, p, combined_entry);
if (QTAILQ_EMPTY(&combined->packets)) {
+ qemu_iovec_destroy(&combined->iov);
g_free(combined);
}
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 5/5] usb: Also reset max_packet_size on ep_reset
2013-09-17 19:44 [Qemu-devel] [PATCH 1/5] xhci: Init a transfers xhci, slotid and epid member on epctx alloc Hans de Goede
` (2 preceding siblings ...)
2013-09-17 19:44 ` [Qemu-devel] [PATCH 4/5] usb: Fix iovec memleak on combined-packet free Hans de Goede
@ 2013-09-17 19:44 ` Hans de Goede
3 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2013-09-17 19:44 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Hans de Goede, qemu-devel
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/usb/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/hw/usb/core.c b/hw/usb/core.c
index 31960c2..cf59a1a 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -622,6 +622,7 @@ void usb_ep_reset(USBDevice *dev)
dev->ep_ctl.nr = 0;
dev->ep_ctl.type = USB_ENDPOINT_XFER_CONTROL;
dev->ep_ctl.ifnum = 0;
+ dev->ep_ctl.max_packet_size = 64;
dev->ep_ctl.dev = dev;
dev->ep_ctl.pipeline = false;
for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
@@ -633,6 +634,8 @@ void usb_ep_reset(USBDevice *dev)
dev->ep_out[ep].type = USB_ENDPOINT_XFER_INVALID;
dev->ep_in[ep].ifnum = USB_INTERFACE_INVALID;
dev->ep_out[ep].ifnum = USB_INTERFACE_INVALID;
+ dev->ep_in[ep].max_packet_size = 0;
+ dev->ep_out[ep].max_packet_size = 0;
dev->ep_in[ep].dev = dev;
dev->ep_out[ep].dev = dev;
dev->ep_in[ep].pipeline = false;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-09-17 19:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-17 19:44 [Qemu-devel] [PATCH 1/5] xhci: Init a transfers xhci, slotid and epid member on epctx alloc Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 2/5] xhci: Add xhci_epid_to_usbep helper function Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 3/5] xhci: Fix memory leak on xhci_disable_ep Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 4/5] usb: Fix iovec memleak on combined-packet free Hans de Goede
2013-09-17 19:44 ` [Qemu-devel] [PATCH 5/5] usb: Also reset max_packet_size on ep_reset Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).