TianoCore EDK2 master
Loading...
Searching...
No Matches
ReportStatusCodeRouterPei.c
Go to the documentation of this file.
1
10
11EFI_PEI_RSC_HANDLER_PPI mRscHandlerPpi = {
14};
15
16EFI_PEI_PROGRESS_CODE_PPI mStatusCodePpi = {
18};
19
20EFI_PEI_PPI_DESCRIPTOR mRscHandlerPpiList[] = {
21 {
22 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
23 &gEfiPeiRscHandlerPpiGuid,
24 &mRscHandlerPpi
25 }
26};
27
28EFI_PEI_PPI_DESCRIPTOR mStatusCodePpiList[] = {
29 {
30 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
31 &gEfiPeiStatusCodePpiGuid,
32 &mStatusCodePpi
33 }
34};
35
45UINTN *
47 VOID
48 )
49{
50 UINTN *NumberOfEntries;
51
52 //
53 // Build GUID'ed HOB with PCD defined size.
54 //
55 NumberOfEntries = BuildGuidHob (
56 &gStatusCodeCallbackGuid,
57 sizeof (EFI_PEI_RSC_HANDLER_CALLBACK) * 64 + sizeof (UINTN)
58 );
59 ASSERT (NumberOfEntries != NULL);
60
61 *NumberOfEntries = 0;
62
63 return NumberOfEntries;
64}
65
83EFIAPI
85 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
86 )
87{
89 EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry;
90 UINTN *NumberOfEntries;
91 UINTN Index;
92 UINTN FreeEntryIndex;
93 UINTN *FreePacket;
94
95 if (Callback == NULL) {
96 return EFI_INVALID_PARAMETER;
97 }
98
99 Hob.Raw = GetFirstGuidHob (&gStatusCodeCallbackGuid);
100 FreePacket = NULL;
101 FreeEntryIndex = 0;
102 while (Hob.Raw != NULL) {
103 NumberOfEntries = GET_GUID_HOB_DATA (Hob);
104 CallbackEntry = (EFI_PEI_RSC_HANDLER_CALLBACK *)(NumberOfEntries + 1);
105 if ((FreePacket == NULL) && (*NumberOfEntries < 64)) {
106 //
107 // If current total number of handlers does not exceed 64, put new handler
108 // at the last of packet
109 //
110 FreePacket = NumberOfEntries;
111 FreeEntryIndex = *NumberOfEntries;
112 }
113
114 for (Index = 0; Index < *NumberOfEntries; Index++) {
115 if (CallbackEntry[Index] == Callback) {
116 //
117 // If the function was already registered. It can't be registered again.
118 //
119 return EFI_ALREADY_STARTED;
120 }
121
122 if ((FreePacket == NULL) && (CallbackEntry[Index] == NULL)) {
123 //
124 // If the total number of handlers in current packet is max value 64,
125 // search an entry with NULL pointer and fill new handler into this entry.
126 //
127 FreePacket = NumberOfEntries;
128 FreeEntryIndex = Index;
129 }
130 }
131
132 Hob.Raw = GET_NEXT_HOB (Hob);
133 Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw);
134 }
135
136 if (FreePacket == NULL) {
137 FreePacket = CreateRscHandlerCallbackPacket ();
138 }
139
140 CallbackEntry = (EFI_PEI_RSC_HANDLER_CALLBACK *)(FreePacket + 1);
141 CallbackEntry[FreeEntryIndex] = Callback;
142
143 if (*FreePacket == FreeEntryIndex) {
144 //
145 // If new registered callback is added as a new entry in the packet,
146 // increase the total number of handlers in the packet.
147 //
148 *FreePacket += 1;
149 }
150
151 return EFI_SUCCESS;
152}
153
168EFIAPI
170 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
171 )
172{
174 EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry;
175 UINTN *NumberOfEntries;
176 UINTN Index;
177
178 if (Callback == NULL) {
179 return EFI_INVALID_PARAMETER;
180 }
181
182 Hob.Raw = GetFirstGuidHob (&gStatusCodeCallbackGuid);
183 while (Hob.Raw != NULL) {
184 NumberOfEntries = GET_GUID_HOB_DATA (Hob);
185 CallbackEntry = (EFI_PEI_RSC_HANDLER_CALLBACK *)(NumberOfEntries + 1);
186 for (Index = 0; Index < *NumberOfEntries; Index++) {
187 if (CallbackEntry[Index] == Callback) {
188 //
189 // Set removed entry as NULL.
190 //
191 CallbackEntry[Index] = NULL;
192 return EFI_SUCCESS;
193 }
194 }
195
196 Hob.Raw = GET_NEXT_HOB (Hob);
197 Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw);
198 }
199
200 return EFI_NOT_FOUND;
201}
202
230EFIAPI
232 IN CONST EFI_PEI_SERVICES **PeiServices,
233 IN EFI_STATUS_CODE_TYPE CodeType,
235 IN UINT32 Instance,
236 IN CONST EFI_GUID *CallerId OPTIONAL,
237 IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
238 )
239{
241 EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry;
242 UINTN *NumberOfEntries;
243 UINTN Index;
244
245 Hob.Raw = GetFirstGuidHob (&gStatusCodeCallbackGuid);
246 while (Hob.Raw != NULL) {
247 NumberOfEntries = GET_GUID_HOB_DATA (Hob);
248 CallbackEntry = (EFI_PEI_RSC_HANDLER_CALLBACK *)(NumberOfEntries + 1);
249 for (Index = 0; Index < *NumberOfEntries; Index++) {
250 if (CallbackEntry[Index] != NULL) {
251 CallbackEntry[Index](
252 PeiServices,
253 CodeType,
254 Value,
255 Instance,
256 CallerId,
257 Data
258 );
259 }
260 }
261
262 Hob.Raw = GET_NEXT_HOB (Hob);
263 Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw);
264 }
265
266 return EFI_SUCCESS;
267}
268
282EFIAPI
284 IN EFI_PEI_FILE_HANDLE FileHandle,
285 IN CONST EFI_PEI_SERVICES **PeiServices
286 )
287{
288 EFI_STATUS Status;
289 EFI_PEI_PPI_DESCRIPTOR *OldDescriptor;
290 EFI_PEI_PROGRESS_CODE_PPI *OldStatusCodePpi;
291
293
294 //
295 // Install Report Status Code Handler PPI
296 //
297 Status = PeiServicesInstallPpi (mRscHandlerPpiList);
298 ASSERT_EFI_ERROR (Status);
299
300 //
301 // Install Status Code PPI. PI spec specifies that there can be only one instance
302 // of this PPI in system. So first check if other instance already exists.
303 // If no other instance exists, then just install the PPI.
304 // If other instance already exists, then reinstall it.
305 //
306 Status = PeiServicesLocatePpi (
307 &gEfiPeiStatusCodePpiGuid,
308 0,
309 &OldDescriptor,
310 (VOID **)&OldStatusCodePpi
311 );
312 if (!EFI_ERROR (Status)) {
313 Status = PeiServicesReInstallPpi (OldDescriptor, mStatusCodePpiList);
314 } else {
315 Status = PeiServicesInstallPpi (mStatusCodePpiList);
316 }
317
318 ASSERT_EFI_ERROR (Status);
319
320 return EFI_SUCCESS;
321}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
Definition: HobLib.c:336
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
Definition: HobLib.c:176
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
EFI_STATUS EFIAPI PeiServicesReInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi, IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
UINT32 EFI_STATUS_CODE_VALUE
Definition: PiStatusCode.h:67
UINT32 EFI_STATUS_CODE_TYPE
Definition: PiStatusCode.h:24
EFI_STATUS EFIAPI GenericStatusCodePeiEntry(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
UINTN * CreateRscHandlerCallbackPacket(VOID)
EFI_STATUS EFIAPI Unregister(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
EFI_STATUS EFIAPI ReportDispatcher(IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_STATUS_CODE_TYPE CodeType, IN EFI_STATUS_CODE_VALUE Value, IN UINT32 Instance, IN CONST EFI_GUID *CallerId OPTIONAL, IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213