[SeaBIOS] [PATCH 08/19] usb: Push 'struct usbdevice_s' usage through to pipe allocation.

Dave Frodin dave at se-eng.com
Mon Mar 12 18:30:36 CET 2012


I had to do some whitespace cleanup in order for patch 08/19 to apply cleanly. I don't have
much experience in applying patches so there might be something I'm missing.

Here are the changes I had to do...

Subject: [PATCH] Whitespace cleanup, replace two tabs with spaces

---
 src/usb-msc.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/usb-msc.c b/src/usb-msc.c
index e143401..62152d8 100644
--- a/src/usb-msc.c
+++ b/src/usb-msc.c
@@ -132,8 +132,8 @@ usb_msc_init(struct usb_pipe *pipe
 
     // Verify right kind of device
     if ((iface->bInterfaceSubClass != US_SC_SCSI &&
-	 iface->bInterfaceSubClass != US_SC_ATAPI_8070 &&
-	 iface->bInterfaceSubClass != US_SC_ATAPI_8020)
+        iface->bInterfaceSubClass != US_SC_ATAPI_8070 &&
+        iface->bInterfaceSubClass != US_SC_ATAPI_8020)
         || iface->bInterfaceProtocol != US_PR_BULK) {
         dprintf(1, "Unsupported MSC USB device (subclass=%02x proto=%02x)\n"
                 , iface->bInterfaceSubClass, iface->bInterfaceProtocol);
-- 
1.7.9

dave

----- Original Message -----
> From: "Kevin O'Connor" <kevin at koconnor.net>
> To: seabios at seabios.org
> Sent: Saturday, March 10, 2012 7:44:46 PM
> Subject: [SeaBIOS] [PATCH 08/19] usb: Push 'struct usbdevice_s' usage through to pipe allocation.
> 
> Pass the usbdevice_s info to device configuration and allocation
> code.
> 
> Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
> ---
>  src/usb-hid.c |   28 +++++++++++++++-------------
>  src/usb-hid.h |    6 ++----
>  src/usb-hub.c |    8 ++++----
>  src/usb-hub.h |    4 ++--
>  src/usb-msc.c |   15 ++++++++-------
>  src/usb-msc.h |    6 ++----
>  src/usb.c     |   35 +++++++++++++++++++----------------
>  src/usb.h     |   13 +++++++------
>  8 files changed, 59 insertions(+), 56 deletions(-)
> 
> diff --git a/src/usb-hid.c b/src/usb-hid.c
> index 168b7fa..21363c3 100644
> --- a/src/usb-hid.c
> +++ b/src/usb-hid.c
> @@ -49,7 +49,8 @@ set_idle(struct usb_pipe *pipe, int ms)
>  #define KEYREPEATMS 33
>  
>  static int
> -usb_kbd_init(struct usb_pipe *pipe, struct usb_endpoint_descriptor
> *epdesc)
> +usb_kbd_init(struct usbdevice_s *usbdev
> +             , struct usb_endpoint_descriptor *epdesc)
>  {
>      if (! CONFIG_USB_KEYBOARD)
>          return -1;
> @@ -61,15 +62,15 @@ usb_kbd_init(struct usb_pipe *pipe, struct
> usb_endpoint_descriptor *epdesc)
>          return -1;
>  
>      // Enable "boot" protocol.
> -    int ret = set_protocol(pipe, 0);
> +    int ret = set_protocol(usbdev->defpipe, 0);
>      if (ret)
>          return -1;
>      // Periodically send reports to enable key repeat.
> -    ret = set_idle(pipe, KEYREPEATMS);
> +    ret = set_idle(usbdev->defpipe, KEYREPEATMS);
>      if (ret)
>          return -1;
>  
> -    keyboard_pipe = alloc_intr_pipe(pipe, epdesc);
> +    keyboard_pipe = alloc_intr_pipe(usbdev, epdesc);
>      if (!keyboard_pipe)
>          return -1;
>  
> @@ -78,7 +79,8 @@ usb_kbd_init(struct usb_pipe *pipe, struct
> usb_endpoint_descriptor *epdesc)
>  }
>  
>  static int
> -usb_mouse_init(struct usb_pipe *pipe, struct usb_endpoint_descriptor
> *epdesc)
> +usb_mouse_init(struct usbdevice_s *usbdev
> +               , struct usb_endpoint_descriptor *epdesc)
>  {
>      if (! CONFIG_USB_MOUSE)
>          return -1;
> @@ -90,11 +92,11 @@ usb_mouse_init(struct usb_pipe *pipe, struct
> usb_endpoint_descriptor *epdesc)
>          return -1;
>  
>      // Enable "boot" protocol.
> -    int ret = set_protocol(pipe, 0);
> +    int ret = set_protocol(usbdev->defpipe, 0);
>      if (ret)
>          return -1;
>  
> -    mouse_pipe = alloc_intr_pipe(pipe, epdesc);
> +    mouse_pipe = alloc_intr_pipe(usbdev, epdesc);
>      if (!mouse_pipe)
>          return -1;
>  
> @@ -104,29 +106,29 @@ usb_mouse_init(struct usb_pipe *pipe, struct
> usb_endpoint_descriptor *epdesc)
>  
>  // Initialize a found USB HID device (if applicable).
>  int
> -usb_hid_init(struct usb_pipe *pipe
> -             , struct usb_interface_descriptor *iface, int imax)
> +usb_hid_init(struct usbdevice_s *usbdev)
>  {
>      if (! CONFIG_USB_KEYBOARD || ! CONFIG_USB_MOUSE)
>          return -1;
> -    dprintf(2, "usb_hid_init %p\n", pipe);
> +    dprintf(2, "usb_hid_init %p\n", usbdev->defpipe);
>  
> +    struct usb_interface_descriptor *iface = usbdev->iface;
>      if (iface->bInterfaceSubClass != USB_INTERFACE_SUBCLASS_BOOT)
>          // Doesn't support boot protocol.
>          return -1;
>  
>      // Find intr in endpoint.
>      struct usb_endpoint_descriptor *epdesc = findEndPointDesc(
> -        iface, imax, USB_ENDPOINT_XFER_INT, USB_DIR_IN);
> +        usbdev, USB_ENDPOINT_XFER_INT, USB_DIR_IN);
>      if (!epdesc) {
>          dprintf(1, "No usb hid intr in?\n");
>          return -1;
>      }
>  
>      if (iface->bInterfaceProtocol ==
>      USB_INTERFACE_PROTOCOL_KEYBOARD)
> -        return usb_kbd_init(pipe, epdesc);
> +        return usb_kbd_init(usbdev, epdesc);
>      if (iface->bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
> -        return usb_mouse_init(pipe, epdesc);
> +        return usb_mouse_init(usbdev, epdesc);
>      return -1;
>  }
>  
> diff --git a/src/usb-hid.h b/src/usb-hid.h
> index 7fbcf4b..bd6445c 100644
> --- a/src/usb-hid.h
> +++ b/src/usb-hid.h
> @@ -2,10 +2,8 @@
>  #define __USB_HID_H
>  
>  // usb-hid.c
> -struct usb_interface_descriptor;
> -struct usb_pipe;
> -int usb_hid_init(struct usb_pipe *pipe
> -                 , struct usb_interface_descriptor *iface, int
> imax);
> +struct usbdevice_s;
> +int usb_hid_init(struct usbdevice_s *usbdev);
>  inline int usb_kbd_active(void);
>  inline int usb_kbd_command(int command, u8 *param);
>  inline int usb_mouse_active(void);
> diff --git a/src/usb-hub.c b/src/usb-hub.c
> index b2d9ff2..caa6a3b 100644
> --- a/src/usb-hub.c
> +++ b/src/usb-hub.c
> @@ -158,21 +158,21 @@ static struct usbhub_op_s HubOp = {
>  
>  // Configure a usb hub and then find devices connected to it.
>  int
> -usb_hub_init(struct usb_pipe *pipe)
> +usb_hub_init(struct usbdevice_s *usbdev)
>  {
>      ASSERT32FLAT();
>      if (!CONFIG_USB_HUB)
>          return -1;
>  
>      struct usb_hub_descriptor desc;
> -    int ret = get_hub_desc(pipe, &desc);
> +    int ret = get_hub_desc(usbdev->defpipe, &desc);
>      if (ret)
>          return ret;
>  
>      struct usbhub_s hub;
>      memset(&hub, 0, sizeof(hub));
> -    hub.pipe = pipe;
> -    hub.cntl = pipe->cntl;
> +    hub.pipe = usbdev->defpipe;
> +    hub.cntl = usbdev->defpipe->cntl;
>      hub.powerwait = desc.bPwrOn2PwrGood * 2;
>      hub.portcount = desc.bNbrPorts;
>      hub.op = &HubOp;
> diff --git a/src/usb-hub.h b/src/usb-hub.h
> index 7672028..a75cbda 100644
> --- a/src/usb-hub.h
> +++ b/src/usb-hub.h
> @@ -2,8 +2,8 @@
>  #define __USB_HUB_H
>  
>  // usb-hub.c
> -struct usb_pipe;
> -int usb_hub_init(struct usb_pipe *pipe);
> +struct usbdevice_s;
> +int usb_hub_init(struct usbdevice_s *usbdev);
>  
>  
>  /****************************************************************
> diff --git a/src/usb-msc.c b/src/usb-msc.c
> index e143401..dad90d6 100644
> --- a/src/usb-msc.c
> +++ b/src/usb-msc.c
> @@ -124,13 +124,13 @@ fail:
>  
>  // Configure a usb msc device.
>  int
> -usb_msc_init(struct usb_pipe *pipe
> -             , struct usb_interface_descriptor *iface, int imax)
> +usb_msc_init(struct usbdevice_s *usbdev)
>  {
>      if (!CONFIG_USB_MSC)
>          return -1;
>  
>      // Verify right kind of device
> +    struct usb_interface_descriptor *iface = usbdev->iface;
>      if ((iface->bInterfaceSubClass != US_SC_SCSI &&
>  	 iface->bInterfaceSubClass != US_SC_ATAPI_8070 &&
>  	 iface->bInterfaceSubClass != US_SC_ATAPI_8020)
> @@ -151,17 +151,18 @@ usb_msc_init(struct usb_pipe *pipe
>  
>      // Find bulk in and bulk out endpoints.
>      struct usb_endpoint_descriptor *indesc = findEndPointDesc(
> -        iface, imax, USB_ENDPOINT_XFER_BULK, USB_DIR_IN);
> +        usbdev, USB_ENDPOINT_XFER_BULK, USB_DIR_IN);
>      struct usb_endpoint_descriptor *outdesc = findEndPointDesc(
> -        iface, imax, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT);
> +        usbdev, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT);
>      if (!indesc || !outdesc)
>          goto fail;
> -    udrive_g->bulkin = alloc_bulk_pipe(pipe, indesc);
> -    udrive_g->bulkout = alloc_bulk_pipe(pipe, outdesc);
> +    udrive_g->bulkin = alloc_bulk_pipe(usbdev, indesc);
> +    udrive_g->bulkout = alloc_bulk_pipe(usbdev, outdesc);
>      if (!udrive_g->bulkin || !udrive_g->bulkout)
>          goto fail;
>  
> -    int prio = bootprio_find_usb(pipe->cntl->pci, pipe->path);
> +    int prio = bootprio_find_usb(usbdev->defpipe->cntl->pci
> +                                 , usbdev->defpipe->path);
>      int ret = scsi_init_drive(&udrive_g->drive, "USB MSC", prio);
>      if (ret)
>          goto fail;
> diff --git a/src/usb-msc.h b/src/usb-msc.h
> index 12d749c..31c81b9 100644
> --- a/src/usb-msc.h
> +++ b/src/usb-msc.h
> @@ -4,10 +4,8 @@
>  // usb-msc.c
>  struct disk_op_s;
>  int usb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize);
> -struct usb_interface_descriptor;
> -struct usb_pipe;
> -int usb_msc_init(struct usb_pipe *pipe
> -                 , struct usb_interface_descriptor *iface, int
> imax);
> +struct usbdevice_s;
> +int usb_msc_init(struct usbdevice_s *usbdev);
>  
>  
>  /****************************************************************
> diff --git a/src/usb.c b/src/usb.c
> index 81aa429..1657bf5 100644
> --- a/src/usb.c
> +++ b/src/usb.c
> @@ -86,19 +86,20 @@ 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
> +desc2pipe(struct usb_pipe *newpipe, struct usbdevice_s *usbdev
>            , struct usb_endpoint_descriptor *epdesc)
>  {
> -    memcpy(newpipe, origpipe, sizeof(*newpipe));
> +    memcpy(newpipe, usbdev->defpipe, sizeof(*newpipe));
>      newpipe->ep = epdesc->bEndpointAddress &
>      USB_ENDPOINT_NUMBER_MASK;
>      newpipe->maxpacket = epdesc->wMaxPacketSize;
>  }
>  
>  struct usb_pipe *
> -alloc_bulk_pipe(struct usb_pipe *pipe, struct
> usb_endpoint_descriptor *epdesc)
> +alloc_bulk_pipe(struct usbdevice_s *usbdev
> +                , struct usb_endpoint_descriptor *epdesc)
>  {
>      struct usb_pipe dummy;
> -    desc2pipe(&dummy, pipe, epdesc);
> +    desc2pipe(&dummy, usbdev, epdesc);
>      dummy.eptype = USB_ENDPOINT_XFER_BULK;
>      return alloc_async_pipe(&dummy);
>  }
> @@ -118,18 +119,19 @@ usb_send_bulk(struct usb_pipe *pipe_fl, int
> dir, void *data, int datasize)
>  }
>  
>  struct usb_pipe *
> -alloc_intr_pipe(struct usb_pipe *pipe, struct
> usb_endpoint_descriptor *epdesc)
> +alloc_intr_pipe(struct usbdevice_s *usbdev
> +                , struct usb_endpoint_descriptor *epdesc)
>  {
>      struct usb_pipe dummy;
> -    desc2pipe(&dummy, pipe, epdesc);
> +    desc2pipe(&dummy, usbdev, epdesc);
>      // Find the exponential period of the requested time.
>      int period = epdesc->bInterval;
>      int frameexp;
> -    if (pipe->speed != USB_HIGHSPEED)
> +    if (usbdev->speed != USB_HIGHSPEED)
>          frameexp = (period <= 0) ? 0 : __fls(period);
>      else
>          frameexp = (period <= 4) ? 0 : period - 4;
> -    switch (pipe->type) {
> +    switch (dummy.type) {
>      default:
>      case USB_TYPE_UHCI:
>          return uhci_alloc_intr_pipe(&dummy, frameexp);
> @@ -161,12 +163,11 @@ usb_poll_intr(struct usb_pipe *pipe_fl, void
> *data)
>  
>  // Find the first endpoing of a given type in an interface
>  description.
>  struct usb_endpoint_descriptor *
> -findEndPointDesc(struct usb_interface_descriptor *iface, int imax
> -                 , int type, int dir)
> +findEndPointDesc(struct usbdevice_s *usbdev, int type, int dir)
>  {
> -    struct usb_endpoint_descriptor *epdesc = (void*)&iface[1];
> +    struct usb_endpoint_descriptor *epdesc =
> (void*)&usbdev->iface[1];
>      for (;;) {
> -        if ((void*)epdesc >= (void*)iface + imax
> +        if ((void*)epdesc >= (void*)usbdev->iface + usbdev->imax
>              || epdesc->bDescriptorType == USB_DT_INTERFACE) {
>              return NULL;
>          }
> @@ -345,13 +346,15 @@ configure_usb_device(struct usbdevice_s
> *usbdev)
>          goto fail;
>  
>      // Configure driver.
> -    int imax = (void*)config + config->wTotalLength - (void*)iface;
> +    usbdev->config = config;
> +    usbdev->iface = iface;
> +    usbdev->imax = (void*)config + config->wTotalLength -
> (void*)iface;
>      if (iface->bInterfaceClass == USB_CLASS_HUB)
> -        ret = usb_hub_init(pipe);
> +        ret = usb_hub_init(usbdev);
>      else if (iface->bInterfaceClass == USB_CLASS_MASS_STORAGE)
> -        ret = usb_msc_init(pipe, iface, imax);
> +        ret = usb_msc_init(usbdev);
>      else
> -        ret = usb_hid_init(pipe, iface, imax);
> +        ret = usb_hid_init(usbdev);
>      if (ret)
>          goto fail;
>  
> diff --git a/src/usb.h b/src/usb.h
> index ab7f559..83ccb58 100644
> --- a/src/usb.h
> +++ b/src/usb.h
> @@ -26,6 +26,9 @@ struct usbdevice_s {
>      struct usbhub_s *hub;
>      struct usb_pipe *defpipe;
>      u32 port;
> +    struct usb_config_descriptor *config;
> +    struct usb_interface_descriptor *iface;
> +    int imax;
>      u8 speed;
>  };
>  
> @@ -215,14 +218,12 @@ int send_default_control(struct usb_pipe *pipe,
> const struct usb_ctrlrequest *re
>                           , 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_pipe *alloc_bulk_pipe(struct usbdevice_s *usbdev
>                                   , struct usb_endpoint_descriptor
>                                   *epdesc);
> -struct usb_pipe *alloc_intr_pipe(struct usb_pipe *pipe
> +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);
> -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);
> +struct usb_endpoint_descriptor *findEndPointDesc(struct usbdevice_s
> *usbdev
> +                                                 , int type, int
> dir);
>  
>  #endif // usb.h
> --
> 1.7.6.5
> 
> 
> _______________________________________________
> SeaBIOS mailing list
> SeaBIOS at seabios.org
> http://www.seabios.org/mailman/listinfo/seabios
> 



More information about the SeaBIOS mailing list