37 if ((Address == 0) || (Data ==
NULL)) {
38 return EFI_INVALID_PARAMETER;
41 if ((Count != 1) && (Count != 2) && (Count != 4) && (Count != 8)) {
42 return EFI_INVALID_PARAMETER;
80 return EFI_INVALID_PARAMETER;
115 if (EFI_ERROR (Status)) {
120 Or = *(UINT8 *)OrData;
121 }
else if (Count == 2) {
122 Or = *(UINT16 *)OrData;
123 }
else if (Count == 4) {
124 Or = *(UINT32 *)OrData;
125 }
else if (Count == 8) {
126 Or = *(UINT64 *)OrData;
128 return EFI_INVALID_PARAMETER;
166 if (EFI_ERROR (Status)) {
171 And = *(UINT8 *)AndData;
172 }
else if (Count == 2) {
173 And = *(UINT16 *)AndData;
174 }
else if (Count == 4) {
175 And = *(UINT32 *)AndData;
176 }
else if (Count == 8) {
177 And = *(UINT64 *)AndData;
179 return EFI_INVALID_PARAMETER;
219 if (EFI_ERROR (Status)) {
225 if (Value == TestValue) {
229 return EFI_NOT_READY;
260 BOOLEAN InfiniteWait;
265 InfiniteWait =
FALSE;
268 while (InfiniteWait || (Timeout > 0)) {
275 if (Status != EFI_NOT_READY) {
310 if (EFI_ERROR (Status)) {
311 DEBUG ((DEBUG_ERROR,
"SdPeimHcReset: write full 1 fails: %r\n", Status));
322 if (EFI_ERROR (Status)) {
323 DEBUG ((DEBUG_INFO,
"SdPeimHcReset: reset done with %r\n", Status));
357 Status =
SdPeimHcRwMmio (Bar + SD_HC_ERR_INT_STS_EN,
FALSE,
sizeof (IntStatus), &IntStatus);
358 if (EFI_ERROR (Status)) {
366 Status =
SdPeimHcRwMmio (Bar + SD_HC_NOR_INT_STS_EN,
FALSE,
sizeof (IntStatus), &IntStatus);
391 if (EFI_ERROR (Status)) {
395 CopyMem (Capability, &Cap,
sizeof (Cap));
426 if (EFI_ERROR (Status)) {
430 if ((Data & (BIT6 | BIT7)) != 0) {
436 if (EFI_ERROR (Status)) {
444 Status =
SdPeimHcRwMmio (Bar + SD_HC_PRESENT_STATE,
TRUE,
sizeof (PresentState), &PresentState);
445 if (EFI_ERROR (Status)) {
449 if ((PresentState & BIT16) != 0) {
482 Bar + SD_HC_PRESENT_STATE,
483 sizeof (PresentState),
488 if (EFI_ERROR (Status)) {
495 ClockCtrl = (UINT16) ~BIT2;
496 Status =
SdPeimHcAndMmio (Bar + SD_HC_CLOCK_CTRL,
sizeof (ClockCtrl), &ClockCtrl);
525 UINT16 ControllerVer;
532 if (EFI_ERROR (Status)) {
536 ASSERT (Capability.BaseClkFreq != 0);
538 BaseClkFreq = Capability.BaseClkFreq;
540 if (ClockFreq == 0) {
541 return EFI_INVALID_PARAMETER;
544 if (ClockFreq > (BaseClkFreq * 1000)) {
545 ClockFreq = BaseClkFreq * 1000;
552 SettingFreq = BaseClkFreq * 1000;
553 while (ClockFreq < SettingFreq) {
556 SettingFreq = (BaseClkFreq * 1000) / (2 * Divisor);
557 Remainder = (BaseClkFreq * 1000) % (2 * Divisor);
558 if ((ClockFreq == SettingFreq) && (Remainder == 0)) {
562 if ((ClockFreq == SettingFreq) && (Remainder != 0)) {
567 DEBUG ((DEBUG_INFO,
"BaseClkFreq %dMHz Divisor %d ClockFreq %dKhz\n", BaseClkFreq, Divisor, ClockFreq));
569 Status =
SdPeimHcRwMmio (Bar + SD_HC_CTRL_VER,
TRUE,
sizeof (ControllerVer), &ControllerVer);
570 if (EFI_ERROR (Status)) {
577 if ((ControllerVer & 0xFF) == 2) {
578 ASSERT (Divisor <= 0x3FF);
579 ClockCtrl = ((Divisor & 0xFF) << 8) | ((Divisor & 0x300) >> 2);
580 }
else if (((ControllerVer & 0xFF) == 0) || ((ControllerVer & 0xFF) == 1)) {
584 if (((Divisor - 1) & Divisor) != 0) {
588 ASSERT (Divisor <= 0x80);
589 ClockCtrl = (Divisor & 0xFF) << 8;
591 DEBUG ((DEBUG_ERROR,
"Unknown SD Host Controller Spec version [0x%x]!!!\n", ControllerVer));
592 return EFI_UNSUPPORTED;
599 if (EFI_ERROR (Status)) {
608 if (EFI_ERROR (Status)) {
609 DEBUG ((DEBUG_ERROR,
"Set SDCLK Frequency Select and Internal Clock Enable fields fails\n"));
617 Bar + SD_HC_CLOCK_CTRL,
623 if (EFI_ERROR (Status)) {
631 Status =
SdPeimHcOrMmio (Bar + SD_HC_CLOCK_CTRL,
sizeof (ClockCtrl), &ClockCtrl);
659 PowerCtrl &= (UINT8) ~BIT0;
661 if (EFI_ERROR (Status)) {
696 HostCtrl1 = (UINT8) ~(BIT5 | BIT1);
697 Status =
SdPeimHcAndMmio (Bar + SD_HC_HOST_CTRL1,
sizeof (HostCtrl1), &HostCtrl1);
698 }
else if (BusWidth == 4) {
699 Status =
SdPeimHcRwMmio (Bar + SD_HC_HOST_CTRL1,
TRUE,
sizeof (HostCtrl1), &HostCtrl1);
700 if (EFI_ERROR (Status)) {
705 HostCtrl1 &= (UINT8) ~BIT5;
707 }
else if (BusWidth == 8) {
708 Status =
SdPeimHcRwMmio (Bar + SD_HC_HOST_CTRL1,
TRUE,
sizeof (HostCtrl1), &HostCtrl1);
709 if (EFI_ERROR (Status)) {
713 HostCtrl1 &= (UINT8) ~BIT1;
718 return EFI_INVALID_PARAMETER;
746 if (EFI_ERROR (Status)) {
750 if (Capability.BaseClkFreq == 0) {
754 return EFI_UNSUPPORTED;
790 if (EFI_ERROR (Status)) {
797 if (Capability.Voltage33 != 0) {
802 }
else if (Capability.Voltage30 != 0) {
807 }
else if (Capability.Voltage18 != 0) {
813 Status =
SdPeimHcOrMmio (Bar + SD_HC_HOST_CTRL2,
sizeof (HostCtrl2), &HostCtrl2);
814 if (EFI_ERROR (Status)) {
821 return EFI_DEVICE_ERROR;
875 if (EFI_ERROR (Status)) {
880 if (EFI_ERROR (Status)) {
909 Status =
SdPeimHcOrMmio (Bar + SD_HC_HOST_CTRL1,
sizeof (HostCtrl1), &HostCtrl1);
911 HostCtrl1 = (UINT8) ~BIT0;
912 Status =
SdPeimHcAndMmio (Bar + SD_HC_HOST_CTRL1,
sizeof (HostCtrl1), &HostCtrl1);
942 DataLen = Trb->DataLen;
946 if ((Data >= 0x100000000ul) || ((Data + DataLen) > 0x100000000ul)) {
947 return EFI_INVALID_PARAMETER;
954 if ((Data & (BIT0 | BIT1)) != 0) {
955 DEBUG ((DEBUG_INFO,
"The buffer [0x%x] to construct ADMA desc is not aligned to 4 bytes boundary!\n", Data));
958 Entries =
DivU64x32 ((DataLen + ADMA_MAX_DATA_PER_LINE - 1), ADMA_MAX_DATA_PER_LINE);
962 if (Trb->AdmaDesc ==
NULL) {
963 return EFI_OUT_OF_RESOURCES;
967 Address = (UINT32)Data;
968 for (Index = 0; Index < Entries; Index++) {
969 if (Remaining <= ADMA_MAX_DATA_PER_LINE) {
970 Trb->AdmaDesc[Index].Valid = 1;
971 Trb->AdmaDesc[Index].Act = 2;
972 Trb->AdmaDesc[Index].Length = (UINT16)Remaining;
973 Trb->AdmaDesc[Index].Address = Address;
976 Trb->AdmaDesc[Index].Valid = 1;
977 Trb->AdmaDesc[Index].Act = 2;
978 Trb->AdmaDesc[Index].Length = 0;
979 Trb->AdmaDesc[Index].Address = Address;
982 Remaining -= ADMA_MAX_DATA_PER_LINE;
983 Address += ADMA_MAX_DATA_PER_LINE;
989 Trb->AdmaDesc[Index].End = 1;
1018 if (EFI_ERROR (Status)) {
1028 Trb->BlockSize = 0x200;
1029 Trb->Packet = Packet;
1030 Trb->Timeout = Packet->Timeout;
1032 if ((Packet->InTransferLength != 0) && (Packet->InDataBuffer !=
NULL)) {
1033 Trb->Data = Packet->InDataBuffer;
1034 Trb->DataLen = Packet->InTransferLength;
1036 }
else if ((Packet->OutTransferLength != 0) && (Packet->OutDataBuffer !=
NULL)) {
1037 Trb->Data = Packet->OutDataBuffer;
1038 Trb->DataLen = Packet->OutTransferLength;
1040 }
else if ((Packet->InTransferLength == 0) && (Packet->OutTransferLength == 0)) {
1047 if ((Trb->DataLen != 0) && (Trb->DataLen < Trb->BlockSize)) {
1048 Trb->BlockSize = (UINT16)Trb->DataLen;
1051 if (Packet->SdCmdBlk->CommandIndex == SD_SEND_TUNING_BLOCK) {
1052 Trb->Mode = SdPioMode;
1060 if (Trb->DataLen != 0) {
1061 MapLength = Trb->DataLen;
1062 Status =
IoMmuMap (MapOp, Trb->Data, &MapLength, &Trb->DataPhy, &Trb->DataMap);
1064 if (EFI_ERROR (Status) || (MapLength != Trb->DataLen)) {
1065 DEBUG ((DEBUG_ERROR,
"SdPeimCreateTrb: Fail to map data buffer.\n"));
1070 if (Trb->DataLen == 0) {
1071 Trb->Mode = SdNoData;
1072 }
else if (Capability.Adma2 != 0) {
1073 Trb->Mode = SdAdmaMode;
1075 if (EFI_ERROR (Status)) {
1078 }
else if (Capability.Sdma != 0) {
1079 Trb->Mode = SdSdmaMode;
1081 Trb->Mode = SdPioMode;
1103 if ((Trb !=
NULL) && (Trb->DataMap !=
NULL)) {
1107 if ((Trb !=
NULL) && (Trb->AdmaDesc !=
NULL)) {
1108 SdPeimFreeMem (Trb->Slot->Private->Pool, Trb->AdmaDesc, Trb->AdmaDescSize);
1137 UINT32 PresentState;
1139 Packet = Trb->Packet;
1141 if ((Packet->SdCmdBlk->CommandType == SdCommandTypeAdtc) ||
1142 (Packet->SdCmdBlk->ResponseType == SdResponseTypeR1b) ||
1143 (Packet->SdCmdBlk->ResponseType == SdResponseTypeR5b))
1149 PresentState = BIT0 | BIT1;
1155 PresentState = BIT0;
1159 Bar + SD_HC_PRESENT_STATE,
1160 sizeof (PresentState),
1188 BOOLEAN InfiniteWait;
1193 Packet = Trb->Packet;
1194 Timeout = Packet->Timeout;
1196 InfiniteWait =
TRUE;
1198 InfiniteWait =
FALSE;
1201 while (InfiniteWait || (Timeout > 0)) {
1206 if (Status != EFI_NOT_READY) {
1249 Packet = Trb->Packet;
1255 if (EFI_ERROR (Status)) {
1264 if (EFI_ERROR (Status)) {
1271 if (Trb->Mode == SdAdmaMode) {
1273 Status =
SdPeimHcOrMmio (Bar + SD_HC_HOST_CTRL1,
sizeof (HostCtrl1), &HostCtrl1);
1274 if (EFI_ERROR (Status)) {
1281 if (Trb->Mode == SdSdmaMode) {
1282 if ((UINT64)(
UINTN)Trb->DataPhy >= 0x100000000ul) {
1283 return EFI_INVALID_PARAMETER;
1286 SdmaAddr = (UINT32)(
UINTN)Trb->DataPhy;
1288 if (EFI_ERROR (Status)) {
1291 }
else if (Trb->Mode == SdAdmaMode) {
1292 AdmaAddr = (UINT64)(
UINTN)Trb->AdmaDesc;
1294 if (EFI_ERROR (Status)) {
1299 BlkSize = Trb->BlockSize;
1300 if (Trb->Mode == SdSdmaMode) {
1308 if (EFI_ERROR (Status)) {
1313 if (Trb->Mode != SdNoData) {
1317 BlkCount = (UINT16)(Trb->DataLen / Trb->BlockSize);
1321 if (EFI_ERROR (Status)) {
1325 Argument = Packet->SdCmdBlk->CommandArgument;
1327 if (EFI_ERROR (Status)) {
1332 if (Trb->Mode != SdNoData) {
1333 if (Trb->Mode != SdPioMode) {
1342 TransMode |= BIT5 | BIT1;
1354 if (EFI_ERROR (Status)) {
1358 Cmd = (UINT16)
LShiftU64 (Packet->SdCmdBlk->CommandIndex, 8);
1359 if (Packet->SdCmdBlk->CommandType == SdCommandTypeAdtc) {
1366 if (Packet->SdCmdBlk->CommandType != SdCommandTypeBc) {
1367 switch (Packet->SdCmdBlk->ResponseType) {
1368 case SdResponseTypeR1:
1369 case SdResponseTypeR5:
1370 case SdResponseTypeR6:
1371 case SdResponseTypeR7:
1372 Cmd |= (BIT1 | BIT3 | BIT4);
1374 case SdResponseTypeR2:
1375 Cmd |= (BIT0 | BIT3);
1377 case SdResponseTypeR3:
1378 case SdResponseTypeR4:
1381 case SdResponseTypeR1b:
1382 case SdResponseTypeR5b:
1383 Cmd |= (BIT0 | BIT1 | BIT3 | BIT4);
1425 Packet = Trb->Packet;
1430 Bar + SD_HC_NOR_INT_STS,
1435 if (EFI_ERROR (Status)) {
1442 if ((IntStatus & BIT1) == BIT1) {
1443 if ((IntStatus & BIT15) == BIT15) {
1451 Bar + SD_HC_ERR_INT_STS,
1456 if (!EFI_ERROR (Status)) {
1457 if ((IntStatus & BIT4) == BIT4) {
1460 Status = EFI_DEVICE_ERROR;
1473 if ((IntStatus & BIT15) == BIT15) {
1475 Bar + SD_HC_ERR_INT_STS,
1480 if (EFI_ERROR (Status)) {
1484 if ((IntStatus & 0x0F) != 0) {
1488 if ((IntStatus & 0xF0) != 0) {
1498 if (EFI_ERROR (Status)) {
1509 if (EFI_ERROR (Status)) {
1513 Status = EFI_DEVICE_ERROR;
1520 if ((Trb->Mode == SdSdmaMode) && ((IntStatus & BIT3) == BIT3)) {
1526 Bar + SD_HC_NOR_INT_STS,
1531 if (EFI_ERROR (Status)) {
1538 SdmaAddr = SD_SDMA_ROUND_UP ((UINT32)(
UINTN)Trb->DataPhy, SD_SDMA_BOUNDARY);
1540 Bar + SD_HC_SDMA_ADDR,
1545 if (EFI_ERROR (Status)) {
1549 Trb->DataPhy = (UINT32)(
UINTN)SdmaAddr;
1552 if ((Packet->SdCmdBlk->CommandType != SdCommandTypeAdtc) &&
1553 (Packet->SdCmdBlk->ResponseType != SdResponseTypeR1b) &&
1554 (Packet->SdCmdBlk->ResponseType != SdResponseTypeR5b))
1556 if ((IntStatus & BIT0) == BIT0) {
1562 if (Packet->SdCmdBlk->CommandIndex == SD_SEND_TUNING_BLOCK) {
1568 if ((IntStatus & BIT5) == BIT5) {
1577 for (PioLength = 0; PioLength < Trb->DataLen; PioLength += 4) {
1586 Status = EFI_NOT_READY;
1591 if (!EFI_ERROR (Status)) {
1592 if (Packet->SdCmdBlk->CommandType != SdCommandTypeBc) {
1593 for (Index = 0; Index < 4; Index++) {
1595 Bar + SD_HC_RESPONSE + Index * 4,
1600 if (EFI_ERROR (Status)) {
1606 CopyMem (Packet->SdStatusBlk, Response, sizeof (Response));
1610 if (Status != EFI_NOT_READY) {
1636 BOOLEAN InfiniteWait;
1638 Packet = Trb->Packet;
1642 Timeout = Packet->Timeout;
1644 InfiniteWait =
TRUE;
1646 InfiniteWait =
FALSE;
1649 while (InfiniteWait || (Timeout > 0)) {
1654 if (Status != EFI_NOT_READY) {
1709 if (Packet ==
NULL) {
1710 return EFI_INVALID_PARAMETER;
1713 if ((Packet->SdCmdBlk ==
NULL) || (Packet->SdStatusBlk ==
NULL)) {
1714 return EFI_INVALID_PARAMETER;
1717 if ((Packet->OutDataBuffer ==
NULL) && (Packet->OutTransferLength != 0)) {
1718 return EFI_INVALID_PARAMETER;
1721 if ((Packet->InDataBuffer ==
NULL) && (Packet->InTransferLength != 0)) {
1722 return EFI_INVALID_PARAMETER;
1727 return EFI_OUT_OF_RESOURCES;
1731 if (EFI_ERROR (Status)) {
1736 if (EFI_ERROR (Status)) {
1741 if (EFI_ERROR (Status)) {
1772 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
1773 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
1774 ZeroMem (&Packet,
sizeof (Packet));
1776 Packet.SdCmdBlk = &SdCmdBlk;
1777 Packet.SdStatusBlk = &SdStatusBlk;
1778 Packet.Timeout = SD_TIMEOUT;
1780 SdCmdBlk.CommandIndex = SD_GO_IDLE_STATE;
1781 SdCmdBlk.CommandType = SdCommandTypeBc;
1782 SdCmdBlk.ResponseType = 0;
1783 SdCmdBlk.CommandArgument = 0;
1807 IN UINT8 SupplyVoltage,
1808 IN UINT8 CheckPattern
1816 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
1817 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
1818 ZeroMem (&Packet,
sizeof (Packet));
1820 Packet.SdCmdBlk = &SdCmdBlk;
1821 Packet.SdStatusBlk = &SdStatusBlk;
1822 Packet.Timeout = SD_TIMEOUT;
1824 SdCmdBlk.CommandIndex = SD_SEND_IF_COND;
1825 SdCmdBlk.CommandType = SdCommandTypeBcr;
1826 SdCmdBlk.ResponseType = SdResponseTypeR7;
1827 SdCmdBlk.CommandArgument = (SupplyVoltage << 8) | CheckPattern;
1830 if (!EFI_ERROR (Status)) {
1831 if (SdStatusBlk.Resp0 != SdCmdBlk.CommandArgument) {
1832 return EFI_DEVICE_ERROR;
1855 IN UINT32 VoltageWindow,
1865 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
1866 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
1867 ZeroMem (&Packet,
sizeof (Packet));
1869 Packet.SdCmdBlk = &SdCmdBlk;
1870 Packet.SdStatusBlk = &SdStatusBlk;
1871 Packet.Timeout = SD_TIMEOUT;
1873 SdCmdBlk.CommandIndex = SDIO_SEND_OP_COND;
1874 SdCmdBlk.CommandType = SdCommandTypeBcr;
1875 SdCmdBlk.ResponseType = SdResponseTypeR4;
1877 Switch = S18r ? BIT24 : 0;
1879 SdCmdBlk.CommandArgument = (VoltageWindow & 0xFFFFFF) | Switch;
1908 IN UINT32 VoltageWindow,
1921 UINT32 HostCapacity;
1923 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
1924 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
1925 ZeroMem (&Packet,
sizeof (Packet));
1927 Packet.SdCmdBlk = &SdCmdBlk;
1928 Packet.SdStatusBlk = &SdStatusBlk;
1929 Packet.Timeout = SD_TIMEOUT;
1931 SdCmdBlk.CommandIndex = SD_APP_CMD;
1932 SdCmdBlk.CommandType = SdCommandTypeAc;
1933 SdCmdBlk.ResponseType = SdResponseTypeR1;
1934 SdCmdBlk.CommandArgument = (UINT32)Rca << 16;
1937 if (EFI_ERROR (Status)) {
1941 SdCmdBlk.CommandIndex = SD_SEND_OP_COND;
1942 SdCmdBlk.CommandType = SdCommandTypeBcr;
1943 SdCmdBlk.ResponseType = SdResponseTypeR3;
1945 Switch = S18r ? BIT24 : 0;
1946 MaxPower = Xpc ? BIT28 : 0;
1947 HostCapacity = Hcs ? BIT30 : 0;
1948 SdCmdBlk.CommandArgument = (VoltageWindow & 0xFFFFFF) | Switch | MaxPower | HostCapacity;
1951 if (!EFI_ERROR (Status)) {
1955 *Ocr = SdStatusBlk.Resp0;
1983 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
1984 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
1985 ZeroMem (&Packet,
sizeof (Packet));
1987 Packet.SdCmdBlk = &SdCmdBlk;
1988 Packet.SdStatusBlk = &SdStatusBlk;
1989 Packet.Timeout = SD_TIMEOUT;
1991 SdCmdBlk.CommandIndex = SD_ALL_SEND_CID;
1992 SdCmdBlk.CommandType = SdCommandTypeBcr;
1993 SdCmdBlk.ResponseType = SdResponseTypeR2;
1994 SdCmdBlk.CommandArgument = 0;
2025 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2026 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2027 ZeroMem (&Packet,
sizeof (Packet));
2029 Packet.SdCmdBlk = &SdCmdBlk;
2030 Packet.SdStatusBlk = &SdStatusBlk;
2031 Packet.Timeout = SD_TIMEOUT;
2033 SdCmdBlk.CommandIndex = SD_SET_RELATIVE_ADDR;
2034 SdCmdBlk.CommandType = SdCommandTypeBcr;
2035 SdCmdBlk.ResponseType = SdResponseTypeR6;
2038 if (!EFI_ERROR (Status)) {
2039 *Rca = (UINT16)(SdStatusBlk.Resp0 >> 16);
2073 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2074 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2075 ZeroMem (&Packet,
sizeof (Packet));
2077 Packet.SdCmdBlk = &SdCmdBlk;
2078 Packet.SdStatusBlk = &SdStatusBlk;
2079 Packet.Timeout = SD_TIMEOUT;
2081 SdCmdBlk.CommandIndex = SD_SEND_CSD;
2082 SdCmdBlk.CommandType = SdCommandTypeAc;
2083 SdCmdBlk.ResponseType = SdResponseTypeR2;
2084 SdCmdBlk.CommandArgument = (UINT32)Rca << 16;
2087 if (!EFI_ERROR (Status)) {
2091 CopyMem (((UINT8 *)Csd) + 1, &SdStatusBlk.Resp0, sizeof (
SD_CSD) - 1);
2120 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2121 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2122 ZeroMem (&Packet,
sizeof (Packet));
2124 Packet.SdCmdBlk = &SdCmdBlk;
2125 Packet.SdStatusBlk = &SdStatusBlk;
2126 Packet.Timeout = SD_TIMEOUT;
2128 SdCmdBlk.CommandIndex = SD_SELECT_DESELECT_CARD;
2129 SdCmdBlk.CommandType = SdCommandTypeAc;
2130 SdCmdBlk.ResponseType = SdResponseTypeR1b;
2131 SdCmdBlk.CommandArgument = (UINT32)Rca << 16;
2159 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2160 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2161 ZeroMem (&Packet,
sizeof (Packet));
2163 Packet.SdCmdBlk = &SdCmdBlk;
2164 Packet.SdStatusBlk = &SdStatusBlk;
2165 Packet.Timeout = SD_TIMEOUT;
2167 SdCmdBlk.CommandIndex = SD_VOLTAGE_SWITCH;
2168 SdCmdBlk.CommandType = SdCommandTypeAc;
2169 SdCmdBlk.ResponseType = SdResponseTypeR1;
2170 SdCmdBlk.CommandArgument = 0;
2203 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2204 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2205 ZeroMem (&Packet,
sizeof (Packet));
2207 Packet.SdCmdBlk = &SdCmdBlk;
2208 Packet.SdStatusBlk = &SdStatusBlk;
2209 Packet.Timeout = SD_TIMEOUT;
2211 SdCmdBlk.CommandIndex = SD_APP_CMD;
2212 SdCmdBlk.CommandType = SdCommandTypeAc;
2213 SdCmdBlk.ResponseType = SdResponseTypeR1;
2214 SdCmdBlk.CommandArgument = (UINT32)Rca << 16;
2217 if (EFI_ERROR (Status)) {
2221 SdCmdBlk.CommandIndex = SD_SET_BUS_WIDTH;
2222 SdCmdBlk.CommandType = SdCommandTypeAc;
2223 SdCmdBlk.ResponseType = SdResponseTypeR1;
2225 if (BusWidth == 1) {
2227 }
else if (BusWidth == 4) {
2230 return EFI_INVALID_PARAMETER;
2233 SdCmdBlk.CommandArgument = Value & 0x3;
2260 IN UINT8 AccessMode,
2261 IN UINT8 CommandSystem,
2262 IN UINT8 DriveStrength,
2263 IN UINT8 PowerLimit,
2265 OUT UINT8 *SwitchResp
2274 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2275 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2276 ZeroMem (&Packet,
sizeof (Packet));
2278 Packet.SdCmdBlk = &SdCmdBlk;
2279 Packet.SdStatusBlk = &SdStatusBlk;
2280 Packet.Timeout = SD_TIMEOUT;
2282 SdCmdBlk.CommandIndex = SD_SWITCH_FUNC;
2283 SdCmdBlk.CommandType = SdCommandTypeAdtc;
2284 SdCmdBlk.ResponseType = SdResponseTypeR1;
2286 ModeValue = Mode ? BIT31 : 0;
2287 SdCmdBlk.CommandArgument = (AccessMode & 0xF) | ((PowerLimit & 0xF) << 4) | \
2288 ((DriveStrength & 0xF) << 8) | ((DriveStrength & 0xF) << 12) | \
2290 Packet.InDataBuffer = SwitchResp;
2291 Packet.InTransferLength = 64;
2315 OUT UINT32 *DevStatus
2323 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2324 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2325 ZeroMem (&Packet,
sizeof (Packet));
2327 Packet.SdCmdBlk = &SdCmdBlk;
2328 Packet.SdStatusBlk = &SdStatusBlk;
2329 Packet.Timeout = SD_TIMEOUT;
2331 SdCmdBlk.CommandIndex = SD_SEND_STATUS;
2332 SdCmdBlk.CommandType = SdCommandTypeAc;
2333 SdCmdBlk.ResponseType = SdResponseTypeR1;
2334 SdCmdBlk.CommandArgument = (UINT32)Rca << 16;
2337 if (!EFI_ERROR (Status)) {
2338 *DevStatus = SdStatusBlk.Resp0;
2365 IN UINT32 BlockSize,
2376 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2377 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2378 ZeroMem (&Packet,
sizeof (Packet));
2380 Packet.SdCmdBlk = &SdCmdBlk;
2381 Packet.SdStatusBlk = &SdStatusBlk;
2388 Packet.Timeout = (BufferSize / (2 * 1024 * 1024) + 1) * 1000 * 1000;
2391 Packet.InDataBuffer = Buffer;
2392 Packet.InTransferLength = (UINT32)BufferSize;
2394 SdCmdBlk.CommandIndex = SD_READ_SINGLE_BLOCK;
2395 SdCmdBlk.CommandType = SdCommandTypeAdtc;
2396 SdCmdBlk.ResponseType = SdResponseTypeR1;
2398 Packet.OutDataBuffer = Buffer;
2399 Packet.OutTransferLength = (UINT32)BufferSize;
2401 SdCmdBlk.CommandIndex = SD_WRITE_SINGLE_BLOCK;
2402 SdCmdBlk.CommandType = SdCommandTypeAdtc;
2403 SdCmdBlk.ResponseType = SdResponseTypeR1;
2406 if (Slot->SectorAddressing) {
2407 SdCmdBlk.CommandArgument = (UINT32)Lba;
2409 SdCmdBlk.CommandArgument = (UINT32)
MultU64x32 (Lba, BlockSize);
2438 IN UINT32 BlockSize,
2449 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2450 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2451 ZeroMem (&Packet,
sizeof (Packet));
2453 Packet.SdCmdBlk = &SdCmdBlk;
2454 Packet.SdStatusBlk = &SdStatusBlk;
2461 Packet.Timeout = (BufferSize / (2 * 1024 * 1024) + 1) * 1000 * 1000;
2464 Packet.InDataBuffer = Buffer;
2465 Packet.InTransferLength = (UINT32)BufferSize;
2467 SdCmdBlk.CommandIndex = SD_READ_MULTIPLE_BLOCK;
2468 SdCmdBlk.CommandType = SdCommandTypeAdtc;
2469 SdCmdBlk.ResponseType = SdResponseTypeR1;
2471 Packet.OutDataBuffer = Buffer;
2472 Packet.OutTransferLength = (UINT32)BufferSize;
2474 SdCmdBlk.CommandIndex = SD_WRITE_MULTIPLE_BLOCK;
2475 SdCmdBlk.CommandType = SdCommandTypeAdtc;
2476 SdCmdBlk.ResponseType = SdResponseTypeR1;
2479 if (Slot->SectorAddressing) {
2480 SdCmdBlk.CommandArgument = (UINT32)Lba;
2482 SdCmdBlk.CommandArgument = (UINT32)
MultU64x32 (Lba, BlockSize);
2513 UINT8 TuningBlock[64];
2515 ZeroMem (&SdCmdBlk,
sizeof (SdCmdBlk));
2516 ZeroMem (&SdStatusBlk,
sizeof (SdStatusBlk));
2517 ZeroMem (&Packet,
sizeof (Packet));
2519 Packet.SdCmdBlk = &SdCmdBlk;
2520 Packet.SdStatusBlk = &SdStatusBlk;
2521 Packet.Timeout = SD_TIMEOUT;
2523 SdCmdBlk.CommandIndex = SD_SEND_TUNING_BLOCK;
2524 SdCmdBlk.CommandType = SdCommandTypeAdtc;
2525 SdCmdBlk.ResponseType = SdResponseTypeR1;
2526 SdCmdBlk.CommandArgument = 0;
2528 Packet.InDataBuffer = TuningBlock;
2529 Packet.InTransferLength =
sizeof (TuningBlock);
2564 Status =
SdPeimHcOrMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
2565 if (EFI_ERROR (Status)) {
2575 if (EFI_ERROR (Status)) {
2579 Status =
SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2,
TRUE, sizeof (HostCtrl2), &HostCtrl2);
2580 if (EFI_ERROR (Status)) {
2584 if ((HostCtrl2 & (BIT6 | BIT7)) == 0) {
2588 if ((HostCtrl2 & (BIT6 | BIT7)) == BIT7) {
2591 }
while (++Retry < 40);
2593 DEBUG ((DEBUG_ERROR,
"SdPeimTuningClock: Send tuning block fails at %d times with HostCtrl2 %02x\n", Retry, HostCtrl2));
2597 HostCtrl2 = (UINT8) ~(BIT6 | BIT7);
2598 Status =
SdPeimHcAndMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
2599 if (EFI_ERROR (Status)) {
2603 return EFI_DEVICE_ERROR;
2631 if (EFI_ERROR (Status)) {
2636 if (EFI_ERROR (Status)) {
2643 if ((DevStatus >> 16) != 0) {
2644 return EFI_DEVICE_ERROR;
2680 UINT8 SwitchResp[64];
2683 if (EFI_ERROR (Status)) {
2684 DEBUG ((DEBUG_ERROR,
"SdPeimSetBusMode: SdPeimGetCsd fails with %r\n", Status));
2689 if (EFI_ERROR (Status)) {
2694 if (EFI_ERROR (Status)) {
2695 DEBUG ((DEBUG_ERROR,
"SdPeimSetBusMode: SdPeimSelect fails with %r\n", Status));
2701 if (EFI_ERROR (Status)) {
2702 DEBUG ((DEBUG_ERROR,
"SdPeimSetBusMode: SdPeimSwitchBusWidth fails with %r\n", Status));
2709 ZeroMem (SwitchResp,
sizeof (SwitchResp));
2711 if (EFI_ERROR (Status)) {
2719 if (S18a && (Capability.Sdr104 != 0) && ((SwitchResp[13] & BIT3) != 0)) {
2722 }
else if (S18a && (Capability.Sdr50 != 0) && ((SwitchResp[13] & BIT2) != 0)) {
2725 }
else if (S18a && (Capability.Ddr50 != 0) && ((SwitchResp[13] & BIT4) != 0)) {
2728 }
else if ((SwitchResp[13] & BIT1) != 0) {
2736 DEBUG ((DEBUG_INFO,
"SdPeimSetBusMode: AccessMode %d ClockFreq %d BusWidth %d\n", AccessMode, ClockFreq, BusWidth));
2739 if (EFI_ERROR (Status)) {
2740 DEBUG ((DEBUG_ERROR,
"SdPeimSetBusMode: SdPeimSwitch fails with %r\n", Status));
2744 if ((SwitchResp[16] & 0xF) != AccessMode) {
2745 DEBUG ((DEBUG_ERROR,
"SdPeimSetBusMode: SdPeimSwitch to AccessMode %d ClockFreq %d BusWidth %d fails! The Switch response is 0x%1x\n", AccessMode, ClockFreq, BusWidth, SwitchResp[16] & 0xF));
2746 return EFI_DEVICE_ERROR;
2752 if (AccessMode == 1) {
2754 Status =
SdPeimHcOrMmio (Slot->SdHcBase + SD_HC_HOST_CTRL1, sizeof (HostCtrl1), &HostCtrl1);
2755 if (EFI_ERROR (Status)) {
2760 HostCtrl2 = (UINT8) ~0x7;
2761 Status =
SdPeimHcAndMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
2762 if (EFI_ERROR (Status)) {
2766 HostCtrl2 = AccessMode;
2767 Status =
SdPeimHcOrMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
2768 if (EFI_ERROR (Status)) {
2773 if (EFI_ERROR (Status)) {
2774 DEBUG ((DEBUG_ERROR,
"SdPeimSetBusMode: SdPeimHcClockSupply %r\n", Status));
2778 if ((AccessMode == 3) || ((AccessMode == 2) && (Capability.TuningSDR50 != 0))) {
2780 if (EFI_ERROR (Status)) {
2781 DEBUG ((DEBUG_ERROR,
"SdPeimSetBusMode: SdPeimTuningClock fails with %r\n", Status));
2786 DEBUG ((DEBUG_INFO,
"SdPeimSetBusMode: SdPeimSetBusMode %r\n", Status));
2814 UINT16 ControllerVer;
2816 UINT32 PresentState;
2825 if (EFI_ERROR (Status)) {
2826 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: Executing Cmd0 fails with %r\n", Status));
2834 if (EFI_ERROR (Status)) {
2835 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: Executing Cmd8 fails with %r\n", Status));
2843 if (!EFI_ERROR (Status)) {
2844 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: Found SDIO device, ignore it as we don't support\n"));
2845 return EFI_DEVICE_ERROR;
2852 if (EFI_ERROR (Status)) {
2853 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: Executing SdPeimSendOpCond fails with %r\n", Status));
2854 return EFI_DEVICE_ERROR;
2858 if (EFI_ERROR (Status)) {
2862 Status =
SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_MAX_CURRENT_CAP,
TRUE, sizeof (Current), &Current);
2863 if (EFI_ERROR (Status)) {
2867 if (Capability.Voltage33 != 0) {
2871 MaxCurrent = ((UINT32)Current & 0xFF) * 4;
2872 }
else if (Capability.Voltage30 != 0) {
2876 MaxCurrent = (((UINT32)Current >> 8) & 0xFF) * 4;
2877 }
else if (Capability.Voltage18 != 0) {
2881 MaxCurrent = (((UINT32)Current >> 16) & 0xFF) * 4;
2884 return EFI_DEVICE_ERROR;
2887 if (MaxCurrent >= 150) {
2893 Status =
SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_CTRL_VER,
TRUE, sizeof (ControllerVer), &ControllerVer);
2894 if (EFI_ERROR (Status)) {
2898 if ((ControllerVer & 0xFF) == 2) {
2900 }
else if (((ControllerVer & 0xFF) == 0) || ((ControllerVer & 0xFF) == 1)) {
2904 return EFI_UNSUPPORTED;
2916 if (EFI_ERROR (Status)) {
2917 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: SdPeimSendOpCond fails with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));
2918 return EFI_DEVICE_ERROR;
2921 if (Retry++ == 100) {
2922 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: SdPeimSendOpCond fails too many times\n"));
2923 return EFI_DEVICE_ERROR;
2927 }
while ((Ocr & BIT31) == 0);
2934 if (((Capability.Sdr50 != 0) ||
2935 (Capability.Sdr104 != 0) ||
2936 (Capability.Ddr50 != 0)) &&
2937 ((Ocr & BIT24) != 0))
2940 if (EFI_ERROR (Status)) {
2941 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: Executing SdPeimVoltageSwitch fails with %r\n", Status));
2942 Status = EFI_DEVICE_ERROR;
2946 if (EFI_ERROR (Status)) {
2947 Status = EFI_DEVICE_ERROR;
2951 SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_PRESENT_STATE,
TRUE, sizeof (PresentState), &PresentState);
2952 if (((PresentState >> 20) & 0xF) != 0) {
2953 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: SwitchVoltage fails with PresentState = 0x%x\n", PresentState));
2954 Status = EFI_DEVICE_ERROR;
2959 SdPeimHcOrMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
2963 SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_HOST_CTRL2,
TRUE, sizeof (HostCtrl2), &HostCtrl2);
2964 if ((HostCtrl2 & BIT3) == 0) {
2965 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: SwitchVoltage fails with HostCtrl2 = 0x%x\n", HostCtrl2));
2966 Status = EFI_DEVICE_ERROR;
2974 SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_PRESENT_STATE,
TRUE, sizeof (PresentState), &PresentState);
2975 if (((PresentState >> 20) & 0xF) != 0xF) {
2976 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));
2977 Status = EFI_DEVICE_ERROR;
2982 DEBUG ((DEBUG_INFO,
"SdPeimIdentification: Switch to 1.8v signal voltage success\n"));
2986 if (EFI_ERROR (Status)) {
2987 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: Executing SdPeimAllSendCid fails with %r\n", Status));
2992 if (EFI_ERROR (Status)) {
2993 DEBUG ((DEBUG_ERROR,
"SdPeimIdentification: Executing SdPeimSetRca fails with %r\n", Status));
3000 DEBUG ((DEBUG_INFO,
"Found a SD device at slot [%d]\n", Slot));
3010 PowerCtrl = (UINT8) ~BIT0;
3011 Status =
SdPeimHcAndMmio (Slot->SdHcBase + SD_HC_POWER_CTRL, sizeof (PowerCtrl), &PowerCtrl);
3012 return EFI_DEVICE_ERROR;
EFI_STATUS IoMmuUnmap(IN VOID *Mapping)
EFI_STATUS IoMmuMap(IN EDKII_IOMMU_OPERATION Operation, IN VOID *HostAddress, IN OUT UINTN *NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
INTN EFIAPI HighBitSet32(IN UINT32 Operand)
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)
UINT64 EFIAPI MmioWrite64(IN UINTN Address, IN UINT64 Value)
UINT64 EFIAPI MmioRead64(IN UINTN Address)
UINT16 EFIAPI MmioRead16(IN UINTN Address)
UINT8 EFIAPI MmioRead8(IN UINTN Address)
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
UINT16 EFIAPI MmioWrite16(IN UINTN Address, IN UINT16 Value)
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
#define DEBUG(Expression)
@ EdkiiIoMmuOperationBusMasterWrite
@ EdkiiIoMmuOperationBusMasterRead
VOID SdPeimFreeMem(IN SD_PEIM_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size)
VOID * SdPeimAllocateMem(IN SD_PEIM_MEM_POOL *Pool, IN UINTN Size)
EFI_STATUS SdPeimHcSetBusWidth(IN UINTN Bar, IN UINT16 BusWidth)
EFI_STATUS SdPeimVoltageCheck(IN SD_PEIM_HC_SLOT *Slot, IN UINT8 SupplyVoltage, IN UINT8 CheckPattern)
EFI_STATUS SdPeimHcStopClock(IN UINTN Bar)
EFI_STATUS EFIAPI SdPeimHcRwMmio(IN UINTN Address, IN BOOLEAN Read, IN UINT8 Count, IN OUT VOID *Data)
EFI_STATUS SdPeimGetCsd(IN SD_PEIM_HC_SLOT *Slot, IN UINT16 Rca, OUT SD_CSD *Csd)
EFI_STATUS EFIAPI SdPeimHcWaitMmioSet(IN UINTN Address, IN UINT8 Count, IN UINT64 MaskValue, IN UINT64 TestValue, IN UINT64 Timeout)
EFI_STATUS SdPeimWaitTrbResult(IN UINTN Bar, IN SD_TRB *Trb)
EFI_STATUS SdPeimCheckTrbResult(IN UINTN Bar, IN SD_TRB *Trb)
EFI_STATUS SdPeimTuningClock(IN SD_PEIM_HC_SLOT *Slot)
EFI_STATUS SdPeimReset(IN SD_PEIM_HC_SLOT *Slot)
SD_TRB * SdPeimCreateTrb(IN SD_PEIM_HC_SLOT *Slot, IN SD_COMMAND_PACKET *Packet)
EFI_STATUS SdPeimHcClockSupply(IN UINTN Bar, IN UINT64 ClockFreq)
EFI_STATUS SdPeimExecTrb(IN UINTN Bar, IN SD_TRB *Trb)
EFI_STATUS SdPeimHcCardDetect(IN UINTN Bar)
EFI_STATUS SdPeimHcInitHost(IN UINTN Bar)
EFI_STATUS SdPeimHcInitClockFreq(IN UINTN Bar)
EFI_STATUS SdPeimSelect(IN SD_PEIM_HC_SLOT *Slot, IN UINT16 Rca)
EFI_STATUS SdPeimHcPowerControl(IN UINTN Bar, IN UINT8 PowerCtrl)
EFI_STATUS SdPeimSetBusMode(IN SD_PEIM_HC_SLOT *Slot, IN UINT16 Rca, IN BOOLEAN S18a)
EFI_STATUS SdPeimVoltageSwitch(IN SD_PEIM_HC_SLOT *Slot)
EFI_STATUS SdPeimHcInitTimeoutCtrl(IN UINTN Bar)
EFI_STATUS SdPeimHcEnableInterrupt(IN UINTN Bar)
EFI_STATUS SdPeimSendTuningBlk(IN SD_PEIM_HC_SLOT *Slot)
EFI_STATUS SdioSendOpCond(IN SD_PEIM_HC_SLOT *Slot, IN UINT32 VoltageWindow, IN BOOLEAN S18r)
EFI_STATUS SdPeimRwMultiBlocks(IN SD_PEIM_HC_SLOT *Slot, IN EFI_LBA Lba, IN UINT32 BlockSize, IN VOID *Buffer, IN UINTN BufferSize, IN BOOLEAN IsRead)
EFI_STATUS SdPeimSendOpCond(IN SD_PEIM_HC_SLOT *Slot, IN UINT16 Rca, IN UINT32 VoltageWindow, IN BOOLEAN S18r, IN BOOLEAN Xpc, IN BOOLEAN Hcs, OUT UINT32 *Ocr)
EFI_STATUS SdPeimCheckTrbEnv(IN UINTN Bar, IN SD_TRB *Trb)
EFI_STATUS SdPeimSwitchBusWidth(IN SD_PEIM_HC_SLOT *Slot, IN UINT16 Rca, IN UINT8 BusWidth)
EFI_STATUS EFIAPI SdPeimHcOrMmio(IN UINTN Address, IN UINT8 Count, IN VOID *OrData)
EFI_STATUS SdPeimAllSendCid(IN SD_PEIM_HC_SLOT *Slot)
EFI_STATUS SdPeimSetRca(IN SD_PEIM_HC_SLOT *Slot, OUT UINT16 *Rca)
EFI_STATUS EFIAPI SdPeimHcCheckMmioSet(IN UINTN Address, IN UINT8 Count, IN UINT64 MaskValue, IN UINT64 TestValue)
EFI_STATUS SdPeimHcReset(IN UINTN Bar)
EFI_STATUS SdPeimIdentification(IN SD_PEIM_HC_SLOT *Slot)
EFI_STATUS SdPeimSendStatus(IN SD_PEIM_HC_SLOT *Slot, IN UINT16 Rca, OUT UINT32 *DevStatus)
EFI_STATUS SdPeimSetBusWidth(IN SD_PEIM_HC_SLOT *Slot, IN UINT16 Rca, IN UINT8 BusWidth)
EFI_STATUS BuildAdmaDescTable(IN SD_TRB *Trb)
EFI_STATUS SdPeimWaitTrbEnv(IN UINTN Bar, IN SD_TRB *Trb)
VOID SdPeimFreeTrb(IN SD_TRB *Trb)
EFI_STATUS EFIAPI SdPeimHcAndMmio(IN UINTN Address, IN UINT8 Count, IN VOID *AndData)
EFI_STATUS SdPeimRwSingleBlock(IN SD_PEIM_HC_SLOT *Slot, IN EFI_LBA Lba, IN UINT32 BlockSize, IN VOID *Buffer, IN UINTN BufferSize, IN BOOLEAN IsRead)
EFI_STATUS SdPeimHcInitPowerVoltage(IN UINTN Bar)
EFI_STATUS SdPeimSwitch(IN SD_PEIM_HC_SLOT *Slot, IN UINT8 AccessMode, IN UINT8 CommandSystem, IN UINT8 DriveStrength, IN UINT8 PowerLimit, IN BOOLEAN Mode, OUT UINT8 *SwitchResp)
EFI_STATUS SdPeimHcLedOnOff(IN UINTN Bar, IN BOOLEAN On)
EFI_STATUS SdPeimHcGetCapability(IN UINTN Bar, OUT SD_HC_SLOT_CAP *Capability)
EFI_STATUS EFIAPI SdPeimExecCmd(IN SD_PEIM_HC_SLOT *Slot, IN OUT SD_COMMAND_PACKET *Packet)
UINT64 EFI_PHYSICAL_ADDRESS