118 EFI_PEI_RECOVERY_BLOCK_IO2_PPI_REVISION,
124 EFI_PEI_PPI_DESCRIPTOR_PPI,
125 &gEfiPeiVirtualBlockIoPpiGuid,
129 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
130 &gEfiPeiVirtualBlockIo2PpiGuid,
134 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
135 &gEfiEndOfPeiSignalPpiGuid,
191 Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS (This);
192 *NumberBlockDevices = Private->TotalBlkIoDevices;
253 Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS (This);
255 if ((DeviceIndex == 0) || (DeviceIndex > Private->TotalBlkIoDevices)) {
256 return EFI_INVALID_PARAMETER;
261 for (SlotNum = 0; SlotNum < Private->SlotNum; SlotNum++) {
262 for (MediaNum = 0; MediaNum < Private->Slot[SlotNum].MediaNum; MediaNum++) {
264 if (Location == DeviceIndex) {
275 MediaInfo->DeviceType =
EMMC;
276 MediaInfo->MediaPresent =
TRUE;
277 MediaInfo->LastBlock = (
UINTN)Private->Slot[SlotNum].Media[MediaNum].
LastBlock;
278 MediaInfo->BlockSize = Private->Slot[SlotNum].Media[MediaNum].
BlockSize;
330 UINTN NumberOfBlocks;
335 UINT8 PartitionConfig;
342 Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS (This);
347 if (Buffer ==
NULL) {
348 return EFI_INVALID_PARAMETER;
351 if (BufferSize == 0) {
355 if ((DeviceIndex == 0) || (DeviceIndex > Private->TotalBlkIoDevices)) {
356 return EFI_INVALID_PARAMETER;
361 for (SlotNum = 0; SlotNum < Private->SlotNum; SlotNum++) {
362 for (MediaNum = 0; MediaNum < Private->Slot[SlotNum].MediaNum; MediaNum++) {
364 if (Location == DeviceIndex) {
375 BlockSize = Private->Slot[SlotNum].Media[MediaNum].
BlockSize;
376 if (BufferSize % BlockSize != 0) {
377 return EFI_BAD_BUFFER_SIZE;
380 if (StartLBA > Private->Slot[SlotNum].Media[MediaNum].
LastBlock) {
381 return EFI_INVALID_PARAMETER;
384 NumberOfBlocks = BufferSize / BlockSize;
389 PartitionConfig = Private->Slot[SlotNum].ExtCsd.PartitionConfig;
390 if ((PartitionConfig & 0x7) != Private->Slot[SlotNum].PartitionType[MediaNum]) {
391 PartitionConfig &= (UINT8) ~0x7;
392 PartitionConfig |= Private->Slot[SlotNum].PartitionType[MediaNum];
394 &Private->Slot[SlotNum],
400 if (EFI_ERROR (Status)) {
404 Private->Slot[SlotNum].ExtCsd.PartitionConfig = PartitionConfig;
410 Remaining = NumberOfBlocks;
413 while (Remaining > 0) {
414 if (Remaining <= MaxBlock) {
415 NumberOfBlocks = Remaining;
417 NumberOfBlocks = MaxBlock;
421 if (EFI_ERROR (Status)) {
425 BufferSize = NumberOfBlocks * BlockSize;
427 if (EFI_ERROR (Status)) {
431 StartLBA += NumberOfBlocks;
432 Buffer = (UINT8 *)Buffer + BufferSize;
433 Remaining -= NumberOfBlocks;
468 Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2 (This);
469 *NumberBlockDevices = Private->TotalBlkIoDevices;
533 Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2 (This);
541 if (EFI_ERROR (Status)) {
547 for (SlotNum = 0; SlotNum < Private->SlotNum; SlotNum++) {
548 for (MediaNum = 0; MediaNum < Private->Slot[SlotNum].MediaNum; MediaNum++) {
550 if (Location == DeviceIndex) {
614 Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2 (This);
648 Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY (NotifyDescriptor);
650 if ((Private->Pool !=
NULL) && (Private->Pool->Head !=
NULL)) {
678 UINT32 PartitionIndex;
702 &gEdkiiPeiSdMmcHostControllerPpiGuid,
707 if (EFI_ERROR (Status)) {
708 return EFI_DEVICE_ERROR;
716 Status = SdMmcHcPpi->GetSdMmcHcMmioBar (SdMmcHcPpi, Controller, &MmioBase, &BarNum);
720 if (EFI_ERROR (Status)) {
730 if (Private ==
NULL) {
731 Status = EFI_OUT_OF_RESOURCES;
735 Private->BlkIoPpiList.
Ppi = (VOID *)&Private->BlkIoPpi;
736 Private->BlkIo2PpiList.
Ppi = (VOID *)&Private->BlkIo2Ppi;
741 if (EFI_ERROR (Status)) {
742 Status = EFI_OUT_OF_RESOURCES;
746 for (Index = 0; Index < BarNum; Index++) {
748 if (EFI_ERROR (Status)) {
752 if (Capability.SlotType != 0x1) {
753 DEBUG ((DEBUG_INFO,
"The slot at 0x%x is not embedded slot type\n", MmioBase[Index]));
754 Status = EFI_UNSUPPORTED;
759 if (EFI_ERROR (Status)) {
764 if (EFI_ERROR (Status)) {
769 if (EFI_ERROR (Status)) {
773 SlotNum = Private->SlotNum;
774 Slot = &Private->Slot[SlotNum];
776 Slot->Private = Private;
777 Slot->EmmcHcBase = MmioBase[Index];
778 CopyMem (&Slot->Capability, &Capability, sizeof (Capability));
781 if (EFI_ERROR (Status)) {
785 ExtCsd = &Slot->ExtCsd;
786 if (ExtCsd->ExtCsdRev < 5) {
787 DEBUG ((DEBUG_ERROR,
"The EMMC device version is too low, we don't support!!!\n"));
788 Status = EFI_UNSUPPORTED;
792 if ((ExtCsd->PartitioningSupport & BIT0) != BIT0) {
793 DEBUG ((DEBUG_ERROR,
"The EMMC device doesn't support Partition Feature!!!\n"));
794 Status = EFI_UNSUPPORTED;
798 for (PartitionIndex = 0; PartitionIndex < EMMC_PEIM_MAX_PARTITIONS; PartitionIndex++) {
799 switch (PartitionIndex) {
800 case EmmcPartitionUserData:
801 SecCount = *(UINT32 *)&ExtCsd->SecCount;
802 Capacity =
MultU64x32 ((UINT64)SecCount, 0x200);
804 case EmmcPartitionBoot1:
805 case EmmcPartitionBoot2:
806 Capacity = ExtCsd->BootSizeMult * SIZE_128KB;
808 case EmmcPartitionRPMB:
809 Capacity = ExtCsd->RpmbSizeMult * SIZE_128KB;
811 case EmmcPartitionGP1:
812 GpSizeMult = (ExtCsd->GpSizeMult[0] | (ExtCsd->GpSizeMult[1] << 8) | (ExtCsd->GpSizeMult[2] << 16));
815 case EmmcPartitionGP2:
816 GpSizeMult = (ExtCsd->GpSizeMult[3] | (ExtCsd->GpSizeMult[4] << 8) | (ExtCsd->GpSizeMult[5] << 16));
819 case EmmcPartitionGP3:
820 GpSizeMult = (ExtCsd->GpSizeMult[6] | (ExtCsd->GpSizeMult[7] << 8) | (ExtCsd->GpSizeMult[8] << 16));
823 case EmmcPartitionGP4:
824 GpSizeMult = (ExtCsd->GpSizeMult[9] | (ExtCsd->GpSizeMult[10] << 8) | (ExtCsd->GpSizeMult[11] << 16));
832 MediaNum = Slot->MediaNum;
835 Slot->PartitionType[MediaNum] = PartitionIndex;
836 Private->TotalBlkIoDevices++;
846 if (!EFI_ERROR (Status)) {
850 if (Private->Pool->Head !=
NULL) {
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI EmmcBlockIoPeimReadBlocks2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI EmmcBlockIoPeimGetDeviceNo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS EFIAPI EmmcBlockIoPeimGetMediaInfo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo)
EFI_STATUS EFIAPI EmmcBlockIoPeimGetDeviceNo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS EFIAPI InitializeEmmcBlockIoPeim(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI EmmcBlockIoPeimGetMediaInfo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo)
EFI_STATUS EFIAPI EmmcBlockIoPeimEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI EmmcBlockIoPeimReadBlocks(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EmmcPeimFreeMemPool(IN EMMC_PEIM_MEM_POOL *Pool)
EFI_STATUS EmmcPeimInitMemPool(IN EMMC_PEIM_HC_PRIVATE_DATA *Private)
EFI_STATUS EmmcPeimHcInitHost(IN UINTN Bar)
EFI_STATUS EmmcPeimSetBlkCount(IN EMMC_PEIM_HC_SLOT *Slot, IN UINT16 BlockCount)
EFI_STATUS EmmcPeimHcGetCapability(IN UINTN Bar, OUT EMMC_HC_SLOT_CAP *Capability)
EFI_STATUS EmmcPeimSwitch(IN EMMC_PEIM_HC_SLOT *Slot, IN UINT8 Access, IN UINT8 Index, IN UINT8 Value, IN UINT8 CmdSet)
EFI_STATUS EmmcPeimHcReset(IN UINTN Bar)
EFI_STATUS EmmcPeimHcCardDetect(IN UINTN Bar)
EFI_STATUS EmmcPeimRwMultiBlocks(IN EMMC_PEIM_HC_SLOT *Slot, IN EFI_LBA Lba, IN UINT32 BlockSize, IN VOID *Buffer, IN UINTN BufferSize, IN BOOLEAN IsRead)
EFI_STATUS EmmcPeimIdentification(IN EMMC_PEIM_HC_SLOT *Slot)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
EFI_STATUS EFIAPI PeiServicesRegisterForShadow(IN EFI_PEI_FILE_HANDLE FileHandle)
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
@ EMMC
The recovery device is a eMMC device.
VOID IoMmuInit(OUT EDKII_IOMMU_PPI **IoMmu)
VOID * EFI_PEI_FILE_HANDLE