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)));
125 DEBUG((DEBUG_INFO
, " Erase sector size 0x%x\n", Csd
->SectorSize
));
126 DEBUG((DEBUG_INFO
, " Erase single block enable 0x%x\n", Csd
->EraseBlkEn
));
127 DEBUG((DEBUG_INFO
, " Write protect group size 0x%x\n", Csd
->WpGrpSize
));
128 DEBUG((DEBUG_INFO
, " Write protect group enable 0x%x\n", Csd
->WpGrpEnable
));
129 DEBUG((DEBUG_INFO
, " Write speed factor 0x%x\n", Csd
->R2WFactor
));
130 DEBUG((DEBUG_INFO
, " Max. write data block length 0x%x\n", Csd
->WriteBlLen
));
131 DEBUG((DEBUG_INFO
, " Partial blocks for write allowed 0x%x\n", Csd
->WriteBlPartial
));
132 DEBUG((DEBUG_INFO
, " File format group 0x%x\n", Csd
->FileFormatGrp
));
133 DEBUG((DEBUG_INFO
, " Copy flag (OTP) 0x%x\n", Csd
->Copy
));
134 DEBUG((DEBUG_INFO
, " Permanent write protection 0x%x\n", Csd
->PermWriteProtect
));
135 DEBUG((DEBUG_INFO
, " Temporary write protection 0x%x\n", Csd
->TmpWriteProtect
));
136 DEBUG((DEBUG_INFO
, " File format 0x%x\n", Csd
->FileFormat
));
142 Get SD device model name.
144 @param[in, out] Device The pointer to the SD_DEVICE data structure.
145 @param[in] Cid Pointer to SD_CID data structure.
147 @retval EFI_SUCCESS The function completed successfully
152 IN OUT SD_DEVICE
*Device
,
156 CHAR8 String
[SD_MODEL_NAME_MAX_LEN
];
158 ZeroMem (String
, sizeof (String
));
159 CopyMem (String
, Cid
->OemId
, sizeof (Cid
->OemId
));
160 String
[sizeof (Cid
->OemId
)] = ' ';
161 CopyMem (String
+ sizeof (Cid
->OemId
) + 1, Cid
->ProductName
, sizeof (Cid
->ProductName
));
162 String
[sizeof (Cid
->OemId
) + sizeof (Cid
->ProductName
)] = ' ';
163 CopyMem (String
+ sizeof (Cid
->OemId
) + sizeof (Cid
->ProductName
) + 1, Cid
->ProductSerialNumber
, sizeof (Cid
->ProductSerialNumber
));
165 AsciiStrToUnicodeStrS (String
, Device
->ModelName
, sizeof (Device
->ModelName
) / sizeof (Device
->ModelName
[0]));
171 Discover user area partition in the SD device.
173 @param[in] Device The pointer to the SD_DEVICE data structure.
175 @retval EFI_SUCCESS The user area partition in the SD device is successfully identified.
176 @return Others Some error occurs when identifying the user area.
196 // Deselect the device to force it enter stby mode.
197 // Note here we don't judge return status as some SD devices return
198 // error but the state has been stby.
200 SdSelect (Device
, 0);
202 Status
= SdSetRca (Device
, &Rca
);
203 if (EFI_ERROR (Status
)) {
204 DEBUG ((EFI_D_ERROR
, "DiscoverUserArea(): Assign new Rca = 0x%x fails with %r\n", Rca
, Status
));
209 Status
= SdGetCsd (Device
, Rca
, Csd
);
210 if (EFI_ERROR (Status
)) {
216 Status
= SdGetCid (Device
, Rca
, Cid
);
217 if (EFI_ERROR (Status
)) {
220 GetSdModelName (Device
, Cid
);
222 Status
= SdSelect (Device
, Rca
);
223 if (EFI_ERROR (Status
)) {
224 DEBUG ((EFI_D_ERROR
, "DiscoverUserArea(): Reselect the device 0x%x fails with %r\n", Rca
, Status
));
228 Status
= SdSendStatus (Device
, Rca
, &DevStatus
);
229 if (EFI_ERROR (Status
)) {
233 if (Csd
->CsdStructure
== 0) {
234 Device
->SectorAddressing
= FALSE
;
235 CSize
= (Csd
->CSizeHigh
<< 2 | Csd
->CSizeLow
) + 1;
236 CSizeMul
= (1 << (Csd
->CSizeMul
+ 2));
237 ReadBlLen
= (1 << (Csd
->ReadBlLen
));
238 Capacity
= MultU64x32 (MultU64x32 ((UINT64
)CSize
, CSizeMul
), ReadBlLen
);
240 Device
->SectorAddressing
= TRUE
;
241 Csd2
= (SD_CSD2
*)(VOID
*)Csd
;
242 CSize
= (Csd2
->CSizeHigh
<< 16 | Csd2
->CSizeLow
) + 1;
243 Capacity
= MultU64x32 ((UINT64
)CSize
, SIZE_512KB
);
246 Device
->BlockIo
.Media
= &Device
->BlockMedia
;
247 Device
->BlockIo2
.Media
= &Device
->BlockMedia
;
248 Device
->BlockMedia
.IoAlign
= Device
->Private
->PassThru
->IoAlign
;
249 Device
->BlockMedia
.BlockSize
= 0x200;
250 Device
->BlockMedia
.LastBlock
= 0x00;
251 Device
->BlockMedia
.RemovableMedia
= TRUE
;
252 Device
->BlockMedia
.MediaPresent
= TRUE
;
253 Device
->BlockMedia
.LogicalPartition
= FALSE
;
254 Device
->BlockMedia
.LastBlock
= DivU64x32 (Capacity
, Device
->BlockMedia
.BlockSize
) - 1;
256 if (Csd
->EraseBlkEn
) {
257 Device
->EraseBlock
.EraseLengthGranularity
= 1;
259 Device
->EraseBlock
.EraseLengthGranularity
= (Csd
->SectorSize
+ 1) * (1 << (Csd
->WriteBlLen
- 9));
266 Scan SD Bus to discover the device.
268 @param[in] Private The SD driver private data structure.
269 @param[in] Slot The slot number to check device present.
271 @retval EFI_SUCCESS Successfully to discover the device and attach
272 SdMmcIoProtocol to it.
273 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
275 @retval EFI_ALREADY_STARTED The device was discovered before.
276 @retval Others Fail to discover the device.
282 IN SD_DRIVER_PRIVATE_DATA
*Private
,
288 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
289 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
290 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
291 EFI_HANDLE DeviceHandle
;
292 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
296 NewDevicePath
= NULL
;
297 RemainingDevicePath
= NULL
;
298 PassThru
= Private
->PassThru
;
303 Status
= PassThru
->BuildDevicePath (
308 if (EFI_ERROR(Status
)) {
312 if (DevicePath
->SubType
!= MSG_SD_DP
) {
313 Status
= EFI_UNSUPPORTED
;
317 NewDevicePath
= AppendDevicePathNode (
318 Private
->ParentDevicePath
,
322 if (NewDevicePath
== NULL
) {
323 Status
= EFI_OUT_OF_RESOURCES
;
328 RemainingDevicePath
= NewDevicePath
;
329 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
330 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd(RemainingDevicePath
)) {
332 // The device has been started, directly return to fast boot.
334 Status
= EFI_ALREADY_STARTED
;
339 // Allocate buffer to store SD_DEVICE private data.
341 Device
= AllocateCopyPool (sizeof (SD_DEVICE
), &mSdDeviceTemplate
);
342 if (Device
== NULL
) {
343 Status
= EFI_OUT_OF_RESOURCES
;
347 Device
->DevicePath
= NewDevicePath
;
349 Device
->Private
= Private
;
350 InitializeListHead (&Device
->Queue
);
353 // Expose user area in the Sd memory card to upper layer.
355 Status
= DiscoverUserArea (Device
);
356 if (EFI_ERROR(Status
)) {
360 Device
->ControllerNameTable
= NULL
;
363 gSdDxeComponentName
.SupportedLanguages
,
364 &Device
->ControllerNameTable
,
370 gSdDxeComponentName2
.SupportedLanguages
,
371 &Device
->ControllerNameTable
,
376 Status
= gBS
->InstallMultipleProtocolInterfaces (
378 &gEfiDevicePathProtocolGuid
,
380 &gEfiBlockIoProtocolGuid
,
382 &gEfiBlockIo2ProtocolGuid
,
384 &gEfiEraseBlockProtocolGuid
,
386 &gEfiDiskInfoProtocolGuid
,
391 if (!EFI_ERROR (Status
)) {
394 &gEfiSdMmcPassThruProtocolGuid
,
395 (VOID
**) &(Private
->PassThru
),
396 Private
->DriverBindingHandle
,
398 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
403 FreePool (DevicePath
);
405 if (EFI_ERROR (Status
) && (NewDevicePath
!= NULL
)) {
406 FreePool (NewDevicePath
);
409 if (EFI_ERROR (Status
) && (Device
!= NULL
)) {
417 Tests to see if this driver supports a given controller. If a child device is provided,
418 it further tests to see if this driver supports creating a handle for the specified child device.
420 This function checks to see if the driver specified by This supports the device specified by
421 ControllerHandle. Drivers will typically use the device path attached to
422 ControllerHandle and/or the services from the bus I/O abstraction attached to
423 ControllerHandle to determine if the driver supports ControllerHandle. This function
424 may be called many times during platform initialization. In order to reduce boot times, the tests
425 performed by this function must be very small, and take as little time as possible to execute. This
426 function must not change the state of any hardware devices, and this function must be aware that the
427 device specified by ControllerHandle may already be managed by the same driver or a
428 different driver. This function must match its calls to AllocatePages() with FreePages(),
429 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
430 Since ControllerHandle may have been previously started by the same driver, if a protocol is
431 already in the opened state, then it must not be closed with CloseProtocol(). This is required
432 to guarantee the state of ControllerHandle is not modified by this function.
434 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
435 @param[in] ControllerHandle The handle of the controller to test. This handle
436 must support a protocol interface that supplies
437 an I/O abstraction to the driver.
438 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
439 parameter is ignored by device drivers, and is optional for bus
440 drivers. For bus drivers, if this parameter is not NULL, then
441 the bus driver must determine if the bus controller specified
442 by ControllerHandle and the child controller specified
443 by RemainingDevicePath are both supported by this
446 @retval EFI_SUCCESS The device specified by ControllerHandle and
447 RemainingDevicePath is supported by the driver specified by This.
448 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
449 RemainingDevicePath is already being managed by the driver
451 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
452 RemainingDevicePath is already being managed by a different
453 driver or an application that requires exclusive access.
454 Currently not implemented.
455 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
456 RemainingDevicePath is not supported by the driver specified by This.
460 SdDxeDriverBindingSupported (
461 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
462 IN EFI_HANDLE Controller
,
463 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
467 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
468 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
472 // Test EFI_SD_MMC_PASS_THRU_PROTOCOL on the controller handle.
474 Status
= gBS
->OpenProtocol (
476 &gEfiSdMmcPassThruProtocolGuid
,
478 This
->DriverBindingHandle
,
480 EFI_OPEN_PROTOCOL_BY_DRIVER
483 if (Status
== EFI_ALREADY_STARTED
) {
487 if (EFI_ERROR (Status
)) {
492 // Test RemainingDevicePath is valid or not.
494 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
495 Status
= PassThru
->GetSlotNumber (PassThru
, RemainingDevicePath
, &Slot
);
496 if (EFI_ERROR (Status
)) {
498 // Close the I/O Abstraction(s) used to perform the supported test
502 &gEfiSdMmcPassThruProtocolGuid
,
503 This
->DriverBindingHandle
,
511 // Close the I/O Abstraction(s) used to perform the supported test
515 &gEfiSdMmcPassThruProtocolGuid
,
516 This
->DriverBindingHandle
,
521 // Open the EFI Device Path protocol needed to perform the supported test
523 Status
= gBS
->OpenProtocol (
525 &gEfiDevicePathProtocolGuid
,
526 (VOID
**) &ParentDevicePath
,
527 This
->DriverBindingHandle
,
529 EFI_OPEN_PROTOCOL_GET_PROTOCOL
535 Starts a device controller or a bus controller.
537 The Start() function is designed to be invoked from the EFI boot service ConnectController().
538 As a result, much of the error checking on the parameters to Start() has been moved into this
539 common boot service. It is legal to call Start() from other locations,
540 but the following calling restrictions must be followed or the system behavior will not be deterministic.
541 1. ControllerHandle must be a valid EFI_HANDLE.
542 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
543 EFI_DEVICE_PATH_PROTOCOL.
544 3. Prior to calling Start(), the Supported() function for the driver specified by This must
545 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
547 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
548 @param[in] ControllerHandle The handle of the controller to start. This handle
549 must support a protocol interface that supplies
550 an I/O abstraction to the driver.
551 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
552 parameter is ignored by device drivers, and is optional for bus
553 drivers. For a bus driver, if this parameter is NULL, then handles
554 for all the children of Controller are created by this driver.
555 If this parameter is not NULL and the first Device Path Node is
556 not the End of Device Path Node, then only the handle for the
557 child device specified by the first Device Path Node of
558 RemainingDevicePath is created by this driver.
559 If the first Device Path Node of RemainingDevicePath is
560 the End of Device Path Node, no child handle is created by this
563 @retval EFI_SUCCESS The device was started.
564 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
565 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
566 @retval Others The driver failded to start the device.
571 SdDxeDriverBindingStart (
572 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
573 IN EFI_HANDLE Controller
,
574 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
578 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
579 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
580 SD_DRIVER_PRIVATE_DATA
*Private
;
585 Status
= gBS
->OpenProtocol (
587 &gEfiSdMmcPassThruProtocolGuid
,
589 This
->DriverBindingHandle
,
591 EFI_OPEN_PROTOCOL_BY_DRIVER
593 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
598 // Check EFI_ALREADY_STARTED to reuse the original SD_DRIVER_PRIVATE_DATA.
600 if (Status
!= EFI_ALREADY_STARTED
) {
601 Private
= AllocateZeroPool (sizeof (SD_DRIVER_PRIVATE_DATA
));
602 if (Private
== NULL
) {
603 Status
= EFI_OUT_OF_RESOURCES
;
607 Status
= gBS
->OpenProtocol (
609 &gEfiDevicePathProtocolGuid
,
610 (VOID
**) &ParentDevicePath
,
611 This
->DriverBindingHandle
,
613 EFI_OPEN_PROTOCOL_GET_PROTOCOL
615 ASSERT_EFI_ERROR (Status
);
616 Private
->PassThru
= PassThru
;
617 Private
->Controller
= Controller
;
618 Private
->ParentDevicePath
= ParentDevicePath
;
619 Private
->DriverBindingHandle
= This
->DriverBindingHandle
;
621 Status
= gBS
->InstallProtocolInterface (
624 EFI_NATIVE_INTERFACE
,
627 if (EFI_ERROR (Status
)) {
631 Status
= gBS
->OpenProtocol (
635 This
->DriverBindingHandle
,
637 EFI_OPEN_PROTOCOL_GET_PROTOCOL
639 if (EFI_ERROR (Status
)) {
644 if (RemainingDevicePath
== NULL
) {
647 Status
= PassThru
->GetNextSlot (PassThru
, &Slot
);
648 if (EFI_ERROR (Status
)) {
650 // Cannot find more legal slots.
652 Status
= EFI_SUCCESS
;
656 Status
= DiscoverSdDevice (Private
, Slot
);
657 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
661 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
662 Status
= PassThru
->GetSlotNumber (PassThru
, RemainingDevicePath
, &Slot
);
663 if (!EFI_ERROR (Status
)) {
664 Status
= DiscoverSdDevice (Private
, Slot
);
669 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
672 &gEfiSdMmcPassThruProtocolGuid
,
673 This
->DriverBindingHandle
,
677 if (Private
!= NULL
) {
678 gBS
->UninstallMultipleProtocolInterfaces (
691 Stops a device controller or a bus controller.
693 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
694 As a result, much of the error checking on the parameters to Stop() has been moved
695 into this common boot service. It is legal to call Stop() from other locations,
696 but the following calling restrictions must be followed or the system behavior will not be deterministic.
697 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
698 same driver's Start() function.
699 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
700 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
701 Start() function, and the Start() function must have called OpenProtocol() on
702 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
704 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
705 @param[in] ControllerHandle A handle to the device being stopped. The handle must
706 support a bus specific I/O protocol for the driver
707 to use to stop the device.
708 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
709 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
710 if NumberOfChildren is 0.
712 @retval EFI_SUCCESS The device was stopped.
713 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
718 SdDxeDriverBindingStop (
719 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
720 IN EFI_HANDLE Controller
,
721 IN UINTN NumberOfChildren
,
722 IN EFI_HANDLE
*ChildHandleBuffer
726 BOOLEAN AllChildrenStopped
;
728 SD_DRIVER_PRIVATE_DATA
*Private
;
730 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
731 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
732 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
734 LIST_ENTRY
*NextLink
;
738 if (NumberOfChildren
== 0) {
739 Status
= gBS
->OpenProtocol (
743 This
->DriverBindingHandle
,
745 EFI_OPEN_PROTOCOL_GET_PROTOCOL
747 if (EFI_ERROR (Status
)) {
748 return EFI_DEVICE_ERROR
;
751 gBS
->UninstallProtocolInterface (
758 &gEfiSdMmcPassThruProtocolGuid
,
759 This
->DriverBindingHandle
,
768 AllChildrenStopped
= TRUE
;
770 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
773 Status
= gBS
->OpenProtocol (
774 ChildHandleBuffer
[Index
],
775 &gEfiBlockIoProtocolGuid
,
777 This
->DriverBindingHandle
,
779 EFI_OPEN_PROTOCOL_GET_PROTOCOL
781 if (EFI_ERROR (Status
)) {
782 Status
= gBS
->OpenProtocol (
783 ChildHandleBuffer
[Index
],
784 &gEfiBlockIo2ProtocolGuid
,
786 This
->DriverBindingHandle
,
788 EFI_OPEN_PROTOCOL_GET_PROTOCOL
790 if (EFI_ERROR (Status
)) {
791 AllChildrenStopped
= FALSE
;
796 if (BlockIo
!= NULL
) {
797 Device
= SD_DEVICE_DATA_FROM_BLKIO (BlockIo
);
799 ASSERT (BlockIo2
!= NULL
);
800 Device
= SD_DEVICE_DATA_FROM_BLKIO2 (BlockIo2
);
804 // Free all on-going async tasks.
806 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
807 for (Link
= GetFirstNode (&Device
->Queue
);
808 !IsNull (&Device
->Queue
, Link
);
810 NextLink
= GetNextNode (&Device
->Queue
, Link
);
811 RemoveEntryList (Link
);
813 Request
= SD_REQUEST_FROM_LINK (Link
);
815 gBS
->CloseEvent (Request
->Event
);
816 Request
->Token
->TransactionStatus
= EFI_ABORTED
;
818 if (Request
->IsEnd
) {
819 gBS
->SignalEvent (Request
->Token
->Event
);
824 gBS
->RestoreTPL (OldTpl
);
827 // Close the child handle
829 Status
= gBS
->CloseProtocol (
831 &gEfiSdMmcPassThruProtocolGuid
,
832 This
->DriverBindingHandle
,
833 ChildHandleBuffer
[Index
]
836 Status
= gBS
->UninstallMultipleProtocolInterfaces (
837 ChildHandleBuffer
[Index
],
838 &gEfiDevicePathProtocolGuid
,
840 &gEfiBlockIoProtocolGuid
,
842 &gEfiBlockIo2ProtocolGuid
,
844 &gEfiEraseBlockProtocolGuid
,
846 &gEfiDiskInfoProtocolGuid
,
850 if (EFI_ERROR (Status
)) {
851 AllChildrenStopped
= FALSE
;
854 &gEfiSdMmcPassThruProtocolGuid
,
856 This
->DriverBindingHandle
,
857 ChildHandleBuffer
[Index
],
858 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
861 FreePool (Device
->DevicePath
);
862 FreeUnicodeStringTable (Device
->ControllerNameTable
);
867 if (!AllChildrenStopped
) {
868 return EFI_DEVICE_ERROR
;
875 The user Entry Point for module SdDxe. The user code starts with this function.
877 @param[in] ImageHandle The firmware allocated handle for the EFI image.
878 @param[in] SystemTable A pointer to the EFI System Table.
880 @retval EFI_SUCCESS The entry point is executed successfully.
881 @retval other Some errors occur when executing this entry point.
887 IN EFI_HANDLE ImageHandle
,
888 IN EFI_SYSTEM_TABLE
*SystemTable
894 // Install driver model protocol(s).
896 Status
= EfiLibInstallDriverBindingComponentName2 (
899 &gSdDxeDriverBinding
,
901 &gSdDxeComponentName
,
902 &gSdDxeComponentName2
904 ASSERT_EFI_ERROR (Status
);