]> xenbits.xensource.com Git - seabios.git/commitdiff
usb: Use usb_realloc_pipe for pipe alloc, update, and free.
authorKevin O'Connor <kevin@koconnor.net>
Thu, 16 Oct 2014 18:03:39 +0000 (14:03 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 16 Oct 2014 20:30:15 +0000 (16:30 -0400)
Now that the usb controller drivers all support the realloc method,
use that for all pipe allocations, reallocations, and freeing.  This
gives the driver more control over the pipe life cycle.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/hw/usb.c
src/hw/usb.h

index 1714968d577466ffda04a6e578c98250f0f80289..bb646a78538a194b484e81e243f38c02911448d8 100644 (file)
  * Controller function wrappers
  ****************************************************************/
 
-// Allocate an async pipe (control or bulk).
-struct usb_pipe *
-usb_alloc_pipe(struct usbdevice_s *usbdev
-               , struct usb_endpoint_descriptor *epdesc)
+// Allocate, update, or free a usb pipe.
+static struct usb_pipe *
+usb_realloc_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe
+                 , struct usb_endpoint_descriptor *epdesc)
 {
     switch (usbdev->hub->cntl->type) {
     default:
     case USB_TYPE_UHCI:
-        return uhci_realloc_pipe(usbdev, NULL, epdesc);
+        return uhci_realloc_pipe(usbdev, pipe, epdesc);
     case USB_TYPE_OHCI:
-        return ohci_realloc_pipe(usbdev, NULL, epdesc);
+        return ohci_realloc_pipe(usbdev, pipe, epdesc);
     case USB_TYPE_EHCI:
-        return ehci_realloc_pipe(usbdev, NULL, epdesc);
-    case USB_TYPE_XHCI:
-        return xhci_realloc_pipe(usbdev, NULL, epdesc);
-    }
-}
-
-// Update an pipe (used for control only)
-struct usb_pipe *
-usb_update_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe
-                , struct usb_endpoint_descriptor *epdesc)
-{
-    switch (usbdev->hub->cntl->type) {
+        return ehci_realloc_pipe(usbdev, pipe, epdesc);
     case USB_TYPE_XHCI:
         return xhci_realloc_pipe(usbdev, pipe, epdesc);
-    default:
-        usb_free_pipe(usbdev, pipe);
-        return usb_alloc_pipe(usbdev, epdesc);
     }
 }
 
@@ -119,10 +105,28 @@ int usb_32bit_pipe(struct usb_pipe *pipe_fl)
     return CONFIG_USB_XHCI && GET_LOWFLAT(pipe_fl->type) == USB_TYPE_XHCI;
 }
 
+
 /****************************************************************
  * Helper functions
  ****************************************************************/
 
+// Allocate a usb pipe.
+struct usb_pipe *
+usb_alloc_pipe(struct usbdevice_s *usbdev
+               , struct usb_endpoint_descriptor *epdesc)
+{
+    return usb_realloc_pipe(usbdev, NULL, epdesc);
+}
+
+// Free an allocated control or bulk pipe.
+void
+usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe)
+{
+    if (!pipe)
+        return;
+    usb_realloc_pipe(usbdev, pipe, NULL);
+}
+
 // Send a message to the default control pipe of a device.
 int
 usb_send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req
@@ -167,16 +171,6 @@ usb_get_freelist(struct usb_s *cntl, u8 eptype)
     }
 }
 
-// Free an allocated control or bulk pipe.
-void
-usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe)
-{
-    ASSERT32FLAT();
-    if (!pipe)
-        return;
-    usb_add_freelist(pipe);
-}
-
 // Fill "pipe" endpoint info from an endpoint descriptor.
 void
 usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev
@@ -335,7 +329,7 @@ usb_set_address(struct usbdevice_s *usbdev)
 
     cntl->maxaddr++;
     usbdev->devaddr = cntl->maxaddr;
-    usbdev->defpipe = usb_update_pipe(usbdev, usbdev->defpipe, &epdesc);
+    usbdev->defpipe = usb_realloc_pipe(usbdev, usbdev->defpipe, &epdesc);
     if (!usbdev->defpipe)
         return -1;
     return 0;
@@ -366,7 +360,7 @@ configure_usb_device(struct usbdevice_s *usbdev)
         .wMaxPacketSize = maxpacket,
         .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
     };
-    usbdev->defpipe = usb_update_pipe(usbdev, usbdev->defpipe, &epdesc);
+    usbdev->defpipe = usb_realloc_pipe(usbdev, usbdev->defpipe, &epdesc);
     if (!usbdev->defpipe)
         return -1;
 
index 8e3e60a077a18c068636228f8c7f662c60af221c..208d08f593292067a07fa92ca37c3c1b383e3b1f 100644 (file)
@@ -228,17 +228,17 @@ struct usb_endpoint_descriptor {
  ****************************************************************/
 
 // usb.c
-struct usb_pipe *usb_alloc_pipe(struct usbdevice_s *usbdev
-                                , struct usb_endpoint_descriptor *epdesc);
 int usb_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize);
 int usb_poll_intr(struct usb_pipe *pipe, void *data);
 int usb_32bit_pipe(struct usb_pipe *pipe_fl);
+struct usb_pipe *usb_alloc_pipe(struct usbdevice_s *usbdev
+                                , struct usb_endpoint_descriptor *epdesc);
+void usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe);
 int usb_send_default_control(struct usb_pipe *pipe
                              , const struct usb_ctrlrequest *req, void *data);
 int usb_is_freelist(struct usb_s *cntl, struct usb_pipe *pipe);
 void usb_add_freelist(struct usb_pipe *pipe);
 struct usb_pipe *usb_get_freelist(struct usb_s *cntl, u8 eptype);
-void usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe);
 void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev
                    , struct usb_endpoint_descriptor *epdesc);
 int usb_get_period(struct usbdevice_s *usbdev