2 The SdDxe driver is used to manage the SD memory card device.
4 It produces BlockIo and BlockIo2 protocols to allow upper layer
5 access the SD memory card device.
7 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
15 // SdDxe Driver Binding Protocol Instance
17 EFI_DRIVER_BINDING_PROTOCOL gSdDxeDriverBinding
= {
18 SdDxeDriverBindingSupported
,
19 SdDxeDriverBindingStart
,
20 SdDxeDriverBindingStop
,
27 // Template for SD_DEVICE data structure.
29 SD_DEVICE mSdDeviceTemplate
= {
30 SD_DEVICE_SIGNATURE
, // Signature
34 FALSE
, // SectorAddressing
36 EFI_BLOCK_IO_PROTOCOL_REVISION
,
52 FALSE
, // RemovableMedia
54 FALSE
, // LogicPartition
56 FALSE
, // WritingCache
62 EFI_ERASE_BLOCK_PROTOCOL_REVISION
,
67 EFI_DISK_INFO_SD_MMC_INTERFACE_GUID
,
83 NULL
, // ControllerNameTable
91 Decode and print SD CSD Register content.
93 @param[in] Csd Pointer to SD_CSD data structure.
95 @retval EFI_SUCCESS The function completed successfully
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
));
122 Csd2
= (SD_CSD2
*)(VOID
*)Csd
;
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
));
143 Get SD device model name.
145 @param[in, out] Device The pointer to the SD_DEVICE data structure.
146 @param[in] Cid Pointer to SD_CID data structure.
148 @retval EFI_SUCCESS The function completed successfully
153 IN OUT SD_DEVICE
*Device
,
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]));
172 Discover user area partition in the SD device.
174 @param[in] Device The pointer to the SD_DEVICE data structure.
176 @retval EFI_SUCCESS The user area partition in the SD device is successfully identified.
177 @return Others Some error occurs when identifying the user area.
197 // Deselect the device to force it enter stby mode.
198 // Note here we don't judge return status as some SD devices return
199 // error but the state has been stby.
201 SdSelect (Device
, 0);
203 Status
= SdSetRca (Device
, &Rca
);
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
)) {
223 GetSdModelName (Device
, Cid
);
225 Status
= SdSelect (Device
, Rca
);
226 if (EFI_ERROR (Status
)) {
227 DEBUG ((DEBUG_ERROR
, "DiscoverUserArea(): Reselect the device 0x%x fails with %r\n", Rca
, Status
));
231 Status
= SdSendStatus (Device
, Rca
, &DevStatus
);
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
));
241 Capacity
= MultU64x32 (MultU64x32 ((UINT64
)CSize
, CSizeMul
), ReadBlLen
);
243 Device
->SectorAddressing
= TRUE
;
244 Csd2
= (SD_CSD2
*)(VOID
*)Csd
;
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));
269 Scan SD Bus to discover the device.
271 @param[in] Private The SD driver private data structure.
272 @param[in] Slot The slot number to check device present.
274 @retval EFI_SUCCESS Successfully to discover the device and attach
275 SdMmcIoProtocol to it.
276 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
278 @retval EFI_ALREADY_STARTED The device was discovered before.
279 @retval Others Fail to discover the device.
285 IN SD_DRIVER_PRIVATE_DATA
*Private
,
291 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
292 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
293 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
294 EFI_HANDLE DeviceHandle
;
295 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
299 NewDevicePath
= NULL
;
300 RemainingDevicePath
= NULL
;
301 PassThru
= Private
->PassThru
;
306 Status
= PassThru
->BuildDevicePath (
311 if (EFI_ERROR (Status
)) {
315 if (DevicePath
->SubType
!= MSG_SD_DP
) {
316 Status
= EFI_UNSUPPORTED
;
320 NewDevicePath
= AppendDevicePathNode (
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
)) {
335 // The device has been started, directly return to fast boot.
337 Status
= EFI_ALREADY_STARTED
;
342 // Allocate buffer to store SD_DEVICE private data.
344 Device
= AllocateCopyPool (sizeof (SD_DEVICE
), &mSdDeviceTemplate
);
345 if (Device
== NULL
) {
346 Status
= EFI_OUT_OF_RESOURCES
;
350 Device
->DevicePath
= NewDevicePath
;
352 Device
->Private
= Private
;
353 InitializeListHead (&Device
->Queue
);
356 // Expose user area in the Sd memory card to upper layer.
358 Status
= DiscoverUserArea (Device
);
359 if (EFI_ERROR (Status
)) {
363 Device
->ControllerNameTable
= NULL
;
366 gSdDxeComponentName
.SupportedLanguages
,
367 &Device
->ControllerNameTable
,
373 gSdDxeComponentName2
.SupportedLanguages
,
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
406 FreePool (DevicePath
);
408 if (EFI_ERROR (Status
) && (NewDevicePath
!= NULL
)) {
409 FreePool (NewDevicePath
);
412 if (EFI_ERROR (Status
) && (Device
!= NULL
)) {
420 Tests to see if this driver supports a given controller. If a child device is provided,
421 it further tests to see if this driver supports creating a handle for the specified child device.
423 This function checks to see if the driver specified by This supports the device specified by
424 ControllerHandle. Drivers will typically use the device path attached to
425 ControllerHandle and/or the services from the bus I/O abstraction attached to
426 ControllerHandle to determine if the driver supports ControllerHandle. This function
427 may be called many times during platform initialization. In order to reduce boot times, the tests
428 performed by this function must be very small, and take as little time as possible to execute. This
429 function must not change the state of any hardware devices, and this function must be aware that the
430 device specified by ControllerHandle may already be managed by the same driver or a
431 different driver. This function must match its calls to AllocatePages() with FreePages(),
432 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
433 Since ControllerHandle may have been previously started by the same driver, if a protocol is
434 already in the opened state, then it must not be closed with CloseProtocol(). This is required
435 to guarantee the state of ControllerHandle is not modified by this function.
437 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
438 @param[in] ControllerHandle The handle of the controller to test. This handle
439 must support a protocol interface that supplies
440 an I/O abstraction to the driver.
441 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
442 parameter is ignored by device drivers, and is optional for bus
443 drivers. For bus drivers, if this parameter is not NULL, then
444 the bus driver must determine if the bus controller specified
445 by ControllerHandle and the child controller specified
446 by RemainingDevicePath are both supported by this
449 @retval EFI_SUCCESS The device specified by ControllerHandle and
450 RemainingDevicePath is supported by the driver specified by This.
451 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
452 RemainingDevicePath is already being managed by the driver
454 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
455 RemainingDevicePath is already being managed by a different
456 driver or an application that requires exclusive access.
457 Currently not implemented.
458 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
459 RemainingDevicePath is not supported by the driver specified by This.
463 SdDxeDriverBindingSupported (
464 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
465 IN EFI_HANDLE Controller
,
466 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
470 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
471 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
475 // Test EFI_SD_MMC_PASS_THRU_PROTOCOL on the controller handle.
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
)) {
495 // Test RemainingDevicePath is valid or not.
497 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
498 Status
= PassThru
->GetSlotNumber (PassThru
, RemainingDevicePath
, &Slot
);
499 if (EFI_ERROR (Status
)) {
501 // Close the I/O Abstraction(s) used to perform the supported test
505 &gEfiSdMmcPassThruProtocolGuid
,
506 This
->DriverBindingHandle
,
514 // Close the I/O Abstraction(s) used to perform the supported test
518 &gEfiSdMmcPassThruProtocolGuid
,
519 This
->DriverBindingHandle
,
524 // Open the EFI Device Path protocol needed to perform the supported test
526 Status
= gBS
->OpenProtocol (
528 &gEfiDevicePathProtocolGuid
,
529 (VOID
**)&ParentDevicePath
,
530 This
->DriverBindingHandle
,
532 EFI_OPEN_PROTOCOL_GET_PROTOCOL
538 Starts a device controller or a bus controller.
540 The Start() function is designed to be invoked from the EFI boot service ConnectController().
541 As a result, much of the error checking on the parameters to Start() has been moved into this
542 common boot service. It is legal to call Start() from other locations,
543 but the following calling restrictions must be followed or the system behavior will not be deterministic.
544 1. ControllerHandle must be a valid EFI_HANDLE.
545 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
546 EFI_DEVICE_PATH_PROTOCOL.
547 3. Prior to calling Start(), the Supported() function for the driver specified by This must
548 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
550 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
551 @param[in] ControllerHandle The handle of the controller to start. This handle
552 must support a protocol interface that supplies
553 an I/O abstraction to the driver.
554 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
555 parameter is ignored by device drivers, and is optional for bus
556 drivers. For a bus driver, if this parameter is NULL, then handles
557 for all the children of Controller are created by this driver.
558 If this parameter is not NULL and the first Device Path Node is
559 not the End of Device Path Node, then only the handle for the
560 child device specified by the first Device Path Node of
561 RemainingDevicePath is created by this driver.
562 If the first Device Path Node of RemainingDevicePath is
563 the End of Device Path Node, no child handle is created by this
566 @retval EFI_SUCCESS The device was started.
567 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
568 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
569 @retval Others The driver failed to start the device.
574 SdDxeDriverBindingStart (
575 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
576 IN EFI_HANDLE Controller
,
577 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
581 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
582 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
583 SD_DRIVER_PRIVATE_DATA
*Private
;
588 Status
= gBS
->OpenProtocol (
590 &gEfiSdMmcPassThruProtocolGuid
,
592 This
->DriverBindingHandle
,
594 EFI_OPEN_PROTOCOL_BY_DRIVER
596 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
601 // Check EFI_ALREADY_STARTED to reuse the original SD_DRIVER_PRIVATE_DATA.
603 if (Status
!= EFI_ALREADY_STARTED
) {
604 Private
= AllocateZeroPool (sizeof (SD_DRIVER_PRIVATE_DATA
));
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
618 ASSERT_EFI_ERROR (Status
);
619 Private
->PassThru
= PassThru
;
620 Private
->Controller
= Controller
;
621 Private
->ParentDevicePath
= ParentDevicePath
;
622 Private
->DriverBindingHandle
= This
->DriverBindingHandle
;
624 Status
= gBS
->InstallProtocolInterface (
627 EFI_NATIVE_INTERFACE
,
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
)) {
653 // Cannot find more legal slots.
655 Status
= EFI_SUCCESS
;
659 Status
= DiscoverSdDevice (Private
, Slot
);
660 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
664 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
665 Status
= PassThru
->GetSlotNumber (PassThru
, RemainingDevicePath
, &Slot
);
666 if (!EFI_ERROR (Status
)) {
667 Status
= DiscoverSdDevice (Private
, Slot
);
672 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
675 &gEfiSdMmcPassThruProtocolGuid
,
676 This
->DriverBindingHandle
,
680 if (Private
!= NULL
) {
681 gBS
->UninstallMultipleProtocolInterfaces (
695 Stops a device controller or a bus controller.
697 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
698 As a result, much of the error checking on the parameters to Stop() has been moved
699 into this common boot service. It is legal to call Stop() from other locations,
700 but the following calling restrictions must be followed or the system behavior will not be deterministic.
701 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
702 same driver's Start() function.
703 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
704 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
705 Start() function, and the Start() function must have called OpenProtocol() on
706 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
708 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
709 @param[in] ControllerHandle A handle to the device being stopped. The handle must
710 support a bus specific I/O protocol for the driver
711 to use to stop the device.
712 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
713 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
714 if NumberOfChildren is 0.
716 @retval EFI_SUCCESS The device was stopped.
717 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
722 SdDxeDriverBindingStop (
723 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
724 IN EFI_HANDLE Controller
,
725 IN UINTN NumberOfChildren
,
726 IN EFI_HANDLE
*ChildHandleBuffer
730 BOOLEAN AllChildrenStopped
;
732 SD_DRIVER_PRIVATE_DATA
*Private
;
734 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
735 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
736 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
738 LIST_ENTRY
*NextLink
;
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
);
808 // Free all on-going async tasks.
810 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
811 for (Link
= GetFirstNode (&Device
->Queue
);
812 !IsNull (&Device
->Queue
, Link
);
815 NextLink
= GetNextNode (&Device
->Queue
, Link
);
816 RemoveEntryList (Link
);
818 Request
= SD_REQUEST_FROM_LINK (Link
);
820 gBS
->CloseEvent (Request
->Event
);
821 Request
->Token
->TransactionStatus
= EFI_ABORTED
;
823 if (Request
->IsEnd
) {
824 gBS
->SignalEvent (Request
->Token
->Event
);
830 gBS
->RestoreTPL (OldTpl
);
833 // Close the child handle
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
867 FreePool (Device
->DevicePath
);
868 FreeUnicodeStringTable (Device
->ControllerNameTable
);
873 if (!AllChildrenStopped
) {
874 return EFI_DEVICE_ERROR
;
881 The user Entry Point for module SdDxe. The user code starts with this function.
883 @param[in] ImageHandle The firmware allocated handle for the EFI image.
884 @param[in] SystemTable A pointer to the EFI System Table.
886 @retval EFI_SUCCESS The entry point is executed successfully.
887 @retval other Some errors occur when executing this entry point.
893 IN EFI_HANDLE ImageHandle
,
894 IN EFI_SYSTEM_TABLE
*SystemTable
900 // Install driver model protocol(s).
902 Status
= EfiLibInstallDriverBindingComponentName2 (
905 &gSdDxeDriverBinding
,
907 &gSdDxeComponentName
,
908 &gSdDxeComponentName2
910 ASSERT_EFI_ERROR (Status
);