aboutsummaryrefslogtreecommitdiffstats
path: root/payloads/libpayload/include/usb/usb.h
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload/include/usb/usb.h')
-rw-r--r--payloads/libpayload/include/usb/usb.h177
1 files changed, 93 insertions, 84 deletions
diff --git a/payloads/libpayload/include/usb/usb.h b/payloads/libpayload/include/usb/usb.h
index 2bf1993b8..83d4a8575 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);