]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
MdeModulePkg/SdMmc: Add EDKII SD/MMC stack
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / EmmcDxe / EmmcDxe.c
1 /** @file
2 The EmmcDxe driver is used to manage the EMMC device.
3
4 It produces BlockIo, BlockIo2 and StorageSecurity protocols to allow upper layer
5 access the EMMC device.
6
7 Copyright (c) 2015, 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
12
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.
15
16 **/
17
18 #include "EmmcDxe.h"
19
20 //
21 // EmmcDxe Driver Binding Protocol Instance
22 //
23 EFI_DRIVER_BINDING_PROTOCOL gEmmcDxeDriverBinding = {
24 EmmcDxeDriverBindingSupported,
25 EmmcDxeDriverBindingStart,
26 EmmcDxeDriverBindingStop,
27 0x10,
28 NULL,
29 NULL
30 };
31
32 //
33 // Template for Emmc Partitions.
34 //
35 EMMC_PARTITION mEmmcPartitionTemplate = {
36 EMMC_PARTITION_SIGNATURE, // Signature
37 FALSE, // Enable
38 EmmcPartitionUnknown, // PartitionType
39 NULL, // Handle
40 NULL, // DevicePath
41 { // BlockIo
42 EFI_BLOCK_IO_PROTOCOL_REVISION,
43 NULL,
44 EmmcReset,
45 EmmcReadBlocks,
46 EmmcWriteBlocks,
47 EmmcFlushBlocks
48 },
49 { // BlockIo2
50 NULL,
51 EmmcResetEx,
52 EmmcReadBlocksEx,
53 EmmcWriteBlocksEx,
54 EmmcFlushBlocksEx
55 },
56 { // BlockMedia
57 0, // MediaId
58 FALSE, // RemovableMedia
59 TRUE, // MediaPresent
60 FALSE, // LogicPartition
61 FALSE, // ReadOnly
62 FALSE, // WritingCache
63 0x200, // BlockSize
64 0, // IoAlign
65 0 // LastBlock
66 },
67 { // StorageSecurity
68 EmmcSecurityProtocolIn,
69 EmmcSecurityProtocolOut
70 },
71 {
72 NULL,
73 NULL
74 },
75 NULL // Device
76 };
77
78 /**
79 Decode and print EMMC CSD Register content.
80
81 @param[in] Csd Pointer to EMMC_CSD data structure.
82
83 @retval EFI_SUCCESS The function completed successfully
84 **/
85 EFI_STATUS
86 DumpCsd (
87 IN EMMC_CSD *Csd
88 )
89 {
90 DEBUG((DEBUG_INFO, "== Dump Emmc Csd Register==\n"));
91 DEBUG((DEBUG_INFO, " CSD structure 0x%x\n", Csd->CsdStructure));
92 DEBUG((DEBUG_INFO, " System specification version 0x%x\n", Csd->SpecVers));
93 DEBUG((DEBUG_INFO, " Data read access-time 1 0x%x\n", Csd->Taac));
94 DEBUG((DEBUG_INFO, " Data read access-time 2 0x%x\n", Csd->Nsac));
95 DEBUG((DEBUG_INFO, " Max. bus clock frequency 0x%x\n", Csd->TranSpeed));
96 DEBUG((DEBUG_INFO, " Device command classes 0x%x\n", Csd->Ccc));
97 DEBUG((DEBUG_INFO, " Max. read data block length 0x%x\n", Csd->ReadBlLen));
98 DEBUG((DEBUG_INFO, " Partial blocks for read allowed 0x%x\n", Csd->ReadBlPartial));
99 DEBUG((DEBUG_INFO, " Write block misalignment 0x%x\n", Csd->WriteBlkMisalign));
100 DEBUG((DEBUG_INFO, " Read block misalignment 0x%x\n", Csd->ReadBlkMisalign));
101 DEBUG((DEBUG_INFO, " DSR implemented 0x%x\n", Csd->DsrImp));
102 DEBUG((DEBUG_INFO, " Device size 0x%x\n", Csd->CSizeLow | (Csd->CSizeHigh << 2)));
103 DEBUG((DEBUG_INFO, " Max. read current @ VDD min 0x%x\n", Csd->VddRCurrMin));
104 DEBUG((DEBUG_INFO, " Max. read current @ VDD max 0x%x\n", Csd->VddRCurrMax));
105 DEBUG((DEBUG_INFO, " Max. write current @ VDD min 0x%x\n", Csd->VddWCurrMin));
106 DEBUG((DEBUG_INFO, " Max. write current @ VDD max 0x%x\n", Csd->VddWCurrMax));
107 DEBUG((DEBUG_INFO, " Device size multiplier 0x%x\n", Csd->CSizeMult));
108 DEBUG((DEBUG_INFO, " Erase group size 0x%x\n", Csd->EraseGrpSize));
109 DEBUG((DEBUG_INFO, " Erase group size multiplier 0x%x\n", Csd->EraseGrpMult));
110 DEBUG((DEBUG_INFO, " Write protect group size 0x%x\n", Csd->WpGrpSize));
111 DEBUG((DEBUG_INFO, " Write protect group enable 0x%x\n", Csd->WpGrpEnable));
112 DEBUG((DEBUG_INFO, " Manufacturer default ECC 0x%x\n", Csd->DefaultEcc));
113 DEBUG((DEBUG_INFO, " Write speed factor 0x%x\n", Csd->R2WFactor));
114 DEBUG((DEBUG_INFO, " Max. write data block length 0x%x\n", Csd->WriteBlLen));
115 DEBUG((DEBUG_INFO, " Partial blocks for write allowed 0x%x\n", Csd->WriteBlPartial));
116 DEBUG((DEBUG_INFO, " Content protection application 0x%x\n", Csd->ContentProtApp));
117 DEBUG((DEBUG_INFO, " File format group 0x%x\n", Csd->FileFormatGrp));
118 DEBUG((DEBUG_INFO, " Copy flag (OTP) 0x%x\n", Csd->Copy));
119 DEBUG((DEBUG_INFO, " Permanent write protection 0x%x\n", Csd->PermWriteProtect));
120 DEBUG((DEBUG_INFO, " Temporary write protection 0x%x\n", Csd->TmpWriteProtect));
121 DEBUG((DEBUG_INFO, " File format 0x%x\n", Csd->FileFormat));
122 DEBUG((DEBUG_INFO, " ECC code 0x%x\n", Csd->Ecc));
123
124 return EFI_SUCCESS;
125 }
126
127 /**
128 Decode and print EMMC EXT_CSD Register content.
129
130 @param[in] ExtCsd Pointer to the EMMC_EXT_CSD data structure.
131
132 @retval EFI_SUCCESS The function completed successfully
133 **/
134 EFI_STATUS
135 DumpExtCsd (
136 IN EMMC_EXT_CSD *ExtCsd
137 )
138 {
139 DEBUG((DEBUG_INFO, "==Dump Emmc ExtCsd Register==\n"));
140 DEBUG((DEBUG_INFO, " Supported Command Sets 0x%x\n", ExtCsd->CmdSet));
141 DEBUG((DEBUG_INFO, " HPI features 0x%x\n", ExtCsd->HpiFeatures));
142 DEBUG((DEBUG_INFO, " Background operations support 0x%x\n", ExtCsd->BkOpsSupport));
143 DEBUG((DEBUG_INFO, " Background operations status 0x%x\n", ExtCsd->BkopsStatus));
144 DEBUG((DEBUG_INFO, " Number of correctly programmed sectors 0x%x\n", *((UINT32*)&ExtCsd->CorrectlyPrgSectorsNum[0])));
145 DEBUG((DEBUG_INFO, " Initialization time after partitioning 0x%x\n", ExtCsd->IniTimeoutAp));
146 DEBUG((DEBUG_INFO, " TRIM Multiplier 0x%x\n", ExtCsd->TrimMult));
147 DEBUG((DEBUG_INFO, " Secure Feature support 0x%x\n", ExtCsd->SecFeatureSupport));
148 DEBUG((DEBUG_INFO, " Secure Erase Multiplier 0x%x\n", ExtCsd->SecEraseMult));
149 DEBUG((DEBUG_INFO, " Secure TRIM Multiplier 0x%x\n", ExtCsd->SecTrimMult));
150 DEBUG((DEBUG_INFO, " Boot information 0x%x\n", ExtCsd->BootInfo));
151 DEBUG((DEBUG_INFO, " Boot partition size 0x%x\n", ExtCsd->BootSizeMult));
152 DEBUG((DEBUG_INFO, " Access size 0x%x\n", ExtCsd->AccSize));
153 DEBUG((DEBUG_INFO, " High-capacity erase unit size 0x%x\n", ExtCsd->HcEraseGrpSize));
154 DEBUG((DEBUG_INFO, " High-capacity erase timeout 0x%x\n", ExtCsd->EraseTimeoutMult));
155 DEBUG((DEBUG_INFO, " Reliable write sector count 0x%x\n", ExtCsd->RelWrSecC));
156 DEBUG((DEBUG_INFO, " High-capacity write protect group size 0x%x\n", ExtCsd->HcWpGrpSize));
157 DEBUG((DEBUG_INFO, " Sleep/awake timeout 0x%x\n", ExtCsd->SATimeout));
158 DEBUG((DEBUG_INFO, " Sector Count 0x%x\n", *((UINT32*)&ExtCsd->SecCount[0])));
159 DEBUG((DEBUG_INFO, " Partition switching timing 0x%x\n", ExtCsd->PartitionSwitchTime));
160 DEBUG((DEBUG_INFO, " Out-of-interrupt busy timing 0x%x\n", ExtCsd->OutOfInterruptTime));
161 DEBUG((DEBUG_INFO, " I/O Driver Strength 0x%x\n", ExtCsd->DriverStrength));
162 DEBUG((DEBUG_INFO, " Device type 0x%x\n", ExtCsd->DeviceType));
163 DEBUG((DEBUG_INFO, " CSD STRUCTURE 0x%x\n", ExtCsd->CsdStructure));
164 DEBUG((DEBUG_INFO, " Extended CSD revision 0x%x\n", ExtCsd->ExtCsdRev));
165 DEBUG((DEBUG_INFO, " Command set 0x%x\n", ExtCsd->CmdSet));
166 DEBUG((DEBUG_INFO, " Command set revision 0x%x\n", ExtCsd->CmdSetRev));
167 DEBUG((DEBUG_INFO, " Power class 0x%x\n", ExtCsd->PowerClass));
168 DEBUG((DEBUG_INFO, " High-speed interface timing 0x%x\n", ExtCsd->HsTiming));
169 DEBUG((DEBUG_INFO, " Bus width mode 0x%x\n", ExtCsd->BusWidth));
170 DEBUG((DEBUG_INFO, " Erased memory content 0x%x\n", ExtCsd->ErasedMemCont));
171 DEBUG((DEBUG_INFO, " Partition configuration 0x%x\n", ExtCsd->PartitionConfig));
172 DEBUG((DEBUG_INFO, " Boot config protection 0x%x\n", ExtCsd->BootConfigProt));
173 DEBUG((DEBUG_INFO, " Boot bus Conditions 0x%x\n", ExtCsd->BootBusConditions));
174 DEBUG((DEBUG_INFO, " High-density erase group definition 0x%x\n", ExtCsd->EraseGroupDef));
175 DEBUG((DEBUG_INFO, " Boot write protection status register 0x%x\n", ExtCsd->BootWpStatus));
176 DEBUG((DEBUG_INFO, " Boot area write protection register 0x%x\n", ExtCsd->BootWp));
177 DEBUG((DEBUG_INFO, " User area write protection register 0x%x\n", ExtCsd->UserWp));
178 DEBUG((DEBUG_INFO, " FW configuration 0x%x\n", ExtCsd->FwConfig));
179 DEBUG((DEBUG_INFO, " RPMB Size 0x%x\n", ExtCsd->RpmbSizeMult));
180 DEBUG((DEBUG_INFO, " H/W reset function 0x%x\n", ExtCsd->RstFunction));
181 DEBUG((DEBUG_INFO, " Partitioning Support 0x%x\n", ExtCsd->PartitioningSupport));
182 DEBUG((DEBUG_INFO, " Max Enhanced Area Size 0x%02x%02x%02x\n", \
183 ExtCsd->MaxEnhSizeMult[2], ExtCsd->MaxEnhSizeMult[1], ExtCsd->MaxEnhSizeMult[0]));
184 DEBUG((DEBUG_INFO, " Partitions attribute 0x%x\n", ExtCsd->PartitionsAttribute));
185 DEBUG((DEBUG_INFO, " Partitioning Setting 0x%x\n", ExtCsd->PartitionSettingCompleted));
186 DEBUG((DEBUG_INFO, " General Purpose Partition 1 Size 0x%02x%02x%02x\n", \
187 ExtCsd->GpSizeMult[2], ExtCsd->GpSizeMult[1], ExtCsd->GpSizeMult[0]));
188 DEBUG((DEBUG_INFO, " General Purpose Partition 2 Size 0x%02x%02x%02x\n", \
189 ExtCsd->GpSizeMult[5], ExtCsd->GpSizeMult[4], ExtCsd->GpSizeMult[3]));
190 DEBUG((DEBUG_INFO, " General Purpose Partition 3 Size 0x%02x%02x%02x\n", \
191 ExtCsd->GpSizeMult[8], ExtCsd->GpSizeMult[7], ExtCsd->GpSizeMult[6]));
192 DEBUG((DEBUG_INFO, " General Purpose Partition 4 Size 0x%02x%02x%02x\n", \
193 ExtCsd->GpSizeMult[11], ExtCsd->GpSizeMult[10], ExtCsd->GpSizeMult[9]));
194 DEBUG((DEBUG_INFO, " Enhanced User Data Area Size 0x%02x%02x%02x\n", \
195 ExtCsd->EnhSizeMult[2], ExtCsd->EnhSizeMult[1], ExtCsd->EnhSizeMult[0]));
196 DEBUG((DEBUG_INFO, " Enhanced User Data Start Address 0x%x\n", *((UINT32*)&ExtCsd->EnhStartAddr[0])));
197 DEBUG((DEBUG_INFO, " Bad Block Management mode 0x%x\n", ExtCsd->SecBadBlkMgmnt));
198 DEBUG((DEBUG_INFO, " Native sector size 0x%x\n", ExtCsd->NativeSectorSize));
199 DEBUG((DEBUG_INFO, " Sector size emulation 0x%x\n", ExtCsd->UseNativeSector));
200 DEBUG((DEBUG_INFO, " Sector size 0x%x\n", ExtCsd->DataSectorSize));
201
202 return EFI_SUCCESS;
203 }
204
205 /**
206 Get EMMC device model name.
207
208 @param[in, out] Device The pointer to the EMMC_DEVICE data structure.
209 @param[in] Cid Pointer to EMMC_CID data structure.
210
211 @retval EFI_SUCCESS The function completed successfully
212
213 **/
214 EFI_STATUS
215 GetEmmcModelName (
216 IN OUT EMMC_DEVICE *Device,
217 IN EMMC_CID *Cid
218 )
219 {
220 CHAR8 String[EMMC_MODEL_NAME_MAX_LEN];
221
222 ZeroMem (String, sizeof (String));
223 CopyMem (String, &Cid->OemId, sizeof (Cid->OemId));
224 String[sizeof (Cid->OemId)] = ' ';
225 CopyMem (String + sizeof (Cid->OemId) + 1, Cid->ProductName, sizeof (Cid->ProductName));
226 String[sizeof (Cid->OemId) + sizeof (Cid->ProductName)] = ' ';
227 CopyMem (String + sizeof (Cid->OemId) + sizeof (Cid->ProductName) + 1, Cid->ProductSerialNumber, sizeof (Cid->ProductSerialNumber));
228
229 AsciiStrToUnicodeStr (String, Device->ModelName);
230
231 return EFI_SUCCESS;
232 }
233
234 /**
235 Discover all partitions in the EMMC device.
236
237 @param[in] Device The pointer to the EMMC_DEVICE data structure.
238
239 @retval EFI_SUCCESS All the partitions in the device are successfully enumerated.
240 @return Others Some error occurs when enumerating the partitions.
241
242 **/
243 EFI_STATUS
244 DiscoverAllPartitions (
245 IN EMMC_DEVICE *Device
246 )
247 {
248 EFI_STATUS Status;
249 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
250 EMMC_PARTITION *Partition;
251 EMMC_CSD *Csd;
252 EMMC_CID *Cid;
253 EMMC_EXT_CSD *ExtCsd;
254 UINT8 Slot;
255 UINT64 Capacity;
256 UINT32 DevStatus;
257 UINT8 Index;
258 UINT32 SecCount;
259 UINT32 GpSizeMult;
260
261 PassThru = Device->Private->PassThru;
262 Slot = Device->Slot;
263
264 Status = EmmcSendStatus (Device, Slot + 1, &DevStatus);
265 if (EFI_ERROR (Status)) {
266 return Status;
267 }
268 //
269 // Deselect the device to force it enter stby mode before getting CSD
270 // register content.
271 // Note here we don't judge return status as some EMMC devices return
272 // error but the state has been stby.
273 //
274 EmmcSelect (Device, 0);
275
276 Status = EmmcSendStatus (Device, Slot + 1, &DevStatus);
277 if (EFI_ERROR (Status)) {
278 return Status;
279 }
280
281 Csd = &Device->Csd;
282 Status = EmmcGetCsd (Device, Slot + 1, Csd);
283 if (EFI_ERROR (Status)) {
284 return Status;
285 }
286 DumpCsd (Csd);
287
288 if ((Csd->CSizeLow | Csd->CSizeHigh << 2) == 0xFFF) {
289 Device->SectorAddressing = TRUE;
290 } else {
291 Device->SectorAddressing = FALSE;
292 }
293
294 Cid = &Device->Cid;
295 Status = EmmcGetCid (Device, Slot + 1, Cid);
296 if (EFI_ERROR (Status)) {
297 return Status;
298 }
299
300 Status = EmmcSelect (Device, Slot + 1);
301 if (EFI_ERROR (Status)) {
302 return Status;
303 }
304
305 ExtCsd = &Device->ExtCsd;
306 Status = EmmcGetExtCsd (Device, ExtCsd);
307 if (EFI_ERROR (Status)) {
308 return Status;
309 }
310 DumpExtCsd (ExtCsd);
311
312 if (ExtCsd->ExtCsdRev < 5) {
313 DEBUG ((EFI_D_ERROR, "The EMMC device version is too low, we don't support!!!\n"));
314 return EFI_UNSUPPORTED;
315 }
316
317 if ((ExtCsd->PartitioningSupport & BIT0) != BIT0) {
318 DEBUG ((EFI_D_ERROR, "The EMMC device doesn't support Partition Feature!!!\n"));
319 return EFI_UNSUPPORTED;
320 }
321
322 for (Index = 0; Index < EMMC_MAX_PARTITIONS; Index++) {
323 Partition = &Device->Partition[Index];
324 CopyMem (Partition, &mEmmcPartitionTemplate, sizeof (EMMC_PARTITION));
325 Partition->Device = Device;
326 InitializeListHead (&Partition->Queue);
327 Partition->BlockIo.Media = &Partition->BlockMedia;
328 Partition->BlockIo2.Media = &Partition->BlockMedia;
329 Partition->PartitionType = Index;
330 Partition->BlockMedia.IoAlign = Device->Private->PassThru->IoAlign;
331 Partition->BlockMedia.BlockSize = 0x200;
332 Partition->BlockMedia.LastBlock = 0x00;
333 Partition->BlockMedia.RemovableMedia = FALSE;
334 Partition->BlockMedia.MediaPresent = TRUE;
335 Partition->BlockMedia.LogicalPartition = FALSE;
336
337 switch (Index) {
338 case EmmcPartitionUserData:
339 SecCount = *(UINT32*)&ExtCsd->SecCount;
340 Capacity = MultU64x32 ((UINT64) SecCount, 0x200);
341 break;
342 case EmmcPartitionBoot1:
343 case EmmcPartitionBoot2:
344 Capacity = ExtCsd->BootSizeMult * SIZE_128KB;
345 break;
346 case EmmcPartitionRPMB:
347 Capacity = ExtCsd->RpmbSizeMult * SIZE_128KB;
348 break;
349 case EmmcPartitionGP1:
350 GpSizeMult = (UINT32)(ExtCsd->GpSizeMult[0] | (ExtCsd->GpSizeMult[1] << 8) | (ExtCsd->GpSizeMult[2] << 16));
351 Capacity = MultU64x32 (MultU64x32 (MultU64x32 ((UINT64)GpSizeMult, ExtCsd->HcWpGrpSize), ExtCsd->HcEraseGrpSize), SIZE_512KB);
352 break;
353 case EmmcPartitionGP2:
354 GpSizeMult = (UINT32)(ExtCsd->GpSizeMult[3] | (ExtCsd->GpSizeMult[4] << 8) | (ExtCsd->GpSizeMult[5] << 16));
355 Capacity = MultU64x32 (MultU64x32 (MultU64x32 ((UINT64)GpSizeMult, ExtCsd->HcWpGrpSize), ExtCsd->HcEraseGrpSize), SIZE_512KB);
356 break;
357 case EmmcPartitionGP3:
358 GpSizeMult = (UINT32)(ExtCsd->GpSizeMult[6] | (ExtCsd->GpSizeMult[7] << 8) | (ExtCsd->GpSizeMult[8] << 16));
359 Capacity = MultU64x32 (MultU64x32 (MultU64x32 ((UINT64)GpSizeMult, ExtCsd->HcWpGrpSize), ExtCsd->HcEraseGrpSize), SIZE_512KB);
360 break;
361 case EmmcPartitionGP4:
362 GpSizeMult = (UINT32)(ExtCsd->GpSizeMult[9] | (ExtCsd->GpSizeMult[10] << 8) | (ExtCsd->GpSizeMult[11] << 16));
363 Capacity = MultU64x32 (MultU64x32 (MultU64x32 ((UINT64)GpSizeMult, ExtCsd->HcWpGrpSize), ExtCsd->HcEraseGrpSize), SIZE_512KB);
364 break;
365 default:
366 ASSERT (FALSE);
367 return EFI_INVALID_PARAMETER;
368 }
369
370 if (Capacity != 0) {
371 Partition->Enable = TRUE;
372 Partition->BlockMedia.LastBlock = DivU64x32 (Capacity, Partition->BlockMedia.BlockSize) - 1;
373 }
374 }
375
376 return EFI_SUCCESS;
377 }
378
379 /**
380 Install BlkIo, BlkIo2 and Ssp protocols for the specified partition in the EMMC device.
381
382 @param[in] Device The pointer to the EMMC_DEVICE data structure.
383 @param[in] Index The index of the partition.
384
385 @retval EFI_SUCCESS The protocols are installed successfully.
386 @retval Others Some error occurs when installing the protocols.
387
388 **/
389 EFI_STATUS
390 InstallProtocolOnPartition (
391 IN EMMC_DEVICE *Device,
392 IN UINT8 Index
393 )
394 {
395 EFI_STATUS Status;
396 EMMC_PARTITION *Partition;
397 CONTROLLER_DEVICE_PATH ControlNode;
398 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
399 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
400 EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
401 EFI_HANDLE DeviceHandle;
402
403 //
404 // Build device path
405 //
406 ParentDevicePath = Device->DevicePath;
407
408 ControlNode.Header.Type = HARDWARE_DEVICE_PATH;
409 ControlNode.Header.SubType = HW_CONTROLLER_DP;
410 SetDevicePathNodeLength (&ControlNode.Header, sizeof (CONTROLLER_DEVICE_PATH));
411 ControlNode.ControllerNumber = Index;
412
413 DevicePath = AppendDevicePathNode (ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*)&ControlNode);
414 if (DevicePath == NULL) {
415 Status = EFI_OUT_OF_RESOURCES;
416 goto Error;
417 }
418
419 DeviceHandle = NULL;
420 RemainingDevicePath = DevicePath;
421 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &DeviceHandle);
422 if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd(RemainingDevicePath)) {
423 Status = EFI_ALREADY_STARTED;
424 goto Error;
425 }
426
427 Partition = &Device->Partition[Index];
428 Partition->DevicePath = DevicePath;
429 if (Partition->Enable) {
430 //
431 // Install BlkIo/BlkIo2/Ssp for the specified partition
432 //
433 Status = gBS->InstallMultipleProtocolInterfaces (
434 &Partition->Handle,
435 &gEfiDevicePathProtocolGuid,
436 Partition->DevicePath,
437 &gEfiBlockIoProtocolGuid,
438 &Partition->BlockIo,
439 &gEfiBlockIo2ProtocolGuid,
440 &Partition->BlockIo2,
441 NULL
442 );
443 if (EFI_ERROR (Status)) {
444 goto Error;
445 }
446
447 if (((Partition->PartitionType == EmmcPartitionUserData) ||
448 (Partition->PartitionType == EmmcPartitionBoot1) ||
449 (Partition->PartitionType == EmmcPartitionBoot2)) &&
450 ((Device->Csd.Ccc & BIT10) != 0)) {
451 Status = gBS->InstallProtocolInterface (
452 &Partition->Handle,
453 &gEfiStorageSecurityCommandProtocolGuid,
454 EFI_NATIVE_INTERFACE,
455 &Partition->StorageSecurity
456 );
457 if (EFI_ERROR (Status)) {
458 gBS->UninstallMultipleProtocolInterfaces (
459 &Partition->Handle,
460 &gEfiDevicePathProtocolGuid,
461 Partition->DevicePath,
462 &gEfiBlockIoProtocolGuid,
463 &Partition->BlockIo,
464 &gEfiBlockIo2ProtocolGuid,
465 &Partition->BlockIo2,
466 NULL
467 );
468 goto Error;
469 }
470 }
471
472 gBS->OpenProtocol (
473 Device->Private->Controller,
474 &gEfiSdMmcPassThruProtocolGuid,
475 (VOID **) &(Device->Private->PassThru),
476 Device->Private->DriverBindingHandle,
477 Partition->Handle,
478 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
479 );
480 } else {
481 Status = EFI_INVALID_PARAMETER;
482 }
483
484 Error:
485 if (EFI_ERROR (Status) && (DevicePath != NULL)) {
486 FreePool (DevicePath);
487 }
488
489 return Status;
490 }
491
492 /**
493 Scan EMMC Bus to discover the device.
494
495 @param[in] Private The EMMC driver private data structure.
496 @param[in] Slot The slot number to check device present.
497
498 @retval EFI_SUCCESS Successfully to discover the device and attach
499 SdMmcIoProtocol to it.
500 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
501 of resources.
502 @retval EFI_ALREADY_STARTED The device was discovered before.
503 @retval Others Fail to discover the device.
504
505 **/
506 EFI_STATUS
507 EFIAPI
508 DiscoverEmmcDevice (
509 IN EMMC_DRIVER_PRIVATE_DATA *Private,
510 IN UINT8 Slot,
511 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
512 )
513 {
514 EFI_STATUS Status;
515 EMMC_DEVICE *Device;
516 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
517 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
518 EFI_DEVICE_PATH_PROTOCOL *RemainingEmmcDevPath;
519 EFI_DEV_PATH *Node;
520 EFI_HANDLE DeviceHandle;
521 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
522 UINT8 Index;
523
524 Device = NULL;
525 DevicePath = NULL;
526 NewDevicePath = NULL;
527 RemainingDevicePath = NULL;
528 PassThru = Private->PassThru;
529 Device = &Private->Device[Slot];
530
531 //
532 // Build Device Path to check if the EMMC device present at the slot.
533 //
534 Status = PassThru->BuildDevicePath (
535 PassThru,
536 Slot,
537 &DevicePath
538 );
539 if (EFI_ERROR(Status)) {
540 return Status;
541 }
542
543 if (DevicePath->SubType != MSG_EMMC_DP) {
544 Status = EFI_UNSUPPORTED;
545 goto Error;
546 }
547
548 NewDevicePath = AppendDevicePathNode (
549 Private->ParentDevicePath,
550 DevicePath
551 );
552 if (NewDevicePath == NULL) {
553 Status = EFI_OUT_OF_RESOURCES;
554 goto Error;
555 }
556
557 DeviceHandle = NULL;
558 RemainingEmmcDevPath = NewDevicePath;
559 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingEmmcDevPath, &DeviceHandle);
560 //
561 // The device path to the EMMC device doesn't exist. It means the corresponding device private data hasn't been initialized.
562 //
563 if (EFI_ERROR (Status) || (DeviceHandle == NULL) || !IsDevicePathEnd (RemainingEmmcDevPath)) {
564 Device->DevicePath = NewDevicePath;
565 Device->Slot = Slot;
566 Device->Private = Private;
567 //
568 // Expose user area in the Sd memory card to upper layer.
569 //
570 Status = DiscoverAllPartitions (Device);
571 if (EFI_ERROR(Status)) {
572 FreePool (NewDevicePath);
573 goto Error;
574 }
575
576 Status = gBS->InstallProtocolInterface (
577 &Device->Handle,
578 &gEfiDevicePathProtocolGuid,
579 EFI_NATIVE_INTERFACE,
580 Device->DevicePath
581 );
582 if (EFI_ERROR(Status)) {
583 FreePool (NewDevicePath);
584 goto Error;
585 }
586
587 Device->ControllerNameTable = NULL;
588 GetEmmcModelName (Device, &Device->Cid);
589 AddUnicodeString2 (
590 "eng",
591 gEmmcDxeComponentName.SupportedLanguages,
592 &Device->ControllerNameTable,
593 Device->ModelName,
594 TRUE
595 );
596 AddUnicodeString2 (
597 "en",
598 gEmmcDxeComponentName.SupportedLanguages,
599 &Device->ControllerNameTable,
600 Device->ModelName,
601 FALSE
602 );
603 }
604
605 if (RemainingDevicePath == NULL) {
606 //
607 // Expose all partitions in the Emmc device to upper layer.
608 //
609 for (Index = 0; Index < EMMC_MAX_PARTITIONS; Index++) {
610 InstallProtocolOnPartition (Device, Index);
611 }
612 } else if (!IsDevicePathEnd (RemainingDevicePath)) {
613 //
614 // Enumerate the specified partition
615 //
616 Node = (EFI_DEV_PATH *) RemainingDevicePath;
617 if ((DevicePathType (&Node->DevPath) != HARDWARE_DEVICE_PATH) ||
618 (DevicePathSubType (&Node->DevPath) != HW_CONTROLLER_DP) ||
619 (DevicePathNodeLength (&Node->DevPath) != sizeof (CONTROLLER_DEVICE_PATH))) {
620 Status = EFI_INVALID_PARAMETER;
621 goto Error;
622 }
623
624 Index = (UINT8)Node->Controller.ControllerNumber;
625 if (Index >= EMMC_MAX_PARTITIONS) {
626 Status = EFI_INVALID_PARAMETER;
627 goto Error;
628 }
629
630 Status = InstallProtocolOnPartition (Device, Index);
631 }
632
633 Error:
634 FreePool (DevicePath);
635
636 return Status;
637 }
638
639 /**
640 Tests to see if this driver supports a given controller. If a child device is provided,
641 it further tests to see if this driver supports creating a handle for the specified child device.
642
643 This function checks to see if the driver specified by This supports the device specified by
644 ControllerHandle. Drivers will typically use the device path attached to
645 ControllerHandle and/or the services from the bus I/O abstraction attached to
646 ControllerHandle to determine if the driver supports ControllerHandle. This function
647 may be called many times during platform initialization. In order to reduce boot times, the tests
648 performed by this function must be very small, and take as little time as possible to execute. This
649 function must not change the state of any hardware devices, and this function must be aware that the
650 device specified by ControllerHandle may already be managed by the same driver or a
651 different driver. This function must match its calls to AllocatePages() with FreePages(),
652 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
653 Since ControllerHandle may have been previously started by the same driver, if a protocol is
654 already in the opened state, then it must not be closed with CloseProtocol(). This is required
655 to guarantee the state of ControllerHandle is not modified by this function.
656
657 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
658 @param[in] ControllerHandle The handle of the controller to test. This handle
659 must support a protocol interface that supplies
660 an I/O abstraction to the driver.
661 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
662 parameter is ignored by device drivers, and is optional for bus
663 drivers. For bus drivers, if this parameter is not NULL, then
664 the bus driver must determine if the bus controller specified
665 by ControllerHandle and the child controller specified
666 by RemainingDevicePath are both supported by this
667 bus driver.
668
669 @retval EFI_SUCCESS The device specified by ControllerHandle and
670 RemainingDevicePath is supported by the driver specified by This.
671 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
672 RemainingDevicePath is already being managed by the driver
673 specified by This.
674 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
675 RemainingDevicePath is already being managed by a different
676 driver or an application that requires exclusive access.
677 Currently not implemented.
678 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
679 RemainingDevicePath is not supported by the driver specified by This.
680 **/
681 EFI_STATUS
682 EFIAPI
683 EmmcDxeDriverBindingSupported (
684 IN EFI_DRIVER_BINDING_PROTOCOL *This,
685 IN EFI_HANDLE Controller,
686 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
687 )
688 {
689 EFI_STATUS Status;
690 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
691 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
692 UINT8 Slot;
693
694 //
695 // Test EFI_SD_MMC_PASS_THRU_PROTOCOL on the controller handle.
696 //
697 Status = gBS->OpenProtocol (
698 Controller,
699 &gEfiSdMmcPassThruProtocolGuid,
700 (VOID**) &PassThru,
701 This->DriverBindingHandle,
702 Controller,
703 EFI_OPEN_PROTOCOL_BY_DRIVER
704 );
705
706 if (Status == EFI_ALREADY_STARTED) {
707 return EFI_SUCCESS;
708 }
709
710 if (EFI_ERROR (Status)) {
711 return Status;
712 }
713
714 //
715 // Test RemainingDevicePath is valid or not.
716 //
717 if ((RemainingDevicePath != NULL) && !IsDevicePathEnd (RemainingDevicePath)) {
718 Status = PassThru->GetSlotNumber (PassThru, RemainingDevicePath, &Slot);
719 if (EFI_ERROR (Status)) {
720 //
721 // Close the I/O Abstraction(s) used to perform the supported test
722 //
723 gBS->CloseProtocol (
724 Controller,
725 &gEfiSdMmcPassThruProtocolGuid,
726 This->DriverBindingHandle,
727 Controller
728 );
729 return Status;
730 }
731 }
732
733 //
734 // Close the I/O Abstraction(s) used to perform the supported test
735 //
736 gBS->CloseProtocol (
737 Controller,
738 &gEfiSdMmcPassThruProtocolGuid,
739 This->DriverBindingHandle,
740 Controller
741 );
742
743 //
744 // Open the EFI Device Path protocol needed to perform the supported test
745 //
746 Status = gBS->OpenProtocol (
747 Controller,
748 &gEfiDevicePathProtocolGuid,
749 (VOID **) &ParentDevicePath,
750 This->DriverBindingHandle,
751 Controller,
752 EFI_OPEN_PROTOCOL_GET_PROTOCOL
753 );
754 return Status;
755 }
756
757 /**
758 Starts a device controller or a bus controller.
759
760 The Start() function is designed to be invoked from the EFI boot service ConnectController().
761 As a result, much of the error checking on the parameters to Start() has been moved into this
762 common boot service. It is legal to call Start() from other locations,
763 but the following calling restrictions must be followed or the system behavior will not be deterministic.
764 1. ControllerHandle must be a valid EFI_HANDLE.
765 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
766 EFI_DEVICE_PATH_PROTOCOL.
767 3. Prior to calling Start(), the Supported() function for the driver specified by This must
768 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
769
770 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
771 @param[in] ControllerHandle The handle of the controller to start. This handle
772 must support a protocol interface that supplies
773 an I/O abstraction to the driver.
774 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
775 parameter is ignored by device drivers, and is optional for bus
776 drivers. For a bus driver, if this parameter is NULL, then handles
777 for all the children of Controller are created by this driver.
778 If this parameter is not NULL and the first Device Path Node is
779 not the End of Device Path Node, then only the handle for the
780 child device specified by the first Device Path Node of
781 RemainingDevicePath is created by this driver.
782 If the first Device Path Node of RemainingDevicePath is
783 the End of Device Path Node, no child handle is created by this
784 driver.
785
786 @retval EFI_SUCCESS The device was started.
787 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
788 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
789 @retval Others The driver failded to start the device.
790
791 **/
792 EFI_STATUS
793 EFIAPI
794 EmmcDxeDriverBindingStart (
795 IN EFI_DRIVER_BINDING_PROTOCOL *This,
796 IN EFI_HANDLE Controller,
797 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
798 )
799 {
800 EFI_STATUS Status;
801 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
802 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
803 EMMC_DRIVER_PRIVATE_DATA *Private;
804 UINT8 Slot;
805
806 Private = NULL;
807 PassThru = NULL;
808 Status = gBS->OpenProtocol (
809 Controller,
810 &gEfiSdMmcPassThruProtocolGuid,
811 (VOID **) &PassThru,
812 This->DriverBindingHandle,
813 Controller,
814 EFI_OPEN_PROTOCOL_BY_DRIVER
815 );
816 if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {
817 return Status;
818 }
819
820 //
821 // Check EFI_ALREADY_STARTED to reuse the original EMMC_DRIVER_PRIVATE_DATA.
822 //
823 if (Status != EFI_ALREADY_STARTED) {
824 Private = AllocateZeroPool (sizeof (EMMC_DRIVER_PRIVATE_DATA));
825 if (Private == NULL) {
826 Status = EFI_OUT_OF_RESOURCES;
827 goto Error;
828 }
829
830 Status = gBS->OpenProtocol (
831 Controller,
832 &gEfiDevicePathProtocolGuid,
833 (VOID **) &ParentDevicePath,
834 This->DriverBindingHandle,
835 Controller,
836 EFI_OPEN_PROTOCOL_GET_PROTOCOL
837 );
838 ASSERT_EFI_ERROR (Status);
839 Private->PassThru = PassThru;
840 Private->Controller = Controller;
841 Private->ParentDevicePath = ParentDevicePath;
842 Private->DriverBindingHandle = This->DriverBindingHandle;
843
844 Status = gBS->InstallProtocolInterface (
845 &Controller,
846 &gEfiCallerIdGuid,
847 EFI_NATIVE_INTERFACE,
848 Private
849 );
850 if (EFI_ERROR (Status)) {
851 goto Error;
852 }
853 } else {
854 Status = gBS->OpenProtocol (
855 Controller,
856 &gEfiCallerIdGuid,
857 (VOID **) &Private,
858 This->DriverBindingHandle,
859 Controller,
860 EFI_OPEN_PROTOCOL_GET_PROTOCOL
861 );
862 if (EFI_ERROR (Status)) {
863 goto Error;
864 }
865 }
866
867 if (RemainingDevicePath == NULL) {
868 Slot = 0xFF;
869 while (TRUE) {
870 Status = PassThru->GetNextSlot (PassThru, &Slot);
871 if (EFI_ERROR (Status)) {
872 //
873 // Cannot find more legal slots.
874 //
875 Status = EFI_SUCCESS;
876 break;
877 }
878
879 Status = DiscoverEmmcDevice (Private, Slot, NULL);
880 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
881 break;
882 }
883 }
884 } else if (!IsDevicePathEnd (RemainingDevicePath)) {
885 Status = PassThru->GetSlotNumber (PassThru, RemainingDevicePath, &Slot);
886 if (!EFI_ERROR (Status)) {
887 Status = DiscoverEmmcDevice (Private, Slot, NextDevicePathNode (RemainingDevicePath));
888 }
889 }
890
891 Error:
892 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
893 gBS->CloseProtocol (
894 Controller,
895 &gEfiSdMmcPassThruProtocolGuid,
896 This->DriverBindingHandle,
897 Controller
898 );
899
900 if (Private != NULL) {
901 gBS->UninstallMultipleProtocolInterfaces (
902 Controller,
903 &gEfiCallerIdGuid,
904 Private,
905 NULL
906 );
907 FreePool (Private);
908 }
909 }
910 return Status;
911 }
912
913 /**
914 Stops a device controller or a bus controller.
915
916 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
917 As a result, much of the error checking on the parameters to Stop() has been moved
918 into this common boot service. It is legal to call Stop() from other locations,
919 but the following calling restrictions must be followed or the system behavior will not be deterministic.
920 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
921 same driver's Start() function.
922 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
923 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
924 Start() function, and the Start() function must have called OpenProtocol() on
925 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
926
927 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
928 @param[in] ControllerHandle A handle to the device being stopped. The handle must
929 support a bus specific I/O protocol for the driver
930 to use to stop the device.
931 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
932 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
933 if NumberOfChildren is 0.
934
935 @retval EFI_SUCCESS The device was stopped.
936 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
937
938 **/
939 EFI_STATUS
940 EFIAPI
941 EmmcDxeDriverBindingStop (
942 IN EFI_DRIVER_BINDING_PROTOCOL *This,
943 IN EFI_HANDLE Controller,
944 IN UINTN NumberOfChildren,
945 IN EFI_HANDLE *ChildHandleBuffer
946 )
947 {
948 EFI_STATUS Status;
949 BOOLEAN AllChildrenStopped;
950 UINTN Index;
951 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
952 EMMC_DRIVER_PRIVATE_DATA *Private;
953 EMMC_DEVICE *Device;
954 EMMC_PARTITION *Partition;
955 EFI_BLOCK_IO_PROTOCOL *BlockIo;
956 EFI_BLOCK_IO2_PROTOCOL *BlockIo2;
957 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *StorageSecurity;
958 LIST_ENTRY *Link;
959 LIST_ENTRY *NextLink;
960 EMMC_REQUEST *Request;
961
962 BlockIo = NULL;
963 BlockIo2 = NULL;
964 if (NumberOfChildren == 0) {
965 Status = gBS->OpenProtocol (
966 Controller,
967 &gEfiCallerIdGuid,
968 (VOID **) &Private,
969 This->DriverBindingHandle,
970 Controller,
971 EFI_OPEN_PROTOCOL_GET_PROTOCOL
972 );
973 if (EFI_ERROR (Status)) {
974 return EFI_DEVICE_ERROR;
975 }
976
977 for (Index = 0; Index < EMMC_MAX_DEVICES; Index++) {
978 Device = &Private->Device[Index];
979 Status = gBS->OpenProtocol (
980 Device->Handle,
981 &gEfiDevicePathProtocolGuid,
982 (VOID **) &DevicePath,
983 This->DriverBindingHandle,
984 Controller,
985 EFI_OPEN_PROTOCOL_GET_PROTOCOL
986 );
987 if (EFI_ERROR (Status)) {
988 continue;
989 }
990 ASSERT (DevicePath == Device->DevicePath);
991 gBS->UninstallProtocolInterface (
992 Device->Handle,
993 &gEfiDevicePathProtocolGuid,
994 DevicePath
995 );
996 FreePool (Device->DevicePath);
997 }
998
999 gBS->UninstallProtocolInterface (
1000 Controller,
1001 &gEfiCallerIdGuid,
1002 Private
1003 );
1004 gBS->CloseProtocol (
1005 Controller,
1006 &gEfiSdMmcPassThruProtocolGuid,
1007 This->DriverBindingHandle,
1008 Controller
1009 );
1010 FreePool (Private);
1011
1012 return EFI_SUCCESS;
1013 }
1014
1015 AllChildrenStopped = TRUE;
1016
1017 for (Index = 0; Index < NumberOfChildren; Index++) {
1018 Status = gBS->OpenProtocol (
1019 ChildHandleBuffer[Index],
1020 &gEfiBlockIoProtocolGuid,
1021 (VOID **) &BlockIo,
1022 This->DriverBindingHandle,
1023 Controller,
1024 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1025 );
1026 if (EFI_ERROR (Status)) {
1027 Status = gBS->OpenProtocol (
1028 ChildHandleBuffer[Index],
1029 &gEfiBlockIo2ProtocolGuid,
1030 (VOID **) &BlockIo2,
1031 This->DriverBindingHandle,
1032 Controller,
1033 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1034 );
1035 if (EFI_ERROR (Status)) {
1036 AllChildrenStopped = FALSE;
1037 continue;
1038 }
1039 }
1040
1041 if (BlockIo != NULL) {
1042 Partition = EMMC_PARTITION_DATA_FROM_BLKIO (BlockIo);
1043 } else {
1044 ASSERT (BlockIo2 != NULL);
1045 Partition = EMMC_PARTITION_DATA_FROM_BLKIO2 (BlockIo2);
1046 }
1047
1048 for (Link = GetFirstNode (&Partition->Queue);
1049 !IsNull (&Partition->Queue, Link);
1050 Link = NextLink) {
1051 NextLink = GetNextNode (&Partition->Queue, Link);
1052
1053 RemoveEntryList (Link);
1054 Request = EMMC_REQUEST_FROM_LINK (Link);
1055
1056 gBS->CloseEvent (Request->Event);
1057 Request->Token->TransactionStatus = EFI_ABORTED;
1058
1059 if (Request->IsEnd) {
1060 gBS->SignalEvent (Request->Token->Event);
1061 }
1062
1063 FreePool (Request);
1064 }
1065
1066 //
1067 // Close the child handle
1068 //
1069 Status = gBS->CloseProtocol (
1070 Controller,
1071 &gEfiSdMmcPassThruProtocolGuid,
1072 This->DriverBindingHandle,
1073 ChildHandleBuffer[Index]
1074 );
1075
1076 Status = gBS->UninstallMultipleProtocolInterfaces (
1077 ChildHandleBuffer[Index],
1078 &gEfiDevicePathProtocolGuid,
1079 Partition->DevicePath,
1080 &gEfiBlockIoProtocolGuid,
1081 &Partition->BlockIo,
1082 &gEfiBlockIo2ProtocolGuid,
1083 &Partition->BlockIo2,
1084 NULL
1085 );
1086 if (EFI_ERROR (Status)) {
1087 AllChildrenStopped = FALSE;
1088 gBS->OpenProtocol (
1089 Controller,
1090 &gEfiSdMmcPassThruProtocolGuid,
1091 (VOID **)&Partition->Device->Private->PassThru,
1092 This->DriverBindingHandle,
1093 ChildHandleBuffer[Index],
1094 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1095 );
1096 continue;
1097 }
1098
1099 //
1100 // If Storage Security Command Protocol is installed, then uninstall this protocol.
1101 //
1102 Status = gBS->OpenProtocol (
1103 ChildHandleBuffer[Index],
1104 &gEfiStorageSecurityCommandProtocolGuid,
1105 (VOID **) &StorageSecurity,
1106 This->DriverBindingHandle,
1107 Controller,
1108 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1109 );
1110
1111 if (!EFI_ERROR (Status)) {
1112 Status = gBS->UninstallProtocolInterface (
1113 ChildHandleBuffer[Index],
1114 &gEfiStorageSecurityCommandProtocolGuid,
1115 &Partition->StorageSecurity
1116 );
1117 if (EFI_ERROR (Status)) {
1118 gBS->OpenProtocol (
1119 Controller,
1120 &gEfiSdMmcPassThruProtocolGuid,
1121 (VOID **) &Partition->Device->Private->PassThru,
1122 This->DriverBindingHandle,
1123 ChildHandleBuffer[Index],
1124 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1125 );
1126 AllChildrenStopped = FALSE;
1127 continue;
1128 }
1129 }
1130
1131 FreePool (Partition->DevicePath);
1132 }
1133
1134 if (!AllChildrenStopped) {
1135 return EFI_DEVICE_ERROR;
1136 }
1137
1138 return EFI_SUCCESS;
1139 }
1140
1141 /**
1142 The user Entry Point for module EmmcDxe. The user code starts with this function.
1143
1144 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1145 @param[in] SystemTable A pointer to the EFI System Table.
1146
1147 @retval EFI_SUCCESS The entry point is executed successfully.
1148 @retval other Some errors occur when executing this entry point.
1149
1150 **/
1151 EFI_STATUS
1152 EFIAPI
1153 InitializeEmmcDxe (
1154 IN EFI_HANDLE ImageHandle,
1155 IN EFI_SYSTEM_TABLE *SystemTable
1156 )
1157 {
1158 EFI_STATUS Status;
1159
1160 //
1161 // Install driver model protocol(s).
1162 //
1163 Status = EfiLibInstallDriverBindingComponentName2 (
1164 ImageHandle,
1165 SystemTable,
1166 &gEmmcDxeDriverBinding,
1167 ImageHandle,
1168 &gEmmcDxeComponentName,
1169 &gEmmcDxeComponentName2
1170 );
1171 ASSERT_EFI_ERROR (Status);
1172
1173 return Status;
1174 }
1175