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.web12.12073.1647966042705375968 for ; Tue, 22 Mar 2022 09:20:42 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=PZyW93Ag; 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 28C9B20DE498; Tue, 22 Mar 2022 09:20:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 28C9B20DE498 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1647966042; bh=SX3XOzvKuaPCWYbYWeqyVyDOnvAevLQxg1BnsWV84LM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PZyW93AgRg3WO6GTQcSiX3x06gIfy5fIZfNX+xLjxd9Kjoz6UuFpzC7EkLdLaw5/6 Eoj6352SQ8mK0hhmndaVCRbK8NpFS+YbWBlQbUt9pb9Ed9zZKUKKWgYT9uhqoqqHuF 43NuXXm89G4NqpNZJskSC+2fVvNuC4VCGsi/ypMY= 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 06/41] PrmPkg: Add initial PrmSampleMemoryAllocationModule Date: Tue, 22 Mar 2022 12:19:12 -0400 Message-Id: <20220322161947.9319-7-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 DEPRECATED: This module is no longer relevant since OS Services that allow memory allocation have been removed. It is still present in the source tree in the event dynamic memory allocation at OS runtime is needed again. Adds a sample PRM module that demonstrates: 1. How to write a PRM module 2. How to use a basic PRM OS service 3. How to dynamically allocate memory at OS runtime 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/PrmSampleMemoryAllocationModule/PrmSampleMemoryAllocation= Module.c | 115 ++++++++++++++++++++ PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAllocation= Module.inf | 41 +++++++ 2 files changed, 156 insertions(+) diff --git a/PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemo= ryAllocationModule.c b/PrmPkg/Samples/PrmSampleMemoryAllocationModule/Prm= SampleMemoryAllocationModule.c new file mode 100644 index 000000000000..f1245664ab9c --- /dev/null +++ b/PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAlloc= ationModule.c @@ -0,0 +1,115 @@ +/** @file + + A sample PRM Module implementation. This PRM Module provides 3 PRM han= dlers that simply take a DEBUG print + function from the OS and invoke it with a debug message internal the P= RM handler. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include + +// +// PRM Handler GUIDs +// + +// {149a5cb3-6a9c-403f-940a-156abf63938a} +#define PRM_HANDLER_1_GUID {0x149a5cb3, 0x6a9c, 0x403f, {0x94, 0x0a, 0x1= 5, 0x6a, 0xbf, 0x63, 0x93, 0x8a}} + +// Note: If the signature size is modified, the PRM Handler test code in= this module needs to be updated. +#define MEMORY_ALLOCATION_TEST_DATA_SIGNATURE SIGNATURE_32('T','E','= S','T') +#define MEMORY_ALLOCATION_TEST_DATA_SIZE sizeof(UINT32) +#define MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE 256 + +/** + A sample Platform Runtime Mechanism (PRM) handler. + + This sample handler currently uses the OS_SERVICES to write a debug me= ssage + indicating this is PRM handler 1. + + @param[in] ParameterBuffer A pointer to the PRM handler parameter = buffer + @param[in] ContextBuffer A pointer to the PRM handler context bu= ffer + + @retval EFI_STATUS The PRM handler executed successfully. + @retval Others An error occurred in the PRM handler. + +**/ +EFI_STATUS +PRM_EXPORT_API +EFIAPI +PrmHandler1 ( + IN VOID *ParameterBuffer, + IN PRM_CONTEXT_BUFFER *ContextBUffer + ) +{ + EFI_STATUS Status; + UINTN Index; + VOID *NonPagedPool; + CHAR8 DebugMessage[256]; + + if (OsServices =3D=3D NULL || OsServices->DebugPrint =3D=3D NULL || Os= Services->AllocateMemory =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + OsServices->DebugPrint ("Memory Allocation PrmHandler1 entry.\n"); + OsServices->DebugPrint (" Requesting allocation of a 256 byte non-pag= ed pool...\n"); + + NonPagedPool =3D NULL; + NonPagedPool =3D OsServices->AllocateMemory (MEMORY_ALLOCATION_TEST_DA= TA_BUFFER_SIZE, FALSE); + if (NonPagedPool =3D=3D NULL) { + OsServices->DebugPrint (" NULL was returned from AllocateMemory()..= .\n"); + return EFI_OUT_OF_RESOURCES; + } + + AsciiSPrint ( + &DebugMessage[0], + ARRAY_SIZE (DebugMessage), + " Buffer address returned from AllocateMemory() =3D 0x%016lx.\n", + (UINTN) NonPagedPool + ); + OsServices->DebugPrint (&DebugMessage[0]); + + // Write the test data + OsServices->DebugPrint (" Beginning memory buffer write and read back= test...\n"); + SetMem32 (NonPagedPool, MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE, MEMOR= Y_ALLOCATION_TEST_DATA_SIGNATURE); + + // Read back and verify the test data is valid + for (Index =3D 0, Status =3D EFI_SUCCESS; Index < (MEMORY_ALLOCATION_T= EST_DATA_BUFFER_SIZE / MEMORY_ALLOCATION_TEST_DATA_SIZE); Index++) { + if (((UINT32 *) NonPagedPool)[Index] !=3D MEMORY_ALLOCATION_TEST_DAT= A_SIGNATURE) { + Status =3D EFI_DEVICE_ERROR; + break; + } + } + if (EFI_ERROR (Status)) { + OsServices->DebugPrint (" Memory write & read test failed.\n"); + } else { + OsServices->DebugPrint (" Memory write & read test passed.\n"); + } + + OsServices->DebugPrint ("Memory Allocation PrmHandler1 exit.\n"); + + return EFI_SUCCESS; +} + +// +// Register the PRM export information for this PRM Module +// +PRM_MODULE_EXPORT ( + PRM_HANDLER_EXPORT_ENTRY (PRM_HANDLER_1_GUID, PrmHandler1) + ); + +EFI_STATUS +EFIAPI +PrmSampleMemoryAllocationModuleInit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return EFI_SUCCESS; +} diff --git a/PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemo= ryAllocationModule.inf b/PrmPkg/Samples/PrmSampleMemoryAllocationModule/P= rmSampleMemoryAllocationModule.inf new file mode 100644 index 000000000000..e6798afe19e8 --- /dev/null +++ b/PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAlloc= ationModule.inf @@ -0,0 +1,41 @@ +## @file +# Sample PRM Driver +# +# This driver simply uses an OS-provided debug message print service to= write +# a debug message. Three PRM handlers are provided that each print a un= ique +# debug message. +# +# Copyright (c) Microsoft Corporation +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PrmSampleMemoryAllocationModule + FILE_GUID =3D C6B3E74A-12E3-4364-8FB4-8C8B34DD153= B + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D PrmSampleMemoryAllocationModuleInit + +[Sources] + PrmSampleMemoryAllocationModule.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + PrmPkg/PrmPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + PrintLib + UefiDriverEntryPoint + UefiLib + +[Depex] + TRUE + +[BuildOptions.common] + MSFT:*_*_*_DLINK_FLAGS =3D /DLL /SUBSYSTEM:CONSOLE --=20 2.28.0.windows.1