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 *Start, *Next, *DevPath;
121 HARDDRIVE_DEVICE_PATH *HardDriveDevicePath;
123 BOOLEAN PreviousNodeIsHardDriveDevicePath;
126 // Initialize for GrowBuffer loop
129 BlockIoBuffer = NULL;
130 BufferSize = 50 * sizeof(EFI_HANDLE);
133 // Call the real function
136 while (GrowBuffer (&Status, (VOID **)&BlockIoBuffer, BufferSize)) {
139 // Get list of device handles that support the BLOCK_IO Protocol.
142 Status = uefi_call_wrapper(
154 NoBlockIoHandles = BufferSize / sizeof (EFI_HANDLE);
155 if (EFI_ERROR(Status)) {
156 NoBlockIoHandles = 0;
160 // If there was an error or there are no device handles that support
161 // the BLOCK_IO Protocol, then return.
164 if (NoBlockIoHandles == 0) {
165 FreePool(BlockIoBuffer);
172 // Loop through all the device handles that support the BLOCK_IO Protocol
177 for(Index=0;Index<NoBlockIoHandles;Index++) {
179 Status = uefi_call_wrapper(
182 BlockIoBuffer[Index],
188 // Search DevicePath for a Hard Drive Media Device Path node.
189 // If one is found, then see if it matches the signature that was
190 // passed in. If it does match, and the next node is the End of the
191 // device path, and the previous node is not a Hard Drive Media Device
192 // Path, then we have found a match.
197 if (DevicePath != NULL) {
199 PreviousNodeIsHardDriveDevicePath = FALSE;
201 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
343 BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
346 // Call the real function
349 while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
350 Status = uefi_call_wrapper(
364 EFI_FILE_SYSTEM_INFO *
366 IN EFI_FILE_HANDLE FHand
370 EFI_FILE_SYSTEM_INFO *Buffer;
374 // Initialize for GrowBuffer loop
378 BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + 200;
381 // Call the real function
384 while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
385 Status = uefi_call_wrapper(
398 EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *
399 LibFileSystemVolumeLabelInfo (
400 IN EFI_FILE_HANDLE FHand
404 EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *Buffer;
408 // Initialize for GrowBuffer loop
412 BufferSize = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL_INFO + 200;
415 // Call the real function
418 while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
419 Status = uefi_call_wrapper(
423 &FileSystemVolumeLabelInfo,
435 LibInstallProtocolInterfaces (
436 IN OUT EFI_HANDLE *Handle,
446 EFI_HANDLE OldHandle;
449 // Syncronize with notifcations
452 OldTpl = uefi_call_wrapper(BS->RaiseTPL, 1, TPL_NOTIFY);
456 // Install the protocol interfaces
460 Status = EFI_SUCCESS;
461 va_start (args, Handle);
463 while (!EFI_ERROR(Status)) {
466 // If protocol is NULL, then it's the end of the list
469 Protocol = va_arg(args, EFI_GUID *);
474 Interface = va_arg(args, VOID *);
480 DEBUG((D_INFO, "LibInstallProtocolInterface: %d %x\n", Protocol, Interface));
481 Status = uefi_call_wrapper(BS->InstallProtocolInterface, 4, Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);
482 if (EFI_ERROR(Status)) {
490 // If there was an error, remove all the interfaces that were
491 // installed without any errors
494 if (EFI_ERROR(Status)) {
495 va_start (args, Handle);
498 Protocol = va_arg(args, EFI_GUID *);
499 Interface = va_arg(args, VOID *);
500 uefi_call_wrapper(BS->UninstallProtocolInterface, 3, *Handle, Protocol, Interface);
512 uefi_call_wrapper(BS->RestoreTPL, 1, OldTpl);
518 LibUninstallProtocolInterfaces (
519 IN EFI_HANDLE Handle,
529 va_start (args, Handle);
533 // If protocol is NULL, then it's the end of the list
536 Protocol = va_arg(args, EFI_GUID *);
541 Interface = va_arg(args, VOID *);
547 Status = uefi_call_wrapper(BS->UninstallProtocolInterface, 3, Handle, Protocol, Interface);
548 if (EFI_ERROR(Status)) {
549 DEBUG((D_ERROR, "LibUninstallProtocolInterfaces: failed %g, %r\n", Protocol, Handle));
556 LibReinstallProtocolInterfaces (
557 IN OUT EFI_HANDLE *Handle,
564 VOID *OldInterface, *NewInterface;
569 // Syncronize with notifcations
572 OldTpl = uefi_call_wrapper(BS->RaiseTPL, 1, TPL_NOTIFY);
575 // Install the protocol interfaces
579 Status = EFI_SUCCESS;
580 va_start (args, Handle);
582 while (!EFI_ERROR(Status)) {
585 // If protocol is NULL, then it's the end of the list
588 Protocol = va_arg(args, EFI_GUID *);
593 OldInterface = va_arg(args, VOID *);
594 NewInterface = va_arg(args, VOID *);
600 Status = uefi_call_wrapper(BS->ReinstallProtocolInterface, 4, Handle, Protocol, OldInterface, NewInterface);
601 if (EFI_ERROR(Status)) {
609 // If there was an error, undo all the interfaces that were
610 // reinstalled without any errors
613 if (EFI_ERROR(Status)) {
614 va_start (args, Handle);
617 Protocol = va_arg(args, EFI_GUID *);
618 OldInterface = va_arg(args, VOID *);
619 NewInterface = va_arg(args, VOID *);
621 uefi_call_wrapper(BS->ReinstallProtocolInterface, 4, Handle, Protocol, NewInterface, OldInterface);
631 uefi_call_wrapper(BS->RestoreTPL, 1, OldTpl);