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