]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h
Enabling usb3.0 XHCI support.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / XhciDxe / XhciSched.h
1 /** @file
2
3 This file contains the definition for XHCI host controller schedule routines.
4
5 Copyright (c) 2011, 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_SCHED_H_
17 #define _EFI_XHCI_SCHED_H_
18
19 #define XHC_URB_SIG SIGNATURE_32 ('U', 'S', 'B', 'R')
20
21 //
22 // Transfer types, used in URB to identify the transfer type
23 //
24 #define XHC_CTRL_TRANSFER 0x01
25 #define XHC_BULK_TRANSFER 0x02
26 #define XHC_INT_TRANSFER_SYNC 0x04
27 #define XHC_INT_TRANSFER_ASYNC 0x08
28 #define XHC_INT_ONLY_TRANSFER_ASYNC 0x10
29
30 //
31 // 6.4.6 TRB Types
32 //
33 #define TRB_TYPE_NORMAL 1
34 #define TRB_TYPE_SETUP_STAGE 2
35 #define TRB_TYPE_DATA_STAGE 3
36 #define TRB_TYPE_STATUS_STAGE 4
37 #define TRB_TYPE_ISOCH 5
38 #define TRB_TYPE_LINK 6
39 #define TRB_TYPE_EVENT_DATA 7
40 #define TRB_TYPE_NO_OP 8
41 #define TRB_TYPE_EN_SLOT 9
42 #define TRB_TYPE_DIS_SLOT 10
43 #define TRB_TYPE_ADDRESS_DEV 11
44 #define TRB_TYPE_CON_ENDPOINT 12
45 #define TRB_TYPE_EVALU_CONTXT 13
46 #define TRB_TYPE_RESET_ENDPOINT 14
47 #define TRB_TYPE_STOP_ENDPOINT 15
48 #define TRB_TYPE_SET_TR_DEQUE 16
49 #define TRB_TYPE_RESET_DEV 17
50 #define TRB_TYPE_GET_PORT_BANW 21
51 #define TRB_TYPE_FORCE_HEADER 22
52 #define TRB_TYPE_NO_OP_COMMAND 23
53 #define TRB_TYPE_TRANS_EVENT 32
54 #define TRB_TYPE_COMMAND_COMPLT_EVENT 33
55 #define TRB_TYPE_PORT_STATUS_CHANGE_EVENT 34
56 #define TRB_TYPE_HOST_CONTROLLER_EVENT 37
57 #define TRB_TYPE_DEVICE_NOTIFI_EVENT 38
58 #define TRB_TYPE_MFINDEX_WRAP_EVENT 39
59
60 //
61 // Endpoint Type (EP Type).
62 //
63 #define ED_NOT_VALID 0
64 #define ED_ISOCH_OUT 1
65 #define ED_BULK_OUT 2
66 #define ED_INTERRUPT_OUT 3
67 #define ED_CONTROL_BIDIR 4
68 #define ED_ISOCH_IN 5
69 #define ED_BULK_IN 6
70 #define ED_INTERRUPT_IN 7
71
72 //
73 // 6.4.5 TRB Completion Codes
74 //
75 #define TRB_COMPLETION_INVALID 0
76 #define TRB_COMPLETION_SUCCESS 1
77 #define TRB_COMPLETION_DATA_BUFFER_ERROR 2
78 #define TRB_COMPLETION_BABBLE_ERROR 3
79 #define TRB_COMPLETION_USB_TRANSACTION_ERROR 4
80 #define TRB_COMPLETION_TRB_ERROR 5
81 #define TRB_COMPLETION_STALL_ERROR 6
82 #define TRB_COMPLETION_SHORT_PACKET 13
83
84 //
85 // USB device RouteChart record
86 //
87 typedef union _USB_DEV_TOPOLOGY {
88 UINT32 Dword;
89 struct {
90 UINT32 RouteString:20; ///< The tier concatenation of down stream port
91 UINT32 RootPortNum:8; ///< The root port number of the chain
92 UINT32 TierNum:4; ///< The Tier the device reside
93 } Field;
94 } USB_DEV_ROUTE;
95
96 //
97 // Endpoint address and its capabilities
98 //
99 typedef struct _USB_ENDPOINT {
100 UINT8 DevAddr;
101 UINT8 EpAddr;
102 EFI_USB_DATA_DIRECTION Direction;
103 UINT8 DevSpeed;
104 UINTN MaxPacket;
105 UINTN Type;
106 } USB_ENDPOINT;
107
108 //
109 // Command TRB
110 //
111 typedef struct _TRB {
112 UINT32 Dword1;
113 UINT32 Dword2;
114 UINT32 Dword3;
115 UINT32 CycleBit:1;
116 UINT32 RsvdZ1:9;
117 UINT32 Type:6;
118 UINT32 RsvdZ2:16;
119 } TRB;
120
121 typedef struct _TRANSFER_RING {
122 VOID *RingSeg0;
123 UINTN TrbNumber;
124 TRB *RingEnqueue;
125 TRB *RingDequeue;
126 UINT32 RingPCS;
127 } TRANSFER_RING;
128
129 typedef struct _EVENT_RING {
130 UINT32 EventInterrupter;
131 VOID *ERSTBase;
132 VOID *EventRingSeg0;
133 UINTN TrbNumber;
134 TRB *EventRingEnqueue;
135 TRB *EventRingDequeue;
136 UINT32 EventRingCCS;
137 } EVENT_RING;
138
139 //
140 // URB (Usb Request Block) contains information for all kinds of
141 // usb requests.
142 //
143 typedef struct _URB {
144 UINT32 Signature;
145 LIST_ENTRY UrbList;
146 //
147 // Usb Device URB related information
148 //
149 USB_ENDPOINT Ep;
150 EFI_USB_DEVICE_REQUEST *Request;
151 VOID *Data;
152 UINTN DataLen;
153 EFI_ASYNC_USB_TRANSFER_CALLBACK Callback;
154 VOID *Context;
155 //
156 // Execute result
157 //
158 UINT32 Result;
159 //
160 // completed data length
161 //
162 UINTN Completed;
163 //
164 // Command/Tranfer Ring info
165 //
166 TRANSFER_RING *Ring;
167 TRB *TrbStart;
168 TRB *TrbEnd;
169 UINTN TrbNum;
170 EVENT_RING *EvtRing;
171 TRB *EvtTrbStart;
172 } URB;
173
174 //
175 // 5.5.2 Interrupter Register Set
176 //
177 typedef struct _INTERRUPTER_REGISTER_SET {
178 UINT32 InterrupterManagement;
179 UINT32 InterrupterModeration;
180 UINT32 RingSegTableSize:16;
181 UINT32 RsvdZ1:16;
182 UINT32 RsvdZ2;
183 UINT32 BasePtrLo;
184 UINT32 BasePtrHi;
185 UINT32 DequeLo;
186 UINT32 DequeHi;
187 } INTERRUPTER_REGISTER_SET;
188
189 //
190 // Host Controller Runtime Registers
191 //
192 typedef struct _HC_RUNTIME_REGS {
193 UINT32 MicroframeIndex;
194 UINT32 RsvdZ1;
195 UINT64 RsvdZ2;
196 UINT64 RsvdZ3;
197 UINT64 RsvdZ4;
198 INTERRUPTER_REGISTER_SET IR[1];
199 } HC_RUNTIME_REGS;
200
201 //
202 // 6.5 Event Ring Segment Table
203 // The Event Ring Segment Table is used to define multi-segment Event Rings and to enable runtime
204 // expansion and shrinking of the Event Ring. The location of the Event Ring Segment Table is defined by the
205 // Event Ring Segment Table Base Address Register (5.5.2.3.2). The size of the Event Ring Segment Table
206 // is defined by the Event Ring Segment Table Base Size Register (5.5.2.3.1).
207 //
208 typedef struct _EVENT_RING_SEG_TABLE_ENTRY {
209 UINT32 PtrLo;
210 UINT32 PtrHi;
211 UINT32 RingTrbSize:16;
212 UINT32 RsvdZ1:16;
213 UINT32 RsvdZ2;
214 } EVENT_RING_SEG_TABLE_ENTRY;
215
216 //
217 // 6.4.1.1 Normal TRB
218 // A Normal TRB is used in several ways; exclusively on Bulk and Interrupt Transfer Rings for normal and
219 // Scatter/Gather operations, to define additional data buffers for Scatter/Gather operations on Isoch Transfer
220 // Rings, and to define the Data stage information for Control Transfer Rings.
221 //
222 typedef struct _TRANSFER_TRB_NORMAL {
223 UINT32 TRBPtrLo;
224 UINT32 TRBPtrHi;
225 UINT32 Lenth:17;
226 UINT32 TDSize:5;
227 UINT32 IntTarget:10;
228 UINT32 CycleBit:1;
229 UINT32 ENT:1;
230 UINT32 ISP:1;
231 UINT32 NS:1;
232 UINT32 CH:1;
233 UINT32 IOC:1;
234 UINT32 IDT:1;
235 UINT32 RsvdZ1:2;
236 UINT32 BEI:1;
237 UINT32 Type:6;
238 UINT32 RsvdZ2:16;
239 } TRANSFER_TRB_NORMAL;
240
241 //
242 // 6.4.1.2.1 Setup Stage TRB
243 // A Setup Stage TRB is created by system software to initiate a USB Setup packet on a control endpoint.
244 //
245 typedef struct _TRANSFER_TRB_CONTROL_SETUP{
246 UINT32 bmRequestType:8;
247 UINT32 bRequest:8;
248 UINT32 wValue:16;
249
250 UINT32 wIndex:16;
251 UINT32 wLength:16;
252
253 UINT32 Lenth:17;
254 UINT32 RsvdZ1:5;
255 UINT32 IntTarget:10;
256
257 UINT32 CycleBit:1;
258 UINT32 RsvdZ2:4;
259 UINT32 IOC:1;
260 UINT32 IDT:1;
261 UINT32 RsvdZ3:3;
262 UINT32 Type:6;
263 UINT32 TRT:2;
264 UINT32 RsvdZ4:14;
265 } TRANSFER_TRB_CONTROL_SETUP;
266
267 //
268 // 6.4.1.2.2 Data Stage TRB
269 // A Data Stage TRB is used generate the Data stage transaction of a USB Control transfer.
270 //
271 typedef struct _TRANSFER_TRB_CONTROL_DATA {
272 UINT32 TRBPtrLo;
273 UINT32 TRBPtrHi;
274 UINT32 Lenth:17;
275 UINT32 TDSize:5;
276 UINT32 IntTarget:10;
277 UINT32 CycleBit:1;
278 UINT32 ENT:1;
279 UINT32 ISP:1;
280 UINT32 NS:1;
281 UINT32 CH:1;
282 UINT32 IOC:1;
283 UINT32 IDT:1;
284 UINT32 RsvdZ1:3;
285 UINT32 Type:6;
286 UINT32 DIR:1;
287 UINT32 RsvdZ2:15;
288 } TRANSFER_TRB_CONTROL_DATA;
289
290 //
291 // 6.4.1.2.2 Data Stage TRB
292 // A Data Stage TRB is used generate the Data stage transaction of a USB Control transfer.
293 //
294 typedef struct _TRANSFER_TRB_CONTROL_STATUS {
295 UINT32 RsvdZ1;
296 UINT32 RsvdZ2;
297 UINT32 RsvdZ3:22;
298 UINT32 IntTarget:10;
299 UINT32 CycleBit:1;
300 UINT32 ENT:1;
301 UINT32 RsvdZ4:2;
302 UINT32 CH:1;
303 UINT32 IOC:1;
304 UINT32 RsvdZ5:4;
305 UINT32 Type:6;
306 UINT32 DIR:1;
307 UINT32 RsvdZ6:15;
308 } TRANSFER_TRB_CONTROL_STATUS;
309
310 //
311 // 6.4.2.1 Transfer Event TRB
312 // A Transfer Event provides the completion status associated with a Transfer TRB. Refer to section 4.11.3.1
313 // for more information on the use and operation of Transfer Events.
314 //
315 typedef struct _EVT_TRB_TRANSFER {
316 UINT32 TRBPtrLo;
317 UINT32 TRBPtrHi;
318 UINT32 Lenth:24;
319 UINT32 Completcode:8;
320 UINT32 CycleBit:1;
321 UINT32 RsvdZ1:1;
322 UINT32 ED:1;
323 UINT32 RsvdZ2:7;
324 UINT32 Type:6;
325 UINT32 EndpointID:5;
326 UINT32 RsvdZ3:3;
327 UINT32 SlotId:8;
328 } EVT_TRB_TRANSFER;
329
330 //
331 // 6.4.2.2 Command Completion Event TRB
332 // A Command Completion Event TRB shall be generated by the xHC when a command completes on the
333 // Command Ring. Refer to section 4.11.4 for more information on the use of Command Completion Events.
334 //
335 typedef struct _EVT_TRB_COMMAND {
336 UINT32 TRBPtrLo;
337 UINT32 TRBPtrHi;
338 UINT32 RsvdZ2:24;
339 UINT32 Completcode:8;
340 UINT32 CycleBit:1;
341 UINT32 RsvdZ3:9;
342 UINT32 Type:6;
343 UINT32 VFID:8;
344 UINT32 SlotId:8;
345 } EVT_TRB_COMMAND;
346
347 //
348 // 6.4.2.3 Port Status Change Event TRB
349 //
350 typedef struct _EVT_TRB_PORT {
351 UINT32 RsvdZ1:24;
352 UINT32 PortID:8;
353 UINT32 RsvdZ2;
354 UINT32 RsvdZ3:24;
355 UINT32 Completcode:8;
356 UINT32 CycleBit:1;
357 UINT32 RsvdZ4:9;
358 UINT32 Type:6;
359 UINT32 RsvdZ5:16;
360 } EVT_TRB_PORT;
361
362 //
363 // 6.4.3.1 No Op Command TRB
364 // The No Op Command TRB provides a simple means for verifying the operation of the Command Ring
365 // mechanisms offered by the xHCI.
366 //
367 typedef struct _CMD_TRB_NO_OP {
368 UINT32 RsvdZ0;
369 UINT32 RsvdZ1;
370 UINT32 RsvdZ2;
371 UINT32 CycleBit:1;
372 UINT32 RsvdZ3:9;
373 UINT32 Type:6;
374 UINT32 RsvdZ4:16;
375 } CMD_TRB_NO_OP;
376
377 //
378 // 6.4.3.2 Enable Slot Command TRB
379 // The Enable Slot Command TRB causes the xHC to select an available Device Slot and return the ID of the
380 // selected slot to the host in a Command Completion Event.
381 //
382 typedef struct _CMD_TRB_EN_SLOT {
383 UINT32 RsvdZ0;
384 UINT32 RsvdZ1;
385 UINT32 RsvdZ2;
386 UINT32 CycleBit:1;
387 UINT32 RsvdZ3:9;
388 UINT32 Type:6;
389 UINT32 RsvdZ4:16;
390 } CMD_TRB_EN_SLOT;
391
392 //
393 // 6.4.3.3 Disable Slot Command TRB
394 // The Disable Slot Command TRB releases any bandwidth assigned to the disabled slot and frees any
395 // internal xHC resources assigned to the slot.
396 //
397 typedef struct _CMD_TRB_DIS_SLOT {
398 UINT32 RsvdZ0;
399 UINT32 RsvdZ1;
400 UINT32 RsvdZ2;
401 UINT32 CycleBit:1;
402 UINT32 RsvdZ3:9;
403 UINT32 Type:6;
404 UINT32 RsvdZ4:8;
405 UINT32 SlotId:8;
406 } CMD_TRB_DIS_SLOT;
407
408 typedef struct _CMD_TRB_RESET_PORT {
409 UINT32 RsvdZ0;
410 UINT32 RsvdZ1;
411 UINT32 RsvdZ2;
412 UINT32 CycleBit:1;
413 UINT32 RsvdZ3:8;
414 UINT32 Tsp:1;
415 UINT32 Type:6;
416 UINT32 Endpoint:5;
417 UINT32 RsvdZ4:3;
418 UINT32 SlotId:8;
419 } CMD_TRB_RESET_PORT;
420
421 //
422 // 6.4.3.4 Address Device Command TRB
423 // The Address Device Command TRB transitions the selected Device Context from the Default to the
424 // Addressed state and causes the xHC to select an address for the USB device in the Default State and
425 // issue a SET_ADDRESS request to the USB device.
426 //
427 typedef struct _CMD_TRB_ADDR_DEV {
428 UINT32 PtrLo;
429 UINT32 PtrHi;
430 UINT32 RsvdZ1;
431 UINT32 CycleBit:1;
432 UINT32 RsvdZ2:8;
433 UINT32 BSR:1;
434 UINT32 Type:6;
435 UINT32 RsvdZ3:8;
436 UINT32 SlotId:8;
437 } CMD_TRB_ADDR_DEV;
438
439 //
440 // 6.4.3.5 Configure Endpoint Command TRB
441 // The Configure Endpoint Command TRB evaluates the bandwidth and resource requirements of the
442 // endpoints selected by the command.
443 //
444 typedef struct _CMD_CFG_ED {
445 UINT32 PtrLo;
446 UINT32 PtrHi;
447 UINT32 RsvdZ1;
448 UINT32 CycleBit:1;
449 UINT32 RsvdZ2:8;
450 UINT32 DC:1;
451 UINT32 Type:6;
452 UINT32 RsvdZ3:8;
453 UINT32 SlotId:8;
454 } CMD_CFG_ED;
455
456 //
457 // 6.4.3.6 Evaluate Context Command TRB
458 // The Evaluate Context Command TRB is used by system software to inform the xHC that the selected
459 // Context data structures in the Device Context have been modified by system software and that the xHC
460 // shall evaluate any changes
461 //
462 typedef struct _CMD_TRB_EVALU_CONTX {
463 UINT32 PtrLo;
464 UINT32 PtrHi;
465 UINT32 RsvdZ1;
466 UINT32 CycleBit:1;
467 UINT32 RsvdZ2:9;
468 UINT32 Type:6;
469 UINT32 RsvdZ3:8;
470 UINT32 SlotId:8;
471 } CMD_TRB_EVALU_CONTX;
472
473 //
474 // 6.4.3.7 Reset Endpoint Command TRB
475 // The Reset Endpoint Command TRB is used by system software to reset a specified Transfer Ring
476 //
477 typedef struct _CMD_TRB_RESET_ED {
478 UINT32 RsvdZ0;
479 UINT32 RsvdZ1;
480 UINT32 RsvdZ2;
481 UINT32 CycleBit:1;
482 UINT32 RsvdZ3:8;
483 UINT32 TSP:1;
484 UINT32 Type:6;
485 UINT32 EDID:5;
486 UINT32 RsvdZ4:3;
487 UINT32 SlotId:8;
488 } CMD_TRB_RESET_ED;
489
490 //
491 // 6.4.3.8 Stop Endpoint Command TRB
492 // The Stop Endpoint Command TRB command allows software to stop the xHC execution of the TDs on a
493 // Transfer Ring and temporarily take ownership of TDs that had previously been passed to the xHC.
494 //
495 typedef struct _CMD_TRB_STOP_ED {
496 UINT32 RsvdZ0;
497 UINT32 RsvdZ1;
498 UINT32 RsvdZ2;
499 UINT32 CycleBit:1;
500 UINT32 RsvdZ3:9;
501 UINT32 Type:6;
502 UINT32 EDID:5;
503 UINT32 RsvdZ4:2;
504 UINT32 SP:1;
505 UINT32 SlotId:8;
506 } CMD_TRB_STOP_ED;
507
508 //
509 // 6.4.3.9 Set TR Dequeue Pointer Command TRB
510 // The Set TR Dequeue Pointer Command TRB is used by system software to modify the TR Dequeue
511 // Pointer and DCS fields of an Endpoint or Stream Context.
512 //
513 typedef struct _CMD_SET_TR_DEQ {
514 UINT32 PtrLo;
515 UINT32 PtrHi;
516 UINT32 RsvdZ1:16;
517 UINT32 StreamID:16;
518 UINT32 CycleBit:1;
519 UINT32 RsvdZ2:9;
520 UINT32 Type:6;
521 UINT32 Endpoint:5;
522 UINT32 RsvdZ3:3;
523 UINT32 SlotId:8;
524 } CMD_SET_TR_DEQ;
525
526 //
527 // A Link TRB provides support for non-contiguous TRB Rings.
528 //
529 typedef struct _LNK_TRB {
530 UINT32 PtrLo;
531 UINT32 PtrHi;
532 UINT32 RsvdZ1:22;
533 UINT32 InterTarget:10;
534 UINT32 CycleBit:1;
535 UINT32 TC:1;
536 UINT32 RsvdZ2:2;
537 UINT32 CH:1;
538 UINT32 IOC:1;
539 UINT32 RsvdZ3:4;
540 UINT32 Type:6;
541 UINT32 RsvdZ4:16;
542 } LNK_TRB;
543
544 //
545 // A Link TRB provides support for non-contiguous TRB Rings.
546 //
547 typedef struct _NO_OP_TRB {
548 UINT32 RsvdZ0;
549 UINT32 RsvdZ1;
550 UINT32 RsvdZ2;
551 UINT32 CycleBit:1;
552 UINT32 RsvdZ3:9;
553 UINT32 Type:6;
554 UINT32 RsvdZ4:16;
555 } CMD_NO_OP_TRB;
556
557 //
558 // 6.2.2 Slot Context
559 //
560 typedef struct _SLOT_CONTEXT {
561 UINT32 RouteStr:20;
562 UINT32 Speed:4;
563 UINT32 RsvdZ1:1;
564 UINT32 MTT:1;
565 UINT32 Hub:1;
566 UINT32 ContextEntries:5;
567
568 UINT32 MaxExitLatency:16;
569 UINT32 RootHubPortNum:8;
570 UINT32 PortNum:8;
571
572 UINT32 TTHubSlotId:8;
573 UINT32 TTPortNum:8;
574 UINT32 TTT:2;
575 UINT32 RsvdZ2:4;
576 UINT32 InterTarget:10;
577
578 UINT32 DeviceAddress:8;
579 UINT32 RsvdZ3:19;
580 UINT32 SlotState:5;
581
582 UINT32 RsvdZ4;
583 UINT32 RsvdZ5;
584 UINT32 RsvdZ6;
585 UINT32 RsvdZ7;
586 } SLOT_CONTEXT;
587
588 //
589 // 6.2.3 Endpoint Context
590 //
591 typedef struct _ENDPOINT_CONTEXT {
592 UINT32 EPState:3;
593 UINT32 RsvdZ1:5;
594 UINT32 Mult:2;
595 UINT32 MaxPStreams:5;
596 UINT32 LSA:1;
597 UINT32 Interval:8;
598 UINT32 RsvdZ2:8;
599
600 UINT32 RsvdZ3:1;
601 UINT32 CErr:2;
602 UINT32 EPType:3;
603 UINT32 RsvdZ4:1;
604 UINT32 HID:1;
605 UINT32 MaxBurstSize:8;
606 UINT32 MaxPacketSize:16;
607
608 UINT32 PtrLo;
609
610 UINT32 PtrHi;
611
612 UINT32 AverageTRBLength:16;
613 UINT32 MaxESITPayload:16;
614
615 UINT32 RsvdZ5;
616 UINT32 RsvdZ6;
617 UINT32 RsvdZ7;
618 } ENDPOINT_CONTEXT;
619
620 //
621 // 6.2.5.1 Input Control Context
622 //
623 typedef struct _INPUT_CONTRL_CONTEXT {
624 UINT32 Dword1;
625 UINT32 Dword2;
626 UINT32 RsvdZ1;
627 UINT32 RsvdZ2;
628 UINT32 RsvdZ3;
629 UINT32 RsvdZ4;
630 UINT32 RsvdZ5;
631 UINT32 RsvdZ6;
632 } INPUT_CONTRL_CONTEXT;
633
634 //
635 // 6.2.1 Device Context
636 //
637 typedef struct _DEVICE_CONTEXT {
638 SLOT_CONTEXT Slot;
639 ENDPOINT_CONTEXT EP[31];
640 } DEVICE_CONTEXT;
641
642 //
643 // 6.2.5 Input Context
644 //
645 typedef struct _INPUT_CONTEXT {
646 INPUT_CONTRL_CONTEXT InputControlContext;
647 SLOT_CONTEXT Slot;
648 ENDPOINT_CONTEXT EP[31];
649 } INPUT_CONTEXT;
650
651 /**
652 Initialize the XHCI host controller for schedule.
653
654 @param Xhc The XHCI device to be initialized.
655
656 **/
657 VOID
658 XhcInitSched (
659 IN USB_XHCI_DEV *Xhc
660 );
661
662 /**
663 Free the resouce allocated at initializing schedule.
664
665 @param Xhc The XHCI device.
666
667 **/
668 VOID
669 XhcFreeSched (
670 IN USB_XHCI_DEV *Xhc
671 );
672
673 /**
674 Ring the door bell to notify XHCI there is a transaction to be executed through URB.
675
676 @param Xhc The XHCI device.
677 @param Urb The URB to be rung.
678
679 @retval EFI_SUCCESS Successfully ring the door bell.
680
681 **/
682 EFI_STATUS
683 RingIntTransferDoorBell (
684 IN USB_XHCI_DEV *Xhc,
685 IN URB *Urb
686 );
687
688 /**
689 Execute the transfer by polling the URB. This is a synchronous operation.
690
691 @param Xhc The XHCI device.
692 @param CmdTransfer The executed URB is for cmd transfer or not.
693 @param Urb The URB to execute.
694 @param TimeOut The time to wait before abort, in millisecond.
695
696 @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
697 @return EFI_TIMEOUT The transfer failed due to time out.
698 @return EFI_SUCCESS The transfer finished OK.
699
700 **/
701 EFI_STATUS
702 XhcExecTransfer (
703 IN USB_XHCI_DEV *Xhc,
704 IN BOOLEAN CmdTransfer,
705 IN URB *Urb,
706 IN UINTN TimeOut
707 );
708
709 /**
710 Delete a single asynchronous interrupt transfer for
711 the device and endpoint.
712
713 @param Xhc The XHCI device.
714 @param DevAddr The address of the target device.
715 @param EpNum The endpoint of the target.
716
717 @retval EFI_SUCCESS An asynchronous transfer is removed.
718 @retval EFI_NOT_FOUND No transfer for the device is found.
719
720 **/
721 EFI_STATUS
722 XhciDelAsyncIntTransfer (
723 IN USB_XHCI_DEV *Xhc,
724 IN UINT8 DevAddr,
725 IN UINT8 EpNum
726 );
727
728 /**
729 Remove all the asynchronous interrupt transfers.
730
731 @param Xhc The XHCI device.
732
733 **/
734 VOID
735 XhciDelAllAsyncIntTransfers (
736 IN USB_XHCI_DEV *Xhc
737 );
738
739 /**
740 Set Bios Ownership
741
742 @param Xhc The XHCI device.
743
744 **/
745 VOID
746 XhcSetBiosOwnership (
747 IN USB_XHCI_DEV *Xhc
748 );
749
750 /**
751 Clear Bios Ownership
752
753 @param Xhc The XHCI device.
754
755 **/
756 VOID
757 XhcClearBiosOwnership (
758 IN USB_XHCI_DEV *Xhc
759 );
760
761 /**
762 Find out the slot id according to device address assigned by XHCI's Address_Device cmd.
763
764 @param DevAddr The device address of the target device.
765
766 @return The slot id used by the device.
767
768 **/
769 UINT8
770 XhcDevAddrToSlotId (
771 IN UINT8 DevAddr
772 );
773
774 /**
775 Find out the slot id according to the device's route string.
776
777 @param RouteString The route string described the device location.
778
779 @return The slot id used by the device.
780
781 **/
782 UINT8
783 EFIAPI
784 XhcRouteStringToSlotId (
785 IN USB_DEV_ROUTE RouteString
786 );
787
788 /**
789 Calculate the device context index by endpoint address and direction.
790
791 @param EpAddr The target endpoint number.
792 @param Direction The direction of the target endpoint.
793
794 @return The device context index of endpoint.
795
796 **/
797 UINT8
798 XhcEndpointToDci (
799 IN UINT8 EpAddr,
800 IN UINT8 Direction
801 );
802
803 /**
804 Ring the door bell to notify XHCI there is a transaction to be executed.
805
806 @param Xhc The XHCI device.
807 @param SlotId The slot id of the target device.
808 @param Dci The device context index of the target slot or endpoint.
809
810 @retval EFI_SUCCESS Successfully ring the door bell.
811
812 **/
813 EFI_STATUS
814 EFIAPI
815 XhcRingDoorBell (
816 IN USB_XHCI_DEV *Xhc,
817 IN UINT8 SlotId,
818 IN UINT8 Dci
819 );
820
821 /**
822 Interrupt transfer periodic check handler.
823
824 @param Event Interrupt event.
825 @param Context Pointer to USB_XHCI_DEV.
826
827 **/
828 VOID
829 EFIAPI
830 XhcMonitorAsyncRequests (
831 IN EFI_EVENT Event,
832 IN VOID *Context
833 );
834
835 /**
836 Monitor the port status change. Enable/Disable device slot if there is a device attached/detached.
837
838 @param Xhc The XHCI device.
839 @param ParentRouteChart The route string pointed to the parent device if it exists.
840 @param Port The port to be polled.
841 @param PortState The port state.
842
843 @retval EFI_SUCCESS Successfully enable/disable device slot according to port state.
844 @retval Others Should not appear.
845
846 **/
847 EFI_STATUS
848 EFIAPI
849 XhcPollPortStatusChange (
850 IN USB_XHCI_DEV* Xhc,
851 IN USB_DEV_ROUTE ParentRouteChart,
852 IN UINT8 Port,
853 IN EFI_USB_PORT_STATUS *PortState
854 );
855
856 /**
857 Evaluate the slot context for hub device through XHCI's Configure_Endpoint cmd.
858
859 @param Xhc The XHCI device.
860 @param SlotId The slot id to be configured.
861 @param PortNum The total number of downstream port supported by the hub.
862 @param TTT The TT think time of the hub device.
863 @param MTT The multi-TT of the hub device.
864
865 @retval EFI_SUCCESS Successfully configure the hub device's slot context.
866
867 **/
868 EFI_STATUS
869 XhcConfigHubContext (
870 IN USB_XHCI_DEV *Xhc,
871 IN UINT8 SlotId,
872 IN UINT8 PortNum,
873 IN UINT8 TTT,
874 IN UINT8 MTT
875 );
876
877 /**
878 Configure all the device endpoints through XHCI's Configure_Endpoint cmd.
879
880 @param Xhc The XHCI device.
881 @param SlotId The slot id to be configured.
882 @param DeviceSpeed The device's speed.
883 @param ConfigDesc The pointer to the usb device configuration descriptor.
884
885 @retval EFI_SUCCESS Successfully configure all the device endpoints.
886
887 **/
888 EFI_STATUS
889 EFIAPI
890 XhcSetConfigCmd (
891 IN USB_XHCI_DEV *Xhc,
892 IN UINT8 SlotId,
893 IN UINT8 DeviceSpeed,
894 IN USB_CONFIG_DESCRIPTOR *ConfigDesc
895 );
896
897 /**
898 Find out the actual device address according to the requested device address from UsbBus.
899
900 @param BusDevAddr The requested device address by UsbBus upper driver.
901
902 @return The actual device address assigned to the device.
903
904 **/
905 UINT8
906 EFIAPI
907 XhcBusDevAddrToSlotId (
908 IN UINT8 BusDevAddr
909 );
910
911 /**
912 Assign and initialize the device slot for a new device.
913
914 @param Xhc The XHCI device.
915 @param ParentRouteChart The route string pointed to the parent device.
916 @param ParentPort The port at which the device is located.
917 @param RouteChart The route string pointed to the device.
918 @param DeviceSpeed The device speed.
919
920 @retval EFI_SUCCESS Successfully assign a slot to the device and assign an address to it.
921
922 **/
923 EFI_STATUS
924 EFIAPI
925 XhcInitializeDeviceSlot (
926 IN USB_XHCI_DEV *Xhc,
927 IN USB_DEV_ROUTE ParentRouteChart,
928 IN UINT16 ParentPort,
929 IN USB_DEV_ROUTE RouteChart,
930 IN UINT8 DeviceSpeed
931 );
932
933 /**
934 Evaluate the endpoint 0 context through XHCI's Evaluate_Context cmd.
935
936 @param Xhc The XHCI device.
937 @param SlotId The slot id to be evaluated.
938 @param MaxPacketSize The max packet size supported by the device control transfer.
939
940 @retval EFI_SUCCESS Successfully evaluate the device endpoint 0.
941
942 **/
943 EFI_STATUS
944 EFIAPI
945 XhcEvaluateContext (
946 IN USB_XHCI_DEV *Xhc,
947 IN UINT8 SlotId,
948 IN UINT32 MaxPacketSize
949 );
950
951 /**
952 Disable the specified device slot.
953
954 @param Xhc The XHCI device.
955 @param SlotId The slot id to be disabled.
956
957 @retval EFI_SUCCESS Successfully disable the device slot.
958
959 **/
960 EFI_STATUS
961 EFIAPI
962 XhcDisableSlotCmd (
963 IN USB_XHCI_DEV *Xhc,
964 IN UINT8 SlotId
965 );
966
967 /**
968 Synchronize the specified transfer ring to update the enqueue and dequeue pointer.
969
970 @param Xhc The XHCI device.
971 @param TrsRing The transfer ring to sync.
972
973 @retval EFI_SUCCESS The transfer ring is synchronized successfully.
974
975 **/
976 EFI_STATUS
977 EFIAPI
978 XhcSyncTrsRing (
979 IN USB_XHCI_DEV *Xhc,
980 TRANSFER_RING *TrsRing
981 );
982
983 /**
984 Synchronize the specified event ring to update the enqueue and dequeue pointer.
985
986 @param Xhc The XHCI device.
987 @param EvtRing The event ring to sync.
988
989 @retval EFI_SUCCESS The event ring is synchronized successfully.
990
991 **/
992 EFI_STATUS
993 EFIAPI
994 XhcSyncEventRing (
995 IN USB_XHCI_DEV *Xhc,
996 EVENT_RING *EvtRing
997 );
998
999 /**
1000 Check if there is a new generated event.
1001
1002 @param Xhc The XHCI device.
1003 @param EvtRing The event ring to check.
1004 @param NewEvtTrb The new event TRB found.
1005
1006 @retval EFI_SUCCESS Found a new event TRB at the event ring.
1007 @retval EFI_NOT_READY The event ring has no new event.
1008
1009 **/
1010 EFI_STATUS
1011 EFIAPI
1012 XhcCheckNewEvent (
1013 IN USB_XHCI_DEV *Xhc,
1014 IN EVENT_RING *EvtRing,
1015 OUT TRB **NewEvtTrb
1016 );
1017
1018 /**
1019 Create XHCI transfer ring.
1020
1021 @param Xhc The XHCI device.
1022 @param TrbNum The number of TRB in the ring.
1023 @param TransferRing The created transfer ring.
1024
1025 **/
1026 VOID
1027 CreateTransferRing (
1028 IN USB_XHCI_DEV *Xhc,
1029 IN UINTN TrbNum,
1030 OUT TRANSFER_RING *TransferRing
1031 );
1032
1033 /**
1034 Create XHCI event ring.
1035
1036 @param Xhc The XHCI device.
1037 @param EventInterrupter The interrupter of event.
1038 @param EventRing The created event ring.
1039
1040 **/
1041 VOID
1042 CreateEventRing (
1043 IN USB_XHCI_DEV *Xhc,
1044 IN UINT8 EventInterrupter,
1045 OUT EVENT_RING *EventRing
1046 );
1047
1048 /**
1049 System software shall use a Reset Endpoint Command (section 4.11.4.7) to remove the Halted
1050 condition in the xHC. After the successful completion of the Reset Endpoint Command, the Endpoint
1051 Context is transitioned from the Halted to the Stopped state and the Transfer Ring of the endpoint is
1052 reenabled. The next write to the Doorbell of the Endpoint will transition the Endpoint Context from the
1053 Stopped to the Running state.
1054
1055 @param Xhc The XHCI device.
1056 @param Urb The urb which makes the endpoint halted.
1057
1058 @retval EFI_SUCCESS The recovery is successful.
1059 @retval Others Failed to recovery halted endpoint.
1060
1061 **/
1062 EFI_STATUS
1063 EFIAPI
1064 XhcRecoverHaltedEndpoint (
1065 IN USB_XHCI_DEV *Xhc,
1066 IN URB *Urb
1067 );
1068
1069 /**
1070 Create a new URB for a new transaction.
1071
1072 @param Xhc The XHCI device
1073 @param DevAddr The device address
1074 @param EpAddr Endpoint addrress
1075 @param DevSpeed The device speed
1076 @param MaxPacket The max packet length of the endpoint
1077 @param Type The transaction type
1078 @param Request The standard USB request for control transfer
1079 @param Data The user data to transfer
1080 @param DataLen The length of data buffer
1081 @param Callback The function to call when data is transferred
1082 @param Context The context to the callback
1083
1084 @return Created URB or NULL
1085
1086 **/
1087 URB*
1088 XhcCreateUrb (
1089 IN USB_XHCI_DEV *Xhc,
1090 IN UINT8 DevAddr,
1091 IN UINT8 EpAddr,
1092 IN UINT8 DevSpeed,
1093 IN UINTN MaxPacket,
1094 IN UINTN Type,
1095 IN EFI_USB_DEVICE_REQUEST *Request,
1096 IN VOID *Data,
1097 IN UINTN DataLen,
1098 IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback,
1099 IN VOID *Context
1100 );
1101
1102 /**
1103 Create a transfer TRB.
1104
1105 @param Xhc The XHCI device
1106 @param Urb The urb used to construct the transfer TRB.
1107
1108 @return Created TRB or NULL
1109
1110 **/
1111 EFI_STATUS
1112 XhcCreateTransferTrb (
1113 IN USB_XHCI_DEV *Xhc,
1114 IN URB *Urb
1115 );
1116
1117 #endif