3 A sample PRM Module implementation. This PRM Module provides 3 PRM handlers that simply take a DEBUG print
4 function from the OS and invoke it with a debug message internal the PRM handler.
6 Copyright (c) Microsoft Corporation
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <PrmModule.h>
13 #include <Library/BaseLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/PrintLib.h>
16 #include <Library/UefiLib.h>
22 // {149a5cb3-6a9c-403f-940a-156abf63938a}
23 #define PRM_HANDLER_1_GUID {0x149a5cb3, 0x6a9c, 0x403f, {0x94, 0x0a, 0x15, 0x6a, 0xbf, 0x63, 0x93, 0x8a}}
25 // Note: If the signature size is modified, the PRM Handler test code in this module needs to be updated.
26 #define MEMORY_ALLOCATION_TEST_DATA_SIGNATURE SIGNATURE_32('T','E','S','T')
27 #define MEMORY_ALLOCATION_TEST_DATA_SIZE sizeof(UINT32)
28 #define MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE 256
31 A sample Platform Runtime Mechanism (PRM) handler.
33 This sample handler currently uses the OS_SERVICES to write a debug message
34 indicating this is PRM handler 1.
36 @param[in] ParameterBuffer A pointer to the PRM handler parameter buffer
37 @param[in] ContextBuffer A pointer to the PRM handler context buffer
39 @retval EFI_STATUS The PRM handler executed successfully.
40 @retval Others An error occurred in the PRM handler.
47 IN VOID
*ParameterBuffer
,
48 IN PRM_CONTEXT_BUFFER
*ContextBUffer
54 CHAR8 DebugMessage
[256];
56 if (OsServices
== NULL
|| OsServices
->DebugPrint
== NULL
|| OsServices
->AllocateMemory
== NULL
) {
57 return EFI_INVALID_PARAMETER
;
60 OsServices
->DebugPrint ("Memory Allocation PrmHandler1 entry.\n");
61 OsServices
->DebugPrint (" Requesting allocation of a 256 byte non-paged pool...\n");
64 NonPagedPool
= OsServices
->AllocateMemory (MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE
, FALSE
);
65 if (NonPagedPool
== NULL
) {
66 OsServices
->DebugPrint (" NULL was returned from AllocateMemory()...\n");
67 return EFI_OUT_OF_RESOURCES
;
72 ARRAY_SIZE (DebugMessage
),
73 " Buffer address returned from AllocateMemory() = 0x%016lx.\n",
76 OsServices
->DebugPrint (&DebugMessage
[0]);
78 // Write the test data
79 OsServices
->DebugPrint (" Beginning memory buffer write and read back test...\n");
80 SetMem32 (NonPagedPool
, MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE
, MEMORY_ALLOCATION_TEST_DATA_SIGNATURE
);
82 // Read back and verify the test data is valid
83 for (Index
= 0, Status
= EFI_SUCCESS
; Index
< (MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE
/ MEMORY_ALLOCATION_TEST_DATA_SIZE
); Index
++) {
84 if (((UINT32
*) NonPagedPool
)[Index
] != MEMORY_ALLOCATION_TEST_DATA_SIGNATURE
) {
85 Status
= EFI_DEVICE_ERROR
;
89 if (EFI_ERROR (Status
)) {
90 OsServices
->DebugPrint (" Memory write & read test failed.\n");
92 OsServices
->DebugPrint (" Memory write & read test passed.\n");
95 OsServices
->DebugPrint ("Memory Allocation PrmHandler1 exit.\n");
101 // Register the PRM export information for this PRM Module
104 PRM_HANDLER_EXPORT_ENTRY (PRM_HANDLER_1_GUID
, PrmHandler1
)
109 PrmSampleMemoryAllocationModuleInit (
110 IN EFI_HANDLE ImageHandle
,
111 IN EFI_SYSTEM_TABLE
*SystemTable