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