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 <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170664
Reviewed-by: Stefan Reinauer <reinauer@google.com>
Commit-Queue: Ronald Minnich <rminnich@chromium.org>
(cherry picked from commit f160d4439c0d7cea1d2e6b97207935d61dcbb2f2)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6776
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
Julius Werner
2013-09-24 20:03:54 -07:00
committed by Isaac Christensen
parent f9d7252a8d
commit e00ba2168b
10 changed files with 209 additions and 198 deletions

View File

@ -59,107 +59,8 @@ typedef enum {
TEST_MODE = 2
} feature_selectors;
typedef struct {
union {
struct {
dev_req_recp req_recp:5;
dev_req_type req_type:2;
dev_req_dir data_dir:1;
} __attribute__ ((packed));
unsigned char bmRequestType;
} __attribute__ ((packed));
unsigned char bRequest;
unsigned short wValue;
unsigned short wIndex;
unsigned short wLength;
} __attribute__ ((packed)) dev_req_t;
struct usbdev_hc;
typedef struct usbdev_hc hci_t;
struct usbdev;
typedef struct usbdev usbdev_t;
typedef enum { SETUP, IN, OUT } direction_t;
typedef enum { CONTROL = 0, ISOCHRONOUS = 1, BULK = 2, INTERRUPT = 3
} endpoint_type;
typedef struct {
usbdev_t *dev;
int endpoint;
direction_t direction;
int toggle;
int maxpacketsize;
endpoint_type type;
int interval; /* expressed as binary logarithm of the number
of microframes (i.e. t = 125us * 2^interval) */
} endpoint_t;
enum { FULL_SPEED = 0, LOW_SPEED = 1, HIGH_SPEED = 2, SUPER_SPEED = 3 };
struct usbdev {
hci_t *controller;
endpoint_t endpoints[32];
int num_endp;
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
u32 quirks; // quirks field. got to love usb
void *data;
u8 *descriptor;
u8 *configuration;
void (*init) (usbdev_t *dev);
void (*destroy) (usbdev_t *dev);
void (*poll) (usbdev_t *dev);
};
typedef enum { OHCI = 0, UHCI = 1, EHCI = 2, XHCI = 3} hc_type;
struct usbdev_hc {
hci_t *next;
u32 reg_base;
pcidev_t pcidev; // 0 if not used (eg on ARM)
hc_type type;
usbdev_t *devices[128]; // dev 0 is root hub, 127 is last addressable
/* start(): Resume operation. */
void (*start) (hci_t *controller);
/* stop(): Stop operation but keep controller initialized. */
void (*stop) (hci_t *controller);
/* reset(): Perform a controller reset. The controller needs to
be (re)initialized afterwards to work (again). */
void (*reset) (hci_t *controller);
/* init(): Initialize a (previously reset) controller
to a working state. */
void (*init) (hci_t *controller);
/* shutdown(): Stop operation, detach host controller and shutdown
this driver instance. After calling shutdown() any
other usage of this hci_t* is invalid. */
void (*shutdown) (hci_t *controller);
int (*bulk) (endpoint_t *ep, int size, u8 *data, int finalize);
int (*control) (usbdev_t *dev, direction_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);
u8* (*poll_intr_queue) (void *queue);
void *instance;
/* set_address(): Tell the usb device its address and
return it. xHCI controllers want to
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);
/* finish_device_config(): Another hook for xHCI,
returns 0 on success. */
int (*finish_device_config) (usbdev_t *dev);
/* destroy_device(): Finally, destroy all structures that
were allocated during set_address()
and finish_device_config(). */
void (*destroy_device) (hci_t *controller, int devaddr);
};
/* SetAddress() recovery interval (USB 2.0 specification 9.2.6.3 */
#define SET_ADDRESS_MDELAY 2
typedef struct {
unsigned char bDescLength;
@ -240,12 +141,118 @@ typedef struct {
unsigned short wReportDescriptorLength;
} __attribute__ ((packed)) hid_descriptor_t;
typedef struct {
union {
struct {
dev_req_recp req_recp:5;
dev_req_type req_type:2;
dev_req_dir data_dir:1;
} __attribute__ ((packed));
unsigned char bmRequestType;
} __attribute__ ((packed));
unsigned char bRequest;
unsigned short wValue;
unsigned short wIndex;
unsigned short wLength;
} __attribute__ ((packed)) dev_req_t;
struct usbdev_hc;
typedef struct usbdev_hc hci_t;
struct usbdev;
typedef struct usbdev usbdev_t;
typedef enum { SETUP, IN, OUT } direction_t;
typedef enum { CONTROL = 0, ISOCHRONOUS = 1, BULK = 2, INTERRUPT = 3
} endpoint_type;
typedef struct {
usbdev_t *dev;
int endpoint;
direction_t direction;
int toggle;
int maxpacketsize;
endpoint_type type;
int interval; /* expressed as binary logarithm of the number
of microframes (i.e. t = 125us * 2^interval) */
} endpoint_t;
typedef enum {
FULL_SPEED = 0, LOW_SPEED = 1, HIGH_SPEED = 2, SUPER_SPEED = 3,
} usb_speed;
struct usbdev {
hci_t *controller;
endpoint_t endpoints[32];
int num_endp;
int address; // usb address
int hub; // hub, device is attached to
int port; // port where device is attached
usb_speed speed;
u32 quirks; // quirks field. got to love usb
void *data;
u8 *descriptor;
u8 *configuration;
void (*init) (usbdev_t *dev);
void (*destroy) (usbdev_t *dev);
void (*poll) (usbdev_t *dev);
};
typedef enum { OHCI = 0, UHCI = 1, EHCI = 2, XHCI = 3} hc_type;
struct usbdev_hc {
hci_t *next;
u32 reg_base;
pcidev_t pcidev; // 0 if not used (eg on ARM)
hc_type type;
usbdev_t *devices[128]; // dev 0 is root hub, 127 is last addressable
/* start(): Resume operation. */
void (*start) (hci_t *controller);
/* stop(): Stop operation but keep controller initialized. */
void (*stop) (hci_t *controller);
/* reset(): Perform a controller reset. The controller needs to
be (re)initialized afterwards to work (again). */
void (*reset) (hci_t *controller);
/* init(): Initialize a (previously reset) controller
to a working state. */
void (*init) (hci_t *controller);
/* shutdown(): Stop operation, detach host controller and shutdown
this driver instance. After calling shutdown() any
other usage of this hci_t* is invalid. */
void (*shutdown) (hci_t *controller);
int (*bulk) (endpoint_t *ep, int size, u8 *data, int finalize);
int (*control) (usbdev_t *dev, direction_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);
u8* (*poll_intr_queue) (void *queue);
void *instance;
/* set_address(): Tell the usb device its address and
return it. xHCI controllers want to
do this by themself. Also, the usbdev
structure has to be allocated and
initialized. */
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);
/* destroy_device(): Finally, destroy all structures that
were allocated during set_address()
and finish_device_config(). */
void (*destroy_device) (hci_t *controller, int devaddr);
};
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);