2 PEIM to produce gPeiUsb2HostControllerPpiGuid based on gPeiUsbControllerPpiGuid
3 which is used to enable recovery function from USB Drivers.
5 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions
9 of the BSD License which accompanies this distribution. The
10 full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 // Two arrays used to translate the XHCI port state (change)
22 // to the UEFI protocol's port state (change).
24 USB_PORT_STATE_MAP mUsbPortStateMap
[] = {
25 {XHC_PORTSC_CCS
, USB_PORT_STAT_CONNECTION
},
26 {XHC_PORTSC_PED
, USB_PORT_STAT_ENABLE
},
27 {XHC_PORTSC_OCA
, USB_PORT_STAT_OVERCURRENT
},
28 {XHC_PORTSC_PP
, USB_PORT_STAT_POWER
},
29 {XHC_PORTSC_RESET
, USB_PORT_STAT_RESET
}
32 USB_PORT_STATE_MAP mUsbPortChangeMap
[] = {
33 {XHC_PORTSC_CSC
, USB_PORT_STAT_C_CONNECTION
},
34 {XHC_PORTSC_PEC
, USB_PORT_STAT_C_ENABLE
},
35 {XHC_PORTSC_OCC
, USB_PORT_STAT_C_OVERCURRENT
},
36 {XHC_PORTSC_PRC
, USB_PORT_STAT_C_RESET
}
39 USB_CLEAR_PORT_MAP mUsbClearPortChangeMap
[] = {
40 {XHC_PORTSC_CSC
, EfiUsbPortConnectChange
},
41 {XHC_PORTSC_PEC
, EfiUsbPortEnableChange
},
42 {XHC_PORTSC_OCC
, EfiUsbPortOverCurrentChange
},
43 {XHC_PORTSC_PRC
, EfiUsbPortResetChange
}
46 USB_PORT_STATE_MAP mUsbHubPortStateMap
[] = {
47 {XHC_HUB_PORTSC_CCS
, USB_PORT_STAT_CONNECTION
},
48 {XHC_HUB_PORTSC_PED
, USB_PORT_STAT_ENABLE
},
49 {XHC_HUB_PORTSC_OCA
, USB_PORT_STAT_OVERCURRENT
},
50 {XHC_HUB_PORTSC_PP
, USB_PORT_STAT_POWER
},
51 {XHC_HUB_PORTSC_RESET
, USB_PORT_STAT_RESET
}
54 USB_PORT_STATE_MAP mUsbHubPortChangeMap
[] = {
55 {XHC_HUB_PORTSC_CSC
, USB_PORT_STAT_C_CONNECTION
},
56 {XHC_HUB_PORTSC_PEC
, USB_PORT_STAT_C_ENABLE
},
57 {XHC_HUB_PORTSC_OCC
, USB_PORT_STAT_C_OVERCURRENT
},
58 {XHC_HUB_PORTSC_PRC
, USB_PORT_STAT_C_RESET
}
61 USB_CLEAR_PORT_MAP mUsbHubClearPortChangeMap
[] = {
62 {XHC_HUB_PORTSC_CSC
, EfiUsbPortConnectChange
},
63 {XHC_HUB_PORTSC_PEC
, EfiUsbPortEnableChange
},
64 {XHC_HUB_PORTSC_OCC
, EfiUsbPortOverCurrentChange
},
65 {XHC_HUB_PORTSC_PRC
, EfiUsbPortResetChange
},
66 {XHC_HUB_PORTSC_BHRC
, Usb3PortBHPortResetChange
}
70 Read XHCI Operation register.
72 @param Xhc The XHCI device.
73 @param Offset The operation register offset.
75 @retval the register content read.
86 ASSERT (Xhc
->CapLength
!= 0);
88 Data
= MmioRead32 (Xhc
->UsbHostControllerBaseAddress
+ Xhc
->CapLength
+ Offset
);
93 Write the data to the XHCI operation register.
95 @param Xhc The XHCI device.
96 @param Offset The operation register offset.
97 @param Data The data to write.
107 ASSERT (Xhc
->CapLength
!= 0);
109 MmioWrite32 (Xhc
->UsbHostControllerBaseAddress
+ Xhc
->CapLength
+ Offset
, Data
);
113 Set one bit of the operational register while keeping other bits.
115 @param Xhc The XHCI device.
116 @param Offset The offset of the operational register.
117 @param Bit The bit mask of the register to set.
129 Data
= XhcPeiReadOpReg (Xhc
, Offset
);
131 XhcPeiWriteOpReg (Xhc
, Offset
, Data
);
135 Clear one bit of the operational register while keeping other bits.
137 @param Xhc The XHCI device.
138 @param Offset The offset of the operational register.
139 @param Bit The bit mask of the register to clear.
143 XhcPeiClearOpRegBit (
151 Data
= XhcPeiReadOpReg (Xhc
, Offset
);
153 XhcPeiWriteOpReg (Xhc
, Offset
, Data
);
157 Wait the operation register's bit as specified by Bit
158 to become set (or clear).
160 @param Xhc The XHCI device.
161 @param Offset The offset of the operational register.
162 @param Bit The bit mask of the register to wait for.
163 @param WaitToSet Wait the bit to set or clear.
164 @param Timeout The time to wait before abort (in millisecond, ms).
166 @retval EFI_SUCCESS The bit successfully changed by host controller.
167 @retval EFI_TIMEOUT The time out occurred.
175 IN BOOLEAN WaitToSet
,
181 for (Index
= 0; Index
< Timeout
* XHC_1_MILLISECOND
; Index
++) {
182 if (XHC_REG_BIT_IS_SET (Xhc
, Offset
, Bit
) == WaitToSet
) {
186 MicroSecondDelay (XHC_1_MICROSECOND
);
193 Read XHCI capability register.
195 @param Xhc The XHCI device.
196 @param Offset Capability register address.
198 @retval the register content read.
202 XhcPeiReadCapRegister (
209 Data
= MmioRead32 (Xhc
->UsbHostControllerBaseAddress
+ Offset
);
215 Read XHCI door bell register.
217 @param Xhc The XHCI device.
218 @param Offset The offset of the door bell register.
220 @return The register content read
224 XhcPeiReadDoorBellReg (
231 ASSERT (Xhc
->DBOff
!= 0);
233 Data
= MmioRead32 (Xhc
->UsbHostControllerBaseAddress
+ Xhc
->DBOff
+ Offset
);
239 Write the data to the XHCI door bell register.
241 @param Xhc The XHCI device.
242 @param Offset The offset of the door bell register.
243 @param Data The data to write.
247 XhcPeiWriteDoorBellReg (
253 ASSERT (Xhc
->DBOff
!= 0);
255 MmioWrite32 (Xhc
->UsbHostControllerBaseAddress
+ Xhc
->DBOff
+ Offset
, Data
);
259 Read XHCI runtime register.
261 @param Xhc The XHCI device.
262 @param Offset The offset of the runtime register.
264 @return The register content read
268 XhcPeiReadRuntimeReg (
275 ASSERT (Xhc
->RTSOff
!= 0);
277 Data
= MmioRead32 (Xhc
->UsbHostControllerBaseAddress
+ Xhc
->RTSOff
+ Offset
);
283 Write the data to the XHCI runtime register.
285 @param Xhc The XHCI device.
286 @param Offset The offset of the runtime register.
287 @param Data The data to write.
291 XhcPeiWriteRuntimeReg (
297 ASSERT (Xhc
->RTSOff
!= 0);
299 MmioWrite32 (Xhc
->UsbHostControllerBaseAddress
+ Xhc
->RTSOff
+ Offset
, Data
);
303 Set one bit of the runtime register while keeping other bits.
305 @param Xhc The XHCI device.
306 @param Offset The offset of the runtime register.
307 @param Bit The bit mask of the register to set.
311 XhcPeiSetRuntimeRegBit (
319 Data
= XhcPeiReadRuntimeReg (Xhc
, Offset
);
321 XhcPeiWriteRuntimeReg (Xhc
, Offset
, Data
);
325 Clear one bit of the runtime register while keeping other bits.
327 @param Xhc The XHCI device.
328 @param Offset The offset of the runtime register.
329 @param Bit The bit mask of the register to set.
333 XhcPeiClearRuntimeRegBit (
341 Data
= XhcPeiReadRuntimeReg (Xhc
, Offset
);
343 XhcPeiWriteRuntimeReg (Xhc
, Offset
, Data
);
347 Check whether Xhc is halted.
349 @param Xhc The XHCI device.
351 @retval TRUE The controller is halted.
352 @retval FALSE The controller isn't halted.
360 return XHC_REG_BIT_IS_SET (Xhc
, XHC_USBSTS_OFFSET
, XHC_USBSTS_HALT
);
364 Check whether system error occurred.
366 @param Xhc The XHCI device.
368 @retval TRUE System error happened.
369 @retval FALSE No system error.
377 return XHC_REG_BIT_IS_SET (Xhc
, XHC_USBSTS_OFFSET
, XHC_USBSTS_HSE
);
381 Reset the host controller.
383 @param Xhc The XHCI device.
384 @param Timeout Time to wait before abort (in millisecond, ms).
386 @retval EFI_TIMEOUT The transfer failed due to time out.
387 @retval Others Failed to reset the host.
399 // Host can only be reset when it is halt. If not so, halt it
401 if (!XhcPeiIsHalt (Xhc
)) {
402 Status
= XhcPeiHaltHC (Xhc
, Timeout
);
404 if (EFI_ERROR (Status
)) {
409 XhcPeiSetOpRegBit (Xhc
, XHC_USBCMD_OFFSET
, XHC_USBCMD_RESET
);
410 Status
= XhcPeiWaitOpRegBit (Xhc
, XHC_USBCMD_OFFSET
, XHC_USBCMD_RESET
, FALSE
, Timeout
);
412 DEBUG ((EFI_D_INFO
, "XhcPeiResetHC: %r\n", Status
));
417 Halt the host controller.
419 @param Xhc The XHCI device.
420 @param Timeout Time to wait before abort.
422 @retval EFI_TIMEOUT Failed to halt the controller before Timeout.
423 @retval EFI_SUCCESS The XHCI is halt.
434 XhcPeiClearOpRegBit (Xhc
, XHC_USBCMD_OFFSET
, XHC_USBCMD_RUN
);
435 Status
= XhcPeiWaitOpRegBit (Xhc
, XHC_USBSTS_OFFSET
, XHC_USBSTS_HALT
, TRUE
, Timeout
);
436 DEBUG ((EFI_D_INFO
, "XhcPeiHaltHC: %r\n", Status
));
443 @param Xhc The XHCI device.
444 @param Timeout Time to wait before abort.
446 @retval EFI_SUCCESS The XHCI is running.
447 @retval Others Failed to set the XHCI to run.
458 XhcPeiSetOpRegBit (Xhc
, XHC_USBCMD_OFFSET
, XHC_USBCMD_RUN
);
459 Status
= XhcPeiWaitOpRegBit (Xhc
, XHC_USBSTS_OFFSET
, XHC_USBSTS_HALT
, FALSE
, Timeout
);
460 DEBUG ((EFI_D_INFO
, "XhcPeiRunHC: %r\n", Status
));
465 Submits control transfer to a target USB device.
467 @param PeiServices The pointer of EFI_PEI_SERVICES.
468 @param This The pointer of PEI_USB2_HOST_CONTROLLER_PPI.
469 @param DeviceAddress The target device address.
470 @param DeviceSpeed Target device speed.
471 @param MaximumPacketLength Maximum packet size the default control transfer
472 endpoint is capable of sending or receiving.
473 @param Request USB device request to send.
474 @param TransferDirection Specifies the data direction for the data stage.
475 @param Data Data buffer to be transmitted or received from USB device.
476 @param DataLength The size (in bytes) of the data buffer.
477 @param TimeOut Indicates the maximum timeout, in millisecond.
478 If Timeout is 0, then the caller must wait for the function
479 to be completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.
480 @param Translator Transaction translator to be used by this device.
481 @param TransferResult Return the result of this control transfer.
483 @retval EFI_SUCCESS Transfer was completed successfully.
484 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.
485 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
486 @retval EFI_TIMEOUT Transfer failed due to timeout.
487 @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.
492 XhcPeiControlTransfer (
493 IN EFI_PEI_SERVICES
**PeiServices
,
494 IN PEI_USB2_HOST_CONTROLLER_PPI
*This
,
495 IN UINT8 DeviceAddress
,
496 IN UINT8 DeviceSpeed
,
497 IN UINTN MaximumPacketLength
,
498 IN EFI_USB_DEVICE_REQUEST
*Request
,
499 IN EFI_USB_DATA_DIRECTION TransferDirection
,
501 IN OUT UINTN
*DataLength
,
503 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
504 OUT UINT32
*TransferResult
511 UINT8 DescriptorType
;
516 EFI_USB_HUB_DESCRIPTOR
*HubDesc
;
518 EFI_STATUS RecoveryStatus
;
520 EFI_USB_PORT_STATUS PortStatus
;
522 EFI_USB_DEVICE_REQUEST ClearPortRequest
;
526 // Validate parameters
528 if ((Request
== NULL
) || (TransferResult
== NULL
)) {
529 return EFI_INVALID_PARAMETER
;
532 if ((TransferDirection
!= EfiUsbDataIn
) &&
533 (TransferDirection
!= EfiUsbDataOut
) &&
534 (TransferDirection
!= EfiUsbNoData
)) {
535 return EFI_INVALID_PARAMETER
;
538 if ((TransferDirection
== EfiUsbNoData
) &&
539 ((Data
!= NULL
) || (*DataLength
!= 0))) {
540 return EFI_INVALID_PARAMETER
;
543 if ((TransferDirection
!= EfiUsbNoData
) &&
544 ((Data
== NULL
) || (*DataLength
== 0))) {
545 return EFI_INVALID_PARAMETER
;
548 if ((MaximumPacketLength
!= 8) && (MaximumPacketLength
!= 16) &&
549 (MaximumPacketLength
!= 32) && (MaximumPacketLength
!= 64) &&
550 (MaximumPacketLength
!= 512)
552 return EFI_INVALID_PARAMETER
;
555 if ((DeviceSpeed
== EFI_USB_SPEED_LOW
) && (MaximumPacketLength
!= 8)) {
556 return EFI_INVALID_PARAMETER
;
559 if ((DeviceSpeed
== EFI_USB_SPEED_SUPER
) && (MaximumPacketLength
!= 512)) {
560 return EFI_INVALID_PARAMETER
;
563 Xhc
= PEI_RECOVERY_USB_XHC_DEV_FROM_THIS (This
);
565 Status
= EFI_DEVICE_ERROR
;
566 *TransferResult
= EFI_USB_ERR_SYSTEM
;
569 if (XhcPeiIsHalt (Xhc
) || XhcPeiIsSysError (Xhc
)) {
570 DEBUG ((EFI_D_ERROR
, "XhcPeiControlTransfer: HC is halted or has system error\n"));
575 // Check if the device is still enabled before every transaction.
577 SlotId
= XhcPeiBusDevAddrToSlotId (Xhc
, DeviceAddress
);
583 // Hook the Set_Address request from UsbBus.
584 // According to XHCI 1.0 spec, the Set_Address request is replaced by XHCI's Address_Device cmd.
586 if ((Request
->Request
== USB_REQ_SET_ADDRESS
) &&
587 (Request
->RequestType
== USB_REQUEST_TYPE (EfiUsbNoData
, USB_REQ_TYPE_STANDARD
, USB_TARGET_DEVICE
))) {
589 // Reset the BusDevAddr field of all disabled entries in UsbDevContext array firstly.
590 // This way is used to clean the history to avoid using wrong device address afterwards.
592 for (Index
= 0; Index
< 255; Index
++) {
593 if (!Xhc
->UsbDevContext
[Index
+ 1].Enabled
&&
594 (Xhc
->UsbDevContext
[Index
+ 1].SlotId
== 0) &&
595 (Xhc
->UsbDevContext
[Index
+ 1].BusDevAddr
== (UINT8
) Request
->Value
)) {
596 Xhc
->UsbDevContext
[Index
+ 1].BusDevAddr
= 0;
600 if (Xhc
->UsbDevContext
[SlotId
].XhciDevAddr
== 0) {
604 // The actual device address has been assigned by XHCI during initializing the device slot.
605 // So we just need establish the mapping relationship between the device address requested from UsbBus
606 // and the actual device address assigned by XHCI. The following invocations through EFI_USB2_HC_PROTOCOL interface
607 // can find out the actual device address by it.
609 Xhc
->UsbDevContext
[SlotId
].BusDevAddr
= (UINT8
) Request
->Value
;
610 Status
= EFI_SUCCESS
;
615 // Create a new URB, insert it into the asynchronous
616 // schedule list, then poll the execution status.
617 // Note that we encode the direction in address although default control
618 // endpoint is bidirectional. XhcPeiCreateUrb expects this
619 // combination of Ep addr and its direction.
621 Endpoint
= (UINT8
) (0 | ((TransferDirection
== EfiUsbDataIn
) ? 0x80 : 0));
622 Urb
= XhcPeiCreateUrb (
637 DEBUG ((EFI_D_ERROR
, "XhcPeiControlTransfer: failed to create URB"));
638 Status
= EFI_OUT_OF_RESOURCES
;
642 Status
= XhcPeiExecTransfer (Xhc
, FALSE
, Urb
, TimeOut
);
645 // Get the status from URB. The result is updated in XhcPeiCheckUrbResult
646 // which is called by XhcPeiExecTransfer
648 *TransferResult
= Urb
->Result
;
649 *DataLength
= Urb
->Completed
;
651 if (*TransferResult
== EFI_USB_NOERROR
) {
652 Status
= EFI_SUCCESS
;
653 } else if (*TransferResult
== EFI_USB_ERR_STALL
) {
654 RecoveryStatus
= XhcPeiRecoverHaltedEndpoint(Xhc
, Urb
);
655 if (EFI_ERROR (RecoveryStatus
)) {
656 DEBUG ((EFI_D_ERROR
, "XhcPeiControlTransfer: XhcPeiRecoverHaltedEndpoint failed\n"));
658 Status
= EFI_DEVICE_ERROR
;
665 // Hook Get_Descriptor request from UsbBus as we need evaluate context and configure endpoint.
666 // Hook Get_Status request form UsbBus as we need trace device attach/detach event happened at hub.
667 // Hook Set_Config request from UsbBus as we need configure device endpoint.
669 if ((Request
->Request
== USB_REQ_GET_DESCRIPTOR
) &&
670 ((Request
->RequestType
== USB_REQUEST_TYPE (EfiUsbDataIn
, USB_REQ_TYPE_STANDARD
, USB_TARGET_DEVICE
)) ||
671 ((Request
->RequestType
== USB_REQUEST_TYPE (EfiUsbDataIn
, USB_REQ_TYPE_CLASS
, USB_TARGET_DEVICE
))))) {
672 DescriptorType
= (UINT8
) (Request
->Value
>> 8);
673 if ((DescriptorType
== USB_DESC_TYPE_DEVICE
) && ((*DataLength
== sizeof (EFI_USB_DEVICE_DESCRIPTOR
)) || ((DeviceSpeed
== EFI_USB_SPEED_FULL
) && (*DataLength
== 8)))) {
674 ASSERT (Data
!= NULL
);
676 // Store a copy of device scriptor as hub device need this info to configure endpoint.
678 CopyMem (&Xhc
->UsbDevContext
[SlotId
].DevDesc
, Data
, *DataLength
);
679 if (Xhc
->UsbDevContext
[SlotId
].DevDesc
.BcdUSB
== 0x0300) {
681 // If it's a usb3.0 device, then its max packet size is a 2^n.
683 MaxPacket0
= 1 << Xhc
->UsbDevContext
[SlotId
].DevDesc
.MaxPacketSize0
;
685 MaxPacket0
= Xhc
->UsbDevContext
[SlotId
].DevDesc
.MaxPacketSize0
;
687 Xhc
->UsbDevContext
[SlotId
].ConfDesc
= AllocateZeroPool (Xhc
->UsbDevContext
[SlotId
].DevDesc
.NumConfigurations
* sizeof (EFI_USB_CONFIG_DESCRIPTOR
*));
688 if (Xhc
->UsbDevContext
[SlotId
].ConfDesc
== NULL
) {
689 Status
= EFI_OUT_OF_RESOURCES
;
692 if (Xhc
->HcCParams
.Data
.Csz
== 0) {
693 Status
= XhcPeiEvaluateContext (Xhc
, SlotId
, MaxPacket0
);
695 Status
= XhcPeiEvaluateContext64 (Xhc
, SlotId
, MaxPacket0
);
697 } else if (DescriptorType
== USB_DESC_TYPE_CONFIG
) {
698 ASSERT (Data
!= NULL
);
699 if (*DataLength
== ((UINT16
*) Data
)[1]) {
701 // Get configuration value from request, store the configuration descriptor for Configure_Endpoint cmd.
703 Index
= (UINT8
) Request
->Value
;
704 ASSERT (Index
< Xhc
->UsbDevContext
[SlotId
].DevDesc
.NumConfigurations
);
705 Xhc
->UsbDevContext
[SlotId
].ConfDesc
[Index
] = AllocateZeroPool (*DataLength
);
706 if (Xhc
->UsbDevContext
[SlotId
].ConfDesc
[Index
] == NULL
) {
707 Status
= EFI_OUT_OF_RESOURCES
;
710 CopyMem (Xhc
->UsbDevContext
[SlotId
].ConfDesc
[Index
], Data
, *DataLength
);
712 } else if (((DescriptorType
== USB_DESC_TYPE_HUB
) ||
713 (DescriptorType
== USB_DESC_TYPE_HUB_SUPER_SPEED
)) && (*DataLength
> 2)) {
714 ASSERT (Data
!= NULL
);
715 HubDesc
= (EFI_USB_HUB_DESCRIPTOR
*) Data
;
716 ASSERT (HubDesc
->NumPorts
<= 15);
718 // The bit 5,6 of HubCharacter field of Hub Descriptor is TTT.
720 TTT
= (UINT8
) ((HubDesc
->HubCharacter
& (BIT5
| BIT6
)) >> 5);
721 if (Xhc
->UsbDevContext
[SlotId
].DevDesc
.DeviceProtocol
== 2) {
723 // Don't support multi-TT feature for super speed hub now.
726 DEBUG ((EFI_D_ERROR
, "XHCI: Don't support multi-TT feature for Hub now. (force to disable MTT)\n"));
731 if (Xhc
->HcCParams
.Data
.Csz
== 0) {
732 Status
= XhcPeiConfigHubContext (Xhc
, SlotId
, HubDesc
->NumPorts
, TTT
, MTT
);
734 Status
= XhcPeiConfigHubContext64 (Xhc
, SlotId
, HubDesc
->NumPorts
, TTT
, MTT
);
737 } else if ((Request
->Request
== USB_REQ_SET_CONFIG
) &&
738 (Request
->RequestType
== USB_REQUEST_TYPE (EfiUsbNoData
, USB_REQ_TYPE_STANDARD
, USB_TARGET_DEVICE
))) {
740 // Hook Set_Config request from UsbBus as we need configure device endpoint.
742 for (Index
= 0; Index
< Xhc
->UsbDevContext
[SlotId
].DevDesc
.NumConfigurations
; Index
++) {
743 if (Xhc
->UsbDevContext
[SlotId
].ConfDesc
[Index
]->ConfigurationValue
== (UINT8
)Request
->Value
) {
744 if (Xhc
->HcCParams
.Data
.Csz
== 0) {
745 Status
= XhcPeiSetConfigCmd (Xhc
, SlotId
, DeviceSpeed
, Xhc
->UsbDevContext
[SlotId
].ConfDesc
[Index
]);
747 Status
= XhcPeiSetConfigCmd64 (Xhc
, SlotId
, DeviceSpeed
, Xhc
->UsbDevContext
[SlotId
].ConfDesc
[Index
]);
752 } else if ((Request
->Request
== USB_REQ_GET_STATUS
) &&
753 (Request
->RequestType
== USB_REQUEST_TYPE (EfiUsbDataIn
, USB_REQ_TYPE_CLASS
, USB_TARGET_OTHER
))) {
754 ASSERT (Data
!= NULL
);
756 // Hook Get_Status request from UsbBus to keep track of the port status change.
758 State
= *(UINT32
*) Data
;
759 PortStatus
.PortStatus
= 0;
760 PortStatus
.PortChangeStatus
= 0;
762 if (DeviceSpeed
== EFI_USB_SPEED_SUPER
) {
764 // For super speed hub, its bit10~12 presents the attached device speed.
766 if ((State
& XHC_PORTSC_PS
) >> 10 == 0) {
767 PortStatus
.PortStatus
|= USB_PORT_STAT_SUPER_SPEED
;
771 // For high or full/low speed hub, its bit9~10 presents the attached device speed.
773 if (XHC_BIT_IS_SET (State
, BIT9
)) {
774 PortStatus
.PortStatus
|= USB_PORT_STAT_LOW_SPEED
;
775 } else if (XHC_BIT_IS_SET (State
, BIT10
)) {
776 PortStatus
.PortStatus
|= USB_PORT_STAT_HIGH_SPEED
;
781 // Convert the XHCI port/port change state to UEFI status
783 MapSize
= sizeof (mUsbHubPortStateMap
) / sizeof (USB_PORT_STATE_MAP
);
784 for (Index
= 0; Index
< MapSize
; Index
++) {
785 if (XHC_BIT_IS_SET (State
, mUsbHubPortStateMap
[Index
].HwState
)) {
786 PortStatus
.PortStatus
= (UINT16
) (PortStatus
.PortStatus
| mUsbHubPortStateMap
[Index
].UefiState
);
790 MapSize
= sizeof (mUsbHubPortChangeMap
) / sizeof (USB_PORT_STATE_MAP
);
791 for (Index
= 0; Index
< MapSize
; Index
++) {
792 if (XHC_BIT_IS_SET (State
, mUsbHubPortChangeMap
[Index
].HwState
)) {
793 PortStatus
.PortChangeStatus
= (UINT16
) (PortStatus
.PortChangeStatus
| mUsbHubPortChangeMap
[Index
].UefiState
);
797 MapSize
= sizeof (mUsbHubClearPortChangeMap
) / sizeof (USB_CLEAR_PORT_MAP
);
799 for (Index
= 0; Index
< MapSize
; Index
++) {
800 if (XHC_BIT_IS_SET (State
, mUsbHubClearPortChangeMap
[Index
].HwState
)) {
801 ZeroMem (&ClearPortRequest
, sizeof (EFI_USB_DEVICE_REQUEST
));
802 ClearPortRequest
.RequestType
= USB_REQUEST_TYPE (EfiUsbNoData
, USB_REQ_TYPE_CLASS
, USB_TARGET_OTHER
);
803 ClearPortRequest
.Request
= (UINT8
) USB_REQ_CLEAR_FEATURE
;
804 ClearPortRequest
.Value
= mUsbHubClearPortChangeMap
[Index
].Selector
;
805 ClearPortRequest
.Index
= Request
->Index
;
806 ClearPortRequest
.Length
= 0;
808 XhcPeiControlTransfer (
825 XhcPeiPollPortStatusChange (Xhc
, Xhc
->UsbDevContext
[SlotId
].RouteString
, (UINT8
)Request
->Index
, &PortStatus
);
827 *(UINT32
*) Data
= *(UINT32
*) &PortStatus
;
831 XhcPeiFreeUrb (Xhc
, Urb
);
835 if (EFI_ERROR (Status
)) {
836 DEBUG ((EFI_D_ERROR
, "XhcPeiControlTransfer: error - %r, transfer - %x\n", Status
, *TransferResult
));
843 Submits bulk transfer to a bulk endpoint of a USB device.
845 @param PeiServices The pointer of EFI_PEI_SERVICES.
846 @param This The pointer of PEI_USB2_HOST_CONTROLLER_PPI.
847 @param DeviceAddress Target device address.
848 @param EndPointAddress Endpoint number and its direction in bit 7.
849 @param DeviceSpeed Device speed, Low speed device doesn't support
851 @param MaximumPacketLength Maximum packet size the endpoint is capable of
852 sending or receiving.
853 @param Data Array of pointers to the buffers of data to transmit
854 from or receive into.
855 @param DataLength The lenght of the data buffer.
856 @param DataToggle On input, the initial data toggle for the transfer;
857 On output, it is updated to to next data toggle to use of
858 the subsequent bulk transfer.
859 @param TimeOut Indicates the maximum time, in millisecond, which the
860 transfer is allowed to complete.
861 If Timeout is 0, then the caller must wait for the function
862 to be completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.
863 @param Translator A pointr to the transaction translator data.
864 @param TransferResult A pointer to the detailed result information of the
867 @retval EFI_SUCCESS The transfer was completed successfully.
868 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
869 @retval EFI_INVALID_PARAMETER Parameters are invalid.
870 @retval EFI_TIMEOUT The transfer failed due to timeout.
871 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
877 IN EFI_PEI_SERVICES
**PeiServices
,
878 IN PEI_USB2_HOST_CONTROLLER_PPI
*This
,
879 IN UINT8 DeviceAddress
,
880 IN UINT8 EndPointAddress
,
881 IN UINT8 DeviceSpeed
,
882 IN UINTN MaximumPacketLength
,
883 IN OUT VOID
*Data
[EFI_USB_MAX_BULK_BUFFER_NUM
],
884 IN OUT UINTN
*DataLength
,
885 IN OUT UINT8
*DataToggle
,
887 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
888 OUT UINT32
*TransferResult
895 EFI_STATUS RecoveryStatus
;
898 // Validate the parameters
900 if ((DataLength
== NULL
) || (*DataLength
== 0) ||
901 (Data
== NULL
) || (Data
[0] == NULL
) || (TransferResult
== NULL
)) {
902 return EFI_INVALID_PARAMETER
;
905 if ((*DataToggle
!= 0) && (*DataToggle
!= 1)) {
906 return EFI_INVALID_PARAMETER
;
909 if ((DeviceSpeed
== EFI_USB_SPEED_LOW
) ||
910 ((DeviceSpeed
== EFI_USB_SPEED_FULL
) && (MaximumPacketLength
> 64)) ||
911 ((DeviceSpeed
== EFI_USB_SPEED_HIGH
) && (MaximumPacketLength
> 512)) ||
912 ((DeviceSpeed
== EFI_USB_SPEED_SUPER
) && (MaximumPacketLength
> 1024))) {
913 return EFI_INVALID_PARAMETER
;
916 Xhc
= PEI_RECOVERY_USB_XHC_DEV_FROM_THIS (This
);
918 *TransferResult
= EFI_USB_ERR_SYSTEM
;
919 Status
= EFI_DEVICE_ERROR
;
921 if (XhcPeiIsHalt (Xhc
) || XhcPeiIsSysError (Xhc
)) {
922 DEBUG ((EFI_D_ERROR
, "XhcPeiBulkTransfer: HC is halted or has system error\n"));
927 // Check if the device is still enabled before every transaction.
929 SlotId
= XhcPeiBusDevAddrToSlotId (Xhc
, DeviceAddress
);
935 // Create a new URB, insert it into the asynchronous
936 // schedule list, then poll the execution status.
938 Urb
= XhcPeiCreateUrb (
953 DEBUG ((EFI_D_ERROR
, "XhcPeiBulkTransfer: failed to create URB\n"));
954 Status
= EFI_OUT_OF_RESOURCES
;
958 Status
= XhcPeiExecTransfer (Xhc
, FALSE
, Urb
, TimeOut
);
960 *TransferResult
= Urb
->Result
;
961 *DataLength
= Urb
->Completed
;
963 if (*TransferResult
== EFI_USB_NOERROR
) {
964 Status
= EFI_SUCCESS
;
965 } else if (*TransferResult
== EFI_USB_ERR_STALL
) {
966 RecoveryStatus
= XhcPeiRecoverHaltedEndpoint(Xhc
, Urb
);
967 if (EFI_ERROR (RecoveryStatus
)) {
968 DEBUG ((EFI_D_ERROR
, "XhcPeiBulkTransfer: XhcPeiRecoverHaltedEndpoint failed\n"));
970 Status
= EFI_DEVICE_ERROR
;
973 XhcPeiFreeUrb (Xhc
, Urb
);
977 if (EFI_ERROR (Status
)) {
978 DEBUG ((EFI_D_ERROR
, "XhcPeiBulkTransfer: error - %r, transfer - %x\n", Status
, *TransferResult
));
985 Retrieves the number of root hub ports.
987 @param[in] PeiServices The pointer to the PEI Services Table.
988 @param[in] This The pointer to this instance of the
989 PEI_USB2_HOST_CONTROLLER_PPI.
990 @param[out] PortNumber The pointer to the number of the root hub ports.
992 @retval EFI_SUCCESS The port number was retrieved successfully.
993 @retval EFI_INVALID_PARAMETER PortNumber is NULL.
998 XhcPeiGetRootHubPortNumber (
999 IN EFI_PEI_SERVICES
**PeiServices
,
1000 IN PEI_USB2_HOST_CONTROLLER_PPI
*This
,
1001 OUT UINT8
*PortNumber
1004 PEI_XHC_DEV
*XhcDev
;
1005 XhcDev
= PEI_RECOVERY_USB_XHC_DEV_FROM_THIS (This
);
1007 if (PortNumber
== NULL
) {
1008 return EFI_INVALID_PARAMETER
;
1011 *PortNumber
= XhcDev
->HcSParams1
.Data
.MaxPorts
;
1012 DEBUG ((EFI_D_INFO
, "XhcPeiGetRootHubPortNumber: PortNumber = %x\n", *PortNumber
));
1017 Clears a feature for the specified root hub port.
1019 @param PeiServices The pointer of EFI_PEI_SERVICES.
1020 @param This The pointer of PEI_USB2_HOST_CONTROLLER_PPI.
1021 @param PortNumber Specifies the root hub port whose feature
1022 is requested to be cleared.
1023 @param PortFeature Indicates the feature selector associated with the
1024 feature clear request.
1026 @retval EFI_SUCCESS The feature specified by PortFeature was cleared
1027 for the USB root hub port specified by PortNumber.
1028 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
1033 XhcPeiClearRootHubPortFeature (
1034 IN EFI_PEI_SERVICES
**PeiServices
,
1035 IN PEI_USB2_HOST_CONTROLLER_PPI
*This
,
1036 IN UINT8 PortNumber
,
1037 IN EFI_USB_PORT_FEATURE PortFeature
1045 Xhc
= PEI_RECOVERY_USB_XHC_DEV_FROM_THIS (This
);
1046 Status
= EFI_SUCCESS
;
1048 if (PortNumber
>= Xhc
->HcSParams1
.Data
.MaxPorts
) {
1049 Status
= EFI_INVALID_PARAMETER
;
1053 Offset
= (UINT32
) (XHC_PORTSC_OFFSET
+ (0x10 * PortNumber
));
1054 State
= XhcPeiReadOpReg (Xhc
, Offset
);
1055 DEBUG ((EFI_D_INFO
, "XhcPeiClearRootHubPortFeature: Port: %x State: %x\n", PortNumber
, State
));
1058 // Mask off the port status change bits, these bits are
1061 State
&= ~ (BIT1
| BIT17
| BIT18
| BIT19
| BIT20
| BIT21
| BIT22
| BIT23
);
1063 switch (PortFeature
) {
1064 case EfiUsbPortEnable
:
1066 // Ports may only be enabled by the xHC. Software cannot enable a port by writing a '1' to this flag.
1067 // A port may be disabled by software writing a '1' to this flag.
1069 State
|= XHC_PORTSC_PED
;
1070 State
&= ~XHC_PORTSC_RESET
;
1071 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1074 case EfiUsbPortSuspend
:
1075 State
|= XHC_PORTSC_LWS
;
1076 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1077 State
&= ~XHC_PORTSC_PLS
;
1078 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1081 case EfiUsbPortReset
:
1083 // PORTSC_RESET BIT(4) bit is RW1S attribute, which means Write-1-to-set status:
1084 // Register bits indicate status when read, a clear bit may be set by
1085 // writing a '1'. Writing a '0' to RW1S bits has no effect.
1089 case EfiUsbPortPower
:
1090 if (Xhc
->HcCParams
.Data
.Ppc
) {
1092 // Port Power Control supported
1094 State
&= ~XHC_PORTSC_PP
;
1095 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1099 case EfiUsbPortOwner
:
1101 // XHCI root hub port don't has the owner bit, ignore the operation
1105 case EfiUsbPortConnectChange
:
1107 // Clear connect status change
1109 State
|= XHC_PORTSC_CSC
;
1110 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1113 case EfiUsbPortEnableChange
:
1115 // Clear enable status change
1117 State
|= XHC_PORTSC_PEC
;
1118 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1121 case EfiUsbPortOverCurrentChange
:
1123 // Clear PortOverCurrent change
1125 State
|= XHC_PORTSC_OCC
;
1126 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1129 case EfiUsbPortResetChange
:
1131 // Clear Port Reset change
1133 State
|= XHC_PORTSC_PRC
;
1134 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1137 case EfiUsbPortSuspendChange
:
1139 // Not supported or not related operation
1144 Status
= EFI_INVALID_PARAMETER
;
1149 DEBUG ((EFI_D_INFO
, "XhcPeiClearRootHubPortFeature: PortFeature: %x Status = %r\n", PortFeature
, Status
));
1154 Sets a feature for the specified root hub port.
1156 @param PeiServices The pointer of EFI_PEI_SERVICES
1157 @param This The pointer of PEI_USB2_HOST_CONTROLLER_PPI
1158 @param PortNumber Root hub port to set.
1159 @param PortFeature Feature to set.
1161 @retval EFI_SUCCESS The feature specified by PortFeature was set.
1162 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
1163 @retval EFI_TIMEOUT The time out occurred.
1168 XhcPeiSetRootHubPortFeature (
1169 IN EFI_PEI_SERVICES
**PeiServices
,
1170 IN PEI_USB2_HOST_CONTROLLER_PPI
*This
,
1171 IN UINT8 PortNumber
,
1172 IN EFI_USB_PORT_FEATURE PortFeature
1180 Xhc
= PEI_RECOVERY_USB_XHC_DEV_FROM_THIS (This
);
1181 Status
= EFI_SUCCESS
;
1183 if (PortNumber
>= Xhc
->HcSParams1
.Data
.MaxPorts
) {
1184 Status
= EFI_INVALID_PARAMETER
;
1188 Offset
= (UINT32
) (XHC_PORTSC_OFFSET
+ (0x10 * PortNumber
));
1189 State
= XhcPeiReadOpReg (Xhc
, Offset
);
1190 DEBUG ((EFI_D_INFO
, "XhcPeiSetRootHubPortFeature: Port: %x State: %x\n", PortNumber
, State
));
1193 // Mask off the port status change bits, these bits are
1196 State
&= ~ (BIT1
| BIT17
| BIT18
| BIT19
| BIT20
| BIT21
| BIT22
| BIT23
);
1198 switch (PortFeature
) {
1199 case EfiUsbPortEnable
:
1201 // Ports may only be enabled by the xHC. Software cannot enable a port by writing a '1' to this flag.
1202 // A port may be disabled by software writing a '1' to this flag.
1206 case EfiUsbPortSuspend
:
1207 State
|= XHC_PORTSC_LWS
;
1208 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1209 State
&= ~XHC_PORTSC_PLS
;
1211 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1214 case EfiUsbPortReset
:
1216 // Make sure Host Controller not halt before reset it
1218 if (XhcPeiIsHalt (Xhc
)) {
1219 Status
= XhcPeiRunHC (Xhc
, XHC_GENERIC_TIMEOUT
);
1220 if (EFI_ERROR (Status
)) {
1226 // 4.3.1 Resetting a Root Hub Port
1227 // 1) Write the PORTSC register with the Port Reset (PR) bit set to '1'.
1228 // 2) Wait for a successful Port Status Change Event for the port, where the Port Reset Change (PRC)
1229 // bit in the PORTSC field is set to '1'.
1231 State
|= XHC_PORTSC_RESET
;
1232 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1233 XhcPeiWaitOpRegBit(Xhc
, Offset
, XHC_PORTSC_PRC
, TRUE
, XHC_GENERIC_TIMEOUT
);
1236 case EfiUsbPortPower
:
1237 if (Xhc
->HcCParams
.Data
.Ppc
) {
1239 // Port Power Control supported
1241 State
|= XHC_PORTSC_PP
;
1242 XhcPeiWriteOpReg (Xhc
, Offset
, State
);
1246 case EfiUsbPortOwner
:
1248 // XHCI root hub port don't has the owner bit, ignore the operation
1253 Status
= EFI_INVALID_PARAMETER
;
1257 DEBUG ((EFI_D_INFO
, "XhcPeiSetRootHubPortFeature: PortFeature: %x Status = %r\n", PortFeature
, Status
));
1262 Retrieves the current status of a USB root hub port.
1264 @param PeiServices The pointer of EFI_PEI_SERVICES.
1265 @param This The pointer of PEI_USB2_HOST_CONTROLLER_PPI.
1266 @param PortNumber The root hub port to retrieve the state from.
1267 @param PortStatus Variable to receive the port state.
1269 @retval EFI_SUCCESS The status of the USB root hub port specified.
1270 by PortNumber was returned in PortStatus.
1271 @retval EFI_INVALID_PARAMETER PortNumber is invalid.
1276 XhcPeiGetRootHubPortStatus (
1277 IN EFI_PEI_SERVICES
**PeiServices
,
1278 IN PEI_USB2_HOST_CONTROLLER_PPI
*This
,
1279 IN UINT8 PortNumber
,
1280 OUT EFI_USB_PORT_STATUS
*PortStatus
1288 USB_DEV_ROUTE ParentRouteChart
;
1290 if (PortStatus
== NULL
) {
1291 return EFI_INVALID_PARAMETER
;
1294 Xhc
= PEI_RECOVERY_USB_XHC_DEV_FROM_THIS (This
);
1296 if (PortNumber
>= Xhc
->HcSParams1
.Data
.MaxPorts
) {
1297 return EFI_INVALID_PARAMETER
;
1301 // Clear port status.
1303 PortStatus
->PortStatus
= 0;
1304 PortStatus
->PortChangeStatus
= 0;
1306 Offset
= (UINT32
) (XHC_PORTSC_OFFSET
+ (0x10 * PortNumber
));
1307 State
= XhcPeiReadOpReg (Xhc
, Offset
);
1308 DEBUG ((EFI_D_INFO
, "XhcPeiGetRootHubPortStatus: Port: %x State: %x\n", PortNumber
, State
));
1311 // According to XHCI 1.0 spec, bit 10~13 of the root port status register identifies the speed of the attached device.
1313 switch ((State
& XHC_PORTSC_PS
) >> 10) {
1315 PortStatus
->PortStatus
|= USB_PORT_STAT_LOW_SPEED
;
1319 PortStatus
->PortStatus
|= USB_PORT_STAT_HIGH_SPEED
;
1323 PortStatus
->PortStatus
|= USB_PORT_STAT_SUPER_SPEED
;
1331 // Convert the XHCI port/port change state to UEFI status
1333 MapSize
= sizeof (mUsbPortStateMap
) / sizeof (USB_PORT_STATE_MAP
);
1335 for (Index
= 0; Index
< MapSize
; Index
++) {
1336 if (XHC_BIT_IS_SET (State
, mUsbPortStateMap
[Index
].HwState
)) {
1337 PortStatus
->PortStatus
= (UINT16
) (PortStatus
->PortStatus
| mUsbPortStateMap
[Index
].UefiState
);
1341 // Bit5~8 reflects its current link state.
1343 if ((State
& XHC_PORTSC_PLS
) >> 5 == 3) {
1344 PortStatus
->PortStatus
|= USB_PORT_STAT_SUSPEND
;
1347 MapSize
= sizeof (mUsbPortChangeMap
) / sizeof (USB_PORT_STATE_MAP
);
1349 for (Index
= 0; Index
< MapSize
; Index
++) {
1350 if (XHC_BIT_IS_SET (State
, mUsbPortChangeMap
[Index
].HwState
)) {
1351 PortStatus
->PortChangeStatus
= (UINT16
) (PortStatus
->PortChangeStatus
| mUsbPortChangeMap
[Index
].UefiState
);
1355 MapSize
= sizeof (mUsbClearPortChangeMap
) / sizeof (USB_CLEAR_PORT_MAP
);
1357 for (Index
= 0; Index
< MapSize
; Index
++) {
1358 if (XHC_BIT_IS_SET (State
, mUsbClearPortChangeMap
[Index
].HwState
)) {
1359 XhcPeiClearRootHubPortFeature (PeiServices
, This
, PortNumber
, (EFI_USB_PORT_FEATURE
)mUsbClearPortChangeMap
[Index
].Selector
);
1364 // Poll the root port status register to enable/disable corresponding device slot if there is a device attached/detached.
1365 // For those devices behind hub, we get its attach/detach event by hooking Get_Port_Status request at control transfer for those hub.
1367 ParentRouteChart
.Dword
= 0;
1368 XhcPeiPollPortStatusChange (Xhc
, ParentRouteChart
, PortNumber
, PortStatus
);
1370 DEBUG ((EFI_D_INFO
, "XhcPeiGetRootHubPortStatus: PortChangeStatus: %x PortStatus: %x\n", PortStatus
->PortChangeStatus
, PortStatus
->PortStatus
));
1375 @param FileHandle Handle of the file being invoked.
1376 @param PeiServices Describes the list of possible PEI Services.
1378 @retval EFI_SUCCESS PPI successfully installed.
1384 IN EFI_PEI_FILE_HANDLE FileHandle
,
1385 IN CONST EFI_PEI_SERVICES
**PeiServices
1388 PEI_USB_CONTROLLER_PPI
*UsbControllerPpi
;
1391 UINTN ControllerType
;
1394 PEI_XHC_DEV
*XhcDev
;
1395 EFI_PHYSICAL_ADDRESS TempPtr
;
1399 // Shadow this PEIM to run from memory.
1401 if (!EFI_ERROR (PeiServicesRegisterForShadow (FileHandle
))) {
1405 Status
= PeiServicesLocatePpi (
1406 &gPeiUsbControllerPpiGuid
,
1409 (VOID
**) &UsbControllerPpi
1411 if (EFI_ERROR (Status
)) {
1412 return EFI_UNSUPPORTED
;
1417 Status
= UsbControllerPpi
->GetUsbController (
1418 (EFI_PEI_SERVICES
**) PeiServices
,
1425 // When status is error, it means no controller is found.
1427 if (EFI_ERROR (Status
)) {
1432 // This PEIM is for XHC type controller.
1434 if (ControllerType
!= PEI_XHCI_CONTROLLER
) {
1439 MemPages
= EFI_SIZE_TO_PAGES (sizeof (PEI_XHC_DEV
));
1440 Status
= PeiServicesAllocatePages (
1441 EfiBootServicesData
,
1445 if (EFI_ERROR (Status
)) {
1446 return EFI_OUT_OF_RESOURCES
;
1448 ZeroMem ((VOID
*) (UINTN
) TempPtr
, EFI_PAGES_TO_SIZE (MemPages
));
1449 XhcDev
= (PEI_XHC_DEV
*) ((UINTN
) TempPtr
);
1451 XhcDev
->Signature
= USB_XHC_DEV_SIGNATURE
;
1452 XhcDev
->UsbHostControllerBaseAddress
= (UINT32
) BaseAddress
;
1453 XhcDev
->CapLength
= (UINT8
) (XhcPeiReadCapRegister (XhcDev
, XHC_CAPLENGTH_OFFSET
) & 0x0FF);
1454 XhcDev
->HcSParams1
.Dword
= XhcPeiReadCapRegister (XhcDev
, XHC_HCSPARAMS1_OFFSET
);
1455 XhcDev
->HcSParams2
.Dword
= XhcPeiReadCapRegister (XhcDev
, XHC_HCSPARAMS2_OFFSET
);
1456 XhcDev
->HcCParams
.Dword
= XhcPeiReadCapRegister (XhcDev
, XHC_HCCPARAMS_OFFSET
);
1457 XhcDev
->DBOff
= XhcPeiReadCapRegister (XhcDev
, XHC_DBOFF_OFFSET
);
1458 XhcDev
->RTSOff
= XhcPeiReadCapRegister (XhcDev
, XHC_RTSOFF_OFFSET
);
1461 // This PageSize field defines the page size supported by the xHC implementation.
1462 // This xHC supports a page size of 2^(n+12) if bit n is Set. For example,
1463 // if bit 0 is Set, the xHC supports 4k byte page sizes.
1465 PageSize
= XhcPeiReadOpReg (XhcDev
, XHC_PAGESIZE_OFFSET
) & XHC_PAGESIZE_MASK
;
1466 XhcDev
->PageSize
= 1 << (HighBitSet32 (PageSize
) + 12);
1468 DEBUG ((EFI_D_INFO
, "XhciPei: UsbHostControllerBaseAddress: %x\n", XhcDev
->UsbHostControllerBaseAddress
));
1469 DEBUG ((EFI_D_INFO
, "XhciPei: CapLength: %x\n", XhcDev
->CapLength
));
1470 DEBUG ((EFI_D_INFO
, "XhciPei: HcSParams1: %x\n", XhcDev
->HcSParams1
.Dword
));
1471 DEBUG ((EFI_D_INFO
, "XhciPei: HcSParams2: %x\n", XhcDev
->HcSParams2
.Dword
));
1472 DEBUG ((EFI_D_INFO
, "XhciPei: HcCParams: %x\n", XhcDev
->HcCParams
.Dword
));
1473 DEBUG ((EFI_D_INFO
, "XhciPei: DBOff: %x\n", XhcDev
->DBOff
));
1474 DEBUG ((EFI_D_INFO
, "XhciPei: RTSOff: %x\n", XhcDev
->RTSOff
));
1475 DEBUG ((EFI_D_INFO
, "XhciPei: PageSize: %x\n", XhcDev
->PageSize
));
1477 XhcPeiResetHC (XhcDev
, XHC_RESET_TIMEOUT
);
1478 ASSERT (XhcPeiIsHalt (XhcDev
));
1481 // Initialize the schedule
1483 XhcPeiInitSched (XhcDev
);
1486 // Start the Host Controller
1488 XhcPeiRunHC (XhcDev
, XHC_GENERIC_TIMEOUT
);
1491 // Wait for root port state stable
1493 MicroSecondDelay (XHC_ROOT_PORT_STATE_STABLE
);
1495 XhcDev
->Usb2HostControllerPpi
.ControlTransfer
= XhcPeiControlTransfer
;
1496 XhcDev
->Usb2HostControllerPpi
.BulkTransfer
= XhcPeiBulkTransfer
;
1497 XhcDev
->Usb2HostControllerPpi
.GetRootHubPortNumber
= XhcPeiGetRootHubPortNumber
;
1498 XhcDev
->Usb2HostControllerPpi
.GetRootHubPortStatus
= XhcPeiGetRootHubPortStatus
;
1499 XhcDev
->Usb2HostControllerPpi
.SetRootHubPortFeature
= XhcPeiSetRootHubPortFeature
;
1500 XhcDev
->Usb2HostControllerPpi
.ClearRootHubPortFeature
= XhcPeiClearRootHubPortFeature
;
1502 XhcDev
->PpiDescriptor
.Flags
= (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
1503 XhcDev
->PpiDescriptor
.Guid
= &gPeiUsb2HostControllerPpiGuid
;
1504 XhcDev
->PpiDescriptor
.Ppi
= &XhcDev
->Usb2HostControllerPpi
;
1506 PeiServicesInstallPpi (&XhcDev
->PpiDescriptor
);