36 EFI_BLOCK_IO_PROTOCOL_REVISION,
62 EFI_ERASE_BLOCK_PROTOCOL_REVISION,
104 DEBUG ((DEBUG_INFO,
"== Dump Sd Csd Register==\n"));
105 DEBUG ((DEBUG_INFO,
" CSD structure 0x%x\n", Csd->CsdStructure));
106 DEBUG ((DEBUG_INFO,
" Data read access-time 1 0x%x\n", Csd->Taac));
107 DEBUG ((DEBUG_INFO,
" Data read access-time 2 0x%x\n", Csd->Nsac));
108 DEBUG ((DEBUG_INFO,
" Max. bus clock frequency 0x%x\n", Csd->TranSpeed));
109 DEBUG ((DEBUG_INFO,
" Device command classes 0x%x\n", Csd->Ccc));
110 DEBUG ((DEBUG_INFO,
" Max. read data block length 0x%x\n", Csd->ReadBlLen));
111 DEBUG ((DEBUG_INFO,
" Partial blocks for read allowed 0x%x\n", Csd->ReadBlPartial));
112 DEBUG ((DEBUG_INFO,
" Write block misalignment 0x%x\n", Csd->WriteBlkMisalign));
113 DEBUG ((DEBUG_INFO,
" Read block misalignment 0x%x\n", Csd->ReadBlkMisalign));
114 DEBUG ((DEBUG_INFO,
" DSR implemented 0x%x\n", Csd->DsrImp));
115 if (Csd->CsdStructure == 0) {
116 DEBUG ((DEBUG_INFO,
" Device size 0x%x\n", Csd->CSizeLow | (Csd->CSizeHigh << 2)));
117 DEBUG ((DEBUG_INFO,
" Max. read current @ VDD min 0x%x\n", Csd->VddRCurrMin));
118 DEBUG ((DEBUG_INFO,
" Max. read current @ VDD max 0x%x\n", Csd->VddRCurrMax));
119 DEBUG ((DEBUG_INFO,
" Max. write current @ VDD min 0x%x\n", Csd->VddWCurrMin));
120 DEBUG ((DEBUG_INFO,
" Max. write current @ VDD max 0x%x\n", Csd->VddWCurrMax));
123 DEBUG ((DEBUG_INFO,
" Device size 0x%x\n", Csd2->CSizeLow | (Csd->CSizeHigh << 16)));
126 DEBUG ((DEBUG_INFO,
" Erase sector size 0x%x\n", Csd->SectorSize));
127 DEBUG ((DEBUG_INFO,
" Erase single block enable 0x%x\n", Csd->EraseBlkEn));
128 DEBUG ((DEBUG_INFO,
" Write protect group size 0x%x\n", Csd->WpGrpSize));
129 DEBUG ((DEBUG_INFO,
" Write protect group enable 0x%x\n", Csd->WpGrpEnable));
130 DEBUG ((DEBUG_INFO,
" Write speed factor 0x%x\n", Csd->R2WFactor));
131 DEBUG ((DEBUG_INFO,
" Max. write data block length 0x%x\n", Csd->WriteBlLen));
132 DEBUG ((DEBUG_INFO,
" Partial blocks for write allowed 0x%x\n", Csd->WriteBlPartial));
133 DEBUG ((DEBUG_INFO,
" File format group 0x%x\n", Csd->FileFormatGrp));
134 DEBUG ((DEBUG_INFO,
" Copy flag (OTP) 0x%x\n", Csd->Copy));
135 DEBUG ((DEBUG_INFO,
" Permanent write protection 0x%x\n", Csd->PermWriteProtect));
136 DEBUG ((DEBUG_INFO,
" Temporary write protection 0x%x\n", Csd->TmpWriteProtect));
137 DEBUG ((DEBUG_INFO,
" File format 0x%x\n", Csd->FileFormat));
157 CHAR8 String[SD_MODEL_NAME_MAX_LEN];
159 ZeroMem (String,
sizeof (String));
160 CopyMem (String, Cid->OemId, sizeof (Cid->OemId));
161 String[
sizeof (Cid->OemId)] =
' ';
162 CopyMem (String +
sizeof (Cid->OemId) + 1, Cid->ProductName, sizeof (Cid->ProductName));
163 String[
sizeof (Cid->OemId) +
sizeof (Cid->ProductName)] =
' ';
164 CopyMem (String +
sizeof (Cid->OemId) + sizeof (Cid->ProductName) + 1, Cid->ProductSerialNumber, sizeof (Cid->ProductSerialNumber));
166 AsciiStrToUnicodeStrS (String, Device->ModelName, sizeof (Device->ModelName) / sizeof (Device->ModelName[0]));
204 if (EFI_ERROR (Status)) {
205 DEBUG ((DEBUG_ERROR,
"DiscoverUserArea(): Assign new Rca = 0x%x fails with %r\n", Rca, Status));
210 Status =
SdGetCsd (Device, Rca, Csd);
211 if (EFI_ERROR (Status)) {
218 Status =
SdGetCid (Device, Rca, Cid);
219 if (EFI_ERROR (Status)) {
226 if (EFI_ERROR (Status)) {
227 DEBUG ((DEBUG_ERROR,
"DiscoverUserArea(): Reselect the device 0x%x fails with %r\n", Rca, Status));
232 if (EFI_ERROR (Status)) {
236 if (Csd->CsdStructure == 0) {
237 Device->SectorAddressing =
FALSE;
238 CSize = (Csd->CSizeHigh << 2 | Csd->CSizeLow) + 1;
239 CSizeMul = (1 << (Csd->CSizeMul + 2));
240 ReadBlLen = (1 << (Csd->ReadBlLen));
243 Device->SectorAddressing =
TRUE;
245 CSize = (Csd2->CSizeHigh << 16 | Csd2->CSizeLow) + 1;
246 Capacity =
MultU64x32 ((UINT64)CSize, SIZE_512KB);
249 Device->BlockIo.Media = &Device->BlockMedia;
250 Device->BlockIo2.Media = &Device->BlockMedia;
251 Device->BlockMedia.IoAlign = Device->Private->PassThru->IoAlign;
252 Device->BlockMedia.BlockSize = 0x200;
253 Device->BlockMedia.LastBlock = 0x00;
254 Device->BlockMedia.RemovableMedia =
TRUE;
255 Device->BlockMedia.MediaPresent =
TRUE;
256 Device->BlockMedia.LogicalPartition =
FALSE;
257 Device->BlockMedia.LastBlock =
DivU64x32 (Capacity, Device->BlockMedia.BlockSize) - 1;
259 if (Csd->EraseBlkEn) {
260 Device->EraseBlock.EraseLengthGranularity = 1;
262 Device->EraseBlock.EraseLengthGranularity = (Csd->SectorSize + 1) * (1 << (Csd->WriteBlLen - 9));
299 NewDevicePath =
NULL;
300 RemainingDevicePath =
NULL;
301 PassThru = Private->PassThru;
306 Status = PassThru->BuildDevicePath (
311 if (EFI_ERROR (Status)) {
316 Status = EFI_UNSUPPORTED;
321 Private->ParentDevicePath,
325 if (NewDevicePath ==
NULL) {
326 Status = EFI_OUT_OF_RESOURCES;
331 RemainingDevicePath = NewDevicePath;
332 Status =
gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &DeviceHandle);
333 if (!EFI_ERROR (Status) && (DeviceHandle !=
NULL) &&
IsDevicePathEnd (RemainingDevicePath)) {
337 Status = EFI_ALREADY_STARTED;
345 if (Device ==
NULL) {
346 Status = EFI_OUT_OF_RESOURCES;
350 Device->DevicePath = NewDevicePath;
352 Device->Private = Private;
359 if (EFI_ERROR (Status)) {
363 Device->ControllerNameTable =
NULL;
367 &Device->ControllerNameTable,
374 &Device->ControllerNameTable,
379 Status =
gBS->InstallMultipleProtocolInterfaces (
381 &gEfiDevicePathProtocolGuid,
383 &gEfiBlockIoProtocolGuid,
385 &gEfiBlockIo2ProtocolGuid,
387 &gEfiEraseBlockProtocolGuid,
389 &gEfiDiskInfoProtocolGuid,
394 if (!EFI_ERROR (Status)) {
397 &gEfiSdMmcPassThruProtocolGuid,
398 (VOID **)&(Private->PassThru),
399 Private->DriverBindingHandle,
401 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
408 if (EFI_ERROR (Status) && (NewDevicePath !=
NULL)) {
412 if (EFI_ERROR (Status) && (Device !=
NULL)) {
477 Status =
gBS->OpenProtocol (
479 &gEfiSdMmcPassThruProtocolGuid,
481 This->DriverBindingHandle,
483 EFI_OPEN_PROTOCOL_BY_DRIVER
486 if (Status == EFI_ALREADY_STARTED) {
490 if (EFI_ERROR (Status)) {
498 Status = PassThru->GetSlotNumber (PassThru, RemainingDevicePath, &Slot);
499 if (EFI_ERROR (Status)) {
505 &gEfiSdMmcPassThruProtocolGuid,
506 This->DriverBindingHandle,
518 &gEfiSdMmcPassThruProtocolGuid,
519 This->DriverBindingHandle,
526 Status =
gBS->OpenProtocol (
528 &gEfiDevicePathProtocolGuid,
529 (VOID **)&ParentDevicePath,
530 This->DriverBindingHandle,
532 EFI_OPEN_PROTOCOL_GET_PROTOCOL
588 Status =
gBS->OpenProtocol (
590 &gEfiSdMmcPassThruProtocolGuid,
592 This->DriverBindingHandle,
594 EFI_OPEN_PROTOCOL_BY_DRIVER
596 if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {
603 if (Status != EFI_ALREADY_STARTED) {
605 if (Private ==
NULL) {
606 Status = EFI_OUT_OF_RESOURCES;
610 Status =
gBS->OpenProtocol (
612 &gEfiDevicePathProtocolGuid,
613 (VOID **)&ParentDevicePath,
614 This->DriverBindingHandle,
616 EFI_OPEN_PROTOCOL_GET_PROTOCOL
619 Private->PassThru = PassThru;
620 Private->Controller = Controller;
621 Private->ParentDevicePath = ParentDevicePath;
622 Private->DriverBindingHandle = This->DriverBindingHandle;
624 Status =
gBS->InstallProtocolInterface (
630 if (EFI_ERROR (Status)) {
634 Status =
gBS->OpenProtocol (
638 This->DriverBindingHandle,
640 EFI_OPEN_PROTOCOL_GET_PROTOCOL
642 if (EFI_ERROR (Status)) {
647 if (RemainingDevicePath ==
NULL) {
650 Status = PassThru->GetNextSlot (PassThru, &Slot);
651 if (EFI_ERROR (Status)) {
660 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
665 Status = PassThru->GetSlotNumber (PassThru, RemainingDevicePath, &Slot);
666 if (!EFI_ERROR (Status)) {
672 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
675 &gEfiSdMmcPassThruProtocolGuid,
676 This->DriverBindingHandle,
680 if (Private !=
NULL) {
681 gBS->UninstallMultipleProtocolInterfaces (
730 BOOLEAN AllChildrenStopped;
742 if (NumberOfChildren == 0) {
743 Status =
gBS->OpenProtocol (
747 This->DriverBindingHandle,
749 EFI_OPEN_PROTOCOL_GET_PROTOCOL
751 if (EFI_ERROR (Status)) {
752 return EFI_DEVICE_ERROR;
755 gBS->UninstallProtocolInterface (
762 &gEfiSdMmcPassThruProtocolGuid,
763 This->DriverBindingHandle,
772 AllChildrenStopped =
TRUE;
774 for (Index = 0; Index < NumberOfChildren; Index++) {
777 Status =
gBS->OpenProtocol (
778 ChildHandleBuffer[Index],
779 &gEfiBlockIoProtocolGuid,
781 This->DriverBindingHandle,
783 EFI_OPEN_PROTOCOL_GET_PROTOCOL
785 if (EFI_ERROR (Status)) {
786 Status =
gBS->OpenProtocol (
787 ChildHandleBuffer[Index],
788 &gEfiBlockIo2ProtocolGuid,
790 This->DriverBindingHandle,
792 EFI_OPEN_PROTOCOL_GET_PROTOCOL
794 if (EFI_ERROR (Status)) {
795 AllChildrenStopped =
FALSE;
800 if (BlockIo !=
NULL) {
801 Device = SD_DEVICE_DATA_FROM_BLKIO (BlockIo);
803 ASSERT (BlockIo2 !=
NULL);
804 Device = SD_DEVICE_DATA_FROM_BLKIO2 (BlockIo2);
810 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
812 !
IsNull (&Device->Queue, Link);
818 Request = SD_REQUEST_FROM_LINK (Link);
820 gBS->CloseEvent (Request->Event);
823 if (Request->IsEnd) {
824 gBS->SignalEvent (Request->Token->
Event);
830 gBS->RestoreTPL (OldTpl);
835 Status =
gBS->CloseProtocol (
837 &gEfiSdMmcPassThruProtocolGuid,
838 This->DriverBindingHandle,
839 ChildHandleBuffer[Index]
842 Status =
gBS->UninstallMultipleProtocolInterfaces (
843 ChildHandleBuffer[Index],
844 &gEfiDevicePathProtocolGuid,
846 &gEfiBlockIoProtocolGuid,
848 &gEfiBlockIo2ProtocolGuid,
850 &gEfiEraseBlockProtocolGuid,
852 &gEfiDiskInfoProtocolGuid,
856 if (EFI_ERROR (Status)) {
857 AllChildrenStopped =
FALSE;
860 &gEfiSdMmcPassThruProtocolGuid,
862 This->DriverBindingHandle,
863 ChildHandleBuffer[Index],
864 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
873 if (!AllChildrenStopped) {
874 return EFI_DEVICE_ERROR;
905 &gSdDxeDriverBinding,
907 &gSdDxeComponentName,
908 &gSdDxeComponentName2
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
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)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
RETURN_STATUS EFIAPI AsciiStrToUnicodeStrS(IN CONST CHAR8 *Source, OUT CHAR16 *Destination, IN UINTN DestMax)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
#define EFI_DISK_INFO_SD_MMC_INTERFACE_GUID
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
EFI_STATUS EFIAPI SdFlushBlocks(IN EFI_BLOCK_IO_PROTOCOL *This)
EFI_STATUS SdSelect(IN SD_DEVICE *Device, IN UINT16 Rca)
EFI_STATUS EFIAPI SdReset(IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
EFI_STATUS EFIAPI SdReadBlocksEx(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 SdGetCsd(IN SD_DEVICE *Device, IN UINT16 Rca, OUT SD_CSD *Csd)
EFI_STATUS SdSendStatus(IN SD_DEVICE *Device, IN UINT16 Rca, OUT UINT32 *DevStatus)
EFI_STATUS EFIAPI SdWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS SdSetRca(IN SD_DEVICE *Device, OUT UINT16 *Rca)
EFI_STATUS EFIAPI SdEraseBlocks(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 SdGetCid(IN SD_DEVICE *Device, IN UINT16 Rca, OUT SD_CID *Cid)
EFI_STATUS EFIAPI SdFlushBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
EFI_STATUS EFIAPI SdWriteBlocksEx(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 EFIAPI SdResetEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
EFI_STATUS EFIAPI SdReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI SdDiskInfoInquiry(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *InquiryData, IN OUT UINT32 *InquiryDataSize)
EFI_STATUS EFIAPI SdDiskInfoSenseData(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *SenseData, IN OUT UINT32 *SenseDataSize, OUT UINT8 *SenseDataNumber)
EFI_STATUS EFIAPI SdDiskInfoWhichIde(IN EFI_DISK_INFO_PROTOCOL *This, OUT UINT32 *IdeChannel, OUT UINT32 *IdeDevice)
EFI_STATUS EFIAPI SdDiskInfoIdentify(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *IdentifyData, IN OUT UINT32 *IdentifyDataSize)
EFI_STATUS EFIAPI InitializeSdDxe(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI SdDxeDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
EFI_STATUS EFIAPI SdDxeDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS EFIAPI SdDxeDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS DiscoverUserArea(IN SD_DEVICE *Device)
EFI_STATUS DumpCsd(IN SD_CSD *Csd)
EFI_STATUS EFIAPI DiscoverSdDevice(IN SD_DRIVER_PRIVATE_DATA *Private, IN UINT8 Slot)
EFI_STATUS GetSdModelName(IN OUT SD_DEVICE *Device, IN SD_CID *Cid)
EFI_STATUS EFIAPI AddUnicodeString2(IN CONST CHAR8 *Language, IN CONST CHAR8 *SupportedLanguages, IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable, IN CONST CHAR16 *UnicodeString, IN BOOLEAN Iso639Language)
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_STATUS EFIAPI FreeUnicodeStringTable(IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable)
CHAR8 * SupportedLanguages
CHAR8 * SupportedLanguages
EFI_STATUS TransactionStatus