29 Status =
gBS->CloseEvent (Event);
30 if (EFI_ERROR (Status)) {
39 "Emmc Async Request: CmdIndex[%d] Arg[%08x] %r\n",
40 Request->SdMmcCmdBlk.CommandIndex,
41 Request->SdMmcCmdBlk.CommandArgument,
42 Request->Packet.TransactionStatus
46 if (EFI_ERROR (Request->Packet.TransactionStatus)) {
53 gBS->SignalEvent (Request->Token->
Event);
82 PassThru = Device->Private->PassThru;
84 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
85 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
86 ZeroMem (&Packet,
sizeof (Packet));
87 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
88 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
89 Packet.Timeout = EMMC_GENERIC_TIMEOUT;
91 SdMmcCmdBlk.CommandIndex = EMMC_SELECT_DESELECT_CARD;
92 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
93 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
94 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
96 Status = PassThru->PassThru (PassThru, Device->Slot, &Packet,
NULL);
117 OUT UINT32 *DevStatus
126 PassThru = Device->Private->PassThru;
128 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
129 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
130 ZeroMem (&Packet,
sizeof (Packet));
131 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
132 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
133 Packet.Timeout = EMMC_GENERIC_TIMEOUT;
135 SdMmcCmdBlk.CommandIndex = EMMC_SEND_STATUS;
136 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
137 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
138 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
140 Status = PassThru->PassThru (PassThru, Device->Slot, &Packet,
NULL);
141 if (!EFI_ERROR (Status)) {
142 CopyMem (DevStatus, &SdMmcStatusBlk.Resp0, sizeof (UINT32));
173 PassThru = Device->Private->PassThru;
175 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
176 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
177 ZeroMem (&Packet,
sizeof (Packet));
180 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
181 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
182 Packet.Timeout = EMMC_GENERIC_TIMEOUT;
184 SdMmcCmdBlk.CommandIndex = EMMC_SEND_CSD;
185 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
186 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR2;
187 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
189 Status = PassThru->PassThru (PassThru, Device->Slot, &Packet,
NULL);
190 if (!EFI_ERROR (Status)) {
194 CopyMem (((UINT8 *)Csd) + 1, &SdMmcStatusBlk.Resp0, sizeof (
EMMC_CSD) - 1);
225 PassThru = Device->Private->PassThru;
227 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
228 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
229 ZeroMem (&Packet,
sizeof (Packet));
232 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
233 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
234 Packet.Timeout = EMMC_GENERIC_TIMEOUT;
236 SdMmcCmdBlk.CommandIndex = EMMC_SEND_CID;
237 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
238 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR2;
239 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
241 Status = PassThru->PassThru (PassThru, Device->Slot, &Packet,
NULL);
242 if (!EFI_ERROR (Status)) {
246 CopyMem (((UINT8 *)Cid) + 1, &SdMmcStatusBlk.Resp0, sizeof (
EMMC_CID) - 1);
275 PassThru = Device->Private->PassThru;
277 ZeroMem (&SdMmcCmdBlk,
sizeof (SdMmcCmdBlk));
278 ZeroMem (&SdMmcStatusBlk,
sizeof (SdMmcStatusBlk));
279 ZeroMem (&Packet,
sizeof (Packet));
281 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
282 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
283 Packet.Timeout = EMMC_GENERIC_TIMEOUT;
285 SdMmcCmdBlk.CommandIndex = EMMC_SEND_EXT_CSD;
286 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
287 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
288 SdMmcCmdBlk.CommandArgument = 0x00000000;
289 Packet.InDataBuffer = ExtCsd;
292 Status = PassThru->PassThru (PassThru, Device->Slot, &Packet,
NULL);
325 UINT32 CommandArgument;
330 Device = Partition->Device;
331 PassThru = Device->Private->PassThru;
334 if (SetExtCsdReq ==
NULL) {
335 Status = EFI_OUT_OF_RESOURCES;
339 SetExtCsdReq->Signature = EMMC_REQUEST_SIGNATURE;
340 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
342 gBS->RestoreTPL (OldTpl);
343 SetExtCsdReq->Packet.SdMmcCmdBlk = &SetExtCsdReq->SdMmcCmdBlk;
344 SetExtCsdReq->Packet.SdMmcStatusBlk = &SetExtCsdReq->SdMmcStatusBlk;
345 SetExtCsdReq->Packet.Timeout = EMMC_GENERIC_TIMEOUT;
347 SetExtCsdReq->SdMmcCmdBlk.CommandIndex = EMMC_SWITCH;
348 SetExtCsdReq->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
349 SetExtCsdReq->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
353 CommandArgument = (Value << 8) | (Offset << 16) | BIT24 | BIT25;
354 SetExtCsdReq->SdMmcCmdBlk.CommandArgument = CommandArgument;
356 SetExtCsdReq->IsEnd = IsEnd;
357 SetExtCsdReq->Token = Token;
359 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
360 Status =
gBS->CreateEvent (
367 if (EFI_ERROR (Status)) {
371 SetExtCsdReq->Event =
NULL;
374 Status = PassThru->PassThru (PassThru, Device->Slot, &SetExtCsdReq->Packet, SetExtCsdReq->Event);
377 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
382 if (EFI_ERROR (Status) && (SetExtCsdReq !=
NULL)) {
383 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
385 gBS->RestoreTPL (OldTpl);
386 if (SetExtCsdReq->Event !=
NULL) {
387 gBS->CloseEvent (SetExtCsdReq->Event);
396 if (SetExtCsdReq !=
NULL) {
397 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
399 gBS->RestoreTPL (OldTpl);
437 Device = Partition->Device;
438 PassThru = Device->Private->PassThru;
441 if (SetBlkCntReq ==
NULL) {
442 Status = EFI_OUT_OF_RESOURCES;
446 SetBlkCntReq->Signature = EMMC_REQUEST_SIGNATURE;
447 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
449 gBS->RestoreTPL (OldTpl);
450 SetBlkCntReq->Packet.SdMmcCmdBlk = &SetBlkCntReq->SdMmcCmdBlk;
451 SetBlkCntReq->Packet.SdMmcStatusBlk = &SetBlkCntReq->SdMmcStatusBlk;
452 SetBlkCntReq->Packet.Timeout = EMMC_GENERIC_TIMEOUT;
454 SetBlkCntReq->SdMmcCmdBlk.CommandIndex = EMMC_SET_BLOCK_COUNT;
455 SetBlkCntReq->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
456 SetBlkCntReq->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
457 SetBlkCntReq->SdMmcCmdBlk.CommandArgument = BlockNum;
459 SetBlkCntReq->IsEnd = IsEnd;
460 SetBlkCntReq->Token = Token;
462 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
463 Status =
gBS->CreateEvent (
470 if (EFI_ERROR (Status)) {
474 SetBlkCntReq->Event =
NULL;
477 Status = PassThru->PassThru (PassThru, Device->Slot, &SetBlkCntReq->Packet, SetBlkCntReq->Event);
480 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
485 if (EFI_ERROR (Status) && (SetBlkCntReq !=
NULL)) {
486 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
488 gBS->RestoreTPL (OldTpl);
489 if (SetBlkCntReq->Event !=
NULL) {
490 gBS->CloseEvent (SetBlkCntReq->Event);
499 if (SetBlkCntReq !=
NULL) {
500 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
502 gBS->RestoreTPL (OldTpl);
537 IN UINT8 SecurityProtocol,
538 IN UINT16 SecurityProtocolSpecificData,
540 OUT VOID *PayloadBuffer,
555 Device = Partition->Device;
556 PassThru = Device->Private->PassThru;
559 if (ProtocolReq ==
NULL) {
560 Status = EFI_OUT_OF_RESOURCES;
564 ProtocolReq->Signature = EMMC_REQUEST_SIGNATURE;
565 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
567 gBS->RestoreTPL (OldTpl);
568 ProtocolReq->Packet.SdMmcCmdBlk = &ProtocolReq->SdMmcCmdBlk;
569 ProtocolReq->Packet.SdMmcStatusBlk = &ProtocolReq->SdMmcStatusBlk;
572 ProtocolReq->Packet.InDataBuffer = PayloadBuffer;
573 ProtocolReq->Packet.InTransferLength = (UINT32)PayloadBufferSize;
575 ProtocolReq->SdMmcCmdBlk.CommandIndex = EMMC_PROTOCOL_RD;
576 ProtocolReq->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
577 ProtocolReq->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
579 ProtocolReq->Packet.OutDataBuffer = PayloadBuffer;
580 ProtocolReq->Packet.OutTransferLength = (UINT32)PayloadBufferSize;
582 ProtocolReq->SdMmcCmdBlk.CommandIndex = EMMC_PROTOCOL_WR;
583 ProtocolReq->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
584 ProtocolReq->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
587 ProtocolReq->SdMmcCmdBlk.CommandArgument = (SecurityProtocol << 8) | (SecurityProtocolSpecificData << 16);
591 ProtocolReq->Packet.Timeout =
DivU64x32 (Timeout, 10) + 1;
593 ProtocolReq->IsEnd = IsEnd;
594 ProtocolReq->Token = Token;
596 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
597 Status =
gBS->CreateEvent (
604 if (EFI_ERROR (Status)) {
608 ProtocolReq->Event =
NULL;
611 Status = PassThru->PassThru (PassThru, Device->Slot, &ProtocolReq->Packet, ProtocolReq->Event);
614 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
619 if (EFI_ERROR (Status) && (ProtocolReq !=
NULL)) {
620 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
622 gBS->RestoreTPL (OldTpl);
623 if (ProtocolReq->Event !=
NULL) {
624 gBS->CloseEvent (ProtocolReq->Event);
633 if (ProtocolReq !=
NULL) {
634 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
636 gBS->RestoreTPL (OldTpl);
680 RwMultiBlkReq =
NULL;
682 Device = Partition->Device;
683 PassThru = Device->Private->PassThru;
686 if (RwMultiBlkReq ==
NULL) {
687 Status = EFI_OUT_OF_RESOURCES;
691 RwMultiBlkReq->Signature = EMMC_REQUEST_SIGNATURE;
692 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
694 gBS->RestoreTPL (OldTpl);
695 RwMultiBlkReq->Packet.SdMmcCmdBlk = &RwMultiBlkReq->SdMmcCmdBlk;
696 RwMultiBlkReq->Packet.SdMmcStatusBlk = &RwMultiBlkReq->SdMmcStatusBlk;
704 RwMultiBlkReq->Packet.Timeout = (BufferSize / (2 * 1024 * 1024) + 1) * 1000 * 1000;
707 RwMultiBlkReq->Packet.InDataBuffer = Buffer;
708 RwMultiBlkReq->Packet.InTransferLength = (UINT32)BufferSize;
710 RwMultiBlkReq->SdMmcCmdBlk.CommandIndex = EMMC_READ_MULTIPLE_BLOCK;
711 RwMultiBlkReq->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
712 RwMultiBlkReq->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
714 RwMultiBlkReq->Packet.OutDataBuffer = Buffer;
715 RwMultiBlkReq->Packet.OutTransferLength = (UINT32)BufferSize;
717 RwMultiBlkReq->SdMmcCmdBlk.CommandIndex = EMMC_WRITE_MULTIPLE_BLOCK;
718 RwMultiBlkReq->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
719 RwMultiBlkReq->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
722 if (Partition->Device->SectorAddressing) {
723 RwMultiBlkReq->SdMmcCmdBlk.CommandArgument = (UINT32)Lba;
725 RwMultiBlkReq->SdMmcCmdBlk.CommandArgument = (UINT32)
MultU64x32 (Lba, Partition->BlockMedia.BlockSize);
728 RwMultiBlkReq->IsEnd = IsEnd;
729 RwMultiBlkReq->Token = Token;
731 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
732 Status =
gBS->CreateEvent (
737 &RwMultiBlkReq->Event
739 if (EFI_ERROR (Status)) {
743 RwMultiBlkReq->Event =
NULL;
746 Status = PassThru->PassThru (PassThru, Device->Slot, &RwMultiBlkReq->Packet, RwMultiBlkReq->Event);
749 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
754 if (EFI_ERROR (Status) && (RwMultiBlkReq !=
NULL)) {
755 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
757 gBS->RestoreTPL (OldTpl);
758 if (RwMultiBlkReq->Event !=
NULL) {
759 gBS->CloseEvent (RwMultiBlkReq->Event);
768 if (RwMultiBlkReq !=
NULL) {
769 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
771 gBS->RestoreTPL (OldTpl);
819 UINT8 PartitionConfig;
825 Device = Partition->Device;
826 Media = &Partition->BlockMedia;
829 if (MediaId != Media->
MediaId) {
830 return EFI_MEDIA_CHANGED;
834 return EFI_WRITE_PROTECTED;
840 if (Buffer ==
NULL) {
841 return EFI_INVALID_PARAMETER;
844 if (BufferSize == 0) {
845 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
847 gBS->SignalEvent (Token->Event);
854 if ((BufferSize % BlockSize) != 0) {
855 return EFI_BAD_BUFFER_SIZE;
858 BlockNum = BufferSize / BlockSize;
859 if ((Lba + BlockNum - 1) > Media->
LastBlock) {
860 return EFI_INVALID_PARAMETER;
864 if ((IoAlign > 0) && (((
UINTN)Buffer & (IoAlign - 1)) != 0)) {
865 return EFI_INVALID_PARAMETER;
868 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
875 PartitionConfig = Device->ExtCsd.PartitionConfig;
876 if ((PartitionConfig & 0x7) != Partition->PartitionType) {
877 PartitionConfig &= (UINT8) ~0x7;
878 PartitionConfig |= Partition->PartitionType;
880 if (EFI_ERROR (Status)) {
884 Device->ExtCsd.PartitionConfig = PartitionConfig;
890 Remaining = BlockNum;
893 while (Remaining > 0) {
894 if (Remaining <= MaxBlock) {
895 BlockNum = Remaining;
902 if (EFI_ERROR (Status)) {
906 BufferSize = BlockNum * BlockSize;
907 Status =
EmmcRwMultiBlocks (Partition, Lba, Buffer, BufferSize, IsRead, Token, LastRw);
908 if (EFI_ERROR (Status)) {
914 "Emmc%a(): Part %d Lba 0x%x BlkNo 0x%x Event %p with %r\n",
915 IsRead ?
"Read " :
"Write",
916 Partition->PartitionType,
919 (Token !=
NULL) ? Token->Event :
NULL,
924 Buffer = (UINT8 *)Buffer + BufferSize;
925 Remaining -= BlockNum;
946 IN BOOLEAN ExtendedVerification
953 Partition = EMMC_PARTITION_DATA_FROM_BLKIO (This);
955 PassThru = Partition->Device->Private->PassThru;
956 Status = PassThru->ResetDevice (PassThru, Partition->Device->Slot);
957 if (EFI_ERROR (Status)) {
958 Status = EFI_DEVICE_ERROR;
996 Partition = EMMC_PARTITION_DATA_FROM_BLKIO (This);
1035 Partition = EMMC_PARTITION_DATA_FROM_BLKIO (This);
1078 IN BOOLEAN ExtendedVerification
1087 Partition = EMMC_PARTITION_DATA_FROM_BLKIO2 (This);
1089 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1091 !
IsNull (&Partition->Queue, Link);
1097 Request = EMMC_REQUEST_FROM_LINK (Link);
1099 gBS->CloseEvent (Request->Event);
1102 if (Request->IsEnd) {
1103 gBS->SignalEvent (Request->Token->
Event);
1109 gBS->RestoreTPL (OldTpl);
1154 Partition = EMMC_PARTITION_DATA_FROM_BLKIO2 (This);
1156 Status =
EmmcReadWrite (Partition, MediaId, Lba, Buffer, BufferSize,
TRUE, Token);
1196 Partition = EMMC_PARTITION_DATA_FROM_BLKIO2 (This);
1223 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
1225 gBS->SignalEvent (Token->Event);
1312 IN UINT8 SecurityProtocolId,
1313 IN UINT16 SecurityProtocolSpecificData,
1315 OUT VOID *PayloadBuffer,
1329 UINT8 PartitionConfig;
1332 Partition = EMMC_PARTITION_DATA_FROM_SSP (This);
1333 Device = Partition->Device;
1334 Media = &Partition->BlockMedia;
1336 if (PayloadTransferSize !=
NULL) {
1337 *PayloadTransferSize = 0;
1340 if ((PayloadBuffer ==
NULL) && (PayloadBufferSize != 0)) {
1341 return EFI_INVALID_PARAMETER;
1344 if (MediaId != Media->
MediaId) {
1345 return EFI_MEDIA_CHANGED;
1348 if (PayloadBufferSize == 0) {
1353 if ((PayloadBufferSize % BlockSize) != 0) {
1354 return EFI_BAD_BUFFER_SIZE;
1357 BlockNum = PayloadBufferSize / BlockSize;
1360 if ((IoAlign > 0) && (((
UINTN)PayloadBuffer & (IoAlign - 1)) != 0)) {
1361 return EFI_INVALID_PARAMETER;
1374 PartitionConfig = Device->ExtCsd.PartitionConfig;
1375 if ((PartitionConfig & 0x7) != Partition->PartitionType) {
1376 PartitionConfig &= (UINT8) ~0x7;
1377 PartitionConfig |= Partition->PartitionType;
1379 if (EFI_ERROR (Status)) {
1383 Device->ExtCsd.PartitionConfig = PartitionConfig;
1389 Remaining = BlockNum;
1392 while (Remaining > 0) {
1393 if (Remaining <= MaxBlock) {
1394 BlockNum = Remaining;
1396 BlockNum = MaxBlock;
1400 if (EFI_ERROR (Status)) {
1404 PayloadBufferSize = BlockNum * BlockSize;
1405 Status =
EmmcProtocolInOut (Partition, SecurityProtocolId, SecurityProtocolSpecificData, PayloadBufferSize, PayloadBuffer, IsRead, Timeout,
NULL,
FALSE);
1406 if (EFI_ERROR (Status)) {
1410 PayloadBuffer = (UINT8 *)PayloadBuffer + PayloadBufferSize;
1411 Remaining -= BlockNum;
1412 if (PayloadTransferSize !=
NULL) {
1413 *PayloadTransferSize += PayloadBufferSize;
1500 IN UINT8 SecurityProtocolId,
1501 IN UINT16 SecurityProtocolSpecificData,
1503 OUT VOID *PayloadBuffer,
1509 if ((PayloadTransferSize ==
NULL) && (PayloadBufferSize != 0)) {
1510 return EFI_INVALID_PARAMETER;
1518 SecurityProtocolSpecificData,
1521 PayloadTransferSize,
1597 IN UINT8 SecurityProtocolId,
1598 IN UINT16 SecurityProtocolSpecificData,
1600 IN VOID *PayloadBuffer
1610 SecurityProtocolSpecificData,
1648 EraseBlockStart =
NULL;
1650 Device = Partition->Device;
1651 PassThru = Device->Private->PassThru;
1654 if (EraseBlockStart ==
NULL) {
1655 Status = EFI_OUT_OF_RESOURCES;
1659 EraseBlockStart->Signature = EMMC_REQUEST_SIGNATURE;
1660 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1662 gBS->RestoreTPL (OldTpl);
1663 EraseBlockStart->Packet.SdMmcCmdBlk = &EraseBlockStart->SdMmcCmdBlk;
1664 EraseBlockStart->Packet.SdMmcStatusBlk = &EraseBlockStart->SdMmcStatusBlk;
1665 EraseBlockStart->Packet.Timeout = EMMC_GENERIC_TIMEOUT;
1667 EraseBlockStart->SdMmcCmdBlk.CommandIndex = EMMC_ERASE_GROUP_START;
1668 EraseBlockStart->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
1669 EraseBlockStart->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
1671 if (Device->SectorAddressing) {
1672 EraseBlockStart->SdMmcCmdBlk.CommandArgument = (UINT32)StartLba;
1674 EraseBlockStart->SdMmcCmdBlk.CommandArgument = (UINT32)
MultU64x32 (StartLba, Partition->BlockMedia.BlockSize);
1677 EraseBlockStart->IsEnd = IsEnd;
1678 EraseBlockStart->Token = Token;
1680 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
1681 Status =
gBS->CreateEvent (
1686 &EraseBlockStart->Event
1688 if (EFI_ERROR (Status)) {
1692 EraseBlockStart->Event =
NULL;
1695 Status = PassThru->PassThru (PassThru, Device->Slot, &EraseBlockStart->Packet, EraseBlockStart->Event);
1698 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
1703 if (EFI_ERROR (Status) && (EraseBlockStart !=
NULL)) {
1704 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1706 gBS->RestoreTPL (OldTpl);
1707 if (EraseBlockStart->Event !=
NULL) {
1708 gBS->CloseEvent (EraseBlockStart->Event);
1717 if (EraseBlockStart !=
NULL) {
1718 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1720 gBS->RestoreTPL (OldTpl);
1756 EraseBlockEnd =
NULL;
1758 Device = Partition->Device;
1759 PassThru = Device->Private->PassThru;
1762 if (EraseBlockEnd ==
NULL) {
1763 Status = EFI_OUT_OF_RESOURCES;
1767 EraseBlockEnd->Signature = EMMC_REQUEST_SIGNATURE;
1768 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1770 gBS->RestoreTPL (OldTpl);
1771 EraseBlockEnd->Packet.SdMmcCmdBlk = &EraseBlockEnd->SdMmcCmdBlk;
1772 EraseBlockEnd->Packet.SdMmcStatusBlk = &EraseBlockEnd->SdMmcStatusBlk;
1773 EraseBlockEnd->Packet.Timeout = EMMC_GENERIC_TIMEOUT;
1775 EraseBlockEnd->SdMmcCmdBlk.CommandIndex = EMMC_ERASE_GROUP_END;
1776 EraseBlockEnd->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
1777 EraseBlockEnd->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
1779 if (Device->SectorAddressing) {
1780 EraseBlockEnd->SdMmcCmdBlk.CommandArgument = (UINT32)EndLba;
1782 EraseBlockEnd->SdMmcCmdBlk.CommandArgument = (UINT32)
MultU64x32 (EndLba, Partition->BlockMedia.BlockSize);
1785 EraseBlockEnd->IsEnd = IsEnd;
1786 EraseBlockEnd->Token = Token;
1788 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
1789 Status =
gBS->CreateEvent (
1794 &EraseBlockEnd->Event
1796 if (EFI_ERROR (Status)) {
1800 EraseBlockEnd->Event =
NULL;
1803 Status = PassThru->PassThru (PassThru, Device->Slot, &EraseBlockEnd->Packet, EraseBlockEnd->Event);
1806 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
1811 if (EFI_ERROR (Status) && (EraseBlockEnd !=
NULL)) {
1812 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1814 gBS->RestoreTPL (OldTpl);
1815 if (EraseBlockEnd->Event !=
NULL) {
1816 gBS->CloseEvent (EraseBlockEnd->Event);
1825 if (EraseBlockEnd !=
NULL) {
1826 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1828 gBS->RestoreTPL (OldTpl);
1864 Device = Partition->Device;
1865 PassThru = Device->Private->PassThru;
1868 if (EraseBlock ==
NULL) {
1869 Status = EFI_OUT_OF_RESOURCES;
1873 EraseBlock->Signature = EMMC_REQUEST_SIGNATURE;
1874 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1876 gBS->RestoreTPL (OldTpl);
1877 EraseBlock->Packet.SdMmcCmdBlk = &EraseBlock->SdMmcCmdBlk;
1878 EraseBlock->Packet.SdMmcStatusBlk = &EraseBlock->SdMmcStatusBlk;
1879 EraseBlock->Packet.Timeout = EMMC_GENERIC_TIMEOUT;
1881 EraseBlock->SdMmcCmdBlk.CommandIndex = EMMC_ERASE;
1882 EraseBlock->SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
1883 EraseBlock->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
1884 if ((Device->ExtCsd.SecFeatureSupport & BIT4) != 0) {
1890 EraseBlock->SdMmcCmdBlk.CommandArgument = 1;
1893 EraseBlock->IsEnd = IsEnd;
1894 EraseBlock->Token = Token;
1896 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
1897 Status =
gBS->CreateEvent (
1904 if (EFI_ERROR (Status)) {
1908 EraseBlock->Event =
NULL;
1911 Status = PassThru->PassThru (PassThru, Device->Slot, &EraseBlock->Packet, EraseBlock->Event);
1914 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
1919 if (EFI_ERROR (Status) && (EraseBlock !=
NULL)) {
1920 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1922 gBS->RestoreTPL (OldTpl);
1923 if (EraseBlock->Event !=
NULL) {
1924 gBS->CloseEvent (EraseBlock->Event);
1933 if (EraseBlock !=
NULL) {
1934 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1936 gBS->RestoreTPL (OldTpl);
1969 if (Buffer ==
NULL) {
1970 return EFI_OUT_OF_RESOURCES;
1973 MediaId = Partition->BlockMedia.MediaId;
2026 UINT32 EraseGroupSize;
2028 UINTN WriteZeroSize;
2029 UINT8 PartitionConfig;
2034 Partition = EMMC_PARTITION_DATA_FROM_ERASEBLK (This);
2035 Device = Partition->Device;
2036 Media = &Partition->BlockMedia;
2038 if (MediaId != Media->
MediaId) {
2039 return EFI_MEDIA_CHANGED;
2043 return EFI_WRITE_PROTECTED;
2050 if ((Size % BlockSize) != 0) {
2051 return EFI_INVALID_PARAMETER;
2054 BlockNum = Size / BlockSize;
2055 if ((Lba + BlockNum - 1) > Media->
LastBlock) {
2056 return EFI_INVALID_PARAMETER;
2059 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
2064 LastLba = Lba + BlockNum - 1;
2069 PartitionConfig = Device->ExtCsd.PartitionConfig;
2070 if ((PartitionConfig & 0x7) != Partition->PartitionType) {
2071 PartitionConfig &= (UINT8) ~0x7;
2072 PartitionConfig |= Partition->PartitionType;
2074 if (EFI_ERROR (Status)) {
2078 Device->ExtCsd.PartitionConfig = PartitionConfig;
2081 if ((Device->ExtCsd.SecFeatureSupport & BIT4) == 0) {
2086 EraseGroupSize = This->EraseLengthGranularity;
2089 StartGroupLba = (Remainder == 0) ? FirstLba : (FirstLba + EraseGroupSize - Remainder);
2092 EndGroupLba = LastLba + 1 - Remainder;
2098 if (BlockNum < EraseGroupSize) {
2100 if (EFI_ERROR (Status)) {
2106 "EmmcEraseBlocks(): Lba 0x%x BlkNo 0x%x Event %p with %r\n",
2109 (Token !=
NULL) ? Token->Event :
NULL,
2113 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
2115 gBS->SignalEvent (Token->Event);
2126 if (StartGroupLba > FirstLba) {
2127 WriteZeroSize = (
UINTN)(StartGroupLba - FirstLba) * BlockSize;
2129 if (EFI_ERROR (Status)) {
2139 if (EndGroupLba <= LastLba) {
2140 WriteZeroSize = (
UINTN)(LastLba + 1 - EndGroupLba) * BlockSize;
2142 if (EFI_ERROR (Status)) {
2150 if (EndGroupLba <= StartGroupLba) {
2153 "EmmcEraseBlocks(): Lba 0x%x BlkNo 0x%x Event %p with %r\n",
2156 (Token !=
NULL) ? Token->Event :
NULL,
2160 if ((Token !=
NULL) && (Token->Event !=
NULL)) {
2162 gBS->SignalEvent (Token->Event);
2168 FirstLba = StartGroupLba;
2169 LastLba = EndGroupLba - 1;
2173 if (EFI_ERROR (Status)) {
2178 if (EFI_ERROR (Status)) {
2183 if (EFI_ERROR (Status)) {
2189 "EmmcEraseBlocks(): Lba 0x%x BlkNo 0x%x Event %p with %r\n",
2192 (Token !=
NULL) ? Token->Event :
NULL,
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
UINT64 EFIAPI DivU64x32Remainder(IN UINT64 Dividend, IN UINT32 Divisor, OUT UINT32 *Remainder OPTIONAL)
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)
EFI_STATUS EmmcSetBlkCount(IN EMMC_PARTITION *Partition, IN UINT16 BlockNum, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
EFI_STATUS EFIAPI EmmcSecurityProtocolIn(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, OUT VOID *PayloadBuffer, OUT UINTN *PayloadTransferSize)
EFI_STATUS EFIAPI EmmcWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS EmmcSetExtCsd(IN EMMC_PARTITION *Partition, IN UINT8 Offset, IN UINT8 Value, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
EFI_STATUS EFIAPI EmmcResetEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
EFI_STATUS EmmcEraseBlockEnd(IN EMMC_PARTITION *Partition, IN EFI_LBA EndLba, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
EFI_STATUS EFIAPI EmmcReadBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EmmcSendStatus(IN EMMC_DEVICE *Device, IN UINT16 Rca, OUT UINT32 *DevStatus)
EFI_STATUS EFIAPI EmmcReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EmmcWriteZeros(IN EMMC_PARTITION *Partition, IN EFI_LBA StartLba, IN UINTN Size)
EFI_STATUS EFIAPI EmmcSecurityProtocolInOut(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, OUT VOID *PayloadBuffer, OUT UINTN *PayloadTransferSize, IN BOOLEAN IsRead)
EFI_STATUS EmmcEraseBlockStart(IN EMMC_PARTITION *Partition, IN EFI_LBA StartLba, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
EFI_STATUS EFIAPI EmmcWriteBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS EmmcGetCsd(IN EMMC_DEVICE *Device, IN UINT16 Rca, OUT EMMC_CSD *Csd)
EFI_STATUS EmmcRwMultiBlocks(IN EMMC_PARTITION *Partition, IN EFI_LBA Lba, IN VOID *Buffer, IN UINTN BufferSize, IN BOOLEAN IsRead, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
EFI_STATUS EmmcGetExtCsd(IN EMMC_DEVICE *Device, OUT EMMC_EXT_CSD *ExtCsd)
EFI_STATUS EFIAPI EmmcEraseBlocks(IN EFI_ERASE_BLOCK_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_ERASE_BLOCK_TOKEN *Token, IN UINTN Size)
EFI_STATUS EFIAPI EmmcFlushBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
EFI_STATUS EFIAPI EmmcSecurityProtocolOut(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, IN VOID *PayloadBuffer)
EFI_STATUS EmmcProtocolInOut(IN EMMC_PARTITION *Partition, IN UINT8 SecurityProtocol, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, OUT VOID *PayloadBuffer, IN BOOLEAN IsRead, IN UINT64 Timeout, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
EFI_STATUS EmmcGetCid(IN EMMC_DEVICE *Device, IN UINT16 Rca, OUT EMMC_CID *Cid)
EFI_STATUS EmmcSelect(IN EMMC_DEVICE *Device, IN UINT16 Rca)
EFI_STATUS EmmcEraseBlock(IN EMMC_PARTITION *Partition, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
EFI_STATUS EFIAPI EmmcFlushBlocks(IN EFI_BLOCK_IO_PROTOCOL *This)
VOID EFIAPI AsyncIoCallback(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EmmcReadWrite(IN EMMC_PARTITION *Partition, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT VOID *Buffer, IN UINTN BufferSize, IN BOOLEAN IsRead, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
EFI_STATUS EFIAPI EmmcReset(IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
#define OFFSET_OF(TYPE, Field)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
EFI_STATUS TransactionStatus