33 DEBUG ((DEBUG_INFO,
" == Slot [%d] Capability is 0x%llx ==\n", Slot, *(UINT64 *)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"));
59 DEBUG ((DEBUG_INFO,
" SDR50 Support %a\n", Capability->Sdr50 ?
"TRUE" :
"FALSE"));
60 DEBUG ((DEBUG_INFO,
" SDR104 Support %a\n", Capability->Sdr104 ?
"TRUE" :
"FALSE"));
61 DEBUG ((DEBUG_INFO,
" DDR50 Support %a\n", Capability->Ddr50 ?
"TRUE" :
"FALSE"));
62 DEBUG ((DEBUG_INFO,
" Driver Type A %a\n", Capability->DriverTypeA ?
"TRUE" :
"FALSE"));
63 DEBUG ((DEBUG_INFO,
" Driver Type C %a\n", Capability->DriverTypeC ?
"TRUE" :
"FALSE"));
64 DEBUG ((DEBUG_INFO,
" Driver Type D %a\n", Capability->DriverTypeD ?
"TRUE" :
"FALSE"));
65 DEBUG ((DEBUG_INFO,
" Driver Type 4 %a\n", Capability->DriverType4 ?
"TRUE" :
"FALSE"));
66 if (Capability->TimerCount == 0) {
67 DEBUG ((DEBUG_INFO,
" Retuning TimerCnt Disabled\n"));
69 DEBUG ((DEBUG_INFO,
" Retuning TimerCnt %dseconds\n", 2 * (Capability->TimerCount - 1)));
72 DEBUG ((DEBUG_INFO,
" SDR50 Tuning %a\n", Capability->TuningSDR50 ?
"TRUE" :
"FALSE"));
73 DEBUG ((DEBUG_INFO,
" Retuning Mode Mode %d\n", Capability->RetuningMod + 1));
74 DEBUG ((DEBUG_INFO,
" Clock Multiplier M = %d\n", Capability->ClkMultiplier + 1));
75 DEBUG ((DEBUG_INFO,
" HS 400 %a\n", Capability->Hs400 ?
"TRUE" :
"FALSE"));
101 Status = PciIo->Pci.Read (
104 SD_MMC_HC_SLOT_OFFSET,
108 if (EFI_ERROR (Status)) {
112 *FirstBar = SlotInfo.FirstBar;
113 *SlotNum = SlotInfo.SlotNum + 1;
114 ASSERT ((*FirstBar + *SlotNum) < SD_MMC_HC_MAX_SLOT);
155 if ((PciIo ==
NULL) || (Data ==
NULL)) {
156 return EFI_INVALID_PARAMETER;
161 Width = EfiPciIoWidthUint8;
164 Width = EfiPciIoWidthUint16;
168 Width = EfiPciIoWidthUint32;
172 Width = EfiPciIoWidthUint32;
176 return EFI_INVALID_PARAMETER;
180 Status = PciIo->Mem.Read (
189 Status = PciIo->Mem.Write (
238 if (EFI_ERROR (Status)) {
243 Or = *(UINT8 *)OrData;
244 }
else if (Count == 2) {
245 Or = *(UINT16 *)OrData;
246 }
else if (Count == 4) {
247 Or = *(UINT32 *)OrData;
248 }
else if (Count == 8) {
249 Or = *(UINT64 *)OrData;
251 return EFI_INVALID_PARAMETER;
296 if (EFI_ERROR (Status)) {
301 And = *(UINT8 *)AndData;
302 }
else if (Count == 2) {
303 And = *(UINT16 *)AndData;
304 }
else if (Count == 4) {
305 And = *(UINT32 *)AndData;
306 }
else if (Count == 8) {
307 And = *(UINT64 *)AndData;
309 return EFI_INVALID_PARAMETER;
356 if (EFI_ERROR (Status)) {
362 if (Value == TestValue) {
366 return EFI_NOT_READY;
404 BOOLEAN InfiniteWait;
409 InfiniteWait =
FALSE;
412 while (InfiniteWait || (Timeout > 0)) {
421 if (Status != EFI_NOT_READY) {
456 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CTRL_VER,
TRUE,
sizeof (UINT16), Version);
457 if (EFI_ERROR (Status)) {
490 if ((mOverride !=
NULL) && (mOverride->NotifyPhase !=
NULL)) {
491 Status = mOverride->NotifyPhase (
492 Private->ControllerHandle,
497 if (EFI_ERROR (Status)) {
500 "%a: SD/MMC pre reset notifier callback failed - %r\n",
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));
524 SD_MMC_HC_GENERIC_TIMEOUT
526 if (EFI_ERROR (Status)) {
527 DEBUG ((DEBUG_INFO,
"SdMmcHcReset: reset done with %r\n", Status));
535 if (EFI_ERROR (Status)) {
538 "SdMmcHcReset: SdMmcHcEnableInterrupt done with %r\n",
548 if ((mOverride !=
NULL) && (mOverride->NotifyPhase !=
NULL)) {
549 Status = mOverride->NotifyPhase (
550 Private->ControllerHandle,
555 if (EFI_ERROR (Status)) {
558 "%a: SD/MMC post reset notifier callback failed - %r\n",
592 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_ERR_INT_STS_EN,
FALSE,
sizeof (IntStatus), &IntStatus);
593 if (EFI_ERROR (Status)) {
601 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_NOR_INT_STS_EN,
FALSE,
sizeof (IntStatus), &IntStatus);
628 if (EFI_ERROR (Status)) {
632 CopyMem (Capability, &Cap,
sizeof (Cap));
652 OUT UINT64 *MaxCurrent
657 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_MAX_CURRENT_CAP,
TRUE,
sizeof (UINT64), MaxCurrent);
681 OUT BOOLEAN *MediaPresent
691 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE,
TRUE,
sizeof (PresentState), &PresentState);
692 if (EFI_ERROR (Status)) {
696 if ((PresentState & BIT16) != 0) {
697 *MediaPresent =
TRUE;
699 *MediaPresent =
FALSE;
705 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_NOR_INT_STS,
TRUE,
sizeof (Data), &Data);
706 if (EFI_ERROR (Status)) {
710 if ((Data & (BIT6 | BIT7)) != 0) {
715 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_NOR_INT_STS,
FALSE,
sizeof (Data), &Data);
716 if (EFI_ERROR (Status)) {
720 return EFI_MEDIA_CHANGED;
756 SD_MMC_HC_PRESENT_STATE,
757 sizeof (PresentState),
760 SD_MMC_HC_GENERIC_TIMEOUT
762 if (EFI_ERROR (Status)) {
769 ClockCtrl = (UINT16) ~BIT2;
770 Status =
SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_CLOCK_CTRL,
sizeof (ClockCtrl), &ClockCtrl);
796 return SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_CLOCK_CTRL,
sizeof (ClockCtrl), &ClockCtrl);
818 IN SD_MMC_BUS_MODE BusTiming,
819 IN BOOLEAN FirstTimeSetup,
829 UINT16 ControllerVer;
832 PciIo = Private->PciIo;
833 BaseClkFreq = Private->BaseClkFreq[Slot];
834 ControllerVer = Private->ControllerVersion[Slot];
836 if ((BaseClkFreq == 0) || (ClockFreq == 0)) {
837 return EFI_INVALID_PARAMETER;
840 if (ClockFreq > (BaseClkFreq * 1000)) {
841 ClockFreq = BaseClkFreq * 1000;
848 SettingFreq = BaseClkFreq * 1000;
849 while (ClockFreq < SettingFreq) {
852 SettingFreq = (BaseClkFreq * 1000) / (2 * Divisor);
853 Remainder = (BaseClkFreq * 1000) % (2 * Divisor);
854 if ((ClockFreq == SettingFreq) && (Remainder == 0)) {
858 if ((ClockFreq == SettingFreq) && (Remainder != 0)) {
863 DEBUG ((DEBUG_INFO,
"BaseClkFreq %dMHz Divisor %d ClockFreq %dKhz\n", BaseClkFreq, Divisor, ClockFreq));
868 if ((ControllerVer >= SD_MMC_HC_CTRL_VER_300) &&
869 (ControllerVer <= SD_MMC_HC_CTRL_VER_420))
871 ASSERT (Divisor <= 0x3FF);
872 ClockCtrl = ((Divisor & 0xFF) << 8) | ((Divisor & 0x300) >> 2);
873 }
else if ((ControllerVer == SD_MMC_HC_CTRL_VER_100) ||
874 (ControllerVer == SD_MMC_HC_CTRL_VER_200))
879 if (((Divisor - 1) & Divisor) != 0) {
883 ASSERT (Divisor <= 0x80);
884 ClockCtrl = (Divisor & 0xFF) << 8;
886 DEBUG ((DEBUG_ERROR,
"Unknown SD Host Controller Spec version [0x%x]!!!\n", ControllerVer));
887 return EFI_UNSUPPORTED;
894 if (EFI_ERROR (Status)) {
902 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CLOCK_CTRL,
FALSE,
sizeof (ClockCtrl), &ClockCtrl);
903 if (EFI_ERROR (Status)) {
904 DEBUG ((DEBUG_ERROR,
"Set SDCLK Frequency Select and Internal Clock Enable fields fails\n"));
914 SD_MMC_HC_CLOCK_CTRL,
918 SD_MMC_HC_GENERIC_TIMEOUT
920 if (EFI_ERROR (Status)) {
925 if (EFI_ERROR (Status)) {
934 if (!FirstTimeSetup && (mOverride !=
NULL) && (mOverride->NotifyPhase !=
NULL)) {
935 Status = mOverride->NotifyPhase (
936 Private->ControllerHandle,
938 EdkiiSdMmcSwitchClockFreqPost,
941 if (EFI_ERROR (Status)) {
944 "%a: SD/MMC switch clock freq post notifier callback failed - %r\n",
952 Private->Slot[Slot].CurrentFreq = ClockFreq;
982 PowerCtrl &= (UINT8) ~BIT0;
983 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_POWER_CTRL,
FALSE,
sizeof (PowerCtrl), &PowerCtrl);
984 if (EFI_ERROR (Status)) {
992 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_POWER_CTRL,
FALSE,
sizeof (PowerCtrl), &PowerCtrl);
1020 if (BusWidth == 1) {
1021 HostCtrl1 = (UINT8) ~(BIT5 | BIT1);
1022 Status =
SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1,
sizeof (HostCtrl1), &HostCtrl1);
1023 }
else if (BusWidth == 4) {
1024 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1,
TRUE,
sizeof (HostCtrl1), &HostCtrl1);
1025 if (EFI_ERROR (Status)) {
1030 HostCtrl1 &= (UINT8) ~BIT5;
1031 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1,
FALSE,
sizeof (HostCtrl1), &HostCtrl1);
1032 }
else if (BusWidth == 8) {
1033 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1,
TRUE,
sizeof (HostCtrl1), &HostCtrl1);
1034 if (EFI_ERROR (Status)) {
1038 HostCtrl1 &= (UINT8) ~BIT1;
1040 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1,
FALSE,
sizeof (HostCtrl1), &HostCtrl1);
1043 return EFI_INVALID_PARAMETER;
1065 IN UINT16 ControllerVer
1074 if (ControllerVer >= SD_MMC_HC_CTRL_VER_400) {
1075 HostCtrl2 = SD_MMC_HC_V4_EN;
1079 if (ControllerVer == SD_MMC_HC_CTRL_VER_400) {
1083 if (Capability.SysBus64V3 != 0) {
1084 HostCtrl2 |= SD_MMC_HC_64_ADDR_EN;
1085 DEBUG ((DEBUG_INFO,
"Enabled V4 64 bit system bus support\n"));
1091 else if (ControllerVer >= SD_MMC_HC_CTRL_VER_410) {
1095 if (Capability.SysBus64V4 != 0) {
1096 HostCtrl2 |= SD_MMC_HC_64_ADDR_EN;
1097 DEBUG ((DEBUG_INFO,
"Enabled V4 64 bit system bus support\n"));
1100 HostCtrl2 |= SD_MMC_HC_26_DATA_LEN_ADMA_EN;
1101 DEBUG ((DEBUG_INFO,
"Enabled V4 26 bit data length ADMA support\n"));
1104 Status =
SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
1105 if (EFI_ERROR (Status)) {
1140 if (Capability.Voltage33 != 0) {
1145 }
else if (Capability.Voltage30 != 0) {
1150 }
else if (Capability.Voltage18 != 0) {
1156 Status =
SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
1158 if (EFI_ERROR (Status)) {
1163 return EFI_DEVICE_ERROR;
1196 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_TIMEOUT_CTRL,
FALSE,
sizeof (Timeout), &Timeout);
1226 if ((mOverride !=
NULL) && (mOverride->NotifyPhase !=
NULL)) {
1227 Status = mOverride->NotifyPhase (
1228 Private->ControllerHandle,
1230 EdkiiSdMmcInitHostPre,
1233 if (EFI_ERROR (Status)) {
1236 "%a: SD/MMC pre init notifier callback failed - %r\n",
1244 PciIo = Private->PciIo;
1245 Capability = Private->Capability[Slot];
1248 if (EFI_ERROR (Status)) {
1260 if (EFI_ERROR (Status)) {
1265 if (EFI_ERROR (Status)) {
1270 if (EFI_ERROR (Status)) {
1278 if ((mOverride !=
NULL) && (mOverride->NotifyPhase !=
NULL)) {
1279 Status = mOverride->NotifyPhase (
1280 Private->ControllerHandle,
1282 EdkiiSdMmcInitHostPost,
1285 if (EFI_ERROR (Status)) {
1288 "%a: SD/MMC post init notifier callback failed - %r\n",
1314 IN SD_MMC_BUS_MODE Timing
1320 HostCtrl2 = (UINT8) ~SD_MMC_HC_CTRL_UHS_MASK;
1321 Status =
SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
1322 if (EFI_ERROR (Status)) {
1328 HostCtrl2 = SD_MMC_HC_CTRL_UHS_SDR12;
1331 HostCtrl2 = SD_MMC_HC_CTRL_UHS_SDR25;
1334 HostCtrl2 = SD_MMC_HC_CTRL_UHS_SDR50;
1336 case SdMmcUhsSdr104:
1337 HostCtrl2 = SD_MMC_HC_CTRL_UHS_SDR104;
1340 HostCtrl2 = SD_MMC_HC_CTRL_UHS_DDR50;
1342 case SdMmcMmcLegacy:
1343 HostCtrl2 = SD_MMC_HC_CTRL_MMC_LEGACY;
1346 HostCtrl2 = SD_MMC_HC_CTRL_MMC_HS_SDR;
1349 HostCtrl2 = SD_MMC_HC_CTRL_MMC_HS_DDR;
1352 HostCtrl2 = SD_MMC_HC_CTRL_MMC_HS200;
1355 HostCtrl2 = SD_MMC_HC_CTRL_MMC_HS400;
1362 Status =
SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
1363 if (EFI_ERROR (Status)) {
1367 if ((mOverride !=
NULL) && (mOverride->NotifyPhase !=
NULL)) {
1368 Status = mOverride->NotifyPhase (
1371 EdkiiSdMmcUhsSignaling,
1374 if (EFI_ERROR (Status)) {
1377 "%a: SD/MMC uhs signaling notifier callback failed - %r\n",
1402 IN SD_DRIVER_STRENGTH_TYPE DriverStrength
1408 if (DriverStrength == SdDriverStrengthIgnore) {
1412 HostCtrl2 = (UINT16) ~SD_MMC_HC_CTRL_DRIVER_STRENGTH_MASK;
1413 Status =
SdMmcHcAndMmio (PciIo, SlotIndex, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
1414 if (EFI_ERROR (Status)) {
1418 HostCtrl2 = (DriverStrength << 4) & SD_MMC_HC_CTRL_DRIVER_STRENGTH_MASK;
1419 return SdMmcHcOrMmio (PciIo, SlotIndex, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
1445 Status =
SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1,
sizeof (HostCtrl1), &HostCtrl1);
1447 HostCtrl1 = (UINT8) ~BIT0;
1448 Status =
SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1,
sizeof (HostCtrl1), &HostCtrl1);
1469 IN UINT16 ControllerVer
1482 UINT32 AdmaMaxDataPerLine;
1486 AdmaMaxDataPerLine = ADMA_MAX_DATA_PER_LINE_16B;
1490 Data = Trb->DataPhy;
1491 DataLen = Trb->DataLen;
1492 PciIo = Trb->Private->PciIo;
1497 if ((Trb->Mode == SdMmcAdma32bMode) &&
1498 ((Data >= 0x100000000ul) || ((Data + DataLen) > 0x100000000ul)))
1500 return EFI_INVALID_PARAMETER;
1506 if (Trb->Mode != SdMmcAdma32bMode) {
1510 if ((Data & (BIT0 | BIT1 | BIT2)) != 0) {
1511 DEBUG ((DEBUG_INFO,
"The buffer [0x%x] to construct ADMA desc is not aligned to 8 bytes boundary!\n", Data));
1517 if ((Data & (BIT0 | BIT1)) != 0) {
1518 DEBUG ((DEBUG_INFO,
"The buffer [0x%x] to construct ADMA desc is not aligned to 4 bytes boundary!\n", Data));
1525 if (Trb->Mode == SdMmcAdma64bV3Mode) {
1527 }
else if (Trb->Mode == SdMmcAdma64bV4Mode) {
1534 if (Trb->AdmaLengthMode == SdMmcAdmaLen26b) {
1535 AdmaMaxDataPerLine = ADMA_MAX_DATA_PER_LINE_26B;
1538 Entries =
DivU64x32 ((DataLen + AdmaMaxDataPerLine - 1), AdmaMaxDataPerLine);
1541 Status = PciIo->AllocateBuffer (
1549 if (EFI_ERROR (Status)) {
1550 return EFI_OUT_OF_RESOURCES;
1553 ZeroMem (AdmaDesc, TableSize);
1555 Status = PciIo->Map (
1564 if (EFI_ERROR (Status) || (Bytes != TableSize)) {
1573 return EFI_OUT_OF_RESOURCES;
1576 if ((Trb->Mode == SdMmcAdma32bMode) &&
1577 ((UINT64)(
UINTN)Trb->AdmaDescPhy > 0x100000000ul))
1586 Trb->AdmaMap =
NULL;
1593 return EFI_DEVICE_ERROR;
1596 Remaining = DataLen;
1598 if (Trb->Mode == SdMmcAdma32bMode) {
1599 Trb->Adma32Desc = AdmaDesc;
1600 }
else if (Trb->Mode == SdMmcAdma64bV3Mode) {
1601 Trb->Adma64V3Desc = AdmaDesc;
1603 Trb->Adma64V4Desc = AdmaDesc;
1606 for (Index = 0; Index < Entries; Index++) {
1607 if (Trb->Mode == SdMmcAdma32bMode) {
1608 if (Remaining <= AdmaMaxDataPerLine) {
1609 Trb->Adma32Desc[Index].Valid = 1;
1610 Trb->Adma32Desc[Index].Act = 2;
1611 if (Trb->AdmaLengthMode == SdMmcAdmaLen26b) {
1612 Trb->Adma32Desc[Index].UpperLength = (UINT16)
RShiftU64 (Remaining, 16);
1615 Trb->Adma32Desc[Index].LowerLength = (UINT16)(Remaining & MAX_UINT16);
1616 Trb->Adma32Desc[Index].Address = (UINT32)Address;
1619 Trb->Adma32Desc[Index].Valid = 1;
1620 Trb->Adma32Desc[Index].Act = 2;
1621 if (Trb->AdmaLengthMode == SdMmcAdmaLen26b) {
1622 Trb->Adma32Desc[Index].UpperLength = 0;
1625 Trb->Adma32Desc[Index].LowerLength = 0;
1626 Trb->Adma32Desc[Index].Address = (UINT32)Address;
1628 }
else if (Trb->Mode == SdMmcAdma64bV3Mode) {
1629 if (Remaining <= AdmaMaxDataPerLine) {
1630 Trb->Adma64V3Desc[Index].Valid = 1;
1631 Trb->Adma64V3Desc[Index].Act = 2;
1632 if (Trb->AdmaLengthMode == SdMmcAdmaLen26b) {
1633 Trb->Adma64V3Desc[Index].UpperLength = (UINT16)
RShiftU64 (Remaining, 16);
1636 Trb->Adma64V3Desc[Index].LowerLength = (UINT16)(Remaining & MAX_UINT16);
1637 Trb->Adma64V3Desc[Index].LowerAddress = (UINT32)Address;
1638 Trb->Adma64V3Desc[Index].UpperAddress = (UINT32)
RShiftU64 (Address, 32);
1641 Trb->Adma64V3Desc[Index].Valid = 1;
1642 Trb->Adma64V3Desc[Index].Act = 2;
1643 if (Trb->AdmaLengthMode == SdMmcAdmaLen26b) {
1644 Trb->Adma64V3Desc[Index].UpperLength = 0;
1647 Trb->Adma64V3Desc[Index].LowerLength = 0;
1648 Trb->Adma64V3Desc[Index].LowerAddress = (UINT32)Address;
1649 Trb->Adma64V3Desc[Index].UpperAddress = (UINT32)
RShiftU64 (Address, 32);
1652 if (Remaining <= AdmaMaxDataPerLine) {
1653 Trb->Adma64V4Desc[Index].Valid = 1;
1654 Trb->Adma64V4Desc[Index].Act = 2;
1655 if (Trb->AdmaLengthMode == SdMmcAdmaLen26b) {
1656 Trb->Adma64V4Desc[Index].UpperLength = (UINT16)
RShiftU64 (Remaining, 16);
1659 Trb->Adma64V4Desc[Index].LowerLength = (UINT16)(Remaining & MAX_UINT16);
1660 Trb->Adma64V4Desc[Index].LowerAddress = (UINT32)Address;
1661 Trb->Adma64V4Desc[Index].UpperAddress = (UINT32)
RShiftU64 (Address, 32);
1664 Trb->Adma64V4Desc[Index].Valid = 1;
1665 Trb->Adma64V4Desc[Index].Act = 2;
1666 if (Trb->AdmaLengthMode == SdMmcAdmaLen26b) {
1667 Trb->Adma64V4Desc[Index].UpperLength = 0;
1670 Trb->Adma64V4Desc[Index].LowerLength = 0;
1671 Trb->Adma64V4Desc[Index].LowerAddress = (UINT32)Address;
1672 Trb->Adma64V4Desc[Index].UpperAddress = (UINT32)
RShiftU64 (Address, 32);
1676 Remaining -= AdmaMaxDataPerLine;
1677 Address += AdmaMaxDataPerLine;
1683 if (Trb->Mode == SdMmcAdma32bMode) {
1684 Trb->Adma32Desc[Index].End = 1;
1685 }
else if (Trb->Mode == SdMmcAdma64bV3Mode) {
1686 Trb->Adma64V3Desc[Index].End = 1;
1688 Trb->Adma64V4Desc[Index].End = 1;
1702 IN UINT32 DebugLevel,
1706 if (Packet ==
NULL) {
1710 DEBUG ((DebugLevel,
"Printing EFI_SD_MMC_PASS_THRU_COMMAND_PACKET\n"));
1711 if (Packet->SdMmcCmdBlk !=
NULL) {
1712 DEBUG ((DebugLevel,
"Command index: %d, argument: %X\n", Packet->SdMmcCmdBlk->CommandIndex, Packet->SdMmcCmdBlk->CommandArgument));
1713 DEBUG ((DebugLevel,
"Command type: %d, response type: %d\n", Packet->SdMmcCmdBlk->CommandType, Packet->SdMmcCmdBlk->ResponseType));
1716 if (Packet->SdMmcStatusBlk !=
NULL) {
1719 "Response 0: %X, 1: %X, 2: %X, 3: %X\n",
1720 Packet->SdMmcStatusBlk->Resp0,
1721 Packet->SdMmcStatusBlk->Resp1,
1722 Packet->SdMmcStatusBlk->Resp2,
1723 Packet->SdMmcStatusBlk->Resp3
1727 DEBUG ((DebugLevel,
"Timeout: %ld\n", Packet->Timeout));
1728 DEBUG ((DebugLevel,
"InDataBuffer: %p\n", Packet->InDataBuffer));
1729 DEBUG ((DebugLevel,
"OutDataBuffer: %p\n", Packet->OutDataBuffer));
1730 DEBUG ((DebugLevel,
"InTransferLength: %d\n", Packet->InTransferLength));
1731 DEBUG ((DebugLevel,
"OutTransferLength: %d\n", Packet->OutTransferLength));
1732 DEBUG ((DebugLevel,
"TransactionStatus: %r\n", Packet->TransactionStatus));
1743 IN UINT32 DebugLevel,
1751 DEBUG ((DebugLevel,
"Printing SD_MMC_HC_TRB\n"));
1752 DEBUG ((DebugLevel,
"Slot: %d\n", Trb->Slot));
1753 DEBUG ((DebugLevel,
"BlockSize: %d\n", Trb->BlockSize));
1754 DEBUG ((DebugLevel,
"Data: %p\n", Trb->Data));
1755 DEBUG ((DebugLevel,
"DataLen: %d\n", Trb->DataLen));
1756 DEBUG ((DebugLevel,
"Read: %d\n", Trb->Read));
1757 DEBUG ((DebugLevel,
"DataPhy: %lX\n", Trb->DataPhy));
1758 DEBUG ((DebugLevel,
"DataMap: %p\n", Trb->DataMap));
1759 DEBUG ((DebugLevel,
"Mode: %d\n", Trb->Mode));
1760 DEBUG ((DebugLevel,
"AdmaLengthMode: %d\n", Trb->AdmaLengthMode));
1761 DEBUG ((DebugLevel,
"Event: %p\n", Trb->Event));
1762 DEBUG ((DebugLevel,
"Started: %d\n", Trb->Started));
1763 DEBUG ((DebugLevel,
"CommandComplete: %d\n", Trb->CommandComplete));
1764 DEBUG ((DebugLevel,
"Timeout: %ld\n", Trb->Timeout));
1765 DEBUG ((DebugLevel,
"Retries: %d\n", Trb->Retries));
1766 DEBUG ((DebugLevel,
"PioModeTransferCompleted: %d\n", Trb->PioModeTransferCompleted));
1767 DEBUG ((DebugLevel,
"PioBlockIndex: %d\n", Trb->PioBlockIndex));
1768 DEBUG ((DebugLevel,
"Adma32Desc: %p\n", Trb->Adma32Desc));
1769 DEBUG ((DebugLevel,
"Adma64V3Desc: %p\n", Trb->Adma64V3Desc));
1770 DEBUG ((DebugLevel,
"Adma64V4Desc: %p\n", Trb->Adma64V4Desc));
1771 DEBUG ((DebugLevel,
"AdmaMap: %p\n", Trb->AdmaMap));
1772 DEBUG ((DebugLevel,
"AdmaPages: %X\n", Trb->AdmaPages));
1805 PciIo = Private->PciIo;
1806 if ((Trb->Data !=
NULL) && (Trb->DataLen != 0)) {
1807 MapLength = Trb->DataLen;
1808 Status = PciIo->Map (
1816 if (EFI_ERROR (Status) || (Trb->DataLen != MapLength)) {
1817 return EFI_BAD_BUFFER_SIZE;
1821 if ((Trb->Mode == SdMmcAdma32bMode) ||
1822 (Trb->Mode == SdMmcAdma64bV3Mode) ||
1823 (Trb->Mode == SdMmcAdma64bV4Mode))
1826 if (EFI_ERROR (Status)) {
1864 Trb->Signature = SD_MMC_HC_TRB_SIG;
1866 Trb->BlockSize = 0x200;
1867 Trb->Packet = Packet;
1869 Trb->Started =
FALSE;
1870 Trb->CommandComplete =
FALSE;
1871 Trb->Timeout = Packet->Timeout;
1872 Trb->Retries = SD_MMC_TRB_RETRIES;
1873 Trb->PioModeTransferCompleted =
FALSE;
1874 Trb->PioBlockIndex = 0;
1875 Trb->Private = Private;
1877 if ((Packet->InTransferLength != 0) && (Packet->InDataBuffer !=
NULL)) {
1878 Trb->Data = Packet->InDataBuffer;
1879 Trb->DataLen = Packet->InTransferLength;
1881 }
else if ((Packet->OutTransferLength != 0) && (Packet->OutDataBuffer !=
NULL)) {
1882 Trb->Data = Packet->OutDataBuffer;
1883 Trb->DataLen = Packet->OutTransferLength;
1885 }
else if ((Packet->InTransferLength == 0) && (Packet->OutTransferLength == 0)) {
1892 if ((Trb->DataLen != 0) && (Trb->DataLen < Trb->BlockSize)) {
1893 Trb->BlockSize = (UINT16)Trb->DataLen;
1896 if (((Private->Slot[Trb->Slot].CardType == EmmcCardType) &&
1897 (Packet->SdMmcCmdBlk->CommandIndex == EMMC_SEND_TUNING_BLOCK)) ||
1898 ((Private->Slot[Trb->Slot].CardType == SdCardType) &&
1899 (Packet->SdMmcCmdBlk->CommandIndex == SD_SEND_TUNING_BLOCK)))
1901 Trb->Mode = SdMmcPioMode;
1903 if (Trb->DataLen == 0) {
1904 Trb->Mode = SdMmcNoData;
1905 }
else if (Private->Capability[Slot].Adma2 != 0) {
1906 Trb->Mode = SdMmcAdma32bMode;
1907 Trb->AdmaLengthMode = SdMmcAdmaLen16b;
1908 if ((Private->ControllerVersion[Slot] == SD_MMC_HC_CTRL_VER_300) &&
1909 (Private->Capability[Slot].SysBus64V3 == 1))
1911 Trb->Mode = SdMmcAdma64bV3Mode;
1912 }
else if (((Private->ControllerVersion[Slot] == SD_MMC_HC_CTRL_VER_400) &&
1913 (Private->Capability[Slot].SysBus64V3 == 1)) ||
1914 ((Private->ControllerVersion[Slot] >= SD_MMC_HC_CTRL_VER_410) &&
1915 (Private->Capability[Slot].SysBus64V4 == 1)))
1917 Trb->Mode = SdMmcAdma64bV4Mode;
1920 if (Private->ControllerVersion[Slot] >= SD_MMC_HC_CTRL_VER_410) {
1921 Trb->AdmaLengthMode = SdMmcAdmaLen26b;
1925 if (EFI_ERROR (Status)) {
1928 }
else if (Private->Capability[Slot].Sdma != 0) {
1929 Trb->Mode = SdMmcSdmaMode;
1931 if (EFI_ERROR (Status)) {
1935 Trb->Mode = SdMmcPioMode;
1939 if (Event !=
NULL) {
1940 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1942 gBS->RestoreTPL (OldTpl);
1965 PciIo = Trb->Private->PciIo;
1967 if (Trb->AdmaMap !=
NULL) {
1974 if (Trb->Adma32Desc !=
NULL) {
1982 if (Trb->Adma64V3Desc !=
NULL) {
1990 if (Trb->Adma64V4Desc !=
NULL) {
1998 if (Trb->DataMap !=
NULL) {
2029 UINT32 PresentState;
2031 Packet = Trb->Packet;
2033 if ((Packet->SdMmcCmdBlk->CommandType == SdMmcCommandTypeAdtc) ||
2034 (Packet->SdMmcCmdBlk->ResponseType == SdMmcResponseTypeR1b) ||
2035 (Packet->SdMmcCmdBlk->ResponseType == SdMmcResponseTypeR5b))
2041 PresentState = BIT0 | BIT1;
2047 PresentState = BIT0;
2050 PciIo = Private->PciIo;
2054 SD_MMC_HC_PRESENT_STATE,
2055 sizeof (PresentState),
2083 BOOLEAN InfiniteWait;
2088 Packet = Trb->Packet;
2089 Timeout = Packet->Timeout;
2091 InfiniteWait =
TRUE;
2093 InfiniteWait =
FALSE;
2096 while (InfiniteWait || (Timeout > 0)) {
2101 if (Status != EFI_NOT_READY) {
2144 BOOLEAN AddressingMode64;
2146 AddressingMode64 =
FALSE;
2148 Packet = Trb->Packet;
2149 PciIo = Trb->Private->PciIo;
2154 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_ERR_INT_STS,
FALSE, sizeof (IntStatus), &IntStatus);
2155 if (EFI_ERROR (Status)) {
2163 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_NOR_INT_STS,
FALSE, sizeof (IntStatus), &IntStatus);
2164 if (EFI_ERROR (Status)) {
2168 if (Private->ControllerVersion[Trb->Slot] >= SD_MMC_HC_CTRL_VER_400) {
2172 SD_MMC_HC_HOST_CTRL2,
2174 SD_MMC_HC_64_ADDR_EN,
2175 SD_MMC_HC_64_ADDR_EN
2177 if (!EFI_ERROR (Status)) {
2178 AddressingMode64 =
TRUE;
2185 if ((Trb->Mode == SdMmcAdma32bMode) ||
2186 (Trb->Mode == SdMmcAdma64bV4Mode))
2189 Status =
SdMmcHcOrMmio (PciIo, Trb->Slot, SD_MMC_HC_HOST_CTRL1, sizeof (HostCtrl1), &HostCtrl1);
2190 if (EFI_ERROR (Status)) {
2193 }
else if (Trb->Mode == SdMmcAdma64bV3Mode) {
2194 HostCtrl1 = BIT4|BIT3;
2195 Status =
SdMmcHcOrMmio (PciIo, Trb->Slot, SD_MMC_HC_HOST_CTRL1, sizeof (HostCtrl1), &HostCtrl1);
2196 if (EFI_ERROR (Status)) {
2203 if (Trb->Mode == SdMmcSdmaMode) {
2204 if ((!AddressingMode64) &&
2205 ((UINT64)(
UINTN)Trb->DataPhy >= 0x100000000ul))
2207 return EFI_INVALID_PARAMETER;
2210 SdmaAddr = (UINT64)(
UINTN)Trb->DataPhy;
2212 if (Private->ControllerVersion[Trb->Slot] >= SD_MMC_HC_CTRL_VER_400) {
2213 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_ADMA_SYS_ADDR,
FALSE, sizeof (UINT64), &SdmaAddr);
2215 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_SDMA_ADDR,
FALSE, sizeof (UINT32), &SdmaAddr);
2218 if (EFI_ERROR (Status)) {
2221 }
else if ((Trb->Mode == SdMmcAdma32bMode) ||
2222 (Trb->Mode == SdMmcAdma64bV3Mode) ||
2223 (Trb->Mode == SdMmcAdma64bV4Mode))
2225 AdmaAddr = (UINT64)(
UINTN)Trb->AdmaDescPhy;
2226 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_ADMA_SYS_ADDR,
FALSE, sizeof (AdmaAddr), &AdmaAddr);
2227 if (EFI_ERROR (Status)) {
2232 BlkSize = Trb->BlockSize;
2233 if (Trb->Mode == SdMmcSdmaMode) {
2240 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_BLK_SIZE,
FALSE, sizeof (BlkSize), &BlkSize);
2241 if (EFI_ERROR (Status)) {
2246 if (Trb->Mode != SdMmcNoData) {
2250 BlkCount = (Trb->DataLen / Trb->BlockSize);
2253 if (Private->ControllerVersion[Trb->Slot] >= SD_MMC_HC_CTRL_VER_410) {
2254 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_SDMA_ADDR,
FALSE, sizeof (UINT32), &BlkCount);
2256 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_BLK_COUNT,
FALSE, sizeof (UINT16), &BlkCount);
2259 if (EFI_ERROR (Status)) {
2263 Argument = Packet->SdMmcCmdBlk->CommandArgument;
2264 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_ARG1,
FALSE, sizeof (Argument), &Argument);
2265 if (EFI_ERROR (Status)) {
2270 if (Trb->Mode != SdMmcNoData) {
2271 if (Trb->Mode != SdMmcPioMode) {
2280 TransMode |= BIT5 | BIT1;
2286 if (Private->Slot[Trb->Slot].CardType == SdCardType) {
2293 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_TRANS_MOD,
FALSE, sizeof (TransMode), &TransMode);
2294 if (EFI_ERROR (Status)) {
2298 Cmd = (UINT16)
LShiftU64 (Packet->SdMmcCmdBlk->CommandIndex, 8);
2299 if (Packet->SdMmcCmdBlk->CommandType == SdMmcCommandTypeAdtc) {
2306 if (Packet->SdMmcCmdBlk->CommandType != SdMmcCommandTypeBc) {
2307 switch (Packet->SdMmcCmdBlk->ResponseType) {
2308 case SdMmcResponseTypeR1:
2309 case SdMmcResponseTypeR5:
2310 case SdMmcResponseTypeR6:
2311 case SdMmcResponseTypeR7:
2312 Cmd |= (BIT1 | BIT3 | BIT4);
2314 case SdMmcResponseTypeR2:
2315 Cmd |= (BIT0 | BIT3);
2317 case SdMmcResponseTypeR3:
2318 case SdMmcResponseTypeR4:
2321 case SdMmcResponseTypeR1b:
2322 case SdMmcResponseTypeR5b:
2323 Cmd |= (BIT0 | BIT1 | BIT3 | BIT4);
2334 Status =
SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_COMMAND,
FALSE, sizeof (Cmd), &Cmd);
2352 IN UINT16 ErrIntStatus
2359 if ((ErrIntStatus & 0x0F) != 0) {
2363 if ((ErrIntStatus & 0x70) != 0) {
2375 if (EFI_ERROR (Status)) {
2386 SD_MMC_HC_GENERIC_TIMEOUT
2388 if (EFI_ERROR (Status)) {
2416 UINT16 ErrIntStatus;
2420 if ((IntStatus & BIT15) == 0) {
2427 SD_MMC_HC_ERR_INT_STS,
2429 sizeof (ErrIntStatus),
2432 if (EFI_ERROR (Status)) {
2436 DEBUG ((DEBUG_ERROR,
"Error reported by SDHCI\n"));
2437 DEBUG ((DEBUG_ERROR,
"Interrupt status = %X\n", IntStatus));
2438 DEBUG ((DEBUG_ERROR,
"Error interrupt status = %X\n", ErrIntStatus));
2449 if (((ErrIntStatus & BIT4) != 0) && ((IntStatus & BIT1) != 0)) {
2460 if ((ErrIntStatus & (BIT1 | BIT2 | BIT5 | BIT6)) != 0) {
2461 ErrorStatus = EFI_CRC_ERROR;
2463 ErrorStatus = EFI_DEVICE_ERROR;
2467 if (EFI_ERROR (Status)) {
2496 Packet = Trb->Packet;
2498 if (Packet->SdMmcCmdBlk->CommandType == SdMmcCommandTypeBc) {
2502 for (Index = 0; Index < 4; Index++) {
2506 SD_MMC_HC_RESPONSE + Index * 4,
2511 if (EFI_ERROR (Status)) {
2516 CopyMem (Packet->SdMmcStatusBlk, Response, sizeof (Response));
2544 if ((IntStatus & BIT0) != 0) {
2549 SD_MMC_HC_NOR_INT_STS,
2554 if (EFI_ERROR (Status)) {
2559 if (EFI_ERROR (Status)) {
2563 Trb->CommandComplete =
TRUE;
2567 return EFI_NOT_READY;
2594 BlockCount = (Trb->DataLen / Trb->BlockSize);
2595 if (Trb->DataLen % Trb->BlockSize != 0) {
2599 if (Trb->PioBlockIndex >= BlockCount) {
2603 switch (Trb->BlockSize % sizeof (UINT32)) {
2605 Width = EfiPciIoWidthFifoUint32;
2606 Count = Trb->BlockSize /
sizeof (UINT32);
2609 Width = EfiPciIoWidthFifoUint16;
2610 Count = Trb->BlockSize /
sizeof (UINT16);
2615 Width = EfiPciIoWidthFifoUint8;
2616 Count = Trb->BlockSize;
2621 if ((IntStatus & BIT5) == 0) {
2622 return EFI_NOT_READY;
2626 SdMmcHcRwMmio (Private->PciIo, Trb->Slot, SD_MMC_HC_NOR_INT_STS,
FALSE, sizeof (Data16), &Data16);
2628 Status = Private->PciIo->Mem.Read (
2632 SD_MMC_HC_BUF_DAT_PORT,
2634 (VOID *)((UINT8 *)Trb->Data + (Trb->BlockSize * Trb->PioBlockIndex))
2636 if (EFI_ERROR (Status)) {
2640 Trb->PioBlockIndex++;
2642 if ((IntStatus & BIT4) == 0) {
2643 return EFI_NOT_READY;
2647 SdMmcHcRwMmio (Private->PciIo, Trb->Slot, SD_MMC_HC_NOR_INT_STS,
FALSE, sizeof (Data16), &Data16);
2649 Status = Private->PciIo->Mem.Write (
2653 SD_MMC_HC_BUF_DAT_PORT,
2655 (VOID *)((UINT8 *)Trb->Data + (Trb->BlockSize * Trb->PioBlockIndex))
2657 if (EFI_ERROR (Status)) {
2661 Trb->PioBlockIndex++;
2664 if (Trb->PioBlockIndex >= BlockCount) {
2665 Trb->PioModeTransferCompleted =
TRUE;
2668 return EFI_NOT_READY;
2690 SdmaAddr = SD_MMC_SDMA_ROUND_UP ((
UINTN)Trb->DataPhy, SD_MMC_SDMA_BOUNDARY);
2692 if (Private->ControllerVersion[Trb->Slot] >= SD_MMC_HC_CTRL_VER_400) {
2696 SD_MMC_HC_ADMA_SYS_ADDR,
2705 SD_MMC_HC_SDMA_ADDR,
2712 if (EFI_ERROR (Status)) {
2716 Trb->DataPhy = (UINT64)(
UINTN)SdmaAddr;
2743 if ((IntStatus & BIT1) != 0) {
2748 SD_MMC_HC_NOR_INT_STS,
2756 if ((Trb->Mode == SdMmcPioMode) && !Trb->PioModeTransferCompleted) {
2758 if (EFI_ERROR (Status)) {
2763 if ((Trb->Mode == SdMmcSdmaMode) && ((IntStatus & BIT3) != 0)) {
2768 SD_MMC_HC_NOR_INT_STS,
2773 if (EFI_ERROR (Status)) {
2778 if (EFI_ERROR (Status)) {
2783 return EFI_NOT_READY;
2807 Packet = Trb->Packet;
2814 SD_MMC_HC_NOR_INT_STS,
2819 if (EFI_ERROR (Status)) {
2828 if (EFI_ERROR (Status)) {
2837 if (((Private->Slot[Trb->Slot].CardType == EmmcCardType) &&
2838 (Packet->SdMmcCmdBlk->CommandIndex == EMMC_SEND_TUNING_BLOCK)) ||
2839 ((Private->Slot[Trb->Slot].CardType == SdCardType) &&
2840 (Packet->SdMmcCmdBlk->CommandIndex == SD_SEND_TUNING_BLOCK)))
2846 if (!Trb->CommandComplete) {
2848 if (EFI_ERROR (Status)) {
2853 if ((Packet->SdMmcCmdBlk->CommandType == SdMmcCommandTypeAdtc) ||
2854 (Packet->SdMmcCmdBlk->ResponseType == SdMmcResponseTypeR1b) ||
2855 (Packet->SdMmcCmdBlk->ResponseType == SdMmcResponseTypeR5b))
2863 if (Status != EFI_NOT_READY) {
2865 if (EFI_ERROR (Status)) {
2866 DEBUG ((DEBUG_ERROR,
"TRB failed with %r\n", Status));
2869 DEBUG ((DEBUG_VERBOSE,
"TRB success\n"));
2896 BOOLEAN InfiniteWait;
2898 Packet = Trb->Packet;
2902 Timeout = Packet->Timeout;
2904 InfiniteWait =
TRUE;
2906 InfiniteWait =
FALSE;
2909 while (InfiniteWait || (Timeout > 0)) {
2914 if (Status != EFI_NOT_READY) {
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
INTN EFIAPI HighBitSet32(IN UINT32 Operand)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
EFI_PCI_IO_PROTOCOL_WIDTH
EFI_PCI_IO_PROTOCOL_OPERATION
@ EfiPciIoOperationBusMasterWrite
@ EfiPciIoOperationBusMasterRead
@ EfiPciIoOperationBusMasterCommonBuffer
EFI_STATUS SdMmcHcInitPowerVoltage(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN SD_MMC_HC_SLOT_CAP Capability)
EFI_STATUS BuildAdmaDescTable(IN SD_MMC_HC_TRB *Trb, IN UINT16 ControllerVer)
EFI_STATUS SdMmcHcReset(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
VOID SdMmcPrintTrb(IN UINT32 DebugLevel, IN SD_MMC_HC_TRB *Trb)
EFI_STATUS SdMmcWaitTrbEnv(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
EFI_STATUS SdMmcCheckDataTransfer(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb, IN UINT16 IntStatus)
EFI_STATUS SdMmcUpdateSdmaAddress(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
EFI_STATUS SdMmcHcCardDetect(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, OUT BOOLEAN *MediaPresent)
EFI_STATUS EFIAPI SdMmcHcRwMmio(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN BOOLEAN Read, IN UINT8 Count, IN OUT VOID *Data)
EFI_STATUS SdMmcCheckTrbResult(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
SD_MMC_HC_TRB * SdMmcCreateTrb(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot, IN EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet, IN EFI_EVENT Event)
EFI_STATUS SdMmcHcStartSdClock(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
EFI_STATUS SdMmcHcInitHost(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
EFI_STATUS SdMmcCheckAndRecoverErrors(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot, IN UINT16 IntStatus)
EFI_STATUS SdMmcHcGetMaxCurrent(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, OUT UINT64 *MaxCurrent)
EFI_STATUS SdMmcSetDriverStrength(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 SlotIndex, IN SD_DRIVER_STRENGTH_TYPE DriverStrength)
VOID SdMmcPrintPacket(IN UINT32 DebugLevel, IN EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet)
EFI_STATUS SdMmcCheckTrbEnv(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
EFI_STATUS SdMmcHcInitV4Enhancements(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN SD_MMC_HC_SLOT_CAP Capability, IN UINT16 ControllerVer)
EFI_STATUS SdMmcHcUhsSignaling(IN EFI_HANDLE ControllerHandle, IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN SD_MMC_BUS_MODE Timing)
EFI_STATUS EFIAPI SdMmcHcGetSlotInfo(IN EFI_PCI_IO_PROTOCOL *PciIo, OUT UINT8 *FirstBar, OUT UINT8 *SlotNum)
EFI_STATUS SdMmcHcClockSupply(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot, IN SD_MMC_BUS_MODE BusTiming, IN BOOLEAN FirstTimeSetup, IN UINT64 ClockFreq)
EFI_STATUS SdMmcTransferDataWithPio(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb, IN UINT16 IntStatus)
EFI_STATUS SdMmcGetResponse(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
EFI_STATUS EFIAPI SdMmcHcAndMmio(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN VOID *AndData)
EFI_STATUS SdMmcHcGetCapability(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, OUT SD_MMC_HC_SLOT_CAP *Capability)
EFI_STATUS SdMmcHcInitTimeoutCtrl(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
EFI_STATUS SdMmcHcStopClock(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
EFI_STATUS SdMmcHcPowerControl(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN UINT8 PowerCtrl)
EFI_STATUS SdMmcCheckCommandComplete(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb, IN UINT16 IntStatus)
EFI_STATUS SdMmcHcGetControllerVersion(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, OUT UINT16 *Version)
EFI_STATUS SdMmcSoftwareReset(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot, IN UINT16 ErrIntStatus)
EFI_STATUS SdMmcSetupMemoryForDmaTransfer(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot, IN SD_MMC_HC_TRB *Trb)
EFI_STATUS SdMmcHcLedOnOff(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN BOOLEAN On)
EFI_STATUS SdMmcWaitTrbResult(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
EFI_STATUS EFIAPI SdMmcHcWaitMmioSet(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN UINT64 MaskValue, IN UINT64 TestValue, IN UINT64 Timeout)
VOID DumpCapabilityReg(IN UINT8 Slot, IN SD_MMC_HC_SLOT_CAP *Capability)
EFI_STATUS EFIAPI SdMmcHcCheckMmioSet(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN UINT64 MaskValue, IN UINT64 TestValue)
EFI_STATUS SdMmcHcSetBusWidth(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN UINT16 BusWidth)
EFI_STATUS SdMmcHcEnableInterrupt(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
VOID SdMmcFreeTrb(IN SD_MMC_HC_TRB *Trb)
EFI_STATUS SdMmcExecTrb(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
EFI_STATUS EFIAPI SdMmcHcOrMmio(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN VOID *OrData)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_SIZE_TO_PAGES(Size)