aboutsummaryrefslogtreecommitdiff
path: root/lib/libusb
diff options
context:
space:
mode:
authorNikunj A Dadhania <nikunj@linux.vnet.ibm.com>2013-07-24 14:27:08 +0530
committerNikunj A Dadhania <nikunj@linux.vnet.ibm.com>2013-07-24 14:46:23 +0530
commit912a746dc1530179560a87f65121feb1920b583f (patch)
tree49418ac6c1154435212145c057072ad59e946a3e /lib/libusb
parent323108d7929c69cc934eb59aee7b5226a49926e9 (diff)
downloadSLOF-912a746dc1530179560a87f65121feb1920b583f.zip
SLOF-912a746dc1530179560a87f65121feb1920b583f.tar.gz
SLOF-912a746dc1530179560a87f65121feb1920b583f.tar.bz2
usb-core: create dev pool allocation
Have a device structure pool and provide apis usb_devpool_[get,put] Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Acked-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Diffstat (limited to 'lib/libusb')
-rw-r--r--lib/libusb/usb-core.c60
-rw-r--r--lib/libusb/usb-core.h3
2 files changed, 63 insertions, 0 deletions
diff --git a/lib/libusb/usb-core.c b/lib/libusb/usb-core.c
index 6e2de1f..b1e3449 100644
--- a/lib/libusb/usb-core.c
+++ b/lib/libusb/usb-core.c
@@ -10,6 +10,7 @@
* IBM Corporation - initial implementation
*****************************************************************************/
+#include <string.h>
#include "usb-core.h"
#undef DEBUG
@@ -21,6 +22,65 @@
#endif
struct usb_hcd_ops *head;
+struct usb_dev *devpool;
+#define USB_DEVPOOL_SIZE 4096
+
+static struct usb_dev *usb_alloc_devpool(void)
+{
+ struct usb_dev *head, *curr, *prev;
+ unsigned int dev_count = 0, i;
+
+ head = SLOF_dma_alloc(USB_DEVPOOL_SIZE);
+ if (!head)
+ return NULL;
+
+ dev_count = USB_DEVPOOL_SIZE/sizeof(struct usb_dev);
+ dprintf("%s: %d number of devices\n", __func__, dev_count);
+ /* Although an array, link them*/
+ for (i = 0, curr = head, prev = NULL; i < dev_count; i++, curr++) {
+ if (prev)
+ prev->next = curr;
+ curr->next = NULL;
+ prev = curr;
+ }
+
+#ifdef DEBUG
+ for (i = 0, curr = head; curr; curr = curr->next)
+ printf("%s: %d dev %p\n", __func__, i++, curr);
+#endif
+
+ return head;
+}
+
+struct usb_dev *usb_devpool_get(void)
+{
+ struct usb_dev *new;
+
+ if (!devpool) {
+ devpool = usb_alloc_devpool();
+ if (!devpool)
+ return NULL;
+ }
+
+ new = devpool;
+ devpool = devpool->next;
+ memset(new, 0, sizeof(*new));
+ new->next = NULL;
+ return new;
+}
+
+void usb_devpool_put(struct usb_dev *dev)
+{
+ struct usb_dev *curr;
+ if (!dev && !devpool)
+ return;
+
+ curr = devpool;
+ while (curr->next)
+ curr = curr->next;
+ curr->next = dev;
+ dev->next = NULL;
+}
#ifndef DEBUG
#define validate_hcd_ops(dev) (dev && dev->hcidev && dev->hcidev->ops)
diff --git a/lib/libusb/usb-core.h b/lib/libusb/usb-core.h
index 1de15d6..cc9dbe9 100644
--- a/lib/libusb/usb-core.h
+++ b/lib/libusb/usb-core.h
@@ -61,6 +61,7 @@ struct usb_ep_descr {
#define USB_DEV_EP_MAX 4
struct usb_dev {
+ struct usb_dev *next;
struct usb_hcd_dev *hcidev;
struct usb_pipe *intr;
struct usb_pipe *control;
@@ -133,5 +134,7 @@ extern struct usb_pipe *usb_get_pipe(struct usb_dev *dev, struct usb_ep_descr *e
char *buf, size_t len);
extern void usb_put_pipe(struct usb_pipe *pipe);
extern int usb_send_ctrl(struct usb_pipe *pipe, struct usb_dev_req *req, void *data);
+extern struct usb_dev *usb_devpool_get(void);
+extern void usb_devpool_put(struct usb_dev *);
#endif