2 Report Status Code Router PEIM which produces Report Stataus Code Handler PPI and Status Code PPI.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "ReportStatusCodeRouterPei.h"
17 EFI_PEI_RSC_HANDLER_PPI mRscHandlerPpi
= {
22 EFI_PEI_PROGRESS_CODE_PPI mStatusCodePpi
= {
26 EFI_PEI_PPI_DESCRIPTOR mRscHandlerPpiList
[] = {
28 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
29 &gEfiPeiRscHandlerPpiGuid
,
34 EFI_PEI_PPI_DESCRIPTOR mStatusCodePpiList
[] = {
36 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
37 &gEfiPeiStatusCodePpiGuid
,
43 Worker function to create one memory status code GUID'ed HOB,
44 using PacketIndex to identify the packet.
46 @param PacketIndex Index of records packet.
48 @return Pointer to the memory status code packet.
52 CreateRscHandlerCallbackPacket (
56 UINTN
*NumberOfEntries
;
59 // Build GUID'ed HOB with PCD defined size.
61 NumberOfEntries
= BuildGuidHob (
62 &gStatusCodeCallbackGuid
,
63 sizeof (EFI_PEI_RSC_HANDLER_CALLBACK
) * 64 + sizeof (UINTN
)
65 ASSERT (NumberOfEntries
!= NULL
);
69 return NumberOfEntries
;
73 Register the callback function for ReportStatusCode() notification.
75 When this function is called the function pointer is added to an internal list and any future calls to
76 ReportStatusCode() will be forwarded to the Callback function.
78 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is called
79 when a call to ReportStatusCode() occurs.
81 @retval EFI_SUCCESS Function was successfully registered.
82 @retval EFI_INVALID_PARAMETER The callback function was NULL.
83 @retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be
85 @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again.
91 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
94 EFI_PEI_HOB_POINTERS Hob
;
95 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
96 UINTN
*NumberOfEntries
;
101 if (Callback
== NULL
) {
102 return EFI_INVALID_PARAMETER
;
105 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
108 while (Hob
.Raw
!= NULL
) {
109 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
110 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
111 if (FreePacket
== NULL
&& *NumberOfEntries
< 64) {
113 // If current total number of handlers does not exceed 64, put new handler
114 // at the last of packet
116 FreePacket
= NumberOfEntries
;
117 FreeEntryIndex
= *NumberOfEntries
;
119 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
120 if (CallbackEntry
[Index
] == Callback
) {
122 // If the function was already registered. It can't be registered again.
124 return EFI_ALREADY_STARTED
;
126 if (FreePacket
== NULL
&& CallbackEntry
[Index
] == NULL
) {
128 // If the total number of handlers in current packet is max value 64,
129 // search an entry with NULL pointer and fill new handler into this entry.
131 FreePacket
= NumberOfEntries
;
132 FreeEntryIndex
= Index
;
135 Hob
.Raw
= GET_NEXT_HOB (Hob
);
136 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
139 if (FreePacket
== NULL
) {
140 FreePacket
= CreateRscHandlerCallbackPacket();
143 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (FreePacket
+ 1);
144 CallbackEntry
[FreeEntryIndex
] = Callback
;
146 if (*FreePacket
== FreeEntryIndex
) {
148 // If new registered callback is added as a new entry in the packet,
149 // increase the total number of handlers in the packet.
158 Remove a previously registered callback function from the notification list.
160 ReportStatusCode() messages will no longer be forwarded to the Callback function.
162 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
165 @retval EFI_SUCCESS The function was successfully unregistered.
166 @retval EFI_INVALID_PARAMETER The callback function was NULL.
167 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
173 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
176 EFI_PEI_HOB_POINTERS Hob
;
177 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
178 UINTN
*NumberOfEntries
;
181 if (Callback
== NULL
) {
182 return EFI_INVALID_PARAMETER
;
185 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
186 while (Hob
.Raw
!= NULL
) {
187 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
188 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
189 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
190 if (CallbackEntry
[Index
] == Callback
) {
192 // Set removed entry as NULL.
194 CallbackEntry
[Index
] = NULL
;
198 Hob
.Raw
= GET_NEXT_HOB (Hob
);
199 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
202 return EFI_NOT_FOUND
;
206 Publishes an interface that allows PEIMs to report status codes.
208 This function implements EFI_PEI_PROGRESS_CODE_PPI.ReportStatusCode().
209 It publishes an interface that allows PEIMs to report status codes.
211 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
212 @param CodeType Indicates the type of status code being reported.
213 @param Value Describes the current status of a hardware or
214 software entity. This includes information about the class and
215 subclass that is used to classify the entity as well as an operation.
216 For progress codes, the operation is the current activity.
217 For error codes, it is the exception.For debug codes,it is not defined at this time.
218 @param Instance The enumeration of a hardware or software entity within
219 the system. A system may contain multiple entities that match a class/subclass
220 pairing. The instance differentiates between them. An instance of 0 indicates
221 that instance information is unavailable, not meaningful, or not relevant.
222 Valid instance numbers start with 1.
223 @param CallerId This optional parameter may be used to identify the caller.
224 This parameter allows the status code driver to apply different rules to
226 @param Data This optional parameter may be used to pass additional data.
228 @retval EFI_SUCCESS The function completed successfully.
234 IN CONST EFI_PEI_SERVICES
**PeiServices
,
235 IN EFI_STATUS_CODE_TYPE CodeType
,
236 IN EFI_STATUS_CODE_VALUE Value
,
238 IN CONST EFI_GUID
*CallerId OPTIONAL
,
239 IN CONST EFI_STATUS_CODE_DATA
*Data OPTIONAL
242 EFI_PEI_HOB_POINTERS Hob
;
243 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
244 UINTN
*NumberOfEntries
;
247 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
248 while (Hob
.Raw
!= NULL
) {
249 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
250 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
251 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
252 CallbackEntry
[Index
](
261 Hob
.Raw
= GET_NEXT_HOB (Hob
);
262 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
269 Entry point of Status Code PEIM.
271 This function is the entry point of this Status Code Router PEIM.
272 It produces Report Stataus Code Handler PPI and Status Code PPI.
274 @param FileHandle Handle of the file being invoked.
275 @param PeiServices Describes the list of possible PEI Services.
277 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
282 GenericStatusCodePeiEntry (
283 IN EFI_PEI_FILE_HANDLE FileHandle
,
284 IN CONST EFI_PEI_SERVICES
**PeiServices
288 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
289 EFI_PEI_PROGRESS_CODE_PPI
*OldStatusCodePpi
;
291 CreateRscHandlerCallbackPacket ();
294 // Install Report Status Code Handler PPI
296 Status
= PeiServicesInstallPpi (mRscHandlerPpiList
);
297 ASSERT_EFI_ERROR (Status
);
300 // Install Status Code PPI. PI spec specifies that there can be only one instance
301 // of this PPI in system. So first check if other instance already exists.
302 // If no other instance exists, then just install the PPI.
303 // If other instance already exists, then reinstall it.
305 Status
= PeiServicesLocatePpi (
306 &gEfiPeiStatusCodePpiGuid
,
309 (VOID
**) &OldStatusCodePpi
311 if (!EFI_ERROR (Status
)) {
312 Status
= PeiServicesReInstallPpi (OldDescriptor
, mStatusCodePpiList
);
314 Status
= PeiServicesInstallPpi (mStatusCodePpiList
);
316 ASSERT_EFI_ERROR (Status
);