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 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include "SdMmcPciHcDxe.h"
18 Dump the content of SD/MMC host controller's Capability Register.
20 @param[in] Slot The slot number of the SD card to send the command to.
21 @param[in] Capability The buffer to store the capability data.
27 IN SD_MMC_HC_SLOT_CAP
*Capability
31 // Dump Capability Data
33 DEBUG ((DEBUG_INFO
, " == Slot [%d] Capability is 0x%x ==\n", Slot
, Capability
));
34 DEBUG ((DEBUG_INFO
, " Timeout Clk Freq %d%a\n", Capability
->TimeoutFreq
, (Capability
->TimeoutUnit
) ? "MHz" : "KHz"));
35 DEBUG ((DEBUG_INFO
, " Base Clk Freq %dMHz\n", Capability
->BaseClkFreq
));
36 DEBUG ((DEBUG_INFO
, " Max Blk Len %dbytes\n", 512 * (1 << Capability
->MaxBlkLen
)));
37 DEBUG ((DEBUG_INFO
, " 8-bit Support %a\n", Capability
->BusWidth8
? "TRUE" : "FALSE"));
38 DEBUG ((DEBUG_INFO
, " ADMA2 Support %a\n", Capability
->Adma2
? "TRUE" : "FALSE"));
39 DEBUG ((DEBUG_INFO
, " HighSpeed Support %a\n", Capability
->HighSpeed
? "TRUE" : "FALSE"));
40 DEBUG ((DEBUG_INFO
, " SDMA Support %a\n", Capability
->Sdma
? "TRUE" : "FALSE"));
41 DEBUG ((DEBUG_INFO
, " Suspend/Resume %a\n", Capability
->SuspRes
? "TRUE" : "FALSE"));
42 DEBUG ((DEBUG_INFO
, " Voltage 3.3 %a\n", Capability
->Voltage33
? "TRUE" : "FALSE"));
43 DEBUG ((DEBUG_INFO
, " Voltage 3.0 %a\n", Capability
->Voltage30
? "TRUE" : "FALSE"));
44 DEBUG ((DEBUG_INFO
, " Voltage 1.8 %a\n", Capability
->Voltage18
? "TRUE" : "FALSE"));
45 DEBUG ((DEBUG_INFO
, " V4 64-bit Sys Bus %a\n", Capability
->SysBus64V4
? "TRUE" : "FALSE"));
46 DEBUG ((DEBUG_INFO
, " V3 64-bit Sys Bus %a\n", Capability
->SysBus64V3
? "TRUE" : "FALSE"));
47 DEBUG ((DEBUG_INFO
, " Async Interrupt %a\n", Capability
->AsyncInt
? "TRUE" : "FALSE"));
48 DEBUG ((DEBUG_INFO
, " SlotType "));
49 if (Capability
->SlotType
== 0x00) {
50 DEBUG ((DEBUG_INFO
, "%a\n", "Removable Slot"));
51 } else if (Capability
->SlotType
== 0x01) {
52 DEBUG ((DEBUG_INFO
, "%a\n", "Embedded Slot"));
53 } else if (Capability
->SlotType
== 0x02) {
54 DEBUG ((DEBUG_INFO
, "%a\n", "Shared Bus Slot"));
56 DEBUG ((DEBUG_INFO
, "%a\n", "Reserved"));
58 DEBUG ((DEBUG_INFO
, " SDR50 Support %a\n", Capability
->Sdr50
? "TRUE" : "FALSE"));
59 DEBUG ((DEBUG_INFO
, " SDR104 Support %a\n", Capability
->Sdr104
? "TRUE" : "FALSE"));
60 DEBUG ((DEBUG_INFO
, " DDR50 Support %a\n", Capability
->Ddr50
? "TRUE" : "FALSE"));
61 DEBUG ((DEBUG_INFO
, " Driver Type A %a\n", Capability
->DriverTypeA
? "TRUE" : "FALSE"));
62 DEBUG ((DEBUG_INFO
, " Driver Type C %a\n", Capability
->DriverTypeC
? "TRUE" : "FALSE"));
63 DEBUG ((DEBUG_INFO
, " Driver Type D %a\n", Capability
->DriverTypeD
? "TRUE" : "FALSE"));
64 DEBUG ((DEBUG_INFO
, " Driver Type 4 %a\n", Capability
->DriverType4
? "TRUE" : "FALSE"));
65 if (Capability
->TimerCount
== 0) {
66 DEBUG ((DEBUG_INFO
, " Retuning TimerCnt Disabled\n", 2 * (Capability
->TimerCount
- 1)));
68 DEBUG ((DEBUG_INFO
, " Retuning TimerCnt %dseconds\n", 2 * (Capability
->TimerCount
- 1)));
70 DEBUG ((DEBUG_INFO
, " SDR50 Tuning %a\n", Capability
->TuningSDR50
? "TRUE" : "FALSE"));
71 DEBUG ((DEBUG_INFO
, " Retuning Mode Mode %d\n", Capability
->RetuningMod
+ 1));
72 DEBUG ((DEBUG_INFO
, " Clock Multiplier M = %d\n", Capability
->ClkMultiplier
+ 1));
73 DEBUG ((DEBUG_INFO
, " HS 400 %a\n", Capability
->Hs400
? "TRUE" : "FALSE"));
78 Read SlotInfo register from SD/MMC host controller pci config space.
80 @param[in] PciIo The PCI IO protocol instance.
81 @param[out] FirstBar The buffer to store the first BAR value.
82 @param[out] SlotNum The buffer to store the supported slot number.
84 @retval EFI_SUCCESS The operation succeeds.
85 @retval Others The operation fails.
91 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
97 SD_MMC_HC_SLOT_INFO SlotInfo
;
99 Status
= PciIo
->Pci
.Read (
102 SD_MMC_HC_SLOT_OFFSET
,
106 if (EFI_ERROR (Status
)) {
110 *FirstBar
= SlotInfo
.FirstBar
;
111 *SlotNum
= SlotInfo
.SlotNum
+ 1;
112 ASSERT ((*FirstBar
+ *SlotNum
) < SD_MMC_HC_MAX_SLOT
);
117 Read/Write specified SD/MMC host controller mmio register.
119 @param[in] PciIo The PCI IO protocol instance.
120 @param[in] BarIndex The BAR index of the standard PCI Configuration
121 header to use as the base address for the memory
122 operation to perform.
123 @param[in] Offset The offset within the selected BAR to start the
125 @param[in] Read A boolean to indicate it's read or write operation.
126 @param[in] Count The width of the mmio register in bytes.
127 Must be 1, 2 , 4 or 8 bytes.
128 @param[in, out] Data For read operations, the destination buffer to store
129 the results. For write operations, the source buffer
130 to write data from. The caller is responsible for
131 having ownership of the data buffer and ensuring its
132 size not less than Count bytes.
134 @retval EFI_INVALID_PARAMETER The PciIo or Data is NULL or the Count is not valid.
135 @retval EFI_SUCCESS The read/write operation succeeds.
136 @retval Others The read/write operation fails.
142 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
151 EFI_PCI_IO_PROTOCOL_WIDTH Width
;
153 if ((PciIo
== NULL
) || (Data
== NULL
)) {
154 return EFI_INVALID_PARAMETER
;
159 Width
= EfiPciIoWidthUint8
;
162 Width
= EfiPciIoWidthUint16
;
166 Width
= EfiPciIoWidthUint32
;
170 Width
= EfiPciIoWidthUint32
;
174 return EFI_INVALID_PARAMETER
;
178 Status
= PciIo
->Mem
.Read (
187 Status
= PciIo
->Mem
.Write (
201 Do OR operation with the value of the specified SD/MMC host controller mmio register.
203 @param[in] PciIo The PCI IO protocol instance.
204 @param[in] BarIndex The BAR index of the standard PCI Configuration
205 header to use as the base address for the memory
206 operation to perform.
207 @param[in] Offset The offset within the selected BAR to start the
209 @param[in] Count The width of the mmio register in bytes.
210 Must be 1, 2 , 4 or 8 bytes.
211 @param[in] OrData The pointer to the data used to do OR operation.
212 The caller is responsible for having ownership of
213 the data buffer and ensuring its size not less than
216 @retval EFI_INVALID_PARAMETER The PciIo or OrData is NULL or the Count is not valid.
217 @retval EFI_SUCCESS The OR operation succeeds.
218 @retval Others The OR operation fails.
224 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
235 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, TRUE
, Count
, &Data
);
236 if (EFI_ERROR (Status
)) {
241 Or
= *(UINT8
*) OrData
;
242 } else if (Count
== 2) {
243 Or
= *(UINT16
*) OrData
;
244 } else if (Count
== 4) {
245 Or
= *(UINT32
*) OrData
;
246 } else if (Count
== 8) {
247 Or
= *(UINT64
*) OrData
;
249 return EFI_INVALID_PARAMETER
;
253 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, FALSE
, Count
, &Data
);
259 Do AND operation with the value of the specified SD/MMC host controller mmio register.
261 @param[in] PciIo The PCI IO protocol instance.
262 @param[in] BarIndex The BAR index of the standard PCI Configuration
263 header to use as the base address for the memory
264 operation to perform.
265 @param[in] Offset The offset within the selected BAR to start the
267 @param[in] Count The width of the mmio register in bytes.
268 Must be 1, 2 , 4 or 8 bytes.
269 @param[in] AndData The pointer to the data used to do AND operation.
270 The caller is responsible for having ownership of
271 the data buffer and ensuring its size not less than
274 @retval EFI_INVALID_PARAMETER The PciIo or AndData is NULL or the Count is not valid.
275 @retval EFI_SUCCESS The AND operation succeeds.
276 @retval Others The AND operation fails.
282 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
293 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, TRUE
, Count
, &Data
);
294 if (EFI_ERROR (Status
)) {
299 And
= *(UINT8
*) AndData
;
300 } else if (Count
== 2) {
301 And
= *(UINT16
*) AndData
;
302 } else if (Count
== 4) {
303 And
= *(UINT32
*) AndData
;
304 } else if (Count
== 8) {
305 And
= *(UINT64
*) AndData
;
307 return EFI_INVALID_PARAMETER
;
311 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, FALSE
, Count
, &Data
);
317 Wait for the value of the specified MMIO register set to the test value.
319 @param[in] PciIo The PCI IO protocol instance.
320 @param[in] BarIndex The BAR index of the standard PCI Configuration
321 header to use as the base address for the memory
322 operation to perform.
323 @param[in] Offset The offset within the selected BAR to start the
325 @param[in] Count The width of the mmio register in bytes.
326 Must be 1, 2, 4 or 8 bytes.
327 @param[in] MaskValue The mask value of memory.
328 @param[in] TestValue The test value of memory.
330 @retval EFI_NOT_READY The MMIO register hasn't set to the expected value.
331 @retval EFI_SUCCESS The MMIO register has expected value.
332 @retval Others The MMIO operation fails.
337 SdMmcHcCheckMmioSet (
338 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
350 // Access PCI MMIO space to see if the value is the tested one.
353 Status
= SdMmcHcRwMmio (PciIo
, BarIndex
, Offset
, TRUE
, Count
, &Value
);
354 if (EFI_ERROR (Status
)) {
360 if (Value
== TestValue
) {
364 return EFI_NOT_READY
;
368 Wait for the value of the specified MMIO register set to the test value.
370 @param[in] PciIo The PCI IO protocol instance.
371 @param[in] BarIndex The BAR index of the standard PCI Configuration
372 header to use as the base address for the memory
373 operation to perform.
374 @param[in] Offset The offset within the selected BAR to start the
376 @param[in] Count The width of the mmio register in bytes.
377 Must be 1, 2, 4 or 8 bytes.
378 @param[in] MaskValue The mask value of memory.
379 @param[in] TestValue The test value of memory.
380 @param[in] Timeout The time out value for wait memory set, uses 1
381 microsecond as a unit.
383 @retval EFI_TIMEOUT The MMIO register hasn't expected value in timeout
385 @retval EFI_SUCCESS The MMIO register has expected value.
386 @retval Others The MMIO operation fails.
392 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
402 BOOLEAN InfiniteWait
;
407 InfiniteWait
= FALSE
;
410 while (InfiniteWait
|| (Timeout
> 0)) {
411 Status
= SdMmcHcCheckMmioSet (
419 if (Status
!= EFI_NOT_READY
) {
424 // Stall for 1 microsecond.
435 Get the controller version information from the specified slot.
437 @param[in] PciIo The PCI IO protocol instance.
438 @param[in] Slot The slot number of the SD card to send the command to.
439 @param[out] Version The buffer to store the version information.
441 @retval EFI_SUCCESS The operation executes successfully.
442 @retval Others The operation fails.
446 SdMmcHcGetControllerVersion (
447 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
454 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_CTRL_VER
, TRUE
, sizeof (UINT16
), Version
);
455 if (EFI_ERROR (Status
)) {
465 Software reset the specified SD/MMC host controller and enable all interrupts.
467 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
468 @param[in] Slot The slot number of the SD card to send the command to.
470 @retval EFI_SUCCESS The software reset executes successfully.
471 @retval Others The software reset fails.
476 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
482 EFI_PCI_IO_PROTOCOL
*PciIo
;
485 // Notify the SD/MMC override protocol that we are about to reset
486 // the SD/MMC host controller.
488 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
489 Status
= mOverride
->NotifyPhase (
490 Private
->ControllerHandle
,
494 if (EFI_ERROR (Status
)) {
496 "%a: SD/MMC pre reset notifier callback failed - %r\n",
497 __FUNCTION__
, Status
));
502 PciIo
= Private
->PciIo
;
504 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_SW_RST
, sizeof (SwReset
), &SwReset
);
506 if (EFI_ERROR (Status
)) {
507 DEBUG ((DEBUG_ERROR
, "SdMmcHcReset: write SW Reset for All fails: %r\n", Status
));
511 Status
= SdMmcHcWaitMmioSet (
518 SD_MMC_HC_GENERIC_TIMEOUT
520 if (EFI_ERROR (Status
)) {
521 DEBUG ((DEBUG_INFO
, "SdMmcHcReset: reset done with %r\n", Status
));
526 // Enable all interrupt after reset all.
528 Status
= SdMmcHcEnableInterrupt (PciIo
, Slot
);
529 if (EFI_ERROR (Status
)) {
530 DEBUG ((DEBUG_INFO
, "SdMmcHcReset: SdMmcHcEnableInterrupt done with %r\n",
536 // Notify the SD/MMC override protocol that we have just reset
537 // the SD/MMC host controller.
539 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
540 Status
= mOverride
->NotifyPhase (
541 Private
->ControllerHandle
,
545 if (EFI_ERROR (Status
)) {
547 "%a: SD/MMC post reset notifier callback failed - %r\n",
548 __FUNCTION__
, Status
));
556 Set all interrupt status bits in Normal and Error Interrupt Status Enable
559 @param[in] PciIo The PCI IO protocol instance.
560 @param[in] Slot The slot number of the SD card to send the command to.
562 @retval EFI_SUCCESS The operation executes successfully.
563 @retval Others The operation fails.
567 SdMmcHcEnableInterrupt (
568 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
576 // Enable all bits in Error Interrupt Status Enable Register
579 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_ERR_INT_STS_EN
, FALSE
, sizeof (IntStatus
), &IntStatus
);
580 if (EFI_ERROR (Status
)) {
584 // Enable all bits in Normal Interrupt Status Enable Register
587 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_NOR_INT_STS_EN
, FALSE
, sizeof (IntStatus
), &IntStatus
);
593 Get the capability data from the specified slot.
595 @param[in] PciIo The PCI IO protocol instance.
596 @param[in] Slot The slot number of the SD card to send the command to.
597 @param[out] Capability The buffer to store the capability data.
599 @retval EFI_SUCCESS The operation executes successfully.
600 @retval Others The operation fails.
604 SdMmcHcGetCapability (
605 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
607 OUT SD_MMC_HC_SLOT_CAP
*Capability
613 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_CAP
, TRUE
, sizeof (Cap
), &Cap
);
614 if (EFI_ERROR (Status
)) {
618 CopyMem (Capability
, &Cap
, sizeof (Cap
));
624 Get the maximum current capability data from the specified slot.
626 @param[in] PciIo The PCI IO protocol instance.
627 @param[in] Slot The slot number of the SD card to send the command to.
628 @param[out] MaxCurrent The buffer to store the maximum current capability data.
630 @retval EFI_SUCCESS The operation executes successfully.
631 @retval Others The operation fails.
635 SdMmcHcGetMaxCurrent (
636 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
638 OUT UINT64
*MaxCurrent
643 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_MAX_CURRENT_CAP
, TRUE
, sizeof (UINT64
), MaxCurrent
);
649 Detect whether there is a SD/MMC card attached at the specified SD/MMC host controller
652 Refer to SD Host Controller Simplified spec 3.0 Section 3.1 for details.
654 @param[in] PciIo The PCI IO protocol instance.
655 @param[in] Slot The slot number of the SD card to send the command to.
656 @param[out] MediaPresent The pointer to the media present boolean value.
658 @retval EFI_SUCCESS There is no media change happened.
659 @retval EFI_MEDIA_CHANGED There is media change happened.
660 @retval Others The detection fails.
665 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
667 OUT BOOLEAN
*MediaPresent
675 // Check Present State Register to see if there is a card presented.
677 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_PRESENT_STATE
, TRUE
, sizeof (PresentState
), &PresentState
);
678 if (EFI_ERROR (Status
)) {
682 if ((PresentState
& BIT16
) != 0) {
683 *MediaPresent
= TRUE
;
685 *MediaPresent
= FALSE
;
689 // Check Normal Interrupt Status Register
691 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_NOR_INT_STS
, TRUE
, sizeof (Data
), &Data
);
692 if (EFI_ERROR (Status
)) {
696 if ((Data
& (BIT6
| BIT7
)) != 0) {
698 // Clear BIT6 and BIT7 by writing 1 to these two bits if set.
701 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_NOR_INT_STS
, FALSE
, sizeof (Data
), &Data
);
702 if (EFI_ERROR (Status
)) {
706 return EFI_MEDIA_CHANGED
;
713 Stop SD/MMC card clock.
715 Refer to SD Host Controller Simplified spec 3.0 Section 3.2.2 for details.
717 @param[in] PciIo The PCI IO protocol instance.
718 @param[in] Slot The slot number of the SD card to send the command to.
720 @retval EFI_SUCCESS Succeed to stop SD/MMC clock.
721 @retval Others Fail to stop SD/MMC clock.
726 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
735 // Ensure no SD transactions are occurring on the SD Bus by
736 // waiting for Command Inhibit (DAT) and Command Inhibit (CMD)
737 // in the Present State register to be 0.
739 Status
= SdMmcHcWaitMmioSet (
742 SD_MMC_HC_PRESENT_STATE
,
743 sizeof (PresentState
),
746 SD_MMC_HC_GENERIC_TIMEOUT
748 if (EFI_ERROR (Status
)) {
753 // Set SD Clock Enable in the Clock Control register to 0
755 ClockCtrl
= (UINT16
)~BIT2
;
756 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_CLOCK_CTRL
, sizeof (ClockCtrl
), &ClockCtrl
);
762 SD/MMC card clock supply.
764 Refer to SD Host Controller Simplified spec 3.0 Section 3.2.1 for details.
766 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
767 @param[in] Slot The slot number of the SD card to send the command to.
768 @param[in] BusTiming BusTiming at which the frequency change is done.
769 @param[in] FirstTimeSetup Flag to indicate whether the clock is being setup for the first time.
770 @param[in] ClockFreq The max clock frequency to be set. The unit is KHz.
772 @retval EFI_SUCCESS The clock is supplied successfully.
773 @retval Others The clock isn't supplied successfully.
778 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
780 IN SD_MMC_BUS_MODE BusTiming
,
781 IN BOOLEAN FirstTimeSetup
,
791 UINT16 ControllerVer
;
792 EFI_PCI_IO_PROTOCOL
*PciIo
;
794 PciIo
= Private
->PciIo
;
795 BaseClkFreq
= Private
->BaseClkFreq
[Slot
];
796 ControllerVer
= Private
->ControllerVersion
[Slot
];
798 if (BaseClkFreq
== 0 || ClockFreq
== 0) {
799 return EFI_INVALID_PARAMETER
;
802 if (ClockFreq
> (BaseClkFreq
* 1000)) {
803 ClockFreq
= BaseClkFreq
* 1000;
807 // Calculate the divisor of base frequency.
810 SettingFreq
= BaseClkFreq
* 1000;
811 while (ClockFreq
< SettingFreq
) {
814 SettingFreq
= (BaseClkFreq
* 1000) / (2 * Divisor
);
815 Remainder
= (BaseClkFreq
* 1000) % (2 * Divisor
);
816 if ((ClockFreq
== SettingFreq
) && (Remainder
== 0)) {
819 if ((ClockFreq
== SettingFreq
) && (Remainder
!= 0)) {
824 DEBUG ((DEBUG_INFO
, "BaseClkFreq %dMHz Divisor %d ClockFreq %dKhz\n", BaseClkFreq
, Divisor
, ClockFreq
));
827 // Set SDCLK Frequency Select and Internal Clock Enable fields in Clock Control register.
829 if ((ControllerVer
>= SD_MMC_HC_CTRL_VER_300
) &&
830 (ControllerVer
<= SD_MMC_HC_CTRL_VER_420
)) {
831 ASSERT (Divisor
<= 0x3FF);
832 ClockCtrl
= ((Divisor
& 0xFF) << 8) | ((Divisor
& 0x300) >> 2);
833 } else if ((ControllerVer
== SD_MMC_HC_CTRL_VER_100
) ||
834 (ControllerVer
== SD_MMC_HC_CTRL_VER_200
)) {
836 // Only the most significant bit can be used as divisor.
838 if (((Divisor
- 1) & Divisor
) != 0) {
839 Divisor
= 1 << (HighBitSet32 (Divisor
) + 1);
841 ASSERT (Divisor
<= 0x80);
842 ClockCtrl
= (Divisor
& 0xFF) << 8;
844 DEBUG ((DEBUG_ERROR
, "Unknown SD Host Controller Spec version [0x%x]!!!\n", ControllerVer
));
845 return EFI_UNSUPPORTED
;
849 // Stop bus clock at first
851 Status
= SdMmcHcStopClock (PciIo
, Slot
);
852 if (EFI_ERROR (Status
)) {
857 // Supply clock frequency with specified divisor
860 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_CLOCK_CTRL
, FALSE
, sizeof (ClockCtrl
), &ClockCtrl
);
861 if (EFI_ERROR (Status
)) {
862 DEBUG ((DEBUG_ERROR
, "Set SDCLK Frequency Select and Internal Clock Enable fields fails\n"));
867 // Wait Internal Clock Stable in the Clock Control register to be 1
869 Status
= SdMmcHcWaitMmioSet (
872 SD_MMC_HC_CLOCK_CTRL
,
876 SD_MMC_HC_GENERIC_TIMEOUT
878 if (EFI_ERROR (Status
)) {
883 // Set SD Clock Enable in the Clock Control register to 1
886 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_CLOCK_CTRL
, sizeof (ClockCtrl
), &ClockCtrl
);
889 // We don't notify the platform on first time setup to avoid changing
890 // legacy behavior. During first time setup we also don't know what type
891 // of the card slot it is and which enum value of BusTiming applies.
893 if (!FirstTimeSetup
&& mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
894 Status
= mOverride
->NotifyPhase (
895 Private
->ControllerHandle
,
897 EdkiiSdMmcSwitchClockFreqPost
,
900 if (EFI_ERROR (Status
)) {
903 "%a: SD/MMC switch clock freq post notifier callback failed - %r\n",
915 SD/MMC bus power control.
917 Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details.
919 @param[in] PciIo The PCI IO protocol instance.
920 @param[in] Slot The slot number of the SD card to send the command to.
921 @param[in] PowerCtrl The value setting to the power control register.
923 @retval TRUE There is a SD/MMC card attached.
924 @retval FALSE There is no a SD/MMC card attached.
928 SdMmcHcPowerControl (
929 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
939 PowerCtrl
&= (UINT8
)~BIT0
;
940 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_POWER_CTRL
, FALSE
, sizeof (PowerCtrl
), &PowerCtrl
);
941 if (EFI_ERROR (Status
)) {
946 // Set SD Bus Voltage Select and SD Bus Power fields in Power Control Register
949 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_POWER_CTRL
, FALSE
, sizeof (PowerCtrl
), &PowerCtrl
);
955 Set the SD/MMC bus width.
957 Refer to SD Host Controller Simplified spec 3.0 Section 3.4 for details.
959 @param[in] PciIo The PCI IO protocol instance.
960 @param[in] Slot The slot number of the SD card to send the command to.
961 @param[in] BusWidth The bus width used by the SD/MMC device, it must be 1, 4 or 8.
963 @retval EFI_SUCCESS The bus width is set successfully.
964 @retval Others The bus width isn't set successfully.
969 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
978 HostCtrl1
= (UINT8
)~(BIT5
| BIT1
);
979 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
980 } else if (BusWidth
== 4) {
981 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, TRUE
, sizeof (HostCtrl1
), &HostCtrl1
);
982 if (EFI_ERROR (Status
)) {
986 HostCtrl1
&= (UINT8
)~BIT5
;
987 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, FALSE
, sizeof (HostCtrl1
), &HostCtrl1
);
988 } else if (BusWidth
== 8) {
989 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, TRUE
, sizeof (HostCtrl1
), &HostCtrl1
);
990 if (EFI_ERROR (Status
)) {
993 HostCtrl1
&= (UINT8
)~BIT1
;
995 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, FALSE
, sizeof (HostCtrl1
), &HostCtrl1
);
998 return EFI_INVALID_PARAMETER
;
1005 Configure V4 controller enhancements at initialization.
1007 @param[in] PciIo The PCI IO protocol instance.
1008 @param[in] Slot The slot number of the SD card to send the command to.
1009 @param[in] Capability The capability of the slot.
1010 @param[in] ControllerVer The version of host controller.
1012 @retval EFI_SUCCESS The clock is supplied successfully.
1016 SdMmcHcInitV4Enhancements (
1017 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1019 IN SD_MMC_HC_SLOT_CAP Capability
,
1020 IN UINT16 ControllerVer
1027 // Check if controller version V4 or higher
1029 if (ControllerVer
>= SD_MMC_HC_CTRL_VER_400
) {
1030 HostCtrl2
= SD_MMC_HC_V4_EN
;
1032 // Check if controller version V4.0
1034 if (ControllerVer
== SD_MMC_HC_CTRL_VER_400
) {
1036 // Check if 64bit support is available
1038 if (Capability
.SysBus64V3
!= 0) {
1039 HostCtrl2
|= SD_MMC_HC_64_ADDR_EN
;
1040 DEBUG ((DEBUG_INFO
, "Enabled V4 64 bit system bus support\n"));
1044 // Check if controller version V4.10 or higher
1046 else if (ControllerVer
>= SD_MMC_HC_CTRL_VER_410
) {
1048 // Check if 64bit support is available
1050 if (Capability
.SysBus64V4
!= 0) {
1051 HostCtrl2
|= SD_MMC_HC_64_ADDR_EN
;
1052 DEBUG ((DEBUG_INFO
, "Enabled V4 64 bit system bus support\n"));
1054 HostCtrl2
|= SD_MMC_HC_26_DATA_LEN_ADMA_EN
;
1055 DEBUG ((DEBUG_INFO
, "Enabled V4 26 bit data length ADMA support\n"));
1057 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1058 if (EFI_ERROR (Status
)) {
1067 Supply SD/MMC card with maximum voltage at initialization.
1069 Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details.
1071 @param[in] PciIo The PCI IO protocol instance.
1072 @param[in] Slot The slot number of the SD card to send the command to.
1073 @param[in] Capability The capability of the slot.
1075 @retval EFI_SUCCESS The voltage is supplied successfully.
1076 @retval Others The voltage isn't supplied successfully.
1080 SdMmcHcInitPowerVoltage (
1081 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1083 IN SD_MMC_HC_SLOT_CAP Capability
1091 // Calculate supported maximum voltage according to SD Bus Voltage Select
1093 if (Capability
.Voltage33
!= 0) {
1098 } else if (Capability
.Voltage30
!= 0) {
1103 } else if (Capability
.Voltage18
!= 0) {
1109 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1111 if (EFI_ERROR (Status
)) {
1116 return EFI_DEVICE_ERROR
;
1120 // Set SD Bus Voltage Select and SD Bus Power fields in Power Control Register
1122 Status
= SdMmcHcPowerControl (PciIo
, Slot
, MaxVoltage
);
1128 Initialize the Timeout Control register with most conservative value at initialization.
1130 Refer to SD Host Controller Simplified spec 3.0 Section 2.2.15 for details.
1132 @param[in] PciIo The PCI IO protocol instance.
1133 @param[in] Slot The slot number of the SD card to send the command to.
1135 @retval EFI_SUCCESS The timeout control register is configured successfully.
1136 @retval Others The timeout control register isn't configured successfully.
1140 SdMmcHcInitTimeoutCtrl (
1141 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1149 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_TIMEOUT_CTRL
, FALSE
, sizeof (Timeout
), &Timeout
);
1155 Initial SD/MMC host controller with lowest clock frequency, max power and max timeout value
1158 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1159 @param[in] Slot The slot number of the SD card to send the command to.
1161 @retval EFI_SUCCESS The host controller is initialized successfully.
1162 @retval Others The host controller isn't initialized successfully.
1167 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1172 EFI_PCI_IO_PROTOCOL
*PciIo
;
1173 SD_MMC_HC_SLOT_CAP Capability
;
1176 // Notify the SD/MMC override protocol that we are about to initialize
1177 // the SD/MMC host controller.
1179 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
1180 Status
= mOverride
->NotifyPhase (
1181 Private
->ControllerHandle
,
1183 EdkiiSdMmcInitHostPre
,
1185 if (EFI_ERROR (Status
)) {
1187 "%a: SD/MMC pre init notifier callback failed - %r\n",
1188 __FUNCTION__
, Status
));
1193 PciIo
= Private
->PciIo
;
1194 Capability
= Private
->Capability
[Slot
];
1196 Status
= SdMmcHcInitV4Enhancements (PciIo
, Slot
, Capability
, Private
->ControllerVersion
[Slot
]);
1197 if (EFI_ERROR (Status
)) {
1202 // Perform first time clock setup with 400 KHz frequency.
1203 // We send the 0 as the BusTiming value because at this time
1204 // we still do not know the slot type and which enum value will apply.
1205 // Since it is a first time setup SdMmcHcClockSupply won't notify
1206 // the platofrm driver anyway so it doesn't matter.
1208 Status
= SdMmcHcClockSupply (Private
, Slot
, 0, TRUE
, 400);
1209 if (EFI_ERROR (Status
)) {
1213 Status
= SdMmcHcInitPowerVoltage (PciIo
, Slot
, Capability
);
1214 if (EFI_ERROR (Status
)) {
1218 Status
= SdMmcHcInitTimeoutCtrl (PciIo
, Slot
);
1219 if (EFI_ERROR (Status
)) {
1224 // Notify the SD/MMC override protocol that we are have just initialized
1225 // the SD/MMC host controller.
1227 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
1228 Status
= mOverride
->NotifyPhase (
1229 Private
->ControllerHandle
,
1231 EdkiiSdMmcInitHostPost
,
1233 if (EFI_ERROR (Status
)) {
1235 "%a: SD/MMC post init notifier callback failed - %r\n",
1236 __FUNCTION__
, Status
));
1243 Set SD Host Controler control 2 registry according to selected speed.
1245 @param[in] ControllerHandle The handle of the controller.
1246 @param[in] PciIo The PCI IO protocol instance.
1247 @param[in] Slot The slot number of the SD card to send the command to.
1248 @param[in] Timing The timing to select.
1250 @retval EFI_SUCCESS The timing is set successfully.
1251 @retval Others The timing isn't set successfully.
1254 SdMmcHcUhsSignaling (
1255 IN EFI_HANDLE ControllerHandle
,
1256 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1258 IN SD_MMC_BUS_MODE Timing
1264 HostCtrl2
= (UINT8
)~SD_MMC_HC_CTRL_UHS_MASK
;
1265 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1266 if (EFI_ERROR (Status
)) {
1272 HostCtrl2
= SD_MMC_HC_CTRL_UHS_SDR12
;
1275 HostCtrl2
= SD_MMC_HC_CTRL_UHS_SDR25
;
1278 HostCtrl2
= SD_MMC_HC_CTRL_UHS_SDR50
;
1280 case SdMmcUhsSdr104
:
1281 HostCtrl2
= SD_MMC_HC_CTRL_UHS_SDR104
;
1284 HostCtrl2
= SD_MMC_HC_CTRL_UHS_DDR50
;
1286 case SdMmcMmcLegacy
:
1287 HostCtrl2
= SD_MMC_HC_CTRL_MMC_LEGACY
;
1290 HostCtrl2
= SD_MMC_HC_CTRL_MMC_HS_SDR
;
1293 HostCtrl2
= SD_MMC_HC_CTRL_MMC_HS_DDR
;
1296 HostCtrl2
= SD_MMC_HC_CTRL_MMC_HS200
;
1299 HostCtrl2
= SD_MMC_HC_CTRL_MMC_HS400
;
1305 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1306 if (EFI_ERROR (Status
)) {
1310 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
1311 Status
= mOverride
->NotifyPhase (
1314 EdkiiSdMmcUhsSignaling
,
1317 if (EFI_ERROR (Status
)) {
1320 "%a: SD/MMC uhs signaling notifier callback failed - %r\n",
1332 Set driver strength in host controller.
1334 @param[in] PciIo The PCI IO protocol instance.
1335 @param[in] SlotIndex The slot index of the card.
1336 @param[in] DriverStrength DriverStrength to set in the controller.
1338 @retval EFI_SUCCESS Driver strength programmed successfully.
1339 @retval Others Failed to set driver strength.
1342 SdMmcSetDriverStrength (
1343 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1345 IN SD_DRIVER_STRENGTH_TYPE DriverStrength
1351 if (DriverStrength
== SdDriverStrengthIgnore
) {
1355 HostCtrl2
= (UINT16
)~SD_MMC_HC_CTRL_DRIVER_STRENGTH_MASK
;
1356 Status
= SdMmcHcAndMmio (PciIo
, SlotIndex
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1357 if (EFI_ERROR (Status
)) {
1361 HostCtrl2
= (DriverStrength
<< 4) & SD_MMC_HC_CTRL_DRIVER_STRENGTH_MASK
;
1362 return SdMmcHcOrMmio (PciIo
, SlotIndex
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
1368 @param[in] PciIo The PCI IO protocol instance.
1369 @param[in] Slot The slot number of the SD card to send the command to.
1370 @param[in] On The boolean to turn on/off LED.
1372 @retval EFI_SUCCESS The LED is turned on/off successfully.
1373 @retval Others The LED isn't turned on/off successfully.
1378 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1388 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
1390 HostCtrl1
= (UINT8
)~BIT0
;
1391 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
1398 Build ADMA descriptor table for transfer.
1400 Refer to SD Host Controller Simplified spec 4.2 Section 1.13 for details.
1402 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1403 @param[in] ControllerVer The version of host controller.
1405 @retval EFI_SUCCESS The ADMA descriptor table is created successfully.
1406 @retval Others The ADMA descriptor table isn't created successfully.
1410 BuildAdmaDescTable (
1411 IN SD_MMC_HC_TRB
*Trb
,
1412 IN UINT16 ControllerVer
1415 EFI_PHYSICAL_ADDRESS Data
;
1422 EFI_PCI_IO_PROTOCOL
*PciIo
;
1425 UINT32 AdmaMaxDataPerLine
;
1429 AdmaMaxDataPerLine
= ADMA_MAX_DATA_PER_LINE_16B
;
1430 DescSize
= sizeof (SD_MMC_HC_ADMA_32_DESC_LINE
);
1433 Data
= Trb
->DataPhy
;
1434 DataLen
= Trb
->DataLen
;
1435 PciIo
= Trb
->Private
->PciIo
;
1438 // Check for valid ranges in 32bit ADMA Descriptor Table
1440 if ((Trb
->Mode
== SdMmcAdma32bMode
) &&
1441 ((Data
>= 0x100000000ul
) || ((Data
+ DataLen
) > 0x100000000ul
))) {
1442 return EFI_INVALID_PARAMETER
;
1445 // Check address field alignment
1447 if (Trb
->Mode
!= SdMmcAdma32bMode
) {
1449 // Address field shall be set on 64-bit boundary (Lower 3-bit is always set to 0)
1451 if ((Data
& (BIT0
| BIT1
| BIT2
)) != 0) {
1452 DEBUG ((DEBUG_INFO
, "The buffer [0x%x] to construct ADMA desc is not aligned to 8 bytes boundary!\n", Data
));
1456 // Address field shall be set on 32-bit boundary (Lower 2-bit is always set to 0)
1458 if ((Data
& (BIT0
| BIT1
)) != 0) {
1459 DEBUG ((DEBUG_INFO
, "The buffer [0x%x] to construct ADMA desc is not aligned to 4 bytes boundary!\n", Data
));
1464 // Configure 64b ADMA.
1466 if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1467 DescSize
= sizeof (SD_MMC_HC_ADMA_64_V3_DESC_LINE
);
1468 }else if (Trb
->Mode
== SdMmcAdma64bV4Mode
) {
1469 DescSize
= sizeof (SD_MMC_HC_ADMA_64_V4_DESC_LINE
);
1472 // Configure 26b data length.
1474 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1475 AdmaMaxDataPerLine
= ADMA_MAX_DATA_PER_LINE_26B
;
1478 Entries
= DivU64x32 ((DataLen
+ AdmaMaxDataPerLine
- 1), AdmaMaxDataPerLine
);
1479 TableSize
= (UINTN
)MultU64x32 (Entries
, DescSize
);
1480 Trb
->AdmaPages
= (UINT32
)EFI_SIZE_TO_PAGES (TableSize
);
1481 Status
= PciIo
->AllocateBuffer (
1484 EfiBootServicesData
,
1485 EFI_SIZE_TO_PAGES (TableSize
),
1489 if (EFI_ERROR (Status
)) {
1490 return EFI_OUT_OF_RESOURCES
;
1492 ZeroMem (AdmaDesc
, TableSize
);
1494 Status
= PciIo
->Map (
1496 EfiPciIoOperationBusMasterCommonBuffer
,
1503 if (EFI_ERROR (Status
) || (Bytes
!= TableSize
)) {
1505 // Map error or unable to map the whole RFis buffer into a contiguous region.
1509 EFI_SIZE_TO_PAGES (TableSize
),
1512 return EFI_OUT_OF_RESOURCES
;
1515 if ((Trb
->Mode
== SdMmcAdma32bMode
) &&
1516 (UINT64
)(UINTN
)Trb
->AdmaDescPhy
> 0x100000000ul
) {
1518 // The ADMA doesn't support 64bit addressing.
1526 EFI_SIZE_TO_PAGES (TableSize
),
1529 return EFI_DEVICE_ERROR
;
1532 Remaining
= DataLen
;
1534 if (Trb
->Mode
== SdMmcAdma32bMode
) {
1535 Trb
->Adma32Desc
= AdmaDesc
;
1536 } else if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1537 Trb
->Adma64V3Desc
= AdmaDesc
;
1539 Trb
->Adma64V4Desc
= AdmaDesc
;
1542 for (Index
= 0; Index
< Entries
; Index
++) {
1543 if (Trb
->Mode
== SdMmcAdma32bMode
) {
1544 if (Remaining
<= AdmaMaxDataPerLine
) {
1545 Trb
->Adma32Desc
[Index
].Valid
= 1;
1546 Trb
->Adma32Desc
[Index
].Act
= 2;
1547 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1548 Trb
->Adma32Desc
[Index
].UpperLength
= (UINT16
)RShiftU64 (Remaining
, 16);
1550 Trb
->Adma32Desc
[Index
].LowerLength
= (UINT16
)(Remaining
& MAX_UINT16
);
1551 Trb
->Adma32Desc
[Index
].Address
= (UINT32
)Address
;
1554 Trb
->Adma32Desc
[Index
].Valid
= 1;
1555 Trb
->Adma32Desc
[Index
].Act
= 2;
1556 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1557 Trb
->Adma32Desc
[Index
].UpperLength
= 0;
1559 Trb
->Adma32Desc
[Index
].LowerLength
= 0;
1560 Trb
->Adma32Desc
[Index
].Address
= (UINT32
)Address
;
1562 } else if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1563 if (Remaining
<= AdmaMaxDataPerLine
) {
1564 Trb
->Adma64V3Desc
[Index
].Valid
= 1;
1565 Trb
->Adma64V3Desc
[Index
].Act
= 2;
1566 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1567 Trb
->Adma64V3Desc
[Index
].UpperLength
= (UINT16
)RShiftU64 (Remaining
, 16);
1569 Trb
->Adma64V3Desc
[Index
].LowerLength
= (UINT16
)(Remaining
& MAX_UINT16
);
1570 Trb
->Adma64V3Desc
[Index
].LowerAddress
= (UINT32
)Address
;
1571 Trb
->Adma64V3Desc
[Index
].UpperAddress
= (UINT32
)RShiftU64 (Address
, 32);
1574 Trb
->Adma64V3Desc
[Index
].Valid
= 1;
1575 Trb
->Adma64V3Desc
[Index
].Act
= 2;
1576 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1577 Trb
->Adma64V3Desc
[Index
].UpperLength
= 0;
1579 Trb
->Adma64V3Desc
[Index
].LowerLength
= 0;
1580 Trb
->Adma64V3Desc
[Index
].LowerAddress
= (UINT32
)Address
;
1581 Trb
->Adma64V3Desc
[Index
].UpperAddress
= (UINT32
)RShiftU64 (Address
, 32);
1584 if (Remaining
<= AdmaMaxDataPerLine
) {
1585 Trb
->Adma64V4Desc
[Index
].Valid
= 1;
1586 Trb
->Adma64V4Desc
[Index
].Act
= 2;
1587 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1588 Trb
->Adma64V4Desc
[Index
].UpperLength
= (UINT16
)RShiftU64 (Remaining
, 16);
1590 Trb
->Adma64V4Desc
[Index
].LowerLength
= (UINT16
)(Remaining
& MAX_UINT16
);
1591 Trb
->Adma64V4Desc
[Index
].LowerAddress
= (UINT32
)Address
;
1592 Trb
->Adma64V4Desc
[Index
].UpperAddress
= (UINT32
)RShiftU64 (Address
, 32);
1595 Trb
->Adma64V4Desc
[Index
].Valid
= 1;
1596 Trb
->Adma64V4Desc
[Index
].Act
= 2;
1597 if (Trb
->AdmaLengthMode
== SdMmcAdmaLen26b
) {
1598 Trb
->Adma64V4Desc
[Index
].UpperLength
= 0;
1600 Trb
->Adma64V4Desc
[Index
].LowerLength
= 0;
1601 Trb
->Adma64V4Desc
[Index
].LowerAddress
= (UINT32
)Address
;
1602 Trb
->Adma64V4Desc
[Index
].UpperAddress
= (UINT32
)RShiftU64 (Address
, 32);
1606 Remaining
-= AdmaMaxDataPerLine
;
1607 Address
+= AdmaMaxDataPerLine
;
1611 // Set the last descriptor line as end of descriptor table
1613 if (Trb
->Mode
== SdMmcAdma32bMode
) {
1614 Trb
->Adma32Desc
[Index
].End
= 1;
1615 } else if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1616 Trb
->Adma64V3Desc
[Index
].End
= 1;
1618 Trb
->Adma64V4Desc
[Index
].End
= 1;
1624 Create a new TRB for the SD/MMC cmd request.
1626 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1627 @param[in] Slot The slot number of the SD card to send the command to.
1628 @param[in] Packet A pointer to the SD command data structure.
1629 @param[in] Event If Event is NULL, blocking I/O is performed. If Event is
1630 not NULL, then nonblocking I/O is performed, and Event
1631 will be signaled when the Packet completes.
1633 @return Created Trb or NULL.
1638 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1640 IN EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
,
1647 EFI_PCI_IO_PROTOCOL_OPERATION Flag
;
1648 EFI_PCI_IO_PROTOCOL
*PciIo
;
1651 Trb
= AllocateZeroPool (sizeof (SD_MMC_HC_TRB
));
1656 Trb
->Signature
= SD_MMC_HC_TRB_SIG
;
1658 Trb
->BlockSize
= 0x200;
1659 Trb
->Packet
= Packet
;
1661 Trb
->Started
= FALSE
;
1662 Trb
->Timeout
= Packet
->Timeout
;
1663 Trb
->Private
= Private
;
1665 if ((Packet
->InTransferLength
!= 0) && (Packet
->InDataBuffer
!= NULL
)) {
1666 Trb
->Data
= Packet
->InDataBuffer
;
1667 Trb
->DataLen
= Packet
->InTransferLength
;
1669 } else if ((Packet
->OutTransferLength
!= 0) && (Packet
->OutDataBuffer
!= NULL
)) {
1670 Trb
->Data
= Packet
->OutDataBuffer
;
1671 Trb
->DataLen
= Packet
->OutTransferLength
;
1673 } else if ((Packet
->InTransferLength
== 0) && (Packet
->OutTransferLength
== 0)) {
1680 if ((Trb
->DataLen
!= 0) && (Trb
->DataLen
< Trb
->BlockSize
)) {
1681 Trb
->BlockSize
= (UINT16
)Trb
->DataLen
;
1684 if (((Private
->Slot
[Trb
->Slot
].CardType
== EmmcCardType
) &&
1685 (Packet
->SdMmcCmdBlk
->CommandIndex
== EMMC_SEND_TUNING_BLOCK
)) ||
1686 ((Private
->Slot
[Trb
->Slot
].CardType
== SdCardType
) &&
1687 (Packet
->SdMmcCmdBlk
->CommandIndex
== SD_SEND_TUNING_BLOCK
))) {
1688 Trb
->Mode
= SdMmcPioMode
;
1691 Flag
= EfiPciIoOperationBusMasterWrite
;
1693 Flag
= EfiPciIoOperationBusMasterRead
;
1696 PciIo
= Private
->PciIo
;
1697 if (Trb
->DataLen
!= 0) {
1698 MapLength
= Trb
->DataLen
;
1699 Status
= PciIo
->Map (
1707 if (EFI_ERROR (Status
) || (Trb
->DataLen
!= MapLength
)) {
1708 Status
= EFI_BAD_BUFFER_SIZE
;
1713 if (Trb
->DataLen
== 0) {
1714 Trb
->Mode
= SdMmcNoData
;
1715 } else if (Private
->Capability
[Slot
].Adma2
!= 0) {
1716 Trb
->Mode
= SdMmcAdma32bMode
;
1717 Trb
->AdmaLengthMode
= SdMmcAdmaLen16b
;
1718 if ((Private
->ControllerVersion
[Slot
] == SD_MMC_HC_CTRL_VER_300
) &&
1719 (Private
->Capability
[Slot
].SysBus64V3
== 1)) {
1720 Trb
->Mode
= SdMmcAdma64bV3Mode
;
1721 } else if (((Private
->ControllerVersion
[Slot
] == SD_MMC_HC_CTRL_VER_400
) &&
1722 (Private
->Capability
[Slot
].SysBus64V3
== 1)) ||
1723 ((Private
->ControllerVersion
[Slot
] >= SD_MMC_HC_CTRL_VER_410
) &&
1724 (Private
->Capability
[Slot
].SysBus64V4
== 1))) {
1725 Trb
->Mode
= SdMmcAdma64bV4Mode
;
1727 if (Private
->ControllerVersion
[Slot
] >= SD_MMC_HC_CTRL_VER_410
) {
1728 Trb
->AdmaLengthMode
= SdMmcAdmaLen26b
;
1730 Status
= BuildAdmaDescTable (Trb
, Private
->ControllerVersion
[Slot
]);
1731 if (EFI_ERROR (Status
)) {
1732 PciIo
->Unmap (PciIo
, Trb
->DataMap
);
1735 } else if (Private
->Capability
[Slot
].Sdma
!= 0) {
1736 Trb
->Mode
= SdMmcSdmaMode
;
1738 Trb
->Mode
= SdMmcPioMode
;
1742 if (Event
!= NULL
) {
1743 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1744 InsertTailList (&Private
->Queue
, &Trb
->TrbList
);
1745 gBS
->RestoreTPL (OldTpl
);
1756 Free the resource used by the TRB.
1758 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1763 IN SD_MMC_HC_TRB
*Trb
1766 EFI_PCI_IO_PROTOCOL
*PciIo
;
1768 PciIo
= Trb
->Private
->PciIo
;
1770 if (Trb
->AdmaMap
!= NULL
) {
1776 if (Trb
->Adma32Desc
!= NULL
) {
1783 if (Trb
->Adma64V3Desc
!= NULL
) {
1790 if (Trb
->Adma64V4Desc
!= NULL
) {
1797 if (Trb
->DataMap
!= NULL
) {
1808 Check if the env is ready for execute specified TRB.
1810 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1811 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1813 @retval EFI_SUCCESS The env is ready for TRB execution.
1814 @retval EFI_NOT_READY The env is not ready for TRB execution.
1815 @retval Others Some erros happen.
1820 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1821 IN SD_MMC_HC_TRB
*Trb
1825 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
1826 EFI_PCI_IO_PROTOCOL
*PciIo
;
1827 UINT32 PresentState
;
1829 Packet
= Trb
->Packet
;
1831 if ((Packet
->SdMmcCmdBlk
->CommandType
== SdMmcCommandTypeAdtc
) ||
1832 (Packet
->SdMmcCmdBlk
->ResponseType
== SdMmcResponseTypeR1b
) ||
1833 (Packet
->SdMmcCmdBlk
->ResponseType
== SdMmcResponseTypeR5b
)) {
1835 // Wait Command Inhibit (CMD) and Command Inhibit (DAT) in
1836 // the Present State register to be 0
1838 PresentState
= BIT0
| BIT1
;
1841 // Wait Command Inhibit (CMD) in the Present State register
1844 PresentState
= BIT0
;
1847 PciIo
= Private
->PciIo
;
1848 Status
= SdMmcHcCheckMmioSet (
1851 SD_MMC_HC_PRESENT_STATE
,
1852 sizeof (PresentState
),
1861 Wait for the env to be ready for execute specified TRB.
1863 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1864 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1866 @retval EFI_SUCCESS The env is ready for TRB execution.
1867 @retval EFI_TIMEOUT The env is not ready for TRB execution in time.
1868 @retval Others Some erros happen.
1873 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1874 IN SD_MMC_HC_TRB
*Trb
1878 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
1880 BOOLEAN InfiniteWait
;
1883 // Wait Command Complete Interrupt Status bit in Normal Interrupt Status Register
1885 Packet
= Trb
->Packet
;
1886 Timeout
= Packet
->Timeout
;
1888 InfiniteWait
= TRUE
;
1890 InfiniteWait
= FALSE
;
1893 while (InfiniteWait
|| (Timeout
> 0)) {
1895 // Check Trb execution result by reading Normal Interrupt Status register.
1897 Status
= SdMmcCheckTrbEnv (Private
, Trb
);
1898 if (Status
!= EFI_NOT_READY
) {
1902 // Stall for 1 microsecond.
1913 Execute the specified TRB.
1915 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1916 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
1918 @retval EFI_SUCCESS The TRB is sent to host controller successfully.
1919 @retval Others Some erros happen when sending this request to the host controller.
1924 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1925 IN SD_MMC_HC_TRB
*Trb
1929 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
1930 EFI_PCI_IO_PROTOCOL
*PciIo
;
1940 BOOLEAN AddressingMode64
;
1942 AddressingMode64
= FALSE
;
1944 Packet
= Trb
->Packet
;
1945 PciIo
= Trb
->Private
->PciIo
;
1947 // Clear all bits in Error Interrupt Status Register
1950 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_ERR_INT_STS
, FALSE
, sizeof (IntStatus
), &IntStatus
);
1951 if (EFI_ERROR (Status
)) {
1955 // Clear all bits in Normal Interrupt Status Register excepts for Card Removal & Card Insertion bits.
1958 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_NOR_INT_STS
, FALSE
, sizeof (IntStatus
), &IntStatus
);
1959 if (EFI_ERROR (Status
)) {
1963 if (Private
->ControllerVersion
[Trb
->Slot
] >= SD_MMC_HC_CTRL_VER_400
) {
1964 Status
= SdMmcHcCheckMmioSet(PciIo
, Trb
->Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof(UINT16
),
1965 SD_MMC_HC_64_ADDR_EN
, SD_MMC_HC_64_ADDR_EN
);
1966 if (!EFI_ERROR (Status
)) {
1967 AddressingMode64
= TRUE
;
1972 // Set Host Control 1 register DMA Select field
1974 if ((Trb
->Mode
== SdMmcAdma32bMode
) ||
1975 (Trb
->Mode
== SdMmcAdma64bV4Mode
)) {
1977 Status
= SdMmcHcOrMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
1978 if (EFI_ERROR (Status
)) {
1981 } else if (Trb
->Mode
== SdMmcAdma64bV3Mode
) {
1982 HostCtrl1
= BIT4
|BIT3
;
1983 Status
= SdMmcHcOrMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
1984 if (EFI_ERROR (Status
)) {
1989 SdMmcHcLedOnOff (PciIo
, Trb
->Slot
, TRUE
);
1991 if (Trb
->Mode
== SdMmcSdmaMode
) {
1992 if ((!AddressingMode64
) &&
1993 ((UINT64
)(UINTN
)Trb
->DataPhy
>= 0x100000000ul
)) {
1994 return EFI_INVALID_PARAMETER
;
1997 SdmaAddr
= (UINT64
)(UINTN
)Trb
->DataPhy
;
1999 if (Private
->ControllerVersion
[Trb
->Slot
] >= SD_MMC_HC_CTRL_VER_400
) {
2000 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_ADMA_SYS_ADDR
, FALSE
, sizeof (UINT64
), &SdmaAddr
);
2002 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_SDMA_ADDR
, FALSE
, sizeof (UINT32
), &SdmaAddr
);
2005 if (EFI_ERROR (Status
)) {
2008 } else if ((Trb
->Mode
== SdMmcAdma32bMode
) ||
2009 (Trb
->Mode
== SdMmcAdma64bV3Mode
) ||
2010 (Trb
->Mode
== SdMmcAdma64bV4Mode
)) {
2011 AdmaAddr
= (UINT64
)(UINTN
)Trb
->AdmaDescPhy
;
2012 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_ADMA_SYS_ADDR
, FALSE
, sizeof (AdmaAddr
), &AdmaAddr
);
2013 if (EFI_ERROR (Status
)) {
2018 BlkSize
= Trb
->BlockSize
;
2019 if (Trb
->Mode
== SdMmcSdmaMode
) {
2021 // Set SDMA boundary to be 512K bytes.
2026 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_BLK_SIZE
, FALSE
, sizeof (BlkSize
), &BlkSize
);
2027 if (EFI_ERROR (Status
)) {
2032 if (Trb
->Mode
!= SdMmcNoData
) {
2034 // Calcuate Block Count.
2036 BlkCount
= (Trb
->DataLen
/ Trb
->BlockSize
);
2038 if (Private
->ControllerVersion
[Trb
->Slot
] >= SD_MMC_HC_CTRL_VER_410
) {
2039 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_SDMA_ADDR
, FALSE
, sizeof (UINT32
), &BlkCount
);
2041 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_BLK_COUNT
, FALSE
, sizeof (UINT16
), &BlkCount
);
2043 if (EFI_ERROR (Status
)) {
2047 Argument
= Packet
->SdMmcCmdBlk
->CommandArgument
;
2048 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_ARG1
, FALSE
, sizeof (Argument
), &Argument
);
2049 if (EFI_ERROR (Status
)) {
2054 if (Trb
->Mode
!= SdMmcNoData
) {
2055 if (Trb
->Mode
!= SdMmcPioMode
) {
2062 TransMode
|= BIT5
| BIT1
;
2065 // Only SD memory card needs to use AUTO CMD12 feature.
2067 if (Private
->Slot
[Trb
->Slot
].CardType
== SdCardType
) {
2074 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_TRANS_MOD
, FALSE
, sizeof (TransMode
), &TransMode
);
2075 if (EFI_ERROR (Status
)) {
2079 Cmd
= (UINT16
)LShiftU64(Packet
->SdMmcCmdBlk
->CommandIndex
, 8);
2080 if (Packet
->SdMmcCmdBlk
->CommandType
== SdMmcCommandTypeAdtc
) {
2084 // Convert ResponseType to value
2086 if (Packet
->SdMmcCmdBlk
->CommandType
!= SdMmcCommandTypeBc
) {
2087 switch (Packet
->SdMmcCmdBlk
->ResponseType
) {
2088 case SdMmcResponseTypeR1
:
2089 case SdMmcResponseTypeR5
:
2090 case SdMmcResponseTypeR6
:
2091 case SdMmcResponseTypeR7
:
2092 Cmd
|= (BIT1
| BIT3
| BIT4
);
2094 case SdMmcResponseTypeR2
:
2095 Cmd
|= (BIT0
| BIT3
);
2097 case SdMmcResponseTypeR3
:
2098 case SdMmcResponseTypeR4
:
2101 case SdMmcResponseTypeR1b
:
2102 case SdMmcResponseTypeR5b
:
2103 Cmd
|= (BIT0
| BIT1
| BIT3
| BIT4
);
2113 Status
= SdMmcHcRwMmio (PciIo
, Trb
->Slot
, SD_MMC_HC_COMMAND
, FALSE
, sizeof (Cmd
), &Cmd
);
2118 Check the TRB execution result.
2120 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
2121 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
2123 @retval EFI_SUCCESS The TRB is executed successfully.
2124 @retval EFI_NOT_READY The TRB is not completed for execution.
2125 @retval Others Some erros happen when executing this request.
2129 SdMmcCheckTrbResult (
2130 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
2131 IN SD_MMC_HC_TRB
*Trb
2135 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
2144 Packet
= Trb
->Packet
;
2146 // Check Trb execution result by reading Normal Interrupt Status register.
2148 Status
= SdMmcHcRwMmio (
2151 SD_MMC_HC_NOR_INT_STS
,
2156 if (EFI_ERROR (Status
)) {
2160 // Check Transfer Complete bit is set or not.
2162 if ((IntStatus
& BIT1
) == BIT1
) {
2163 if ((IntStatus
& BIT15
) == BIT15
) {
2165 // Read Error Interrupt Status register to check if the error is
2166 // Data Timeout Error.
2167 // If yes, treat it as success as Transfer Complete has higher
2168 // priority than Data Timeout Error.
2170 Status
= SdMmcHcRwMmio (
2173 SD_MMC_HC_ERR_INT_STS
,
2178 if (!EFI_ERROR (Status
)) {
2179 if ((IntStatus
& BIT4
) == BIT4
) {
2180 Status
= EFI_SUCCESS
;
2182 Status
= EFI_DEVICE_ERROR
;
2190 // Check if there is a error happened during cmd execution.
2191 // If yes, then do error recovery procedure to follow SD Host Controller
2192 // Simplified Spec 3.0 section 3.10.1.
2194 if ((IntStatus
& BIT15
) == BIT15
) {
2195 Status
= SdMmcHcRwMmio (
2198 SD_MMC_HC_ERR_INT_STS
,
2203 if (EFI_ERROR (Status
)) {
2206 if ((IntStatus
& 0x0F) != 0) {
2209 if ((IntStatus
& 0xF0) != 0) {
2213 Status
= SdMmcHcRwMmio (
2221 if (EFI_ERROR (Status
)) {
2224 Status
= SdMmcHcWaitMmioSet (
2231 SD_MMC_HC_GENERIC_TIMEOUT
2233 if (EFI_ERROR (Status
)) {
2237 Status
= EFI_DEVICE_ERROR
;
2241 // Check if DMA interrupt is signalled for the SDMA transfer.
2243 if ((Trb
->Mode
== SdMmcSdmaMode
) && ((IntStatus
& BIT3
) == BIT3
)) {
2245 // Clear DMA interrupt bit.
2248 Status
= SdMmcHcRwMmio (
2251 SD_MMC_HC_NOR_INT_STS
,
2256 if (EFI_ERROR (Status
)) {
2260 // Update SDMA Address register.
2262 SdmaAddr
= SD_MMC_SDMA_ROUND_UP ((UINTN
)Trb
->DataPhy
, SD_MMC_SDMA_BOUNDARY
);
2264 if (Private
->ControllerVersion
[Trb
->Slot
] >= SD_MMC_HC_CTRL_VER_400
) {
2265 Status
= SdMmcHcRwMmio (
2268 SD_MMC_HC_ADMA_SYS_ADDR
,
2274 Status
= SdMmcHcRwMmio (
2277 SD_MMC_HC_SDMA_ADDR
,
2284 if (EFI_ERROR (Status
)) {
2287 Trb
->DataPhy
= (UINT64
)(UINTN
)SdmaAddr
;
2290 if ((Packet
->SdMmcCmdBlk
->CommandType
!= SdMmcCommandTypeAdtc
) &&
2291 (Packet
->SdMmcCmdBlk
->ResponseType
!= SdMmcResponseTypeR1b
) &&
2292 (Packet
->SdMmcCmdBlk
->ResponseType
!= SdMmcResponseTypeR5b
)) {
2293 if ((IntStatus
& BIT0
) == BIT0
) {
2294 Status
= EFI_SUCCESS
;
2299 if (((Private
->Slot
[Trb
->Slot
].CardType
== EmmcCardType
) &&
2300 (Packet
->SdMmcCmdBlk
->CommandIndex
== EMMC_SEND_TUNING_BLOCK
)) ||
2301 ((Private
->Slot
[Trb
->Slot
].CardType
== SdCardType
) &&
2302 (Packet
->SdMmcCmdBlk
->CommandIndex
== SD_SEND_TUNING_BLOCK
))) {
2304 // When performing tuning procedure (Execute Tuning is set to 1) through PIO mode,
2305 // wait Buffer Read Ready bit of Normal Interrupt Status Register to be 1.
2306 // Refer to SD Host Controller Simplified Specification 3.0 figure 2-29 for details.
2308 if ((IntStatus
& BIT5
) == BIT5
) {
2310 // Clear Buffer Read Ready interrupt at first.
2313 SdMmcHcRwMmio (Private
->PciIo
, Trb
->Slot
, SD_MMC_HC_NOR_INT_STS
, FALSE
, sizeof (IntStatus
), &IntStatus
);
2315 // Read data out from Buffer Port register
2317 for (PioLength
= 0; PioLength
< Trb
->DataLen
; PioLength
+= 4) {
2318 SdMmcHcRwMmio (Private
->PciIo
, Trb
->Slot
, SD_MMC_HC_BUF_DAT_PORT
, TRUE
, 4, (UINT8
*)Trb
->Data
+ PioLength
);
2320 Status
= EFI_SUCCESS
;
2325 Status
= EFI_NOT_READY
;
2328 // Get response data when the cmd is executed successfully.
2330 if (!EFI_ERROR (Status
)) {
2331 if (Packet
->SdMmcCmdBlk
->CommandType
!= SdMmcCommandTypeBc
) {
2332 for (Index
= 0; Index
< 4; Index
++) {
2333 Status
= SdMmcHcRwMmio (
2336 SD_MMC_HC_RESPONSE
+ Index
* 4,
2341 if (EFI_ERROR (Status
)) {
2342 SdMmcHcLedOnOff (Private
->PciIo
, Trb
->Slot
, FALSE
);
2346 CopyMem (Packet
->SdMmcStatusBlk
, Response
, sizeof (Response
));
2350 if (Status
!= EFI_NOT_READY
) {
2351 SdMmcHcLedOnOff (Private
->PciIo
, Trb
->Slot
, FALSE
);
2358 Wait for the TRB execution result.
2360 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
2361 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
2363 @retval EFI_SUCCESS The TRB is executed successfully.
2364 @retval Others Some erros happen when executing this request.
2368 SdMmcWaitTrbResult (
2369 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
2370 IN SD_MMC_HC_TRB
*Trb
2374 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET
*Packet
;
2376 BOOLEAN InfiniteWait
;
2378 Packet
= Trb
->Packet
;
2380 // Wait Command Complete Interrupt Status bit in Normal Interrupt Status Register
2382 Timeout
= Packet
->Timeout
;
2384 InfiniteWait
= TRUE
;
2386 InfiniteWait
= FALSE
;
2389 while (InfiniteWait
|| (Timeout
> 0)) {
2391 // Check Trb execution result by reading Normal Interrupt Status register.
2393 Status
= SdMmcCheckTrbResult (Private
, Trb
);
2394 if (Status
!= EFI_NOT_READY
) {
2398 // Stall for 1 microsecond.