2 Report Status Code Router PEIM which produces Report Stataus Code Handler PPI and Status Code PPI.
4 Copyright (c) 2009 - 2010, 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
;
100 if (Callback
== NULL
) {
101 return EFI_INVALID_PARAMETER
;
104 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
106 while (Hob
.Raw
!= NULL
) {
107 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
108 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
109 if (*NumberOfEntries
< 64) {
110 FreePacket
= NumberOfEntries
;
112 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
113 if (CallbackEntry
[Index
] == Callback
) {
115 // If the function was already registered. It can't be registered again.
117 return EFI_ALREADY_STARTED
;
120 Hob
.Raw
= GET_NEXT_HOB (Hob
);
121 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
124 if (FreePacket
== NULL
) {
125 FreePacket
= CreateRscHandlerCallbackPacket();
128 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (FreePacket
+ 1);
129 CallbackEntry
[*FreePacket
] = Callback
;
136 Remove a previously registered callback function from the notification list.
138 ReportStatusCode() messages will no longer be forwarded to the Callback function.
140 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
143 @retval EFI_SUCCESS The function was successfully unregistered.
144 @retval EFI_INVALID_PARAMETER The callback function was NULL.
145 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
151 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
154 EFI_PEI_HOB_POINTERS Hob
;
155 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
156 UINTN
*NumberOfEntries
;
159 if (Callback
== NULL
) {
160 return EFI_INVALID_PARAMETER
;
163 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
164 while (Hob
.Raw
!= NULL
) {
165 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
166 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
167 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
168 if (CallbackEntry
[Index
] == Callback
) {
169 CallbackEntry
[Index
] = CallbackEntry
[*NumberOfEntries
- 1];
170 *NumberOfEntries
-= 1;
174 Hob
.Raw
= GET_NEXT_HOB (Hob
);
175 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
178 return EFI_NOT_FOUND
;
182 Publishes an interface that allows PEIMs to report status codes.
184 This function implements EFI_PEI_PROGRESS_CODE_PPI.ReportStatusCode().
185 It publishes an interface that allows PEIMs to report status codes.
187 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
188 @param CodeType Indicates the type of status code being reported.
189 @param Value Describes the current status of a hardware or
190 software entity. This includes information about the class and
191 subclass that is used to classify the entity as well as an operation.
192 For progress codes, the operation is the current activity.
193 For error codes, it is the exception.For debug codes,it is not defined at this time.
194 @param Instance The enumeration of a hardware or software entity within
195 the system. A system may contain multiple entities that match a class/subclass
196 pairing. The instance differentiates between them. An instance of 0 indicates
197 that instance information is unavailable, not meaningful, or not relevant.
198 Valid instance numbers start with 1.
199 @param CallerId This optional parameter may be used to identify the caller.
200 This parameter allows the status code driver to apply different rules to
202 @param Data This optional parameter may be used to pass additional data.
204 @retval EFI_SUCCESS The function completed successfully.
210 IN CONST EFI_PEI_SERVICES
**PeiServices
,
211 IN EFI_STATUS_CODE_TYPE CodeType
,
212 IN EFI_STATUS_CODE_VALUE Value
,
214 IN CONST EFI_GUID
*CallerId OPTIONAL
,
215 IN CONST EFI_STATUS_CODE_DATA
*Data OPTIONAL
218 EFI_PEI_HOB_POINTERS Hob
;
219 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
220 UINTN
*NumberOfEntries
;
223 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
224 while (Hob
.Raw
!= NULL
) {
225 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
226 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
227 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
228 CallbackEntry
[Index
](
237 Hob
.Raw
= GET_NEXT_HOB (Hob
);
238 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
245 Entry point of Status Code PEIM.
247 This function is the entry point of this Status Code Router PEIM.
248 It produces Report Stataus Code Handler PPI and Status Code PPI.
250 @param FileHandle Handle of the file being invoked.
251 @param PeiServices Describes the list of possible PEI Services.
253 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
258 GenericStatusCodePeiEntry (
259 IN EFI_PEI_FILE_HANDLE FileHandle
,
260 IN CONST EFI_PEI_SERVICES
**PeiServices
264 EFI_PEI_PPI_DESCRIPTOR
*OldDescriptor
;
265 EFI_PEI_PROGRESS_CODE_PPI
*OldStatusCodePpi
;
267 CreateRscHandlerCallbackPacket ();
270 // Install Report Status Code Handler PPI
272 Status
= PeiServicesInstallPpi (mRscHandlerPpiList
);
273 ASSERT_EFI_ERROR (Status
);
276 // Install Status Code PPI. PI spec specifies that there can be only one instance
277 // of this PPI in system. So first check if other instance already exists.
278 // If no other instance exists, then just install the PPI.
279 // If other instance already exists, then reinstall it.
281 Status
= PeiServicesLocatePpi (
282 &gEfiPeiStatusCodePpiGuid
,
285 (VOID
**) &OldStatusCodePpi
287 if (!EFI_ERROR (Status
)) {
288 Status
= PeiServicesReInstallPpi (OldDescriptor
, mStatusCodePpiList
);
290 Status
= PeiServicesInstallPpi (mStatusCodePpiList
);
292 ASSERT_EFI_ERROR (Status
);