3 Copyright (c) 1998 Intel Corporation
19 #include "efistdarg.h" // !!!
24 IN EFI_GUID
*ProtocolGuid
,
28 // Find the first instance of this Protocol in the system and return it's interface
32 UINTN NumberHandles
, Index
;
37 Status
= LibLocateHandle (ByProtocol
, ProtocolGuid
, NULL
, &NumberHandles
, &Handles
);
38 if (EFI_ERROR(Status
)) {
39 DEBUG((D_INFO
, "LibLocateProtocol: Handle not found\n"));
43 for (Index
=0; Index
< NumberHandles
; Index
++) {
44 Status
= uefi_call_wrapper(BS
->HandleProtocol
, 3, Handles
[Index
], ProtocolGuid
, Interface
);
45 if (!EFI_ERROR(Status
)) {
59 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
60 IN EFI_GUID
*Protocol OPTIONAL
,
61 IN VOID
*SearchKey OPTIONAL
,
62 IN OUT UINTN
*NoHandles
,
63 OUT EFI_HANDLE
**Buffer
71 // Initialize for GrowBuffer loop
76 BufferSize
= 50 * sizeof(EFI_HANDLE
);
79 // Call the real function
82 while (GrowBuffer (&Status
, (VOID
**) Buffer
, BufferSize
)) {
84 Status
= uefi_call_wrapper(
96 *NoHandles
= BufferSize
/ sizeof (EFI_HANDLE
);
97 if (EFI_ERROR(Status
)) {
105 LibLocateHandleByDiskSignature (
107 IN UINT8 SignatureType
,
109 IN OUT UINTN
*NoHandles
,
110 OUT EFI_HANDLE
**Buffer
116 UINTN NoBlockIoHandles
;
117 EFI_HANDLE
*BlockIoBuffer
;
118 EFI_DEVICE_PATH
*DevicePath
;
120 EFI_DEVICE_PATH
*Next
, *DevPath
;
121 HARDDRIVE_DEVICE_PATH
*HardDriveDevicePath
;
123 BOOLEAN PreviousNodeIsHardDriveDevicePath
;
126 // Initialize for GrowBuffer loop
129 Status
= EFI_SUCCESS
;
130 BlockIoBuffer
= NULL
;
131 BufferSize
= 50 * sizeof(EFI_HANDLE
);
134 // Call the real function
137 while (GrowBuffer (&Status
, (VOID
**)&BlockIoBuffer
, BufferSize
)) {
140 // Get list of device handles that support the BLOCK_IO Protocol.
143 Status
= uefi_call_wrapper(
155 NoBlockIoHandles
= BufferSize
/ sizeof (EFI_HANDLE
);
156 if (EFI_ERROR(Status
)) {
157 NoBlockIoHandles
= 0;
161 // If there was an error or there are no device handles that support
162 // the BLOCK_IO Protocol, then return.
165 if (NoBlockIoHandles
== 0) {
166 FreePool(BlockIoBuffer
);
173 // Loop through all the device handles that support the BLOCK_IO Protocol
178 for(Index
=0;Index
<NoBlockIoHandles
;Index
++) {
180 Status
= uefi_call_wrapper(
183 BlockIoBuffer
[Index
],
189 // Search DevicePath for a Hard Drive Media Device Path node.
190 // If one is found, then see if it matches the signature that was
191 // passed in. If it does match, and the next node is the End of the
192 // device path, and the previous node is not a Hard Drive Media Device
193 // Path, then we have found a match.
198 if (DevicePath
!= NULL
) {
200 PreviousNodeIsHardDriveDevicePath
= FALSE
;
202 DevPath
= DevicePath
;
205 // Check for end of device path type
210 if ((DevicePathType(DevPath
) == MEDIA_DEVICE_PATH
) &&
211 (DevicePathSubType(DevPath
) == MEDIA_HARDDRIVE_DP
)) {
213 HardDriveDevicePath
= (HARDDRIVE_DEVICE_PATH
*)(DevPath
);
215 if (PreviousNodeIsHardDriveDevicePath
== FALSE
) {
217 Next
= NextDevicePathNode(DevPath
);
218 if (IsDevicePathEndType(Next
)) {
219 if ((HardDriveDevicePath
->MBRType
== MBRType
) &&
220 (HardDriveDevicePath
->SignatureType
== SignatureType
)) {
221 switch(SignatureType
) {
222 case SIGNATURE_TYPE_MBR
:
223 if (*((UINT32
*)(Signature
)) == *(UINT32
*)(&(HardDriveDevicePath
->Signature
[0]))) {
227 case SIGNATURE_TYPE_GUID
:
228 if (CompareGuid((EFI_GUID
*)Signature
,(EFI_GUID
*)(&(HardDriveDevicePath
->Signature
[0]))) == 0) {
236 PreviousNodeIsHardDriveDevicePath
= TRUE
;
238 PreviousNodeIsHardDriveDevicePath
= FALSE
;
241 if (IsDevicePathEnd(DevPath
)) {
245 DevPath
= NextDevicePathNode(DevPath
);
250 if (Match
== FALSE
) {
251 BlockIoBuffer
[Index
] = NULL
;
253 *NoHandles
= *NoHandles
+ 1;
258 // If there are no matches, then return
261 if (*NoHandles
== 0) {
262 FreePool(BlockIoBuffer
);
269 // Allocate space for the return buffer of device handles.
272 *Buffer
= AllocatePool(*NoHandles
* sizeof(EFI_HANDLE
));
274 if (*Buffer
== NULL
) {
275 FreePool(BlockIoBuffer
);
278 return EFI_OUT_OF_RESOURCES
;
282 // Build list of matching device handles.
286 for(Index
=0;Index
<NoBlockIoHandles
;Index
++) {
287 if (BlockIoBuffer
[Index
] != NULL
) {
288 (*Buffer
)[*NoHandles
] = BlockIoBuffer
[Index
];
289 *NoHandles
= *NoHandles
+ 1;
293 FreePool(BlockIoBuffer
);
300 IN EFI_HANDLE DeviceHandle
304 EFI_FILE_IO_INTERFACE
*Volume
;
305 EFI_FILE_HANDLE File
;
309 // File the file system interface to the device
312 Status
= uefi_call_wrapper(BS
->HandleProtocol
, 3, DeviceHandle
, &FileSystemProtocol
, (VOID
*)&Volume
);
315 // Open the root directory of the volume
318 if (!EFI_ERROR(Status
)) {
319 Status
= uefi_call_wrapper(Volume
->OpenVolume
, 2, Volume
, &File
);
326 return EFI_ERROR(Status
) ? NULL
: File
;
331 IN EFI_FILE_HANDLE FHand
335 EFI_FILE_INFO
*Buffer
;
339 // Initialize for GrowBuffer loop
342 Status
= EFI_SUCCESS
;
344 BufferSize
= SIZE_OF_EFI_FILE_INFO
+ 200;
347 // Call the real function
350 while (GrowBuffer (&Status
, (VOID
**) &Buffer
, BufferSize
)) {
351 Status
= uefi_call_wrapper(
365 EFI_FILE_SYSTEM_INFO
*
367 IN EFI_FILE_HANDLE FHand
371 EFI_FILE_SYSTEM_INFO
*Buffer
;
375 // Initialize for GrowBuffer loop
378 Status
= EFI_SUCCESS
;
380 BufferSize
= SIZE_OF_EFI_FILE_SYSTEM_INFO
+ 200;
383 // Call the real function
386 while (GrowBuffer (&Status
, (VOID
**) &Buffer
, BufferSize
)) {
387 Status
= uefi_call_wrapper(
400 EFI_FILE_SYSTEM_VOLUME_LABEL_INFO
*
401 LibFileSystemVolumeLabelInfo (
402 IN EFI_FILE_HANDLE FHand
406 EFI_FILE_SYSTEM_VOLUME_LABEL_INFO
*Buffer
;
410 // Initialize for GrowBuffer loop
413 Status
= EFI_SUCCESS
;
415 BufferSize
= SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL_INFO
+ 200;
418 // Call the real function
421 while (GrowBuffer (&Status
, (VOID
**) &Buffer
, BufferSize
)) {
422 Status
= uefi_call_wrapper(
426 &FileSystemVolumeLabelInfo
,
438 LibInstallProtocolInterfaces (
439 IN OUT EFI_HANDLE
*Handle
,
449 EFI_HANDLE OldHandle
;
452 // Syncronize with notifcations
455 OldTpl
= uefi_call_wrapper(BS
->RaiseTPL
, 1, TPL_NOTIFY
);
459 // Install the protocol interfaces
463 Status
= EFI_SUCCESS
;
464 va_start (args
, Handle
);
466 while (!EFI_ERROR(Status
)) {
469 // If protocol is NULL, then it's the end of the list
472 Protocol
= va_arg(args
, EFI_GUID
*);
477 Interface
= va_arg(args
, VOID
*);
483 DEBUG((D_INFO
, "LibInstallProtocolInterface: %d %x\n", Protocol
, Interface
));
484 Status
= uefi_call_wrapper(BS
->InstallProtocolInterface
, 4, Handle
, Protocol
, EFI_NATIVE_INTERFACE
, Interface
);
485 if (EFI_ERROR(Status
)) {
493 // If there was an error, remove all the interfaces that were
494 // installed without any errors
497 if (EFI_ERROR(Status
)) {
498 va_start (args
, Handle
);
501 Protocol
= va_arg(args
, EFI_GUID
*);
502 Interface
= va_arg(args
, VOID
*);
503 uefi_call_wrapper(BS
->UninstallProtocolInterface
, 3, *Handle
, Protocol
, Interface
);
515 uefi_call_wrapper(BS
->RestoreTPL
, 1, OldTpl
);
521 LibUninstallProtocolInterfaces (
522 IN EFI_HANDLE Handle
,
532 va_start (args
, Handle
);
536 // If protocol is NULL, then it's the end of the list
539 Protocol
= va_arg(args
, EFI_GUID
*);
544 Interface
= va_arg(args
, VOID
*);
550 Status
= uefi_call_wrapper(BS
->UninstallProtocolInterface
, 3, Handle
, Protocol
, Interface
);
551 if (EFI_ERROR(Status
)) {
552 DEBUG((D_ERROR
, "LibUninstallProtocolInterfaces: failed %g, %r\n", Protocol
, Handle
));
559 LibReinstallProtocolInterfaces (
560 IN OUT EFI_HANDLE
*Handle
,
567 VOID
*OldInterface
, *NewInterface
;
572 // Syncronize with notifcations
575 OldTpl
= uefi_call_wrapper(BS
->RaiseTPL
, 1, TPL_NOTIFY
);
578 // Install the protocol interfaces
582 Status
= EFI_SUCCESS
;
583 va_start (args
, Handle
);
585 while (!EFI_ERROR(Status
)) {
588 // If protocol is NULL, then it's the end of the list
591 Protocol
= va_arg(args
, EFI_GUID
*);
596 OldInterface
= va_arg(args
, VOID
*);
597 NewInterface
= va_arg(args
, VOID
*);
603 Status
= uefi_call_wrapper(BS
->ReinstallProtocolInterface
, 4, Handle
, Protocol
, OldInterface
, NewInterface
);
604 if (EFI_ERROR(Status
)) {
612 // If there was an error, undo all the interfaces that were
613 // reinstalled without any errors
616 if (EFI_ERROR(Status
)) {
617 va_start (args
, Handle
);
620 Protocol
= va_arg(args
, EFI_GUID
*);
621 OldInterface
= va_arg(args
, VOID
*);
622 NewInterface
= va_arg(args
, VOID
*);
624 uefi_call_wrapper(BS
->ReinstallProtocolInterface
, 4, Handle
, Protocol
, NewInterface
, OldInterface
);
634 uefi_call_wrapper(BS
->RestoreTPL
, 1, OldTpl
);