TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeContextBufferModuleConfigLib.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
15#include <Protocol/PrmConfig.h>
17
18#include <PrmContextBuffer.h>
19#include <PrmDataBuffer.h>
20
21STATIC EFI_HANDLE mPrmConfigProtocolHandle;
22
23// {5a6cf42b-8bb4-472c-a233-5c4dc4033dc7}
24STATIC CONST EFI_GUID mPrmModuleGuid = {
25 0x5a6cf42b, 0x8bb4, 0x472c, { 0xa2, 0x33, 0x5c, 0x4d, 0xc4, 0x03, 0x3d, 0xc7 }
26};
27
28// {e1466081-7562-430f-896b-b0e523dc335a}
29STATIC CONST EFI_GUID mCheckStaticDataBufferPrmHandlerGuid = {
30 0xe1466081, 0x7562, 0x430f, { 0x89, 0x6b, 0xb0, 0xe5, 0x23, 0xdc, 0x33, 0x5a }
31};
32
45 )
46{
47 if (StaticDataBuffer == NULL) {
48 return EFI_INVALID_PARAMETER;
49 }
50
51 //
52 // Note: In a real-world module these values would likely come from somewhere
53 // like a Setup menu option, PCD, binary data, runtime device info, etc. Ideally,
54 // this configuration library would be provided an API to get what it needs (the data)
55 // and not be concerned with how the data is provided. This makes the PRM module more
56 // portable across systems.
57 //
58 StaticDataBuffer->Policy1Enabled = TRUE;
59 StaticDataBuffer->Policy2Enabled = FALSE;
60 SetMem (StaticDataBuffer->SomeValueArray, ARRAY_SIZE (StaticDataBuffer->SomeValueArray), 'D');
61
62 return EFI_SUCCESS;
63}
64
77 OUT PRM_DATA_BUFFER **StaticDataBuffer
78 )
79{
80 EFI_STATUS Status;
81 PRM_DATA_BUFFER *DataBuffer;
82 UINTN DataBufferLength;
83
84 if (StaticDataBuffer == NULL) {
85 return EFI_INVALID_PARAMETER;
86 }
87
88 *StaticDataBuffer = NULL;
89
90 //
91 // Length of the data buffer = Buffer Header Size + Buffer Data Size
92 //
93 DataBufferLength = sizeof (PRM_DATA_BUFFER_HEADER) + sizeof (STATIC_DATA_SAMPLE_CONTEXT_BUFFER_MODULE);
94
95 DataBuffer = AllocateRuntimeZeroPool (DataBufferLength);
96 if (DataBuffer == NULL) {
97 return EFI_OUT_OF_RESOURCES;
98 }
99
100 //
101 // Initialize the data buffer header
102 //
103 DataBuffer->Header.Signature = PRM_DATA_BUFFER_HEADER_SIGNATURE;
104 DataBuffer->Header.Length = (UINT32)DataBufferLength;
105
107 ASSERT_EFI_ERROR (Status);
108
109 *StaticDataBuffer = DataBuffer;
110 return EFI_SUCCESS;
111}
112
123EFIAPI
125 IN EFI_HANDLE ImageHandle,
126 IN EFI_SYSTEM_TABLE *SystemTable
127 )
128{
129 EFI_STATUS Status;
130 PRM_CONTEXT_BUFFER *PrmContextBuffer;
131 PRM_DATA_BUFFER *StaticDataBuffer;
132 PRM_CONFIG_PROTOCOL *PrmConfigProtocol;
133
134 PrmContextBuffer = NULL;
135 StaticDataBuffer = NULL;
136 PrmConfigProtocol = NULL;
137
138 /*
139 In this sample PRM module, the protocol describing this sample module's resources is simply
140 installed in the constructor.
141
142 However, if some data is not available until later, this constructor could register a callback
143 on the dependency for the data to be available (e.g. ability to communicate with some device)
144 and then install the protocol. The requirement is that the protocol is installed before end of DXE.
145 */
146
147 //
148 // Allocate and populate the static data buffer
149 //
150 Status = GetStaticDataBuffer (&StaticDataBuffer);
151 ASSERT_EFI_ERROR (Status);
152 if (EFI_ERROR (Status) || (StaticDataBuffer == NULL)) {
153 goto Done;
154 }
155
156 //
157 // Allocate and populate the context buffer
158 //
159
160 //
161 // This context buffer is not actually used by PRM handler at OS runtime. The OS will allocate
162 // the actual context buffer passed to the PRM handler.
163 //
164 // This context buffer is used internally in the firmware to associate a PRM handler with a
165 // a static data buffer and a runtime MMIO ranges array so those can be placed into the
166 // PRM_HANDLER_INFORMATION_STRUCT and PRM_MODULE_INFORMATION_STRUCT respectively for the PRM handler.
167 //
168 PrmContextBuffer = AllocateZeroPool (sizeof (*PrmContextBuffer));
169 ASSERT (PrmContextBuffer != NULL);
170 if (PrmContextBuffer == NULL) {
171 Status = EFI_OUT_OF_RESOURCES;
172 goto Done;
173 }
174
175 CopyGuid (&PrmContextBuffer->HandlerGuid, &mCheckStaticDataBufferPrmHandlerGuid);
176 PrmContextBuffer->Signature = PRM_CONTEXT_BUFFER_SIGNATURE;
177 PrmContextBuffer->Version = PRM_CONTEXT_BUFFER_INTERFACE_VERSION;
178 PrmContextBuffer->StaticDataBuffer = StaticDataBuffer;
179
180 PrmConfigProtocol = AllocateZeroPool (sizeof (*PrmConfigProtocol));
181 ASSERT (PrmConfigProtocol != NULL);
182 if (PrmConfigProtocol == NULL) {
183 Status = EFI_OUT_OF_RESOURCES;
184 goto Done;
185 }
186
187 CopyGuid (&PrmConfigProtocol->ModuleContextBuffers.ModuleGuid, &mPrmModuleGuid);
188 PrmConfigProtocol->ModuleContextBuffers.BufferCount = 1;
189 PrmConfigProtocol->ModuleContextBuffers.Buffer = PrmContextBuffer;
190
191 //
192 // Install the PRM Configuration Protocol for this module. This indicates the configuration
193 // library has completed resource initialization for the PRM module.
194 //
195 Status = gBS->InstallProtocolInterface (
196 &mPrmConfigProtocolHandle,
197 &gPrmConfigProtocolGuid,
199 (VOID *)PrmConfigProtocol
200 );
201
202Done:
203 if (EFI_ERROR (Status)) {
204 if (StaticDataBuffer != NULL) {
205 FreePool (StaticDataBuffer);
206 }
207
208 if (PrmContextBuffer != NULL) {
209 FreePool (PrmContextBuffer);
210 }
211
212 if (PrmConfigProtocol != NULL) {
213 FreePool (PrmConfigProtocol);
214 }
215 }
216
217 return Status;
218}
UINT64 UINTN
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
EFI_STATUS GetStaticDataBuffer(OUT PRM_DATA_BUFFER **StaticDataBuffer)
EFI_STATUS EFIAPI ContextBufferModuleConfigLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS PopulateStaticDataBuffer(OUT STATIC_DATA_SAMPLE_CONTEXT_BUFFER_MODULE *StaticDataBuffer)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateRuntimeZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
Definition: Base.h:213
PRM_DATA_BUFFER * StaticDataBuffer
PRM_DATA_BUFFER_HEADER Header
Definition: PrmDataBuffer.h:40
PRM_CONTEXT_BUFFER * Buffer