[SeaBIOS] [PATCH 14/19] usb: Generalize controller alloc_async_pipe / alloc_intr_pipe code.

Kevin O'Connor kevin at koconnor.net
Sun Mar 11 03:47:34 CET 2012


Use one function (X_alloc_pipe) as the main entry point for usb pipe
allocation in the controller code.  The determination of
interrupt/bulk/control can be done within the controller.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/usb-ehci.c |   12 ++++++------
 src/usb-ehci.h |    6 ++----
 src/usb-hid.c  |    4 ++--
 src/usb-msc.c  |    4 ++--
 src/usb-ohci.c |   10 +++++-----
 src/usb-ohci.h |    6 ++----
 src/usb-uhci.c |   12 ++++++------
 src/usb-uhci.h |    6 ++----
 src/usb.c      |   31 ++++++++-----------------------
 src/usb.h      |    6 ++----
 10 files changed, 37 insertions(+), 60 deletions(-)

diff --git a/src/usb-ehci.c b/src/usb-ehci.c
index 67b8450..da5ed6f 100644
--- a/src/usb-ehci.c
+++ b/src/usb-ehci.c
@@ -380,12 +380,10 @@ ehci_init(struct pci_device *pci, int busid, struct pci_device *comppci)
  * End point communication
  ****************************************************************/
 
-struct usb_pipe *
+static struct usb_pipe *
 ehci_alloc_intr_pipe(struct usbdevice_s *usbdev
                      , struct usb_endpoint_descriptor *epdesc)
 {
-    if (! CONFIG_USB_EHCI)
-        return NULL;
     struct usb_ehci_s *cntl = container_of(
         usbdev->hub->cntl, struct usb_ehci_s, usb);
     int frameexp = usb_getFrameExp(usbdev, epdesc);
@@ -457,14 +455,16 @@ fail:
 }
 
 struct usb_pipe *
-ehci_alloc_async_pipe(struct usbdevice_s *usbdev
-                      , struct usb_endpoint_descriptor *epdesc)
+ehci_alloc_pipe(struct usbdevice_s *usbdev
+                , struct usb_endpoint_descriptor *epdesc)
 {
     if (! CONFIG_USB_EHCI)
         return NULL;
+    u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
+    if (eptype == USB_ENDPOINT_XFER_INT)
+        return ehci_alloc_intr_pipe(usbdev, epdesc);
     struct usb_ehci_s *cntl = container_of(
         usbdev->hub->cntl, struct usb_ehci_s, usb);
-    u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
     dprintf(7, "ehci_alloc_async_pipe %p %d\n", &cntl->usb, eptype);
 
     struct usb_pipe *usbpipe = usb_getFreePipe(&cntl->usb, eptype);
diff --git a/src/usb-ehci.h b/src/usb-ehci.h
index 958f444..b295c78 100644
--- a/src/usb-ehci.h
+++ b/src/usb-ehci.h
@@ -5,14 +5,12 @@
 int ehci_init(struct pci_device *pci, int busid, struct pci_device *comppci);
 struct usbdevice_s;
 struct usb_endpoint_descriptor;
-struct usb_pipe *ehci_alloc_async_pipe(struct usbdevice_s *usbdev
-                                       , struct usb_endpoint_descriptor *epdesc);
+struct usb_pipe *ehci_alloc_pipe(struct usbdevice_s *usbdev
+                                 , struct usb_endpoint_descriptor *epdesc);
 struct usb_pipe;
 int ehci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
                  , void *data, int datasize);
 int ehci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize);
-struct usb_pipe *ehci_alloc_intr_pipe(struct usbdevice_s *usbdev
-                                      , struct usb_endpoint_descriptor *epdesc);
 int ehci_poll_intr(struct usb_pipe *p, void *data);
 
 
