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 - 2016, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 // SdDxe Driver Binding Protocol Instance
23 EFI_DRIVER_BINDING_PROTOCOL gSdDxeDriverBinding
= {
24 SdDxeDriverBindingSupported
,
25 SdDxeDriverBindingStart
,
26 SdDxeDriverBindingStop
,
33 // Template for SD_DEVICE data structure.
35 SD_DEVICE mSdDeviceTemplate
= {
36 SD_DEVICE_SIGNATURE
, // Signature
40 FALSE
, // SectorAddressing
42 EFI_BLOCK_IO_PROTOCOL_REVISION
,
58 FALSE
, // RemovableMedia
60 FALSE
, // LogicPartition
62 FALSE
, // WritingCache
68 EFI_ERASE_BLOCK_PROTOCOL_REVISION
,
82 NULL
, // ControllerNameTable
90 Decode and print SD CSD Register content.
92 @param[in] Csd Pointer to SD_CSD data structure.
94 @retval EFI_SUCCESS The function completed successfully
103 DEBUG((DEBUG_INFO
, "== Dump Sd Csd Register==\n"));
104 DEBUG((DEBUG_INFO
, " CSD structure 0x%x\n", Csd
->CsdStructure
));
105 DEBUG((DEBUG_INFO
, " Data read access-time 1 0x%x\n", Csd
->Taac
));
106 DEBUG((DEBUG_INFO
, " Data read access-time 2 0x%x\n", Csd
->Nsac
));
107 DEBUG((DEBUG_INFO
, " Max. bus clock frequency 0x%x\n", Csd
->TranSpeed
));
108 DEBUG((DEBUG_INFO
, " Device command classes 0x%x\n", Csd
->Ccc
));
109 DEBUG((DEBUG_INFO
, " Max. read data block length 0x%x\n", Csd
->ReadBlLen
));
110 DEBUG((DEBUG_INFO
, " Partial blocks for read allowed 0x%x\n", Csd
->ReadBlPartial
));
111 DEBUG((DEBUG_INFO
, " Write block misalignment 0x%x\n", Csd
->WriteBlkMisalign
));
112 DEBUG((DEBUG_INFO
, " Read block misalignment 0x%x\n", Csd
->ReadBlkMisalign
));
113 DEBUG((DEBUG_INFO
, " DSR implemented 0x%x\n", Csd
->DsrImp
));
114 if (Csd
->CsdStructure
== 0) {
115 DEBUG((DEBUG_INFO
, " Device size 0x%x\n", Csd
->CSizeLow
| (Csd
->CSizeHigh
<< 2)));
116 DEBUG((DEBUG_INFO
, " Max. read current @ VDD min 0x%x\n", Csd
->VddRCurrMin
));
117 DEBUG((DEBUG_INFO
, " Max. read current @ VDD max 0x%x\n", Csd
->VddRCurrMax
));
118 DEBUG((DEBUG_INFO
, " Max. write current @ VDD min 0x%x\n", Csd
->VddWCurrMin
));
119 DEBUG((DEBUG_INFO
, " Max. write current @ VDD max 0x%x\n", Csd
->VddWCurrMax
));
121 Csd2
= (SD_CSD2
*)(VOID
*)Csd
;
122 DEBUG((DEBUG_INFO
, " Device size 0x%x\n", Csd2
->CSizeLow
| (Csd
->CSizeHigh
<< 16)));
124 DEBUG((DEBUG_INFO
, " Erase sector size 0x%x\n", Csd
->SectorSize
));
125 DEBUG((DEBUG_INFO
, " Erase single block enable 0x%x\n", Csd
->EraseBlkEn
));
126 DEBUG((DEBUG_INFO
, " Write protect group size 0x%x\n", Csd
->WpGrpSize
));
127 DEBUG((DEBUG_INFO
, " Write protect group enable 0x%x\n", Csd
->WpGrpEnable
));
128 DEBUG((DEBUG_INFO
, " Write speed factor 0x%x\n", Csd
->R2WFactor
));
129 DEBUG((DEBUG_INFO
, " Max. write data block length 0x%x\n", Csd
->WriteBlLen
));
130 DEBUG((DEBUG_INFO
, " Partial blocks for write allowed 0x%x\n", Csd
->WriteBlPartial
));
131 DEBUG((DEBUG_INFO
, " File format group 0x%x\n", Csd
->FileFormatGrp
));
132 DEBUG((DEBUG_INFO
, " Copy flag (OTP) 0x%x\n", Csd
->Copy
));
133 DEBUG((DEBUG_INFO
, " Permanent write protection 0x%x\n", Csd
->PermWriteProtect
));
134 DEBUG((DEBUG_INFO
, " Temporary write protection 0x%x\n", Csd
->TmpWriteProtect
));
135 DEBUG((DEBUG_INFO
, " File format 0x%x\n", Csd
->FileFormat
));
141 Get SD device model name.
143 @param[in, out] Device The pointer to the SD_DEVICE data structure.
144 @param[in] Cid Pointer to SD_CID data structure.
146 @retval EFI_SUCCESS The function completed successfully
151 IN OUT SD_DEVICE
*Device
,
155 CHAR8 String
[SD_MODEL_NAME_MAX_LEN
];
157 ZeroMem (String
, sizeof (String
));
158 CopyMem (String
, Cid
->OemId
, sizeof (Cid
->OemId
));
159 String
[sizeof (Cid
->OemId
)] = ' ';
160 CopyMem (String
+ sizeof (Cid
->OemId
) + 1, Cid
->ProductName
, sizeof (Cid
->ProductName
));
161 String
[sizeof (Cid
->OemId
) + sizeof (Cid
->ProductName
)] = ' ';
162 CopyMem (String
+ sizeof (Cid
->OemId
) + sizeof (Cid
->ProductName
) + 1, Cid
->ProductSerialNumber
, sizeof (Cid
->ProductSerialNumber
));
164 AsciiStrToUnicodeStrS (String
, Device
->ModelName
, sizeof (Device
->ModelName
) / sizeof (Device
->ModelName
[0]));
170 Discover user area partition in the SD device.
172 @param[in] Device The pointer to the SD_DEVICE data structure.
174 @retval EFI_SUCCESS The user area partition in the SD device is successfully identified.
175 @return Others Some error occurs when identifying the user area.
195 // Deselect the device to force it enter stby mode.
196 // Note here we don't judge return status as some SD devices return
197 // error but the state has been stby.
199 SdSelect (Device
, 0);
201 Status
= SdSetRca (Device
, &Rca
);
202 if (EFI_ERROR (Status
)) {
203 DEBUG ((EFI_D_ERROR
, "DiscoverUserArea(): Assign new Rca = 0x%x fails with %r\n", Rca
, Status
));
208 Status
= SdGetCsd (Device
, Rca
, Csd
);
209 if (EFI_ERROR (Status
)) {
215 Status
= SdGetCid (Device
, Rca
, Cid
);
216 if (EFI_ERROR (Status
)) {
219 GetSdModelName (Device
, Cid
);
221 Status
= SdSelect (Device
, Rca
);
222 if (EFI_ERROR (Status
)) {
223 DEBUG ((EFI_D_ERROR
, "DiscoverUserArea(): Reselect the device 0x%x fails with %r\n", Rca
, Status
));
227 Status
= SdSendStatus (Device
, Rca
, &DevStatus
);
228 if (EFI_ERROR (Status
)) {
232 if (Csd
->CsdStructure
== 0) {
233 Device
->SectorAddressing
= FALSE
;
234 CSize
= (Csd
->CSizeHigh
<< 2 | Csd
->CSizeLow
) + 1;
235 CSizeMul
= (1 << (Csd
->CSizeMul
+ 2));
236 ReadBlLen
= (1 << (Csd
->ReadBlLen
));
237 Capacity
= MultU64x32 (MultU64x32 ((UINT64
)CSize
, CSizeMul
), ReadBlLen
);
239 Device
->SectorAddressing
= TRUE
;
240 Csd2
= (SD_CSD2
*)(VOID
*)Csd
;
241 CSize
= (Csd2
->CSizeHigh
<< 16 | Csd2
->CSizeLow
) + 1;
242 Capacity
= MultU64x32 ((UINT64
)CSize
, SIZE_512KB
);
245 Device
->BlockIo
.Media
= &Device
->BlockMedia
;
246 Device
->BlockIo2
.Media
= &Device
->BlockMedia
;
247 Device
->BlockMedia
.IoAlign
= Device
->Private
->PassThru
->IoAlign
;
248 Device
->BlockMedia
.BlockSize
= 0x200;
249 Device
->BlockMedia
.LastBlock
= 0x00;
250 Device
->BlockMedia
.RemovableMedia
= TRUE
;
251 Device
->BlockMedia
.MediaPresent
= TRUE
;
252 Device
->BlockMedia
.LogicalPartition
= FALSE
;
253 Device
->BlockMedia
.LastBlock
= DivU64x32 (Capacity
, Device
->BlockMedia
.BlockSize
) - 1;
255 if (Csd
->EraseBlkEn
) {
256 Device
->EraseBlock
.EraseLengthGranularity
= 1;
258 Device
->EraseBlock
.EraseLengthGranularity
= (Csd
->SectorSize
+ 1) * (1 << (Csd
->WriteBlLen
- 9));
265 Scan SD Bus to discover the device.
267 @param[in] Private The SD driver private data structure.
268 @param[in] Slot The slot number to check device present.
270 @retval EFI_SUCCESS Successfully to discover the device and attach
271 SdMmcIoProtocol to it.
272 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
274 @retval EFI_ALREADY_STARTED The device was discovered before.
275 @retval Others Fail to discover the device.
281 IN SD_DRIVER_PRIVATE_DATA
*Private
,
287 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
288 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
289 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
290 EFI_HANDLE DeviceHandle
;
291 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
295 NewDevicePath
= NULL
;
296 RemainingDevicePath
= NULL
;
297 PassThru
= Private
->PassThru
;
302 Status
= PassThru
->BuildDevicePath (
307 if (EFI_ERROR(Status
)) {
311 if (DevicePath
->SubType
!= MSG_SD_DP
) {
312 Status
= EFI_UNSUPPORTED
;
316 NewDevicePath
= AppendDevicePathNode (
317 Private
->ParentDevicePath
,
321 if (NewDevicePath
== NULL
) {
322 Status
= EFI_OUT_OF_RESOURCES
;
327 RemainingDevicePath
= NewDevicePath
;
328 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
329 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd(RemainingDevicePath
)) {
331 // The device has been started, directly return to fast boot.
333 Status
= EFI_ALREADY_STARTED
;
338 // Allocate buffer to store SD_DEVICE private data.
340 Device
= AllocateCopyPool (sizeof (SD_DEVICE
), &mSdDeviceTemplate
);
341 if (Device
== NULL
) {
342 Status
= EFI_OUT_OF_RESOURCES
;
346 Device
->DevicePath
= NewDevicePath
;
348 Device
->Private
= Private
;
349 InitializeListHead (&Device
->Queue
);
352 // Expose user area in the Sd memory card to upper layer.
354 Status
= DiscoverUserArea (Device
);
355 if (EFI_ERROR(Status
)) {
359 Device
->ControllerNameTable
= NULL
;
362 gSdDxeComponentName
.SupportedLanguages
,
363 &Device
->ControllerNameTable
,
369 gSdDxeComponentName
.SupportedLanguages
,
370 &Device
->ControllerNameTable
,
375 Status
= gBS
->InstallMultipleProtocolInterfaces (
377 &gEfiDevicePathProtocolGuid
,
379 &gEfiBlockIoProtocolGuid
,
381 &gEfiBlockIo2ProtocolGuid
,
383 &gEfiEraseBlockProtocolGuid
,
388 if (!EFI_ERROR (Status
)) {
391 &gEfiSdMmcPassThruProtocolGuid
,
392 (VOID
**) &(Private
->PassThru
),
393 Private
->DriverBindingHandle
,
395 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
400 FreePool (DevicePath
);
402 if (EFI_ERROR (Status
) && (NewDevicePath
!= NULL
)) {
403 FreePool (NewDevicePath
);
406 if (EFI_ERROR (Status
) && (Device
!= NULL
)) {
414 Tests to see if this driver supports a given controller. If a child device is provided,
415 it further tests to see if this driver supports creating a handle for the specified child device.
417 This function checks to see if the driver specified by This supports the device specified by
418 ControllerHandle. Drivers will typically use the device path attached to
419 ControllerHandle and/or the services from the bus I/O abstraction attached to
420 ControllerHandle to determine if the driver supports ControllerHandle. This function
421 may be called many times during platform initialization. In order to reduce boot times, the tests
422 performed by this function must be very small, and take as little time as possible to execute. This
423 function must not change the state of any hardware devices, and this function must be aware that the
424 device specified by ControllerHandle may already be managed by the same driver or a
425 different driver. This function must match its calls to AllocatePages() with FreePages(),
426 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
427 Since ControllerHandle may have been previously started by the same driver, if a protocol is
428 already in the opened state, then it must not be closed with CloseProtocol(). This is required
429 to guarantee the state of ControllerHandle is not modified by this function.
431 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
432 @param[in] ControllerHandle The handle of the controller to test. This handle
433 must support a protocol interface that supplies
434 an I/O abstraction to the driver.
435 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
436 parameter is ignored by device drivers, and is optional for bus
437 drivers. For bus drivers, if this parameter is not NULL, then
438 the bus driver must determine if the bus controller specified
439 by ControllerHandle and the child controller specified
440 by RemainingDevicePath are both supported by this
443 @retval EFI_SUCCESS The device specified by ControllerHandle and
444 RemainingDevicePath is supported by the driver specified by This.
445 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
446 RemainingDevicePath is already being managed by the driver
448 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
449 RemainingDevicePath is already being managed by a different
450 driver or an application that requires exclusive access.
451 Currently not implemented.
452 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
453 RemainingDevicePath is not supported by the driver specified by This.
457 SdDxeDriverBindingSupported (
458 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
459 IN EFI_HANDLE Controller
,
460 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
464 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
465 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
469 // Test EFI_SD_MMC_PASS_THRU_PROTOCOL on the controller handle.
471 Status
= gBS
->OpenProtocol (
473 &gEfiSdMmcPassThruProtocolGuid
,
475 This
->DriverBindingHandle
,
477 EFI_OPEN_PROTOCOL_BY_DRIVER
480 if (Status
== EFI_ALREADY_STARTED
) {
484 if (EFI_ERROR (Status
)) {
489 // Test RemainingDevicePath is valid or not.
491 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
492 Status
= PassThru
->GetSlotNumber (PassThru
, RemainingDevicePath
, &Slot
);
493 if (EFI_ERROR (Status
)) {
495 // Close the I/O Abstraction(s) used to perform the supported test
499 &gEfiSdMmcPassThruProtocolGuid
,
500 This
->DriverBindingHandle
,
508 // Close the I/O Abstraction(s) used to perform the supported test
512 &gEfiSdMmcPassThruProtocolGuid
,
513 This
->DriverBindingHandle
,
518 // Open the EFI Device Path protocol needed to perform the supported test
520 Status
= gBS
->OpenProtocol (
522 &gEfiDevicePathProtocolGuid
,
523 (VOID
**) &ParentDevicePath
,
524 This
->DriverBindingHandle
,
526 EFI_OPEN_PROTOCOL_GET_PROTOCOL
532 Starts a device controller or a bus controller.
534 The Start() function is designed to be invoked from the EFI boot service ConnectController().
535 As a result, much of the error checking on the parameters to Start() has been moved into this
536 common boot service. It is legal to call Start() from other locations,
537 but the following calling restrictions must be followed or the system behavior will not be deterministic.
538 1. ControllerHandle must be a valid EFI_HANDLE.
539 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
540 EFI_DEVICE_PATH_PROTOCOL.
541 3. Prior to calling Start(), the Supported() function for the driver specified by This must
542 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
544 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
545 @param[in] ControllerHandle The handle of the controller to start. This handle
546 must support a protocol interface that supplies
547 an I/O abstraction to the driver.
548 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
549 parameter is ignored by device drivers, and is optional for bus
550 drivers. For a bus driver, if this parameter is NULL, then handles
551 for all the children of Controller are created by this driver.
552 If this parameter is not NULL and the first Device Path Node is
553 not the End of Device Path Node, then only the handle for the
554 child device specified by the first Device Path Node of
555 RemainingDevicePath is created by this driver.
556 If the first Device Path Node of RemainingDevicePath is
557 the End of Device Path Node, no child handle is created by this
560 @retval EFI_SUCCESS The device was started.
561 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
562 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
563 @retval Others The driver failded to start the device.
568 SdDxeDriverBindingStart (
569 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
570 IN EFI_HANDLE Controller
,
571 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
575 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
576 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
577 SD_DRIVER_PRIVATE_DATA
*Private
;
582 Status
= gBS
->OpenProtocol (
584 &gEfiSdMmcPassThruProtocolGuid
,
586 This
->DriverBindingHandle
,
588 EFI_OPEN_PROTOCOL_BY_DRIVER
590 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
595 // Check EFI_ALREADY_STARTED to reuse the original SD_DRIVER_PRIVATE_DATA.
597 if (Status
!= EFI_ALREADY_STARTED
) {
598 Private
= AllocateZeroPool (sizeof (SD_DRIVER_PRIVATE_DATA
));
599 if (Private
== NULL
) {
600 Status
= EFI_OUT_OF_RESOURCES
;
604 Status
= gBS
->OpenProtocol (
606 &gEfiDevicePathProtocolGuid
,
607 (VOID
**) &ParentDevicePath
,
608 This
->DriverBindingHandle
,
610 EFI_OPEN_PROTOCOL_GET_PROTOCOL
612 ASSERT_EFI_ERROR (Status
);
613 Private
->PassThru
= PassThru
;
614 Private
->Controller
= Controller
;
615 Private
->ParentDevicePath
= ParentDevicePath
;
616 Private
->DriverBindingHandle
= This
->DriverBindingHandle
;
618 Status
= gBS
->InstallProtocolInterface (
621 EFI_NATIVE_INTERFACE
,
624 if (EFI_ERROR (Status
)) {
628 Status
= gBS
->OpenProtocol (
632 This
->DriverBindingHandle
,
634 EFI_OPEN_PROTOCOL_GET_PROTOCOL
636 if (EFI_ERROR (Status
)) {
641 if (RemainingDevicePath
== NULL
) {
644 Status
= PassThru
->GetNextSlot (PassThru
, &Slot
);
645 if (EFI_ERROR (Status
)) {
647 // Cannot find more legal slots.
649 Status
= EFI_SUCCESS
;
653 Status
= DiscoverSdDevice (Private
, Slot
);
654 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
658 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
659 Status
= PassThru
->GetSlotNumber (PassThru
, RemainingDevicePath
, &Slot
);
660 if (!EFI_ERROR (Status
)) {
661 Status
= DiscoverSdDevice (Private
, Slot
);
666 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
669 &gEfiSdMmcPassThruProtocolGuid
,
670 This
->DriverBindingHandle
,
674 if (Private
!= NULL
) {
675 gBS
->UninstallMultipleProtocolInterfaces (
688 Stops a device controller or a bus controller.
690 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
691 As a result, much of the error checking on the parameters to Stop() has been moved
692 into this common boot service. It is legal to call Stop() from other locations,
693 but the following calling restrictions must be followed or the system behavior will not be deterministic.
694 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
695 same driver's Start() function.
696 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
697 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
698 Start() function, and the Start() function must have called OpenProtocol() on
699 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
701 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
702 @param[in] ControllerHandle A handle to the device being stopped. The handle must
703 support a bus specific I/O protocol for the driver
704 to use to stop the device.
705 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
706 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
707 if NumberOfChildren is 0.
709 @retval EFI_SUCCESS The device was stopped.
710 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
715 SdDxeDriverBindingStop (
716 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
717 IN EFI_HANDLE Controller
,
718 IN UINTN NumberOfChildren
,
719 IN EFI_HANDLE
*ChildHandleBuffer
723 BOOLEAN AllChildrenStopped
;
725 SD_DRIVER_PRIVATE_DATA
*Private
;
727 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
728 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
729 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
731 LIST_ENTRY
*NextLink
;
735 if (NumberOfChildren
== 0) {
736 Status
= gBS
->OpenProtocol (
740 This
->DriverBindingHandle
,
742 EFI_OPEN_PROTOCOL_GET_PROTOCOL
744 if (EFI_ERROR (Status
)) {
745 return EFI_DEVICE_ERROR
;
748 gBS
->UninstallProtocolInterface (
755 &gEfiSdMmcPassThruProtocolGuid
,
756 This
->DriverBindingHandle
,
765 AllChildrenStopped
= TRUE
;
767 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
770 Status
= gBS
->OpenProtocol (
771 ChildHandleBuffer
[Index
],
772 &gEfiBlockIoProtocolGuid
,
774 This
->DriverBindingHandle
,
776 EFI_OPEN_PROTOCOL_GET_PROTOCOL
778 if (EFI_ERROR (Status
)) {
779 Status
= gBS
->OpenProtocol (
780 ChildHandleBuffer
[Index
],
781 &gEfiBlockIo2ProtocolGuid
,
783 This
->DriverBindingHandle
,
785 EFI_OPEN_PROTOCOL_GET_PROTOCOL
787 if (EFI_ERROR (Status
)) {
788 AllChildrenStopped
= FALSE
;
793 if (BlockIo
!= NULL
) {
794 Device
= SD_DEVICE_DATA_FROM_BLKIO (BlockIo
);
796 ASSERT (BlockIo2
!= NULL
);
797 Device
= SD_DEVICE_DATA_FROM_BLKIO2 (BlockIo2
);
801 // Free all on-going async tasks.
803 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
804 for (Link
= GetFirstNode (&Device
->Queue
);
805 !IsNull (&Device
->Queue
, Link
);
807 NextLink
= GetNextNode (&Device
->Queue
, Link
);
808 RemoveEntryList (Link
);
810 Request
= SD_REQUEST_FROM_LINK (Link
);
812 gBS
->CloseEvent (Request
->Event
);
813 Request
->Token
->TransactionStatus
= EFI_ABORTED
;
815 if (Request
->IsEnd
) {
816 gBS
->SignalEvent (Request
->Token
->Event
);
821 gBS
->RestoreTPL (OldTpl
);
824 // Close the child handle
826 Status
= gBS
->CloseProtocol (
828 &gEfiSdMmcPassThruProtocolGuid
,
829 This
->DriverBindingHandle
,
830 ChildHandleBuffer
[Index
]
833 Status
= gBS
->UninstallMultipleProtocolInterfaces (
834 ChildHandleBuffer
[Index
],
835 &gEfiDevicePathProtocolGuid
,
837 &gEfiBlockIoProtocolGuid
,
839 &gEfiBlockIo2ProtocolGuid
,
841 &gEfiEraseBlockProtocolGuid
,
845 if (EFI_ERROR (Status
)) {
846 AllChildrenStopped
= FALSE
;
849 &gEfiSdMmcPassThruProtocolGuid
,
851 This
->DriverBindingHandle
,
852 ChildHandleBuffer
[Index
],
853 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
856 FreePool (Device
->DevicePath
);
857 FreeUnicodeStringTable (Device
->ControllerNameTable
);
862 if (!AllChildrenStopped
) {
863 return EFI_DEVICE_ERROR
;
870 The user Entry Point for module SdDxe. The user code starts with this function.
872 @param[in] ImageHandle The firmware allocated handle for the EFI image.
873 @param[in] SystemTable A pointer to the EFI System Table.
875 @retval EFI_SUCCESS The entry point is executed successfully.
876 @retval other Some errors occur when executing this entry point.
882 IN EFI_HANDLE ImageHandle
,
883 IN EFI_SYSTEM_TABLE
*SystemTable
889 // Install driver model protocol(s).
891 Status
= EfiLibInstallDriverBindingComponentName2 (
894 &gSdDxeDriverBinding
,
896 &gSdDxeComponentName
,
897 &gSdDxeComponentName2
899 ASSERT_EFI_ERROR (Status
);