From: Leandro Dorilex ldorileo@gmail.com
To fit our current ohci implementation we have to make some hc functions to return int instead of void returning we currenctly verify handle errors using those returns. --- drivers/usb/uhci.c | 32 +++++++++++++++++--------------- drivers/usb/usb.c | 14 +++++++------- drivers/usb/usbmsc.c | 4 ++-- include/usb/usb.h | 9 ++++++--- 4 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/drivers/usb/uhci.c b/drivers/usb/uhci.c index def6b45..7eb947b 100644 --- a/drivers/usb/uhci.c +++ b/drivers/usb/uhci.c @@ -31,19 +31,27 @@ #include "uhci.h" #include <arch/virtual.h>
-static void uhci_start (hci_t *controller); +static int uhci_start (hci_t *controller); static void uhci_stop (hci_t *controller); -static void uhci_reset (hci_t *controller); +static int uhci_reset (hci_t *controller); static void uhci_shutdown (hci_t *controller); static int uhci_packet (usbdev_t *dev, int endp, int pid, int toggle, int length, u8 *data); static int uhci_bulk (endpoint_t *ep, int size, u8 *data, int finalize); -static int uhci_control (usbdev_t *dev, pid_t dir, int drlen, void *devreq, +static int uhci_control (endpoint_t *ep, pid_t dir, int drlen, void *devreq, int dalen, u8 *data); static void* uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming); static void uhci_destroy_intr_queue (endpoint_t *ep, void *queue); static u8* uhci_poll_intr_queue (void *queue);
+int min (int a, int b) +{ + if (a < b) + return a; + else + return b; +} + #if 0 /* dump uhci */ static void @@ -96,7 +104,7 @@ td_dump (td_t *td) printf (" still active - timeout?\n"); }
-static void +static int uhci_reset (hci_t *controller) { /* reset */ @@ -122,6 +130,7 @@ uhci_reset (hci_t *controller) uhci_reg_mask16 (controller, USBCMD, ~0, 0xc0); // max packets, configure flag
uhci_start (controller); + return 1; }
hci_t * @@ -246,10 +255,11 @@ uhci_shutdown (hci_t *controller) free (controller); }
-static void +static int uhci_start (hci_t *controller) { uhci_reg_mask16 (controller, USBCMD, ~0, 1); // start work on schedule + return 1; }
static void @@ -296,18 +306,10 @@ maxlen (int size) }
static int -min (int a, int b) -{ - if (a < b) - return a; - else - return b; -} - -static int -uhci_control (usbdev_t *dev, pid_t dir, int drlen, void *devreq, int dalen, +uhci_control (endpoint_t *ep, pid_t dir, int drlen, void *devreq, int dalen, unsigned char *data) { + usbdev_t *dev = ep->dev; int endp = 0; /* this is control: always 0 */ int mlen = dev->endpoints[0].maxpacketsize; int count = (2 + (dalen + mlen - 1) / mlen); diff --git a/drivers/usb/usb.c b/drivers/usb/usb.c index 25e8006..4a0dbad 100644 --- a/drivers/usb/usb.c +++ b/drivers/usb/usb.c @@ -111,7 +111,7 @@ set_feature (usbdev_t *dev, int endp, int feature, int rtype) dr.wValue = feature; dr.wIndex = endp; dr.wLength = 0; - dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0); + dev->controller->control (&dev->endpoints[0], OUT, sizeof (dr), &dr, 0, 0); }
void @@ -125,7 +125,7 @@ get_status (usbdev_t *dev, int intf, int rtype, int len, void *data) dr.wValue = 0; dr.wIndex = intf; dr.wLength = len; - dev->controller->control (dev, IN, sizeof (dr), &dr, len, data); + dev->controller->control (&dev->endpoints[0], IN, sizeof (dr), &dr, len, data); }
u8 * @@ -143,7 +143,7 @@ get_descriptor (usbdev_t *dev, unsigned char bmRequestType, int descType, dr.wValue = (descType << 8) | descIdx; dr.wIndex = langID; dr.wLength = 8; - if (dev->controller->control (dev, IN, sizeof (dr), &dr, 8, buf)) { + if (dev->controller->control (&dev->endpoints[0], IN, sizeof (dr), &dr, 8, buf)) { printf ("getting descriptor size (type %x) failed\n", descType); } @@ -167,7 +167,7 @@ get_descriptor (usbdev_t *dev, unsigned char bmRequestType, int descType, memset (result, 0, size); dr.wLength = size; if (dev->controller-> - control (dev, IN, sizeof (dr), &dr, size, result)) { + control (&dev->endpoints[0], IN, sizeof (dr), &dr, size, result)) { printf ("getting descriptor (type %x, size %x) failed\n", descType, size); } @@ -185,7 +185,7 @@ set_configuration (usbdev_t *dev) dr.wValue = dev->configuration[5]; dr.wIndex = 0; dr.wLength = 0; - dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0); + dev->controller->control (&dev->endpoints[0], OUT, sizeof (dr), &dr, 0, 0); }
int @@ -203,7 +203,7 @@ clear_stall (endpoint_t *ep) dr.wValue = ENDPOINT_HALT; dr.wIndex = endp; dr.wLength = 0; - dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0); + dev->controller->control (&dev->endpoints[0], OUT, sizeof (dr), &dr, 0, 0); return 0; }
@@ -248,7 +248,7 @@ set_address (hci_t *controller, int lowspeed) dev->endpoints[0].toggle = 0; dev->endpoints[0].direction = SETUP; mdelay (50); - if (dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0)) { + if (dev->controller->control (&dev->endpoints[0], OUT, sizeof (dr), &dr, 0, 0)) { printf ("set_address failed\n"); return -1; } diff --git a/drivers/usb/usbmsc.c b/drivers/usb/usbmsc.c index f24bd6d..fb5d9b6 100644 --- a/drivers/usb/usbmsc.c +++ b/drivers/usb/usbmsc.c @@ -122,7 +122,7 @@ typedef struct { dr.wValue = 0; dr.wIndex = 0; dr.wLength = 0; - dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0); + dev->controller->control (&dev->endpoints[0], OUT, sizeof (dr), &dr, 0, 0); clear_stall (MSC_INST (dev)->bulk_in); clear_stall (MSC_INST (dev)->bulk_out); } @@ -143,7 +143,7 @@ get_max_luns (usbdev_t *dev) dr.wValue = 0; dr.wIndex = 0; dr.wLength = 1; - if (dev->controller->control (dev, IN, sizeof (dr), &dr, 1, &luns)) { + if (dev->controller->control (&dev->endpoints[0], IN, sizeof (dr), &dr, 1, &luns)) { luns = 0; // assume only 1 lun if req fails } return luns; diff --git a/include/usb/usb.h b/include/usb/usb.h index 9f38b84..c3c5f19 100644 --- a/include/usb/usb.h +++ b/include/usb/usb.h @@ -115,14 +115,14 @@ struct usbdev_hc { pcidev_t bus_address; u32 reg_base; usbdev_t *devices[128]; // dev 0 is root hub, 127 is last addressable - void (*start) (hci_t *controller); + int (*start) (hci_t *controller); void (*stop) (hci_t *controller); - void (*reset) (hci_t *controller); + int (*reset) (hci_t *controller); void (*shutdown) (hci_t *controller); int (*packet) (usbdev_t *dev, int endp, int pid, int toggle, int length, u8 *data); int (*bulk) (endpoint_t *ep, int size, u8 *data, int finalize); - int (*control) (usbdev_t *dev, pid_t pid, int dr_length, + int (*control) (endpoint_t *ep, pid_t pid, int dr_length, void *devreq, int data_length, u8 *data); void* (*create_intr_queue) (endpoint_t *ep, int reqsize, int reqcount, int reqtiming); void (*destroy_intr_queue) (endpoint_t *ep, void *queue); @@ -228,4 +228,7 @@ void usb_detach_device(hci_t *controller, int devno); int usb_attach_device(hci_t *controller, int hubaddress, int port, int lowspeed);
void usb_fatal(const char *message) __attribute__ ((noreturn)); + +#define ED_TO_HCI_T(endpoint)((hci_t *) endpoint->dev->controller) + #endif