diff --git a/src/usb-hid.c b/src/usb-hid.c
index 21363c3..6e8ec4e 100644
--- a/src/usb-hid.c
+++ b/src/usb-hid.c
@@ -70,7 +70,7 @@ usb_kbd_init(struct usbdevice_s *usbdev
     if (ret)
         return -1;
 
-    keyboard_pipe = alloc_intr_pipe(usbdev, epdesc);
+    keyboard_pipe = usb_alloc_pipe(usbdev, epdesc);
     if (!keyboard_pipe)
         return -1;
 
@@ -96,7 +96,7 @@ usb_mouse_init(struct usbdevice_s *usbdev
     if (ret)
         return -1;
 
-    mouse_pipe = alloc_intr_pipe(usbdev, epdesc);
+    mouse_pipe = usb_alloc_pipe(usbdev, epdesc);
     if (!mouse_pipe)
         return -1;
 
diff --git a/src/usb-msc.c b/src/usb-msc.c
index 4bf24a3..f6f9958 100644
--- a/src/usb-msc.c
+++ b/src/usb-msc.c
@@ -156,8 +156,8 @@ usb_msc_init(struct usbdevice_s *usbdev)
         usbdev, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT);
     if (!indesc || !outdesc)
         goto fail;
-    udrive_g->bulkin = alloc_async_pipe(usbdev, indesc);
-    udrive_g->bulkout = alloc_async_pipe(usbdev, outdesc);
+    udrive_g->bulkin = usb_alloc_pipe(usbdev, indesc);
+    udrive_g->bulkout = usb_alloc_pipe(usbdev, outdesc);
     if (!udrive_g->bulkin || !udrive_g->bulkout)
         goto fail;
 
diff --git a/src/usb-ohci.c b/src/usb-ohci.c
index 39ed92a..a0937a2 100644
--- a/src/usb-ohci.c
+++ b/src/usb-ohci.c
@@ -302,12 +302,10 @@ ohci_init(struct pci_device *pci, int busid)
  * End point communication
  ****************************************************************/
 
-struct usb_pipe *
+static struct usb_pipe *
 ohci_alloc_intr_pipe(struct usbdevice_s *usbdev
                      , struct usb_endpoint_descriptor *epdesc)
 {
-    if (! CONFIG_USB_OHCI)
-        return NULL;
     struct usb_ohci_s *cntl = container_of(
         usbdev->hub->cntl, struct usb_ohci_s, usb);
     int frameexp = usb_getFrameExp(usbdev, epdesc);
@@ -370,12 +368,14 @@ err:
 }
 
 struct usb_pipe *
-ohci_alloc_async_pipe(struct usbdevice_s *usbdev
-                      , struct usb_endpoint_descriptor *epdesc)
+ohci_alloc_pipe(struct usbdevice_s *usbdev
+                , struct usb_endpoint_descriptor *epdesc)
 {
     if (! CONFIG_USB_OHCI)
         return NULL;
     u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
+    if (eptype == USB_ENDPOINT_XFER_INT)
+        return ohci_alloc_intr_pipe(usbdev, epdesc);
     if (eptype != USB_ENDPOINT_XFER_CONTROL) {
         dprintf(1, "OHCI Bulk transfers not supported.\n");
         return NULL;
diff --git a/src/usb-ohci.h b/src/usb-ohci.h
index ab957e6..25900a7 100644
--- a/src/usb-ohci.h
+++ b/src/usb-ohci.h
@@ -5,14 +5,12 @@
 void ohci_init(struct pci_device *pci, int busid);
 struct usbdevice_s;
 struct usb_endpoint_descriptor;
-struct usb_pipe *ohci_alloc_async_pipe(struct usbdevice_s *usbdev
-                                       , struct usb_endpoint_descriptor *epdesc);
+struct usb_pipe *ohci_alloc_pipe(struct usbdevice_s *usbdev
+                                 , struct usb_endpoint_descriptor *epdesc);
 struct usb_pipe;
 int ohci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
                  , void *data, int datasize);
 int ohci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize);
-struct usb_pipe *ohci_alloc_intr_pipe(struct usbdevice_s *usbdev
-                                      , struct usb_endpoint_descriptor *epdesc);
 int ohci_poll_intr(struct usb_pipe *p, void *data);
 
 
diff --git a/src/usb-uhci.c b/src/usb-uhci.c
index aa49681..b2677b8 100644
--- a/src/usb-uhci.c
+++ b/src/usb-uhci.c
@@ -268,12 +268,10 @@ uhci_init(struct pci_device *pci, int busid)
  * End point communication
  ****************************************************************/
 
-struct usb_pipe *
+static struct usb_pipe *
 uhci_alloc_intr_pipe(struct usbdevice_s *usbdev
                      , struct usb_endpoint_descriptor *epdesc)
 {
-    if (! CONFIG_USB_UHCI)
-        return NULL;
     struct usb_uhci_s *cntl = container_of(
         usbdev->hub->cntl, struct usb_uhci_s, usb);
     int frameexp = usb_getFrameExp(usbdev, epdesc);
@@ -341,14 +339,16 @@ fail:
 }
 
 struct usb_pipe *
-uhci_alloc_async_pipe(struct usbdevice_s *usbdev
-                      , struct usb_endpoint_descriptor *epdesc)
+uhci_alloc_pipe(struct usbdevice_s *usbdev
+                , struct usb_endpoint_descriptor *epdesc)
 {
     if (! CONFIG_USB_UHCI)
         return NULL;
+    u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
+    if (eptype == USB_ENDPOINT_XFER_INT)
+        return uhci_alloc_intr_pipe(usbdev, epdesc);
     struct usb_uhci_s *cntl = container_of(
         usbdev->hub->cntl, struct usb_uhci_s, usb);
-    u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
     dprintf(7, "uhci_alloc_async_pipe %p %d\n", &cntl->usb, eptype);
 
     struct usb_pipe *usbpipe = usb_getFreePipe(&cntl->usb, eptype);
diff --git a/src/usb-uhci.h b/src/usb-uhci.h
index 708ba59..9e3297c 100644
--- a/src/usb-uhci.h
+++ b/src/usb-uhci.h
@@ -5,14 +5,12 @@
 void uhci_init(struct pci_device *pci, int busid);
 struct usbdevice_s;
 struct usb_endpoint_descriptor;
-struct usb_pipe *uhci_alloc_async_pipe(struct usbdevice_s *usbdev
-                                       , struct usb_endpoint_descriptor *epdesc);
+struct usb_pipe *uhci_alloc_pipe(struct usbdevice_s *usbdev
+                                 , struct usb_endpoint_descriptor *epdesc);
 struct usb_pipe;
 int uhci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
                  , void *data, int datasize);
 int uhci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize);
