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