Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/usb-ehci.c | 10 ++++++---- src/usb-ehci.h | 3 ++- src/usb-ohci.c | 14 ++++++++------ src/usb-ohci.h | 3 ++- src/usb-uhci.c | 14 ++++++++------ src/usb-uhci.h | 3 ++- src/usb.c | 28 +++++++++++++++------------- src/usb.h | 2 ++ 8 files changed, 45 insertions(+), 32 deletions(-)
diff --git a/src/usb-ehci.c b/src/usb-ehci.c index 9721568..477b1cf 100644 --- a/src/usb-ehci.c +++ b/src/usb-ehci.c @@ -621,17 +621,19 @@ ehci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize) }
struct usb_pipe * -ehci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp) +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( - dummy->cntl, struct usb_ehci_s, usb); + usbdev->hub->cntl, struct usb_ehci_s, usb); + int frameexp = usb_getFrameExp(usbdev, epdesc); dprintf(7, "ehci_alloc_intr_pipe %p %d\n", &cntl->usb, frameexp);
if (frameexp > 10) frameexp = 10; - int maxpacket = dummy->maxpacket; + int maxpacket = epdesc->wMaxPacketSize; // Determine number of entries needed for 2 timer ticks. int ms = 1<<frameexp; int count = DIV_ROUND_UP(PIT_TICK_INTERVAL * 1000 * 2, PIT_TICK_RATE * ms); @@ -643,7 +645,7 @@ ehci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp) goto fail; } memset(pipe, 0, sizeof(*pipe)); - memcpy(&pipe->pipe, dummy, sizeof(pipe->pipe)); + usb_desc2pipe(&pipe->pipe, usbdev, epdesc); pipe->next_td = pipe->tds = tds; pipe->data = data;
diff --git a/src/usb-ehci.h b/src/usb-ehci.h index ed2c3f7..958f444 100644 --- a/src/usb-ehci.h +++ b/src/usb-ehci.h @@ -11,7 +11,8 @@ 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 usb_pipe *dummy, int frameexp); +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-ohci.c b/src/usb-ohci.c index 8703b26..a012c6c 100644 --- a/src/usb-ohci.c +++ b/src/usb-ohci.c @@ -425,19 +425,19 @@ ohci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize) }
struct usb_pipe * -ohci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp) +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( - dummy->cntl, struct usb_ohci_s, usb); + usbdev->hub->cntl, struct usb_ohci_s, usb); + int frameexp = usb_getFrameExp(usbdev, epdesc); dprintf(7, "ohci_alloc_intr_pipe %p %d\n", &cntl->usb, frameexp);
if (frameexp > 5) frameexp = 5; - int maxpacket = dummy->maxpacket; - int lowspeed = dummy->speed; - int devaddr = dummy->devaddr | (dummy->ep << 7); + int maxpacket = epdesc->wMaxPacketSize; // Determine number of entries needed for 2 timer ticks. int ms = 1<<frameexp; int count = DIV_ROUND_UP(PIT_TICK_INTERVAL * 1000 * 2, PIT_TICK_RATE * ms)+1; @@ -447,7 +447,9 @@ ohci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp) if (!pipe || !tds || !data) goto err; memset(pipe, 0, sizeof(*pipe)); - memcpy(&pipe->pipe, dummy, sizeof(pipe->pipe)); + usb_desc2pipe(&pipe->pipe, usbdev, epdesc); + int lowspeed = pipe->pipe.speed; + int devaddr = pipe->pipe.devaddr | (pipe->pipe.ep << 7); pipe->data = data; pipe->count = count; pipe->tds = tds; diff --git a/src/usb-ohci.h b/src/usb-ohci.h index bc6eb7b..ab957e6 100644 --- a/src/usb-ohci.h +++ b/src/usb-ohci.h @@ -11,7 +11,8 @@ 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 usb_pipe *dummy, int frameexp); +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 0da4eff..50d98fc 100644 --- a/src/usb-uhci.c +++ b/src/usb-uhci.c @@ -475,19 +475,19 @@ fail: }
struct usb_pipe * -uhci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp) +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( - dummy->cntl, struct usb_uhci_s, usb); + usbdev->hub->cntl, struct usb_uhci_s, usb); + int frameexp = usb_getFrameExp(usbdev, epdesc); dprintf(7, "uhci_alloc_intr_pipe %p %d\n", &cntl->usb, frameexp);
if (frameexp > 10) frameexp = 10; - int maxpacket = dummy->maxpacket; - int lowspeed = dummy->speed; - int devaddr = dummy->devaddr | (dummy->ep << 7); + int maxpacket = epdesc->wMaxPacketSize; // Determine number of entries needed for 2 timer ticks. int ms = 1<<frameexp; int count = DIV_ROUND_UP(PIT_TICK_INTERVAL * 1000 * 2, PIT_TICK_RATE * ms); @@ -500,7 +500,9 @@ uhci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp) goto fail; } memset(pipe, 0, sizeof(*pipe)); - memcpy(&pipe->pipe, dummy, sizeof(pipe->pipe)); + usb_desc2pipe(&pipe->pipe, usbdev, epdesc); + int lowspeed = pipe->pipe.speed; + int devaddr = pipe->pipe.devaddr | (pipe->pipe.ep << 7); pipe->qh.element = (u32)tds; pipe->next_td = &tds[0]; pipe->iobase = cntl->iobase; diff --git a/src/usb-uhci.h b/src/usb-uhci.h index 035a565..708ba59 100644 --- a/src/usb-uhci.h +++ b/src/usb-uhci.h @@ -11,7 +11,8 @@ 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 usb_pipe *dummy, int frameexp); +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 b61fbc1..7276e15 100644 --- a/src/usb.c +++ b/src/usb.c @@ -127,27 +127,29 @@ usb_send_bulk(struct usb_pipe *pipe_fl, int dir, void *data, int datasize) } }
-struct usb_pipe * -alloc_intr_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) { - struct usb_pipe dummy; - usb_desc2pipe(&dummy, usbdev, epdesc); - // Find the exponential period of the requested time. int period = epdesc->bInterval; - int frameexp; if (usbdev->speed != USB_HIGHSPEED) - frameexp = (period <= 0) ? 0 : __fls(period); - else - frameexp = (period <= 4) ? 0 : period - 4; - switch (dummy.type) { + return (period <= 0) ? 0 : __fls(period); + 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(&dummy, frameexp); + return uhci_alloc_intr_pipe(usbdev, epdesc); case USB_TYPE_OHCI: - return ohci_alloc_intr_pipe(&dummy, frameexp); + return ohci_alloc_intr_pipe(usbdev, epdesc); case USB_TYPE_EHCI: - return ehci_alloc_intr_pipe(&dummy, frameexp); + return ehci_alloc_intr_pipe(usbdev, epdesc); } }
diff --git a/src/usb.h b/src/usb.h index c792376..eddf9af 100644 --- a/src/usb.h +++ b/src/usb.h @@ -223,6 +223,8 @@ void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev 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); +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);