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