From e00ba2168bf9e61535b83ab4320364fa8e26910c Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Tue, 24 Sep 2013 20:03:54 -0700 Subject: libpayload: usb: Unify USB speed between XHCI stack and USB core This patch removes the confusing concept of a special "xhci_speed" with a different numeric value from the usual speed used throughout the USB core (except for the places directly interacting with the xHC, which are explicitly marked). It also moves the MPS0 decoding function into the core and moves some definitions around in preparation of later changes that will make the stack SuperSpeed-ready. It makes both set_address implementations share a constant for the specification-defined SetAddress() recovery delay and removes pointless additional delays from the non-XHCI version. Change-Id: I422379d05d4a502b12dae183504e5231add5466a Signed-off-by: Julius Werner Reviewed-on: https://chromium-review.googlesource.com/170664 Reviewed-by: Stefan Reinauer Commit-Queue: Ronald Minnich (cherry picked from commit f160d4439c0d7cea1d2e6b97207935d61dcbb2f2) Signed-off-by: Isaac Christensen Reviewed-on: http://review.coreboot.org/6776 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- payloads/libpayload/include/usb/usb.h | 177 ++++++++++++++++++---------------- 1 file changed, 93 insertions(+), 84 deletions(-) (limited to 'payloads/libpayload/include') diff --git a/payloads/libpayload/include/usb/usb.h b/payloads/libpayload/include/usb/usb.h index 2bf1993b82..83d4a85759 100644 --- a/payloads/libpayload/include/usb/usb.h +++ b/payloads/libpayload/include/usb/usb.h @@ -59,6 +59,88 @@ typedef enum { TEST_MODE = 2 } feature_selectors; +/* SetAddress() recovery interval (USB 2.0 specification 9.2.6.3 */ +#define SET_ADDRESS_MDELAY 2 + +typedef struct { + unsigned char bDescLength; + unsigned char bDescriptorType; + unsigned char bNbrPorts; + union { + struct { + unsigned long logicalPowerSwitchingMode:2; + unsigned long isCompoundDevice:1; + unsigned long overcurrentProtectionMode:2; + unsigned long ttThinkTime:2; + unsigned long arePortIndicatorsSupported:1; + unsigned long:8; + } __attribute__ ((packed)); + unsigned short wHubCharacteristics; + } __attribute__ ((packed)); + unsigned char bPowerOn2PwrGood; + unsigned char bHubContrCurrent; + char DeviceRemovable[]; +} __attribute__ ((packed)) hub_descriptor_t; + +typedef struct { + unsigned char bLength; + unsigned char bDescriptorType; + unsigned short bcdUSB; + unsigned char bDeviceClass; + unsigned char bDeviceSubClass; + unsigned char bDeviceProtocol; + unsigned char bMaxPacketSize0; + unsigned short idVendor; + unsigned short idProduct; + unsigned short bcdDevice; + unsigned char iManufacturer; + unsigned char iProduct; + unsigned char iSerialNumber; + unsigned char bNumConfigurations; +} __attribute__ ((packed)) device_descriptor_t; + +typedef struct { + unsigned char bLength; + unsigned char bDescriptorType; + unsigned short wTotalLength; + unsigned char bNumInterfaces; + unsigned char bConfigurationValue; + unsigned char iConfiguration; + unsigned char bmAttributes; + unsigned char bMaxPower; +} __attribute__ ((packed)) configuration_descriptor_t; + +typedef struct { + unsigned char bLength; + unsigned char bDescriptorType; + unsigned char bInterfaceNumber; + unsigned char bAlternateSetting; + unsigned char bNumEndpoints; + unsigned char bInterfaceClass; + unsigned char bInterfaceSubClass; + unsigned char bInterfaceProtocol; + unsigned char iInterface; +} __attribute__ ((packed)) interface_descriptor_t; + +typedef struct { + unsigned char bLength; + unsigned char bDescriptorType; + unsigned char bEndpointAddress; + unsigned char bmAttributes; + unsigned short wMaxPacketSize; + unsigned char bInterval; +} __attribute__ ((packed)) endpoint_descriptor_t; + +typedef struct { + unsigned char bLength; + unsigned char bDescriptorType; + unsigned short bcdHID; + unsigned char bCountryCode; + unsigned char bNumDescriptors; + unsigned char bReportDescriptorType; + unsigned short wReportDescriptorLength; +} __attribute__ ((packed)) hid_descriptor_t; + typedef struct { union { struct { @@ -95,7 +177,9 @@ typedef struct { of microframes (i.e. t = 125us * 2^interval) */ } endpoint_t; -enum { FULL_SPEED = 0, LOW_SPEED = 1, HIGH_SPEED = 2, SUPER_SPEED = 3 }; +typedef enum { + FULL_SPEED = 0, LOW_SPEED = 1, HIGH_SPEED = 2, SUPER_SPEED = 3, +} usb_speed; struct usbdev { hci_t *controller; @@ -104,7 +188,7 @@ struct usbdev { int address; // usb address int hub; // hub, device is attached to int port; // port where device is attached - int speed; // 1: lowspeed, 0: fullspeed, 2: highspeed + usb_speed speed; u32 quirks; // quirks field. got to love usb void *data; u8 *descriptor; @@ -151,7 +235,8 @@ struct usbdev_hc { do this by themself. Also, the usbdev structure has to be allocated and initialized. */ - int (*set_address) (hci_t *controller, int speed, int hubport, int hubaddr); + int (*set_address) (hci_t *controller, usb_speed speed, + int hubport, int hubaddr); /* finish_device_config(): Another hook for xHCI, returns 0 on success. */ int (*finish_device_config) (usbdev_t *dev); @@ -161,91 +246,13 @@ struct usbdev_hc { void (*destroy_device) (hci_t *controller, int devaddr); }; -typedef struct { - unsigned char bDescLength; - unsigned char bDescriptorType; - unsigned char bNbrPorts; - union { - struct { - unsigned long logicalPowerSwitchingMode:2; - unsigned long isCompoundDevice:1; - unsigned long overcurrentProtectionMode:2; - unsigned long ttThinkTime:2; - unsigned long arePortIndicatorsSupported:1; - unsigned long:8; - } __attribute__ ((packed)); - unsigned short wHubCharacteristics; - } __attribute__ ((packed)); - unsigned char bPowerOn2PwrGood; - unsigned char bHubContrCurrent; - char DeviceRemovable[]; -} __attribute__ ((packed)) hub_descriptor_t; - -typedef struct { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short bcdUSB; - unsigned char bDeviceClass; - unsigned char bDeviceSubClass; - unsigned char bDeviceProtocol; - unsigned char bMaxPacketSize0; - unsigned short idVendor; - unsigned short idProduct; - unsigned short bcdDevice; - unsigned char iManufacturer; - unsigned char iProduct; - unsigned char iSerialNumber; - unsigned char bNumConfigurations; -} __attribute__ ((packed)) device_descriptor_t; - -typedef struct { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short wTotalLength; - unsigned char bNumInterfaces; - unsigned char bConfigurationValue; - unsigned char iConfiguration; - unsigned char bmAttributes; - unsigned char bMaxPower; -} __attribute__ ((packed)) configuration_descriptor_t; - -typedef struct { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned char bInterfaceNumber; - unsigned char bAlternateSetting; - unsigned char bNumEndpoints; - unsigned char bInterfaceClass; - unsigned char bInterfaceSubClass; - unsigned char bInterfaceProtocol; - unsigned char iInterface; -} __attribute__ ((packed)) interface_descriptor_t; - -typedef struct { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned char bEndpointAddress; - unsigned char bmAttributes; - unsigned short wMaxPacketSize; - unsigned char bInterval; -} __attribute__ ((packed)) endpoint_descriptor_t; - -typedef struct { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short bcdHID; - unsigned char bCountryCode; - unsigned char bNumDescriptors; - unsigned char bReportDescriptorType; - unsigned short wReportDescriptorLength; -} __attribute__ ((packed)) hid_descriptor_t; - hci_t *usb_add_mmio_hc(hc_type type, void *bar); hci_t *new_controller (void); void detach_controller (hci_t *controller); void usb_poll (void); void init_device_entry (hci_t *controller, int num); +int usb_decode_mps0 (usb_speed speed, u8 bMaxPacketSize0); void set_feature (usbdev_t *dev, int endp, int feature, int rtype); void get_status (usbdev_t *dev, int endp, int rtype, int len, void *data); void set_configuration (usbdev_t *dev); @@ -268,10 +275,12 @@ gen_bmRequestType (dev_req_dir dir, dev_req_type type, dev_req_recp recp) } /* default "set address" handler */ -int generic_set_address (hci_t *controller, int speed, int hubport, int hubaddr); +int generic_set_address (hci_t *controller, usb_speed speed, + int hubport, int hubaddr); void usb_detach_device(hci_t *controller, int devno); -int usb_attach_device(hci_t *controller, int hubaddress, int port, int speed); +int usb_attach_device(hci_t *controller, int hubaddress, int port, + usb_speed speed); u32 usb_quirk_check(u16 vendor, u16 device); int usb_interface_check(u16 vendor, u16 device); -- cgit v1.2.3