35 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
36 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
37 ZeroMem (&Packet,
sizeof (Packet));
39 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
40 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
41 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
43 SdMmcCmdBlk.CommandIndex = SD_GO_IDLE_STATE;
44 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBc;
70 IN UINT8 SupplyVoltage,
79 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
80 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
81 ZeroMem (&Packet,
sizeof (Packet));
83 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
84 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
85 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
87 SdMmcCmdBlk.CommandIndex = SD_SEND_IF_COND;
88 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
89 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR7;
90 SdMmcCmdBlk.CommandArgument = (SupplyVoltage << 8) | CheckPattern;
94 if (!EFI_ERROR (Status)) {
95 if (SdMmcStatusBlk.Resp0 != SdMmcCmdBlk.CommandArgument) {
96 return EFI_DEVICE_ERROR;
121 IN UINT32 VoltageWindow,
131 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
132 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
133 ZeroMem (&Packet,
sizeof (Packet));
135 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
136 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
137 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
139 SdMmcCmdBlk.CommandIndex = SDIO_SEND_OP_COND;
140 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
141 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR4;
143 Switch = S18R ? BIT24 : 0;
145 SdMmcCmdBlk.CommandArgument = (VoltageWindow & 0xFFFFFF) | Switch;
175 IN UINT32 VoltageWindow,
190 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
191 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
192 ZeroMem (&Packet,
sizeof (Packet));
194 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
195 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
196 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
198 SdMmcCmdBlk.CommandIndex = SD_APP_CMD;
199 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
200 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
201 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
204 if (EFI_ERROR (Status)) {
208 SdMmcCmdBlk.CommandIndex = SD_SEND_OP_COND;
209 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
210 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR3;
212 Switch = S18R ? BIT24 : 0;
213 MaxPower = Xpc ? BIT28 : 0;
214 HostCapacity = Hcs ? BIT30 : 0;
216 SdMmcCmdBlk.CommandArgument = (VoltageWindow & 0xFFFFFF) | Switch | MaxPower | HostCapacity;
219 if (!EFI_ERROR (Status)) {
223 *Ocr = SdMmcStatusBlk.Resp0;
253 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
254 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
255 ZeroMem (&Packet,
sizeof (Packet));
257 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
258 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
259 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
261 SdMmcCmdBlk.CommandIndex = SD_ALL_SEND_CID;
262 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
263 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR2;
296 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
297 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
298 ZeroMem (&Packet,
sizeof (Packet));
300 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
301 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
302 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
304 SdMmcCmdBlk.CommandIndex = SD_SET_RELATIVE_ADDR;
305 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
306 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR6;
309 if (!EFI_ERROR (Status)) {
310 *Rca = (UINT16)(SdMmcStatusBlk.Resp0 >> 16);
341 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
342 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
343 ZeroMem (&Packet,
sizeof (Packet));
345 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
346 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
347 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
349 SdMmcCmdBlk.CommandIndex = SD_SELECT_DESELECT_CARD;
350 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
352 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
355 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
385 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
386 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
387 ZeroMem (&Packet,
sizeof (Packet));
389 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
390 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
391 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
393 SdMmcCmdBlk.CommandIndex = SD_VOLTAGE_SWITCH;
394 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
395 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
396 SdMmcCmdBlk.CommandArgument = 0;
431 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
432 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
433 ZeroMem (&Packet,
sizeof (Packet));
435 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
436 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
437 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
439 SdMmcCmdBlk.CommandIndex = SD_APP_CMD;
440 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
441 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
442 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
445 if (EFI_ERROR (Status)) {
449 SdMmcCmdBlk.CommandIndex = SD_SET_BUS_WIDTH;
450 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
451 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
455 }
else if (BusWidth == 4) {
458 return EFI_INVALID_PARAMETER;
461 SdMmcCmdBlk.CommandArgument = Value & 0x3;
489 IN SD_MMC_BUS_MODE BusTiming,
490 IN UINT8 CommandSystem,
491 IN SD_DRIVER_STRENGTH_TYPE DriverStrength,
494 OUT UINT8 *SwitchResp
504 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
505 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
506 ZeroMem (&Packet,
sizeof (Packet));
508 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
509 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
510 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
512 SdMmcCmdBlk.CommandIndex = SD_SWITCH_FUNC;
513 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
514 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
516 ModeValue = Mode ? BIT31 : 0;
540 SdMmcCmdBlk.CommandArgument = (AccessMode & 0xF) | ((CommandSystem & 0xF) << 4) | \
541 ((DriverStrength & 0xF) << 8) | ((PowerLimit & 0xF) << 12) | \
544 Packet.InDataBuffer = SwitchResp;
545 Packet.InTransferLength = 64;
548 if (EFI_ERROR (Status)) {
553 if ((((AccessMode & 0xF) != 0xF) && ((SwitchResp[16] & 0xF) != AccessMode)) ||
554 (((CommandSystem & 0xF) != 0xF) && (((SwitchResp[16] >> 4) & 0xF) != CommandSystem)) ||
555 (((DriverStrength & 0xF) != 0xF) && ((SwitchResp[15] & 0xF) != DriverStrength)) ||
556 (((PowerLimit & 0xF) != 0xF) && (((SwitchResp[15] >> 4) & 0xF) != PowerLimit)))
558 return EFI_DEVICE_ERROR;
584 OUT UINT32 *DevStatus
592 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
593 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
594 ZeroMem (&Packet,
sizeof (Packet));
596 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
597 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
598 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
600 SdMmcCmdBlk.CommandIndex = SD_SEND_STATUS;
601 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
602 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
603 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
606 if (!EFI_ERROR (Status)) {
607 *DevStatus = SdMmcStatusBlk.Resp0;
638 UINT8 TuningBlock[64];
640 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
641 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
642 ZeroMem (&Packet,
sizeof (Packet));
644 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
645 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
646 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
648 SdMmcCmdBlk.CommandIndex = SD_SEND_TUNING_BLOCK;
649 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
650 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
651 SdMmcCmdBlk.CommandArgument = 0;
653 Packet.InDataBuffer = TuningBlock;
654 Packet.InTransferLength =
sizeof (TuningBlock);
693 Status =
SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
694 if (EFI_ERROR (Status)) {
704 if (EFI_ERROR (Status)) {
705 DEBUG ((DEBUG_ERROR,
"SdCardSendTuningBlk: Send tuning block fails with %r\n", Status));
709 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
TRUE,
sizeof (HostCtrl2), &HostCtrl2);
710 if (EFI_ERROR (Status)) {
714 if ((HostCtrl2 & (BIT6 | BIT7)) == 0) {
718 if ((HostCtrl2 & (BIT6 | BIT7)) == BIT7) {
721 }
while (++Retry < 40);
723 DEBUG ((DEBUG_ERROR,
"SdCardTuningClock: Send tuning block fails at %d times with HostCtrl2 %02x\n", Retry, HostCtrl2));
727 HostCtrl2 = (UINT8) ~(BIT6 | BIT7);
728 Status =
SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
729 if (EFI_ERROR (Status)) {
733 return EFI_DEVICE_ERROR;
765 if (EFI_ERROR (Status)) {
766 DEBUG ((DEBUG_ERROR,
"SdCardSwitchBusWidth: Switch to bus width %d fails with %r\n", BusWidth, Status));
771 if (EFI_ERROR (Status)) {
772 DEBUG ((DEBUG_ERROR,
"SdCardSwitchBusWidth: Send status fails with %r\n", Status));
779 if ((DevStatus >> 16) != 0) {
780 DEBUG ((DEBUG_ERROR,
"SdCardSwitchBusWidth: The switch operation fails as DevStatus is 0x%08x\n", DevStatus));
781 return EFI_DEVICE_ERROR;
804 IN UINT8 CardSupportedBusTimings,
806 IN SD_MMC_BUS_MODE BusTiming
811 Capability = &Private->Capability[SlotIndex];
816 if ((Capability->Sdr104 != 0) && ((CardSupportedBusTimings & BIT3) != 0)) {
822 if ((Capability->Ddr50 != 0) && ((CardSupportedBusTimings & BIT4) != 0)) {
828 if ((Capability->Sdr50 != 0) && ((CardSupportedBusTimings & BIT2) != 0)) {
834 if ((CardSupportedBusTimings & BIT1) != 0) {
840 if ((CardSupportedBusTimings & BIT0) != 0) {
851 if ((Capability->HighSpeed != 0) && ((CardSupportedBusTimings & BIT1) != 0)) {
857 if ((CardSupportedBusTimings & BIT0) != 0) {
886 IN UINT8 CardSupportedBusTimings,
890 SD_MMC_BUS_MODE BusTiming;
893 BusTiming = SdMmcUhsSdr104;
895 BusTiming = SdMmcSdHs;
898 while (BusTiming > SdMmcSdDs) {
922 IN SD_MMC_BUS_MODE BusTiming
926 UINT8 PreferredBusWidth;
928 PreferredBusWidth = Private->Slot[SlotIndex].OperatingParameters.BusWidth;
930 if ((BusTiming == SdMmcSdDs) || (BusTiming == SdMmcSdHs)) {
931 if ((PreferredBusWidth != EDKII_SD_MMC_BUS_WIDTH_IGNORE) &&
932 ((PreferredBusWidth == 1) || (PreferredBusWidth == 4)))
934 BusWidth = PreferredBusWidth;
963 IN SD_MMC_BUS_MODE BusTiming
966 UINT32 PreferredClockFreq;
969 PreferredClockFreq = Private->Slot[SlotIndex].OperatingParameters.ClockFreq;
989 if ((PreferredClockFreq != EDKII_SD_MMC_CLOCK_FREQ_IGNORE) && (PreferredClockFreq < MaxClockFreq)) {
990 return PreferredClockFreq;
1010 IN UINT8 CardSupportedDriverStrengths,
1011 IN SD_MMC_BUS_MODE BusTiming
1017 if ((BusTiming == SdMmcSdDs) || (BusTiming == SdMmcSdHs)) {
1018 DriverStrength.Sd = SdDriverStrengthIgnore;
1019 return DriverStrength;
1022 PreferredDriverStrength = Private->Slot[SlotIndex].OperatingParameters.DriverStrength;
1023 DriverStrength.Sd = SdDriverStrengthTypeB;
1025 if ((PreferredDriverStrength.Sd != EDKII_SD_MMC_DRIVER_STRENGTH_IGNORE) &&
1026 (CardSupportedDriverStrengths & (BIT0 << PreferredDriverStrength.Sd)))
1028 if (((PreferredDriverStrength.Sd == SdDriverStrengthTypeA) &&
1029 (Private->Capability[SlotIndex].DriverTypeA != 0)) ||
1030 ((PreferredDriverStrength.Sd == SdDriverStrengthTypeC) &&
1031 (Private->Capability[SlotIndex].DriverTypeC != 0)) ||
1032 ((PreferredDriverStrength.Sd == SdDriverStrengthTypeD) &&
1033 (Private->Capability[SlotIndex].DriverTypeD != 0)))
1035 DriverStrength.Sd = PreferredDriverStrength.Sd;
1039 return DriverStrength;
1055 IN UINT8 *SwitchQueryResp,
1056 IN BOOLEAN IsInUhsI,
1090 IN BOOLEAN SdVersion1
1096 UINT8 SwitchResp[64];
1100 ZeroMem (SwitchResp, 64 *
sizeof (UINT8));
1102 Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
1104 Capability = &Private->Capability[Slot];
1107 if (EFI_ERROR (Status)) {
1117 if (EFI_ERROR (Status)) {
1127 Status =
SdCardSwitch (PassThru, Slot, 0xFF, 0xF, SdDriverStrengthIgnore, 0xF,
FALSE, SwitchResp);
1128 if (EFI_ERROR (Status)) {
1137 "SdCardSetBusMode: Target bus mode: bus timing = %d, bus width = %d, clock freq[MHz] = %d, driver strength = %d\n",
1141 BusMode.DriverStrength.Sd
1146 if (EFI_ERROR (Status)) {
1155 Status =
SdCardSwitch (PassThru, Slot, BusMode.BusTiming, 0xF, BusMode.DriverStrength.Sd, 0xF,
TRUE, SwitchResp);
1156 if (EFI_ERROR (Status)) {
1162 if (EFI_ERROR (Status)) {
1169 if (BusMode.BusTiming == SdMmcSdHs) {
1171 Status =
SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1,
sizeof (HostCtrl1), &HostCtrl1);
1172 if (EFI_ERROR (Status)) {
1178 if (EFI_ERROR (Status)) {
1183 if (EFI_ERROR (Status)) {
1187 if ((BusMode.BusTiming == SdMmcUhsSdr104) || ((BusMode.BusTiming == SdMmcUhsSdr50) && (Capability->TuningSDR50 != 0))) {
1189 if (EFI_ERROR (Status)) {
1223 UINT16 ControllerVer;
1225 UINT32 PresentState;
1228 BOOLEAN ForceVoltage33;
1231 ForceVoltage33 =
FALSE;
1234 PciIo = Private->PciIo;
1235 PassThru = &Private->PassThru;
1242 if (EFI_ERROR (Status)) {
1243 DEBUG ((DEBUG_INFO,
"SdCardIdentification: Executing Cmd0 fails with %r\n", Status));
1251 if (EFI_ERROR (Status)) {
1253 DEBUG ((DEBUG_INFO,
"SdCardIdentification: Executing Cmd8 fails with %r\n", Status));
1260 if (!EFI_ERROR (Status)) {
1261 DEBUG ((DEBUG_INFO,
"SdCardIdentification: Found SDIO device, ignore it as we don't support\n"));
1262 return EFI_DEVICE_ERROR;
1269 if (EFI_ERROR (Status)) {
1270 DEBUG ((DEBUG_INFO,
"SdCardIdentification: Executing SdCardSendOpCond fails with %r\n", Status));
1271 return EFI_DEVICE_ERROR;
1274 if (Private->Capability[Slot].Voltage33 != 0) {
1278 MaxCurrent = ((UINT32)Private->MaxCurrent[Slot] & 0xFF) * 4;
1279 }
else if (Private->Capability[Slot].Voltage30 != 0) {
1283 MaxCurrent = (((UINT32)Private->MaxCurrent[Slot] >> 8) & 0xFF) * 4;
1284 }
else if (Private->Capability[Slot].Voltage18 != 0) {
1288 MaxCurrent = (((UINT32)Private->MaxCurrent[Slot] >> 16) & 0xFF) * 4;
1291 return EFI_DEVICE_ERROR;
1294 if (MaxCurrent >= 150) {
1300 Status =
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CTRL_VER,
TRUE,
sizeof (ControllerVer), &ControllerVer);
1301 if (EFI_ERROR (Status)) {
1305 if (((ControllerVer & 0xFF) >= SD_MMC_HC_CTRL_VER_300) &&
1306 ((ControllerVer & 0xFF) <= SD_MMC_HC_CTRL_VER_420))
1309 }
else if (((ControllerVer & 0xFF) == SD_MMC_HC_CTRL_VER_100) || ((ControllerVer & 0xFF) == SD_MMC_HC_CTRL_VER_200)) {
1313 return EFI_UNSUPPORTED;
1319 if (ForceVoltage33 ==
TRUE) {
1332 if (EFI_ERROR (Status)) {
1333 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: SdCardSendOpCond fails with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));
1334 return EFI_DEVICE_ERROR;
1337 if (Retry++ == 100) {
1338 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: SdCardSendOpCond fails too many times\n"));
1339 return EFI_DEVICE_ERROR;
1342 gBS->Stall (10 * 1000);
1343 }
while ((Ocr & BIT31) == 0);
1350 if (((Private->Capability[Slot].Sdr50 != 0) ||
1351 (Private->Capability[Slot].Sdr104 != 0) ||
1352 (Private->Capability[Slot].Ddr50 != 0)) &&
1353 ((Ocr & BIT24) != 0))
1356 if (EFI_ERROR (Status)) {
1357 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: Executing SdCardVoltageSwitch fails with %r\n", Status));
1358 Status = EFI_DEVICE_ERROR;
1362 if (EFI_ERROR (Status)) {
1363 Status = EFI_DEVICE_ERROR;
1367 SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE,
TRUE,
sizeof (PresentState), &PresentState);
1368 if (((PresentState >> 20) & 0xF) != 0) {
1369 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x\n", PresentState));
1370 Status = EFI_DEVICE_ERROR;
1375 SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
1379 SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2,
TRUE,
sizeof (HostCtrl2), &HostCtrl2);
1380 if ((HostCtrl2 & BIT3) == 0) {
1381 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: SwitchVoltage fails with HostCtrl2 = 0x%x\n", HostCtrl2));
1382 Status = EFI_DEVICE_ERROR;
1387 if (EFI_ERROR (Status)) {
1393 SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE,
TRUE,
sizeof (PresentState), &PresentState);
1394 if (((PresentState >> 20) & 0xF) != 0xF) {
1399 SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE,
TRUE,
sizeof (PresentState), &PresentState);
1400 if (((PresentState >> 20) & 0xF) != 0xF) {
1401 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));
1406 if (EFI_ERROR (Status)) {
1411 if (EFI_ERROR (Status)) {
1415 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: Switching to 1.8V failed, forcing a retry with 3.3V instead\n"));
1416 ForceVoltage33 =
TRUE;
1417 goto Voltage33Retry;
1422 DEBUG ((DEBUG_INFO,
"SdCardIdentification: Switch to 1.8v signal voltage success\n"));
1426 if (EFI_ERROR (Status)) {
1427 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: Executing SdCardAllSendCid fails with %r\n", Status));
1432 if (EFI_ERROR (Status)) {
1433 DEBUG ((DEBUG_ERROR,
"SdCardIdentification: Executing SdCardSetRca fails with %r\n", Status));
1440 DEBUG ((DEBUG_INFO,
"SdCardIdentification: Found a SD device at slot [%d]\n", Slot));
1441 Private->Slot[Slot].CardType = SdCardType;
1443 Status =
SdCardSetBusMode (PciIo, PassThru, Slot, Rca, ((Ocr & BIT24) != 0), SdVersion1);
1451 PowerCtrl = (UINT8) ~BIT0;
1452 Status =
SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_POWER_CTRL,
sizeof (PowerCtrl), &PowerCtrl);
1453 return EFI_DEVICE_ERROR;
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define DEBUG(Expression)
EDKII_SD_MMC_DRIVER_STRENGTH SdGetTargetDriverStrength(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN UINT8 CardSupportedDriverStrengths, IN SD_MMC_BUS_MODE BusTiming)
EFI_STATUS SdCardSwitch(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN SD_MMC_BUS_MODE BusTiming, IN UINT8 CommandSystem, IN SD_DRIVER_STRENGTH_TYPE DriverStrength, IN UINT8 PowerLimit, IN BOOLEAN Mode, OUT UINT8 *SwitchResp)
VOID SdGetTargetBusMode(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN UINT8 *SwitchQueryResp, IN BOOLEAN IsInUhsI, OUT SD_MMC_BUS_SETTINGS *BusMode)
BOOLEAN SdIsBusTimingSupported(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN UINT8 CardSupportedBusTimings, IN BOOLEAN IsInUhsI, IN SD_MMC_BUS_MODE BusTiming)
EFI_STATUS SdCardSendTuningBlk(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
EFI_STATUS SdCardSendStatus(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, OUT UINT32 *DevStatus)
EFI_STATUS SdCardSendOpCond(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, IN UINT32 VoltageWindow, IN BOOLEAN S18R, IN BOOLEAN Xpc, IN BOOLEAN Hcs, OUT UINT32 *Ocr)
UINT8 SdGetTargetBusWidth(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN SD_MMC_BUS_MODE BusTiming)
EFI_STATUS SdCardReset(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
SD_MMC_BUS_MODE SdGetTargetBusTiming(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN UINT8 CardSupportedBusTimings, IN BOOLEAN IsInUhsI)
EFI_STATUS SdCardSwitchBusWidth(IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, IN UINT8 BusWidth)
EFI_STATUS SdioSendOpCond(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT32 VoltageWindow, IN BOOLEAN S18R)
EFI_STATUS SdCardSetRca(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, OUT UINT16 *Rca)
EFI_STATUS SdCardSetBusWidth(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, IN UINT8 BusWidth)
EFI_STATUS SdCardAllSendCid(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
EFI_STATUS SdCardSetBusMode(IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca, IN BOOLEAN S18A, IN BOOLEAN SdVersion1)
UINT32 SdGetTargetBusClockFreq(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 SlotIndex, IN SD_MMC_BUS_MODE BusTiming)
EFI_STATUS SdCardTuningClock(IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
EFI_STATUS SdCardVoltageCheck(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT8 SupplyVoltage, IN UINT8 CheckPattern)
EFI_STATUS SdCardSelect(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot, IN UINT16 Rca)
EFI_STATUS SdCardIdentification(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
EFI_STATUS SdCardVoltageSwitch(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru, IN UINT8 Slot)
EFI_STATUS EFIAPI SdMmcPassThruPassThru(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This, IN UINT8 Slot, IN OUT EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet, IN EFI_EVENT Event OPTIONAL)
EFI_STATUS SdMmcHcReset(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
EFI_STATUS SdMmcHcInitHost(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
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 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 SdMmcHcStartSdClock(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
EFI_STATUS SdMmcSetDriverStrength(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 SlotIndex, IN SD_DRIVER_STRENGTH_TYPE DriverStrength)
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 SdMmcHcAndMmio(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN VOID *AndData)
EFI_STATUS SdMmcHcStopClock(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
EFI_STATUS SdMmcHcSetBusWidth(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN UINT16 BusWidth)
EFI_STATUS EFIAPI SdMmcHcOrMmio(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN VOID *OrData)