]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c
Enable Report Status Code Router introduced in PI 1.2 for PEI and DXE.
[mirror_edk2.git] / MdeModulePkg / Universal / ReportStatusCodeRouter / Pei / ReportStatusCodeRouterPei.c
1 /** @file
2 Report Status Code Router PEIM which produces Report Stataus Code Handler PPI and Status Code PPI.
3
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
9
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.
12
13 **/
14
15 #include "ReportStatusCodeRouterPei.h"
16
17 EFI_PEI_RSC_HANDLER_PPI mRscHandlerPpi = {
18 Register,
19 Unregister
20 };
21
22 EFI_PEI_PROGRESS_CODE_PPI mStatusCodePpi = {
23 ReportDispatcher
24 };
25
26 EFI_PEI_PPI_DESCRIPTOR mStatusCodePpiList[] = {
27 {
28 EFI_PEI_PPI_DESCRIPTOR_PPI,
29 &gEfiPeiRscHandlerPpiGuid,
30 &mRscHandlerPpi
31 },
32 {
33 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
34 &gEfiPeiStatusCodePpiGuid,
35 &mStatusCodePpi
36 }
37 };
38
39 /**
40 Worker function to create one memory status code GUID'ed HOB,
41 using PacketIndex to identify the packet.
42
43 @param PacketIndex Index of records packet.
44
45 @return Pointer to the memory status code packet.
46
47 **/
48 UINTN *
49 CreateRscHandlerCallbackPacket (
50 VOID
51 )
52 {
53 UINTN *NumberOfEntries;
54
55 //
56 // Build GUID'ed HOB with PCD defined size.
57 //
58 NumberOfEntries = BuildGuidHob (
59 &gStatusCodeCallbackGuid,
60 sizeof (EFI_PEI_RSC_HANDLER_CALLBACK) * 64 + sizeof (UINTN)
61 );
62 ASSERT (NumberOfEntries != NULL);
63
64 *NumberOfEntries = 0;
65
66 return NumberOfEntries;
67 }
68
69 /**
70 Register the callback function for ReportStatusCode() notification.
71
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.
74
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.
77
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
81 registered.
82 @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again.
83
84 **/
85 EFI_STATUS
86 EFIAPI
87 Register (
88 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
89 )
90 {
91 EFI_PEI_HOB_POINTERS Hob;
92 EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry;
93 UINTN *NumberOfEntries;
94 UINTN Index;
95 UINTN *FreePacket;
96
97 if (Callback == NULL) {
98 return EFI_INVALID_PARAMETER;
99 }
100
101 Hob.Raw = GetFirstGuidHob (&gStatusCodeCallbackGuid);
102 FreePacket = NULL;
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;
108 }
109 for (Index = 0; Index < *NumberOfEntries; Index++) {
110 if (CallbackEntry[Index] == Callback) {
111 //
112 // If the function was already registered. It can't be registered again.
113 //
114 return EFI_ALREADY_STARTED;
115 }
116 }
117 Hob.Raw = GET_NEXT_HOB (Hob);
118 Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw);
119 }
120
121 if (FreePacket == NULL) {
122 FreePacket = CreateRscHandlerCallbackPacket();
123 }
124
125 CallbackEntry = (EFI_PEI_RSC_HANDLER_CALLBACK *) (FreePacket + 1);
126 CallbackEntry[*FreePacket] = Callback;
127 *FreePacket += 1;
128
129 return EFI_SUCCESS;
130 }
131
132 /**
133 Remove a previously registered callback function from the notification list.
134
135 ReportStatusCode() messages will no longer be forwarded to the Callback function.
136
137 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
138 unregistered.
139
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.
143
144 **/
145 EFI_STATUS
146 EFIAPI
147 Unregister (
148 IN EFI_PEI_RSC_HANDLER_CALLBACK Callback
149 )
150 {
151 EFI_PEI_HOB_POINTERS Hob;
152 EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry;
153 UINTN *NumberOfEntries;
154 UINTN Index;
155
156 if (Callback == NULL) {
157 return EFI_INVALID_PARAMETER;
158 }
159
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;
168 return EFI_SUCCESS;
169 }
170 }
171 Hob.Raw = GET_NEXT_HOB (Hob);
172 Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw);
173 }
174
175 return EFI_NOT_FOUND;
176 }
177
178 /**
179 Publishes an interface that allows PEIMs to report status codes.
180
181 This function implements EFI_PEI_PROGRESS_CODE_PPI.ReportStatusCode().
182 It publishes an interface that allows PEIMs to report status codes.
183
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
198 different callers.
199 @param Data This optional parameter may be used to pass additional data.
200
201 @retval EFI_SUCCESS The function completed successfully.
202
203 **/
204 EFI_STATUS
205 EFIAPI
206 ReportDispatcher (
207 IN CONST EFI_PEI_SERVICES **PeiServices,
208 IN EFI_STATUS_CODE_TYPE CodeType,
209 IN EFI_STATUS_CODE_VALUE Value,
210 IN UINT32 Instance,
211 IN CONST EFI_GUID *CallerId OPTIONAL,
212 IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
213 )
214 {
215 EFI_PEI_HOB_POINTERS Hob;
216 EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry;
217 UINTN *NumberOfEntries;
218 UINTN Index;
219
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](
226 PeiServices,
227 CodeType,
228 Value,
229 Instance,
230 CallerId,
231 Data
232 );
233 }
234 Hob.Raw = GET_NEXT_HOB (Hob);
235 Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw);
236 }
237
238 return EFI_SUCCESS;
239 }
240
241 /**
242 Entry point of Status Code PEIM.
243
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.
246
247 @param FileHandle Handle of the file being invoked.
248 @param PeiServices Describes the list of possible PEI Services.
249
250 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
251
252 **/
253 EFI_STATUS
254 EFIAPI
255 GenericStatusCodePeiEntry (
256 IN EFI_PEI_FILE_HANDLE FileHandle,
257 IN CONST EFI_PEI_SERVICES **PeiServices
258 )
259 {
260 EFI_STATUS Status;
261
262 CreateRscHandlerCallbackPacket ();
263
264 Status = PeiServicesInstallPpi (mStatusCodePpiList);
265 ASSERT_EFI_ERROR (Status);
266
267 return EFI_SUCCESS;
268 }