]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
Set the BlockIo.Media.IoAlign to 0 because the BlockIo produced by Partition driver...
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Partition.c
1 /** @file
2 Partition driver that produces logical BlockIo devices from a physical
3 BlockIo device. The logical BlockIo devices are based on the format
4 of the raw block devices media. Currently "El Torito CD-ROM", Legacy
5 MBR, and GPT partition schemes are supported.
6
7 Copyright (c) 2006 - 2011, 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
19 #include "Partition.h"
20
21 //
22 // Partition Driver Global Variables.
23 //
24 EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {
25 PartitionDriverBindingSupported,
26 PartitionDriverBindingStart,
27 PartitionDriverBindingStop,
28 0xa,
29 NULL,
30 NULL
31 };
32
33 //
34 // Prioritized function list to detect partition table.
35 //
36 PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {
37 PartitionInstallGptChildHandles,
38 PartitionInstallElToritoChildHandles,
39 PartitionInstallMbrChildHandles,
40 NULL
41 };
42
43
44
45 /**
46 Test to see if this driver supports ControllerHandle. Any ControllerHandle
47 than contains a BlockIo and DiskIo protocol can be supported.
48
49 @param This Protocol instance pointer.
50 @param ControllerHandle Handle of device to test
51 @param RemainingDevicePath Optional parameter use to pick a specific child
52 device to start.
53
54 @retval EFI_SUCCESS This driver supports this device
55 @retval EFI_ALREADY_STARTED This driver is already running on this device
56 @retval other This driver does not support this device
57
58 **/
59 EFI_STATUS
60 EFIAPI
61 PartitionDriverBindingSupported (
62 IN EFI_DRIVER_BINDING_PROTOCOL *This,
63 IN EFI_HANDLE ControllerHandle,
64 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
65 )
66 {
67 EFI_STATUS Status;
68 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
69 EFI_DISK_IO_PROTOCOL *DiskIo;
70 EFI_DEV_PATH *Node;
71
72 //
73 // Check RemainingDevicePath validation
74 //
75 if (RemainingDevicePath != NULL) {
76 //
77 // Check if RemainingDevicePath is the End of Device Path Node,
78 // if yes, go on checking other conditions
79 //
80 if (!IsDevicePathEnd (RemainingDevicePath)) {
81 //
82 // If RemainingDevicePath isn't the End of Device Path Node,
83 // check its validation
84 //
85 Node = (EFI_DEV_PATH *) RemainingDevicePath;
86 if (Node->DevPath.Type != MEDIA_DEVICE_PATH ||
87 Node->DevPath.SubType != MEDIA_HARDDRIVE_DP ||
88 DevicePathNodeLength (&Node->DevPath) != sizeof (HARDDRIVE_DEVICE_PATH)) {
89 return EFI_UNSUPPORTED;
90 }
91 }
92 }
93
94 //
95 // Open the IO Abstraction(s) needed to perform the supported test
96 //
97 Status = gBS->OpenProtocol (
98 ControllerHandle,
99 &gEfiDiskIoProtocolGuid,
100 (VOID **) &DiskIo,
101 This->DriverBindingHandle,
102 ControllerHandle,
103 EFI_OPEN_PROTOCOL_BY_DRIVER
104 );
105 if (Status == EFI_ALREADY_STARTED) {
106 return EFI_SUCCESS;
107 }
108
109 if (EFI_ERROR (Status)) {
110 return Status;
111 }
112 //
113 // Close the I/O Abstraction(s) used to perform the supported test
114 //
115 gBS->CloseProtocol (
116 ControllerHandle,
117 &gEfiDiskIoProtocolGuid,
118 This->DriverBindingHandle,
119 ControllerHandle
120 );
121
122 //
123 // Open the EFI Device Path protocol needed to perform the supported test
124 //
125 Status = gBS->OpenProtocol (
126 ControllerHandle,
127 &gEfiDevicePathProtocolGuid,
128 (VOID **) &ParentDevicePath,
129 This->DriverBindingHandle,
130 ControllerHandle,
131 EFI_OPEN_PROTOCOL_BY_DRIVER
132 );
133 if (Status == EFI_ALREADY_STARTED) {
134 return EFI_SUCCESS;
135 }
136
137 if (EFI_ERROR (Status)) {
138 return Status;
139 }
140
141 //
142 // Close protocol, don't use device path protocol in the Support() function
143 //
144 gBS->CloseProtocol (
145 ControllerHandle,
146 &gEfiDevicePathProtocolGuid,
147 This->DriverBindingHandle,
148 ControllerHandle
149 );
150
151 //
152 // Open the IO Abstraction(s) needed to perform the supported test
153 //
154 Status = gBS->OpenProtocol (
155 ControllerHandle,
156 &gEfiBlockIoProtocolGuid,
157 NULL,
158 This->DriverBindingHandle,
159 ControllerHandle,
160 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
161 );
162
163 return Status;
164 }
165
166
167 /**
168 Start this driver on ControllerHandle by opening a Block IO and Disk IO
169 protocol, reading Device Path, and creating a child handle with a
170 Disk IO and device path protocol.
171
172 @param This Protocol instance pointer.
173 @param ControllerHandle Handle of device to bind driver to
174 @param RemainingDevicePath Optional parameter use to pick a specific child
175 device to start.
176
177 @retval EFI_SUCCESS This driver is added to ControllerHandle
178 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
179 @retval other This driver does not support this device
180
181 **/
182 EFI_STATUS
183 EFIAPI
184 PartitionDriverBindingStart (
185 IN EFI_DRIVER_BINDING_PROTOCOL *This,
186 IN EFI_HANDLE ControllerHandle,
187 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
188 )
189 {
190 EFI_STATUS Status;
191 EFI_STATUS OpenStatus;
192 EFI_BLOCK_IO_PROTOCOL *BlockIo;
193 EFI_DISK_IO_PROTOCOL *DiskIo;
194 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
195 PARTITION_DETECT_ROUTINE *Routine;
196 BOOLEAN MediaPresent;
197 EFI_TPL OldTpl;
198
199 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
200 //
201 // Check RemainingDevicePath validation
202 //
203 if (RemainingDevicePath != NULL) {
204 //
205 // Check if RemainingDevicePath is the End of Device Path Node,
206 // if yes, return EFI_SUCCESS
207 //
208 if (IsDevicePathEnd (RemainingDevicePath)) {
209 Status = EFI_SUCCESS;
210 goto Exit;
211 }
212 }
213
214 Status = gBS->OpenProtocol (
215 ControllerHandle,
216 &gEfiBlockIoProtocolGuid,
217 (VOID **) &BlockIo,
218 This->DriverBindingHandle,
219 ControllerHandle,
220 EFI_OPEN_PROTOCOL_GET_PROTOCOL
221 );
222 if (EFI_ERROR (Status)) {
223 goto Exit;
224 }
225 //
226 // Get the Device Path Protocol on ControllerHandle's handle
227 //
228 Status = gBS->OpenProtocol (
229 ControllerHandle,
230 &gEfiDevicePathProtocolGuid,
231 (VOID **) &ParentDevicePath,
232 This->DriverBindingHandle,
233 ControllerHandle,
234 EFI_OPEN_PROTOCOL_BY_DRIVER
235 );
236 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
237 goto Exit;
238 }
239
240 Status = gBS->OpenProtocol (
241 ControllerHandle,
242 &gEfiDiskIoProtocolGuid,
243 (VOID **) &DiskIo,
244 This->DriverBindingHandle,
245 ControllerHandle,
246 EFI_OPEN_PROTOCOL_BY_DRIVER
247 );
248 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
249 gBS->CloseProtocol (
250 ControllerHandle,
251 &gEfiDevicePathProtocolGuid,
252 This->DriverBindingHandle,
253 ControllerHandle
254 );
255 goto Exit;
256 }
257
258 OpenStatus = Status;
259
260 //
261 // Try to read blocks when there's media or it is removable physical partition.
262 //
263 Status = EFI_UNSUPPORTED;
264 MediaPresent = BlockIo->Media->MediaPresent;
265 if (BlockIo->Media->MediaPresent ||
266 (BlockIo->Media->RemovableMedia && !BlockIo->Media->LogicalPartition)) {
267 //
268 // Try for GPT, then El Torito, and then legacy MBR partition types. If the
269 // media supports a given partition type install child handles to represent
270 // the partitions described by the media.
271 //
272 Routine = &mPartitionDetectRoutineTable[0];
273 while (*Routine != NULL) {
274 Status = (*Routine) (
275 This,
276 ControllerHandle,
277 DiskIo,
278 BlockIo,
279 ParentDevicePath
280 );
281 if (!EFI_ERROR (Status) || Status == EFI_MEDIA_CHANGED || Status == EFI_NO_MEDIA) {
282 break;
283 }
284 Routine++;
285 }
286 }
287 //
288 // In the case that the driver is already started (OpenStatus == EFI_ALREADY_STARTED),
289 // the DevicePathProtocol and the DiskIoProtocol are not actually opened by the
290 // driver. So don't try to close them. Otherwise, we will break the dependency
291 // between the controller and the driver set up before.
292 //
293 // In the case that when the media changes on a device it will Reinstall the
294 // BlockIo interaface. This will cause a call to our Stop(), and a subsequent
295 // reentrant call to our Start() successfully. We should leave the device open
296 // when this happen. The "media change" case includes either the status is
297 // EFI_MEDIA_CHANGED or it is a "media" to "no media" change.
298 //
299 if (EFI_ERROR (Status) &&
300 !EFI_ERROR (OpenStatus) &&
301 Status != EFI_MEDIA_CHANGED &&
302 !(MediaPresent && Status == EFI_NO_MEDIA)) {
303 gBS->CloseProtocol (
304 ControllerHandle,
305 &gEfiDiskIoProtocolGuid,
306 This->DriverBindingHandle,
307 ControllerHandle
308 );
309
310 gBS->CloseProtocol (
311 ControllerHandle,
312 &gEfiDevicePathProtocolGuid,
313 This->DriverBindingHandle,
314 ControllerHandle
315 );
316 }
317
318 Exit:
319 gBS->RestoreTPL (OldTpl);
320 return Status;
321 }
322
323
324 /**
325 Stop this driver on ControllerHandle. Support stopping any child handles
326 created by this driver.
327
328 @param This Protocol instance pointer.
329 @param ControllerHandle Handle of device to stop driver on
330 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
331 children is zero stop the entire bus driver.
332 @param ChildHandleBuffer List of Child Handles to Stop.
333
334 @retval EFI_SUCCESS This driver is removed ControllerHandle
335 @retval other This driver was not removed from this device
336
337 **/
338 EFI_STATUS
339 EFIAPI
340 PartitionDriverBindingStop (
341 IN EFI_DRIVER_BINDING_PROTOCOL *This,
342 IN EFI_HANDLE ControllerHandle,
343 IN UINTN NumberOfChildren,
344 IN EFI_HANDLE *ChildHandleBuffer
345 )
346 {
347 EFI_STATUS Status;
348 UINTN Index;
349 EFI_BLOCK_IO_PROTOCOL *BlockIo;
350 BOOLEAN AllChildrenStopped;
351 PARTITION_PRIVATE_DATA *Private;
352 EFI_DISK_IO_PROTOCOL *DiskIo;
353
354 if (NumberOfChildren == 0) {
355 //
356 // Close the bus driver
357 //
358 gBS->CloseProtocol (
359 ControllerHandle,
360 &gEfiDiskIoProtocolGuid,
361 This->DriverBindingHandle,
362 ControllerHandle
363 );
364
365 gBS->CloseProtocol (
366 ControllerHandle,
367 &gEfiDevicePathProtocolGuid,
368 This->DriverBindingHandle,
369 ControllerHandle
370 );
371
372 return EFI_SUCCESS;
373 }
374
375 AllChildrenStopped = TRUE;
376 for (Index = 0; Index < NumberOfChildren; Index++) {
377 Status = gBS->OpenProtocol (
378 ChildHandleBuffer[Index],
379 &gEfiBlockIoProtocolGuid,
380 (VOID **) &BlockIo,
381 This->DriverBindingHandle,
382 ControllerHandle,
383 EFI_OPEN_PROTOCOL_GET_PROTOCOL
384 );
385 if (!EFI_ERROR (Status)) {
386
387 Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (BlockIo);
388
389 //
390 // All Software protocols have be freed from the handle so remove it.
391 //
392 BlockIo->FlushBlocks (BlockIo);
393
394 Status = gBS->CloseProtocol (
395 ControllerHandle,
396 &gEfiDiskIoProtocolGuid,
397 This->DriverBindingHandle,
398 ChildHandleBuffer[Index]
399 );
400
401 Status = gBS->UninstallMultipleProtocolInterfaces (
402 ChildHandleBuffer[Index],
403 &gEfiDevicePathProtocolGuid,
404 Private->DevicePath,
405 &gEfiBlockIoProtocolGuid,
406 &Private->BlockIo,
407 Private->EspGuid,
408 NULL,
409 NULL
410 );
411 if (EFI_ERROR (Status)) {
412 gBS->OpenProtocol (
413 ControllerHandle,
414 &gEfiDiskIoProtocolGuid,
415 (VOID **) &DiskIo,
416 This->DriverBindingHandle,
417 ChildHandleBuffer[Index],
418 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
419 );
420 } else {
421 FreePool (Private->DevicePath);
422 FreePool (Private);
423 }
424
425 }
426
427 if (EFI_ERROR (Status)) {
428 AllChildrenStopped = FALSE;
429 }
430 }
431
432 if (!AllChildrenStopped) {
433 return EFI_DEVICE_ERROR;
434 }
435
436 return EFI_SUCCESS;
437 }
438
439
440 /**
441 Reset the Block Device.
442
443 @param This Protocol instance pointer.
444 @param ExtendedVerification Driver may perform diagnostics on reset.
445
446 @retval EFI_SUCCESS The device was reset.
447 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
448 not be reset.
449
450 **/
451 EFI_STATUS
452 EFIAPI
453 PartitionReset (
454 IN EFI_BLOCK_IO_PROTOCOL *This,
455 IN BOOLEAN ExtendedVerification
456 )
457 {
458 PARTITION_PRIVATE_DATA *Private;
459
460 Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);
461
462 return Private->ParentBlockIo->Reset (
463 Private->ParentBlockIo,
464 ExtendedVerification
465 );
466 }
467
468
469 /**
470 Read by using the Disk IO protocol on the parent device. Lba addresses
471 must be converted to byte offsets.
472
473 @param This Protocol instance pointer.
474 @param MediaId Id of the media, changes every time the media is replaced.
475 @param Lba The starting Logical Block Address to read from
476 @param BufferSize Size of Buffer, must be a multiple of device block size.
477 @param Buffer Buffer containing read data
478
479 @retval EFI_SUCCESS The data was read correctly from the device.
480 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
481 @retval EFI_NO_MEDIA There is no media in the device.
482 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
483 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
484 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not
485 valid for the device.
486
487 **/
488 EFI_STATUS
489 EFIAPI
490 PartitionReadBlocks (
491 IN EFI_BLOCK_IO_PROTOCOL *This,
492 IN UINT32 MediaId,
493 IN EFI_LBA Lba,
494 IN UINTN BufferSize,
495 OUT VOID *Buffer
496 )
497 {
498 PARTITION_PRIVATE_DATA *Private;
499 UINT64 Offset;
500
501 Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);
502
503 if (BufferSize % Private->BlockSize != 0) {
504 return EFI_BAD_BUFFER_SIZE;
505 }
506
507 Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;
508 if (Offset + BufferSize > Private->End) {
509 return EFI_INVALID_PARAMETER;
510 }
511 //
512 // Because some kinds of partition have different block size from their parent
513 // device, we call the Disk IO protocol on the parent device, not the Block IO
514 // protocol
515 //
516 return Private->DiskIo->ReadDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);
517 }
518
519 /**
520 Write by using the Disk IO protocol on the parent device. Lba addresses
521 must be converted to byte offsets.
522
523 @param This Protocol instance pointer.
524 @param MediaId Id of the media, changes every time the media is replaced.
525 @param Lba The starting Logical Block Address to read from
526 @param BufferSize Size of Buffer, must be a multiple of device block size.
527 @param Buffer Buffer containing read data
528
529 @retval EFI_SUCCESS The data was written correctly to the device.
530 @retval EFI_WRITE_PROTECTED The device can not be written to.
531 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
532 @retval EFI_NO_MEDIA There is no media in the device.
533 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
534 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
535 @retval EFI_INVALID_PARAMETER The write request contains a LBA that is not
536 valid for the device.
537
538 **/
539 EFI_STATUS
540 EFIAPI
541 PartitionWriteBlocks (
542 IN EFI_BLOCK_IO_PROTOCOL *This,
543 IN UINT32 MediaId,
544 IN EFI_LBA Lba,
545 IN UINTN BufferSize,
546 OUT VOID *Buffer
547 )
548 {
549 PARTITION_PRIVATE_DATA *Private;
550 UINT64 Offset;
551
552 Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);
553
554 if (BufferSize % Private->BlockSize != 0) {
555 return EFI_BAD_BUFFER_SIZE;
556 }
557
558 Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;
559 if (Offset + BufferSize > Private->End) {
560 return EFI_INVALID_PARAMETER;
561 }
562 //
563 // Because some kinds of partition have different block size from their parent
564 // device, we call the Disk IO protocol on the parent device, not the Block IO
565 // protocol
566 //
567 return Private->DiskIo->WriteDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);
568 }
569
570
571 /**
572 Flush the parent Block Device.
573
574 @param This Protocol instance pointer.
575
576 @retval EFI_SUCCESS All outstanding data was written to the device
577 @retval EFI_DEVICE_ERROR The device reported an error while writting back the data
578 @retval EFI_NO_MEDIA There is no media in the device.
579
580 **/
581 EFI_STATUS
582 EFIAPI
583 PartitionFlushBlocks (
584 IN EFI_BLOCK_IO_PROTOCOL *This
585 )
586 {
587 PARTITION_PRIVATE_DATA *Private;
588
589 Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);
590
591 return Private->ParentBlockIo->FlushBlocks (Private->ParentBlockIo);
592 }
593
594
595
596 /**
597 Create a child handle for a logical block device that represents the
598 bytes Start to End of the Parent Block IO device.
599
600 @param[in] This Protocol instance pointer
601 @param[in] ParentHandle Parent Handle for new child
602 @param[in] ParentDiskIo Parent DiskIo interface
603 @param[in] ParentBlockIo Parent BlockIo interface
604 @param[in] ParentDevicePath Parent Device Path
605 @param[in] DevicePathNode Child Device Path node
606 @param[in] Start Start Block
607 @param[in] End End Block
608 @param[in] BlockSize Child block size
609 @param[in] InstallEspGuid Flag to install EFI System Partition GUID on handle
610
611 @retval EFI_SUCCESS A child handle was added
612 @retval other A child handle was not added
613
614 **/
615 EFI_STATUS
616 PartitionInstallChildHandle (
617 IN EFI_DRIVER_BINDING_PROTOCOL *This,
618 IN EFI_HANDLE ParentHandle,
619 IN EFI_DISK_IO_PROTOCOL *ParentDiskIo,
620 IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo,
621 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
622 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
623 IN EFI_LBA Start,
624 IN EFI_LBA End,
625 IN UINT32 BlockSize,
626 IN BOOLEAN InstallEspGuid
627 )
628 {
629 EFI_STATUS Status;
630 PARTITION_PRIVATE_DATA *Private;
631
632 Private = AllocateZeroPool (sizeof (PARTITION_PRIVATE_DATA));
633 if (Private == NULL) {
634 return EFI_OUT_OF_RESOURCES;
635 }
636
637 Private->Signature = PARTITION_PRIVATE_DATA_SIGNATURE;
638
639 Private->Start = MultU64x32 (Start, ParentBlockIo->Media->BlockSize);
640 Private->End = MultU64x32 (End + 1, ParentBlockIo->Media->BlockSize);
641
642 Private->BlockSize = BlockSize;
643 Private->ParentBlockIo = ParentBlockIo;
644 Private->DiskIo = ParentDiskIo;
645
646 Private->BlockIo.Revision = ParentBlockIo->Revision;
647
648 Private->BlockIo.Media = &Private->Media;
649 CopyMem (Private->BlockIo.Media, ParentBlockIo->Media, sizeof (EFI_BLOCK_IO_MEDIA));
650 Private->Media.LogicalPartition = TRUE;
651
652 //
653 // Logical BlockIo instance doesn't have IoAlign restriction because it implements block io operation based on DiskIo
654 //
655 Private->Media.IoAlign = 0;
656 Private->Media.LastBlock = DivU64x32 (
657 MultU64x32 (
658 End - Start + 1,
659 ParentBlockIo->Media->BlockSize
660 ),
661 BlockSize
662 ) - 1;
663
664 Private->Media.BlockSize = (UINT32) BlockSize;
665
666 //
667 // Per UEFI Spec, LowestAlignedLba and LogicalBlocksPerPhysicalBlock must be 0
668 // for logical partitions.
669 //
670 if (Private->BlockIo.Revision >= EFI_BLOCK_IO_PROTOCOL_REVISION2) {
671 Private->BlockIo.Media->LowestAlignedLba = 0;
672 Private->BlockIo.Media->LogicalBlocksPerPhysicalBlock = 0;
673 }
674
675 Private->BlockIo.Reset = PartitionReset;
676 Private->BlockIo.ReadBlocks = PartitionReadBlocks;
677 Private->BlockIo.WriteBlocks = PartitionWriteBlocks;
678 Private->BlockIo.FlushBlocks = PartitionFlushBlocks;
679
680 Private->DevicePath = AppendDevicePathNode (ParentDevicePath, DevicePathNode);
681
682 if (Private->DevicePath == NULL) {
683 FreePool (Private);
684 return EFI_OUT_OF_RESOURCES;
685 }
686
687 if (InstallEspGuid) {
688 Private->EspGuid = &gEfiPartTypeSystemPartGuid;
689 } else {
690 //
691 // If NULL InstallMultipleProtocolInterfaces will ignore it.
692 //
693 Private->EspGuid = NULL;
694 }
695 //
696 // Create the new handle
697 //
698 Private->Handle = NULL;
699 Status = gBS->InstallMultipleProtocolInterfaces (
700 &Private->Handle,
701 &gEfiDevicePathProtocolGuid,
702 Private->DevicePath,
703 &gEfiBlockIoProtocolGuid,
704 &Private->BlockIo,
705 Private->EspGuid,
706 NULL,
707 NULL
708 );
709
710 if (!EFI_ERROR (Status)) {
711 //
712 // Open the Parent Handle for the child
713 //
714 Status = gBS->OpenProtocol (
715 ParentHandle,
716 &gEfiDiskIoProtocolGuid,
717 (VOID **) &ParentDiskIo,
718 This->DriverBindingHandle,
719 Private->Handle,
720 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
721 );
722 } else {
723 FreePool (Private->DevicePath);
724 FreePool (Private);
725 }
726
727 return Status;
728 }
729
730
731 /**
732 The user Entry Point for module Partition. The user code starts with this function.
733
734 @param[in] ImageHandle The firmware allocated handle for the EFI image.
735 @param[in] SystemTable A pointer to the EFI System Table.
736
737 @retval EFI_SUCCESS The entry point is executed successfully.
738 @retval other Some error occurs when executing this entry point.
739
740 **/
741 EFI_STATUS
742 EFIAPI
743 InitializePartition (
744 IN EFI_HANDLE ImageHandle,
745 IN EFI_SYSTEM_TABLE *SystemTable
746 )
747 {
748 EFI_STATUS Status;
749
750 //
751 // Install driver model protocol(s).
752 //
753 Status = EfiLibInstallDriverBindingComponentName2 (
754 ImageHandle,
755 SystemTable,
756 &gPartitionDriverBinding,
757 ImageHandle,
758 &gPartitionComponentName,
759 &gPartitionComponentName2
760 );
761 ASSERT_EFI_ERROR (Status);
762
763
764 return Status;
765 }
766