-struct usb_pipe *uhci_alloc_intr_pipe(struct usbdevice_s *usbdev
-                                      , struct usb_endpoint_descriptor *epdesc);
 int uhci_poll_intr(struct usb_pipe *p, void *data);
 
 
diff --git a/src/usb.c b/src/usb.c
index 7276e15..5a5331f 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -82,17 +82,17 @@ usb_getFreePipe(struct usb_s *cntl, u8 eptype)
 
 // Allocate an async pipe (control or bulk).
 struct usb_pipe *
-alloc_async_pipe(struct usbdevice_s *usbdev
-                 , struct usb_endpoint_descriptor *epdesc)
+usb_alloc_pipe(struct usbdevice_s *usbdev
+               , struct usb_endpoint_descriptor *epdesc)
 {
     switch (usbdev->hub->cntl->type) {
     default:
     case USB_TYPE_UHCI:
-        return uhci_alloc_async_pipe(usbdev, epdesc);
+        return uhci_alloc_pipe(usbdev, epdesc);
     case USB_TYPE_OHCI:
-        return ohci_alloc_async_pipe(usbdev, epdesc);
+        return ohci_alloc_pipe(usbdev, epdesc);
     case USB_TYPE_EHCI:
-        return ehci_alloc_async_pipe(usbdev, epdesc);
+        return ehci_alloc_pipe(usbdev, epdesc);
     }
 }
 
@@ -138,21 +138,6 @@ usb_getFrameExp(struct usbdevice_s *usbdev
     return (period <= 4) ? 0 : period - 4;
 }
 
-struct usb_pipe *
-alloc_intr_pipe(struct usbdevice_s *usbdev
-                , struct usb_endpoint_descriptor *epdesc)
-{
-    switch (usbdev->hub->cntl->type) {
-    default:
-    case USB_TYPE_UHCI:
-        return uhci_alloc_intr_pipe(usbdev, epdesc);
-    case USB_TYPE_OHCI:
-        return ohci_alloc_intr_pipe(usbdev, epdesc);
-    case USB_TYPE_EHCI:
-        return ehci_alloc_intr_pipe(usbdev, epdesc);
-    }
-}
-
 int noinline
 usb_poll_intr(struct usb_pipe *pipe_fl, void *data)
 {
@@ -271,7 +256,7 @@ usb_set_address(struct usbdevice_s *usbdev)
         .wMaxPacketSize = 8,
         .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
     };
-    usbdev->defpipe = alloc_async_pipe(usbdev, &epdesc);
+    usbdev->defpipe = usb_alloc_pipe(usbdev, &epdesc);
     if (!usbdev->defpipe)
         return -1;
 
@@ -293,7 +278,7 @@ usb_set_address(struct usbdevice_s *usbdev)
 
     cntl->maxaddr++;
     usbdev->devaddr = cntl->maxaddr;
-    usbdev->defpipe = alloc_async_pipe(usbdev, &epdesc);
+    usbdev->defpipe = usb_alloc_pipe(usbdev, &epdesc);
     if (!usbdev->defpipe)
         return -1;
     return 0;
@@ -322,7 +307,7 @@ configure_usb_device(struct usbdevice_s *usbdev)
         .wMaxPacketSize = dinfo.bMaxPacketSize0,
         .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
     };
-    usbdev->defpipe = alloc_async_pipe(usbdev, &epdesc);
+    usbdev->defpipe = usb_alloc_pipe(usbdev, &epdesc);
     if (!usbdev->defpipe)
         return -1;
 
diff --git a/src/usb.h b/src/usb.h
index eddf9af..3802c35 100644
--- a/src/usb.h
+++ b/src/usb.h
@@ -221,12 +221,10 @@ void free_pipe(struct usb_pipe *pipe);
 void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev
                    , struct usb_endpoint_descriptor *epdesc);
 struct usb_pipe *usb_getFreePipe(struct usb_s *cntl, u8 eptype);
-struct usb_pipe *alloc_async_pipe(struct usbdevice_s *usbdev
-                                  , struct usb_endpoint_descriptor *epdesc);
+struct usb_pipe *usb_alloc_pipe(struct usbdevice_s *usbdev
+                                , struct usb_endpoint_descriptor *epdesc);
 int usb_getFrameExp(struct usbdevice_s *usbdev
                     , struct usb_endpoint_descriptor *epdesc);
-struct usb_pipe *alloc_intr_pipe(struct usbdevice_s *usbdev
-                                 , struct usb_endpoint_descriptor *epdesc);
 int usb_poll_intr(struct usb_pipe *pipe, void *data);
 struct usb_endpoint_descriptor *findEndPointDesc(struct usbdevice_s *usbdev
                                                  , int type, int dir);
-- 
1.7.6.5




More information about the SeaBIOS mailing list