]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h
MdeModulePkg/PciHostBridge: Add RESOURCE_VALID() to simplify code
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / XhciDxe / XhciReg.h
CommitLineData
92870c98 1/** @file\r
2\r
3 This file contains the register definition of XHCI host controller.\r
4\r
2f6ef874 5Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
92870c98 6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _EFI_XHCI_REG_H_\r
17#define _EFI_XHCI_REG_H_\r
18\r
19#define PCI_IF_XHCI 0x30\r
20\r
21//\r
22// PCI Configuration Registers\r
23//\r
24#define XHC_BAR_INDEX 0x00\r
25\r
26#define XHC_PCI_BAR_OFFSET 0x10 // Memory Bar Register Offset\r
27#define XHC_PCI_BAR_MASK 0xFFFF // Memory Base Address Mask\r
28\r
29#define USB_HUB_CLASS_CODE 0x09\r
30#define USB_HUB_SUBCLASS_CODE 0x00\r
31\r
5bcb62a4
EL
32#define XHC_CAP_USB_LEGACY 0x01\r
33#define XHC_CAP_USB_DEBUG 0x0A\r
34\r
92870c98 35//============================================//\r
36// XHCI register offset //\r
37//============================================//\r
38\r
39//\r
40// Capability registers offset\r
41//\r
42#define XHC_CAPLENGTH_OFFSET 0x00 // Capability register length offset\r
43#define XHC_HCIVERSION_OFFSET 0x02 // Interface Version Number 02-03h\r
44#define XHC_HCSPARAMS1_OFFSET 0x04 // Structural Parameters 1\r
45#define XHC_HCSPARAMS2_OFFSET 0x08 // Structural Parameters 2\r
46#define XHC_HCSPARAMS3_OFFSET 0x0c // Structural Parameters 3\r
47#define XHC_HCCPARAMS_OFFSET 0x10 // Capability Parameters\r
48#define XHC_DBOFF_OFFSET 0x14 // Doorbell Offset\r
49#define XHC_RTSOFF_OFFSET 0x18 // Runtime Register Space Offset\r
50\r
51//\r
52// Operational registers offset\r
53//\r
54#define XHC_USBCMD_OFFSET 0x0000 // USB Command Register Offset\r
55#define XHC_USBSTS_OFFSET 0x0004 // USB Status Register Offset\r
56#define XHC_PAGESIZE_OFFSET 0x0008 // USB Page Size Register Offset\r
57#define XHC_DNCTRL_OFFSET 0x0014 // Device Notification Control Register Offset\r
58#define XHC_CRCR_OFFSET 0x0018 // Command Ring Control Register Offset\r
59#define XHC_DCBAAP_OFFSET 0x0030 // Device Context Base Address Array Pointer Register Offset\r
60#define XHC_CONFIG_OFFSET 0x0038 // Configure Register Offset\r
61#define XHC_PORTSC_OFFSET 0x0400 // Port Status and Control Register Offset\r
62\r
63//\r
64// Runtime registers offset\r
65//\r
66#define XHC_MFINDEX_OFFSET 0x00 // Microframe Index Register Offset\r
67#define XHC_IMAN_OFFSET 0x20 // Interrupter X Management Register Offset\r
68#define XHC_IMOD_OFFSET 0x24 // Interrupter X Moderation Register Offset\r
69#define XHC_ERSTSZ_OFFSET 0x28 // Event Ring Segment Table Size Register Offset\r
70#define XHC_ERSTBA_OFFSET 0x30 // Event Ring Segment Table Base Address Register Offset\r
71#define XHC_ERDP_OFFSET 0x38 // Event Ring Dequeue Pointer Register Offset\r
72\r
5bcb62a4
EL
73//\r
74// Debug registers offset\r
75//\r
76#define XHC_DC_DCCTRL 0x20\r
77\r
92870c98 78#define USBLEGSP_BIOS_SEMAPHORE BIT16 // HC BIOS Owned Semaphore\r
79#define USBLEGSP_OS_SEMAPHORE BIT24 // HC OS Owned Semaphore\r
80\r
81#pragma pack (1)\r
a9292c13 82typedef struct {\r
83 UINT8 MaxSlots; // Number of Device Slots\r
84 UINT16 MaxIntrs:11; // Number of Interrupters\r
85 UINT16 Rsvd:5;\r
86 UINT8 MaxPorts; // Number of Ports\r
87} HCSPARAMS1;\r
88\r
92870c98 89//\r
90// Structural Parameters 1 Register Bitmap Definition\r
91//\r
a9292c13 92typedef union {\r
93 UINT32 Dword;\r
94 HCSPARAMS1 Data;\r
92870c98 95} XHC_HCSPARAMS1;\r
96\r
a9292c13 97typedef struct {\r
98 UINT32 Ist:4; // Isochronous Scheduling Threshold\r
99 UINT32 Erst:4; // Event Ring Segment Table Max\r
100 UINT32 Rsvd:13;\r
101 UINT32 ScratchBufHi:5; // Max Scratchpad Buffers Hi\r
102 UINT32 Spr:1; // Scratchpad Restore\r
103 UINT32 ScratchBufLo:5; // Max Scratchpad Buffers Lo\r
104} HCSPARAMS2;\r
105\r
92870c98 106//\r
107// Structural Parameters 2 Register Bitmap Definition\r
108//\r
a9292c13 109typedef union {\r
110 UINT32 Dword;\r
111 HCSPARAMS2 Data;\r
92870c98 112} XHC_HCSPARAMS2;\r
113\r
a9292c13 114typedef struct {\r
115 UINT16 Ac64:1; // 64-bit Addressing Capability\r
116 UINT16 Bnc:1; // BW Negotiation Capability\r
117 UINT16 Csz:1; // Context Size\r
118 UINT16 Ppc:1; // Port Power Control\r
119 UINT16 Pind:1; // Port Indicators\r
120 UINT16 Lhrc:1; // Light HC Reset Capability\r
121 UINT16 Ltc:1; // Latency Tolerance Messaging Capability\r
122 UINT16 Nss:1; // No Secondary SID Support\r
123 UINT16 Pae:1; // Parse All Event Data\r
124 UINT16 Rsvd:3;\r
125 UINT16 MaxPsaSize:4; // Maximum Primary Stream Array Size\r
126 UINT16 ExtCapReg; // xHCI Extended Capabilities Pointer\r
127} HCCPARAMS;\r
128\r
92870c98 129//\r
130// Capability Parameters Register Bitmap Definition\r
131//\r
a9292c13 132typedef union {\r
133 UINT32 Dword;\r
134 HCCPARAMS Data;\r
92870c98 135} XHC_HCCPARAMS;\r
136\r
137#pragma pack ()\r
138\r
139//\r
140// Register Bit Definition\r
141//\r
142#define XHC_USBCMD_RUN BIT0 // Run/Stop\r
143#define XHC_USBCMD_RESET BIT1 // Host Controller Reset\r
144#define XHC_USBCMD_INTE BIT2 // Interrupter Enable\r
145#define XHC_USBCMD_HSEE BIT3 // Host System Error Enable\r
146\r
147#define XHC_USBSTS_HALT BIT0 // Host Controller Halted\r
148#define XHC_USBSTS_HSE BIT2 // Host System Error\r
149#define XHC_USBSTS_EINT BIT3 // Event Interrupt\r
150#define XHC_USBSTS_PCD BIT4 // Port Change Detect\r
151#define XHC_USBSTS_SSS BIT8 // Save State Status\r
152#define XHC_USBSTS_RSS BIT9 // Restore State Status\r
153#define XHC_USBSTS_SRE BIT10 // Save/Restore Error\r
154#define XHC_USBSTS_CNR BIT11 // Host Controller Not Ready\r
155#define XHC_USBSTS_HCE BIT12 // Host Controller Error\r
156\r
157#define XHC_PAGESIZE_MASK 0xFFFF // Page Size\r
158\r
159#define XHC_CRCR_RCS BIT0 // Ring Cycle State\r
160#define XHC_CRCR_CS BIT1 // Command Stop\r
161#define XHC_CRCR_CA BIT2 // Command Abort\r
162#define XHC_CRCR_CRR BIT3 // Command Ring Running\r
163\r
164#define XHC_CONFIG_MASK 0xFF // Command Ring Running\r
165\r
166#define XHC_PORTSC_CCS BIT0 // Current Connect Status\r
167#define XHC_PORTSC_PED BIT1 // Port Enabled/Disabled\r
168#define XHC_PORTSC_OCA BIT3 // Over-current Active\r
169#define XHC_PORTSC_RESET BIT4 // Port Reset\r
170#define XHC_PORTSC_PLS (BIT5|BIT6|BIT7|BIT8) // Port Link State\r
171#define XHC_PORTSC_PP BIT9 // Port Power\r
c3f44a77 172#define XHC_PORTSC_PS (BIT10|BIT11|BIT12) // Port Speed\r
92870c98 173#define XHC_PORTSC_LWS BIT16 // Port Link State Write Strobe\r
174#define XHC_PORTSC_CSC BIT17 // Connect Status Change\r
175#define XHC_PORTSC_PEC BIT18 // Port Enabled/Disabled Change\r
176#define XHC_PORTSC_WRC BIT19 // Warm Port Reset Change\r
177#define XHC_PORTSC_OCC BIT20 // Over-Current Change\r
178#define XHC_PORTSC_PRC BIT21 // Port Reset Change\r
179#define XHC_PORTSC_PLC BIT22 // Port Link State Change\r
180#define XHC_PORTSC_CEC BIT23 // Port Config Error Change\r
181#define XHC_PORTSC_CAS BIT24 // Cold Attach Status\r
182\r
a50f7c4c 183#define XHC_HUB_PORTSC_CCS BIT0 // Hub's Current Connect Status\r
184#define XHC_HUB_PORTSC_PED BIT1 // Hub's Port Enabled/Disabled\r
185#define XHC_HUB_PORTSC_OCA BIT3 // Hub's Over-current Active\r
186#define XHC_HUB_PORTSC_RESET BIT4 // Hub's Port Reset\r
187#define XHC_HUB_PORTSC_PP BIT9 // Hub's Port Power\r
188#define XHC_HUB_PORTSC_CSC BIT16 // Hub's Connect Status Change\r
189#define XHC_HUB_PORTSC_PEC BIT17 // Hub's Port Enabled/Disabled Change\r
190#define XHC_HUB_PORTSC_OCC BIT19 // Hub's Over-Current Change\r
191#define XHC_HUB_PORTSC_PRC BIT20 // Hub's Port Reset Change\r
c3f44a77 192#define XHC_HUB_PORTSC_BHRC BIT21 // Hub's Port Warm Reset Change\r
92870c98 193#define XHC_IMAN_IP BIT0 // Interrupt Pending\r
194#define XHC_IMAN_IE BIT1 // Interrupt Enable\r
195\r
196#define XHC_IMODI_MASK 0x0000FFFF // Interrupt Moderation Interval\r
197#define XHC_IMODC_MASK 0xFFFF0000 // Interrupt Moderation Counter\r
198\r
c3f44a77
FT
199//\r
200// Hub Class Feature Selector for Clear Port Feature Request\r
8d84dbe9
FT
201// It's the extension of hub class feature selector of USB 2.0 in USB 3.0 Spec.\r
202// For more details, Please refer to USB 3.0 Spec Table 10-7.\r
c3f44a77 203//\r
8d84dbe9
FT
204typedef enum {\r
205 Usb3PortBHPortReset = 28,\r
206 Usb3PortBHPortResetChange = 29\r
207} XHC_PORT_FEATURE;\r
c3f44a77 208\r
92870c98 209//\r
210// Structure to map the hardware port states to the\r
211// UEFI's port states.\r
212//\r
213typedef struct {\r
214 UINT32 HwState;\r
215 UINT16 UefiState;\r
216} USB_PORT_STATE_MAP;\r
217\r
c3f44a77
FT
218//\r
219// Structure to map the hardware port states to feature selector for clear port feature request.\r
220//\r
221typedef struct {\r
222 UINT32 HwState;\r
223 UINT16 Selector;\r
224} USB_CLEAR_PORT_MAP;\r
225\r
92870c98 226/**\r
227 Read 1-byte width XHCI capability register.\r
228\r
a9292c13 229 @param Xhc The XHCI Instance.\r
92870c98 230 @param Offset The offset of the 1-byte width capability register.\r
231\r
232 @return The register content read.\r
233 @retval If err, return 0xFFFF.\r
234\r
235**/\r
236UINT8\r
237XhcReadCapReg8 (\r
a9292c13 238 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 239 IN UINT32 Offset\r
240 );\r
241\r
242/**\r
243 Read 4-bytes width XHCI capability register.\r
244\r
a9292c13 245 @param Xhc The XHCI Instance.\r
92870c98 246 @param Offset The offset of the 4-bytes width capability register.\r
247\r
248 @return The register content read.\r
249 @retval If err, return 0xFFFFFFFF.\r
250\r
251**/\r
252UINT32\r
253XhcReadCapReg (\r
a9292c13 254 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 255 IN UINT32 Offset\r
256 );\r
257\r
258/**\r
259 Read 4-bytes width XHCI Operational register.\r
260\r
a9292c13 261 @param Xhc The XHCI Instance.\r
92870c98 262 @param Offset The offset of the 4-bytes width operational register.\r
263\r
264 @return The register content read.\r
265 @retval If err, return 0xFFFFFFFF.\r
266\r
267**/\r
268UINT32\r
269XhcReadOpReg (\r
a9292c13 270 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 271 IN UINT32 Offset\r
272 );\r
273\r
274/**\r
275 Write the data to the 4-bytes width XHCI operational register.\r
276\r
a9292c13 277 @param Xhc The XHCI Instance.\r
92870c98 278 @param Offset The offset of the 4-bytes width operational register.\r
279 @param Data The data to write.\r
280\r
281**/\r
282VOID\r
283XhcWriteOpReg (\r
a9292c13 284 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 285 IN UINT32 Offset,\r
286 IN UINT32 Data\r
287 );\r
288\r
92870c98 289\r
92870c98 290/**\r
291 Read XHCI runtime register.\r
292\r
a9292c13 293 @param Xhc The XHCI Instance.\r
92870c98 294 @param Offset The offset of the runtime register.\r
295\r
296 @return The register content read\r
297\r
298**/\r
299UINT32\r
300XhcReadRuntimeReg (\r
a9292c13 301 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 302 IN UINT32 Offset\r
303 );\r
304\r
92870c98 305/**\r
306 Write the data to the XHCI runtime register.\r
307\r
a9292c13 308 @param Xhc The XHCI Instance.\r
92870c98 309 @param Offset The offset of the runtime register.\r
310 @param Data The data to write.\r
311\r
312**/\r
313VOID\r
314XhcWriteRuntimeReg (\r
a9292c13 315 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 316 IN UINT32 Offset,\r
317 IN UINT32 Data\r
318 );\r
319\r
92870c98 320\r
321/**\r
322 Write the data to the XHCI door bell register.\r
323\r
a9292c13 324 @param Xhc The XHCI Instance.\r
92870c98 325 @param Offset The offset of the door bell register.\r
326 @param Data The data to write.\r
327\r
328**/\r
329VOID\r
330XhcWriteDoorBellReg (\r
a9292c13 331 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 332 IN UINT32 Offset,\r
333 IN UINT32 Data\r
334 );\r
335\r
336/**\r
337 Set one bit of the operational register while keeping other bits.\r
338\r
a9292c13 339 @param Xhc The XHCI Instance.\r
92870c98 340 @param Offset The offset of the operational register.\r
341 @param Bit The bit mask of the register to set.\r
342\r
343**/\r
344VOID\r
345XhcSetOpRegBit (\r
a9292c13 346 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 347 IN UINT32 Offset,\r
348 IN UINT32 Bit\r
349 );\r
350\r
351/**\r
352 Clear one bit of the operational register while keeping other bits.\r
353\r
a9292c13 354 @param Xhc The XHCI Instance.\r
92870c98 355 @param Offset The offset of the operational register.\r
356 @param Bit The bit mask of the register to clear.\r
357\r
358**/\r
359VOID\r
360XhcClearOpRegBit (\r
a9292c13 361 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 362 IN UINT32 Offset,\r
363 IN UINT32 Bit\r
364 );\r
365\r
366/**\r
367 Wait the operation register's bit as specified by Bit\r
368 to be set (or clear).\r
369\r
a9292c13 370 @param Xhc The XHCI Instance.\r
92870c98 371 @param Offset The offset of the operational register.\r
372 @param Bit The bit of the register to wait for.\r
373 @param WaitToSet Wait the bit to set or clear.\r
2f6ef874 374 @param Timeout The time to wait before abort (in millisecond, ms).\r
92870c98 375\r
376 @retval EFI_SUCCESS The bit successfully changed by host controller.\r
377 @retval EFI_TIMEOUT The time out occurred.\r
378\r
379**/\r
380EFI_STATUS\r
381XhcWaitOpRegBit (\r
a9292c13 382 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 383 IN UINT32 Offset,\r
384 IN UINT32 Bit,\r
385 IN BOOLEAN WaitToSet,\r
386 IN UINT32 Timeout\r
387 );\r
388\r
389/**\r
390 Read XHCI runtime register.\r
391\r
a9292c13 392 @param Xhc The XHCI Instance.\r
92870c98 393 @param Offset The offset of the runtime register.\r
394\r
395 @return The register content read\r
396\r
397**/\r
398UINT32\r
399XhcReadRuntimeReg (\r
a9292c13 400 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 401 IN UINT32 Offset\r
402 );\r
403\r
404/**\r
405 Write the data to the XHCI runtime register.\r
406\r
a9292c13 407 @param Xhc The XHCI Instance.\r
92870c98 408 @param Offset The offset of the runtime register.\r
409 @param Data The data to write.\r
410\r
411**/\r
412VOID\r
413XhcWriteRuntimeReg (\r
a9292c13 414 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 415 IN UINT32 Offset,\r
416 IN UINT32 Data\r
417 );\r
418\r
419/**\r
420 Set one bit of the runtime register while keeping other bits.\r
421\r
a9292c13 422 @param Xhc The XHCI Instance.\r
92870c98 423 @param Offset The offset of the runtime register.\r
424 @param Bit The bit mask of the register to set.\r
425\r
426**/\r
427VOID\r
428XhcSetRuntimeRegBit (\r
a9292c13 429 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 430 IN UINT32 Offset,\r
431 IN UINT32 Bit\r
432 );\r
433\r
434/**\r
435 Clear one bit of the runtime register while keeping other bits.\r
436\r
a9292c13 437 @param Xhc The XHCI Instance.\r
92870c98 438 @param Offset The offset of the runtime register.\r
439 @param Bit The bit mask of the register to set.\r
440\r
441**/\r
442VOID\r
443XhcClearRuntimeRegBit (\r
a9292c13 444 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 445 IN UINT32 Offset,\r
446 IN UINT32 Bit\r
447 );\r
448\r
5bcb62a4
EL
449/**\r
450 Read XHCI extended capability register.\r
451\r
452 @param Xhc The XHCI Instance.\r
453 @param Offset The offset of the extended capability register.\r
454\r
455 @return The register content read\r
456\r
457**/\r
458UINT32\r
459XhcReadExtCapReg (\r
460 IN USB_XHCI_INSTANCE *Xhc,\r
461 IN UINT32 Offset\r
462 );\r
463\r
92870c98 464/**\r
465 Whether the XHCI host controller is halted.\r
466\r
a9292c13 467 @param Xhc The XHCI Instance.\r
92870c98 468\r
469 @retval TRUE The controller is halted.\r
470 @retval FALSE It isn't halted.\r
471\r
472**/\r
473BOOLEAN\r
474XhcIsHalt (\r
a9292c13 475 IN USB_XHCI_INSTANCE *Xhc\r
92870c98 476 );\r
477\r
478/**\r
479 Whether system error occurred.\r
480\r
a9292c13 481 @param Xhc The XHCI Instance.\r
92870c98 482\r
483 @retval TRUE System error happened.\r
484 @retval FALSE No system error.\r
485\r
486**/\r
487BOOLEAN\r
488XhcIsSysError (\r
a9292c13 489 IN USB_XHCI_INSTANCE *Xhc\r
92870c98 490 );\r
491\r
492/**\r
493 Reset the XHCI host controller.\r
494\r
a9292c13 495 @param Xhc The XHCI Instance.\r
2f6ef874 496 @param Timeout Time to wait before abort (in millisecond, ms).\r
92870c98 497\r
498 @retval EFI_SUCCESS The XHCI host controller is reset.\r
499 @return Others Failed to reset the XHCI before Timeout.\r
500\r
501**/\r
502EFI_STATUS\r
503XhcResetHC (\r
a9292c13 504 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 505 IN UINT32 Timeout\r
506 );\r
507\r
508/**\r
509 Halt the XHCI host controller.\r
510\r
a9292c13 511 @param Xhc The XHCI Instance.\r
2f6ef874 512 @param Timeout Time to wait before abort (in millisecond, ms).\r
92870c98 513\r
514 @return EFI_SUCCESS The XHCI host controller is halt.\r
515 @return EFI_TIMEOUT Failed to halt the XHCI before Timeout.\r
516\r
517**/\r
518EFI_STATUS\r
519XhcHaltHC (\r
a9292c13 520 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 521 IN UINT32 Timeout\r
522 );\r
523\r
524/**\r
525 Set the XHCI host controller to run.\r
526\r
a9292c13 527 @param Xhc The XHCI Instance.\r
2f6ef874 528 @param Timeout Time to wait before abort (in millisecond, ms).\r
92870c98 529\r
530 @return EFI_SUCCESS The XHCI host controller is running.\r
531 @return EFI_TIMEOUT Failed to set the XHCI to run before Timeout.\r
532\r
533**/\r
534EFI_STATUS\r
535XhcRunHC (\r
a9292c13 536 IN USB_XHCI_INSTANCE *Xhc,\r
92870c98 537 IN UINT32 Timeout\r
538 );\r
539\r
540/**\r
5bcb62a4 541 Calculate the offset of the XHCI capability.\r
92870c98 542\r
a9292c13 543 @param Xhc The XHCI Instance.\r
5bcb62a4 544 @param CapId The XHCI Capability ID.\r
92870c98 545\r
546 @return The offset of XHCI legacy support capability register.\r
547\r
548**/\r
549UINT32\r
5bcb62a4
EL
550XhcGetCapabilityAddr (\r
551 IN USB_XHCI_INSTANCE *Xhc,\r
552 IN UINT8 CapId\r
92870c98 553 );\r
554\r
555#endif\r