]> git.proxmox.com Git - mirror_edk2.git/blob - PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.c
PrmPkg/SampleAcpiParameterBufferModule: Add initial module
[mirror_edk2.git] / PrmPkg / Samples / PrmSampleAcpiParameterBufferModule / Library / DxeAcpiParameterBufferModuleConfigLib / DxeAcpiParameterBufferModuleConfigLib.c
1 /** @file
2
3 The boot services environment configuration library for the ACPI Parameter Buffer Sample PRM module.
4
5 Copyright (c) Microsoft Corporation
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/MemoryAllocationLib.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Protocol/PrmConfig.h>
16
17 STATIC EFI_HANDLE mPrmConfigProtocolHandle;
18
19 // {dc2a58a6-5927-4776-b995-d118a27335a2}
20 STATIC CONST EFI_GUID mPrmModuleGuid = {0xdc2a58a6, 0x5927, 0x4776, {0xb9, 0x95, 0xd1, 0x18, 0xa2, 0x73, 0x35, 0xa2}};
21
22 // {2e4f2d13-6240-4ed0-a401-c723fbdc34e8}
23 STATIC CONST EFI_GUID mCheckParamBufferPrmHandlerGuid = {0x2e4f2d13, 0x6240, 0x4ed0, {0xa4, 0x01, 0xc7, 0x23, 0xfb, 0xdc, 0x34, 0xe8}};
24
25 /**
26 Constructor of the PRM configuration library.
27
28 @param[in] ImageHandle The image handle of the driver.
29 @param[in] SystemTable The EFI System Table pointer.
30
31 @retval EFI_SUCCESS The shell command handlers were installed successfully.
32 @retval EFI_UNSUPPORTED The shell level required was not found.
33 **/
34 EFI_STATUS
35 EFIAPI
36 AcpiParameterBufferModuleConfigLibConstructor (
37 IN EFI_HANDLE ImageHandle,
38 IN EFI_SYSTEM_TABLE *SystemTable
39 )
40 {
41 EFI_STATUS Status;
42 VOID *AcpiParameterBuffer;
43 ACPI_PARAMETER_BUFFER_DESCRIPTOR *AcpiParamBufferDescriptor;
44 PRM_CONFIG_PROTOCOL *PrmConfigProtocol;
45
46 AcpiParameterBuffer = NULL;
47 AcpiParamBufferDescriptor = NULL;
48 PrmConfigProtocol = NULL;
49
50 /*
51 In this sample PRM module, the protocol describing this sample module's resources is simply
52 installed in the constructor.
53
54 However, if some data is not available until later, this constructor could register a callback
55 on the dependency for the data to be available (e.g. ability to communicate with some device)
56 and then install the protocol. The requirement is that the protocol is installed before end of DXE.
57 */
58
59 // Allocate the ACPI parameter buffer
60
61 // A parameter buffer is arbitrary data that is handler specific. This handler buffer is specified
62 // to consist of a UINT32 that represents the test data signature ('T', 'E', 'S', 'T').
63 AcpiParameterBuffer = AllocateRuntimeZeroPool (sizeof (UINT32));
64 ASSERT (AcpiParameterBuffer != NULL);
65 if (AcpiParameterBuffer == NULL) {
66 Status = EFI_OUT_OF_RESOURCES;
67 goto Done;
68 }
69
70 // Allocate the ACPI Parameter Buffer Descriptor structure for a single PRM handler
71 AcpiParamBufferDescriptor = AllocateZeroPool (sizeof (*AcpiParamBufferDescriptor));
72 ASSERT (AcpiParamBufferDescriptor != NULL);
73 if (AcpiParamBufferDescriptor == NULL) {
74 Status = EFI_OUT_OF_RESOURCES;
75 goto Done;
76 }
77
78 // Allocate the PRM Configuration protocol structure for this PRM module
79 PrmConfigProtocol = AllocateZeroPool (sizeof (*PrmConfigProtocol));
80 ASSERT (PrmConfigProtocol != NULL);
81 if (PrmConfigProtocol == NULL) {
82 Status = EFI_OUT_OF_RESOURCES;
83 goto Done;
84 }
85 CopyGuid (&PrmConfigProtocol->ModuleContextBuffers.ModuleGuid, &mPrmModuleGuid);
86
87 // Populate the ACPI Parameter Buffer Descriptor structure
88 CopyGuid (&AcpiParamBufferDescriptor->HandlerGuid, &mCheckParamBufferPrmHandlerGuid);
89 AcpiParamBufferDescriptor->AcpiParameterBufferAddress = (UINT64) (UINTN) AcpiParameterBuffer;
90
91 // Populate the PRM Module Context Buffers structure
92 PrmConfigProtocol->ModuleContextBuffers.AcpiParameterBufferDescriptorCount = 1;
93 PrmConfigProtocol->ModuleContextBuffers.AcpiParameterBufferDescriptors = AcpiParamBufferDescriptor;
94
95 //
96 // Install the PRM Configuration Protocol for this module. This indicates the configuration
97 // library has completed resource initialization for the PRM module.
98 //
99 Status = gBS->InstallProtocolInterface (
100 &mPrmConfigProtocolHandle,
101 &gPrmConfigProtocolGuid,
102 EFI_NATIVE_INTERFACE,
103 (VOID *) PrmConfigProtocol
104 );
105
106 Done:
107 if (EFI_ERROR (Status)) {
108 if (AcpiParameterBuffer != NULL) {
109 FreePool (AcpiParameterBuffer);
110 }
111 if (AcpiParamBufferDescriptor != NULL) {
112 FreePool (AcpiParamBufferDescriptor);
113 }
114 if (PrmConfigProtocol != NULL) {
115 FreePool (PrmConfigProtocol);
116 }
117 }
118
119 return Status;
120 }