]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/EhciPei/EhciReg.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciPei / EhciReg.h
CommitLineData
4b1bf81c 1/** @file\r
2Private Header file for Usb Host Controller PEIM\r
3\r
d1102dba
LG
4Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
5\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
4b1bf81c 7\r
8**/\r
9\r
10#ifndef _EFI_EHCI_REG_H_\r
11#define _EFI_EHCI_REG_H_\r
12\r
13\r
14\r
15//\r
16// Capability register offset\r
17//\r
18#define EHC_CAPLENGTH_OFFSET 0 // Capability register length offset\r
19#define EHC_HCSPARAMS_OFFSET 0x04 // Structural Parameters 04-07h\r
20#define EHC_HCCPARAMS_OFFSET 0x08 // Capability parameters offset\r
21\r
22//\r
23// Capability register bit definition\r
24//\r
25#define HCSP_NPORTS 0x0F // Number of root hub port\r
26#define HCCP_64BIT 0x01 // 64-bit addressing capability\r
27\r
28//\r
29// Operational register offset\r
30//\r
31#define EHC_USBCMD_OFFSET 0x0 // USB command register offset\r
32#define EHC_USBSTS_OFFSET 0x04 // Statue register offset\r
33#define EHC_USBINTR_OFFSET 0x08 // USB interrutp offset\r
34#define EHC_FRINDEX_OFFSET 0x0C // Frame index offset\r
35#define EHC_CTRLDSSEG_OFFSET 0x10 // Control data structure segment offset\r
36#define EHC_FRAME_BASE_OFFSET 0x14 // Frame list base address offset\r
37#define EHC_ASYNC_HEAD_OFFSET 0x18 // Next asynchronous list address offset\r
38#define EHC_CONFIG_FLAG_OFFSET 0x40 // Configure flag register offset\r
39#define EHC_PORT_STAT_OFFSET 0x44 // Port status/control offset\r
40\r
41#define EHC_FRAME_LEN 1024\r
42\r
43//\r
44// Register bit definition\r
45//\r
46#define CONFIGFLAG_ROUTE_EHC 0x01 // Route port to EHC\r
47\r
48#define USBCMD_RUN 0x01 // Run/stop\r
49#define USBCMD_RESET 0x02 // Start the host controller reset\r
50#define USBCMD_ENABLE_PERIOD 0x10 // Enable periodic schedule\r
51#define USBCMD_ENABLE_ASYNC 0x20 // Enable asynchronous schedule\r
52#define USBCMD_IAAD 0x40 // Interrupt on async advance doorbell\r
53\r
54#define USBSTS_IAA 0x20 // Interrupt on async advance\r
55#define USBSTS_PERIOD_ENABLED 0x4000 // Periodic schedule status\r
56#define USBSTS_ASYNC_ENABLED 0x8000 // Asynchronous schedule status\r
57#define USBSTS_HALT 0x1000 // Host controller halted\r
58#define USBSTS_SYS_ERROR 0x10 // Host system error\r
59#define USBSTS_INTACK_MASK 0x003F // Mask for the interrupt ACK, the WC\r
60 // (write clean) bits in USBSTS register\r
61\r
62#define PORTSC_CONN 0x01 // Current Connect Status\r
63#define PORTSC_CONN_CHANGE 0x02 // Connect Status Change\r
64#define PORTSC_ENABLED 0x04 // Port Enable / Disable\r
65#define PORTSC_ENABLE_CHANGE 0x08 // Port Enable / Disable Change\r
66#define PORTSC_OVERCUR 0x10 // Over current Active\r
67#define PORTSC_OVERCUR_CHANGE 0x20 // Over current Change\r
68#define PORSTSC_RESUME 0x40 // Force Port Resume\r
69#define PORTSC_SUSPEND 0x80 // Port Suspend State\r
70#define PORTSC_RESET 0x100 // Port Reset\r
71#define PORTSC_LINESTATE_K 0x400 // Line Status K-state\r
72#define PORTSC_LINESTATE_J 0x800 // Line Status J-state\r
73#define PORTSC_POWER 0x1000 // Port Power\r
74#define PORTSC_OWNER 0x2000 // Port Owner\r
75#define PORTSC_CHANGE_MASK 0x2A // Mask of the port change bits,\r
76 // they are WC (write clean)\r
77//\r
78// PCI Configuration Registers\r
79//\r
80#define EHC_BAR_INDEX 0 // how many bytes away from USB_BASE to 0x10\r
81\r
82#define EHC_LINK_TERMINATED(Link) (((Link) & 0x01) != 0)\r
83\r
84#define EHC_ADDR(High, QhHw32) \\r
85 ((VOID *) (UINTN) (LShiftU64 ((High), 32) | ((QhHw32) & 0xFFFFFFF0)))\r
86\r
87#define EHCI_IS_DATAIN(EndpointAddr) EHC_BIT_IS_SET((EndpointAddr), 0x80)\r
88\r
89//\r
d1102dba
LG
90// Structure to map the hardware port states to the\r
91// UEFI's port states.\r
4b1bf81c 92//\r
93typedef struct {\r
94 UINT16 HwState;\r
95 UINT16 UefiState;\r
96} USB_PORT_STATE_MAP;\r
97\r
98//\r
99// Ehci Data and Ctrl Structures\r
100//\r
101#pragma pack(1)\r
102typedef struct {\r
103 UINT8 Pi;\r
104 UINT8 SubClassCode;\r
105 UINT8 BaseCode;\r
106} USB_CLASSC;\r
107#pragma pack()\r
108\r
109\r
110/**\r
111 Read EHCI capability register.\r
d1102dba 112\r
4b1bf81c 113 @param Ehc The EHCI device.\r
114 @param Offset Capability register address.\r
115\r
116 @retval the register content read.\r
117\r
118**/\r
119UINT32\r
120EhcReadCapRegister (\r
121 IN PEI_USB2_HC_DEV *Ehc,\r
122 IN UINT32 Offset\r
123 )\r
124;\r
125\r
126/**\r
127 Read Ehc Operation register.\r
d1102dba 128\r
4b1bf81c 129 @param Ehc The EHCI device.\r
130 @param Offset The operation register offset.\r
131\r
132 @retval the register content read.\r
133\r
134**/\r
135UINT32\r
136EhcReadOpReg (\r
137 IN PEI_USB2_HC_DEV *Ehc,\r
138 IN UINT32 Offset\r
139 )\r
140;\r
141\r
142/**\r
143 Write the data to the EHCI operation register.\r
d1102dba 144\r
4b1bf81c 145 @param Ehc The EHCI device.\r
146 @param Offset EHCI operation register offset.\r
147 @param Data The data to write.\r
148\r
149**/\r
150VOID\r
151EhcWriteOpReg (\r
152 IN PEI_USB2_HC_DEV *Ehc,\r
153 IN UINT32 Offset,\r
154 IN UINT32 Data\r
155 )\r
156;\r
157\r
158/**\r
159 Stop the legacy USB SMI support.\r
d1102dba 160\r
4b1bf81c 161 @param Ehc The EHCI device.\r
162\r
163**/\r
164VOID\r
165EhcClearLegacySupport (\r
166 IN PEI_USB2_HC_DEV *Ehc\r
167 )\r
168;\r
169\r
170/**\r
171 Set door bell and wait it to be ACKed by host controller.\r
172 This function is used to synchronize with the hardware.\r
d1102dba 173\r
4b1bf81c 174 @param Ehc The EHCI device.\r
175 @param Timeout The time to wait before abort (in millisecond, ms).\r
176\r
177 @retval EFI_TIMEOUT Time out happened while waiting door bell to set.\r
178 @retval EFI_SUCCESS Synchronized with the hardware.\r
179\r
180**/\r
181EFI_STATUS\r
182EhcSetAndWaitDoorBell (\r
183 IN PEI_USB2_HC_DEV *Ehc,\r
184 IN UINT32 Timeout\r
185 )\r
186;\r
187\r
188/**\r
d1102dba 189 Clear all the interrutp status bits, these bits\r
4b1bf81c 190 are Write-Clean.\r
d1102dba 191\r
4b1bf81c 192 @param Ehc The EHCI device.\r
193\r
194**/\r
195VOID\r
196EhcAckAllInterrupt (\r
197 IN PEI_USB2_HC_DEV *Ehc\r
198 )\r
199;\r
200\r
201/**\r
202 Check whether Ehc is halted.\r
d1102dba 203\r
4b1bf81c 204 @param Ehc The EHCI device.\r
205\r
206 @retval TRUE The controller is halted.\r
207 @retval FALSE The controller isn't halted.\r
208\r
209**/\r
210BOOLEAN\r
211EhcIsHalt (\r
212 IN PEI_USB2_HC_DEV *Ehc\r
213 )\r
214;\r
215\r
216/**\r
217 Check whether system error occurred.\r
d1102dba 218\r
4b1bf81c 219 @param Ehc The EHCI device.\r
220\r
221 @retval TRUE System error happened.\r
222 @retval FALSE No system error.\r
223\r
224**/\r
225BOOLEAN\r
226EhcIsSysError (\r
227 IN PEI_USB2_HC_DEV *Ehc\r
228 )\r
229;\r
230\r
231/**\r
232 Reset the host controller.\r
d1102dba 233\r
4b1bf81c 234 @param Ehc The EHCI device.\r
235 @param Timeout Time to wait before abort (in millisecond, ms).\r
236\r
237 @retval EFI_TIMEOUT The transfer failed due to time out.\r
238 @retval Others Failed to reset the host.\r
239\r
240**/\r
241EFI_STATUS\r
242EhcResetHC (\r
243 IN PEI_USB2_HC_DEV *Ehc,\r
244 IN UINT32 Timeout\r
245 )\r
246;\r
247\r
248/**\r
249 Halt the host controller.\r
d1102dba 250\r
4b1bf81c 251 @param Ehc The EHCI device.\r
252 @param Timeout Time to wait before abort.\r
253\r
254 @retval EFI_TIMEOUT Failed to halt the controller before Timeout.\r
255 @retval EFI_SUCCESS The EHCI is halt.\r
256\r
257**/\r
258EFI_STATUS\r
259EhcHaltHC (\r
260 IN PEI_USB2_HC_DEV *Ehc,\r
261 IN UINT32 Timeout\r
262 )\r
263;\r
264\r
265/**\r
266 Set the EHCI to run\r
d1102dba 267\r
4b1bf81c 268 @param Ehc The EHCI device.\r
269 @param Timeout Time to wait before abort.\r
270\r
271 @retval EFI_SUCCESS The EHCI is running.\r
272 @retval Others Failed to set the EHCI to run.\r
273\r
274**/\r
275EFI_STATUS\r
276EhcRunHC (\r
277 IN PEI_USB2_HC_DEV *Ehc,\r
278 IN UINT32 Timeout\r
279 )\r
280;\r
281\r
282/**\r
d1102dba 283 Initialize the HC hardware.\r
4b1bf81c 284 EHCI spec lists the five things to do to initialize the hardware.\r
285 1. Program CTRLDSSEGMENT.\r
286 2. Set USBINTR to enable interrupts.\r
287 3. Set periodic list base.\r
288 4. Set USBCMD, interrupt threshold, frame list size etc.\r
289 5. Write 1 to CONFIGFLAG to route all ports to EHCI.\r
d1102dba 290\r
4b1bf81c 291 @param Ehc The EHCI device.\r
292\r
293 @retval EFI_SUCCESS The EHCI has come out of halt state.\r
294 @retval EFI_TIMEOUT Time out happened.\r
295\r
296**/\r
297EFI_STATUS\r
298EhcInitHC (\r
299 IN PEI_USB2_HC_DEV *Ehc\r
300 )\r
301;\r
302\r
303#endif\r