From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.12292.1647966028953866033 for ; Tue, 22 Mar 2022 09:20:29 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=my6ahKg8; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.202.59.224]) by linux.microsoft.com (Postfix) with ESMTPSA id AA3D220B4783; Tue, 22 Mar 2022 09:20:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AA3D220B4783 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1647966028; bh=twg5sPH+M7Lh+UXk7KwD0sNQftC5y0o/p1mmfEGlwF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=my6ahKg8creBgbULWeslGMvH0rbrqjmYIcpKUbD8M49Moh9yLH5hsHSXLZl2ggyv2 CF3bgC60qyDaO1DUZVxYtK6sPE3mZWlm3ZDO4XSgSAbLKS2QBKwuFIL+xTjamSl1nx jXe6oyznyMSbMM0NRuNfwYcMRmetgM9523MoCvdg= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Andrew Fish , Kang Gao , Michael D Kinney , Michael Kubacki , Leif Lindholm , Benjamin You , Liu Yun , Ankit Sinha , Nate DeSimone Subject: [PATCH v1 03/41] PrmPkg/PrmContextBufferLib: Add initial library instance Date: Tue, 22 Mar 2022 12:19:09 -0400 Message-Id: <20220322161947.9319-4-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220322161947.9319-1-mikuback@linux.microsoft.com> References: <20220322161947.9319-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3812 This library is introduced to add a general abstraction for PRM context buffer management. Cc: Andrew Fish Cc: Kang Gao Cc: Michael D Kinney Cc: Michael Kubacki Cc: Leif Lindholm Cc: Benjamin You Cc: Liu Yun Cc: Ankit Sinha Cc: Nate DeSimone Signed-off-by: Michael Kubacki --- PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c | 196 += +++++++++++++++++++ PrmPkg/Include/Library/PrmContextBufferLib.h | 99 += +++++++++ PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf | 35 += +++ 3 files changed, 330 insertions(+) diff --git a/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib= .c b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c new file mode 100644 index 000000000000..1a1a15b5cdbb --- /dev/null +++ b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c @@ -0,0 +1,196 @@ +/** @file + + The PRM Buffer Context library provides a general abstraction for cont= ext buffer management. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#define _DBGMSGID_ "[PRMCONTEXTBUFFERLIB]" + +/** + Finds a PRM context buffer for the given PRM handler GUID. + + Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_= CONTEXT_BUFFER is at the PRM handler level. + + @param[in] HandlerGuid A pointer to the PRM handler G= UID. + @param[in] ModuleContextBuffers A pointer to the PRM context b= uffers structure for the PRM module. + @param[out] PrmModuleContextBuffer A pointer to a pointer that wi= ll be set to the PRM context buffer + if successfully found. + + @retval EFI_SUCCESS The PRM context buffer was fou= nd. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffer for the giv= en PRM handler GUID could not be found. + +**/ +EFI_STATUS +FindContextBufferInModuleBuffers ( + IN CONST EFI_GUID *HandlerGuid, + IN CONST PRM_MODULE_CONTEXT_BUFFERS *ModuleContextBuffers, + OUT CONST PRM_CONTEXT_BUFFER **ContextBuffer + ) +{ + UINTN Index; + + DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__))= ; + + if (HandlerGuid =3D=3D NULL || ModuleContextBuffers =3D=3D NULL || Con= textBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + for (Index =3D 0; Index < ModuleContextBuffers->BufferCount; Index++) = { + if (CompareGuid (&ModuleContextBuffers->Buffer[Index].HandlerGuid, H= andlerGuid)) { + *ContextBuffer =3D &ModuleContextBuffers->Buffer[Index]; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Returns a PRM context buffers structure for the given PRM search type. + + This function allows a caller to get the context buffers structure for= a PRM module with either the PRM module + GUID or the GUID for a PRM handler in the module. + + Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_= CONTEXT_BUFFER is at the PRM handler level. + + @param[in] GuidSearchType The type of GUID passed in the= Guid argument. + @param[in] Guid A pointer to the GUID of a PRM= module or PRM handler. The actual GUID type + will be interpreted based on t= he value passed in GuidSearchType. + @param[out] PrmModuleContextBuffers A pointer to a pointer that wi= ll be set to the PRM context buffers + structure if successfully foun= d. + + @retval EFI_SUCCESS The PRM context buffers struct= ure was found. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffers for the gi= ven GUID could not be found. + +**/ +EFI_STATUS +GetModuleContextBuffers ( + IN PRM_GUID_SEARCH_TYPE GuidSearchType, + IN CONST EFI_GUID *Guid, + OUT CONST PRM_MODULE_CONTEXT_BUFFERS **PrmModuleContextBuffers + ) +{ + EFI_STATUS Status; + UINTN HandleCount; + UINTN Index; + EFI_HANDLE *HandleBuffer; + PRM_CONFIG_PROTOCOL *PrmConfigProtocol; + CONST PRM_CONTEXT_BUFFER *PrmContextBuffer; + + DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__))= ; + + if (Guid =3D=3D NULL || PrmModuleContextBuffers =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + *PrmModuleContextBuffers =3D NULL; + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gPrmConfigProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (Index =3D 0; Index < HandleCount; Index++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer[Index], + &gPrmConfigProtocolGuid, + (VOID **) &PrmConfigProtocol + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status) || PrmConfigProtocol =3D=3D NULL) { + continue; + } + + if (GuidSearchType =3D=3D ByModuleGuid) { + if (CompareGuid (&PrmConfigProtocol->ModuleContextBuffers.Module= Guid, Guid)) { + DEBUG (( + DEBUG_INFO, + " %a %a: Found a PRM configuration protocol for PRM mod= ule %g.\n", + _DBGMSGID_, + __FUNCTION__, + Guid + )); + + *PrmModuleContextBuffers =3D &PrmConfigProtocol->ModuleContext= Buffers; + return EFI_SUCCESS; + } + } else { + Status =3D FindContextBufferInModuleBuffers (Guid, &PrmConfigPro= tocol->ModuleContextBuffers, &PrmContextBuffer); + if (!EFI_ERROR (Status)) { + *PrmModuleContextBuffers =3D &PrmConfigProtocol->ModuleContext= Buffers; + return EFI_SUCCESS; + } + } + } + } + + DEBUG (( + DEBUG_INFO, + " %a %a: Could not locate a PRM configuration protocol for PRM = handler %g.\n", + _DBGMSGID_, + __FUNCTION__, + Guid + )); + + return EFI_NOT_FOUND; +} + +/** + Returns a PRM context buffer for the given PRM handler. + + @param[in] PrmHandlerGuid A pointer to the GUID for the = PRM handler. + @param[in] PrmModuleContextBuffers A pointer to a PRM_MODULE_CONT= EXT_BUFFERS structure. If this optional + parameter is provided, the han= dler context buffer will be searched for in this + buffer structure which saves t= ime by not performing a global search for the + module buffer structure. + @param[out] PrmContextBuffer A pointer to a pointer that wi= ll be set to the PRM context buffer + if successfully found. + + @retval EFI_SUCCESS The PRM context buffer was fou= nd. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffer for the PRM= handler could not be found. + +**/ +EFI_STATUS +GetContextBuffer ( + IN CONST EFI_GUID *PrmHandlerGuid, + IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTI= ONAL, + OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer + ) +{ + EFI_STATUS Status; + CONST PRM_MODULE_CONTEXT_BUFFERS *ContextBuffers; + + DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__))= ; + + if (PrmHandlerGuid =3D=3D NULL || PrmContextBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + *PrmContextBuffer =3D NULL; + + if (PrmModuleContextBuffers =3D=3D NULL) { + Status =3D GetModuleContextBuffers (ByHandlerGuid, PrmHandlerGuid, &= ContextBuffers); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + } else { + ContextBuffers =3D PrmModuleContextBuffers; + } + Status =3D FindContextBufferInModuleBuffers (PrmHandlerGuid, ContextBu= ffers, PrmContextBuffer); + + return Status; +} diff --git a/PrmPkg/Include/Library/PrmContextBufferLib.h b/PrmPkg/Includ= e/Library/PrmContextBufferLib.h new file mode 100644 index 000000000000..93dcd1e76642 --- /dev/null +++ b/PrmPkg/Include/Library/PrmContextBufferLib.h @@ -0,0 +1,99 @@ +/** @file + + The PRM Buffer Context library provides a general abstraction for cont= ext buffer management. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_CONTEXT_BUFFER_LIB_H_ +#define PRM_CONTEXT_BUFFER_LIB_H_ + +#include +#include +#include + +typedef enum { + /// + /// Search by the PRM module GUID + /// + ByModuleGuid, + /// + /// Search by the PRM handler GUID + /// + ByHandlerGuid +} PRM_GUID_SEARCH_TYPE; + +/** + Finds a PRM context buffer for the given PRM handler GUID. + + Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_= CONTEXT_BUFFER is at the PRM handler level. + + @param[in] HandlerGuid A pointer to the PRM handler G= UID. + @param[in] ModuleContextBuffers A pointer to the PRM context b= uffers structure for the PRM module. + @param[out] PrmModuleContextBuffer A pointer to a pointer that wi= ll be set to the PRM context buffer + if successfully found. + + @retval EFI_SUCCESS The PRM context buffer was fou= nd. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffer for the giv= en PRM handler GUID could not be found. + +**/ +EFI_STATUS +FindContextBufferInModuleBuffers ( + IN CONST EFI_GUID *HandlerGuid, + IN CONST PRM_MODULE_CONTEXT_BUFFERS *ModuleContextBuffers, + OUT CONST PRM_CONTEXT_BUFFER **ContextBuffer + ); + +/** + Returns a PRM context buffers structure for the given PRM search type. + + This function allows a caller to get the context buffers structure for= a PRM module with either the PRM module + GUID or the GUID for a PRM handler in the module. + + Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_= CONTEXT_BUFFER is at the PRM handler level. + + @param[in] GuidSearchType The type of GUID passed in the= Guid argument. + @param[in] Guid A pointer to the GUID of a PRM= module or PRM handler. The actual GUID type + will be interpreted based on t= he value passed in GuidSearchType. + @param[out] PrmModuleContextBuffers A pointer to a pointer that wi= ll be set to the PRM context buffers + structure if successfully foun= d. + + @retval EFI_SUCCESS The PRM context buffers struct= ure was found. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffers for the gi= ven GUID could not be found. + +**/ +EFI_STATUS +GetModuleContextBuffers ( + IN PRM_GUID_SEARCH_TYPE GuidSearchType, + IN CONST EFI_GUID *Guid, + OUT CONST PRM_MODULE_CONTEXT_BUFFERS **PrmModuleContextBuffers + ); + +/** + Returns a PRM context buffer for the given PRM handler. + + @param[in] PrmHandlerGuid A pointer to the GUID for the = PRM handler. + @param[in] PrmModuleContextBuffers A pointer to a PRM_MODULE_CONT= EXT_BUFFERS structure. If this optional + parameter is provided, the han= dler context buffer will be searched for in this + buffer structure which saves t= ime by not performing a global search for the + module buffer structure. + @param[out] PrmContextBuffer A pointer to a pointer that wi= ll be set to the PRM context buffer + if successfully found. + + @retval EFI_SUCCESS The PRM context buffer was fou= nd. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffer for the PRM= handler could not be found. + +**/ +EFI_STATUS +GetContextBuffer ( + IN CONST EFI_GUID *PrmHandlerGuid, + IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTI= ONAL, + OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer + ); + +#endif diff --git a/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib= .inf b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf new file mode 100644 index 000000000000..16ed1edfe36a --- /dev/null +++ b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf @@ -0,0 +1,35 @@ +## @file +# PRM Context Buffer Library +# +# Provides a general abstraction for PRM context buffer management. +# +# Copyright (c) Microsoft Corporation +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxePrmContextBufferLib + FILE_GUID =3D 49828E93-29FA-4665-B8B1-19BA4059D140 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PrmContextBufferLib|DXE_DRIVER UEFI_DRIVER UEF= I_APPLICATION + +[Sources] + DxePrmContextBufferLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + PrmPkg/PrmPkg.dec + +[Protocols] + gPrmConfigProtocolGuid + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + UefiBootServicesTableLib --=20 2.28.0.windows.1