[U-Boot] [PATCH] usb: ci_udc: Allocate the qTD list directly

Marek Vasut marex at denx.de
Tue Jul 1 01:53:18 CEST 2014


Instead of weird allocation of ci_drv->items_mem and then even weirder
distribution of offsets in this memory area into ci_drv->items array,
just allocate ci_drv->items as a big slab of aligned memory (replaces
ci_drv->items_mem) and let ci_get_qtd() do the distribution of offsets
in this memory area.

Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Jörg Krause <jkrause at posteo.de>
Cc: Stephen Warren <swarren at wwwdotorg.org>
---
 drivers/usb/gadget/ci_udc.c | 18 +++++++-----------
 drivers/usb/gadget/ci_udc.h |  3 +--
 2 files changed, 8 insertions(+), 13 deletions(-)

Note: Please test, it's too late and I'm barely conscious anymore ...

diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
index 334b5d2..8d92324 100644
--- a/drivers/usb/gadget/ci_udc.c
+++ b/drivers/usb/gadget/ci_udc.c
@@ -137,7 +137,7 @@ static struct ept_queue_head *ci_get_qh(int ep_num, int dir_in)
  */
 static struct ept_queue_item *ci_get_qtd(int ep_num, int dir_in)
 {
-	return controller.items[(ep_num * 2) + dir_in];
+	return controller.items + ((ep_num * 2) + dir_in);
 }
 
 /**
@@ -727,7 +727,8 @@ static int ci_udc_probe(void)
 	const int ilist_sz = NUM_ENDPOINTS * ilist_ent_sz;
 
 	/* The QH list must be aligned to 4096 bytes. */
-	controller.epts = memalign(eplist_align, eplist_sz);
+	if (!controller.epts)
+		controller.epts = memalign(eplist_align, eplist_sz);
 	if (!controller.epts)
 		return -ENOMEM;
 	memset(controller.epts, 0, eplist_sz);
@@ -738,12 +739,13 @@ static int ci_udc_probe(void)
 	 * only one of them is used for the endpoint at time, so we can group
 	 * them together.
 	 */
-	controller.items_mem = memalign(ilist_align, ilist_sz);
-	if (!controller.items_mem) {
+	if (!controller.items)
+		controller.items = memalign(ilist_align, ilist_sz);
+	if (!controller.items) {
 		free(controller.epts);
 		return -ENOMEM;
 	}
-	memset(controller.items_mem, 0, ilist_sz);
+	memset(controller.items, 0, ilist_sz);
 
 	for (i = 0; i < 2 * NUM_ENDPOINTS; i++) {
 		/*
@@ -763,12 +765,6 @@ static int ci_udc_probe(void)
 		head->next = TERMINATE;
 		head->info = 0;
 
-		imem = controller.items_mem + ((i >> 1) * ilist_ent_sz);
-		if (i & 1)
-			imem += sizeof(struct ept_queue_item);
-
-		controller.items[i] = (struct ept_queue_item *)imem;
-
 		if (i & 1) {
 			ci_flush_qh(i - 1);
 			ci_flush_qtd(i - 1);
diff --git a/drivers/usb/gadget/ci_udc.h b/drivers/usb/gadget/ci_udc.h
index 7d76af8..d464368 100644
--- a/drivers/usb/gadget/ci_udc.h
+++ b/drivers/usb/gadget/ci_udc.h
@@ -101,8 +101,7 @@ struct ci_drv {
 	struct usb_gadget_driver	*driver;
 	struct ehci_ctrl		*ctrl;
 	struct ept_queue_head		*epts;
-	struct ept_queue_item		*items[2 * NUM_ENDPOINTS];
-	uint8_t				*items_mem;
+	struct ept_queue_item		*items;
 	struct ci_ep			ep[NUM_ENDPOINTS];
 };
 
-- 
2.0.0.rc2



More information about the U-Boot mailing list