2 Report Status Code Router PEIM which produces Report Stataus Code Handler PPI and Status Code PPI.
4 Copyright (c) 2009, Intel Corporation
5 All rights reserved. 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 mStatusCodePpiList
[] = {
28 EFI_PEI_PPI_DESCRIPTOR_PPI
,
29 &gEfiPeiRscHandlerPpiGuid
,
33 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
34 &gEfiPeiStatusCodePpiGuid
,
40 Worker function to create one memory status code GUID'ed HOB,
41 using PacketIndex to identify the packet.
43 @param PacketIndex Index of records packet.
45 @return Pointer to the memory status code packet.
49 CreateRscHandlerCallbackPacket (
53 UINTN
*NumberOfEntries
;
56 // Build GUID'ed HOB with PCD defined size.
58 NumberOfEntries
= BuildGuidHob (
59 &gStatusCodeCallbackGuid
,
60 sizeof (EFI_PEI_RSC_HANDLER_CALLBACK
) * 64 + sizeof (UINTN
)
62 ASSERT (NumberOfEntries
!= NULL
);
66 return NumberOfEntries
;
70 Register the callback function for ReportStatusCode() notification.
72 When this function is called the function pointer is added to an internal list and any future calls to
73 ReportStatusCode() will be forwarded to the Callback function.
75 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is called
76 when a call to ReportStatusCode() occurs.
78 @retval EFI_SUCCESS Function was successfully registered.
79 @retval EFI_INVALID_PARAMETER The callback function was NULL.
80 @retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be
82 @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again.
88 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
91 EFI_PEI_HOB_POINTERS Hob
;
92 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
93 UINTN
*NumberOfEntries
;
97 if (Callback
== NULL
) {
98 return EFI_INVALID_PARAMETER
;
101 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
103 while (Hob
.Raw
!= NULL
) {
104 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
105 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
106 if (*NumberOfEntries
< 64) {
107 FreePacket
= NumberOfEntries
;
109 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
110 if (CallbackEntry
[Index
] == Callback
) {
112 // If the function was already registered. It can't be registered again.
114 return EFI_ALREADY_STARTED
;
117 Hob
.Raw
= GET_NEXT_HOB (Hob
);
118 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
121 if (FreePacket
== NULL
) {
122 FreePacket
= CreateRscHandlerCallbackPacket();
125 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (FreePacket
+ 1);
126 CallbackEntry
[*FreePacket
] = Callback
;
133 Remove a previously registered callback function from the notification list.
135 ReportStatusCode() messages will no longer be forwarded to the Callback function.
137 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
140 @retval EFI_SUCCESS The function was successfully unregistered.
141 @retval EFI_INVALID_PARAMETER The callback function was NULL.
142 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
148 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
151 EFI_PEI_HOB_POINTERS Hob
;
152 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
153 UINTN
*NumberOfEntries
;
156 if (Callback
== NULL
) {
157 return EFI_INVALID_PARAMETER
;
160 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
161 while (Hob
.Raw
!= NULL
) {
162 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
163 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
164 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
165 if (CallbackEntry
[Index
] == Callback
) {
166 CallbackEntry
[Index
] = CallbackEntry
[*NumberOfEntries
- 1];
167 *NumberOfEntries
-= 1;
171 Hob
.Raw
= GET_NEXT_HOB (Hob
);
172 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
175 return EFI_NOT_FOUND
;
179 Publishes an interface that allows PEIMs to report status codes.
181 This function implements EFI_PEI_PROGRESS_CODE_PPI.ReportStatusCode().
182 It publishes an interface that allows PEIMs to report status codes.
184 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
185 @param CodeType Indicates the type of status code being reported.
186 @param Value Describes the current status of a hardware or
187 software entity. This includes information about the class and
188 subclass that is used to classify the entity as well as an operation.
189 For progress codes, the operation is the current activity.
190 For error codes, it is the exception.For debug codes,it is not defined at this time.
191 @param Instance The enumeration of a hardware or software entity within
192 the system. A system may contain multiple entities that match a class/subclass
193 pairing. The instance differentiates between them. An instance of 0 indicates
194 that instance information is unavailable, not meaningful, or not relevant.
195 Valid instance numbers start with 1.
196 @param CallerId This optional parameter may be used to identify the caller.
197 This parameter allows the status code driver to apply different rules to
199 @param Data This optional parameter may be used to pass additional data.
201 @retval EFI_SUCCESS The function completed successfully.
207 IN CONST EFI_PEI_SERVICES
**PeiServices
,
208 IN EFI_STATUS_CODE_TYPE CodeType
,
209 IN EFI_STATUS_CODE_VALUE Value
,
211 IN CONST EFI_GUID
*CallerId OPTIONAL
,
212 IN CONST EFI_STATUS_CODE_DATA
*Data OPTIONAL
215 EFI_PEI_HOB_POINTERS Hob
;
216 EFI_PEI_RSC_HANDLER_CALLBACK
*CallbackEntry
;
217 UINTN
*NumberOfEntries
;
220 Hob
.Raw
= GetFirstGuidHob (&gStatusCodeCallbackGuid
);
221 while (Hob
.Raw
!= NULL
) {
222 NumberOfEntries
= GET_GUID_HOB_DATA (Hob
);
223 CallbackEntry
= (EFI_PEI_RSC_HANDLER_CALLBACK
*) (NumberOfEntries
+ 1);
224 for (Index
= 0; Index
< *NumberOfEntries
; Index
++) {
225 CallbackEntry
[Index
](
234 Hob
.Raw
= GET_NEXT_HOB (Hob
);
235 Hob
.Raw
= GetNextGuidHob (&gStatusCodeCallbackGuid
, Hob
.Raw
);
242 Entry point of Status Code PEIM.
244 This function is the entry point of this Status Code Router PEIM.
245 It produces Report Stataus Code Handler PPI and Status Code PPI.
247 @param FileHandle Handle of the file being invoked.
248 @param PeiServices Describes the list of possible PEI Services.
250 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
255 GenericStatusCodePeiEntry (
256 IN EFI_PEI_FILE_HANDLE FileHandle
,
257 IN CONST EFI_PEI_SERVICES
**PeiServices
262 CreateRscHandlerCallbackPacket ();
264 Status
= PeiServicesInstallPpi (mStatusCodePpiList
);
265 ASSERT_EFI_ERROR (Status
);