aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2014-10-16 14:03:39 -0400
committerKevin O'Connor <kevin@koconnor.net>2014-10-16 16:30:15 -0400
commit54a1c6d629b7aafe52974a2a9f5c8cf3a3780413 (patch)
treeeebcb20dda928f91edd94b368cbab555b115e472
parent277ea6f5d145f77d2374b9425016735c302811a0 (diff)
downloadseabios-54a1c6d629b7aafe52974a2a9f5c8cf3a3780413.tar.gz
usb: Use usb_realloc_pipe for pipe alloc, update, and free.
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>
-rw-r--r--src/hw/usb.c60
-rw-r--r--src/hw/usb.h6
2 files changed, 30 insertions, 36 deletions
diff --git a/src/hw/usb.c b/src/hw/usb.c
index 1714968d..bb646a78 100644
--- a/src/hw/usb.c
+++ b/src/hw/usb.c
@@ -26,35 +26,21 @@
* 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;
diff --git a/src/hw/usb.h b/src/hw/usb.h
index 8e3e60a0..208d08f5 100644
--- a/src/hw/usb.h
+++ b/src/hw/usb.h
@@ -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