]> xenbits.xensource.com Git - seabios.git/commitdiff
usb: Generalize controller alloc_async_pipe / alloc_intr_pipe code.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 10 Mar 2012 14:03:25 +0000 (09:03 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 11 Mar 2012 02:04:28 +0000 (21:04 -0500)
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@koconnor.net>
src/usb-ehci.c
src/usb-ehci.h
src/usb-hid.c
src/usb-msc.c
src/usb-ohci.c
src/usb-ohci.h
src/usb-uhci.c
src/usb-uhci.h
src/usb.c
src/usb.h

index 67b84508560f210b153afd7e9f0358079c69fe50..da5ed6f1a1deb0433cf1e89b7a053ab8dd7712ba 100644 (file)
@@ -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);
index 958f4444d12efcce9bb8952761fe6fdf1b528272..b295c78e512d6380a82f5865faa2739c3725fd66 100644 (file)
@@ -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);
 
 
index 21363c39d4cb513bfa6277465fec6046933db1cc..6e8ec4e05bc67632401d068c28c7fbdda9717c98 100644 (file)
@@ -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;
 
index 4bf24a314a196f94a7d767f3b43412e5976a010e..f6f9958b2d306ca9b9500253ae59756694c54d30 100644 (file)
@@ -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;
 
index 39ed92ad0cd3f79ce0e6987ff5de80584a857db7..a0937a24eae81adfd4a297ccb81417d410f21ef4 100644 (file)
@@ -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;
index ab957e61a58e88fcb9ff5539976e3463971f9139..25900a7257c3199394e1a5211d47a27acf0ca9cf 100644 (file)
@@ -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);
 
 
index aa49681b40e155c3e89aad815f665e507d08a589..b2677b854cec34b3bd49cde52ad018ea8bab9ace 100644 (file)
@@ -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);
index 708ba59a9f0bdb64cd70b88199905815a5faa92e..9e3297c41f4848c62f4c6736dcc8f9e0d74781ef 100644 (file)
@@ -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);
 
 
index 7276e157e20b0f065cb2c9984f923f21f89f45d5..5a5331fa45fdef8a2386a100e58bc0fc6a89d355 100644 (file)
--- 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;
 
index eddf9af92f532674d84f33d386032ff816bddf88..3802c35e89a5ddaae3819aca69bb57191c09dd7a 100644 (file)
--- 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);