From 4547eb904992b12771f040a8c1abc84892a64f98 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 28 Feb 2010 02:17:28 -0500 Subject: [PATCH] Replace USB encoded 'u32 endp' scheme with explicit struct fields. Expand 'struct usb_pipe' with all the fields that are needed from the encoded 'u32 endp' field. --- src/usb-hid.c | 5 +-- src/usb-hub.c | 2 +- src/usb-msc.c | 6 +-- src/usb-ohci.c | 41 +++++++++---------- src/usb-ohci.h | 6 +-- src/usb-uhci.c | 73 +++++++++++++++++---------------- src/usb-uhci.h | 14 +++---- src/usb.c | 108 +++++++++++++++++++++++-------------------------- src/usb.h | 79 ++++++++++++++---------------------- 9 files changed, 151 insertions(+), 183 deletions(-) diff --git a/src/usb-hid.c b/src/usb-hid.c index eae6823..67b5e54 100644 --- a/src/usb-hid.c +++ b/src/usb-hid.c @@ -53,7 +53,7 @@ usb_keyboard_init(struct usb_pipe *pipe if (keyboard_pipe) // XXX - this enables the first found keyboard (could be random) return -1; - dprintf(2, "usb_keyboard_setup %x\n", pipe->endp); + dprintf(2, "usb_keyboard_setup %p\n", pipe); // Find intr in endpoint. struct usb_endpoint_descriptor *epdesc = findEndPointDesc( @@ -72,8 +72,7 @@ usb_keyboard_init(struct usb_pipe *pipe if (ret) return -1; - u32 inendp = mkendpFromDesc(pipe, epdesc); - keyboard_pipe = alloc_intr_pipe(inendp, epdesc->bInterval); + keyboard_pipe = alloc_intr_pipe(pipe, epdesc); if (!keyboard_pipe) return -1; diff --git a/src/usb-hub.c b/src/usb-hub.c index da7d9f8..ce40099 100644 --- a/src/usb-hub.c +++ b/src/usb-hub.c @@ -168,7 +168,7 @@ usb_hub_init(struct usb_pipe *pipe) struct usbhub_s hub; memset(&hub, 0, sizeof(hub)); hub.pipe = pipe; - hub.cntl = endp2cntl(pipe->endp); + hub.cntl = pipe->cntl; hub.powerwait = desc.bPwrOn2PwrGood * 2; // Launch a thread for every port. diff --git a/src/usb-msc.c b/src/usb-msc.c index cb60c3e..a7047fd 100644 --- a/src/usb-msc.c +++ b/src/usb-msc.c @@ -194,10 +194,8 @@ usb_msc_init(struct usb_pipe *pipe iface, imax, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT); if (!indesc || !outdesc) goto fail; - u32 inendp = mkendpFromDesc(pipe, indesc); - struct usb_pipe *bulkin = alloc_bulk_pipe(inendp); - u32 outendp = mkendpFromDesc(pipe, outdesc); - struct usb_pipe *bulkout = alloc_bulk_pipe(outendp); + struct usb_pipe *bulkin = alloc_bulk_pipe(pipe, indesc); + struct usb_pipe *bulkout = alloc_bulk_pipe(pipe, outdesc); if (!bulkin || !bulkout) goto fail; diff --git a/src/usb-ohci.c b/src/usb-ohci.c index 3e94de6..d825964 100644 --- a/src/usb-ohci.c +++ b/src/usb-ohci.c @@ -300,10 +300,9 @@ ohci_free_pipe(struct usb_pipe *p) { if (! CONFIG_USB_OHCI) return; + dprintf(7, "ohci_free_pipe %p\n", p); struct ohci_pipe *pipe = container_of(p, struct ohci_pipe, pipe); - u32 endp = pipe->pipe.endp; - dprintf(7, "ohci_free_pipe %x\n", endp); - struct usb_s *cntl = endp2cntl(endp); + struct usb_s *cntl = pipe->pipe.cntl; u32 *pos = &cntl->ohci.regs->ed_controlhead; for (;;) { @@ -324,12 +323,12 @@ ohci_free_pipe(struct usb_pipe *p) } struct usb_pipe * -ohci_alloc_control_pipe(u32 endp) +ohci_alloc_control_pipe(struct usb_pipe *dummy) { if (! CONFIG_USB_OHCI) return NULL; - struct usb_s *cntl = endp2cntl(endp); - dprintf(7, "ohci_alloc_control_pipe %x\n", endp); + struct usb_s *cntl = dummy->cntl; + dprintf(7, "ohci_alloc_control_pipe %p\n", cntl); // Allocate a queue head. struct ohci_pipe *pipe = malloc_tmphigh(sizeof(*pipe)); @@ -339,7 +338,7 @@ ohci_alloc_control_pipe(u32 endp) } memset(pipe, 0, sizeof(*pipe)); pipe->ed.hwINFO = ED_SKIP; - pipe->pipe.endp = endp; + memcpy(&pipe->pipe, dummy, sizeof(pipe->pipe)); // Add queue head to controller list. pipe->ed.hwNextED = cntl->ohci.regs->ed_controlhead; @@ -354,18 +353,17 @@ ohci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize { if (! CONFIG_USB_OHCI) return -1; + dprintf(5, "ohci_control %p\n", p); if (datasize > 4096) { // XXX - should support larger sizes. warn_noalloc(); return -1; } struct ohci_pipe *pipe = container_of(p, struct ohci_pipe, pipe); - u32 endp = pipe->pipe.endp; - dprintf(5, "ohci_control %x\n", endp); - struct usb_s *cntl = endp2cntl(endp); - int maxpacket = endp2maxsize(endp); - int lowspeed = endp2speed(endp); - int devaddr = endp2devaddr(endp) | (endp2ep(endp) << 7); + struct usb_s *cntl = pipe->pipe.cntl; + int maxpacket = pipe->pipe.maxpacket; + int lowspeed = pipe->pipe.lowspeed; + int devaddr = pipe->pipe.devaddr | (pipe->pipe.ep << 7); // Setup transfer descriptors struct ohci_td *tds = malloc_tmphigh(sizeof(*tds) * 3); @@ -400,18 +398,18 @@ ohci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize } struct usb_pipe * -ohci_alloc_intr_pipe(u32 endp, int frameexp) +ohci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp) { if (! CONFIG_USB_OHCI) return NULL; + struct usb_s *cntl = dummy->cntl; + dprintf(7, "ohci_alloc_intr_pipe %p %d\n", cntl, frameexp); - dprintf(7, "ohci_alloc_intr_pipe %x %d\n", endp, frameexp); if (frameexp > 5) frameexp = 5; - struct usb_s *cntl = endp2cntl(endp); - int maxpacket = endp2maxsize(endp); - int lowspeed = endp2speed(endp); - int devaddr = endp2devaddr(endp) | (endp2ep(endp) << 7); + int maxpacket = dummy->maxpacket; + int lowspeed = dummy->lowspeed; + int devaddr = dummy->devaddr | (dummy->ep << 7); // Determine number of entries needed for 2 timer ticks. int ms = 1<data = data; pipe->count = count; pipe->tds = tds; - pipe->pipe.endp = endp; + memcpy(&pipe->pipe, dummy, sizeof(pipe->pipe)); return &pipe->pipe; err: @@ -482,8 +480,7 @@ ohci_poll_intr(struct usb_pipe *p, void *data) // XXX - check for errors. // Copy data. - u32 endp = GET_FLATPTR(pipe->pipe.endp); - int maxpacket = endp2maxsize(endp); + int maxpacket = GET_FLATPTR(pipe->pipe.maxpacket); void *pipedata = GET_FLATPTR(pipe->data); void *intrdata = pipedata + maxpacket * pos; memcpy_far(GET_SEG(SS), data diff --git a/src/usb-ohci.h b/src/usb-ohci.h index fadd396..b7b2b29 100644 --- a/src/usb-ohci.h +++ b/src/usb-ohci.h @@ -6,11 +6,11 @@ struct usb_s; void ohci_init(void *data); struct usb_pipe; void ohci_free_pipe(struct usb_pipe *p); -struct usb_pipe *ohci_alloc_control_pipe(u32 endp); +struct usb_pipe *ohci_alloc_control_pipe(struct usb_pipe *dummy); int ohci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize , void *data, int datasize); -struct usb_pipe *ohci_alloc_intr_pipe(u32 endp, int frameexp); -int ohci_poll_intr(struct usb_pipe *pipe, void *data); +struct usb_pipe *ohci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp); +int ohci_poll_intr(struct usb_pipe *p, void *data); /**************************************************************** diff --git a/src/usb-uhci.c b/src/usb-uhci.c index 86eecea..a870963 100644 --- a/src/usb-uhci.c +++ b/src/usb-uhci.c @@ -251,10 +251,9 @@ uhci_free_pipe(struct usb_pipe *p) { if (! CONFIG_USB_UHCI) return; + dprintf(7, "uhci_free_pipe %p\n", p); struct uhci_pipe *pipe = container_of(p, struct uhci_pipe, pipe); - u32 endp = pipe->pipe.endp; - dprintf(7, "uhci_free_pipe %x\n", endp); - struct usb_s *cntl = endp2cntl(endp); + struct usb_s *cntl = pipe->pipe.cntl; struct uhci_framelist *fl = cntl->uhci.framelist; struct uhci_qh *pos = (void*)(fl->links[0] & ~UHCI_PTR_BITS); @@ -281,12 +280,12 @@ uhci_free_pipe(struct usb_pipe *p) } struct usb_pipe * -uhci_alloc_control_pipe(u32 endp) +uhci_alloc_control_pipe(struct usb_pipe *dummy) { if (! CONFIG_USB_UHCI) return NULL; - struct usb_s *cntl = endp2cntl(endp); - dprintf(7, "uhci_alloc_control_pipe %x\n", endp); + struct usb_s *cntl = dummy->cntl; + dprintf(7, "uhci_alloc_control_pipe %p\n", cntl); // Allocate a queue head. struct uhci_pipe *pipe = malloc_tmphigh(sizeof(*pipe)); @@ -294,9 +293,9 @@ uhci_alloc_control_pipe(u32 endp) warn_noalloc(); return NULL; } + memset(pipe, 0, sizeof(*pipe)); pipe->qh.element = UHCI_PTR_TERM; - pipe->next_td = 0; - pipe->pipe.endp = endp; + memcpy(&pipe->pipe, dummy, sizeof(pipe->pipe)); // Add queue head to controller list. struct uhci_qh *control_qh = cntl->uhci.control_qh; @@ -315,14 +314,13 @@ uhci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize ASSERT32FLAT(); if (! CONFIG_USB_UHCI) return -1; + dprintf(5, "uhci_control %p\n", p); struct uhci_pipe *pipe = container_of(p, struct uhci_pipe, pipe); - u32 endp = pipe->pipe.endp; - dprintf(5, "uhci_control %x\n", endp); - struct usb_s *cntl = endp2cntl(endp); - int maxpacket = endp2maxsize(endp); - int lowspeed = endp2speed(endp); - int devaddr = endp2devaddr(endp) | (endp2ep(endp) << 7); + struct usb_s *cntl = pipe->pipe.cntl; + int maxpacket = pipe->pipe.maxpacket; + int lowspeed = pipe->pipe.lowspeed; + int devaddr = pipe->pipe.devaddr | (pipe->pipe.ep << 7); // Setup transfer descriptors int count = 2 + DIV_ROUND_UP(datasize, maxpacket); @@ -368,12 +366,12 @@ uhci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize } struct usb_pipe * -uhci_alloc_bulk_pipe(u32 endp) +uhci_alloc_bulk_pipe(struct usb_pipe *dummy) { if (! CONFIG_USB_UHCI) return NULL; - struct usb_s *cntl = endp2cntl(endp); - dprintf(7, "uhci_alloc_bulk_pipe %x\n", endp); + struct usb_s *cntl = dummy->cntl; + dprintf(7, "uhci_alloc_bulk_pipe %p\n", cntl); // Allocate a queue head. struct uhci_pipe *pipe = malloc_low(sizeof(*pipe)); @@ -381,9 +379,9 @@ uhci_alloc_bulk_pipe(u32 endp) warn_noalloc(); return NULL; } + memset(pipe, 0, sizeof(*pipe)); pipe->qh.element = UHCI_PTR_TERM; - pipe->next_td = 0; - pipe->pipe.endp = endp; + memcpy(&pipe->pipe, dummy, sizeof(pipe->pipe)); // Add queue head to controller list. struct uhci_qh *bulk_qh = cntl->uhci.bulk_qh; @@ -423,13 +421,13 @@ int uhci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize) { struct uhci_pipe *pipe = container_of(p, struct uhci_pipe, pipe); - u32 endp = GET_FLATPTR(pipe->pipe.endp); - dprintf(7, "uhci_send_bulk qh=%p endp=%x dir=%d data=%p size=%d\n" - , &pipe->qh, endp, dir, data, datasize); - int maxpacket = endp2maxsize(endp); - int lowspeed = endp2speed(endp); - int devaddr = endp2devaddr(endp) | (endp2ep(endp) << 7); - int toggle = (u32)GET_FLATPTR(pipe->next_td); // XXX + dprintf(7, "uhci_send_bulk qh=%p dir=%d data=%p size=%d\n" + , &pipe->qh, dir, data, datasize); + int maxpacket = GET_FLATPTR(pipe->pipe.maxpacket); + int lowspeed = GET_FLATPTR(pipe->pipe.lowspeed); + int devaddr = (GET_FLATPTR(pipe->pipe.devaddr) + | (GET_FLATPTR(pipe->pipe.ep) << 7)); + int toggle = GET_FLATPTR(pipe->pipe.toggle) ? TD_TOKEN_TOGGLE : 0; // Allocate 4 tds on stack (16byte aligned) u8 tdsbuf[sizeof(struct uhci_td) * STACKTDS + TDALIGN - 1]; @@ -472,28 +470,28 @@ uhci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize) goto fail; } - SET_FLATPTR(pipe->next_td, (void*)toggle); // XXX + SET_FLATPTR(pipe->pipe.toggle, !!toggle); return 0; fail: dprintf(1, "uhci_send_bulk failed\n"); SET_FLATPTR(pipe->qh.element, UHCI_PTR_TERM); - uhci_waittick(endp2cntl(endp)); + uhci_waittick(GET_FLATPTR(pipe->pipe.cntl)); return -1; } struct usb_pipe * -uhci_alloc_intr_pipe(u32 endp, int frameexp) +uhci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp) { if (! CONFIG_USB_UHCI) return NULL; + struct usb_s *cntl = dummy->cntl; + dprintf(7, "uhci_alloc_intr_pipe %p %d\n", cntl, frameexp); - dprintf(7, "uhci_alloc_intr_pipe %x %d\n", endp, frameexp); if (frameexp > 10) frameexp = 10; - struct usb_s *cntl = endp2cntl(endp); - int maxpacket = endp2maxsize(endp); - int lowspeed = endp2speed(endp); - int devaddr = endp2devaddr(endp) | (endp2ep(endp) << 7); + int maxpacket = dummy->maxpacket; + int lowspeed = dummy->lowspeed; + int devaddr = dummy->devaddr | (dummy->ep << 7); // Determine number of entries needed for 2 timer ticks. int ms = 1< sizeof(tds[0].data)) goto fail; + memset(pipe, 0, sizeof(*pipe)); pipe->qh.element = (u32)tds; + pipe->next_td = &tds[0]; + memcpy(&pipe->pipe, dummy, sizeof(pipe->pipe)); + int toggle = 0; int i; for (i=0; inext_td = &tds[0]; - pipe->pipe.endp = endp; - // Add to interrupt schedule. struct uhci_framelist *fl = cntl->uhci.framelist; if (frameexp == 0) { diff --git a/src/usb-uhci.h b/src/usb-uhci.h index 8dbee9c..894027b 100644 --- a/src/usb-uhci.h +++ b/src/usb-uhci.h @@ -4,14 +4,14 @@ // usb-uhci.c void uhci_init(void *data); struct usb_pipe; -void uhci_free_pipe(struct usb_pipe *pipe); -struct usb_pipe *uhci_alloc_control_pipe(u32 endp); -int uhci_control(struct usb_pipe *pipe, int dir, const void *cmd, int cmdsize +void uhci_free_pipe(struct usb_pipe *p); +struct usb_pipe *uhci_alloc_control_pipe(struct usb_pipe *dummy); +int uhci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize , void *data, int datasize); -struct usb_pipe *uhci_alloc_bulk_pipe(u32 endp); -int uhci_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize); -struct usb_pipe *uhci_alloc_intr_pipe(u32 endp, int frameexp); -int uhci_poll_intr(struct usb_pipe *pipe, void *data); +struct usb_pipe *uhci_alloc_bulk_pipe(struct usb_pipe *dummy); +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); +int uhci_poll_intr(struct usb_pipe *p, void *data); /**************************************************************** diff --git a/src/usb.c b/src/usb.c index ba70181..57d1ad5 100644 --- a/src/usb.c +++ b/src/usb.c @@ -31,8 +31,7 @@ free_pipe(struct usb_pipe *pipe) ASSERT32FLAT(); if (!pipe) return; - struct usb_s *cntl = endp2cntl(pipe->endp); - switch (cntl->type) { + switch (pipe->type) { default: case USB_TYPE_UHCI: return uhci_free_pipe(pipe); @@ -41,17 +40,17 @@ free_pipe(struct usb_pipe *pipe) } } -// Allocate a control pipe (which can only be used by 32bit code) +// Allocate a control pipe to a default endpoint (which can only be +// used by 32bit code) static struct usb_pipe * -alloc_control_pipe(u32 endp) +alloc_default_control_pipe(struct usb_pipe *dummy) { - struct usb_s *cntl = endp2cntl(endp); - switch (cntl->type) { + switch (dummy->type) { default: case USB_TYPE_UHCI: - return uhci_alloc_control_pipe(endp); + return uhci_alloc_control_pipe(dummy); case USB_TYPE_OHCI: - return ohci_alloc_control_pipe(endp); + return ohci_alloc_control_pipe(dummy); } } @@ -61,8 +60,7 @@ send_control(struct usb_pipe *pipe, int dir, const void *cmd, int cmdsize , void *data, int datasize) { ASSERT32FLAT(); - struct usb_s *cntl = endp2cntl(pipe->endp); - switch (cntl->type) { + switch (pipe->type) { default: case USB_TYPE_UHCI: return uhci_control(pipe, dir, cmd, cmdsize, data, datasize); @@ -71,61 +69,70 @@ send_control(struct usb_pipe *pipe, int dir, const void *cmd, int cmdsize } } +// Fill "pipe" endpoint info from an endpoint descriptor. +static void +desc2pipe(struct usb_pipe *newpipe, struct usb_pipe *origpipe + , struct usb_endpoint_descriptor *epdesc) +{ + memcpy(newpipe, origpipe, sizeof(*newpipe)); + newpipe->ep = epdesc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; + newpipe->maxpacket = epdesc->wMaxPacketSize; +} + struct usb_pipe * -alloc_bulk_pipe(u32 endp) +alloc_bulk_pipe(struct usb_pipe *pipe, struct usb_endpoint_descriptor *epdesc) { - struct usb_s *cntl = endp2cntl(endp); - switch (cntl->type) { + struct usb_pipe dummy; + desc2pipe(&dummy, pipe, epdesc); + switch (pipe->type) { default: case USB_TYPE_UHCI: - return uhci_alloc_bulk_pipe(endp); + return uhci_alloc_bulk_pipe(&dummy); case USB_TYPE_OHCI: return NULL; } } int -usb_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize) +usb_send_bulk(struct usb_pipe *pipe_fl, int dir, void *data, int datasize) { - u32 endp = GET_FLATPTR(pipe->endp); - struct usb_s *cntl = endp2cntl(endp); - switch (cntl->type) { + switch (GET_FLATPTR(pipe_fl->type)) { default: case USB_TYPE_UHCI: - return uhci_send_bulk(pipe, dir, data, datasize); + return uhci_send_bulk(pipe_fl, dir, data, datasize); case USB_TYPE_OHCI: return -1; } } struct usb_pipe * -alloc_intr_pipe(u32 endp, int period) +alloc_intr_pipe(struct usb_pipe *pipe, struct usb_endpoint_descriptor *epdesc) { - struct usb_s *cntl = endp2cntl(endp); + struct usb_pipe dummy; + desc2pipe(&dummy, pipe, epdesc); // Find the exponential period of the requested time. + int period = epdesc->bInterval; if (period <= 0) period = 1; int frameexp = __fls(period); - switch (cntl->type) { + switch (pipe->type) { default: case USB_TYPE_UHCI: - return uhci_alloc_intr_pipe(endp, frameexp); + return uhci_alloc_intr_pipe(&dummy, frameexp); case USB_TYPE_OHCI: - return ohci_alloc_intr_pipe(endp, frameexp); + return ohci_alloc_intr_pipe(&dummy, frameexp); } } int noinline -usb_poll_intr(struct usb_pipe *pipe, void *data) +usb_poll_intr(struct usb_pipe *pipe_fl, void *data) { - u32 endp = GET_FLATPTR(pipe->endp); - struct usb_s *cntl = endp2cntl(endp); - switch (GET_GLOBAL(cntl->type)) { + switch (GET_FLATPTR(pipe_fl->type)) { default: case USB_TYPE_UHCI: - return uhci_poll_intr(pipe, data); + return uhci_poll_intr(pipe_fl, data); case USB_TYPE_OHCI: - return ohci_poll_intr(pipe, data); + return ohci_poll_intr(pipe_fl, data); } } @@ -153,23 +160,6 @@ findEndPointDesc(struct usb_interface_descriptor *iface, int imax } } -// Change endpoint characteristics of the default control pipe. -static void -usb_alter_control(struct usb_pipe *pipe, u32 endp) -{ - pipe->endp = endp; -} - -// Build an encoded "endp" from an endpoint descriptor. -u32 -mkendpFromDesc(struct usb_pipe *pipe, struct usb_endpoint_descriptor *epdesc) -{ - u32 endp = pipe->endp; - return mkendp(endp2cntl(endp), endp2devaddr(endp) - , epdesc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK - , endp2speed(endp), epdesc->wMaxPacketSize); -} - // Send a message to the default control pipe of a device. int send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req @@ -246,13 +236,18 @@ usb_set_address(struct usb_s *cntl, int lowspeed) return NULL; struct usb_pipe *defpipe = cntl->defaultpipe; - u32 endp = mkendp(cntl, 0, 0, lowspeed, 8); if (!defpipe) { - cntl->defaultpipe = defpipe = alloc_control_pipe(endp); + // Create a pipe for the default address. + struct usb_pipe dummy; + memset(&dummy, 0, sizeof(dummy)); + dummy.cntl = cntl; + dummy.type = cntl->type; + dummy.maxpacket = 8; + cntl->defaultpipe = defpipe = alloc_default_control_pipe(&dummy); if (!defpipe) return NULL; } - usb_alter_control(defpipe, endp); + defpipe->lowspeed = lowspeed; msleep(USB_TIME_RSTRCY); @@ -269,8 +264,10 @@ usb_set_address(struct usb_s *cntl, int lowspeed) msleep(USB_TIME_SETADDR_RECOVERY); cntl->maxaddr++; - endp = mkendp(cntl, cntl->maxaddr, 0, lowspeed, 8); - return alloc_control_pipe(endp); + defpipe->devaddr = cntl->maxaddr; + struct usb_pipe *pipe = alloc_default_control_pipe(defpipe); + defpipe->devaddr = 0; + return pipe; } // Called for every found device - see if a driver is available for @@ -279,8 +276,7 @@ int configure_usb_device(struct usb_pipe *pipe) { ASSERT32FLAT(); - struct usb_s *cntl = endp2cntl(pipe->endp); - dprintf(3, "config_usb: %p\n", cntl); + dprintf(3, "config_usb: %p\n", pipe); // Set the max packet size for endpoint 0 of this device. struct usb_device_descriptor dinfo; @@ -292,9 +288,7 @@ configure_usb_device(struct usb_pipe *pipe) , dinfo.bDeviceProtocol, dinfo.bMaxPacketSize0); if (dinfo.bMaxPacketSize0 < 8 || dinfo.bMaxPacketSize0 > 64) return 0; - u32 endp = mkendp(cntl, endp2devaddr(pipe->endp), 0 - , endp2speed(pipe->endp), dinfo.bMaxPacketSize0); - usb_alter_control(pipe, endp); + pipe->maxpacket = dinfo.bMaxPacketSize0; // Get configuration struct usb_config_descriptor *config = get_device_config(pipe); diff --git a/src/usb.h b/src/usb.h index 5a6fc0f..6bc0cfd 100644 --- a/src/usb.h +++ b/src/usb.h @@ -5,7 +5,13 @@ #include "util.h" // struct mutex_s struct usb_pipe { - u32 endp; + struct usb_s *cntl; + u8 type; + u8 ep; + u8 devaddr; + u8 lowspeed; + u16 maxpacket; + u8 toggle; }; // Local information for a usb controller. @@ -34,54 +40,6 @@ extern struct usb_s USBControllers[]; #define USB_MAXADDR 127 -// usb.c -void usb_setup(void); -struct usb_pipe *usb_set_address(struct usb_s *cntl, int lowspeed); -int configure_usb_device(struct usb_pipe *pipe); -struct usb_ctrlrequest; -int send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req - , void *data); -int usb_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize); -void free_pipe(struct usb_pipe *pipe); -struct usb_pipe *alloc_bulk_pipe(u32 endp); -struct usb_pipe *alloc_intr_pipe(u32 endp, int period); -int usb_poll_intr(struct usb_pipe *pipe, void *data); -struct usb_interface_descriptor; -struct usb_endpoint_descriptor *findEndPointDesc( - struct usb_interface_descriptor *iface, int imax, int type, int dir); -u32 mkendpFromDesc(struct usb_pipe *pipe - , struct usb_endpoint_descriptor *epdesc); - - -/**************************************************************** - * endpoint definition - ****************************************************************/ - -static inline u32 -mkendp(struct usb_s *cntl, u8 devaddr, u8 ep, u8 lowspeed, u8 maxsize) -{ - u8 bus = cntl-USBControllers; - u8 size = __ffs(maxsize); - return (size<<25) | (lowspeed<<24) | (bus<<16) | (devaddr<<8) | ep; -} - -static inline u8 endp2ep(u32 endp) { - return endp; -} -static inline u8 endp2devaddr(u32 endp) { - return endp>>8; -} -static inline struct usb_s *endp2cntl(u32 endp) { - u8 bus = endp>>16; - return &USBControllers[bus]; -} -static inline u8 endp2speed(u32 endp) { - return (endp>>24) & 1; -} -static inline u8 endp2maxsize(u32 endp) { - return 1 << (endp>>25); -} - /**************************************************************** * usb structs and flags @@ -216,4 +174,27 @@ struct usb_endpoint_descriptor { #define USB_ENDPOINT_XFER_INT 3 #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 + +/**************************************************************** + * function defs + ****************************************************************/ + +// usb.c +void usb_setup(void); +struct usb_pipe *usb_set_address(struct usb_s *cntl, int lowspeed); +int configure_usb_device(struct usb_pipe *pipe); +int send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req + , void *data); +int usb_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize); +void free_pipe(struct usb_pipe *pipe); +struct usb_pipe *alloc_bulk_pipe(struct usb_pipe *pipe + , struct usb_endpoint_descriptor *epdesc); +struct usb_pipe *alloc_intr_pipe(struct usb_pipe *pipe + , struct usb_endpoint_descriptor *epdesc); +int usb_poll_intr(struct usb_pipe *pipe, void *data); +struct usb_endpoint_descriptor *findEndPointDesc( + struct usb_interface_descriptor *iface, int imax, int type, int dir); +u32 mkendpFromDesc(struct usb_pipe *pipe + , struct usb_endpoint_descriptor *epdesc); + #endif // usb.h -- 2.25.1