It assumes that the reader is familiar with the USB 2.0 and USB 1.1 specifications, as well as the EHCI and OHCI specifications. It also assumes the reader has access to the AHB sub-system hardware specifications. Please see the list of references for links to these documents. Only details peculiar to our system are described in this document. It does not try to explain the USB specifications.
Also, as defined by the OHCI specifications, there are no hardware interlocks for the data structures operated on by the host-controller as well as the host-controller driver. Procedures to enqueue and dequeue transfer and endpoint descriptors described in the OHCI specifications must be followed, in order to avoid race conditions in the processing of queues.
In the sources, you will find 3 kinds of OHCI resource managers and 1 EHCI resource manager. See the README included in the EHCI sources for a description of the EHCI RM. The 3 OHCI RMs are:
The USB resource managers (OHCI1, OHCI0, EHCI) can be accessed via the standard IOP OS resource manager interface. However, a "shim layer" library is provided on the IOP as well as the PPC, in order to allow easier access to them. This API is also referred to as the "IUSB API".
The IOP version of this library is described in the "IOP USB API" document and can be found in "libusb.a" included in the IOP SDK. The PPC version is described in the "PPC USB API" document and can be found in "usb.a" or "usbD.a" in the PPC SDK.
This section describes some of the internals of the OHCI0 resource manager. A description of the individual files can be found in a later section.
typedef struct ohci_opregs {
u32 rev; /* HcRevision */
u32 ctrl; /* HcControl */
u32 cmd_stat; /* HcCommandStatus */
u32 int_stat; /* HcInterruptStatus */
u32 int_en; /* HcInterruptEnable */
u32 int_dis; /* HcInterruptDisable */
u32 hcca; /* HcHCCA */
u32 prd_curr; /* HcPeriodCurrentED */
u32 ctrl_head; /* HcControlHeadED */
u32 ctrl_curr; /* HcControlCurrentED */
u32 blk_head; /* HcBulkHeadED */
u32 blk_curr; /* HcBulkCurrentED */
u32 done_head; /* HcDoneHead */
u32 frm_int; /* HcFmInterval */
u32 frm_rem; /* HcFmRemaining */
u32 frm_num; /* HcFmNumber */
u32 prd_start; /* HcPeriodicStart */
u32 ls_thres; /* HcLSThreshold */
u32 rhub_desca; /* HcRhDescriptorA */
u32 rhub_descb; /* HcRhDescriptorB */
u32 rhub_stat; /* HcRhStatus */
u32 rhub_pstat[USB_RHUB_PORT_MAX]; /* HcRhPortStatus */
} ohci_opregs __attribute__((aligned(32)));
#define OHCI_HCCA_ALIGN 256
typedef struct ohci_hcca {
u32 inttbl[OHCI_HCCA_NINT];
u32 frmnum; /* includes 2 byte pad */
u32 donehead;
u8 hcrsvd[116]; /* reserved for HC */
u8 pad[4]; /* undefined bytes in spec */
} ohci_hcca __attribute__((aligned(OHCI_HCCA_ALIGN)));
#define OHCI_ED_ALIGN 16
typedef struct ohci_ed {
u32 flags;
u32 tailP;
u32 headP;
u32 nextED;
} ohci_ed __attribute__((aligned(OHCI_ED_ALIGN)));
#define OHCI_TD_ALIGN 32 /* at least 16 for general td, 32 for itd */
typedef struct ohci_td {
u32 flags; /* Transfer flags */
u32 cbp; /* Current buffer pointer or bp0*/
u32 nextTD; /* Next TD */
u32 be; /* Buffer end */
u32 psw[4]; /* Packet status word for iTD only */
/* Stuff for HCD's use */
OHCIrp *irp; /* IRP containing this transfer */
u16 len; /* Transfer length */
} ohci_td __attribute((aligned(OHCI_TD_ALIGN)));
typedef struct ohci_hcd {
struct ohci_opregs *opregs; /* Operational registers in IO space */
struct ohci_hcca *hcca; /* Memory shared with HC (sec ) */
/* For HCD use */
u32 frm_int; /* Save frame interval */
ohci_ed *intr_list; /* Interrupt endpoint list */
IOSTimerId tmr; /* Timer used by main thread */
IOSTimerId tmrEv; /* Timer used by event thread */
IOSMessageQueueId qid; /* QueueId used by main thread */
IOSMessageQueueId qidEv; /* QueueId used by event thread */
IOSMessageQueueId rm_qid; /* QueueId used for RM loop */
IOSMessage mq[1]; /* Queue used by main thread */
IOSMessage mqEv[1]; /* Queue used by event thread */
IOSEvent event; /* Constant: IOS_EVENT_OH0 for OHCI0 RM */
u8 ndp; /* Number of downstream ports for root-hub */
u32 flags; /* HCD initialization flag */
u32 openid; /* Used to assign device numbers */
OHCCtrlReq *req; /* Used for internal control requests */
IOSThreadId rmId; /* Main thread id */
u8 rwc; /* Save remote wakeup connected bit */
u8 hc_rdb; /* Constant: IOS_RB_OHCI0 for OHCI0 RM */
u8 hc_wb; /* Constant: IOS_WB_OHCI0 for OHCI0 RM */
u32 load_ns; /* Periodic transfer load */
} ohci_hcd;
typedef struct usb_hub {
u8 devnum; /* Index into device nodes list */
u8 ndp; /* Number of downstream ports */
u8 ndp_stat; /* Status */
u8 potpgt; /* Power-up to power-good time */
u8 data[4] __attribute__((aligned(32))); /* Status data */
} usb_hub;
typedef struct usb_dev {
u8 hub; /* Hub for current device */
u8 port; /* Port for current device */
u16 spd; /* High, full or low speed */
u8 maxPower; /* Max power */
u16 vid; /* Vendor id */
u16 pid; /* Product id */
u8 devClass; /* Device class */
u8 subClass; /* Device subclass */
u8 protocol; /* Protocol */
u8 nintf; /* Number of interfaces */
IOSResourceRequest *notifyRemoval; /* Notify removal request */
usb_intf intf[OHCI_DEV_MAX_INTF]; /* Interface data */
struct usb_dev_ep ep0; /* Device endpoint 0 */
struct usb_dev_ep ep[OHCI_DEV_MAX_EP]; /* Other device endpoints */
struct usb_hub *hubp; /* Hub node used for hubs */
} usb_dev;
typedef struct ohci_device {
u8 type; /* Device or hub */
struct usb_dev dev; /* usb device structure */
u32 openid; /* Id for repeated open/close */
u32 opened; /* Device currently opened? */
} ohci_device;
Please see the EHCI README for information about port routing (handover of ports from EHCI to OHCI, if full or low speed devices are connected to the root hub). Port routing is transparent to the OHCI0 resource manager and is entirely handled by the EHCI resource manager (and the hardware).
The resource manager thread starts as the main thread at priority IOS_PRIORITY_OH0 (72). After the host-controller is initialized, the event thread is started at priority IOS_PRIORITY_OH0 and the main thread lowers its own priority to (IOS_PRIORITY_OH0 - 1) and becomes the resource manager thread.
The main thread initializes the RM and the host-controller hardware. As the resource manager thread, it handles user requests for transfers, etc.
The event handler thread handles the event, IOS_EVENT_OH0.
The OHCI0 RM has separate memory regions allocated for the HCCA (1K) and interrupt ED space (4K).
Certain pathological devices randomly fail to respond to requests during enumeration. It was found that retrying a few times always works. So we make up to 3 attempts to enumerate any attached device.
Enumerated devices are assigned an address as required. However, this device address is not exposed to users directly. Users specify devices via a handle obtained by using the IOS_Open call.
Opening the host-controller driver /dev/usb/oh0 returns the reserved handle OHC_RSVD_HANDLE.
Control transfers are used internally by the OHCI0 RM in device enumeration and to control hubs. The OHCI0 RM uses interrupt transfers to detect changes in hub status. An internal message queue is used by the RM thread to get completion replies from the event handler thread.
The endpoints in the interrupt transfer tree are allocated statically and enqueued into a tree structure as specified by the OHCI specifications. Control, bulk and isochronous endpoints are allocated and enqueued, when they are found in connected devices.
OHCI imposes constraints on the size and number of packets per isochronous transfer.
Please see