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