The first six patches in this series make the internal usb naming convention a little more standard. (Use a "usb_" prefix on all exported functions and don't use camel case on exported functions.)
The remaining five patches convert the USB controller drivers to a single pipe "realloc" function for managing pipe allocations and freeing. This should make it easier for xhci to implement pipe freeing (not implemented in this series).
-Kevin
Kevin O'Connor (11): usb: Rename ?hci_control() to ?hci_send_control() usb: Rename usb_getFrameExp() to usb_get_period() usb: Rename findEndPointDesc() to usb_find_desc() usb: Rename send_default_control() to usb_send_default_control() usb: Rename free_pipe() to usb_free_pipe() usb: Clarify usb freelist manipulations xhci: Change xhci_update_pipe() to xhci_realloc_pipe() and use for alloc too uhci: Export uhci_realloc_pipe() instead of uhci_alloc_pipe() ohci: Export ohci_realloc_pipe() instead of ohci_alloc_pipe() ehci: Export ehci_realloc_pipe() instead of ehci_alloc_pipe() usb: Use usb_realloc_pipe for pipe alloc, update, and free.
src/hw/usb-ehci.c | 17 +++++---- src/hw/usb-ehci.h | 9 +++-- src/hw/usb-hid.c | 6 +-- src/hw/usb-hub.c | 8 ++-- src/hw/usb-msc.c | 10 ++--- src/hw/usb-ohci.c | 17 +++++---- src/hw/usb-ohci.h | 9 +++-- src/hw/usb-uas.c | 8 ++-- src/hw/usb-uhci.c | 17 +++++---- src/hw/usb-uhci.h | 9 +++-- src/hw/usb-xhci.c | 18 ++++++--- src/hw/usb-xhci.h | 12 +++--- src/hw/usb.c | 109 +++++++++++++++++++++++++++++------------------------- src/hw/usb.h | 22 ++++++----- 14 files changed, 149 insertions(+), 122 deletions(-)
This is just function renaming - no code implementation changes.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-ehci.c | 4 ++-- src/hw/usb-ehci.h | 4 ++-- src/hw/usb-ohci.c | 4 ++-- src/hw/usb-ohci.h | 4 ++-- src/hw/usb-uhci.c | 4 ++-- src/hw/usb-uhci.h | 4 ++-- src/hw/usb-xhci.c | 4 ++-- src/hw/usb-xhci.h | 4 ++-- src/hw/usb.c | 16 ++++++++-------- 9 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index f5ee5bf..6e32e04 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -550,8 +550,8 @@ fillTDbuffer(struct ehci_qtd *td, u16 maxpacket, const void *buf, int bytes) }
int -ehci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize - , void *data, int datasize) +ehci_send_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize + , void *data, int datasize) { ASSERT32FLAT(); if (! CONFIG_USB_EHCI) diff --git a/src/hw/usb-ehci.h b/src/hw/usb-ehci.h index fcb8d94..6346d78 100644 --- a/src/hw/usb-ehci.h +++ b/src/hw/usb-ehci.h @@ -8,8 +8,8 @@ struct usb_endpoint_descriptor; 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_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); int ehci_poll_intr(struct usb_pipe *p, void *data);
diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index 7a22057..b9c5d4c 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -443,8 +443,8 @@ wait_ed(struct ohci_ed *ed, int timeout) }
int -ohci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize - , void *data, int datasize) +ohci_send_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize + , void *data, int datasize) { if (! CONFIG_USB_OHCI) return -1; diff --git a/src/hw/usb-ohci.h b/src/hw/usb-ohci.h index 3cae21f..14d2b1a 100644 --- a/src/hw/usb-ohci.h +++ b/src/hw/usb-ohci.h @@ -8,8 +8,8 @@ struct usb_endpoint_descriptor; 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_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); int ohci_poll_intr(struct usb_pipe *p, void *data);
diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index a34f6db..bd9e317 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -441,8 +441,8 @@ wait_td(struct uhci_td *td, u32 end) }
int -uhci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize - , void *data, int datasize) +uhci_send_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize + , void *data, int datasize) { ASSERT32FLAT(); if (! CONFIG_USB_UHCI) diff --git a/src/hw/usb-uhci.h b/src/hw/usb-uhci.h index 2916465..6b675bb 100644 --- a/src/hw/usb-uhci.h +++ b/src/hw/usb-uhci.h @@ -8,8 +8,8 @@ struct usb_endpoint_descriptor; 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_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); int uhci_poll_intr(struct usb_pipe *p, void *data);
diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c index eafa4cb..470cece 100644 --- a/src/hw/usb-xhci.c +++ b/src/hw/usb-xhci.c @@ -1113,8 +1113,8 @@ xhci_update_pipe(struct usbdevice_s *usbdev, struct usb_pipe *upipe }
int -xhci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize - , void *data, int datalen) +xhci_send_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize + , void *data, int datalen) { if (!CONFIG_USB_XHCI) return -1; diff --git a/src/hw/usb-xhci.h b/src/hw/usb-xhci.h index bd98d17..7639409 100644 --- a/src/hw/usb-xhci.h +++ b/src/hw/usb-xhci.h @@ -14,8 +14,8 @@ struct usb_pipe *xhci_alloc_pipe(struct usbdevice_s *usbdev struct usb_pipe *xhci_update_pipe(struct usbdevice_s *usbdev , struct usb_pipe *pipe , struct usb_endpoint_descriptor *epdesc); -int xhci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize - , void *data, int datasize); +int xhci_send_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize + , void *data, int datasize); int xhci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize); int xhci_poll_intr(struct usb_pipe *p, void *data);
diff --git a/src/hw/usb.c b/src/hw/usb.c index 153e153..f870481 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -60,20 +60,20 @@ usb_update_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe
// Send a message on a control pipe using the default control descriptor. static int -send_control(struct usb_pipe *pipe, int dir, const void *cmd, int cmdsize - , void *data, int datasize) +usb_send_control(struct usb_pipe *pipe, int dir, const void *cmd, int cmdsize + , void *data, int datasize) { ASSERT32FLAT(); switch (pipe->type) { default: case USB_TYPE_UHCI: - return uhci_control(pipe, dir, cmd, cmdsize, data, datasize); + return uhci_send_control(pipe, dir, cmd, cmdsize, data, datasize); case USB_TYPE_OHCI: - return ohci_control(pipe, dir, cmd, cmdsize, data, datasize); + return ohci_send_control(pipe, dir, cmd, cmdsize, data, datasize); case USB_TYPE_EHCI: - return ehci_control(pipe, dir, cmd, cmdsize, data, datasize); + return ehci_send_control(pipe, dir, cmd, cmdsize, data, datasize); case USB_TYPE_XHCI: - return xhci_control(pipe, dir, cmd, cmdsize, data, datasize); + return xhci_send_control(pipe, dir, cmd, cmdsize, data, datasize); } }
@@ -128,8 +128,8 @@ int send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req , void *data) { - return send_control(pipe, req->bRequestType & USB_DIR_IN - , req, sizeof(*req), data, req->wLength); + return usb_send_control(pipe, req->bRequestType & USB_DIR_IN + , req, sizeof(*req), data, req->wLength); }
// Free an allocated control or bulk pipe.
This is just function renaming - no code implementation changes.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-ehci.c | 2 +- src/hw/usb-ohci.c | 2 +- src/hw/usb-uhci.c | 2 +- src/hw/usb-xhci.c | 2 +- src/hw/usb.c | 4 ++-- src/hw/usb.h | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index 6e32e04..2376b1f 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -386,7 +386,7 @@ ehci_alloc_intr_pipe(struct usbdevice_s *usbdev { struct usb_ehci_s *cntl = container_of( usbdev->hub->cntl, struct usb_ehci_s, usb); - int frameexp = usb_getFrameExp(usbdev, epdesc); + int frameexp = usb_get_period(usbdev, epdesc); dprintf(7, "ehci_alloc_intr_pipe %p %d\n", &cntl->usb, frameexp);
if (frameexp > 10) diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index b9c5d4c..a91e24d 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -328,7 +328,7 @@ ohci_alloc_intr_pipe(struct usbdevice_s *usbdev { struct usb_ohci_s *cntl = container_of( usbdev->hub->cntl, struct usb_ohci_s, usb); - int frameexp = usb_getFrameExp(usbdev, epdesc); + int frameexp = usb_get_period(usbdev, epdesc); dprintf(7, "ohci_alloc_intr_pipe %p %d\n", &cntl->usb, frameexp);
if (frameexp > 5) diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index bd9e317..a270a82 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -287,7 +287,7 @@ uhci_alloc_intr_pipe(struct usbdevice_s *usbdev { struct usb_uhci_s *cntl = container_of( usbdev->hub->cntl, struct usb_uhci_s, usb); - int frameexp = usb_getFrameExp(usbdev, epdesc); + int frameexp = usb_get_period(usbdev, epdesc); dprintf(7, "uhci_alloc_intr_pipe %p %d\n", &cntl->usb, frameexp);
if (frameexp > 10) diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c index 470cece..0b8ed64 100644 --- a/src/hw/usb-xhci.c +++ b/src/hw/usb-xhci.c @@ -1014,7 +1014,7 @@ xhci_alloc_pipe(struct usbdevice_s *usbdev in->add = 0x01 | (1 << epid); struct xhci_epctx *ep = (void*)&in[(pipe->epid+1) << xhci->context64]; if (eptype == USB_ENDPOINT_XFER_INT) - ep->ctx[0] = (usb_getFrameExp(usbdev, epdesc) + 3) << 16; + ep->ctx[0] = (usb_get_period(usbdev, epdesc) + 3) << 16; ep->ctx[1] |= eptype << 3; if (epdesc->bEndpointAddress & USB_DIR_IN || eptype == USB_ENDPOINT_XFER_CONTROL) diff --git a/src/hw/usb.c b/src/hw/usb.c index f870481..720e8b0 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -178,8 +178,8 @@ usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev
// Find the exponential period of the requested interrupt end point. int -usb_getFrameExp(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc) +usb_get_period(struct usbdevice_s *usbdev + , struct usb_endpoint_descriptor *epdesc) { int period = epdesc->bInterval; if (usbdev->speed != USB_HIGHSPEED) diff --git a/src/hw/usb.h b/src/hw/usb.h index fe80ea6..0d07032 100644 --- a/src/hw/usb.h +++ b/src/hw/usb.h @@ -239,8 +239,8 @@ void free_pipe(struct usb_pipe *pipe); struct usb_pipe *usb_getFreePipe(struct usb_s *cntl, u8 eptype); void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc); -int usb_getFrameExp(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc); +int usb_get_period(struct usbdevice_s *usbdev + , struct usb_endpoint_descriptor *epdesc); int usb_xfer_time(struct usb_pipe *pipe, int datalen); struct usb_endpoint_descriptor *findEndPointDesc(struct usbdevice_s *usbdev , int type, int dir);
This is just function renaming - no code implementation changes.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-hid.c | 2 +- src/hw/usb-msc.c | 4 ++-- src/hw/usb.c | 4 ++-- src/hw/usb.h | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/hw/usb-hid.c b/src/hw/usb-hid.c index 13f134c..98f323e 100644 --- a/src/hw/usb-hid.c +++ b/src/hw/usb-hid.c @@ -119,7 +119,7 @@ usb_hid_setup(struct usbdevice_s *usbdev) return -1;
// Find intr in endpoint. - struct usb_endpoint_descriptor *epdesc = findEndPointDesc( + struct usb_endpoint_descriptor *epdesc = usb_find_desc( usbdev, USB_ENDPOINT_XFER_INT, USB_DIR_IN); if (!epdesc) { dprintf(1, "No usb hid intr in?\n"); diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index a7af9a7..55d5d63 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -189,9 +189,9 @@ usb_msc_setup(struct usbdevice_s *usbdev)
// Find bulk in and bulk out endpoints. struct usb_pipe *inpipe = NULL, *outpipe = NULL; - struct usb_endpoint_descriptor *indesc = findEndPointDesc( + struct usb_endpoint_descriptor *indesc = usb_find_desc( usbdev, USB_ENDPOINT_XFER_BULK, USB_DIR_IN); - struct usb_endpoint_descriptor *outdesc = findEndPointDesc( + struct usb_endpoint_descriptor *outdesc = usb_find_desc( usbdev, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT); if (!indesc || !outdesc) goto fail; diff --git a/src/hw/usb.c b/src/hw/usb.c index 720e8b0..cfeeb8e 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -200,9 +200,9 @@ usb_xfer_time(struct usb_pipe *pipe, int datalen) return USB_TIME_COMMAND + 100; }
-// Find the first endpoing of a given type in an interface description. +// Find the first endpoint of a given type in an interface description. struct usb_endpoint_descriptor * -findEndPointDesc(struct usbdevice_s *usbdev, int type, int dir) +usb_find_desc(struct usbdevice_s *usbdev, int type, int dir) { struct usb_endpoint_descriptor *epdesc = (void*)&usbdev->iface[1]; for (;;) { diff --git a/src/hw/usb.h b/src/hw/usb.h index 0d07032..cadf543 100644 --- a/src/hw/usb.h +++ b/src/hw/usb.h @@ -242,8 +242,8 @@ void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev int usb_get_period(struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc); int usb_xfer_time(struct usb_pipe *pipe, int datalen); -struct usb_endpoint_descriptor *findEndPointDesc(struct usbdevice_s *usbdev - , int type, int dir); +struct usb_endpoint_descriptor *usb_find_desc(struct usbdevice_s *usbdev + , int type, int dir); void usb_enumerate(struct usbhub_s *hub); void usb_setup(void);
This is just function renaming - no code implementation changes.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-hid.c | 4 ++-- src/hw/usb-hub.c | 8 ++++---- src/hw/usb-msc.c | 2 +- src/hw/usb.c | 14 +++++++------- src/hw/usb.h | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/hw/usb-hid.c b/src/hw/usb-hid.c index 98f323e..09a6cf4 100644 --- a/src/hw/usb-hid.c +++ b/src/hw/usb-hid.c @@ -30,7 +30,7 @@ set_protocol(struct usb_pipe *pipe, u16 val) req.wValue = val; req.wIndex = 0; req.wLength = 0; - return send_default_control(pipe, &req, NULL); + return usb_send_default_control(pipe, &req, NULL); }
// Send USB HID SetIdle request. @@ -43,7 +43,7 @@ set_idle(struct usb_pipe *pipe, int ms) req.wValue = (ms/4)<<8; req.wIndex = 0; req.wLength = 0; - return send_default_control(pipe, &req, NULL); + return usb_send_default_control(pipe, &req, NULL); }
#define KEYREPEATWAITMS 500 diff --git a/src/hw/usb-hub.c b/src/hw/usb-hub.c index 4731a91..c21cbfb 100644 --- a/src/hw/usb-hub.c +++ b/src/hw/usb-hub.c @@ -20,7 +20,7 @@ get_hub_desc(struct usb_pipe *pipe, struct usb_hub_descriptor *desc) req.wValue = USB_DT_HUB<<8; req.wIndex = 0; req.wLength = sizeof(*desc); - return send_default_control(pipe, &req, desc); + return usb_send_default_control(pipe, &req, desc); }
static int @@ -33,7 +33,7 @@ set_port_feature(struct usbhub_s *hub, int port, int feature) req.wIndex = port + 1; req.wLength = 0; mutex_lock(&hub->lock); - int ret = send_default_control(hub->usbdev->defpipe, &req, NULL); + int ret = usb_send_default_control(hub->usbdev->defpipe, &req, NULL); mutex_unlock(&hub->lock); return ret; } @@ -48,7 +48,7 @@ clear_port_feature(struct usbhub_s *hub, int port, int feature) req.wIndex = port + 1; req.wLength = 0; mutex_lock(&hub->lock); - int ret = send_default_control(hub->usbdev->defpipe, &req, NULL); + int ret = usb_send_default_control(hub->usbdev->defpipe, &req, NULL); mutex_unlock(&hub->lock); return ret; } @@ -63,7 +63,7 @@ get_port_status(struct usbhub_s *hub, int port, struct usb_port_status *sts) req.wIndex = port + 1; req.wLength = sizeof(*sts); mutex_lock(&hub->lock); - int ret = send_default_control(hub->usbdev->defpipe, &req, sts); + int ret = usb_send_default_control(hub->usbdev->defpipe, &req, sts); mutex_unlock(&hub->lock); return ret; } diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index 55d5d63..388cbe5 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -130,7 +130,7 @@ usb_msc_maxlun(struct usb_pipe *pipe) req.wIndex = 0; req.wLength = 1; unsigned char maxlun; - int ret = send_default_control(pipe, &req, &maxlun); + int ret = usb_send_default_control(pipe, &req, &maxlun); if (ret) return 0; return maxlun; diff --git a/src/hw/usb.c b/src/hw/usb.c index cfeeb8e..dfd2c89 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -125,8 +125,8 @@ int usb_32bit_pipe(struct usb_pipe *pipe_fl)
// Send a message to the default control pipe of a device. int -send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req - , void *data) +usb_send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req + , void *data) { return usb_send_control(pipe, req->bRequestType & USB_DIR_IN , req, sizeof(*req), data, req->wLength); @@ -228,7 +228,7 @@ get_device_info8(struct usb_pipe *pipe, struct usb_device_descriptor *dinfo) req.wValue = USB_DT_DEVICE<<8; req.wIndex = 0; req.wLength = 8; - return send_default_control(pipe, &req, dinfo); + return usb_send_default_control(pipe, &req, dinfo); }
static struct usb_config_descriptor * @@ -242,7 +242,7 @@ get_device_config(struct usb_pipe *pipe) req.wValue = USB_DT_CONFIG<<8; req.wIndex = 0; req.wLength = sizeof(cfg); - int ret = send_default_control(pipe, &req, &cfg); + int ret = usb_send_default_control(pipe, &req, &cfg); if (ret) return NULL;
@@ -250,7 +250,7 @@ get_device_config(struct usb_pipe *pipe) if (!config) return NULL; req.wLength = cfg.wTotalLength; - ret = send_default_control(pipe, &req, config); + ret = usb_send_default_control(pipe, &req, config); if (ret) return NULL; //hexdump(config, cfg.wTotalLength); @@ -266,7 +266,7 @@ set_configuration(struct usb_pipe *pipe, u16 val) req.wValue = val; req.wIndex = 0; req.wLength = 0; - return send_default_control(pipe, &req, NULL); + return usb_send_default_control(pipe, &req, NULL); }
@@ -310,7 +310,7 @@ usb_set_address(struct usbdevice_s *usbdev) req.wValue = cntl->maxaddr + 1; req.wIndex = 0; req.wLength = 0; - int ret = send_default_control(usbdev->defpipe, &req, NULL); + int ret = usb_send_default_control(usbdev->defpipe, &req, NULL); if (ret) { free_pipe(usbdev->defpipe); return -1; diff --git a/src/hw/usb.h b/src/hw/usb.h index cadf543..bcbad77 100644 --- a/src/hw/usb.h +++ b/src/hw/usb.h @@ -233,8 +233,8 @@ struct usb_pipe *usb_alloc_pipe(struct usbdevice_s *usbdev 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); -int send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req - , void *data); +int usb_send_default_control(struct usb_pipe *pipe + , const struct usb_ctrlrequest *req, void *data); void free_pipe(struct usb_pipe *pipe); struct usb_pipe *usb_getFreePipe(struct usb_s *cntl, u8 eptype); void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev
Also, pass in usbdev to usb_free_pipe().
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-msc.c | 4 ++-- src/hw/usb-uas.c | 8 ++++---- src/hw/usb.c | 8 ++++---- src/hw/usb.h | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index 388cbe5..d90319f 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -214,7 +214,7 @@ usb_msc_setup(struct usbdevice_s *usbdev) return 0; fail: dprintf(1, "Unable to configure USB MSC device.\n"); - free_pipe(inpipe); - free_pipe(outpipe); + usb_free_pipe(usbdev, inpipe); + usb_free_pipe(usbdev, outpipe); return -1; } diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index 9474383..6ef8d09 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -266,9 +266,9 @@ usb_uas_setup(struct usbdevice_s *usbdev) return 0;
fail: - free_pipe(command); - free_pipe(status); - free_pipe(data_in); - free_pipe(data_out); + usb_free_pipe(usbdev, command); + usb_free_pipe(usbdev, status); + usb_free_pipe(usbdev, data_in); + usb_free_pipe(usbdev, data_out); return -1; } diff --git a/src/hw/usb.c b/src/hw/usb.c index dfd2c89..c7cb674 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -53,7 +53,7 @@ usb_update_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe case USB_TYPE_XHCI: return xhci_update_pipe(usbdev, pipe, epdesc); default: - free_pipe(pipe); + usb_free_pipe(usbdev, pipe); return usb_alloc_pipe(usbdev, epdesc); } } @@ -134,7 +134,7 @@ usb_send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *re
// Free an allocated control or bulk pipe. void -free_pipe(struct usb_pipe *pipe) +usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe) { ASSERT32FLAT(); if (!pipe) @@ -312,7 +312,7 @@ usb_set_address(struct usbdevice_s *usbdev) req.wLength = 0; int ret = usb_send_default_control(usbdev->defpipe, &req, NULL); if (ret) { - free_pipe(usbdev->defpipe); + usb_free_pipe(usbdev, usbdev->defpipe); return -1; }
@@ -436,7 +436,7 @@ usb_hub_port_setup(void *data)
// Configure the device int count = configure_usb_device(usbdev); - free_pipe(usbdev->defpipe); + usb_free_pipe(usbdev, usbdev->defpipe); if (!count) hub->op->disconnect(hub, port); hub->devcount += count; diff --git a/src/hw/usb.h b/src/hw/usb.h index bcbad77..e6948de 100644 --- a/src/hw/usb.h +++ b/src/hw/usb.h @@ -235,7 +235,7 @@ int usb_poll_intr(struct usb_pipe *pipe, void *data); int usb_32bit_pipe(struct usb_pipe *pipe_fl); int usb_send_default_control(struct usb_pipe *pipe , const struct usb_ctrlrequest *req, void *data); -void free_pipe(struct usb_pipe *pipe); +void usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe); struct usb_pipe *usb_getFreePipe(struct usb_s *cntl, u8 eptype); void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc);
Rename usb_getFreePipe() to usb_get_freelist(). Add usb_is_freelist() and usb_add_freelist() functions.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-ehci.c | 4 ++-- src/hw/usb-ohci.c | 4 ++-- src/hw/usb-uhci.c | 4 ++-- src/hw/usb.c | 25 ++++++++++++++++++++----- src/hw/usb.h | 4 +++- 5 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index 2376b1f..1df7ec8 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -195,7 +195,7 @@ ehci_free_pipes(struct usb_ehci_s *cntl) if (next == start) break; struct ehci_pipe *pipe = container_of(next, struct ehci_pipe, qh); - if (pipe->pipe.cntl != &cntl->usb) + if (usb_is_freelist(&cntl->usb, &pipe->pipe)) pos->next = next->next; else pos = next; @@ -457,7 +457,7 @@ ehci_alloc_pipe(struct usbdevice_s *usbdev usbdev->hub->cntl, struct usb_ehci_s, usb); dprintf(7, "ehci_alloc_async_pipe %p %d\n", &cntl->usb, eptype);
- struct usb_pipe *usbpipe = usb_getFreePipe(&cntl->usb, eptype); + struct usb_pipe *usbpipe = usb_get_freelist(&cntl->usb, eptype); if (usbpipe) { // Use previously allocated pipe. struct ehci_pipe *pipe = container_of(usbpipe, struct ehci_pipe, pipe); diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index a91e24d..d19b667 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -152,7 +152,7 @@ ohci_free_pipes(struct usb_ohci_s *cntl) if (!next) break; struct ohci_pipe *pipe = container_of(next, struct ohci_pipe, ed); - if (pipe->pipe.cntl != &cntl->usb) { + if (usb_is_freelist(&cntl->usb, &pipe->pipe)) { *pos = next->hwNextED; free(pipe); } else { @@ -403,7 +403,7 @@ ohci_alloc_pipe(struct usbdevice_s *usbdev usbdev->hub->cntl, struct usb_ohci_s, usb); dprintf(7, "ohci_alloc_async_pipe %p\n", &cntl->usb);
- struct usb_pipe *usbpipe = usb_getFreePipe(&cntl->usb, eptype); + struct usb_pipe *usbpipe = usb_get_freelist(&cntl->usb, eptype); if (usbpipe) { // Use previously allocated pipe. struct ohci_pipe *pipe = container_of(usbpipe, struct ohci_pipe, pipe); diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index a270a82..e940d91 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -138,7 +138,7 @@ uhci_free_pipes(struct usb_uhci_s *cntl) break; struct uhci_qh *next = (void*)(link & ~UHCI_PTR_BITS); struct uhci_pipe *pipe = container_of(next, struct uhci_pipe, qh); - if (pipe->pipe.cntl != &cntl->usb) + if (usb_is_freelist(&cntl->usb, &pipe->pipe)) pos->link = next->link; else pos = next; @@ -364,7 +364,7 @@ uhci_alloc_pipe(struct usbdevice_s *usbdev usbdev->hub->cntl, struct usb_uhci_s, usb); dprintf(7, "uhci_alloc_async_pipe %p %d\n", &cntl->usb, eptype);
- struct usb_pipe *usbpipe = usb_getFreePipe(&cntl->usb, eptype); + struct usb_pipe *usbpipe = usb_get_freelist(&cntl->usb, eptype); if (usbpipe) { // Use previously allocated pipe. usb_desc2pipe(usbpipe, usbdev, epdesc); diff --git a/src/hw/usb.c b/src/hw/usb.c index c7cb674..f7d5502 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -132,14 +132,19 @@ usb_send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *re , req, sizeof(*req), data, req->wLength); }
-// Free an allocated control or bulk pipe. +// Check if a pipe for a given controller is on the freelist +int +usb_is_freelist(struct usb_s *cntl, struct usb_pipe *pipe) +{ + return pipe->cntl != cntl; +} + +// Add a pipe to the controller's freelist void -usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe) +usb_add_freelist(struct usb_pipe *pipe) { - ASSERT32FLAT(); if (!pipe) return; - // Add to controller's free list. struct usb_s *cntl = pipe->cntl; pipe->freenext = cntl->freelist; cntl->freelist = pipe; @@ -147,7 +152,7 @@ usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe)
// Check for an available pipe on the freelist. struct usb_pipe * -usb_getFreePipe(struct usb_s *cntl, u8 eptype) +usb_get_freelist(struct usb_s *cntl, u8 eptype) { struct usb_pipe **pfree = &cntl->freelist; for (;;) { @@ -162,6 +167,16 @@ usb_getFreePipe(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 diff --git a/src/hw/usb.h b/src/hw/usb.h index e6948de..8e3e60a 100644 --- a/src/hw/usb.h +++ b/src/hw/usb.h @@ -235,8 +235,10 @@ int usb_poll_intr(struct usb_pipe *pipe, void *data); int usb_32bit_pipe(struct usb_pipe *pipe_fl); 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); -struct usb_pipe *usb_getFreePipe(struct usb_s *cntl, u8 eptype); void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc); int usb_get_period(struct usbdevice_s *usbdev
Instead of exporting both xhci_alloc_pipe() and xhci_update_pipe(), export only xhci_realloc_pipe() and support alloc, update, and free from it.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-xhci.c | 12 +++++++++--- src/hw/usb-xhci.h | 8 +++----- src/hw/usb.c | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c index 0b8ed64..3bcc465 100644 --- a/src/hw/usb-xhci.c +++ b/src/hw/usb-xhci.c @@ -972,7 +972,7 @@ static int xhci_config_hub(struct usbhub_s *hub) return 0; }
-struct usb_pipe * +static struct usb_pipe * xhci_alloc_pipe(struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc) { @@ -1077,11 +1077,17 @@ fail: }
struct usb_pipe * -xhci_update_pipe(struct usbdevice_s *usbdev, struct usb_pipe *upipe - , struct usb_endpoint_descriptor *epdesc) +xhci_realloc_pipe(struct usbdevice_s *usbdev, struct usb_pipe *upipe + , struct usb_endpoint_descriptor *epdesc) { if (!CONFIG_USB_XHCI) return NULL; + if (!epdesc) { + usb_add_freelist(upipe); + return NULL; + } + if (!upipe) + return xhci_alloc_pipe(usbdev, epdesc); u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; int oldmaxpacket = upipe->maxpacket; usb_desc2pipe(upipe, usbdev, epdesc); diff --git a/src/hw/usb-xhci.h b/src/hw/usb-xhci.h index 7639409..807d597 100644 --- a/src/hw/usb-xhci.h +++ b/src/hw/usb-xhci.h @@ -9,11 +9,9 @@ struct usb_pipe;
// usb-xhci.c void xhci_setup(void); -struct usb_pipe *xhci_alloc_pipe(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc); -struct usb_pipe *xhci_update_pipe(struct usbdevice_s *usbdev - , struct usb_pipe *pipe - , struct usb_endpoint_descriptor *epdesc); +struct usb_pipe *xhci_realloc_pipe(struct usbdevice_s *usbdev + , struct usb_pipe *upipe + , struct usb_endpoint_descriptor *epdesc); int xhci_send_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize , void *data, int datasize); int xhci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize); diff --git a/src/hw/usb.c b/src/hw/usb.c index f7d5502..1fb5051 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -40,7 +40,7 @@ usb_alloc_pipe(struct usbdevice_s *usbdev case USB_TYPE_EHCI: return ehci_alloc_pipe(usbdev, epdesc); case USB_TYPE_XHCI: - return xhci_alloc_pipe(usbdev, epdesc); + return xhci_realloc_pipe(usbdev, NULL, epdesc); } }
@@ -51,7 +51,7 @@ usb_update_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe { switch (usbdev->hub->cntl->type) { case USB_TYPE_XHCI: - return xhci_update_pipe(usbdev, pipe, epdesc); + return xhci_realloc_pipe(usbdev, pipe, epdesc); default: usb_free_pipe(usbdev, pipe); return usb_alloc_pipe(usbdev, epdesc);
Support alloc, update, and free from the single exported function.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-uhci.c | 7 +++++-- src/hw/usb-uhci.h | 5 +++-- src/hw/usb.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index e940d91..6dcc340 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -352,11 +352,14 @@ fail: }
struct usb_pipe * -uhci_alloc_pipe(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc) +uhci_realloc_pipe(struct usbdevice_s *usbdev, struct usb_pipe *upipe + , struct usb_endpoint_descriptor *epdesc) { if (! CONFIG_USB_UHCI) return NULL; + usb_add_freelist(upipe); + if (!epdesc) + return NULL; u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; if (eptype == USB_ENDPOINT_XFER_INT) return uhci_alloc_intr_pipe(usbdev, epdesc); diff --git a/src/hw/usb-uhci.h b/src/hw/usb-uhci.h index 6b675bb..541954a 100644 --- a/src/hw/usb-uhci.h +++ b/src/hw/usb-uhci.h @@ -5,9 +5,10 @@ void uhci_setup(void); struct usbdevice_s; struct usb_endpoint_descriptor; -struct usb_pipe *uhci_alloc_pipe(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc); struct usb_pipe; +struct usb_pipe *uhci_realloc_pipe(struct usbdevice_s *usbdev + , struct usb_pipe *upipe + , struct usb_endpoint_descriptor *epdesc); int uhci_send_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); diff --git a/src/hw/usb.c b/src/hw/usb.c index 1fb5051..5110053 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -34,7 +34,7 @@ usb_alloc_pipe(struct usbdevice_s *usbdev switch (usbdev->hub->cntl->type) { default: case USB_TYPE_UHCI: - return uhci_alloc_pipe(usbdev, epdesc); + return uhci_realloc_pipe(usbdev, NULL, epdesc); case USB_TYPE_OHCI: return ohci_alloc_pipe(usbdev, epdesc); case USB_TYPE_EHCI:
Support alloc, update, and free from the single exported function.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-ohci.c | 7 +++++-- src/hw/usb-ohci.h | 5 +++-- src/hw/usb.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index d19b667..4789768 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -387,11 +387,14 @@ err: }
struct usb_pipe * -ohci_alloc_pipe(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc) +ohci_realloc_pipe(struct usbdevice_s *usbdev, struct usb_pipe *upipe + , struct usb_endpoint_descriptor *epdesc) { if (! CONFIG_USB_OHCI) return NULL; + usb_add_freelist(upipe); + if (!epdesc) + return NULL; u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; if (eptype == USB_ENDPOINT_XFER_INT) return ohci_alloc_intr_pipe(usbdev, epdesc); diff --git a/src/hw/usb-ohci.h b/src/hw/usb-ohci.h index 14d2b1a..5699523 100644 --- a/src/hw/usb-ohci.h +++ b/src/hw/usb-ohci.h @@ -5,9 +5,10 @@ void ohci_setup(void); struct usbdevice_s; struct usb_endpoint_descriptor; -struct usb_pipe *ohci_alloc_pipe(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc); struct usb_pipe; +struct usb_pipe *ohci_realloc_pipe(struct usbdevice_s *usbdev + , struct usb_pipe *upipe + , struct usb_endpoint_descriptor *epdesc); int ohci_send_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); diff --git a/src/hw/usb.c b/src/hw/usb.c index 5110053..8551c4d 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -36,7 +36,7 @@ usb_alloc_pipe(struct usbdevice_s *usbdev case USB_TYPE_UHCI: return uhci_realloc_pipe(usbdev, NULL, epdesc); case USB_TYPE_OHCI: - return ohci_alloc_pipe(usbdev, epdesc); + return ohci_realloc_pipe(usbdev, NULL, epdesc); case USB_TYPE_EHCI: return ehci_alloc_pipe(usbdev, epdesc); case USB_TYPE_XHCI:
Support alloc, update, and free from the single exported function.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-ehci.c | 7 +++++-- src/hw/usb-ehci.h | 5 +++-- src/hw/usb.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index 1df7ec8..8938915 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -445,11 +445,14 @@ fail: }
struct usb_pipe * -ehci_alloc_pipe(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc) +ehci_realloc_pipe(struct usbdevice_s *usbdev, struct usb_pipe *upipe + , struct usb_endpoint_descriptor *epdesc) { if (! CONFIG_USB_EHCI) return NULL; + usb_add_freelist(upipe); + if (!epdesc) + return NULL; u8 eptype = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; if (eptype == USB_ENDPOINT_XFER_INT) return ehci_alloc_intr_pipe(usbdev, epdesc); diff --git a/src/hw/usb-ehci.h b/src/hw/usb-ehci.h index 6346d78..da74438 100644 --- a/src/hw/usb-ehci.h +++ b/src/hw/usb-ehci.h @@ -5,9 +5,10 @@ void ehci_setup(void); struct usbdevice_s; struct usb_endpoint_descriptor; -struct usb_pipe *ehci_alloc_pipe(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc); struct usb_pipe; +struct usb_pipe *ehci_realloc_pipe(struct usbdevice_s *usbdev + , struct usb_pipe *upipe + , struct usb_endpoint_descriptor *epdesc); int ehci_send_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); diff --git a/src/hw/usb.c b/src/hw/usb.c index 8551c4d..1714968 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -38,7 +38,7 @@ usb_alloc_pipe(struct usbdevice_s *usbdev case USB_TYPE_OHCI: return ohci_realloc_pipe(usbdev, NULL, epdesc); case USB_TYPE_EHCI: - return ehci_alloc_pipe(usbdev, epdesc); + return ehci_realloc_pipe(usbdev, NULL, epdesc); case USB_TYPE_XHCI: return xhci_realloc_pipe(usbdev, NULL, epdesc); }
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 | 60 +++++++++++++++++++++++++++--------------------------------- src/hw/usb.h | 6 +++--- 2 files changed, 30 insertions(+), 36 deletions(-)
diff --git a/src/hw/usb.c b/src/hw/usb.c index 1714968..bb646a7 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 8e3e60a..208d08f 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
On Thu, Oct 16, 2014 at 04:22:52PM -0400, Kevin O'Connor wrote:
The first six patches in this series make the internal usb naming convention a little more standard. (Use a "usb_" prefix on all exported functions and don't use camel case on exported functions.)
The remaining five patches convert the USB controller drivers to a single pipe "realloc" function for managing pipe allocations and freeing. This should make it easier for xhci to implement pipe freeing (not implemented in this series).
FYI, I have pushed this series to the master branch.
-Kevin