3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 // Universal Host Controller Interface data structures and defines
28 #include <IndustryStandard/pci22.h>
31 extern UINTN gEHCDebugLevel
;
32 extern UINTN gEHCErrorLevel
;
35 #define STALL_1_MACRO_SECOND 1
36 #define STALL_1_MILLI_SECOND 1000 * STALL_1_MACRO_SECOND
37 #define STALL_1_SECOND 1000 * STALL_1_MILLI_SECOND
39 #define MEM_UNIT_SIZE 128
42 #define SETUP_PACKET_PID_CODE 0x02
43 #define INPUT_PACKET_PID_CODE 0x01
44 #define OUTPUT_PACKET_PID_CODE 0x0
46 #define ITD_SELECT_TYPE 0x0
47 #define QH_SELECT_TYPE 0x01
48 #define SITD_SELECT_TYPE 0x02
49 #define FSTN_SELECT_TYPE 0x03
51 #define EHCI_SET_PORT_RESET_RECOVERY_TIME 50 * STALL_1_MILLI_SECOND
52 #define EHCI_CLEAR_PORT_RESET_RECOVERY_TIME STALL_1_MILLI_SECOND
53 #define EHCI_GENERIC_TIMEOUT 50 * STALL_1_MILLI_SECOND
54 #define EHCI_GENERIC_RECOVERY_TIME 50 * STALL_1_MACRO_SECOND
55 #define EHCI_SYNC_REQUEST_POLLING_TIME 50 * STALL_1_MACRO_SECOND
56 #define EHCI_ASYNC_REQUEST_POLLING_TIME 50 * STALL_1_MILLI_SECOND
58 #define USB_BAR_INDEX 0 /* how many bytes away from USB_BASE to 0x10 */
60 #define NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES 16
62 #define EHCI_MIN_PACKET_SIZE 8
63 #define EHCI_MAX_PACKET_SIZE 1024
64 #define EHCI_MAX_FRAME_LIST_LENGTH 1024
65 #define EHCI_BLOCK_SIZE_WITH_TT 64
66 #define EHCI_BLOCK_SIZE 512
67 #define EHCI_MAX_QTD_CAPACITY (EFI_PAGE_SIZE * 5)
69 #define NAK_COUNT_RELOAD 3
70 #define QTD_ERROR_COUNTER 3
71 #define HIGH_BANDWIDTH_PIPE_MULTIPLIER 1
73 #define QTD_STATUS_ACTIVE 0x80
74 #define QTD_STATUS_HALTED 0x40
75 #define QTD_STATUS_BUFFER_ERR 0x20
76 #define QTD_STATUS_BABBLE_ERR 0x10
77 #define QTD_STATUS_TRANSACTION_ERR 0x08
78 #define QTD_STATUS_DO_STOP_SPLIT 0x02
79 #define QTD_STATUS_DO_START_SPLIT 0
80 #define QTD_STATUS_DO_PING 0x01
81 #define QTD_STATUS_DO_OUT 0
86 #define MICRO_FRAME_0_CHANNEL 0x01
87 #define MICRO_FRAME_1_CHANNEL 0x02
88 #define MICRO_FRAME_2_CHANNEL 0x04
89 #define MICRO_FRAME_3_CHANNEL 0x08
90 #define MICRO_FRAME_4_CHANNEL 0x10
91 #define MICRO_FRAME_5_CHANNEL 0x20
92 #define MICRO_FRAME_6_CHANNEL 0x40
93 #define MICRO_FRAME_7_CHANNEL 0x80
95 #define CONTROL_TRANSFER 0x01
96 #define BULK_TRANSFER 0x02
97 #define SYNC_INTERRUPT_TRANSFER 0x04
98 #define ASYNC_INTERRUPT_TRANSFER 0x08
99 #define SYNC_ISOCHRONOUS_TRANSFER 0x10
100 #define ASYNC_ISOCHRONOUS_TRANSFER 0x20
104 // Enhanced Host Controller Registers definitions
106 extern EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding
;
107 extern EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName
;
109 #define USBCMD 0x0 /* Command Register Offset 00-03h */
110 #define USBCMD_RS 0x01 /* Run / Stop */
111 #define USBCMD_HCRESET 0x02 /* Host controller reset */
112 #define USBCMD_FLS_512 0x04 /* 512 elements (2048bytes) in Frame List */
113 #define USBCMD_FLS_256 0x08 /* 256 elements (1024bytes) in Frame List */
114 #define USBCMD_PSE 0x10 /* Periodic schedule enable */
115 #define USBCMD_ASE 0x20 /* Asynchronous schedule enable */
116 #define USBCMD_IAAD 0x40 /* Interrupt on async advance doorbell */
118 #define USBSTS 0x04 /* Statue Register Offset 04-07h */
119 #define USBSTS_HSE 0x10 /* Host system error */
120 #define USBSTS_IAA 0x20 /* Interrupt on async advance */
121 #define USBSTS_HCH 0x1000 /* Host controller halted */
122 #define USBSTS_PSS 0x4000 /* Periodic schedule status */
123 #define USBSTS_ASS 0x8000 /* Asynchronous schedule status */
125 #define USBINTR 0x08 /* Command Register Offset 08-0bh */
127 #define FRINDEX 0x0c /* Frame Index Offset 0c-0fh */
129 #define CTRLDSSGMENT 0x10 /* 4G Segment Selector Offset 10-13h */
131 #define PERIODICLISTBASE 0x14 /* Frame List Base Address Offset 14-17h */
133 #define ASYNCLISTADDR 0x18 /* Next Asynchronous List Address Offset 18-1bh */
135 #define CONFIGFLAG 0x40 /* Configured Flag Register Offset 40-43h */
136 #define CONFIGFLAG_CF 0x01 /* Configure Flag */
138 #define PORTSC 0x44 /* Port Status/Control Offset 44-47h */
139 #define PORTSC_CCS 0x01 /* Current Connect Status*/
140 #define PORTSC_CSC 0x02 /* Connect Status Change */
141 #define PORTSC_PED 0x04 /* Port Enable / Disable */
142 #define PORTSC_PEDC 0x08 /* Port Enable / Disable Change */
143 #define PORTSC_OCA 0x10 /* Over current Active */
144 #define PORTSC_OCC 0x20 /* Over current Change */
145 #define PORTSC_FPR 0x40 /* Force Port Resume */
146 #define PORTSC_SUSP 0x80 /* Port Suspend State */
147 #define PORTSC_PR 0x100 /* Port Reset */
148 #define PORTSC_LS_KSTATE 0x400 /* Line Status K-state */
149 #define PORTSC_LS_JSTATE 0x800 /* Line Status J-state */
150 #define PORTSC_PP 0x1000 /* Port Power */
151 #define PORTSC_PO 0x2000 /* Port Owner */
153 #define CAPLENGTH 0 /* Capability Register Length 00h */
155 #define HCIVERSION 0x02 /* Interface Version Number 02-03h */
157 #define HCSPARAMS 0x04 /* Structural Parameters 04-07h */
158 #define HCSP_NPORTS 0x0f /* Number of physical downstream ports on host controller */
160 #define HCCPARAMS 0x08 /* Capability Parameters 08-0bh */
161 #define HCCP_64BIT 0x01 /* 64-bit Addressing Capability */
162 #define HCCP_PFLF 0x02 /* Programmable Frame List Flag */
163 #define HCCP_EECP 0xff00 /* EHCI Extemded Capabilities Pointer */
165 #define HCSPPORTROUTE 0x0c /* Companion Port Route Description 60b */
167 #define CLASSC 0x09 /* Class Code 09-0bh */
169 #define USBBASE 0x10 /* Base Address to Memory-mapped Host Controller Register Space 10-13h */
171 #define SBRN 0x60 /* Serial Bus Release Number 60h */
173 #define FLADJ 0x61 /* Frame Length Adjustment Register 61h */
175 #define PORTWAKECAP 0x62 /* Port wake capablilities register(OPIONAL) 61-62h */
178 // PCI Configuration Registers
180 #define EHCI_PCI_CLASSC 0x09
181 #define EHCI_PCI_MEMORY_BASE 0x10
184 // Memory Offset Registers
186 #define EHCI_MEMORY_CAPLENGTH 0x0
187 #define EHCI_MEMORY_CONFIGFLAG 0x40
190 // USB Base Class Code,Sub-Class Code and Programming Interface
192 #define PCI_CLASSC_PI_EHCI PCI_IF_EHCI
194 #define SETUP_PACKET_ID 0x2D
195 #define INPUT_PACKET_ID 0x69
196 #define OUTPUT_PACKET_ID 0xE1
197 #define ERROR_PACKET_ID 0x55
199 #define bit(a) (1 << (a))
201 #define GET_0B_TO_31B(Addr) (((UINTN) Addr) & (0xffffffff))
202 #define GET_32B_TO_63B(Addr) ((UINTN)RShiftU64((UINTN) Addr, 32) & (0xffffffff))
206 // Ehci Data and Ctrl Structures
220 UINT32 NextQtdTerminate
: 1;
222 UINT32 NextQtdPointer
: 27;
224 UINT32 AltNextQtdTerminate
: 1;
226 UINT32 AltNextQtdPointer
: 27;
230 UINT32 ErrorCount
: 2;
231 UINT32 CurrentPage
: 3;
232 UINT32 InterruptOnComplete
: 1;
233 UINT32 TotalBytes
: 15;
234 UINT32 DataToggle
: 1;
236 UINT32 CurrentOffset
: 12;
237 UINT32 BufferPointer0
: 20;
240 UINT32 BufferPointer1
: 20;
243 UINT32 BufferPointer2
: 20;
246 UINT32 BufferPointer3
: 20;
249 UINT32 BufferPointer4
: 20;
258 UINT32 QhTerminate
: 1;
259 UINT32 SelectType
: 2;
261 UINT32 QhHorizontalPointer
: 27;
263 UINT32 DeviceAddr
: 7;
265 UINT32 EndpointNum
: 4;
266 UINT32 EndpointSpeed
: 2;
267 UINT32 DataToggleControl
: 1;
268 UINT32 HeadReclamationFlag
: 1;
269 UINT32 MaxPacketLen
: 11;
270 UINT32 ControlEndpointFlag
: 1;
271 UINT32 NakCountReload
: 4;
273 UINT32 InerruptScheduleMask
: 8;
274 UINT32 SplitComletionMask
: 8;
277 UINT32 Multiplier
: 2;
280 UINT32 CurrentQtdPointer
: 27;
282 UINT32 NextQtdTerminate
: 1;
284 UINT32 NextQtdPointer
: 27;
286 UINT32 AltNextQtdTerminate
: 1;
288 UINT32 AltNextQtdPointer
: 27;
292 UINT32 ErrorCount
: 2;
293 UINT32 CurrentPage
: 3;
294 UINT32 InterruptOnComplete
: 1;
295 UINT32 TotalBytes
: 15;
296 UINT32 DataToggle
: 1;
298 UINT32 CurrentOffset
: 12;
299 UINT32 BufferPointer0
: 20;
301 UINT32 CompleteSplitMask
: 8;
303 UINT32 BufferPointer1
: 20;
306 UINT32 SplitBytes
: 7;
307 UINT32 BufferPointer2
: 20;
310 UINT32 BufferPointer3
: 20;
313 UINT32 BufferPointer4
: 20;
319 UINT32 LinkTerminate
: 1;
320 UINT32 SelectType
: 2;
322 UINT32 LinkPointer
: 27;
327 typedef struct _EHCI_QTD_ENTITY EHCI_QTD_ENTITY
;
328 typedef struct _EHCI_QH_ENTITY EHCI_QH_ENTITY
;
329 typedef struct _EHCI_ASYNC_REQUEST EHCI_ASYNC_REQUEST
;
333 struct _EHCI_QTD_ENTITY
{
336 UINT32 StaticTotalBytes
;
337 UINT32 StaticCurrentOffset
;
338 EHCI_QTD_ENTITY
*Prev
;
339 EHCI_QTD_ENTITY
*Next
;
340 EHCI_QTD_ENTITY
*AltNext
;
341 EHCI_QH_ENTITY
*SelfQh
;
346 struct _EHCI_QH_ENTITY
{
348 EHCI_QH_ENTITY
*Next
;
349 EHCI_QH_ENTITY
*Prev
;
350 EHCI_QTD_ENTITY
*FirstQtdPtr
;
351 EHCI_QTD_ENTITY
*LastQtdPtr
;
352 EHCI_QTD_ENTITY
*AltQtdPtr
;
357 #define GET_QH_ENTITY_ADDR(a) ((EHCI_QH_ENTITY *) a)
358 #define GET_QTD_ENTITY_ADDR(a) ((EHCI_QTD_ENTITY *) a)
362 // Ehci Managment Structures
364 #define USB2_HC_DEV_FROM_THIS(a) CR (a, USB2_HC_DEV, Usb2Hc, USB2_HC_DEV_SIGNATURE)
366 #define USB2_HC_DEV_SIGNATURE EFI_SIGNATURE_32 ('e', 'h', 'c', 'i')
368 struct _EHCI_ASYNC_REQUEST
{
370 EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunc
;
372 EHCI_ASYNC_REQUEST
*Prev
;
373 EHCI_ASYNC_REQUEST
*Next
;
374 EHCI_QH_ENTITY
*QhPtr
;
377 typedef struct _MEMORY_MANAGE_HEADER
{
379 UINTN BitArraySizeInBytes
;
380 UINT8
*MemoryBlockPtr
;
381 UINTN MemoryBlockSizeInBytes
;
383 struct _MEMORY_MANAGE_HEADER
*Next
;
384 } MEMORY_MANAGE_HEADER
;
386 typedef struct _USB2_HC_DEV
{
388 EFI_PCI_IO_PROTOCOL
*PciIo
;
389 EFI_USB2_HC_PROTOCOL Usb2Hc
;
390 UINTN PeriodicFrameListLength
;
391 VOID
*PeriodicFrameListBuffer
;
392 VOID
*PeriodicFrameListMap
;
394 EHCI_ASYNC_REQUEST
*AsyncRequestList
;
395 EFI_EVENT AsyncRequestEvent
;
396 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
397 MEMORY_MANAGE_HEADER
*MemoryHeader
;
398 UINT8 Is64BitCapable
;
399 UINT32 High32BitAddr
;
400 EHCI_QH_ENTITY
*NULLQH
;
401 UINT32 UsbCapabilityLen
;
402 UINT16 DeviceSpeed
[16];
408 // Driver model protocol interface
413 EhciDriverBindingSupported (
414 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
415 IN EFI_HANDLE Controller
,
416 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
421 EhciDriverBindingStart (
422 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
423 IN EFI_HANDLE Controller
,
424 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
429 EhciDriverBindingStop (
430 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
431 IN EFI_HANDLE Controller
,
432 IN UINTN NumberOfChildren
,
433 IN EFI_HANDLE
*ChildHandleBuffer
437 // Ehci protocol interface
442 IN EFI_USB2_HC_PROTOCOL
*This
,
444 OUT UINT8
*PortNumber
,
445 OUT UINT8
*Is64BitCapable
451 IN EFI_USB2_HC_PROTOCOL
*This
,
458 IN EFI_USB2_HC_PROTOCOL
*This
,
459 OUT EFI_USB_HC_STATE
*State
465 IN EFI_USB2_HC_PROTOCOL
*This
,
466 IN EFI_USB_HC_STATE State
471 EhciControlTransfer (
472 IN EFI_USB2_HC_PROTOCOL
*This
,
473 IN UINT8 DeviceAddress
,
474 IN UINT8 DeviceSpeed
,
475 IN UINTN MaximumPacketLength
,
476 IN EFI_USB_DEVICE_REQUEST
*Request
,
477 IN EFI_USB_DATA_DIRECTION TransferDirection
,
479 IN OUT UINTN
*DataLength
,
481 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
482 OUT UINT32
*TransferResult
488 IN EFI_USB2_HC_PROTOCOL
*This
,
489 IN UINT8 DeviceAddress
,
490 IN UINT8 EndPointAddress
,
491 IN UINT8 DeviceSpeed
,
492 IN UINTN MaximumPacketLength
,
493 IN UINT8 DataBuffersNumber
,
494 IN OUT VOID
*Data
[EFI_USB_MAX_BULK_BUFFER_NUM
],
495 IN OUT UINTN
*DataLength
,
496 IN OUT UINT8
*DataToggle
,
498 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
499 OUT UINT32
*TransferResult
504 EhciAsyncInterruptTransfer (
505 IN EFI_USB2_HC_PROTOCOL
* This
,
506 IN UINT8 DeviceAddress
,
507 IN UINT8 EndPointAddress
,
508 IN UINT8 DeviceSpeed
,
509 IN UINTN MaxiumPacketLength
,
510 IN BOOLEAN IsNewTransfer
,
511 IN OUT UINT8
*DataToggle
,
512 IN UINTN PollingInterval
,
514 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
515 IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction
,
516 IN VOID
*Context OPTIONAL
521 EhciSyncInterruptTransfer (
522 IN EFI_USB2_HC_PROTOCOL
*This
,
523 IN UINT8 DeviceAddress
,
524 IN UINT8 EndPointAddress
,
525 IN UINT8 DeviceSpeed
,
526 IN UINTN MaximumPacketLength
,
528 IN OUT UINTN
*DataLength
,
529 IN OUT UINT8
*DataToggle
,
531 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
532 OUT UINT32
*TransferResult
537 EhciIsochronousTransfer (
538 IN EFI_USB2_HC_PROTOCOL
*This
,
539 IN UINT8 DeviceAddress
,
540 IN UINT8 EndPointAddress
,
541 IN UINT8 DeviceSpeed
,
542 IN UINTN MaximumPacketLength
,
543 IN UINT8 DataBuffersNumber
,
544 IN OUT VOID
*Data
[EFI_USB_MAX_ISO_BUFFER_NUM
],
546 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
547 OUT UINT32
*TransferResult
552 EhciAsyncIsochronousTransfer (
553 IN EFI_USB2_HC_PROTOCOL
*This
,
554 IN UINT8 DeviceAddress
,
555 IN UINT8 EndPointAddress
,
556 IN UINT8 DeviceSpeed
,
557 IN UINTN MaximumPacketLength
,
558 IN UINT8 DataBuffersNumber
,
559 IN OUT VOID
*Data
[EFI_USB_MAX_ISO_BUFFER_NUM
],
561 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
562 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack
,
568 EhciGetRootHubPortStatus (
569 IN EFI_USB2_HC_PROTOCOL
*This
,
571 OUT EFI_USB_PORT_STATUS
*PortStatus
576 EhciSetRootHubPortFeature (
577 IN EFI_USB2_HC_PROTOCOL
*This
,
579 IN EFI_USB_PORT_FEATURE PortFeature
584 EhciClearRootHubPortFeature (
585 IN EFI_USB2_HC_PROTOCOL
*This
,
587 IN EFI_USB_PORT_FEATURE PortFeature
591 // EFI Component Name Functions
595 EhciComponentNameGetDriverName (
596 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
598 OUT CHAR16
**DriverName
603 EhciComponentNameGetControllerName (
604 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
605 IN EFI_HANDLE ControllerHandle
,
606 IN EFI_HANDLE ChildHandle
, OPTIONAL
608 OUT CHAR16
**ControllerName
612 // Internal Functions Declaration
620 IN USB2_HC_DEV
*HcDev
,
621 OUT MEMORY_MANAGE_HEADER
**MemoryHeader
,
622 IN UINTN MemoryBlockSizeInPages
628 Use PciIo->AllocateBuffer to allocate common buffer for the memory block,
629 and use PciIo->Map to map the common buffer for Bus Master Read/Write.
634 MemoryHeader - MEMORY_MANAGE_HEADER to output
635 MemoryBlockSizeInPages - MemoryBlockSizeInPages
640 EFI_OUT_OF_RESOURCES Fail for no resources
641 EFI_UNSUPPORTED Unsupported currently
648 IN USB2_HC_DEV
*HcDev
,
649 IN MEMORY_MANAGE_HEADER
*MemoryHeader
660 MemoryHeader - MemoryHeader to be freed
665 EFI_INVALID_PARAMETER Parameter is error
671 InsertMemoryHeaderToList (
672 IN MEMORY_MANAGE_HEADER
*MemoryHeader
,
673 IN MEMORY_MANAGE_HEADER
*NewMemoryHeader
679 Insert Memory Header To List
683 MemoryHeader - MEMORY_MANAGE_HEADER
684 NewMemoryHeader - MEMORY_MANAGE_HEADER
694 AllocMemInMemoryBlock (
695 IN MEMORY_MANAGE_HEADER
*MemoryHeader
,
697 IN UINTN NumberOfMemoryUnit
703 Alloc Memory In MemoryBlock
707 MemoryHeader - MEMORY_MANAGE_HEADER
708 Pool - Place to store pointer to memory
709 NumberOfMemoryUnit - Number Of Memory Unit
714 EFI_NOT_FOUND Can't find the free memory
720 IsMemoryBlockEmptied (
721 IN MEMORY_MANAGE_HEADER
*MemoryHeaderPtr
727 Is Memory Block Emptied
731 MemoryHeaderPtr - MEMORY_MANAGE_HEADER
743 IN MEMORY_MANAGE_HEADER
*FirstMemoryHeader
,
744 IN MEMORY_MANAGE_HEADER
*NeedFreeMemoryHeader
754 FirstMemoryHeader - MEMORY_MANAGE_HEADER
755 NeedFreeMemoryHeader - MEMORY_MANAGE_HEADER
765 InitialMemoryManagement (
766 IN USB2_HC_DEV
*HcDev
772 Initialize Memory Management
781 EFI_DEVICE_ERROR Fail
787 DeinitialMemoryManagement (
788 IN USB2_HC_DEV
*HcDev
794 Deinitialize Memory Management
803 EFI_DEVICE_ERROR Fail
810 IN USB2_HC_DEV
*HcDev
,
823 Pool - Place to store pointer to the memory buffer
824 AllocSize - Alloc Size
829 EFI_DEVICE_ERROR Fail
836 IN USB2_HC_DEV
*HcDev
,
850 AllocSize - Pool size
863 ReadEhcCapabiltiyReg (
864 IN USB2_HC_DEV
*HcDev
,
865 IN UINT32 CapabiltiyRegAddr
,
872 Read Ehc Capabitlity register
877 CapabiltiyRegAddr - Ehc Capability register address
878 Data - A pointer to data read from register
883 EFI_DEVICE_ERROR Fail
889 ReadEhcOperationalReg (
890 IN USB2_HC_DEV
*HcDev
,
891 IN UINT32 OperationalRegAddr
,
898 Read Ehc Operation register
903 OperationalRegAddr - Ehc Operation register address
904 Data - A pointer to data read from register
909 EFI_DEVICE_ERROR Fail
915 WriteEhcOperationalReg (
916 IN USB2_HC_DEV
*HcDev
,
917 IN UINT32 OperationalRegAddr
,
924 Write Ehc Operation register
929 OperationalRegAddr - Ehc Operation register address
930 Data - 32bit write to register
935 EFI_DEVICE_ERROR Fail
942 IN USB2_HC_DEV
*HcDev
948 Set Ehc door bell bit
957 EFI_DEVICE_ERROR Fail
964 IN USB2_HC_DEV
*HcDev
,
971 Set the length of Frame List
976 Length - the required length of frame list
981 EFI_INVALID_PARAMETER Invalid parameter
982 EFI_DEVICE_ERROR Fail
988 IsFrameListProgrammable (
989 IN USB2_HC_DEV
*HcDev
995 Whether frame list is programmable
1004 FALSE Unprogrammable
1010 IsPeriodicScheduleEnabled (
1011 IN USB2_HC_DEV
*HcDev
1015 Routine Description:
1017 Whether periodic schedule is enabled
1032 IsAsyncScheduleEnabled (
1033 IN USB2_HC_DEV
*HcDev
1037 Routine Description:
1039 Whether asynchronous schedule is enabled
1055 IN USB2_HC_DEV
*HcDev
,
1060 Routine Description:
1062 Whether port is enabled
1078 IN USB2_HC_DEV
*HcDev
1082 Routine Description:
1084 Whether Ehc is halted
1100 IN USB2_HC_DEV
*HcDev
1104 Routine Description:
1106 Whether Ehc is halted
1122 IN USB2_HC_DEV
*HcDev
1126 Routine Description:
1128 Whether Ehc is system error
1137 FALSE No system error
1144 IN EFI_USB2_HC_PROTOCOL
*This
,
1149 Routine Description:
1151 Whether high speed device attached
1167 IN USB2_HC_DEV
*HcDev
,
1172 Routine Description:
1174 wait for Ehc reset or timeout
1179 Timeout - timeout threshold
1191 IN USB2_HC_DEV
*HcDev
,
1196 Routine Description:
1198 wait for Ehc halt or timeout
1203 Timeout - timeout threshold
1215 IN USB2_HC_DEV
*HcDev
,
1220 Routine Description:
1222 wait for Ehc not halt or timeout
1227 Timeout - timeout threshold
1238 WaitForEhcDoorbell (
1239 IN USB2_HC_DEV
*HcDev
,
1244 Routine Description:
1246 Wait for periodic schedule disable or timeout
1251 Timeout - timeout threshold
1262 WaitForAsyncScheduleEnable (
1263 IN USB2_HC_DEV
*HcDev
,
1268 Routine Description:
1270 Wait for Ehc asynchronous schedule enable or timeout
1275 Timeout - timeout threshold
1286 WaitForAsyncScheduleDisable (
1287 IN USB2_HC_DEV
*HcDev
,
1292 Routine Description:
1294 Wait for Ehc asynchronous schedule disable or timeout
1299 Timeout - timeout threshold
1310 WaitForPeriodicScheduleEnable (
1311 IN USB2_HC_DEV
*HcDev
,
1316 Routine Description:
1318 Wait for Ehc periodic schedule enable or timeout
1323 Timeout - timeout threshold
1334 WaitForPeriodicScheduleDisable (
1335 IN USB2_HC_DEV
*HcDev
,
1340 Routine Description:
1342 Wait for periodic schedule disable or timeout
1347 Timeout - timeout threshold
1359 IN USB2_HC_DEV
*HcDev
1363 Routine Description:
1365 Get the length of capability register
1374 EFI_DEVICE_ERROR Fail
1380 SetFrameListBaseAddr (
1381 IN USB2_HC_DEV
*HcDev
,
1382 IN UINT32 FrameBuffer
1386 Routine Description:
1388 Set base address of frame list first entry
1393 FrameBuffer - base address of first entry of frame list
1398 EFI_DEVICE_ERROR Fail
1405 IN USB2_HC_DEV
*HcDev
,
1406 IN EHCI_QH_ENTITY
*QhPtr
1410 Routine Description:
1412 Set address of first Async schedule Qh
1417 QhPtr - A pointer to first Qh in the Async schedule
1422 EFI_DEVICE_ERROR Fail
1428 SetCtrlDataStructSeg (
1429 IN USB2_HC_DEV
*HcDev
1433 Routine Description:
1435 Set address of first Async schedule Qh
1440 QhPtr - A pointer to first Qh in the Async schedule
1445 EFI_DEVICE_ERROR Fail
1452 IN USB2_HC_DEV
*HcDev
1456 Routine Description:
1458 Set Ehc port routing bit
1467 EFI_DEVICE_ERROR Fail
1473 EnablePeriodicSchedule (
1474 IN USB2_HC_DEV
*HcDev
1478 Routine Description:
1480 Enable periodic schedule
1489 EFI_DEVICE_ERROR Fail
1495 DisablePeriodicSchedule (
1496 IN USB2_HC_DEV
*HcDev
1500 Routine Description:
1502 Disable periodic schedule
1511 EFI_DEVICE_ERROR Fail
1517 EnableAsynchronousSchedule (
1518 IN USB2_HC_DEV
*HcDev
1522 Routine Description:
1524 Enable asynchrounous schedule
1533 EFI_DEVICE_ERROR Fail
1539 DisableAsynchronousSchedule (
1540 IN USB2_HC_DEV
*HcDev
1544 Routine Description:
1546 Disable asynchrounous schedule
1555 EFI_DEVICE_ERROR Fail
1561 StartScheduleExecution (
1562 IN USB2_HC_DEV
*HcDev
1566 Routine Description:
1568 Start Ehc schedule execution
1577 EFI_DEVICE_ERROR Fail
1584 IN USB2_HC_DEV
*HcDev
1588 Routine Description:
1599 EFI_DEVICE_ERROR Fail
1606 IN USB2_HC_DEV
*HcDev
1610 Routine Description:
1612 Clear Ehc all status bits
1621 EFI_DEVICE_ERROR Fail
1627 // EhciSched Functions
1630 InitialPeriodicFrameList (
1631 IN USB2_HC_DEV
*HcDev
,
1636 Routine Description:
1638 Initialize Periodic Schedule Frame List
1643 Length - Frame List Length
1648 EFI_DEVICE_ERROR Fail
1654 DeinitialPeriodicFrameList (
1655 IN USB2_HC_DEV
*HcDev
1659 Routine Description:
1661 Deinitialize Periodic Schedule Frame List
1675 CreatePollingTimer (
1676 IN USB2_HC_DEV
*HcDev
,
1677 IN EFI_EVENT_NOTIFY NotifyFunction
1681 Routine Description:
1683 Create Async Request Polling Timer
1688 NotifyFunction - Timer Notify Function
1693 EFI_DEVICE_ERROR Fail
1699 DestoryPollingTimer (
1700 IN USB2_HC_DEV
*HcDev
1704 Routine Description:
1706 Destory Async Request Polling Timer
1715 EFI_DEVICE_ERROR Fail
1722 IN USB2_HC_DEV
*HcDev
1726 Routine Description:
1728 Start Async Request Polling Timer
1737 EFI_DEVICE_ERROR Fail
1744 IN USB2_HC_DEV
*HcDev
1748 Routine Description:
1750 Stop Async Request Polling Timer
1759 EFI_DEVICE_ERROR Fail
1766 IN USB2_HC_DEV
*HcDev
,
1767 IN UINT8 DeviceAddr
,
1769 IN UINT8 DeviceSpeed
,
1770 IN UINTN MaxPacketLen
,
1771 OUT EHCI_QH_ENTITY
**QhPtrPtr
1775 Routine Description:
1777 Create Qh Structure and Pre-Initialize
1782 DeviceAddr - Address of Device
1783 Endpoint - Endpoint Number
1784 DeviceSpeed - Device Speed
1785 MaxPacketLen - Max Length of one Packet
1786 QhPtrPtr - A pointer of pointer to Qh for return
1791 EFI_DEVICE_ERROR Fail
1798 IN USB2_HC_DEV
*HcDev
,
1799 IN UINT8 DeviceAddr
,
1800 IN UINT8 DeviceSpeed
,
1801 IN UINTN MaxPacketLen
,
1802 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
1803 OUT EHCI_QH_ENTITY
**QhPtrPtr
1807 Routine Description:
1809 Create Qh for Control Transfer
1814 DeviceAddr - Address of Device
1815 DeviceSpeed - Device Speed
1816 MaxPacketLen - Max Length of one Packet
1817 Translator - Translator Transaction for SplitX
1818 QhPtrPtr - A pointer of pointer to Qh for return
1823 EFI_DEVICE_ERROR Fail
1830 IN USB2_HC_DEV
*HcDev
,
1831 IN UINT8 DeviceAddr
,
1832 IN UINT8 EndPointAddr
,
1833 IN UINT8 DeviceSpeed
,
1834 IN UINT8 DataToggle
,
1835 IN UINTN MaxPacketLen
,
1836 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
1837 OUT EHCI_QH_ENTITY
**QhPtrPtr
1841 Routine Description:
1843 Create Qh for Bulk Transfer
1848 DeviceAddr - Address of Device
1849 EndPointAddr - Address of Endpoint
1850 DeviceSpeed - Device Speed
1851 MaxPacketLen - Max Length of one Packet
1852 Translator - Translator Transaction for SplitX
1853 QhPtrPtr - A pointer of pointer to Qh for return
1858 EFI_DEVICE_ERROR Fail
1865 IN USB2_HC_DEV
*HcDev
,
1866 IN UINT8 DeviceAddr
,
1867 IN UINT8 EndPointAddr
,
1868 IN UINT8 DeviceSpeed
,
1869 IN UINT8 DataToggle
,
1870 IN UINTN MaxPacketLen
,
1872 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
1873 OUT EHCI_QH_ENTITY
**QhPtrPtr
1877 Routine Description:
1879 Create Qh for Control Transfer
1884 DeviceAddr - Address of Device
1885 EndPointAddr - Address of Endpoint
1886 DeviceSpeed - Device Speed
1887 MaxPacketLen - Max Length of one Packet
1888 Interval - value of interval
1889 Translator - Translator Transaction for SplitX
1890 QhPtrPtr - A pointer of pointer to Qh for return
1895 EFI_DEVICE_ERROR Fail
1902 IN USB2_HC_DEV
*HcDev
,
1903 IN EHCI_QH_ENTITY
*QhPtr
1907 Routine Description:
1909 Destory Qh Structure
1914 QhPtr - A pointer to Qh
1925 IN USB2_HC_DEV
*HcDev
,
1931 OUT EHCI_QTD_ENTITY
**QtdPtrPtr
1935 Routine Description:
1937 Create Qtd Structure and Pre-Initialize it
1942 DataPtr - A pointer to user data buffer to transfer
1943 DataLen - Length of user data to transfer
1944 PktId - Packet Identification of this Qtd
1945 Toggle - Data Toggle of this Qtd
1946 QtdStatus - Default value of status of this Qtd
1947 QtdPtrPtr - A pointer of pointer to Qtd for return
1952 EFI_OUT_OF_RESOURCES Cannot allocate resources
1959 IN USB2_HC_DEV
*HcDev
,
1960 IN UINT8
*DevReqPtr
,
1961 OUT EHCI_QTD_ENTITY
**QtdPtrPtr
1965 Routine Description:
1967 Create Qtd Structure for Setup
1972 DevReqPtr - A pointer to Device Request Data
1973 QtdPtrPtr - A pointer of pointer to Qtd for return
1978 EFI_OUT_OF_RESOURCES Cannot allocate resources
1985 IN USB2_HC_DEV
*HcDev
,
1990 OUT EHCI_QTD_ENTITY
**QtdPtrPtr
1994 Routine Description:
1996 Create Qtd Structure for data
2001 DataPtr - A pointer to user data buffer to transfer
2002 DataLen - Length of user data to transfer
2003 PktId - Packet Identification of this Qtd
2004 Toggle - Data Toggle of this Qtd
2005 QtdPtrPtr - A pointer of pointer to Qtd for return
2010 EFI_OUT_OF_RESOURCES Cannot allocate resources
2017 IN USB2_HC_DEV
*HcDev
,
2019 OUT EHCI_QTD_ENTITY
**QtdPtrPtr
2023 Routine Description:
2025 Create Qtd Structure for status
2030 PktId - Packet Identification of this Qtd
2031 QtdPtrPtr - A pointer of pointer to Qtd for return
2036 EFI_OUT_OF_RESOURCES Cannot allocate resources
2043 IN USB2_HC_DEV
*HcDev
,
2045 OUT EHCI_QTD_ENTITY
**QtdPtrPtr
2049 Routine Description:
2051 Create Qtd Structure for Alternative
2056 PktId - Packet Identification of this Qtd
2057 QtdPtrPtr - A pointer of pointer to Qtd for return
2062 EFI_OUT_OF_RESOURCES Cannot allocate resources
2069 IN USB2_HC_DEV
*HcDev
,
2071 IN UINT8
*RequestCursor
,
2072 IN UINT8
*DataCursor
,
2074 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
2075 OUT EHCI_QTD_ENTITY
**ControlQtdsHead
2079 Routine Description:
2081 Create Qtds list for Control Transfer
2086 DataPktId - Packet Identification of Data Qtds
2087 RequestCursor - A pointer to request structure buffer to transfer
2088 DataCursor - A pointer to user data buffer to transfer
2089 DataLen - Length of user data to transfer
2090 ControlQtdsHead - A pointer of pointer to first Qtd for control tranfer for return
2095 EFI_DEVICE_ERROR Fail
2101 CreateBulkOrInterruptQtds (
2102 IN USB2_HC_DEV
*HcDev
,
2104 IN UINT8
*DataCursor
,
2106 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
2107 OUT EHCI_QTD_ENTITY
**QtdsHead
2111 Routine Description:
2113 Create Qtds list for Bulk or Interrupt Transfer
2118 PktId - Packet Identification of Qtds
2119 DataCursor - A pointer to user data buffer to transfer
2120 DataLen - Length of user data to transfer
2121 DataToggle - Data Toggle to start
2122 Translator - Translator Transaction for SplitX
2123 QtdsHead - A pointer of pointer to first Qtd for control tranfer for return
2128 EFI_DEVICE_ERROR Fail
2135 IN USB2_HC_DEV
*HcDev
,
2136 IN EHCI_QTD_ENTITY
*FirstQtdPtr
2140 Routine Description:
2142 Destory all Qtds in the list
2147 FirstQtdPtr - A pointer to first Qtd in the list
2158 IN EHCI_QTD_ENTITY
*PreQtdPtr
,
2159 IN EHCI_QTD_ENTITY
*QtdPtr
2163 Routine Description:
2169 PreQtdPtr - A pointer to pre Qtd
2170 QtdPtr - A pointer to next Qtd
2181 IN EHCI_QTD_ENTITY
*FirstQtdPtr
,
2182 IN EHCI_QTD_ENTITY
*AltQtdPtr
2186 Routine Description:
2188 Link AlterQtds together
2192 FirstQtdPtr - A pointer to first Qtd in the list
2193 AltQtdPtr - A pointer to alternative Qtd
2203 IN EHCI_QH_ENTITY
*QhPtr
,
2204 IN EHCI_QTD_ENTITY
*QtdEntryPtr
2208 Routine Description:
2210 Link Qtds list to Qh
2214 QhPtr - A pointer to Qh
2215 QtdPtr - A pointer to first Qtd in the list
2226 IN USB2_HC_DEV
*HcDev
,
2227 IN EHCI_QH_ENTITY
*QhPtr
2231 Routine Description:
2233 Link Qh to Async Schedule List
2238 QhPtr - A pointer to Qh
2243 EFI_DEVICE_ERROR Fail
2249 UnlinkQhFromAsyncList (
2250 IN USB2_HC_DEV
*HcDev
,
2251 IN EHCI_QH_ENTITY
*QhPtr
2255 Routine Description:
2257 Unlink Qh from Async Schedule List
2262 QhPtr - A pointer to Qh
2267 EFI_DEVICE_ERROR Fail
2273 LinkQhToPeriodicList (
2274 IN USB2_HC_DEV
*HcDev
,
2275 IN EHCI_QH_ENTITY
*QhPtr
2279 Routine Description:
2281 Link Qh to Periodic Schedule List
2286 QhPtr - A pointer to Qh
2296 UnlinkQhFromPeriodicList (
2297 IN USB2_HC_DEV
*HcDev
,
2298 IN EHCI_QH_ENTITY
*QhPtr
,
2303 Routine Description:
2305 Unlink Qh from Periodic Schedule List
2310 QhPtr - A pointer to Qh
2311 Interval - Interval of this periodic transfer
2321 LinkToAsyncReqeust (
2322 IN USB2_HC_DEV
*HcDev
,
2323 IN EHCI_ASYNC_REQUEST
*AsyncRequestPtr
2327 Routine Description:
2329 Llink AsyncRequest Entry to Async Request List
2334 AsyncRequestPtr - A pointer to Async Request Entry
2344 UnlinkFromAsyncReqeust (
2345 IN USB2_HC_DEV
*HcDev
,
2346 IN EHCI_ASYNC_REQUEST
*AsyncRequestPtr
2350 Routine Description:
2352 Unlink AsyncRequest Entry from Async Request List
2357 AsyncRequestPtr - A pointer to Async Request Entry
2368 IN EHCI_QTD_ENTITY
*FirstQtdPtr
2372 Routine Description:
2374 Number of Qtds in the list
2378 FirstQtdPtr - A pointer to first Qtd in the list
2382 Number of Qtds in the list
2391 IN UINT8
*BufferCursor
2395 Routine Description:
2401 BufferCursor - BufferCursor of the Qtd
2411 GetApproxiOfInterval (
2416 Routine Description:
2418 Get the approximate value in the 2 index sequence
2422 Interval - the value of interval
2426 approximate value of interval in the 2 index sequence
2433 IN EHCI_QTD_HW
*HwQtdPtr
2437 Routine Description:
2439 Get Qtd next pointer field
2443 HwQtdPtr - A pointer to hardware Qtd structure
2447 A pointer to next hardware Qtd structure
2454 IN EHCI_QTD_HW
*HwQtdPtr
2458 Routine Description:
2460 Whether Qtd status is active or not
2464 HwQtdPtr - A pointer to hardware Qtd structure
2476 IN EHCI_QTD_HW
*HwQtdPtr
2480 Routine Description:
2482 Whether Qtd status is halted or not
2486 HwQtdPtr - A pointer to hardware Qtd structure
2497 IsQtdStatusBufferError (
2498 IN EHCI_QTD_HW
*HwQtdPtr
2502 Routine Description:
2504 Whether Qtd status is buffer error or not
2508 HwQtdPtr - A pointer to hardware Qtd structure
2513 FALSE No buffer error
2519 IsQtdStatusBabbleError (
2520 IN EHCI_QTD_HW
*HwQtdPtr
2524 Routine Description:
2526 Whether Qtd status is babble error or not
2530 HwQtdPtr - A pointer to hardware Qtd structure
2535 FALSE No babble error
2541 IsQtdStatusTransactionError (
2542 IN EHCI_QTD_HW
*HwQtdPtr
2546 Routine Description:
2548 Whether Qtd status is transaction error or not
2552 HwQtdPtr - A pointer to hardware Qtd structure
2556 TRUE Transaction error
2557 FALSE No transaction error
2564 IN UINT8 EndPointAddress
2568 Routine Description:
2570 Whether is a DataIn direction transfer
2574 EndPointAddress - address of the endpoint
2586 IN USB2_HC_DEV
*HcDev
,
2587 IN EFI_USB_DATA_DIRECTION TransferDirection
,
2589 IN OUT UINTN
*DataLength
,
2591 OUT UINT8
**DataCursor
,
2596 Routine Description:
2598 Map address of user data buffer
2603 TransferDirection - direction of transfer
2604 Data - A pointer to user data buffer
2605 DataLength - length of user data
2606 PktId - Packte Identificaion
2607 DataCursor - mapped address to return
2608 DataMap - identificaion of this mapping to return
2613 EFI_DEVICE_ERROR Fail
2620 IN USB2_HC_DEV
*HcDev
,
2621 IN OUT VOID
*Request
,
2622 OUT UINT8
**RequestCursor
,
2623 OUT VOID
**RequestMap
2627 Routine Description:
2629 Map address of request structure buffer
2634 Request - A pointer to request structure
2635 RequestCursor - Mapped address of request structure to return
2636 RequestMap - Identificaion of this mapping to return
2641 EFI_DEVICE_ERROR Fail
2647 SetQtdBufferPointer (
2648 IN EHCI_QTD_HW
*QtdHwPtr
,
2654 Routine Description:
2656 Set data buffer pointers in Qtd
2660 QtdHwPtr - A pointer to Qtd hardware structure
2661 DataPtr - A pointer to user data buffer
2662 DataLen - Length of the user data buffer
2672 GetQtdAlternateNextPointer (
2673 IN EHCI_QTD_HW
*HwQtdPtr
2677 Routine Description:
2679 Get Qtd alternate next pointer field
2683 HwQtdPtr - A pointer to hardware Qtd structure
2687 A pointer to hardware alternate Qtd
2694 IN EHCI_QH_ENTITY
*QhPtr
2698 Routine Description:
2700 Zero out the fields in Qh structure
2704 QhPtr - A pointer to Qh structure
2714 UpdateAsyncRequestTransfer (
2715 IN EHCI_ASYNC_REQUEST
*AsyncRequestPtr
,
2716 IN UINT32 TransferResult
,
2721 Routine Description:
2723 Update asynchronous request transfer
2727 AsyncRequestPtr - A pointer to async request
2728 TransferResult - transfer result
2729 ErrQtdPos - postion of error Qtd
2740 DeleteAsyncRequestTransfer (
2741 IN USB2_HC_DEV
*HcDev
,
2742 IN UINT8 DeviceAddress
,
2743 IN UINT8 EndPointAddress
,
2744 OUT UINT8
*DataToggle
2748 Routine Description:
2750 Delete all asynchronous request transfer
2755 DeviceAddress - address of usb device
2756 EndPointAddress - address of endpoint
2757 DataToggle - stored data toggle
2762 EFI_DEVICE_ERROR Fail
2768 CleanUpAllAsyncRequestTransfer (
2769 IN USB2_HC_DEV
*HcDev
2773 Routine Description:
2775 Clean up all asynchronous request transfer
2789 IN USB2_HC_DEV
*HcDev
,
2790 IN BOOLEAN IsControl
,
2791 IN EHCI_QH_ENTITY
*QhPtr
,
2792 IN OUT UINTN
*ActualLen
,
2793 OUT UINT8
*DataToggle
,
2795 OUT UINT32
*TransferResult
2799 Routine Description:
2801 Execute Bulk or SyncInterrupt Transfer
2806 IsControl - Is control transfer or not
2807 QhPtr - A pointer to Qh
2808 ActualLen - Actual transfered Len
2809 DataToggle - Data Toggle
2810 TimeOut - TimeOut threshold
2811 TransferResult - Transfer result
2816 EFI_DEVICE_ERROR Error
2822 CheckQtdsTransferResult (
2823 IN BOOLEAN IsControl
,
2824 IN EHCI_QH_ENTITY
*QhPtr
,
2826 OUT UINTN
*ErrQtdPos
,
2827 OUT UINTN
*ActualLen
2831 Routine Description:
2833 Check transfer result of Qtds
2837 IsControl - Is control transfer or not
2838 QhPtr - A pointer to Qh
2839 Result - Transfer result
2840 ErrQtdPos - Error TD Position
2841 ActualLen - Actual Transfer Size
2852 AsyncRequestMoniter (
2858 Routine Description:
2860 Interrupt transfer periodic check handler
2864 Event - Interrupt event
2865 Context - Pointer to USB2_HC_DEV
2870 EFI_DEVICE_ERROR Fail
2878 IN USB2_HC_DEV
*HcDev
2882 Routine Description:
2884 Create the NULL QH to make it as the Async QH header
2898 IN USB2_HC_DEV
*HcDev
2902 ClearLegacySupport (
2903 IN USB2_HC_DEV
*HcDev
2908 IN USB2_HC_DEV
*HcDev
2913 DumpEHCIPortsStatus (
2914 IN USB2_HC_DEV
*HcDev