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