46 EFI_PEI_RECOVERY_BLOCK_IO2_PPI_REVISION,
52 EFI_PEI_PPI_DESCRIPTOR_PPI,
53 &gEfiPeiVirtualBlockIoPpiGuid,
57 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
58 &gEfiPeiVirtualBlockIo2PpiGuid,
62 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
63 &gEfiEndOfPeiSignalPpiGuid,
119 Private = GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS (This);
120 *NumberBlockDevices = Private->TotalBlkIoDevices;
176 Private = GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS (This);
178 if ((DeviceIndex == 0) || (DeviceIndex > Private->TotalBlkIoDevices) || (DeviceIndex > SD_PEIM_MAX_SLOTS)) {
179 return EFI_INVALID_PARAMETER;
182 MediaInfo->DeviceType =
SD;
183 MediaInfo->MediaPresent =
TRUE;
184 MediaInfo->LastBlock = (
UINTN)Private->Slot[DeviceIndex - 1].Media.
LastBlock;
185 MediaInfo->BlockSize = Private->Slot[DeviceIndex - 1].Media.
BlockSize;
237 UINTN NumberOfBlocks;
243 Private = GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS (This);
248 if (Buffer ==
NULL) {
249 return EFI_INVALID_PARAMETER;
252 if (BufferSize == 0) {
256 if ((DeviceIndex == 0) || (DeviceIndex > Private->TotalBlkIoDevices) || (DeviceIndex > SD_PEIM_MAX_SLOTS)) {
257 return EFI_INVALID_PARAMETER;
260 BlockSize = Private->Slot[DeviceIndex - 1].Media.
BlockSize;
261 if (BufferSize % BlockSize != 0) {
262 return EFI_BAD_BUFFER_SIZE;
265 if (StartLBA > Private->Slot[DeviceIndex - 1].Media.
LastBlock) {
266 return EFI_INVALID_PARAMETER;
269 NumberOfBlocks = BufferSize / BlockSize;
274 Remaining = NumberOfBlocks;
277 while (Remaining > 0) {
278 if (Remaining <= MaxBlock) {
279 NumberOfBlocks = Remaining;
281 NumberOfBlocks = MaxBlock;
284 BufferSize = NumberOfBlocks * BlockSize;
285 if (NumberOfBlocks != 1) {
291 if (EFI_ERROR (Status)) {
295 StartLBA += NumberOfBlocks;
296 Buffer = (UINT8 *)Buffer + BufferSize;
297 Remaining -= NumberOfBlocks;
332 Private = GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS2 (This);
333 *NumberBlockDevices = Private->TotalBlkIoDevices;
392 Private = GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS2 (This);
400 if (EFI_ERROR (Status)) {
457 Private = GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS2 (This);
491 Private = GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY (NotifyDescriptor);
493 if ((Private->Pool !=
NULL) && (Private->Pool->Head !=
NULL)) {
545 &gEdkiiPeiSdMmcHostControllerPpiGuid,
550 if (EFI_ERROR (Status)) {
551 return EFI_DEVICE_ERROR;
559 Status = SdMmcHcPpi->GetSdMmcHcMmioBar (SdMmcHcPpi, Controller, &MmioBase, &BarNum);
563 if (EFI_ERROR (Status)) {
573 if (Private ==
NULL) {
574 Status = EFI_OUT_OF_RESOURCES;
578 Private->BlkIoPpiList.
Ppi = (VOID *)&Private->BlkIoPpi;
579 Private->BlkIo2PpiList.
Ppi = (VOID *)&Private->BlkIo2Ppi;
584 if (EFI_ERROR (Status)) {
585 Status = EFI_OUT_OF_RESOURCES;
589 for (Index = 0; Index < BarNum; Index++) {
591 if (EFI_ERROR (Status)) {
595 if (Capability.SlotType != 0x1) {
596 DEBUG ((DEBUG_INFO,
"The slot at 0x%x is not embedded slot type\n", MmioBase[Index]));
597 Status = EFI_UNSUPPORTED;
602 if (EFI_ERROR (Status)) {
607 if (EFI_ERROR (Status)) {
612 if (EFI_ERROR (Status)) {
616 SlotNum = Private->SlotNum;
617 Slot = &Private->Slot[SlotNum];
619 Slot->Private = Private;
620 Slot->SdHcBase = MmioBase[Index];
621 CopyMem (&Slot->Capability, &Capability, sizeof (Capability));
624 if (EFI_ERROR (Status)) {
629 if (Csd->CsdStructure == 0) {
630 Slot->SectorAddressing =
FALSE;
631 CSize = (Csd->CSizeHigh << 2 | Csd->CSizeLow) + 1;
632 CSizeMul = (1 << (Csd->CSizeMul + 2));
633 ReadBlLen = (1 << (Csd->ReadBlLen));
636 Slot->SectorAddressing =
TRUE;
638 CSize = (Csd2->CSizeHigh << 16 | Csd2->CSizeLow) + 1;
639 Capacity =
MultU64x32 ((UINT64)CSize, SIZE_512KB);
644 Private->TotalBlkIoDevices++;
649 if (!EFI_ERROR (Status)) {
653 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)
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 DEBUG(Expression)
@ SD
The recovery device is a Secure Digital device.
VOID IoMmuInit(OUT EDKII_IOMMU_PPI **IoMmu)
VOID * EFI_PEI_FILE_HANDLE
EFI_STATUS EFIAPI SdBlockIoPeimGetDeviceNo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS EFIAPI SdBlockIoPeimGetMediaInfo2(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 InitializeSdBlockIoPeim(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI SdBlockIoPeimReadBlocks2(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 SdBlockIoPeimGetMediaInfo(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 SdBlockIoPeimEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI SdBlockIoPeimGetDeviceNo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS EFIAPI SdBlockIoPeimReadBlocks(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 SdPeimFreeMemPool(IN SD_PEIM_MEM_POOL *Pool)
EFI_STATUS SdPeimInitMemPool(IN SD_PEIM_HC_PRIVATE_DATA *Private)
EFI_STATUS SdPeimHcCardDetect(IN UINTN Bar)
EFI_STATUS SdPeimHcInitHost(IN UINTN Bar)
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 SdPeimHcReset(IN UINTN Bar)
EFI_STATUS SdPeimIdentification(IN SD_PEIM_HC_SLOT *Slot)
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 SdPeimHcGetCapability(IN UINTN Bar, OUT SD_HC_SLOT_CAP *Capability)