2 This driver is used to manage SD/MMC PCI host controllers which are compliance
3 with SD Host Controller Simplified Specification version 3.00 plus the 64-bit
4 System Addressing support in SD Host Controller Simplified Specification version
7 It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
9 Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
10 Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
11 This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include "SdMmcPciHcDxe.h"
24 Dump the content of SD/MMC host controller's Capability Register.
26 @param[in] Slot The slot number of the SD card to send the command to.
27 @param[in] Capability The buffer to store the capability data.
33 IN SD_MMC_HC_SLOT_CAP
*Capability
37 // Dump Capability Data
39 DEBUG ((DEBUG_INFO
, " == Slot [%d] Capability is 0x%x ==\n", Slot
, Capability
));
40 DEBUG ((DEBUG_INFO
, " Timeout Clk Freq %d%a\n", Capability
->TimeoutFreq
, (Capability
->TimeoutUnit
) ? "MHz" : "KHz"));
41 DEBUG ((DEBUG_INFO
, " Base Clk Freq %dMHz\n", Capability
->BaseClkFreq
));
42 DEBUG ((DEBUG_INFO
, " Max Blk Len %dbytes\n", 512 * (1 << Capability
->MaxBlkLen
)));
43 DEBUG ((DEBUG_INFO
, " 8-bit Support %a\n", Capability
->BusWidth8
? "TRUE" : "FALSE"));
44 DEBUG ((DEBUG_INFO
, " ADMA2 Support %a\n", Capability
->Adma2
? "TRUE" : "FALSE"));
45 DEBUG ((DEBUG_INFO
, " HighSpeed Support %a\n", Capability
->HighSpeed
? "TRUE" : "FALSE"));
46 DEBUG ((DEBUG_INFO
, " SDMA Support %a\n", Capability
->Sdma
? "TRUE" : "FALSE"));
47 DEBUG ((DEBUG_INFO
, " Suspend/Resume %a\n", Capability
->SuspRes
? "TRUE" : "FALSE"));
48 DEBUG ((DEBUG_INFO
, " Voltage 3.3 %a\n", Capability
->Voltage33
? "TRUE" : "FALSE"));
49 DEBUG ((DEBUG_INFO
, " Voltage 3.0 %a\n", Capability
->Voltage30
? "TRUE" : "FALSE"));
50 DEBUG ((DEBUG_INFO
, " Voltage 1.8 %a\n", Capability
->Voltage18
? "TRUE" : "FALSE"));
51 DEBUG ((DEBUG_INFO
, " V4 64-bit Sys Bus %a\n", Capability
->SysBus64V4
? "TRUE" : "FALSE"));
52 DEBUG ((DEBUG_INFO
, " V3 64-bit Sys Bus %a\n", Capability
->SysBus64V3
? "TRUE" : "FALSE"));
53 DEBUG ((DEBUG_INFO
, " Async Interrupt %a\n", Capability
->AsyncInt
? "TRUE" : "FALSE"));
54 DEBUG ((DEBUG_INFO
, " SlotType "));
55 if (Capability
->SlotType
== 0x00) {
56 DEBUG ((DEBUG_INFO
, "%a\n", "Removable Slot"));
57 } else if (Capability
->SlotType
== 0x01) {
58 DEBUG ((DEBUG_INFO
, "%a\n", "Embedded Slot"));
59 } else if (Capability
->SlotType
== 0x02) {
60 DEBUG ((DEBUG_INFO
, "%a\n", "Shared Bus Slot"));
62 DEBUG ((DEBUG_INFO
, "%a\n", "Reserved"));
64 DEBUG ((DEBUG_INFO
, " SDR50 Support %a\n", Capability
->Sdr50
? "TRUE" : "FALSE"));
65 DEBUG ((DEBUG_INFO
, " SDR104 Support %a\n", Capability
->Sdr104
? "TRUE" : "FALSE"));
66 DEBUG ((DEBUG_INFO
, " DDR50 Support %a\n", Capability
->Ddr50
? "TRUE" : "FALSE"));
67 DEBUG ((DEBUG_INFO
, " Driver Type A %a\n", Capability
->DriverTypeA
? "TRUE" : "FALSE"));
68 DEBUG ((DEBUG_INFO
, " Driver Type C %a\n", Capability
->DriverTypeC
? "TRUE" : "FALSE"));
69 DEBUG ((DEBUG_INFO
, " Driver Type D %a\n", Capability
->DriverTypeD
? "TRUE" : "FALSE"));
70 DEBUG ((DEBUG_INFO
, " Driver Type 4 %a\n", Capability
->DriverType4
? "TRUE" : "FALSE"));
71 if (Capability
->TimerCount
== 0) {
72 DEBUG ((DEBUG_INFO
, " Retuning TimerCnt Disabled\n", 2 * (Capability
->TimerCount
- 1)));
74 DEBUG ((DEBUG_INFO
, " Retuning TimerCnt %dseconds\n", 2 * (Capability
->TimerCount
- 1)));
76 DEBUG ((DEBUG_INFO
, " SDR50 Tuning %a\n", Capability
->TuningSDR50
? "TRUE" : "FALSE"));
77 DEBUG ((DEBUG_INFO
, " Retuning Mode Mode %d\n", Capability
->RetuningMod
+ 1));
78 DEBUG ((DEBUG_INFO
, " Clock Multiplier M = %d\n", Capability
->ClkMultiplier
+ 1));
79 DEBUG ((DEBUG_INFO
, " HS 400 %a\n", Capability
->Hs400
? "TRUE" : "FALSE"));
84 Read SlotInfo register from SD/MMC host controller pci config space.
86 @param[in] PciIo The PCI IO protocol instance.
87 @param[out] FirstBar The buffer to store the first BAR value.
88 @param[out] SlotNum The buffer to store the supported slot number.
90 @retval EFI_SUCCESS The operation succeeds.
91 @retval Others The operation fails.
97 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
103 SD_MMC_HC_SLOT_INFO SlotInfo
;
105 Status
= PciIo
->Pci
.Read (
108 SD_MMC_HC_SLOT_OFFSET
,
112 if (EFI_ERROR (Status
)) {
116 *FirstBar
= SlotInfo
.FirstBar
;
117 *SlotNum
= SlotInfo
.SlotNum
+ 1;
118 ASSERT ((*FirstBar
+ *SlotNum
) < SD_MMC_HC_MAX_SLOT
);
123 Read/Write specified SD/MMC host controller mmio register.
125 @param[in] PciIo The PCI IO protocol instance.
126 @param[in] BarIndex The BAR index of the standard PCI Configuration
127 header to use as the base address for the memory
128 operation to perform.
129 @param[in] Offset The offset within the selected BAR to start the
131 @param[in] Read A boolean to indicate it's read or write operation.
132 @param[in] Count The width of the mmio register in bytes.
133 Must be 1, 2 , 4 or 8 bytes.
134 @param[in, out] Data For read operations, the destination buffer to store
135 the results. For write operations, the source buffer
136 to write data from. The caller is responsible for
137 having ownership of the data buffer and ensuring its
138 size not less than Count bytes.
140 @retval EFI_INVALID_PARAMETER The PciIo or Data is NULL or the Count is not valid.
141 @retval EFI_SUCCESS The read/write operation succeeds.
142 @retval Others The read/write operation fails.
148 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
157 EFI_PCI_IO_PROTOCOL_WIDTH Width
;
159 if ((PciIo
== NULL
) || (Data
== NULL
)) {
160 return EFI_INVALID_PARAMETER
;
165 Width
= EfiPciIoWidthUint8
;
168 Width
= EfiPciIoWidthUint16
;
172 Width
= EfiPciIoWidthUint32
;
176 Width
= EfiPciIoWidthUint32
;
180 return EFI_INVALID_PARAMETER
;
184 Status
= PciIo
->Mem
.Read (
193 Status
= PciIo
->Mem
.Write (
207 Do OR operation with the value of the specified SD/MMC host controller mmio register.
209 @param[in] PciIo The PCI IO protocol instance.
210 @param[in] BarIndex The BAR index of the standard PCI Configuration
211 header to use as the base address for the memory
212 operation to perform.
213 @param[in] Offset The offset within the selected BAR to start the
215 @param[in] Count The width of the mmio register in bytes.
216 Must be 1, 2 , 4 or 8 bytes.
217 @param[in] OrData The pointer to the data used to do OR operation.
218 The caller is responsible for having ownership of
219 the data buffer and ensuring its size not less than
222 @retval EFI_INVALID_PARAMETER The PciIo or OrData is NULL or the Count is not valid.
223 @retval EFI_SUCCESS The OR operation succeeds.
224 @retval Others The OR operation fails.
230 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
241 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, TRUE
, Count
, &Data
);
242 if (EFI_ERROR (Status
)) {
247 Or
= *(UINT8
*) OrData
;
248 } else if (Count
== 2) {
249 Or
= *(UINT16
*) OrData
;
250 } else if (Count
== 4) {
251 Or
= *(UINT32
*) OrData
;
252 } else if (Count
== 8) {
253 Or
= *(UINT64
*) OrData
;
255 return EFI_INVALID_PARAMETER
;
259 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, FALSE
, Count
, &Data
);
265 Do AND operation with the value of the specified SD/MMC host controller mmio register.
267 @param[in] PciIo The PCI IO protocol instance.
268 @param[in] BarIndex The BAR index of the standard PCI Configuration
269 header to use as the base address for the memory
270 operation to perform.
271 @param[in] Offset The offset within the selected BAR to start the
273 @param[in] Count The width of the mmio register in bytes.
274 Must be 1, 2 , 4 or 8 bytes.
275 @param[in] AndData The pointer to the data used to do AND operation.
276 The caller is responsible for having ownership of
277 the data buffer and ensuring its size not less than
280 @retval EFI_INVALID_PARAMETER The PciIo or AndData is NULL or the Count is not valid.
281 @retval EFI_SUCCESS The AND operation succeeds.
282 @retval Others The AND operation fails.
288 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
299 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, TRUE
, Count
, &Data
);
300 if (EFI_ERROR (Status
)) {
305 And
= *(UINT8
*) AndData
;
306 } else if (Count
== 2) {
307 And
= *(UINT16
*) AndData
;
308 } else if (Count
== 4) {
309 And
= *(UINT32
*) AndData
;
310 } else if (Count
== 8) {
311 And
= *(UINT64
*) AndData
;
313 return EFI_INVALID_PARAMETER
;
317 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, FALSE
, Count
, &Data
);
323 Wait for the value of the specified MMIO register set to the test value.
325 @param[in] PciIo The PCI IO protocol instance.
326 @param[in] BarIndex The BAR index of the standard PCI Configuration
327 header to use as the base address for the memory
328 operation to perform.
329 @param[in] Offset The offset within the selected BAR to start the
331 @param[in] Count The width of the mmio register in bytes.
332 Must be 1, 2, 4 or 8 bytes.
333 @param[in] MaskValue The mask value of memory.
334 @param[in] TestValue The test value of memory.
336 @retval EFI_NOT_READY The MMIO register hasn't set to the expected value.
337 @retval EFI_SUCCESS The MMIO register has expected value.
338 @retval Others The MMIO operation fails.
343 SdMmcHcCheckMmioSet (
344 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
356 // Access PCI MMIO space to see if the value is the tested one.
359 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, TRUE
, Count
, &Value
);
360 if (EFI_ERROR (Status
)) {
366 if (Value
== TestValue
) {
370 return EFI_NOT_READY
;
374 Wait for the value of the specified MMIO register set to the test value.
376 @param[in] PciIo The PCI IO protocol instance.
377 @param[in] BarIndex The BAR index of the standard PCI Configuration
378 header to use as the base address for the memory
379 operation to perform.
380 @param[in] Offset The offset within the selected BAR to start the
382 @param[in] Count The width of the mmio register in bytes.
383 Must be 1, 2, 4 or 8 bytes.
384 @param[in] MaskValue The mask value of memory.
385 @param[in] TestValue The test value of memory.
386 @param[in] Timeout The time out value for wait memory set, uses 1
387 microsecond as a unit.
389 @retval EFI_TIMEOUT The MMIO register hasn't expected value in timeout
391 @retval EFI_SUCCESS The MMIO register has expected value.
392 @retval Others The MMIO operation fails.
398 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
408 BOOLEAN InfiniteWait
;
413 InfiniteWait
= FALSE
;
416 while (InfiniteWait
|| (Timeout
> 0)) {
417 Status
= SdMmcHcCheckMmioSet (
425 if (Status
!= EFI_NOT_READY
) {
430 // Stall for 1 microsecond.
441 Get the controller version information from the specified slot.
443 @param[in] PciIo The PCI IO protocol instance.
444 @param[in] Slot The slot number of the SD card to send the command to.
445 @param[out] Version The buffer to store the version information.
447 @retval EFI_SUCCESS The operation executes successfully.
448 @retval Others The operation fails.
452 SdMmcHcGetControllerVersion (
453 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
460 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_CTRL_VER
, TRUE
, sizeof (UINT16
), Version
);
461 if (EFI_ERROR (Status
)) {
471 Software reset the specified SD/MMC host controller and enable all interrupts.
473 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
474 @param[in] Slot The slot number of the SD card to send the command to.
476 @retval EFI_SUCCESS The software reset executes successfully.
477 @retval Others The software reset fails.
482 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
488 EFI_PCI_IO_PROTOCOL
*PciIo
;
491 // Notify the SD/MMC override protocol that we are about to reset
492 // the SD/MMC host controller.
494 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
495 Status
= mOverride
->NotifyPhase (
496 Private
->ControllerHandle
,
500 if (EFI_ERROR (Status
)) {
502 "%a: SD/MMC pre reset notifier callback failed - %r\n",
503 __FUNCTION__
, Status
));
508 PciIo
= Private
->PciIo
;
510 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_SW_RST
, sizeof (SwReset
), &SwReset
);
512 if (EFI_ERROR (Status
)) {
513 DEBUG ((DEBUG_ERROR
, "SdMmcHcReset: write SW Reset for All fails: %r\n", Status
));
517 Status
= SdMmcHcWaitMmioSet (
524 SD_MMC_HC_GENERIC_TIMEOUT
526 if (EFI_ERROR (Status
)) {
527 DEBUG ((DEBUG_INFO
, "SdMmcHcReset: reset done with %r\n", Status
));
532 // Enable all interrupt after reset all.
534 Status
= SdMmcHcEnableInterrupt (PciIo
, Slot
);
535 if (EFI_ERROR (Status
)) {
536 DEBUG ((DEBUG_INFO
, "SdMmcHcReset: SdMmcHcEnableInterrupt done with %r\n",
542 // Notify the SD/MMC override protocol that we have just reset
543 // the SD/MMC host controller.
545 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
546 Status
= mOverride
->NotifyPhase (
547 Private
->ControllerHandle
,
551 if (EFI_ERROR (Status
)) {
553 "%a: SD/MMC post reset notifier callback failed - %r\n",
554 __FUNCTION__
, Status
));
562 Set all interrupt status bits in Normal and Error Interrupt Status Enable
565 @param[in] PciIo The PCI IO protocol instance.
566 @param[in] Slot The slot number of the SD card to send the command to.
568 @retval EFI_SUCCESS The operation executes successfully.
569 @retval Others The operation fails.
573 SdMmcHcEnableInterrupt (
574 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
582 // Enable all bits in Error Interrupt Status Enable Register
585 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_ERR_INT_STS_EN
, FALSE
, sizeof (IntStatus
), &IntStatus
);
586 if (EFI_ERROR (Status
)) {
590 // Enable all bits in Normal Interrupt Status Enable Register
593 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_NOR_INT_STS_EN
, FALSE
, sizeof (IntStatus
), &IntStatus
);
599 Get the capability data from the specified slot.
601 @param[in] PciIo The PCI IO protocol instance.
602 @param[in] Slot The slot number of the SD card to send the command to.
603 @param[out] Capability The buffer to store the capability data.
605 @retval EFI_SUCCESS The operation executes successfully.
606 @retval Others The operation fails.
610 SdMmcHcGetCapability (
611 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
613 OUT SD_MMC_HC_SLOT_CAP
*Capability
619 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_CAP
, TRUE
, sizeof (Cap
), &Cap
);
620 if (EFI_ERROR (Status
)) {
624 CopyMem (Capability
, &Cap
, sizeof (Cap
));
630 Get the maximum current capability data from the specified slot.
632 @param[in] PciIo The PCI IO protocol instance.
633 @param[in] Slot The slot number of the SD card to send the command to.
634 @param[out] MaxCurrent The buffer to store the maximum current capability data.
636 @retval EFI_SUCCESS The operation executes successfully.
637 @retval Others The operation fails.
641 SdMmcHcGetMaxCurrent (
642 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
644 OUT UINT64
*MaxCurrent
649 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_MAX_CURRENT_CAP
, TRUE
, sizeof (UINT64
), MaxCurrent
);
655 Detect whether there is a SD/MMC card attached at the specified SD/MMC host controller
658 Refer to SD Host Controller Simplified spec 3.0 Section 3.1 for details.
660 @param[in] PciIo The PCI IO protocol instance.
661 @param[in] Slot The slot number of the SD card to send the command to.
662 @param[out] MediaPresent The pointer to the media present boolean value.
664 @retval EFI_SUCCESS There is no media change happened.
665 @retval EFI_MEDIA_CHANGED There is media change happened.
666 @retval Others The detection fails.
671 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
673 OUT BOOLEAN
*MediaPresent
681 // Check Present State Register to see if there is a card presented.
683 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_PRESENT_STATE
, TRUE
, sizeof (PresentState
), &PresentState
);
684 if (EFI_ERROR (Status
)) {
688 if ((PresentState
& BIT16
) != 0) {
689 *MediaPresent
= TRUE
;
691 *MediaPresent
= FALSE
;
695 // Check Normal Interrupt Status Register
697 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_NOR_INT_STS
, TRUE
, sizeof (Data
), &Data
);
698 if (EFI_ERROR (Status
)) {
702 if ((Data
& (BIT6
| BIT7
)) != 0) {
704 // Clear BIT6 and BIT7 by writing 1 to these two bits if set.
707 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_NOR_INT_STS
, FALSE
, sizeof (Data
), &Data
);
708 if (EFI_ERROR (Status
)) {
712 return EFI_MEDIA_CHANGED
;
719 Stop SD/MMC card clock.
721 Refer to SD Host Controller Simplified spec 3.0 Section 3.2.2 for details.
723 @param[in] PciIo The PCI IO protocol instance.
724 @param[in] Slot The slot number of the SD card to send the command to.
726 @retval EFI_SUCCESS Succeed to stop SD/MMC clock.
727 @retval Others Fail to stop SD/MMC clock.
732 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
741 // Ensure no SD transactions are occurring on the SD Bus by
742 // waiting for Command Inhibit (DAT) and Command Inhibit (CMD)
743 // in the Present State register to be 0.
745 Status
= SdMmcHcWaitMmioSet (
748 SD_MMC_HC_PRESENT_STATE
,
749 sizeof (PresentState
),
752 SD_MMC_HC_GENERIC_TIMEOUT
754 if (EFI_ERROR (Status
)) {
759 // Set SD Clock Enable in the Clock Control register to 0
761 ClockCtrl
= (UINT16
)~BIT2
;
762 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_CLOCK_CTRL
, sizeof (ClockCtrl
), &ClockCtrl
);
768 SD/MMC card clock supply.
770 Refer to SD Host Controller Simplified spec 3.0 Section 3.2.1 for details.
772 @param[in] PciIo The PCI IO protocol instance.
773 @param[in] Slot The slot number of the SD card to send the command to.
774 @param[in] ClockFreq The max clock frequency to be set. The unit is KHz.
775 @param[in] BaseClkFreq The base clock frequency of host controller in MHz.
776 @param[in] ControllerVer The version of host controller.
778 @retval EFI_SUCCESS The clock is supplied successfully.
779 @retval Others The clock isn't supplied successfully.
784 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
787 IN UINT32 BaseClkFreq
,
788 IN UINT16 ControllerVer
798 // Calculate a divisor for SD clock frequency
800 ASSERT (BaseClkFreq
!= 0);
802 if (ClockFreq
== 0) {
803 return EFI_INVALID_PARAMETER
;
806 if (ClockFreq
> (BaseClkFreq
* 1000)) {
807 ClockFreq
= BaseClkFreq
* 1000;
811 // Calculate the divisor of base frequency.
814 SettingFreq
= BaseClkFreq
* 1000;
815 while (ClockFreq
< SettingFreq
) {
818 SettingFreq
= (BaseClkFreq
* 1000) / (2 * Divisor
);
819 Remainder
= (BaseClkFreq
* 1000) % (2 * Divisor
);
820 if ((ClockFreq
== SettingFreq
) && (Remainder
== 0)) {
823 if ((ClockFreq
== SettingFreq
) && (Remainder
!= 0)) {
828 DEBUG ((DEBUG_INFO
, "BaseClkFreq %dMHz Divisor %d ClockFreq %dKhz\n", BaseClkFreq
, Divisor
, ClockFreq
));
831 // Set SDCLK Frequency Select and Internal Clock Enable fields in Clock Control register.
833 if ((ControllerVer
>= SD_MMC_HC_CTRL_VER_300
) &&
834 (ControllerVer
<= SD_MMC_HC_CTRL_VER_420
)) {
835 ASSERT (Divisor
<= 0x3FF);
836 ClockCtrl
= ((Divisor
& 0xFF) << 8) | ((Divisor
& 0x300) >> 2);
837 } else if ((ControllerVer
== SD_MMC_HC_CTRL_VER_100
) ||
838 (ControllerVer
== SD_MMC_HC_CTRL_VER_200
)) {
840 // Only the most significant bit can be used as divisor.
842 if (((Divisor
- 1) & Divisor
) != 0) {
843 Divisor
= 1 << (HighBitSet32 (Divisor
) + 1);
845 ASSERT (Divisor
<= 0x80);
846 ClockCtrl
= (Divisor
& 0xFF) << 8;
848 DEBUG ((DEBUG_ERROR
, "Unknown SD Host Controller Spec version [0x%x]!!!\n", ControllerVer
));
849 return EFI_UNSUPPORTED
;
853 // Stop bus clock at first
855 Status
= SdMmcHcStopClock (PciIo
, Slot
);
856 if (EFI_ERROR (Status
)) {
861 // Supply clock frequency with specified divisor
864 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_CLOCK_CTRL
, FALSE
, sizeof (ClockCtrl
), &ClockCtrl
);
865 if (EFI_ERROR (Status
)) {
866 DEBUG ((DEBUG_ERROR
, "Set SDCLK Frequency Select and Internal Clock Enable fields fails\n"));
871 // Wait Internal Clock Stable in the Clock Control register to be 1
873 Status
= SdMmcHcWaitMmioSet (
876 SD_MMC_HC_CLOCK_CTRL
,
880 SD_MMC_HC_GENERIC_TIMEOUT
882 if (EFI_ERROR (Status
)) {
887 // Set SD Clock Enable in the Clock Control register to 1
890 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_CLOCK_CTRL
, sizeof (ClockCtrl
), &ClockCtrl
);
896 SD/MMC bus power control.
898 Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details.
900 @param[in] PciIo The PCI IO protocol instance.
901 @param[in] Slot The slot number of the SD card to send the command to.
902 @param[in] PowerCtrl The value setting to the power control register.
904 @retval TRUE There is a SD/MMC card attached.
905 @retval FALSE There is no a SD/MMC card attached.
909 SdMmcHcPowerControl (
910 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
920 PowerCtrl
&= (UINT8
)~BIT0
;
921 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_POWER_CTRL
, FALSE
, sizeof (PowerCtrl
), &PowerCtrl
);
922 if (EFI_ERROR (Status
)) {
927 // Set SD Bus Voltage Select and SD Bus Power fields in Power Control Register
930 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_POWER_CTRL
, FALSE
, sizeof (PowerCtrl
), &PowerCtrl
);
936 Set the SD/MMC bus width.
938 Refer to SD Host Controller Simplified spec 3.0 Section 3.4 for details.
940 @param[in] PciIo The PCI IO protocol instance.
941 @param[in] Slot The slot number of the SD card to send the command to.
942 @param[in] BusWidth The bus width used by the SD/MMC device, it must be 1, 4 or 8.
944 @retval EFI_SUCCESS The bus width is set successfully.
945 @retval Others The bus width isn't set successfully.
950 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
959 HostCtrl1
= (UINT8
)~(BIT5
| BIT1
);
960 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
961 } else if (BusWidth
== 4) {
962 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, TRUE
, sizeof (HostCtrl1
), &HostCtrl1
);
963 if (EFI_ERROR (Status
)) {
967 HostCtrl1
&= (UINT8
)~BIT5
;
968 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, FALSE
, sizeof (HostCtrl1
), &HostCtrl1
);
969 } else if (BusWidth
== 8) {
970 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, TRUE
, sizeof (HostCtrl1
), &HostCtrl1
);
971 if (EFI_ERROR (Status
)) {
974 HostCtrl1
&= (UINT8
)~BIT1
;
976 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, FALSE
, sizeof (HostCtrl1
), &HostCtrl1
);
979 return EFI_INVALID_PARAMETER
;
986 Configure V4 controller enhancements at initialization.
988 @param[in] PciIo The PCI IO protocol instance.
989 @param[in] Slot The slot number of the SD card to send the command to.
990 @param[in] Capability The capability of the slot.
991 @param[in] ControllerVer The version of host controller.
993 @retval EFI_SUCCESS The clock is supplied successfully.
997 SdMmcHcInitV4Enhancements (
998 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1000 IN SD_MMC_HC_SLOT_CAP Capability
,
1001 IN UINT16 ControllerVer
1008 // Check if controller version V4 or higher
1010 if (ControllerVer
>= SD_MMC_HC_CTRL_VER_400
) {
1011 HostCtrl2
= SD_MMC_HC_V4_EN
;
1013 // Check if controller version V4.0
1015 if (ControllerVer
== SD_MMC_HC_CTRL_VER_400
) {
1017 // Check if 64bit support is available
1019 if (Capability
.SysBus64V3
!= 0) {
1020 HostCtrl2
|= SD_MMC_HC_64_ADDR_EN
;
1021 DEBUG ((DEBUG_INFO
, "Enabled V4 64 bit system bus support\n"));
1025 // Check if controller version V4.10 or higher
1027 else if (ControllerVer
>= SD_MMC_HC_CTRL_VER_410
) {
1029 // Check if 64bit support is available
1031 if (Capability
.SysBus64V4
!= 0) {
1032 HostCtrl2
|= SD_MMC_HC_64_ADDR_EN
;
1033 DEBUG ((DEBUG_INFO
, "Enabled V4 64 bit system bus support\n"));
1035 HostCtrl2
|= SD_MMC_HC_26_DATA_LEN_ADMA_EN
;
1036 DEBUG ((DEBUG_INFO
, "Enabled V4 26 bit data length ADMA support\n"));
1038 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1039 if (EFI_ERROR (Status
)) {
1048 Supply SD/MMC card with lowest clock frequency at initialization.
1050 @param[in] PciIo The PCI IO protocol instance.
1051 @param[in] Slot The slot number of the SD card to send the command to.
1052 @param[in] BaseClkFreq The base clock frequency of host controller in MHz.
1053 @param[in] ControllerVer The version of host controller.
1055 @retval EFI_SUCCESS The clock is supplied successfully.
1056 @retval Others The clock isn't supplied successfully.
1060 SdMmcHcInitClockFreq (
1061 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1063 IN UINT32 BaseClkFreq
,
1064 IN UINT16 ControllerVer
1071 // According to SDHCI specification ver. 4.2, BaseClkFreq field value of
1072 // the Capability Register 1 can be zero, which means a need for obtaining
1073 // the clock frequency via another method. Fail in case it is not updated
1074 // by SW at this point.
1076 if (BaseClkFreq
== 0) {
1078 // Don't support get Base Clock Frequency information via another method
1080 return EFI_UNSUPPORTED
;
1083 // Supply 400KHz clock frequency at initialization phase.
1086 Status
= SdMmcHcClockSupply (PciIo
, Slot
, InitFreq
, BaseClkFreq
, ControllerVer
);
1091 Supply SD/MMC card with maximum voltage at initialization.
1093 Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details.
1095 @param[in] PciIo The PCI IO protocol instance.
1096 @param[in] Slot The slot number of the SD card to send the command to.
1097 @param[in] Capability The capability of the slot.
1099 @retval EFI_SUCCESS The voltage is supplied successfully.
1100 @retval Others The voltage isn't supplied successfully.
1104 SdMmcHcInitPowerVoltage (
1105 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1107 IN SD_MMC_HC_SLOT_CAP Capability
1115 // Calculate supported maximum voltage according to SD Bus Voltage Select
1117 if (Capability
.Voltage33
!= 0) {
1122 } else if (Capability
.Voltage30
!= 0) {
1127 } else if (Capability
.Voltage18
!= 0) {
1133 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1135 if (EFI_ERROR (Status
)) {
1140 return EFI_DEVICE_ERROR
;
1144 // Set SD Bus Voltage Select and SD Bus Power fields in Power Control Register
1146 Status
= SdMmcHcPowerControl (PciIo
, Slot
, MaxVoltage
);
1152 Initialize the Timeout Control register with most conservative value at initialization.
1154 Refer to SD Host Controller Simplified spec 3.0 Section 2.2.15 for details.
1156 @param[in] PciIo The PCI IO protocol instance.
1157 @param[in] Slot The slot number of the SD card to send the command to.
1159 @retval EFI_SUCCESS The timeout control register is configured successfully.
1160 @retval Others The timeout control register isn't configured successfully.
1164 SdMmcHcInitTimeoutCtrl (
1165 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1173 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_TIMEOUT_CTRL
, FALSE
, sizeof (Timeout
), &Timeout
);
1179 Initial SD/MMC host controller with lowest clock frequency, max power and max timeout value
1182 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1183 @param[in] Slot The slot number of the SD card to send the command to.
1185 @retval EFI_SUCCESS The host controller is initialized successfully.
1186 @retval Others The host controller isn't initialized successfully.
1191 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1196 EFI_PCI_IO_PROTOCOL
*PciIo
;
1197 SD_MMC_HC_SLOT_CAP Capability
;
1200 // Notify the SD/MMC override protocol that we are about to initialize
1201 // the SD/MMC host controller.
1203 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
1204 Status
= mOverride
->NotifyPhase (
1205 Private
->ControllerHandle
,
1207 EdkiiSdMmcInitHostPre
,
1209 if (EFI_ERROR (Status
)) {
1211 "%a: SD/MMC pre init notifier callback failed - %r\n",
1212 __FUNCTION__
, Status
));
1217 PciIo
= Private
->PciIo
;
1218 Capability
= Private
->Capability
[Slot
];
1220 Status
= SdMmcHcInitV4Enhancements (PciIo
, Slot
, Capability
, Private
->ControllerVersion
[Slot
]);
1221 if (EFI_ERROR (Status
)) {
1225 Status
= SdMmcHcInitClockFreq (PciIo
, Slot
, Private
->BaseClkFreq
[Slot
], Private
->ControllerVersion
[Slot
]);
1226 if (EFI_ERROR (Status
)) {
1230 Status
= SdMmcHcInitPowerVoltage (PciIo
, Slot
, Capability
);
1231 if (EFI_ERROR (Status
)) {
1235 Status
= SdMmcHcInitTimeoutCtrl (PciIo
, Slot
);
1236 if (EFI_ERROR (Status
)) {
1241 // Notify the SD/MMC override protocol that we are have just initialized
1242 // the SD/MMC host controller.
1244 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
1245 Status
= mOverride
->NotifyPhase (
1246 Private
->ControllerHandle
,
1248 EdkiiSdMmcInitHostPost
,
1250 if (EFI_ERROR (Status
)) {
1252 "%a: SD/MMC post init notifier callback failed - %r\n",
1253 __FUNCTION__
, Status
));
1260 Set SD Host Controler control 2 registry according to selected speed.
1262 @param[in] ControllerHandle The handle of the controller.
1263 @param[in] PciIo The PCI IO protocol instance.
1264 @param[in] Slot The slot number of the SD card to send the command to.
1265 @param[in] Timing The timing to select.
1267 @retval EFI_SUCCESS The timing is set successfully.
1268 @retval Others The timing isn't set successfully.
1271 SdMmcHcUhsSignaling (
1272 IN EFI_HANDLE ControllerHandle
,
1273 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1275 IN SD_MMC_BUS_MODE Timing
1281 HostCtrl2
= (UINT8
)~SD_MMC_HC_CTRL_UHS_MASK
;
1282 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1283 if (EFI_ERROR (Status
)) {
1289 HostCtrl2
= SD_MMC_HC_CTRL_UHS_SDR12
;
1292 HostCtrl2
= SD_MMC_HC_CTRL_UHS_SDR25
;
1295 HostCtrl2
= SD_MMC_HC_CTRL_UHS_SDR50
;
1297 case SdMmcUhsSdr104
:
1298 HostCtrl2
= SD_MMC_HC_CTRL_UHS_SDR104
;
1301 HostCtrl2
= SD_MMC_HC_CTRL_UHS_DDR50
;
1303 case SdMmcMmcLegacy
:
1304 HostCtrl2
= SD_MMC_HC_CTRL_MMC_LEGACY
;
1307 HostCtrl2
= SD_MMC_HC_CTRL_MMC_HS_SDR
;
1310 HostCtrl2
= SD_MMC_HC_CTRL_MMC_HS_DDR
;
1313 HostCtrl2
= SD_MMC_HC_CTRL_MMC_HS200
;
1316 HostCtrl2
= SD_MMC_HC_CTRL_MMC_HS400
;
1322 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1323 if (EFI_ERROR (Status
)) {
1327 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
1328 Status
= mOverride
->NotifyPhase (
1331 EdkiiSdMmcUhsSignaling
,
1334 if (EFI_ERROR (Status
)) {
1337 "%a: SD/MMC uhs signaling notifier callback failed - %r\n",
1351 @param[in] PciIo The PCI IO protocol instance.
1352 @param[in] Slot The slot number of the SD card to send the command to.
1353 @param[in] On The boolean to turn on/off LED.
1355 @retval EFI_SUCCESS The LED is turned on/off successfully.
1356 @retval Others The LED isn't turned on/off successfully.
1361 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1371 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
1373 HostCtrl1
= (UINT8
)~BIT0
;
1374 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
1381 Build ADMA descriptor table for transfer.
1383 Refer to SD Host Controller Simplified spec 4.2 Section 1.13 for details.
1385 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1386 @param[in] ControllerVer The version of host controller.
1388 @retval EFI_SUCCESS The ADMA descriptor table is created successfully.
1389 @retval Others The ADMA descriptor table isn't created successfully.
1393 BuildAdmaDescTable (
1394 IN SD_MMC_HC_TRB
*Trb
,
1395 IN UINT16 ControllerVer
1398 EFI_PHYSICAL_ADDRESS Data
;
1405 EFI_PCI_IO_PROTOCOL
*PciIo
;
1408 UINT32 AdmaMaxDataPerLine
;
1412 AdmaMaxDataPerLine
= ADMA_MAX_DATA_PER_LINE_16B
;
1413 DescSize
= sizeof (SD_MMC_HC_ADMA_32_DESC_LINE
);
1416 Data
= Trb
->DataPhy
;
1417 DataLen
= Trb
->DataLen
;
1418 PciIo
= Trb
->Private
->PciIo
;
1421 // Check for valid ranges in 32bit ADMA Descriptor Table
1423 if ((Trb
->Mode
== SdMmcAdma32bMode
) &&
1424 ((Data
>= 0x100000000ul
) || ((Data
+ DataLen
) > 0x100000000ul
))) {
1425 return EFI_INVALID_PARAMETER
;
1428 // Check address field alignment
1430 if (Trb
->Mode
!= SdMmcAdma32bMode
) {
1432 // Address field shall be set on 64-bit boundary (Lower 3-bit is always set to 0)
1434 if ((Data
& (BIT0
| BIT1
| BIT2
)) != 0) {
1435 DEBUG ((DEBUG_INFO
, "The buffer [0x%x] to construct ADMA desc is not aligned to 8 bytes boundary!\n", Data
));
1439 // Address field shall be set on 32-bit boundary (Lower 2-bit is always set to 0)
1441 if ((Data
& (BIT0
| BIT1
)) != 0) {
1442 DEBUG ((DEBUG_INFO
, "The buffer [0x%x] to construct ADMA desc is not aligned to 4 bytes boundary!\n", Data
));
1447 // Configure 64b ADMA.
1449 if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1450 DescSize
= sizeof (SD_MMC_HC_ADMA_64_V3_DESC_LINE
);
1451 }else if (Trb
->Mode
== SdMmcAdma64bV4Mode
) {
1452 DescSize
= sizeof (SD_MMC_HC_ADMA_64_V4_DESC_LINE
);
1455 // Configure 26b data length.
1457 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1458 AdmaMaxDataPerLine
= ADMA_MAX_DATA_PER_LINE_26B
;
1461 Entries
= DivU64x32 ((DataLen
+ AdmaMaxDataPerLine
- 1), AdmaMaxDataPerLine
);
1462 TableSize
= (UINTN
)MultU64x32 (Entries
, DescSize
);
1463 Trb
->AdmaPages
= (UINT32
)EFI_SIZE_TO_PAGES (TableSize
);
1464 Status
= PciIo
->AllocateBuffer (
1467 EfiBootServicesData
,
1468 EFI_SIZE_TO_PAGES (TableSize
),
1472 if (EFI_ERROR (Status
)) {
1473 return EFI_OUT_OF_RESOURCES
;
1475 ZeroMem (AdmaDesc
, TableSize
);
1477 Status
= PciIo
->Map (
1479 EfiPciIoOperationBusMasterCommonBuffer
,
1486 if (EFI_ERROR (Status
) || (Bytes
!= TableSize
)) {
1488 // Map error or unable to map the whole RFis buffer into a contiguous region.
1492 EFI_SIZE_TO_PAGES (TableSize
),
1495 return EFI_OUT_OF_RESOURCES
;
1498 if ((Trb
->Mode
== SdMmcAdma32bMode
) &&
1499 (UINT64
)(UINTN
)Trb
->AdmaDescPhy
> 0x100000000ul
) {
1501 // The ADMA doesn't support 64bit addressing.
1509 EFI_SIZE_TO_PAGES (TableSize
),
1512 return EFI_DEVICE_ERROR
;
1515 Remaining
= DataLen
;
1517 if (Trb
->Mode
== SdMmcAdma32bMode
) {
1518 Trb
->Adma32Desc
= AdmaDesc
;
1519 } else if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1520 Trb
->Adma64V3Desc
= AdmaDesc
;
1522 Trb
->Adma64V4Desc
= AdmaDesc
;
1525 for (Index
= 0; Index
< Entries
; Index
++) {
1526 if (Trb
->Mode
== SdMmcAdma32bMode
) {
1527 if (Remaining
<= AdmaMaxDataPerLine
) {
1528 Trb
->Adma32Desc
[Index
].Valid
= 1;
1529 Trb
->Adma32Desc
[Index
].Act
= 2;
1530 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1531 Trb
->Adma32Desc
[Index
].UpperLength
= (UINT16
)RShiftU64 (Remaining
, 16);
1533 Trb
->Adma32Desc
[Index
].LowerLength
= (UINT16
)(Remaining
& MAX_UINT16
);
1534 Trb
->Adma32Desc
[Index
].Address
= (UINT32
)Address
;
1537 Trb
->Adma32Desc
[Index
].Valid
= 1;
1538 Trb
->Adma32Desc
[Index
].Act
= 2;
1539 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1540 Trb
->Adma32Desc
[Index
].UpperLength
= 0;
1542 Trb
->Adma32Desc
[Index
].LowerLength
= 0;
1543 Trb
->Adma32Desc
[Index
].Address
= (UINT32
)Address
;
1545 } else if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1546 if (Remaining
<= AdmaMaxDataPerLine
) {
1547 Trb
->Adma64V3Desc
[Index
].Valid
= 1;
1548 Trb
->Adma64V3Desc
[Index
].Act
= 2;
1549 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1550 Trb
->Adma64V3Desc
[Index
].UpperLength
= (UINT16
)RShiftU64 (Remaining
, 16);
1552 Trb
->Adma64V3Desc
[Index
].LowerLength
= (UINT16
)(Remaining
& MAX_UINT16
);
1553 Trb
->Adma64V3Desc
[Index
].LowerAddress
= (UINT32
)Address
;
1554 Trb
->Adma64V3Desc
[Index
].UpperAddress
= (UINT32
)RShiftU64 (Address
, 32);
1557 Trb
->Adma64V3Desc
[Index
].Valid
= 1;
1558 Trb
->Adma64V3Desc
[Index
].Act
= 2;
1559 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1560 Trb
->Adma64V3Desc
[Index
].UpperLength
= 0;
1562 Trb
->Adma64V3Desc
[Index
].LowerLength
= 0;
1563 Trb
->Adma64V3Desc
[Index
].LowerAddress
= (UINT32
)Address
;
1564 Trb
->Adma64V3Desc
[Index
].UpperAddress
= (UINT32
)RShiftU64 (Address
, 32);
1567 if (Remaining
<= AdmaMaxDataPerLine
) {
1568 Trb
->Adma64V4Desc
[Index
].Valid
= 1;
1569 Trb
->Adma64V4Desc
[Index
].Act
= 2;
1570 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1571 Trb
->Adma64V4Desc
[Index
].UpperLength
= (UINT16
)RShiftU64 (Remaining
, 16);
1573 Trb
->Adma64V4Desc
[Index
].LowerLength
= (UINT16
)(Remaining
& MAX_UINT16
);
1574 Trb
->Adma64V4Desc
[Index
].LowerAddress
= (UINT32
)Address
;
1575 Trb
->Adma64V4Desc
[Index
].UpperAddress
= (UINT32
)RShiftU64 (Address
, 32);
1578 Trb
->Adma64V4Desc
[Index
].Valid
= 1;
1579 Trb
->Adma64V4Desc
[Index
].Act
= 2;
1580 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1581 Trb
->Adma64V4Desc
[Index
].UpperLength
= 0;
1583 Trb
->Adma64V4Desc
[Index
].LowerLength
= 0;
1584 Trb
->Adma64V4Desc
[Index
].LowerAddress
= (UINT32
)Address
;
1585 Trb
->Adma64V4Desc
[Index
].UpperAddress
= (UINT32
)RShiftU64 (Address
, 32);
1589 Remaining
-= AdmaMaxDataPerLine
;
1590 Address
+= AdmaMaxDataPerLine
;
1594 // Set the last descriptor line as end of descriptor table
1596 if (Trb
->Mode
== SdMmcAdma32bMode
) {
1597 Trb
->Adma32Desc
[Index
].End
= 1;
1598 } else if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1599 Trb
->Adma64V3Desc
[Index
].End
= 1;
1601 Trb
->Adma64V4Desc
[Index
].End
= 1;
1607 Create a new TRB for the SD/MMC cmd request.
1609 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1610 @param[in] Slot The slot number of the SD card to send the command to.
1611 @param[in] Packet A pointer to the SD command data structure.
1612 @param[in] Event If Event is NULL, blocking I/O is performed. If Event is
1613 not NULL, then nonblocking I/O is performed, and Event
1614 will be signaled when the Packet completes.
1616 @return Created Trb or NULL.
1621 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1623 IN EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
,
1630 EFI_PCI_IO_PROTOCOL_OPERATION Flag
;
1631 EFI_PCI_IO_PROTOCOL
*PciIo
;
1634 Trb
= AllocateZeroPool (sizeof (SD_MMC_HC_TRB
));
1639 Trb
->Signature
= SD_MMC_HC_TRB_SIG
;
1641 Trb
->BlockSize
= 0x200;
1642 Trb
->Packet
= Packet
;
1644 Trb
->Started
= FALSE
;
1645 Trb
->Timeout
= Packet
->Timeout
;
1646 Trb
->Private
= Private
;
1648 if ((Packet
->InTransferLength
!= 0) && (Packet
->InDataBuffer
!= NULL
)) {
1649 Trb
->Data
= Packet
->InDataBuffer
;
1650 Trb
->DataLen
= Packet
->InTransferLength
;
1652 } else if ((Packet
->OutTransferLength
!= 0) && (Packet
->OutDataBuffer
!= NULL
)) {
1653 Trb
->Data
= Packet
->OutDataBuffer
;
1654 Trb
->DataLen
= Packet
->OutTransferLength
;
1656 } else if ((Packet
->InTransferLength
== 0) && (Packet
->OutTransferLength
== 0)) {
1663 if ((Trb
->DataLen
!= 0) && (Trb
->DataLen
< Trb
->BlockSize
)) {
1664 Trb
->BlockSize
= (UINT16
)Trb
->DataLen
;
1667 if (((Private
->Slot
[Trb
->Slot
].CardType
== EmmcCardType
) &&
1668 (Packet
->SdMmcCmdBlk
->CommandIndex
== EMMC_SEND_TUNING_BLOCK
)) ||
1669 ((Private
->Slot
[Trb
->Slot
].CardType
== SdCardType
) &&
1670 (Packet
->SdMmcCmdBlk
->CommandIndex
== SD_SEND_TUNING_BLOCK
))) {
1671 Trb
->Mode
= SdMmcPioMode
;
1674 Flag
= EfiPciIoOperationBusMasterWrite
;
1676 Flag
= EfiPciIoOperationBusMasterRead
;
1679 PciIo
= Private
->PciIo
;
1680 if (Trb
->DataLen
!= 0) {
1681 MapLength
= Trb
->DataLen
;
1682 Status
= PciIo
->Map (
1690 if (EFI_ERROR (Status
) || (Trb
->DataLen
!= MapLength
)) {
1691 Status
= EFI_BAD_BUFFER_SIZE
;
1696 if (Trb
->DataLen
== 0) {
1697 Trb
->Mode
= SdMmcNoData
;
1698 } else if (Private
->Capability
[Slot
].Adma2
!= 0) {
1699 Trb
->Mode
= SdMmcAdma32bMode
;
1700 Trb
->AdmaLengthMode
= SdMmcAdmaLen16b
;
1701 if ((Private
->ControllerVersion
[Slot
] == SD_MMC_HC_CTRL_VER_300
) &&
1702 (Private
->Capability
[Slot
].SysBus64V3
== 1)) {
1703 Trb
->Mode
= SdMmcAdma64bV3Mode
;
1704 } else if (((Private
->ControllerVersion
[Slot
] == SD_MMC_HC_CTRL_VER_400
) &&
1705 (Private
->Capability
[Slot
].SysBus64V3
== 1)) ||
1706 ((Private
->ControllerVersion
[Slot
] >= SD_MMC_HC_CTRL_VER_410
) &&
1707 (Private
->Capability
[Slot
].SysBus64V4
== 1))) {
1708 Trb
->Mode
= SdMmcAdma64bV4Mode
;
1710 if (Private
->ControllerVersion
[Slot
] >= SD_MMC_HC_CTRL_VER_410
) {
1711 Trb
->AdmaLengthMode
= SdMmcAdmaLen26b
;
1713 Status
= BuildAdmaDescTable (Trb
, Private
->ControllerVersion
[Slot
]);
1714 if (EFI_ERROR (Status
)) {
1715 PciIo
->Unmap (PciIo
, Trb
->DataMap
);
1718 } else if (Private
->Capability
[Slot
].Sdma
!= 0) {
1719 Trb
->Mode
= SdMmcSdmaMode
;
1721 Trb
->Mode
= SdMmcPioMode
;
1725 if (Event
!= NULL
) {
1726 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1727 InsertTailList (&Private
->Queue
, &Trb
->TrbList
);
1728 gBS
->RestoreTPL (OldTpl
);
1739 Free the resource used by the TRB.
1741 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1746 IN SD_MMC_HC_TRB
*Trb
1749 EFI_PCI_IO_PROTOCOL
*PciIo
;
1751 PciIo
= Trb
->Private
->PciIo
;
1753 if (Trb
->AdmaMap
!= NULL
) {
1759 if (Trb
->Adma32Desc
!= NULL
) {
1766 if (Trb
->Adma64V3Desc
!= NULL
) {
1773 if (Trb
->Adma64V4Desc
!= NULL
) {
1780 if (Trb
->DataMap
!= NULL
) {
1791 Check if the env is ready for execute specified TRB.
1793 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1794 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1796 @retval EFI_SUCCESS The env is ready for TRB execution.
1797 @retval EFI_NOT_READY The env is not ready for TRB execution.
1798 @retval Others Some erros happen.
1803 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1804 IN SD_MMC_HC_TRB
*Trb
1808 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
1809 EFI_PCI_IO_PROTOCOL
*PciIo
;
1810 UINT32 PresentState
;
1812 Packet
= Trb
->Packet
;
1814 if ((Packet
->SdMmcCmdBlk
->CommandType
== SdMmcCommandTypeAdtc
) ||
1815 (Packet
->SdMmcCmdBlk
->ResponseType
== SdMmcResponseTypeR1b
) ||
1816 (Packet
->SdMmcCmdBlk
->ResponseType
== SdMmcResponseTypeR5b
)) {
1818 // Wait Command Inhibit (CMD) and Command Inhibit (DAT) in
1819 // the Present State register to be 0
1821 PresentState
= BIT0
| BIT1
;
1824 // Wait Command Inhibit (CMD) in the Present State register
1827 PresentState
= BIT0
;
1830 PciIo
= Private
->PciIo
;
1831 Status
= SdMmcHcCheckMmioSet (
1834 SD_MMC_HC_PRESENT_STATE
,
1835 sizeof (PresentState
),
1844 Wait for the env to be ready for execute specified TRB.
1846 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1847 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1849 @retval EFI_SUCCESS The env is ready for TRB execution.
1850 @retval EFI_TIMEOUT The env is not ready for TRB execution in time.
1851 @retval Others Some erros happen.
1856 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1857 IN SD_MMC_HC_TRB
*Trb
1861 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
1863 BOOLEAN InfiniteWait
;
1866 // Wait Command Complete Interrupt Status bit in Normal Interrupt Status Register
1868 Packet
= Trb
->Packet
;
1869 Timeout
= Packet
->Timeout
;
1871 InfiniteWait
= TRUE
;
1873 InfiniteWait
= FALSE
;
1876 while (InfiniteWait
|| (Timeout
> 0)) {
1878 // Check Trb execution result by reading Normal Interrupt Status register.
1880 Status
= SdMmcCheckTrbEnv (Private
, Trb
);
1881 if (Status
!= EFI_NOT_READY
) {
1885 // Stall for 1 microsecond.
1896 Execute the specified TRB.
1898 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1899 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1901 @retval EFI_SUCCESS The TRB is sent to host controller successfully.
1902 @retval Others Some erros happen when sending this request to the host controller.
1907 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1908 IN SD_MMC_HC_TRB
*Trb
1912 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
1913 EFI_PCI_IO_PROTOCOL
*PciIo
;
1923 BOOLEAN AddressingMode64
;
1925 AddressingMode64
= FALSE
;
1927 Packet
= Trb
->Packet
;
1928 PciIo
= Trb
->Private
->PciIo
;
1930 // Clear all bits in Error Interrupt Status Register
1933 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_ERR_INT_STS
, FALSE
, sizeof (IntStatus
), &IntStatus
);
1934 if (EFI_ERROR (Status
)) {
1938 // Clear all bits in Normal Interrupt Status Register excepts for Card Removal & Card Insertion bits.
1941 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_NOR_INT_STS
, FALSE
, sizeof (IntStatus
), &IntStatus
);
1942 if (EFI_ERROR (Status
)) {
1946 if (Private
->ControllerVersion
[Trb
->Slot
] >= SD_MMC_HC_CTRL_VER_400
) {
1947 Status
= SdMmcHcCheckMmioSet(PciIo
, Trb
->Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof(UINT16
),
1948 SD_MMC_HC_64_ADDR_EN
, SD_MMC_HC_64_ADDR_EN
);
1949 if (!EFI_ERROR (Status
)) {
1950 AddressingMode64
= TRUE
;
1955 // Set Host Control 1 register DMA Select field
1957 if ((Trb
->Mode
== SdMmcAdma32bMode
) ||
1958 (Trb
->Mode
== SdMmcAdma64bV4Mode
)) {
1960 Status
= SdMmcHcOrMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
1961 if (EFI_ERROR (Status
)) {
1964 } else if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1965 HostCtrl1
= BIT4
|BIT3
;
1966 Status
= SdMmcHcOrMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
1967 if (EFI_ERROR (Status
)) {
1972 SdMmcHcLedOnOff (PciIo
, Trb
->Slot
, TRUE
);
1974 if (Trb
->Mode
== SdMmcSdmaMode
) {
1975 if ((!AddressingMode64
) &&
1976 ((UINT64
)(UINTN
)Trb
->DataPhy
>= 0x100000000ul
)) {
1977 return EFI_INVALID_PARAMETER
;
1980 SdmaAddr
= (UINT64
)(UINTN
)Trb
->DataPhy
;
1982 if (Private
->ControllerVersion
[Trb
->Slot
] >= SD_MMC_HC_CTRL_VER_400
) {
1983 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_ADMA_SYS_ADDR
, FALSE
, sizeof (UINT64
), &SdmaAddr
);
1985 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_SDMA_ADDR
, FALSE
, sizeof (UINT32
), &SdmaAddr
);
1988 if (EFI_ERROR (Status
)) {
1991 } else if ((Trb
->Mode
== SdMmcAdma32bMode
) ||
1992 (Trb
->Mode
== SdMmcAdma64bV3Mode
) ||
1993 (Trb
->Mode
== SdMmcAdma64bV4Mode
)) {
1994 AdmaAddr
= (UINT64
)(UINTN
)Trb
->AdmaDescPhy
;
1995 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_ADMA_SYS_ADDR
, FALSE
, sizeof (AdmaAddr
), &AdmaAddr
);
1996 if (EFI_ERROR (Status
)) {
2001 BlkSize
= Trb
->BlockSize
;
2002 if (Trb
->Mode
== SdMmcSdmaMode
) {
2004 // Set SDMA boundary to be 512K bytes.
2009 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_BLK_SIZE
, FALSE
, sizeof (BlkSize
), &BlkSize
);
2010 if (EFI_ERROR (Status
)) {
2015 if (Trb
->Mode
!= SdMmcNoData
) {
2017 // Calcuate Block Count.
2019 BlkCount
= (Trb
->DataLen
/ Trb
->BlockSize
);
2021 if (Private
->ControllerVersion
[Trb
->Slot
] >= SD_MMC_HC_CTRL_VER_410
) {
2022 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_SDMA_ADDR
, FALSE
, sizeof (UINT32
), &BlkCount
);
2024 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_BLK_COUNT
, FALSE
, sizeof (UINT16
), &BlkCount
);
2026 if (EFI_ERROR (Status
)) {
2030 Argument
= Packet
->SdMmcCmdBlk
->CommandArgument
;
2031 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_ARG1
, FALSE
, sizeof (Argument
), &Argument
);
2032 if (EFI_ERROR (Status
)) {
2037 if (Trb
->Mode
!= SdMmcNoData
) {
2038 if (Trb
->Mode
!= SdMmcPioMode
) {
2045 TransMode
|= BIT5
| BIT1
;
2048 // Only SD memory card needs to use AUTO CMD12 feature.
2050 if (Private
->Slot
[Trb
->Slot
].CardType
== SdCardType
) {
2057 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_TRANS_MOD
, FALSE
, sizeof (TransMode
), &TransMode
);
2058 if (EFI_ERROR (Status
)) {
2062 Cmd
= (UINT16
)LShiftU64(Packet
->SdMmcCmdBlk
->CommandIndex
, 8);
2063 if (Packet
->SdMmcCmdBlk
->CommandType
== SdMmcCommandTypeAdtc
) {
2067 // Convert ResponseType to value
2069 if (Packet
->SdMmcCmdBlk
->CommandType
!= SdMmcCommandTypeBc
) {
2070 switch (Packet
->SdMmcCmdBlk
->ResponseType
) {
2071 case SdMmcResponseTypeR1
:
2072 case SdMmcResponseTypeR5
:
2073 case SdMmcResponseTypeR6
:
2074 case SdMmcResponseTypeR7
:
2075 Cmd
|= (BIT1
| BIT3
| BIT4
);
2077 case SdMmcResponseTypeR2
:
2078 Cmd
|= (BIT0
| BIT3
);
2080 case SdMmcResponseTypeR3
:
2081 case SdMmcResponseTypeR4
:
2084 case SdMmcResponseTypeR1b
:
2085 case SdMmcResponseTypeR5b
:
2086 Cmd
|= (BIT0
| BIT1
| BIT3
| BIT4
);
2096 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_COMMAND
, FALSE
, sizeof (Cmd
), &Cmd
);
2101 Check the TRB execution result.
2103 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
2104 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
2106 @retval EFI_SUCCESS The TRB is executed successfully.
2107 @retval EFI_NOT_READY The TRB is not completed for execution.
2108 @retval Others Some erros happen when executing this request.
2112 SdMmcCheckTrbResult (
2113 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
2114 IN SD_MMC_HC_TRB
*Trb
2118 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
2127 Packet
= Trb
->Packet
;
2129 // Check Trb execution result by reading Normal Interrupt Status register.
2131 Status
= SdMmcHcRwMmio (
2134 SD_MMC_HC_NOR_INT_STS
,
2139 if (EFI_ERROR (Status
)) {
2143 // Check Transfer Complete bit is set or not.
2145 if ((IntStatus
& BIT1
) == BIT1
) {
2146 if ((IntStatus
& BIT15
) == BIT15
) {
2148 // Read Error Interrupt Status register to check if the error is
2149 // Data Timeout Error.
2150 // If yes, treat it as success as Transfer Complete has higher
2151 // priority than Data Timeout Error.
2153 Status
= SdMmcHcRwMmio (
2156 SD_MMC_HC_ERR_INT_STS
,
2161 if (!EFI_ERROR (Status
)) {
2162 if ((IntStatus
& BIT4
) == BIT4
) {
2163 Status
= EFI_SUCCESS
;
2165 Status
= EFI_DEVICE_ERROR
;
2173 // Check if there is a error happened during cmd execution.
2174 // If yes, then do error recovery procedure to follow SD Host Controller
2175 // Simplified Spec 3.0 section 3.10.1.
2177 if ((IntStatus
& BIT15
) == BIT15
) {
2178 Status
= SdMmcHcRwMmio (
2181 SD_MMC_HC_ERR_INT_STS
,
2186 if (EFI_ERROR (Status
)) {
2189 if ((IntStatus
& 0x0F) != 0) {
2192 if ((IntStatus
& 0xF0) != 0) {
2196 Status
= SdMmcHcRwMmio (
2204 if (EFI_ERROR (Status
)) {
2207 Status
= SdMmcHcWaitMmioSet (
2214 SD_MMC_HC_GENERIC_TIMEOUT
2216 if (EFI_ERROR (Status
)) {
2220 Status
= EFI_DEVICE_ERROR
;
2224 // Check if DMA interrupt is signalled for the SDMA transfer.
2226 if ((Trb
->Mode
== SdMmcSdmaMode
) && ((IntStatus
& BIT3
) == BIT3
)) {
2228 // Clear DMA interrupt bit.
2231 Status
= SdMmcHcRwMmio (
2234 SD_MMC_HC_NOR_INT_STS
,
2239 if (EFI_ERROR (Status
)) {
2243 // Update SDMA Address register.
2245 SdmaAddr
= SD_MMC_SDMA_ROUND_UP ((UINTN
)Trb
->DataPhy
, SD_MMC_SDMA_BOUNDARY
);
2247 if (Private
->ControllerVersion
[Trb
->Slot
] >= SD_MMC_HC_CTRL_VER_400
) {
2248 Status
= SdMmcHcRwMmio (
2251 SD_MMC_HC_ADMA_SYS_ADDR
,
2257 Status
= SdMmcHcRwMmio (
2260 SD_MMC_HC_SDMA_ADDR
,
2267 if (EFI_ERROR (Status
)) {
2270 Trb
->DataPhy
= (UINT64
)(UINTN
)SdmaAddr
;
2273 if ((Packet
->SdMmcCmdBlk
->CommandType
!= SdMmcCommandTypeAdtc
) &&
2274 (Packet
->SdMmcCmdBlk
->ResponseType
!= SdMmcResponseTypeR1b
) &&
2275 (Packet
->SdMmcCmdBlk
->ResponseType
!= SdMmcResponseTypeR5b
)) {
2276 if ((IntStatus
& BIT0
) == BIT0
) {
2277 Status
= EFI_SUCCESS
;
2282 if (((Private
->Slot
[Trb
->Slot
].CardType
== EmmcCardType
) &&
2283 (Packet
->SdMmcCmdBlk
->CommandIndex
== EMMC_SEND_TUNING_BLOCK
)) ||
2284 ((Private
->Slot
[Trb
->Slot
].CardType
== SdCardType
) &&
2285 (Packet
->SdMmcCmdBlk
->CommandIndex
== SD_SEND_TUNING_BLOCK
))) {
2287 // When performing tuning procedure (Execute Tuning is set to 1) through PIO mode,
2288 // wait Buffer Read Ready bit of Normal Interrupt Status Register to be 1.
2289 // Refer to SD Host Controller Simplified Specification 3.0 figure 2-29 for details.
2291 if ((IntStatus
& BIT5
) == BIT5
) {
2293 // Clear Buffer Read Ready interrupt at first.
2296 SdMmcHcRwMmio (Private
->PciIo
, Trb
->Slot
, SD_MMC_HC_NOR_INT_STS
, FALSE
, sizeof (IntStatus
), &IntStatus
);
2298 // Read data out from Buffer Port register
2300 for (PioLength
= 0; PioLength
< Trb
->DataLen
; PioLength
+= 4) {
2301 SdMmcHcRwMmio (Private
->PciIo
, Trb
->Slot
, SD_MMC_HC_BUF_DAT_PORT
, TRUE
, 4, (UINT8
*)Trb
->Data
+ PioLength
);
2303 Status
= EFI_SUCCESS
;
2308 Status
= EFI_NOT_READY
;
2311 // Get response data when the cmd is executed successfully.
2313 if (!EFI_ERROR (Status
)) {
2314 if (Packet
->SdMmcCmdBlk
->CommandType
!= SdMmcCommandTypeBc
) {
2315 for (Index
= 0; Index
< 4; Index
++) {
2316 Status
= SdMmcHcRwMmio (
2319 SD_MMC_HC_RESPONSE
+ Index
* 4,
2324 if (EFI_ERROR (Status
)) {
2325 SdMmcHcLedOnOff (Private
->PciIo
, Trb
->Slot
, FALSE
);
2329 CopyMem (Packet
->SdMmcStatusBlk
, Response
, sizeof (Response
));
2333 if (Status
!= EFI_NOT_READY
) {
2334 SdMmcHcLedOnOff (Private
->PciIo
, Trb
->Slot
, FALSE
);
2341 Wait for the TRB execution result.
2343 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
2344 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
2346 @retval EFI_SUCCESS The TRB is executed successfully.
2347 @retval Others Some erros happen when executing this request.
2351 SdMmcWaitTrbResult (
2352 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
2353 IN SD_MMC_HC_TRB
*Trb
2357 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
2359 BOOLEAN InfiniteWait
;
2361 Packet
= Trb
->Packet
;
2363 // Wait Command Complete Interrupt Status bit in Normal Interrupt Status Register
2365 Timeout
= Packet
->Timeout
;
2367 InfiniteWait
= TRUE
;
2369 InfiniteWait
= FALSE
;
2372 while (InfiniteWait
|| (Timeout
> 0)) {
2374 // Check Trb execution result by reading Normal Interrupt Status register.
2376 Status
= SdMmcCheckTrbResult (Private
, Trb
);
2377 if (Status
!= EFI_NOT_READY
) {
2381 // Stall for 1 microsecond.