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