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
;
113 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
114 if (CallbackEntry
[Index
] == Callback
) {
116 // If the function was already registered. It can't be registered again.
118 return EFI_ALREADY_STARTED
;
120 if (FreePacket
== NULL
&& CallbackEntry
[Index
] == NULL
) {
122 // If the total number of handlers in current packet is max value 64,
123 // search an entry with NULL pointer and fill new handler into this entry.
125 FreePacket
= NumberOfEntries
;
126 FreeEntryIndex
= Index
;
129 Hob
.Raw
= GET_NEXT_HOB (Hob
);
130 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
133 if (FreePacket
== NULL
) {
134 FreePacket
= CreateRscHandlerCallbackPacket();
137 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (FreePacket
+ 1);
138 CallbackEntry
[FreeEntryIndex
] = Callback
;
140 if (*FreePacket
== FreeEntryIndex
) {
142 // If new registered callback is added as a new entry in the packet,
143 // increase the total number of handlers in the packet.
152 Remove a previously registered callback function from the notification list.
154 ReportStatusCode() messages will no longer be forwarded to the Callback function.
156 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
159 @retval EFI_SUCCESS The function was successfully unregistered.
160 @retval EFI_INVALID_PARAMETER The callback function was NULL.
161 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
167 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
170 EFI_PEI_HOB_POINTERS Hob
;
171 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
172 UINTN
*NumberOfEntries
;
175 if (Callback
== NULL
) {
176 return EFI_INVALID_PARAMETER
;
179 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
180 while (Hob
.Raw
!= NULL
) {
181 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
182 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
183 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
184 if (CallbackEntry
[Index
] == Callback
) {
186 // Set removed entry as NULL.
188 CallbackEntry
[Index
] = NULL
;
192 Hob
.Raw
= GET_NEXT_HOB (Hob
);
193 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
196 return EFI_NOT_FOUND
;
200 Publishes an interface that allows PEIMs to report status codes.
202 This function implements EFI_PEI_PROGRESS_CODE_PPI.ReportStatusCode().
203 It publishes an interface that allows PEIMs to report status codes.
205 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
206 @param CodeType Indicates the type of status code being reported.
207 @param Value Describes the current status of a hardware or
208 software entity. This includes information about the class and
209 subclass that is used to classify the entity as well as an operation.
210 For progress codes, the operation is the current activity.
211 For error codes, it is the exception.For debug codes,it is not defined at this time.
212 @param Instance The enumeration of a hardware or software entity within
213 the system. A system may contain multiple entities that match a class/subclass
214 pairing. The instance differentiates between them. An instance of 0 indicates
215 that instance information is unavailable, not meaningful, or not relevant.
216 Valid instance numbers start with 1.
217 @param CallerId This optional parameter may be used to identify the caller.
218 This parameter allows the status code driver to apply different rules to
220 @param Data This optional parameter may be used to pass additional data.
222 @retval EFI_SUCCESS The function completed successfully.
228 IN CONST EFI_PEI_SERVICES
**PeiServices
,
229 IN EFI_STATUS_CODE_TYPE CodeType
,
230 IN EFI_STATUS_CODE_VALUE Value
,
232 IN CONST EFI_GUID
*CallerId OPTIONAL
,
233 IN CONST EFI_STATUS_CODE_DATA
*Data OPTIONAL
236 EFI_PEI_HOB_POINTERS Hob
;
237 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
238 UINTN
*NumberOfEntries
;
241 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
242 while (Hob
.Raw
!= NULL
) {
243 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
244 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
245 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
246 if (CallbackEntry
[Index
] != NULL
) {
247 CallbackEntry
[Index
](
257 Hob
.Raw
= GET_NEXT_HOB (Hob
);
258 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
265 Entry point of Status Code PEIM.
267 This function is the entry point of this Status Code Router PEIM.
268 It produces Report Stataus Code Handler PPI and Status Code PPI.
270 @param FileHandle Handle of the file being invoked.
271 @param PeiServices Describes the list of possible PEI Services.
273 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
278 GenericStatusCodePeiEntry (
279 IN EFI_PEI_FILE_HANDLE FileHandle
,
280 IN CONST EFI_PEI_SERVICES
**PeiServices
284 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
285 EFI_PEI_PROGRESS_CODE_PPI
*OldStatusCodePpi
;
287 CreateRscHandlerCallbackPacket ();
290 // Install Report Status Code Handler PPI
292 Status
= PeiServicesInstallPpi (mRscHandlerPpiList
);
293 ASSERT_EFI_ERROR (Status
);
296 // Install Status Code PPI. PI spec specifies that there can be only one instance
297 // of this PPI in system. So first check if other instance already exists.
298 // If no other instance exists, then just install the PPI.
299 // If other instance already exists, then reinstall it.
301 Status
= PeiServicesLocatePpi (
302 &gEfiPeiStatusCodePpiGuid
,
305 (VOID
**) &OldStatusCodePpi
307 if (!EFI_ERROR (Status
)) {
308 Status
= PeiServicesReInstallPpi (OldDescriptor
, mStatusCodePpiList
);
310 Status
= PeiServicesInstallPpi (mStatusCodePpiList
);
312 ASSERT_EFI_ERROR (Status
);