]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/XhciPei/XhciReg.h
MdeModulePkg/XhciDxe: Check return value of XHC_PAGESIZE register
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / XhciPei / XhciReg.h
1 /** @file
2 Private Header file for Usb Host Controller PEIM
3
4 Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _EFI_PEI_XHCI_REG_H_
11 #define _EFI_PEI_XHCI_REG_H_
12
13 //
14 // Capability registers offset
15 //
16 #define XHC_CAPLENGTH_OFFSET 0x00 // Capability register length offset
17 #define XHC_HCIVERSION_OFFSET 0x02 // Interface Version Number 02-03h
18 #define XHC_HCSPARAMS1_OFFSET 0x04 // Structural Parameters 1
19 #define XHC_HCSPARAMS2_OFFSET 0x08 // Structural Parameters 2
20 #define XHC_HCSPARAMS3_OFFSET 0x0c // Structural Parameters 3
21 #define XHC_HCCPARAMS_OFFSET 0x10 // Capability Parameters
22 #define XHC_DBOFF_OFFSET 0x14 // Doorbell Offset
23 #define XHC_RTSOFF_OFFSET 0x18 // Runtime Register Space Offset
24
25 //
26 // Operational registers offset
27 //
28 #define XHC_USBCMD_OFFSET 0x0000 // USB Command Register Offset
29 #define XHC_USBSTS_OFFSET 0x0004 // USB Status Register Offset
30 #define XHC_PAGESIZE_OFFSET 0x0008 // USB Page Size Register Offset
31 #define XHC_DNCTRL_OFFSET 0x0014 // Device Notification Control Register Offset
32 #define XHC_CRCR_OFFSET 0x0018 // Command Ring Control Register Offset
33 #define XHC_DCBAAP_OFFSET 0x0030 // Device Context Base Address Array Pointer Register Offset
34 #define XHC_CONFIG_OFFSET 0x0038 // Configure Register Offset
35 #define XHC_PORTSC_OFFSET 0x0400 // Port Status and Control Register Offset
36
37 //
38 // Runtime registers offset
39 //
40 #define XHC_MFINDEX_OFFSET 0x00 // Microframe Index Register Offset
41 #define XHC_IMAN_OFFSET 0x20 // Interrupter X Management Register Offset
42 #define XHC_IMOD_OFFSET 0x24 // Interrupter X Moderation Register Offset
43 #define XHC_ERSTSZ_OFFSET 0x28 // Event Ring Segment Table Size Register Offset
44 #define XHC_ERSTBA_OFFSET 0x30 // Event Ring Segment Table Base Address Register Offset
45 #define XHC_ERDP_OFFSET 0x38 // Event Ring Dequeue Pointer Register Offset
46
47 //
48 // Register Bit Definition
49 //
50 #define XHC_USBCMD_RUN BIT0 // Run/Stop
51 #define XHC_USBCMD_RESET BIT1 // Host Controller Reset
52 #define XHC_USBCMD_INTE BIT2 // Interrupter Enable
53 #define XHC_USBCMD_HSEE BIT3 // Host System Error Enable
54
55 #define XHC_USBSTS_HALT BIT0 // Host Controller Halted
56 #define XHC_USBSTS_HSE BIT2 // Host System Error
57 #define XHC_USBSTS_EINT BIT3 // Event Interrupt
58 #define XHC_USBSTS_PCD BIT4 // Port Change Detect
59 #define XHC_USBSTS_SSS BIT8 // Save State Status
60 #define XHC_USBSTS_RSS BIT9 // Restore State Status
61 #define XHC_USBSTS_SRE BIT10 // Save/Restore Error
62 #define XHC_USBSTS_CNR BIT11 // Host Controller Not Ready
63 #define XHC_USBSTS_HCE BIT12 // Host Controller Error
64
65 #define XHC_PAGESIZE_MASK 0xFFFF // Page Size
66
67 #define XHC_CRCR_RCS BIT0 // Ring Cycle State
68 #define XHC_CRCR_CS BIT1 // Command Stop
69 #define XHC_CRCR_CA BIT2 // Command Abort
70 #define XHC_CRCR_CRR BIT3 // Command Ring Running
71
72 #define XHC_CONFIG_MASK 0xFF // Max Device Slots Enabled
73
74 #define XHC_PORTSC_CCS BIT0 // Current Connect Status
75 #define XHC_PORTSC_PED BIT1 // Port Enabled/Disabled
76 #define XHC_PORTSC_OCA BIT3 // Over-current Active
77 #define XHC_PORTSC_RESET BIT4 // Port Reset
78 #define XHC_PORTSC_PLS (BIT5|BIT6|BIT7|BIT8) // Port Link State
79 #define XHC_PORTSC_PP BIT9 // Port Power
80 #define XHC_PORTSC_PS (BIT10|BIT11|BIT12|BIT13) // Port Speed
81 #define XHC_PORTSC_LWS BIT16 // Port Link State Write Strobe
82 #define XHC_PORTSC_CSC BIT17 // Connect Status Change
83 #define XHC_PORTSC_PEC BIT18 // Port Enabled/Disabled Change
84 #define XHC_PORTSC_WRC BIT19 // Warm Port Reset Change
85 #define XHC_PORTSC_OCC BIT20 // Over-Current Change
86 #define XHC_PORTSC_PRC BIT21 // Port Reset Change
87 #define XHC_PORTSC_PLC BIT22 // Port Link State Change
88 #define XHC_PORTSC_CEC BIT23 // Port Config Error Change
89 #define XHC_PORTSC_CAS BIT24 // Cold Attach Status
90
91 #define XHC_HUB_PORTSC_CCS BIT0 // Hub's Current Connect Status
92 #define XHC_HUB_PORTSC_PED BIT1 // Hub's Port Enabled/Disabled
93 #define XHC_HUB_PORTSC_OCA BIT3 // Hub's Over-current Active
94 #define XHC_HUB_PORTSC_RESET BIT4 // Hub's Port Reset
95 #define XHC_HUB_PORTSC_PP BIT9 // Hub's Port Power
96 #define XHC_HUB_PORTSC_CSC BIT16 // Hub's Connect Status Change
97 #define XHC_HUB_PORTSC_PEC BIT17 // Hub's Port Enabled/Disabled Change
98 #define XHC_HUB_PORTSC_OCC BIT19 // Hub's Over-Current Change
99 #define XHC_HUB_PORTSC_PRC BIT20 // Hub's Port Reset Change
100 #define XHC_HUB_PORTSC_BHRC BIT21 // Hub's Port Warm Reset Change
101
102 #define XHC_IMAN_IP BIT0 // Interrupt Pending
103 #define XHC_IMAN_IE BIT1 // Interrupt Enable
104
105 #define XHC_IMODI_MASK 0x0000FFFF // Interrupt Moderation Interval
106 #define XHC_IMODC_MASK 0xFFFF0000 // Interrupt Moderation Counter
107
108 #pragma pack (1)
109 typedef struct {
110 UINT8 MaxSlots; // Number of Device Slots
111 UINT16 MaxIntrs : 11; // Number of Interrupters
112 UINT16 Rsvd : 5;
113 UINT8 MaxPorts; // Number of Ports
114 } HCSPARAMS1;
115
116 //
117 // Structural Parameters 1 Register Bitmap Definition
118 //
119 typedef union {
120 UINT32 Dword;
121 HCSPARAMS1 Data;
122 } XHC_HCSPARAMS1;
123
124 typedef struct {
125 UINT32 Ist : 4; // Isochronous Scheduling Threshold
126 UINT32 Erst : 4; // Event Ring Segment Table Max
127 UINT32 Rsvd : 13;
128 UINT32 ScratchBufHi : 5; // Max Scratchpad Buffers Hi
129 UINT32 Spr : 1; // Scratchpad Restore
130 UINT32 ScratchBufLo : 5; // Max Scratchpad Buffers Lo
131 } HCSPARAMS2;
132
133 //
134 // Structural Parameters 2 Register Bitmap Definition
135 //
136 typedef union {
137 UINT32 Dword;
138 HCSPARAMS2 Data;
139 } XHC_HCSPARAMS2;
140
141 typedef struct {
142 UINT16 Ac64 : 1; // 64-bit Addressing Capability
143 UINT16 Bnc : 1; // BW Negotiation Capability
144 UINT16 Csz : 1; // Context Size
145 UINT16 Ppc : 1; // Port Power Control
146 UINT16 Pind : 1; // Port Indicators
147 UINT16 Lhrc : 1; // Light HC Reset Capability
148 UINT16 Ltc : 1; // Latency Tolerance Messaging Capability
149 UINT16 Nss : 1; // No Secondary SID Support
150 UINT16 Pae : 1; // Parse All Event Data
151 UINT16 Rsvd : 3;
152 UINT16 MaxPsaSize : 4; // Maximum Primary Stream Array Size
153 UINT16 ExtCapReg; // xHCI Extended Capabilities Pointer
154 } HCCPARAMS;
155
156 //
157 // Capability Parameters Register Bitmap Definition
158 //
159 typedef union {
160 UINT32 Dword;
161 HCCPARAMS Data;
162 } XHC_HCCPARAMS;
163
164 #pragma pack ()
165
166 //
167 // XHCi Data and Ctrl Structures
168 //
169 #pragma pack(1)
170 typedef struct {
171 UINT8 Pi;
172 UINT8 SubClassCode;
173 UINT8 BaseCode;
174 } USB_CLASSC;
175
176 typedef struct {
177 UINT8 Length;
178 UINT8 DescType;
179 UINT8 NumPorts;
180 UINT16 HubCharacter;
181 UINT8 PwrOn2PwrGood;
182 UINT8 HubContrCurrent;
183 UINT8 Filler[16];
184 } EFI_USB_HUB_DESCRIPTOR;
185 #pragma pack()
186
187 //
188 // Hub Class Feature Selector for Clear Port Feature Request
189 // It's the extension of hub class feature selector of USB 2.0 in USB 3.0 Spec.
190 // For more details, Please refer to USB 3.0 Spec Table 10-7.
191 //
192 typedef enum {
193 Usb3PortBHPortReset = 28,
194 Usb3PortBHPortResetChange = 29
195 } XHC_PORT_FEATURE;
196
197 //
198 // Structure to map the hardware port states to the
199 // UEFI's port states.
200 //
201 typedef struct {
202 UINT32 HwState;
203 UINT16 UefiState;
204 } USB_PORT_STATE_MAP;
205
206 //
207 // Structure to map the hardware port states to feature selector for clear port feature request.
208 //
209 typedef struct {
210 UINT32 HwState;
211 UINT16 Selector;
212 } USB_CLEAR_PORT_MAP;
213
214 /**
215 Read XHCI Operation register.
216
217 @param Xhc The XHCI device.
218 @param Offset The operation register offset.
219
220 @retval the register content read.
221
222 **/
223 UINT32
224 XhcPeiReadOpReg (
225 IN PEI_XHC_DEV *Xhc,
226 IN UINT32 Offset
227 );
228
229 /**
230 Write the data to the XHCI operation register.
231
232 @param Xhc The XHCI device.
233 @param Offset The operation register offset.
234 @param Data The data to write.
235
236 **/
237 VOID
238 XhcPeiWriteOpReg (
239 IN PEI_XHC_DEV *Xhc,
240 IN UINT32 Offset,
241 IN UINT32 Data
242 );
243
244 /**
245 Set one bit of the operational register while keeping other bits.
246
247 @param Xhc The XHCI device.
248 @param Offset The offset of the operational register.
249 @param Bit The bit mask of the register to set.
250
251 **/
252 VOID
253 XhcPeiSetOpRegBit (
254 IN PEI_XHC_DEV *Xhc,
255 IN UINT32 Offset,
256 IN UINT32 Bit
257 );
258
259 /**
260 Clear one bit of the operational register while keeping other bits.
261
262 @param Xhc The XHCI device.
263 @param Offset The offset of the operational register.
264 @param Bit The bit mask of the register to clear.
265
266 **/
267 VOID
268 XhcPeiClearOpRegBit (
269 IN PEI_XHC_DEV *Xhc,
270 IN UINT32 Offset,
271 IN UINT32 Bit
272 );
273
274 /**
275 Wait the operation register's bit as specified by Bit
276 to be set (or clear).
277
278 @param Xhc The XHCI device.
279 @param Offset The offset of the operational register.
280 @param Bit The bit of the register to wait for.
281 @param WaitToSet Wait the bit to set or clear.
282 @param Timeout The time to wait before abort (in millisecond, ms).
283
284 @retval EFI_SUCCESS The bit successfully changed by host controller.
285 @retval EFI_TIMEOUT The time out occurred.
286
287 **/
288 EFI_STATUS
289 XhcPeiWaitOpRegBit (
290 IN PEI_XHC_DEV *Xhc,
291 IN UINT32 Offset,
292 IN UINT32 Bit,
293 IN BOOLEAN WaitToSet,
294 IN UINT32 Timeout
295 );
296
297 /**
298 Write the data to the XHCI door bell register.
299
300 @param Xhc The XHCI device.
301 @param Offset The offset of the door bell register.
302 @param Data The data to write.
303
304 **/
305 VOID
306 XhcPeiWriteDoorBellReg (
307 IN PEI_XHC_DEV *Xhc,
308 IN UINT32 Offset,
309 IN UINT32 Data
310 );
311
312 /**
313 Read XHCI runtime register.
314
315 @param Xhc The XHCI device.
316 @param Offset The offset of the runtime register.
317
318 @return The register content read
319
320 **/
321 UINT32
322 XhcPeiReadRuntimeReg (
323 IN PEI_XHC_DEV *Xhc,
324 IN UINT32 Offset
325 );
326
327 /**
328 Write the data to the XHCI runtime register.
329
330 @param Xhc The XHCI device.
331 @param Offset The offset of the runtime register.
332 @param Data The data to write.
333
334 **/
335 VOID
336 XhcPeiWriteRuntimeReg (
337 IN PEI_XHC_DEV *Xhc,
338 IN UINT32 Offset,
339 IN UINT32 Data
340 );
341
342 /**
343 Set one bit of the runtime register while keeping other bits.
344
345 @param Xhc The XHCI device.
346 @param Offset The offset of the runtime register.
347 @param Bit The bit mask of the register to set.
348
349 **/
350 VOID
351 XhcPeiSetRuntimeRegBit (
352 IN PEI_XHC_DEV *Xhc,
353 IN UINT32 Offset,
354 IN UINT32 Bit
355 );
356
357 /**
358 Clear one bit of the runtime register while keeping other bits.
359
360 @param Xhc The XHCI device.
361 @param Offset The offset of the runtime register.
362 @param Bit The bit mask of the register to set.
363
364 **/
365 VOID
366 XhcPeiClearRuntimeRegBit (
367 IN PEI_XHC_DEV *Xhc,
368 IN UINT32 Offset,
369 IN UINT32 Bit
370 );
371
372 /**
373 Check whether Xhc is halted.
374
375 @param Xhc The XHCI device.
376
377 @retval TRUE The controller is halted.
378 @retval FALSE The controller isn't halted.
379
380 **/
381 BOOLEAN
382 XhcPeiIsHalt (
383 IN PEI_XHC_DEV *Xhc
384 );
385
386 /**
387 Check whether system error occurred.
388
389 @param Xhc The XHCI device.
390
391 @retval TRUE System error happened.
392 @retval FALSE No system error.
393
394 **/
395 BOOLEAN
396 XhcPeiIsSysError (
397 IN PEI_XHC_DEV *Xhc
398 );
399
400 /**
401 Reset the host controller.
402
403 @param Xhc The XHCI device.
404 @param Timeout Time to wait before abort (in millisecond, ms).
405
406 @retval EFI_TIMEOUT The transfer failed due to time out.
407 @retval Others Failed to reset the host.
408
409 **/
410 EFI_STATUS
411 XhcPeiResetHC (
412 IN PEI_XHC_DEV *Xhc,
413 IN UINT32 Timeout
414 );
415
416 /**
417 Halt the host controller.
418
419 @param Xhc The XHCI device.
420 @param Timeout Time to wait before abort.
421
422 @retval EFI_TIMEOUT Failed to halt the controller before Timeout.
423 @retval EFI_SUCCESS The XHCI is halt.
424
425 **/
426 EFI_STATUS
427 XhcPeiHaltHC (
428 IN PEI_XHC_DEV *Xhc,
429 IN UINT32 Timeout
430 );
431
432 /**
433 Set the XHCI to run.
434
435 @param Xhc The XHCI device.
436 @param Timeout Time to wait before abort.
437
438 @retval EFI_SUCCESS The XHCI is running.
439 @retval Others Failed to set the XHCI to run.
440
441 **/
442 EFI_STATUS
443 XhcPeiRunHC (
444 IN PEI_XHC_DEV *Xhc,
445 IN UINT32 Timeout
446 );
447
448 #endif