mirror of https://github.com/acidanthera/audk.git
MdePkg/UefiLib: Add EfiLocateProtocolBuffer()
https://bugzilla.tianocore.org/show_bug.cgi?id=838 Add new API to the UefiLib that locates and returns an array of protocols instances that match a given protocol. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>
This commit is contained in:
parent
6ef394ffe2
commit
40070a186a
|
@ -12,7 +12,7 @@
|
||||||
of size reduction when compiler optimization is disabled. If MDEPKG_NDEBUG is
|
of size reduction when compiler optimization is disabled. If MDEPKG_NDEBUG is
|
||||||
defined, then debug and assert related macros wrapped by it are the NULL implementations.
|
defined, then debug and assert related macros wrapped by it are the NULL implementations.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials are licensed and made available under
|
This program and the accompanying materials are licensed and made available under
|
||||||
the terms and conditions of the BSD License that accompanies this distribution.
|
the terms and conditions of the BSD License that accompanies this distribution.
|
||||||
The full text of the license may be found at
|
The full text of the license may be found at
|
||||||
|
@ -1490,4 +1490,34 @@ CatSPrint (
|
||||||
...
|
...
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns an array of protocol instance that matches the given protocol.
|
||||||
|
|
||||||
|
@param[in] Protocol Provides the protocol to search for.
|
||||||
|
@param[out] NoProtocols The number of protocols returned in Buffer.
|
||||||
|
@param[out] Buffer A pointer to the buffer to return the requested
|
||||||
|
array of protocol instances that match Protocol.
|
||||||
|
The returned buffer is allocated using
|
||||||
|
EFI_BOOT_SERVICES.AllocatePool(). The caller is
|
||||||
|
responsible for freeing this buffer with
|
||||||
|
EFI_BOOT_SERVICES.FreePool().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The array of protocols was returned in Buffer,
|
||||||
|
and the number of protocols in Buffer was
|
||||||
|
returned in NoProtocols.
|
||||||
|
@retval EFI_NOT_FOUND No protocols found.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
|
||||||
|
matching results.
|
||||||
|
@retval EFI_INVALID_PARAMETER Protocol is NULL.
|
||||||
|
@retval EFI_INVALID_PARAMETER NoProtocols is NULL.
|
||||||
|
@retval EFI_INVALID_PARAMETER Buffer is NULL.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EfiLocateProtocolBuffer (
|
||||||
|
IN EFI_GUID *Protocol,
|
||||||
|
OUT UINTN *NoProtocols,
|
||||||
|
OUT VOID ***Buffer
|
||||||
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers,
|
EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers,
|
||||||
and print messages on the console output and standard error devices.
|
and print messages on the console output and standard error devices.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -1605,3 +1605,113 @@ GetBestLanguage (
|
||||||
//
|
//
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns an array of protocol instance that matches the given protocol.
|
||||||
|
|
||||||
|
@param[in] Protocol Provides the protocol to search for.
|
||||||
|
@param[out] NoProtocols The number of protocols returned in Buffer.
|
||||||
|
@param[out] Buffer A pointer to the buffer to return the requested
|
||||||
|
array of protocol instances that match Protocol.
|
||||||
|
The returned buffer is allocated using
|
||||||
|
EFI_BOOT_SERVICES.AllocatePool(). The caller is
|
||||||
|
responsible for freeing this buffer with
|
||||||
|
EFI_BOOT_SERVICES.FreePool().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The array of protocols was returned in Buffer,
|
||||||
|
and the number of protocols in Buffer was
|
||||||
|
returned in NoProtocols.
|
||||||
|
@retval EFI_NOT_FOUND No protocols found.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
|
||||||
|
matching results.
|
||||||
|
@retval EFI_INVALID_PARAMETER Protocol is NULL.
|
||||||
|
@retval EFI_INVALID_PARAMETER NoProtocols is NULL.
|
||||||
|
@retval EFI_INVALID_PARAMETER Buffer is NULL.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EfiLocateProtocolBuffer (
|
||||||
|
IN EFI_GUID *Protocol,
|
||||||
|
OUT UINTN *NoProtocols,
|
||||||
|
OUT VOID ***Buffer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINTN NoHandles;
|
||||||
|
EFI_HANDLE *HandleBuffer;
|
||||||
|
UINTN Index;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check input parameters
|
||||||
|
//
|
||||||
|
if (Protocol == NULL || NoProtocols == NULL || Buffer == NULL) {
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialze output parameters
|
||||||
|
//
|
||||||
|
*NoProtocols = 0;
|
||||||
|
*Buffer = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve the array of handles that support Protocol
|
||||||
|
//
|
||||||
|
Status = gBS->LocateHandleBuffer (
|
||||||
|
ByProtocol,
|
||||||
|
Protocol,
|
||||||
|
NULL,
|
||||||
|
&NoHandles,
|
||||||
|
&HandleBuffer
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Allocate array of protocol instances
|
||||||
|
//
|
||||||
|
Status = gBS->AllocatePool (
|
||||||
|
EfiBootServicesData,
|
||||||
|
NoHandles * sizeof (VOID *),
|
||||||
|
(VOID **)Buffer
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
ZeroMem (*Buffer, NoHandles * sizeof (VOID *));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lookup Protocol on each handle in HandleBuffer to fill in the array of
|
||||||
|
// protocol instances. Handle case where protocol instance was present when
|
||||||
|
// LocateHandleBuffer() was called, but is not present when HandleProtocol()
|
||||||
|
// is called.
|
||||||
|
//
|
||||||
|
for (Index = 0, *NoProtocols = 0; Index < NoHandles; Index++) {
|
||||||
|
Status = gBS->HandleProtocol (
|
||||||
|
HandleBuffer[Index],
|
||||||
|
Protocol,
|
||||||
|
&((*Buffer)[*NoProtocols])
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
(*NoProtocols)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Free the handle buffer
|
||||||
|
//
|
||||||
|
gBS->FreePool (HandleBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Make sure at least one protocol instance was found
|
||||||
|
//
|
||||||
|
if (*NoProtocols == 0) {
|
||||||
|
gBS->FreePool (*Buffer);
|
||||||
|
*Buffer = NULL;
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue