2 Report Status Code Router PEIM which produces Report Stataus Code Handler PPI and Status Code PPI.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "ReportStatusCodeRouterPei.h"
11 EFI_PEI_RSC_HANDLER_PPI mRscHandlerPpi
= {
16 EFI_PEI_PROGRESS_CODE_PPI mStatusCodePpi
= {
20 EFI_PEI_PPI_DESCRIPTOR mRscHandlerPpiList
[] = {
22 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
23 &gEfiPeiRscHandlerPpiGuid
,
28 EFI_PEI_PPI_DESCRIPTOR mStatusCodePpiList
[] = {
30 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
31 &gEfiPeiStatusCodePpiGuid
,
37 Worker function to create one memory status code GUID'ed HOB,
38 using PacketIndex to identify the packet.
40 @param PacketIndex Index of records packet.
42 @return Pointer to the memory status code packet.
46 CreateRscHandlerCallbackPacket (
50 UINTN
*NumberOfEntries
;
53 // Build GUID'ed HOB with PCD defined size.
55 NumberOfEntries
= BuildGuidHob (
56 &gStatusCodeCallbackGuid
,
57 sizeof (EFI_PEI_RSC_HANDLER_CALLBACK
) * 64 + sizeof (UINTN
)
59 ASSERT (NumberOfEntries
!= NULL
);
63 return NumberOfEntries
;
67 Register the callback function for ReportStatusCode() notification.
69 When this function is called the function pointer is added to an internal list and any future calls to
70 ReportStatusCode() will be forwarded to the Callback function.
72 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is called
73 when a call to ReportStatusCode() occurs.
75 @retval EFI_SUCCESS Function was successfully registered.
76 @retval EFI_INVALID_PARAMETER The callback function was NULL.
77 @retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be
79 @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again.
85 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
88 EFI_PEI_HOB_POINTERS Hob
;
89 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
90 UINTN
*NumberOfEntries
;
95 if (Callback
== NULL
) {
96 return EFI_INVALID_PARAMETER
;
99 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
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)) {
107 // If current total number of handlers does not exceed 64, put new handler
108 // at the last of packet
110 FreePacket
= NumberOfEntries
;
111 FreeEntryIndex
= *NumberOfEntries
;
114 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
115 if (CallbackEntry
[Index
] == Callback
) {
117 // If the function was already registered. It can't be registered again.
119 return EFI_ALREADY_STARTED
;
122 if ((FreePacket
== NULL
) && (CallbackEntry
[Index
] == NULL
)) {
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.
127 FreePacket
= NumberOfEntries
;
128 FreeEntryIndex
= Index
;
132 Hob
.Raw
= GET_NEXT_HOB (Hob
);
133 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
136 if (FreePacket
== NULL
) {
137 FreePacket
= CreateRscHandlerCallbackPacket ();
140 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*)(FreePacket
+ 1);
141 CallbackEntry
[FreeEntryIndex
] = Callback
;
143 if (*FreePacket
== FreeEntryIndex
) {
145 // If new registered callback is added as a new entry in the packet,
146 // increase the total number of handlers in the packet.
155 Remove a previously registered callback function from the notification list.
157 ReportStatusCode() messages will no longer be forwarded to the Callback function.
159 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
162 @retval EFI_SUCCESS The function was successfully unregistered.
163 @retval EFI_INVALID_PARAMETER The callback function was NULL.
164 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
170 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
173 EFI_PEI_HOB_POINTERS Hob
;
174 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
175 UINTN
*NumberOfEntries
;
178 if (Callback
== NULL
) {
179 return EFI_INVALID_PARAMETER
;
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
) {
189 // Set removed entry as NULL.
191 CallbackEntry
[Index
] = NULL
;
196 Hob
.Raw
= GET_NEXT_HOB (Hob
);
197 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
200 return EFI_NOT_FOUND
;
204 Publishes an interface that allows PEIMs to report status codes.
206 This function implements EFI_PEI_PROGRESS_CODE_PPI.ReportStatusCode().
207 It publishes an interface that allows PEIMs to report status codes.
209 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
210 @param CodeType Indicates the type of status code being reported.
211 @param Value Describes the current status of a hardware or
212 software entity. This includes information about the class and
213 subclass that is used to classify the entity as well as an operation.
214 For progress codes, the operation is the current activity.
215 For error codes, it is the exception.For debug codes,it is not defined at this time.
216 @param Instance The enumeration of a hardware or software entity within
217 the system. A system may contain multiple entities that match a class/subclass
218 pairing. The instance differentiates between them. An instance of 0 indicates
219 that instance information is unavailable, not meaningful, or not relevant.
220 Valid instance numbers start with 1.
221 @param CallerId This optional parameter may be used to identify the caller.
222 This parameter allows the status code driver to apply different rules to
224 @param Data This optional parameter may be used to pass additional data.
226 @retval EFI_SUCCESS The function completed successfully.
232 IN CONST EFI_PEI_SERVICES
**PeiServices
,
233 IN EFI_STATUS_CODE_TYPE CodeType
,
234 IN EFI_STATUS_CODE_VALUE Value
,
236 IN CONST EFI_GUID
*CallerId OPTIONAL
,
237 IN CONST EFI_STATUS_CODE_DATA
*Data OPTIONAL
240 EFI_PEI_HOB_POINTERS Hob
;
241 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
242 UINTN
*NumberOfEntries
;
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
](
262 Hob
.Raw
= GET_NEXT_HOB (Hob
);
263 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
270 Entry point of Status Code PEIM.
272 This function is the entry point of this Status Code Router PEIM.
273 It produces Report Stataus Code Handler PPI and Status Code PPI.
275 @param FileHandle Handle of the file being invoked.
276 @param PeiServices Describes the list of possible PEI Services.
278 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
283 GenericStatusCodePeiEntry (
284 IN EFI_PEI_FILE_HANDLE FileHandle
,
285 IN CONST EFI_PEI_SERVICES
**PeiServices
289 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
290 EFI_PEI_PROGRESS_CODE_PPI
*OldStatusCodePpi
;
292 CreateRscHandlerCallbackPacket ();
295 // Install Report Status Code Handler PPI
297 Status
= PeiServicesInstallPpi (mRscHandlerPpiList
);
298 ASSERT_EFI_ERROR (Status
);
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.
306 Status
= PeiServicesLocatePpi (
307 &gEfiPeiStatusCodePpiGuid
,
310 (VOID
**)&OldStatusCodePpi
312 if (!EFI_ERROR (Status
)) {
313 Status
= PeiServicesReInstallPpi (OldDescriptor
, mStatusCodePpiList
);
315 Status
= PeiServicesInstallPpi (mStatusCodePpiList
);
318 ASSERT_EFI_ERROR (Status
);