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.web08.12162.1647966120647961979 for ; Tue, 22 Mar 2022 09:22:00 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=GyGfGyyI; 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 5BE5220B4783; Tue, 22 Mar 2022 09:21:59 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5BE5220B4783 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1647966120; bh=UPheVvcrb3BCYxRIw2j5CwudZap0awulY5M3Sck7iu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GyGfGyyINByRMBeEIS2f2Y52d/n+3y7Zgnacz2YTUmIkDoQFe+jPyeBD0/L7FwQpN 4AQTQBIOU772IBXFRpIEj818GCOMitl25GIp4PX02ohiz4PgxhGZYHnRJHnFz2LfYp jrRJ4FWEMMCwTEGuFONUx2bLyYMDlykIfXTt/64c= 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 22/41] PrmPkg/SampleAcpiParameterBufferModule: Add initial module Date: Tue, 22 Mar 2022 12:19:28 -0400 Message-Id: <20220322161947.9319-23-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 Adds a new PRM module called SampleAcpiParameterBufferModule that demonstrates how a PRM module can use an ACPI parameter buffer with a PRM handler. 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/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParamet= erBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.c | 120 += +++++++++++++++++++ PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameter= BufferModule.c | 79 += ++++++++++++ PrmPkg/PrmPkg.dsc = | 3 + PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParamet= erBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf | 39 += ++++++ PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameter= BufferModule.inf | 41 += ++++++ 5 files changed, 282 insertions(+) diff --git a/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/Dx= eAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib= .c b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiPar= ameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.c new file mode 100644 index 000000000000..b135517232f7 --- /dev/null +++ b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiPa= rameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.c @@ -0,0 +1,120 @@ +/** @file + + The boot services environment configuration library for the ACPI Param= eter Buffer Sample PRM module. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +STATIC EFI_HANDLE mPrmConfigProtocolHandle; + +// {dc2a58a6-5927-4776-b995-d118a27335a2} +STATIC CONST EFI_GUID mPrmModuleGuid =3D {0xdc2a58a6, 0x5927, 0x4776, {0= xb9, 0x95, 0xd1, 0x18, 0xa2, 0x73, 0x35, 0xa2}}; + +// {2e4f2d13-6240-4ed0-a401-c723fbdc34e8} +STATIC CONST EFI_GUID mCheckParamBufferPrmHandlerGuid =3D {0x2e4f2d13, 0= x6240, 0x4ed0, {0xa4, 0x01, 0xc7, 0x23, 0xfb, 0xdc, 0x34, 0xe8}}; + +/** + Constructor of the PRM configuration library. + + @param[in] ImageHandle The image handle of the driver. + @param[in] SystemTable The EFI System Table pointer. + + @retval EFI_SUCCESS The shell command handlers were installe= d successfully. + @retval EFI_UNSUPPORTED The shell level required was not found. +**/ +EFI_STATUS +EFIAPI +AcpiParameterBufferModuleConfigLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + VOID *AcpiParameterBuffer; + ACPI_PARAMETER_BUFFER_DESCRIPTOR *AcpiParamBufferDescriptor; + PRM_CONFIG_PROTOCOL *PrmConfigProtocol; + + AcpiParameterBuffer =3D NULL; + AcpiParamBufferDescriptor =3D NULL; + PrmConfigProtocol =3D NULL; + + /* + In this sample PRM module, the protocol describing this sample modul= e's resources is simply + installed in the constructor. + + However, if some data is not available until later, this constructor= could register a callback + on the dependency for the data to be available (e.g. ability to comm= unicate with some device) + and then install the protocol. The requirement is that the protocol = is installed before end of DXE. + */ + + // Allocate the ACPI parameter buffer + + // A parameter buffer is arbitrary data that is handler specific. This= handler buffer is specified + // to consist of a UINT32 that represents the test data signature ('T'= , 'E', 'S', 'T'). + AcpiParameterBuffer =3D AllocateRuntimeZeroPool (sizeof (UINT32)); + ASSERT (AcpiParameterBuffer !=3D NULL); + if (AcpiParameterBuffer =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Done; + } + + // Allocate the ACPI Parameter Buffer Descriptor structure for a singl= e PRM handler + AcpiParamBufferDescriptor =3D AllocateZeroPool (sizeof (*AcpiParamBuff= erDescriptor)); + ASSERT (AcpiParamBufferDescriptor !=3D NULL); + if (AcpiParamBufferDescriptor =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Done; + } + + // Allocate the PRM Configuration protocol structure for this PRM modu= le + PrmConfigProtocol =3D AllocateZeroPool (sizeof (*PrmConfigProtocol)); + ASSERT (PrmConfigProtocol !=3D NULL); + if (PrmConfigProtocol =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Done; + } + CopyGuid (&PrmConfigProtocol->ModuleContextBuffers.ModuleGuid, &mPrmMo= duleGuid); + + // Populate the ACPI Parameter Buffer Descriptor structure + CopyGuid (&AcpiParamBufferDescriptor->HandlerGuid, &mCheckParamBufferP= rmHandlerGuid); + AcpiParamBufferDescriptor->AcpiParameterBufferAddress =3D (UINT64) (UI= NTN) AcpiParameterBuffer; + + // Populate the PRM Module Context Buffers structure + PrmConfigProtocol->ModuleContextBuffers.AcpiParameterBufferDescriptorC= ount =3D 1; + PrmConfigProtocol->ModuleContextBuffers.AcpiParameterBufferDescriptors= =3D AcpiParamBufferDescriptor; + + // + // Install the PRM Configuration Protocol for this module. This indica= tes the configuration + // library has completed resource initialization for the PRM module. + // + Status =3D gBS->InstallProtocolInterface ( + &mPrmConfigProtocolHandle, + &gPrmConfigProtocolGuid, + EFI_NATIVE_INTERFACE, + (VOID *) PrmConfigProtocol + ); + +Done: + if (EFI_ERROR (Status)) { + if (AcpiParameterBuffer !=3D NULL) { + FreePool (AcpiParameterBuffer); + } + if (AcpiParamBufferDescriptor !=3D NULL) { + FreePool (AcpiParamBufferDescriptor); + } + if (PrmConfigProtocol !=3D NULL) { + FreePool (PrmConfigProtocol); + } + } + + return Status; +} diff --git a/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleA= cpiParameterBufferModule.c b/PrmPkg/Samples/PrmSampleAcpiParameterBufferM= odule/PrmSampleAcpiParameterBufferModule.c new file mode 100644 index 000000000000..ebb5ba01a30c --- /dev/null +++ b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiPara= meterBufferModule.c @@ -0,0 +1,79 @@ +/** @file + + This PRM Module demonstrates how to define an ACPI parameter buffer th= at is used by a PRM handler. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include + +// TEMP +#include + +#define PARAM_BUFFER_TEST_SIGNATURE SIGNATURE_32('T','E','S','T'= ) + +// +// PRM Handler GUIDs +// + +// {2e4f2d13-6240-4ed0-a401-c723fbdc34e8} +#define CHECK_PARAM_BUFFER_PRM_HANDLER_GUID {0x2e4f2d13, 0x6240, 0x4ed0,= {0xa4, 0x01, 0xc7, 0x23, 0xfb, 0xdc, 0x34, 0xe8}} + +/** + A sample Platform Runtime Mechanism (PRM) handler. + + This sample handler checks if a parameter buffer is provided with the = data signature + ('T', 'E', 'S', 'T') at the beginning of the buffer. + + The contents are expected to be updated by ACPI code at OS runtime. + + @param[in] ParameterBuffer A pointer to the PRM handler parameter= buffer + @param[in] ContextBUffer A pointer to the PRM handler context b= uffer + + @retval EFI_STATUS The PRM handler executed successfully. + @retval Others An error occurred in the PRM handler. + +**/ +PRM_HANDLER_EXPORT (CheckParamBufferPrmHandler) +{ + if (ParameterBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (*((UINT32 *) ParameterBuffer) =3D=3D PARAM_BUFFER_TEST_SIGNATURE) = { + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} + +// +// Register the PRM export information for this PRM Module +// +PRM_MODULE_EXPORT ( + PRM_HANDLER_EXPORT_ENTRY (CHECK_PARAM_BUFFER_PRM_HANDLER_GUID, CheckPa= ramBufferPrmHandler) + ); + +/** + Module entry point. + + @param[in] ImageHandle The image handle. + @param[in] SystemTable A pointer to the system table. + + @retval EFI_SUCCESS This function always returns success. + +**/ +EFI_STATUS +EFIAPI +PrmSampleAcpiParameterBufferModuleInit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return EFI_SUCCESS; +} diff --git a/PrmPkg/PrmPkg.dsc b/PrmPkg/PrmPkg.dsc index 6d352dfadb26..2409378926b9 100644 --- a/PrmPkg/PrmPkg.dsc +++ b/PrmPkg/PrmPkg.dsc @@ -68,6 +68,7 @@ [Components] # PRM Libraries # $(PLATFORM_PACKAGE)/Library/DxePrmContextBufferLib/DxePrmContextBuffer= Lib.inf + $(PLATFORM_PACKAGE)/Samples/PrmSampleAcpiParameterBufferModule/Library= /DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfig= Lib.inf $(PLATFORM_PACKAGE)/Samples/PrmSampleContextBufferModule/Library/DxeCo= ntextBufferModuleConfigLib/DxeContextBufferModuleConfigLib.inf $(PLATFORM_PACKAGE)/Samples/PrmSampleHardwareAccessModule/Library/DxeH= ardwareAccessModuleConfigLib/DxeHardwareAccessModuleConfigLib.inf =20 @@ -76,6 +77,7 @@ [Components] # $(PLATFORM_PACKAGE)/PrmConfigDxe/PrmConfigDxe.inf { + NULL|$(PLATFORM_PACKAGE)/Samples/PrmSampleAcpiParameterBufferModul= e/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferMod= uleConfigLib.inf NULL|$(PLATFORM_PACKAGE)/Samples/PrmSampleContextBufferModule/Libr= ary/DxeContextBufferModuleConfigLib/DxeContextBufferModuleConfigLib.inf } =20 @@ -93,6 +95,7 @@ [Components] # PRM Sample Modules # $(PLATFORM_PACKAGE)/Samples/PrmSamplePrintModule/PrmSamplePrintModule.= inf + $(PLATFORM_PACKAGE)/Samples/PrmSampleAcpiParameterBufferModule/PrmSamp= leAcpiParameterBufferModule.inf $(PLATFORM_PACKAGE)/Samples/PrmSampleHardwareAccessModule/PrmSampleHar= dwareAccessModule.inf { DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf diff --git a/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/Dx= eAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib= .inf b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiP= arameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf new file mode 100644 index 000000000000..9ac83857cf8e --- /dev/null +++ b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiPa= rameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf @@ -0,0 +1,39 @@ +## @file +# Sample PRM Configuration Library Instance +# +# The PRM configuration library instance is responsible for initializin= g and setting the corresponding +# PRM module's configuration in the boot environment. +# +# Copyright (c) Microsoft Corporation +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeAcpiParameterBufferModuleConfigLib + FILE_GUID =3D D43D19E9-007A-4D40-AC4A-418F958AFB9D + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D NULL |DXE_DRIVER + CONSTRUCTOR =3D AcpiParameterBufferModuleConfigLibConstructor + +[Sources] + DxeAcpiParameterBufferModuleConfigLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + PrmPkg/PrmPkg.dec + +[Protocols] + gPrmConfigProtocolGuid + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiDriverEntryPoint diff --git a/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleA= cpiParameterBufferModule.inf b/PrmPkg/Samples/PrmSampleAcpiParameterBuffe= rModule/PrmSampleAcpiParameterBufferModule.inf new file mode 100644 index 000000000000..e8b71a970d83 --- /dev/null +++ b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiPara= meterBufferModule.inf @@ -0,0 +1,41 @@ +## @file +# Sample PRM Driver +# +# A sample PRM Module implementation. This PRM Module includes a PRM Mo= dule configuration library instance +# that applies the configuration for an ACPI parameter buffer in the bo= ot environment. A PRM handler +# is provided that checks for a specific value in the parameter buffer = that should be provided by ACPI +# code at OS runtime. +# +# Copyright (c) Microsoft Corporation +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PrmSampleAcpiParameterBufferModule + FILE_GUID =3D DC2A58A6-5927-4776-B995-D118A27335A2 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D PrmSampleAcpiParameterBufferModuleInit + +[Sources] + PrmSampleAcpiParameterBufferModule.c + +[Packages] + MdePkg/MdePkg.dec + PrmPkg/PrmPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiDriverEntryPoint + UefiLib + +[Depex] + TRUE + +[BuildOptions.common] + MSFT:*_*_*_DLINK_FLAGS =3D /DLL /SUBSYSTEM:CONSOLE /VERSION:1.0 + MSFT:*_*_*_GENFW_FLAGS =3D --keepoptionalheader --=20 2.28.0.windows.1