49 if (Value == TestValue) {
59 }
while (InfiniteWait || (Delay > 0));
77 if (UicOpcode <= UfsUicDmePeerSet) {
82 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - INVALID_MIB_ATTRIBUTE\n"));
85 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - INVALID_MIB_ATTRIBUTE_VALUE\n"));
88 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - READ_ONLY_MIB_ATTRIBUTE\n"));
91 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - WRITE_ONLY_MIB_ATTRIBUTE\n"));
94 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - BAD_INDEX\n"));
97 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - LOCKED_MIB_ATTRIBUTE\n"));
100 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - BAD_TEST_FEATURE_INDEX\n"));
103 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - PEER_COMMUNICATION_FAILURE\n"));
106 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - BUSY\n"));
109 DEBUG ((DEBUG_VERBOSE,
"UIC configuration command fails - DME_FAILURE\n"));
120 DEBUG ((DEBUG_VERBOSE,
"UIC control command fails - FAILURE\n"));
142 DEBUG ((DEBUG_VERBOSE,
"Query Response with Parameter Not Readable\n"));
145 DEBUG ((DEBUG_VERBOSE,
"Query Response with Parameter Not Writeable\n"));
148 DEBUG ((DEBUG_VERBOSE,
"Query Response with Parameter Already Written\n"));
151 DEBUG ((DEBUG_VERBOSE,
"Query Response with Invalid Length\n"));
154 DEBUG ((DEBUG_VERBOSE,
"Query Response with Invalid Value\n"));
157 DEBUG ((DEBUG_VERBOSE,
"Query Response with Invalid Selector\n"));
160 DEBUG ((DEBUG_VERBOSE,
"Query Response with Invalid Index\n"));
163 DEBUG ((DEBUG_VERBOSE,
"Query Response with Invalid Idn\n"));
166 DEBUG ((DEBUG_VERBOSE,
"Query Response with Invalid Opcode\n"));
169 DEBUG ((DEBUG_VERBOSE,
"Query Response with General Failure\n"));
187 IN OUT UINT8 *Buffer,
195 SwapCount = BufferSize / 2;
196 for (Index = 0; Index < SwapCount; Index++) {
197 Temp = Buffer[Index];
198 Buffer[Index] = Buffer[BufferSize - 1 - Index];
199 Buffer[BufferSize - 1 - Index] = Temp;
219 IN UINT8 DescId OPTIONAL,
220 IN UINT8 Index OPTIONAL,
221 IN UINT8 Selector OPTIONAL,
222 IN UINT16 Length OPTIONAL,
223 IN UINT32 Value OPTIONAL
226 ASSERT (TsfBase !=
NULL);
227 ASSERT (Opcode <= UtpQueryFuncOpcodeTogFlag);
229 TsfBase->Opcode = Opcode;
230 if (Opcode != UtpQueryFuncOpcodeNop) {
231 TsfBase->DescId = DescId;
232 TsfBase->Index = Index;
233 TsfBase->Selector = Selector;
235 if ((Opcode == UtpQueryFuncOpcodeRdDesc) || (Opcode == UtpQueryFuncOpcodeWrDesc)) {
237 TsfBase->Length = Length;
240 if (Opcode == UtpQueryFuncOpcodeWrAttr) {
242 TsfBase->Value = Value;
268 IN UFS_DATA_DIRECTION DataDirection,
269 IN UINT32 ExpDataTranLen
274 ASSERT ((Command !=
NULL) && (Cdb !=
NULL));
279 if (DataDirection == UfsDataIn) {
281 }
else if (DataDirection == UfsDataOut) {
290 Command->TransCode = 0x01;
291 Command->Flags = Flags;
293 Command->TaskTag = TaskTag;
294 Command->CmdSet = 0x00;
296 Command->ExpDataTranLen = ExpDataTranLen;
298 CopyMem (Command->Cdb, Cdb, CdbLength);
325 if ((BufferSize & (BIT0 | BIT1)) != 0) {
326 BufferSize &= ~(BIT0 | BIT1);
327 DEBUG ((DEBUG_WARN,
"UfsInitUtpPrdt: The BufferSize [%d] is not dword-aligned!\n", BufferSize));
330 if (BufferSize == 0) {
334 ASSERT (((
UINTN)Buffer & (BIT0 | BIT1)) == 0);
336 RemainingLen = BufferSize;
338 PrdtNumber = (
UINTN)
DivU64x32 ((UINT64)BufferSize + UFS_MAX_DATA_LEN_PER_PRD - 1, UFS_MAX_DATA_LEN_PER_PRD);
340 for (PrdtIndex = 0; PrdtIndex < PrdtNumber; PrdtIndex++) {
341 if (RemainingLen < UFS_MAX_DATA_LEN_PER_PRD) {
342 Prdt[PrdtIndex].DbCount = (UINT32)RemainingLen - 1;
344 Prdt[PrdtIndex].DbCount = UFS_MAX_DATA_LEN_PER_PRD - 1;
347 Prdt[PrdtIndex].DbAddr = (UINT32)
RShiftU64 ((UINT64)(
UINTN)Remaining, 2);
348 Prdt[PrdtIndex].DbAddrU = (UINT32)
RShiftU64 ((UINT64)(
UINTN)Remaining, 32);
349 RemainingLen -= UFS_MAX_DATA_LEN_PER_PRD;
350 Remaining += UFS_MAX_DATA_LEN_PER_PRD;
380 IN UINT8 *Data OPTIONAL
383 ASSERT (QueryReq !=
NULL);
385 QueryReq->TransCode = 0x16;
386 QueryReq->TaskTag = TaskTag;
387 if ((Opcode == UtpQueryFuncOpcodeRdDesc) || (Opcode == UtpQueryFuncOpcodeRdFlag) || (Opcode == UtpQueryFuncOpcodeRdAttr)) {
388 QueryReq->QueryFunc = QUERY_FUNC_STD_READ_REQ;
390 QueryReq->QueryFunc = QUERY_FUNC_STD_WRITE_REQ;
393 if (Opcode == UtpQueryFuncOpcodeWrAttr) {
395 }
else if ((Opcode == UtpQueryFuncOpcodeRdDesc) || (Opcode == UtpQueryFuncOpcodeWrDesc)) {
401 if (Opcode == UtpQueryFuncOpcodeWrDesc) {
402 CopyMem (QueryReq + 1, Data, DataSize);
405 QueryReq->DataSegLen = (UINT16)DataSize;
441 UFS_DATA_DIRECTION DataDirection;
447 ASSERT ((Private !=
NULL) && (Packet !=
NULL) && (Trd !=
NULL));
451 if (Packet->DataDirection == UfsDataIn) {
452 Buffer = Packet->InDataBuffer;
453 Length = Packet->InTransferLength;
454 DataDirection = UfsDataIn;
457 Buffer = Packet->OutDataBuffer;
458 Length = Packet->OutTransferLength;
459 DataDirection = UfsDataOut;
464 DataDirection = UfsNoData;
467 Status =
IoMmuMap (MapOp, Buffer, &MapLength, &BufferPhyAddr, BufferMap);
469 if (EFI_ERROR (Status) || (MapLength != Length)) {
470 DEBUG ((DEBUG_ERROR,
"UfsCreateScsiCommandDesc: Fail to map data buffer.\n"));
471 return EFI_OUT_OF_RESOURCES;
475 PrdtNumber = (
UINTN)
DivU64x32 ((UINT64)Length + UFS_MAX_DATA_LEN_PER_PRD - 1, UFS_MAX_DATA_LEN_PER_PRD);
479 if (CommandDesc ==
NULL) {
480 return EFI_OUT_OF_RESOURCES;
486 UfsInitCommandUpiu (CommandUpiu, Lun, Private->TaskTag++, Packet->Cdb, Packet->CdbLength, DataDirection, Length);
494 Trd->Int = UFS_INTERRUPT_COMMAND;
495 Trd->Dd = DataDirection;
496 Trd->Ct = UFS_STORAGE_COMMAND_TYPE;
497 Trd->Ocs = UFS_HC_TRD_OCS_INIT_VALUE;
502 Trd->PrdtL = (UINT16)PrdtNumber;
535 ASSERT ((Private !=
NULL) && (Packet !=
NULL) && (Trd !=
NULL));
537 Opcode = Packet->Opcode;
538 if ((Opcode > UtpQueryFuncOpcodeTogFlag) || (Opcode == UtpQueryFuncOpcodeNop)) {
539 return EFI_INVALID_PARAMETER;
542 DataDirection = Packet->DataDirection;
543 if (DataDirection == UfsDataIn) {
544 DataSize = Packet->InTransferLength;
545 Data = Packet->InDataBuffer;
546 }
else if (DataDirection == UfsDataOut) {
547 DataSize = Packet->OutTransferLength;
548 Data = Packet->OutDataBuffer;
554 if (((Opcode != UtpQueryFuncOpcodeRdFlag) && (Opcode != UtpQueryFuncOpcodeSetFlag) &&
555 (Opcode != UtpQueryFuncOpcodeClrFlag) && (Opcode != UtpQueryFuncOpcodeTogFlag) &&
556 (Opcode != UtpQueryFuncOpcodeRdAttr)) && ((DataSize == 0) || (Data ==
NULL)))
558 return EFI_INVALID_PARAMETER;
561 if ((Opcode == UtpQueryFuncOpcodeWrAttr) && (DataSize !=
sizeof (UINT32))) {
562 return EFI_INVALID_PARAMETER;
565 if ((Opcode == UtpQueryFuncOpcodeWrDesc) || (Opcode == UtpQueryFuncOpcodeRdDesc)) {
572 if (CommandDesc ==
NULL) {
573 return EFI_OUT_OF_RESOURCES;
595 Trd->Int = UFS_INTERRUPT_COMMAND;
596 Trd->Dd = DataDirection;
597 Trd->Ct = UFS_STORAGE_COMMAND_TYPE;
598 Trd->Ocs = UFS_HC_TRD_OCS_INIT_VALUE;
600 Trd->UcdBaU = (UINT32)
RShiftU64 ((UINT64)(
UINTN)QueryReqUpiu, 32);
601 if (Opcode == UtpQueryFuncOpcodeWrDesc) {
633 ASSERT ((Private !=
NULL) && (Trd !=
NULL));
637 if (CommandDesc ==
NULL) {
638 return EFI_OUT_OF_RESOURCES;
643 NopOutUpiu->TaskTag = Private->TaskTag++;
649 Trd->Int = UFS_INTERRUPT_COMMAND;
651 Trd->Ct = UFS_STORAGE_COMMAND_TYPE;
652 Trd->Ocs = UFS_HC_TRD_OCS_INIT_VALUE;
676 ASSERT ((Private !=
NULL) && (Slot !=
NULL));
704 UfsHcBase = Private->UfsHcBase;
706 Address = UfsHcBase + UFS_HC_UTRLRSR_OFFSET;
708 if ((Data & UFS_HC_UTRLRSR) != UFS_HC_UTRLRSR) {
712 Address = UfsHcBase + UFS_HC_UTRLDBR_OFFSET;
733 UfsHcBase = Private->UfsHcBase;
735 Address = UfsHcBase + UFS_HC_UTRLDBR_OFFSET;
737 if ((Data & (BIT0 << Slot)) != 0) {
738 Address = UfsHcBase + UFS_HC_UTRLCLR_OFFSET;
761 UINT16 ReturnDataSize;
766 if ((Packet ==
NULL) || (QueryResp ==
NULL)) {
767 return EFI_INVALID_PARAMETER;
770 switch (Packet->Opcode) {
771 case UtpQueryFuncOpcodeRdDesc:
772 ReturnDataSize = QueryResp->Tsf.Length;
777 if (ReturnDataSize > Packet->InTransferLength) {
778 return EFI_DEVICE_ERROR;
781 CopyMem (Packet->InDataBuffer, (QueryResp + 1), ReturnDataSize);
782 Packet->InTransferLength = ReturnDataSize;
784 case UtpQueryFuncOpcodeWrDesc:
785 ReturnDataSize = QueryResp->Tsf.Length;
787 Packet->OutTransferLength = ReturnDataSize;
789 case UtpQueryFuncOpcodeRdFlag:
793 *((UINT8 *)(Packet->InDataBuffer)) = *((UINT8 *)&(QueryResp->Tsf.Value) + 3);
795 case UtpQueryFuncOpcodeSetFlag:
796 case UtpQueryFuncOpcodeClrFlag:
797 case UtpQueryFuncOpcodeTogFlag:
801 *((UINT8 *)(Packet->OutDataBuffer)) = *((UINT8 *)&(QueryResp->Tsf.Value) + 3);
803 case UtpQueryFuncOpcodeRdAttr:
804 ReturnData = QueryResp->Tsf.Value;
806 CopyMem (Packet->InDataBuffer, &ReturnData, sizeof (UINT32));
808 case UtpQueryFuncOpcodeWrAttr:
809 ReturnData = QueryResp->Tsf.Value;
811 CopyMem (Packet->OutDataBuffer, &ReturnData, sizeof (UINT32));
814 return EFI_INVALID_PARAMETER;
853 if (EFI_ERROR (Status)) {
857 Trd = ((
UTP_TRD *)Private->UtpTrlBase) + Slot;
862 if (EFI_ERROR (Status)) {
863 DEBUG ((DEBUG_ERROR,
"Failed to create DM command descriptor\n"));
872 CmdDescSize = Trd->RuO *
sizeof (UINT32) + Trd->RuL * sizeof (UINT32);
882 Address = Private->UfsHcBase + UFS_HC_UTRLDBR_OFFSET;
883 Status =
UfsWaitMemSet (Address, (BIT0 << Slot), 0, Packet->Timeout);
884 if (EFI_ERROR (Status)) {
888 if ((Trd->Ocs != 0) || (QueryResp->QueryResp != UfsUtpQueryResponseSuccess)) {
889 DEBUG ((DEBUG_ERROR,
"Failed to send query request, OCS = %X, QueryResp = %X\n", Trd->Ocs, QueryResp->QueryResp));
891 Status = EFI_DEVICE_ERROR;
896 if (EFI_ERROR (Status)) {
897 DEBUG ((DEBUG_ERROR,
"Failed to get return data from query response\n"));
932 for (Retry = 0; Retry < 5; Retry++) {
934 if (!EFI_ERROR (Status)) {
939 DEBUG ((DEBUG_ERROR,
"Failed to get response from the device after %d retries\n", Retry));
966 IN OUT VOID *Descriptor,
976 Packet.DataDirection = UfsDataIn;
977 Packet.InDataBuffer = Descriptor;
978 Packet.InTransferLength = DescSize;
979 Packet.Opcode = UtpQueryFuncOpcodeRdDesc;
981 Packet.DataDirection = UfsDataOut;
982 Packet.OutDataBuffer = Descriptor;
983 Packet.OutTransferLength = DescSize;
984 Packet.Opcode = UtpQueryFuncOpcodeWrDesc;
987 Packet.DescId = DescId;
988 Packet.Index = Index;
989 Packet.Selector = Selector;
990 Packet.Timeout = UFS_TIMEOUT;
1020 IN OUT UINT32 *Attributes
1028 Packet.DataDirection = UfsDataIn;
1029 Packet.Opcode = UtpQueryFuncOpcodeRdAttr;
1030 Packet.InDataBuffer = Attributes;
1032 Packet.DataDirection = UfsDataOut;
1033 Packet.Opcode = UtpQueryFuncOpcodeWrAttr;
1034 Packet.OutDataBuffer = Attributes;
1035 Packet.OutTransferLength =
sizeof (UINT32);
1038 Packet.DescId = AttrId;
1039 Packet.Index = Index;
1040 Packet.Selector = Selector;
1041 Packet.Timeout = UFS_TIMEOUT;
1070 if (Value ==
NULL) {
1071 return EFI_INVALID_PARAMETER;
1077 ASSERT (Value !=
NULL);
1078 Packet.DataDirection = UfsDataIn;
1079 Packet.InDataBuffer = (VOID *)Value;
1080 Packet.InTransferLength = 0;
1081 Packet.Opcode = UtpQueryFuncOpcodeRdFlag;
1083 Packet.DataDirection = UfsDataOut;
1084 Packet.OutDataBuffer = (VOID *)Value;
1085 Packet.OutTransferLength = 0;
1087 Packet.Opcode = UtpQueryFuncOpcodeSetFlag;
1088 }
else if (*Value == 0) {
1089 Packet.Opcode = UtpQueryFuncOpcodeClrFlag;
1091 return EFI_INVALID_PARAMETER;
1095 Packet.DescId = FlagId;
1097 Packet.Selector = 0;
1098 Packet.Timeout = UFS_TIMEOUT;
1187 if (EFI_ERROR (Status)) {
1191 Trd = ((
UTP_TRD *)Private->UtpTrlBase) + Slot;
1193 if (EFI_ERROR (Status)) {
1201 NopInUpiu = (
UTP_NOP_IN_UPIU *)(CmdDescBase + Trd->RuO * sizeof (UINT32));
1202 CmdDescSize = Trd->RuO *
sizeof (UINT32) + Trd->RuL * sizeof (UINT32);
1212 Address = Private->UfsHcBase + UFS_HC_UTRLDBR_OFFSET;
1213 Status =
UfsWaitMemSet (Address, BIT0 << Slot, 0, UFS_TIMEOUT);
1214 if (EFI_ERROR (Status)) {
1218 if (NopInUpiu->Resp != 0) {
1219 Status = EFI_DEVICE_ERROR;
1264 UINT16 SenseDataLen;
1265 UINT32 ResTranCount;
1266 VOID *PacketBufferMap;
1272 if (EFI_ERROR (Status)) {
1276 Trd = ((
UTP_TRD *)Private->UtpTrlBase) + Slot;
1277 PacketBufferMap =
NULL;
1283 if (EFI_ERROR (Status)) {
1288 CmdDescSize = Trd->PrdtO *
sizeof (UINT32) + Trd->PrdtL * sizeof (
UTP_TR_PRD);
1298 Address = Private->UfsHcBase + UFS_HC_UTRLDBR_OFFSET;
1299 Status =
UfsWaitMemSet (Address, BIT0 << Slot, 0, Packet->Timeout);
1300 if (EFI_ERROR (Status)) {
1308 SenseDataLen = Response->SenseDataLen;
1311 if ((Packet->SenseDataLength != 0) && (Packet->SenseData !=
NULL)) {
1315 if (SenseDataLen <= Packet->SenseDataLength) {
1316 CopyMem (Packet->SenseData, Response->SenseData, SenseDataLen);
1317 Packet->SenseDataLength = (UINT8)SenseDataLen;
1319 Packet->SenseDataLength = 0;
1326 if (Response->Response != 0) {
1327 DEBUG ((DEBUG_ERROR,
"UfsExecScsiCmds() fails with Target Failure\n"));
1328 Status = EFI_DEVICE_ERROR;
1332 if (Trd->Ocs == 0) {
1333 if (Packet->DataDirection == UfsDataIn) {
1334 if ((Response->Flags & BIT5) == BIT5) {
1335 ResTranCount = Response->ResTranCount;
1337 Packet->InTransferLength -= ResTranCount;
1339 }
else if (Packet->DataDirection == UfsDataOut) {
1340 if ((Response->Flags & BIT5) == BIT5) {
1341 ResTranCount = Response->ResTranCount;
1343 Packet->OutTransferLength -= ResTranCount;
1347 Status = EFI_DEVICE_ERROR;
1351 if (PacketBufferMap !=
NULL) {
1389 UfsHcBase = Private->UfsHcBase;
1390 Address = UfsHcBase + UFS_HC_IS_OFFSET;
1392 if ((Data & UFS_HC_IS_UCCS) == UFS_HC_IS_UCCS) {
1404 Address = UfsHcBase + UFS_HC_UCMD_ARG1_OFFSET;
1407 Address = UfsHcBase + UFS_HC_UCMD_ARG2_OFFSET;
1410 Address = UfsHcBase + UFS_HC_UCMD_ARG3_OFFSET;
1416 Address = Private->UfsHcBase + UFS_HC_STATUS_OFFSET;
1417 Status =
UfsWaitMemSet (Address, UFS_HC_HCS_UCRDY, UFS_HC_HCS_UCRDY, UFS_TIMEOUT);
1418 if (EFI_ERROR (Status)) {
1422 Address = UfsHcBase + UFS_HC_UIC_CMD_OFFSET;
1429 Address = UfsHcBase + UFS_HC_IS_OFFSET;
1431 Status =
UfsWaitMemSet (Address, UFS_HC_IS_UCCS, UFS_HC_IS_UCCS, UFS_TIMEOUT);
1432 if (EFI_ERROR (Status)) {
1436 if (UicOpcode != UfsUicDmeReset) {
1437 Address = UfsHcBase + UFS_HC_UCMD_ARG2_OFFSET;
1439 if ((Data & 0xFF) != 0) {
1443 return EFI_DEVICE_ERROR;
1470 if ((UfsHcPlatformPpi !=
NULL) && (UfsHcPlatformPpi->Callback !=
NULL)) {
1471 Status = UfsHcPlatformPpi->Callback (&Private->UfsHcBase, EdkiiUfsHcPreHce);
1472 if (EFI_ERROR (Status)) {
1473 DEBUG ((DEBUG_ERROR,
"Failure from platform driver during EdkiiUfsHcPreHce, Status = %r\n", Status));
1483 Address = Private->UfsHcBase + UFS_HC_ENABLE_OFFSET;
1485 if ((Data & UFS_HC_HCE_EN) == UFS_HC_HCE_EN) {
1493 Status =
UfsWaitMemSet (Address, UFS_HC_HCE_EN, 0, UFS_TIMEOUT);
1494 if (EFI_ERROR (Status)) {
1495 return EFI_DEVICE_ERROR;
1506 Status =
UfsWaitMemSet (Address, UFS_HC_HCE_EN, UFS_HC_HCE_EN, UFS_TIMEOUT);
1507 if (EFI_ERROR (Status)) {
1508 return EFI_DEVICE_ERROR;
1511 if ((UfsHcPlatformPpi !=
NULL) && (UfsHcPlatformPpi->Callback !=
NULL)) {
1512 Status = UfsHcPlatformPpi->Callback (&Private->UfsHcBase, EdkiiUfsHcPostHce);
1513 if (EFI_ERROR (Status)) {
1514 DEBUG ((DEBUG_ERROR,
"Failure from platform driver during EdkiiUfsHcPostHce, Status = %r\n", Status));
1543 if ((UfsHcPlatformPpi !=
NULL) && (UfsHcPlatformPpi->Callback !=
NULL)) {
1544 Status = UfsHcPlatformPpi->Callback (&Private->UfsHcBase, EdkiiUfsHcPreLinkStartup);
1545 if (EFI_ERROR (Status)) {
1546 DEBUG ((DEBUG_ERROR,
"Failure from platform driver during EdkiiUfsHcPreLinkStartup, Status = %r\n", Status));
1555 for (Retry = 0; Retry < 3; Retry++) {
1557 if (EFI_ERROR (Status)) {
1558 return EFI_DEVICE_ERROR;
1564 Address = Private->UfsHcBase + UFS_HC_STATUS_OFFSET;
1566 if ((Data & UFS_HC_HCS_DP) == 0) {
1567 Address = Private->UfsHcBase + UFS_HC_IS_OFFSET;
1568 Status =
UfsWaitMemSet (Address, UFS_HC_IS_ULSS, UFS_HC_IS_ULSS, UFS_TIMEOUT);
1569 if (EFI_ERROR (Status)) {
1570 return EFI_DEVICE_ERROR;
1573 DEBUG ((DEBUG_INFO,
"UfsblockioPei: found a attached UFS device\n"));
1578 return EFI_NOT_FOUND;
1600 VOID *CmdDescMapping;
1606 Address = Private->UfsHcBase + UFS_HC_CAP_OFFSET;
1608 Private->Capabilities = Data;
1613 Nutmrs = (UINT8)(
RShiftU64 ((Private->Capabilities & UFS_HC_CAP_NUTMRS), 16) + 1);
1620 if (EFI_ERROR (Status)) {
1621 return EFI_DEVICE_ERROR;
1630 Address = Private->UfsHcBase + UFS_HC_UTMRLBA_OFFSET;
1632 Address = Private->UfsHcBase + UFS_HC_UTMRLBAU_OFFSET;
1634 Private->UtpTmrlBase = (VOID *)(
UINTN)CmdDescHost;
1635 Private->Nutmrs = Nutmrs;
1636 Private->TmrlMapping = CmdDescMapping;
1642 Address = Private->UfsHcBase + UFS_HC_UTMRLRSR_OFFSET;
1667 VOID *CmdDescMapping;
1673 Address = Private->UfsHcBase + UFS_HC_CAP_OFFSET;
1675 Private->Capabilities = Data;
1680 Nutrs = (UINT8)((Private->Capabilities & UFS_HC_CAP_NUTRS) + 1);
1687 if (EFI_ERROR (Status)) {
1688 return EFI_DEVICE_ERROR;
1697 Address = Private->UfsHcBase + UFS_HC_UTRLBA_OFFSET;
1699 Address = Private->UfsHcBase + UFS_HC_UTRLBAU_OFFSET;
1701 Private->UtpTrlBase = (VOID *)(
UINTN)CmdDescHost;
1702 Private->Nutrs = Nutrs;
1703 Private->TrlMapping = CmdDescMapping;
1709 Address = Private->UfsHcBase + UFS_HC_UTRLRSR_OFFSET;
1734 if (EFI_ERROR (Status)) {
1735 DEBUG ((DEBUG_ERROR,
"UfsDevicePei: Enable Host Controller Fails, Status = %r\n", Status));
1740 if (EFI_ERROR (Status)) {
1741 DEBUG ((DEBUG_ERROR,
"UfsDevicePei: Device Detection Fails, Status = %r\n", Status));
1746 if (EFI_ERROR (Status)) {
1747 DEBUG ((DEBUG_ERROR,
"UfsDevicePei: Task management list initialization Fails, Status = %r\n", Status));
1752 if (EFI_ERROR (Status)) {
1753 DEBUG ((DEBUG_ERROR,
"UfsDevicePei: Transfer list initialization Fails, Status = %r\n", Status));
1755 if (Private->TmrlMapping !=
NULL) {
1758 Private->UtpTmrlBase,
1759 Private->TmrlMapping
1761 Private->TmrlMapping =
NULL;
1767 DEBUG ((DEBUG_INFO,
"UfsDevicePei Finished\n"));
1793 Address = Private->UfsHcBase + UFS_HC_UTMRLRSR_OFFSET;
1800 Address = Private->UfsHcBase + UFS_HC_UTRLRSR_OFFSET;
1806 Address = Private->UfsHcBase + UFS_HC_ENABLE_OFFSET;
1808 ASSERT ((Data & UFS_HC_HCE_EN) == UFS_HC_HCE_EN);
1814 Status =
UfsWaitMemSet (Address, UFS_HC_HCE_EN, 0, UFS_TIMEOUT);
1815 if (EFI_ERROR (Status)) {
1816 return EFI_DEVICE_ERROR;
1819 DEBUG ((DEBUG_INFO,
"UfsDevicePei: Stop the UFS Host Controller\n"));
EFI_STATUS IoMmuUnmap(IN VOID *Mapping)
EFI_STATUS IoMmuAllocateBuffer(IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT 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)
EFI_STATUS IoMmuFreeBuffer(IN UINTN Pages, IN VOID *HostAddress, IN VOID *Mapping)
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
@ EdkiiIoMmuOperationBusMasterWrite
@ EdkiiIoMmuOperationBusMasterRead
VOID EFIAPI Exit(IN EFI_STATUS Status)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
VOID * UfsPeimAllocateMem(IN UFS_PEIM_MEM_POOL *Pool, IN UINTN Size)
VOID UfsPeimFreeMem(IN UFS_PEIM_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size)
EFI_STATUS UfsCreateNopCommandDesc(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UTP_TRD *Trd)
EFI_STATUS UfsGetReturnDataFromQueryResponse(IN OUT UFS_DEVICE_MANAGEMENT_REQUEST_PACKET *Packet, IN UTP_QUERY_RESP_UPIU *QueryResp)
VOID UfsStopExecCmd(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
EFI_STATUS EFIAPI UfsWaitMemSet(IN UINTN Address, IN UINT32 MaskValue, IN UINT32 TestValue, IN UINT64 Timeout)
EFI_STATUS UfsRwDeviceDesc(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN BOOLEAN Read, IN UINT8 DescId, IN UINT8 Index, IN UINT8 Selector, IN OUT VOID *Descriptor, IN UINT32 DescSize)
EFI_STATUS UfsInitTransferRequestList(IN UFS_PEIM_HC_PRIVATE_DATA *Private)
EFI_STATUS UfsRwAttributes(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN BOOLEAN Read, IN UINT8 AttrId, IN UINT8 Index, IN UINT8 Selector, IN OUT UINT32 *Attributes)
EFI_STATUS UfsFindAvailableSlotInTrl(IN UFS_PEIM_HC_PRIVATE_DATA *Private, OUT UINT8 *Slot)
VOID SwapLittleEndianToBigEndian(IN OUT UINT8 *Buffer, IN UINT32 BufferSize)
EFI_STATUS UfsReadFlag(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 FlagId, OUT UINT8 *Value)
EFI_STATUS UfsCreateScsiCommandDesc(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 Lun, IN UFS_SCSI_REQUEST_PACKET *Packet, IN UTP_TRD *Trd, OUT VOID **BufferMap)
EFI_STATUS UfsExecNopCmds(IN UFS_PEIM_HC_PRIVATE_DATA *Private)
EFI_STATUS UfsSendDmRequest(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN OUT UFS_DEVICE_MANAGEMENT_REQUEST_PACKET *Packet)
VOID UfsFillTsfOfQueryReqUpiu(IN OUT UTP_UPIU_TSF *TsfBase, IN UINT8 Opcode, IN UINT8 DescId OPTIONAL, IN UINT8 Index OPTIONAL, IN UINT8 Selector OPTIONAL, IN UINT16 Length OPTIONAL, IN UINT32 Value OPTIONAL)
VOID DumpUicCmdExecResult(IN UINT8 UicOpcode, IN UINT8 Result)
EFI_STATUS UfsInitUtpPrdt(IN UTP_TR_PRD *Prdt, IN VOID *Buffer, IN UINT32 BufferSize)
EFI_STATUS UfsControllerInit(IN EDKII_UFS_HC_PLATFORM_PPI *UfsHcPlatformPpi, IN UFS_PEIM_HC_PRIVATE_DATA *Private)
EFI_STATUS UfsSendDmRequestRetry(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN OUT UFS_DEVICE_MANAGEMENT_REQUEST_PACKET *Packet)
EFI_STATUS UfsRwFlags(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN BOOLEAN Read, IN UINT8 FlagId, IN OUT UINT8 *Value)
EFI_STATUS UfsInitCommandUpiu(IN OUT UTP_COMMAND_UPIU *Command, IN UINT8 Lun, IN UINT8 TaskTag, IN UINT8 *Cdb, IN UINT8 CdbLength, IN UFS_DATA_DIRECTION DataDirection, IN UINT32 ExpDataTranLen)
EFI_STATUS UfsDeviceDetection(IN EDKII_UFS_HC_PLATFORM_PPI *UfsHcPlatformPpi, IN UFS_PEIM_HC_PRIVATE_DATA *Private)
EFI_STATUS UfsControllerStop(IN UFS_PEIM_HC_PRIVATE_DATA *Private)
EFI_STATUS UfsEnableHostController(IN EDKII_UFS_HC_PLATFORM_PPI *UfsHcPlatformPpi, IN UFS_PEIM_HC_PRIVATE_DATA *Private)
VOID UfsStartExecCmd(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
EFI_STATUS UfsInitTaskManagementRequestList(IN UFS_PEIM_HC_PRIVATE_DATA *Private)
EFI_STATUS UfsSetFlag(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 FlagId)
EFI_STATUS UfsExecUicCommands(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 UicOpcode, IN UINT32 Arg1, IN UINT32 Arg2, IN UINT32 Arg3)
VOID DumpQueryResponseResult(IN UINT8 Result)
EFI_STATUS UfsCreateDMCommandDesc(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UFS_DEVICE_MANAGEMENT_REQUEST_PACKET *Packet, IN UTP_TRD *Trd)
EFI_STATUS UfsExecScsiCmds(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 Lun, IN OUT UFS_SCSI_REQUEST_PACKET *Packet)
EFI_STATUS UfsInitQueryRequestUpiu(IN OUT UTP_QUERY_REQ_UPIU *QueryReq, IN UINT8 TaskTag, IN UINT8 Opcode, IN UINT8 DescId, IN UINT8 Index, IN UINT8 Selector, IN UINTN DataSize OPTIONAL, IN UINT8 *Data OPTIONAL)