TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeDebugPrintErrorLevelLib.c
Go to the documentation of this file.
1
12#include <PiDxe.h>
13
15#include <Library/PcdLib.h>
16#include <Library/HobLib.h>
17
18#include <Guid/DebugMask.h>
19
23
40EFIAPI
43 IN OUT UINTN *CurrentDebugMask
44 );
45
60EFIAPI
63 IN UINTN NewDebugMask
64 );
65
70 EFI_DEBUG_MASK_REVISION,
73};
74
82
94
102
115EFIAPI
117 IN EFI_HANDLE ImageHandle,
118 IN EFI_SYSTEM_TABLE *SystemTable
119 )
120{
121 EFI_STATUS Status;
122
123 //
124 // Initialize the error level mask from PCD setting.
125 //
126 mDebugPrintErrorLevel = PcdGet32 (PcdDebugPrintErrorLevel);
127
128 //
129 // Install Debug Mask Protocol onto ImageHandle
130 //
131 mSystemTable = SystemTable;
132 Status = SystemTable->BootServices->InstallMultipleProtocolInterfaces (
133 &ImageHandle,
134 &gEfiDebugMaskProtocolGuid,
136 NULL
137 );
138
139 //
140 // Attempt to retrieve the global debug print error level mask from the EFI Variable
141 // If the EFI Variable can not be accessed when this module's library constructors are
142 // executed a HOB can be used to set the global debug print error level. If no value
143 // was found then the EFI Variable access will be reattempted on every DEBUG() print
144 // from this module until the EFI Variable services are available.
145 //
147
148 return Status;
149}
150
163EFIAPI
165 IN EFI_HANDLE ImageHandle,
166 IN EFI_SYSTEM_TABLE *SystemTable
167 )
168{
169 //
170 // Uninstall the Debug Mask Protocol from ImageHandle
171 //
172 return SystemTable->BootServices->UninstallMultipleProtocolInterfaces (
173 ImageHandle,
174 &gEfiDebugMaskProtocolGuid,
176 NULL
177 );
178}
179
186UINT32
187EFIAPI
189 VOID
190 )
191{
192 EFI_STATUS Status;
193 EFI_TPL CurrentTpl;
194 UINTN Size;
195 UINTN GlobalErrorLevel;
196 VOID *Hob;
197
198 //
199 // If the constructor has not been executed yet, then just return the PCD value.
200 // This case should only occur if debug print is generated by a library
201 // constructor for this module
202 //
203 if (mSystemTable == NULL) {
204 return PcdGet32 (PcdDebugPrintErrorLevel);
205 }
206
207 //
208 // Check to see if an attempt has been made to retrieve the global debug print
209 // error level mask. Since this library instance stores the global debug print
210 // error level mask in an EFI Variable, the EFI Variable should only be accessed
211 // once to reduce the overhead of reading the EFI Variable on every debug print
212 //
214 //
215 // Make sure the TPL Level is low enough for EFI Variable Services to be called
216 //
217 CurrentTpl = mSystemTable->BootServices->RaiseTPL (TPL_HIGH_LEVEL);
218 mSystemTable->BootServices->RestoreTPL (CurrentTpl);
219 if (CurrentTpl <= TPL_CALLBACK) {
220 //
221 // Attempt to retrieve the global debug print error level mask from the
222 // EFI Variable
223 //
224 Size = sizeof (GlobalErrorLevel);
225 Status = mSystemTable->RuntimeServices->GetVariable (
226 DEBUG_MASK_VARIABLE_NAME,
227 &gEfiGenericVariableGuid,
228 NULL,
229 &Size,
230 &GlobalErrorLevel
231 );
232 if (Status != EFI_NOT_AVAILABLE_YET) {
233 //
234 // If EFI Variable Services are available, then set a flag so the EFI
235 // Variable will not be read again by this module.
236 //
238 if (!EFI_ERROR (Status)) {
239 //
240 // If the EFI Varible exists, then set this module's module's mask to
241 // the global debug print error level mask value.
242 //
243 mDebugPrintErrorLevel = (UINT32)GlobalErrorLevel;
244 }
245 } else {
246 //
247 // If variable services are not yet available optionally get the global
248 // debug print error level mask from a HOB.
249 //
250 Hob = GetFirstGuidHob (&gEfiGenericVariableGuid);
251 if (Hob != NULL) {
252 if (GET_GUID_HOB_DATA_SIZE (Hob) == sizeof (UINT32)) {
253 mDebugPrintErrorLevel = *(UINT32 *)GET_GUID_HOB_DATA (Hob);
255 }
256 }
257 }
258 }
259 }
260
261 //
262 // Return the current mask value for this module.
263 //
265}
266
276BOOLEAN
277EFIAPI
279 UINT32 ErrorLevel
280 )
281{
282 EFI_STATUS Status;
283 EFI_TPL CurrentTpl;
284 UINTN Size;
285 UINTN GlobalErrorLevel;
286
287 //
288 // Make sure the constructor has been executed
289 //
290 if (mSystemTable != NULL) {
291 //
292 // Make sure the TPL Level is low enough for EFI Variable Services
293 //
294 CurrentTpl = mSystemTable->BootServices->RaiseTPL (TPL_HIGH_LEVEL);
295 mSystemTable->BootServices->RestoreTPL (CurrentTpl);
296 if (CurrentTpl <= TPL_CALLBACK) {
297 //
298 // Attempt to store the global debug print error level mask in an EFI Variable
299 //
300 GlobalErrorLevel = (UINTN)ErrorLevel;
301 Size = sizeof (GlobalErrorLevel);
302 Status = mSystemTable->RuntimeServices->SetVariable (
303 DEBUG_MASK_VARIABLE_NAME,
304 &gEfiGenericVariableGuid,
305 (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS),
306 Size,
307 &GlobalErrorLevel
308 );
309 if (!EFI_ERROR (Status)) {
310 //
311 // If the EFI Variable was updated, then update the mask value for this
312 // module and return TRUE.
313 //
315 mDebugPrintErrorLevel = ErrorLevel;
316 return TRUE;
317 }
318 }
319 }
320
321 //
322 // Return FALSE since the EFI Variable could not be updated.
323 //
324 return FALSE;
325}
326
343EFIAPI
346 IN OUT UINTN *CurrentDebugMask
347 )
348{
349 if (CurrentDebugMask == NULL) {
350 return EFI_INVALID_PARAMETER;
351 }
352
353 //
354 // Retrieve the current debug mask from mDebugPrintErrorLevel
355 //
356 *CurrentDebugMask = (UINTN)mDebugPrintErrorLevel;
357 return EFI_SUCCESS;
358}
359
374EFIAPI
377 IN UINTN NewDebugMask
378 )
379{
380 //
381 // Store the new debug mask into mDebugPrintErrorLevel
382 //
383 mDebugPrintErrorLevel = (UINT32)NewDebugMask;
384 return EFI_SUCCESS;
385}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
BOOLEAN EFIAPI SetDebugPrintErrorLevel(UINT32 ErrorLevel)
EFI_STATUS EFIAPI DxeDebugPrintErrorLevelLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI GetDebugMask(IN EFI_DEBUG_MASK_PROTOCOL *This, IN OUT UINTN *CurrentDebugMask)
UINT32 mDebugPrintErrorLevel
EFI_STATUS EFIAPI SetDebugMask(IN EFI_DEBUG_MASK_PROTOCOL *This, IN UINTN NewDebugMask)
UINT32 EFIAPI GetDebugPrintErrorLevel(VOID)
EFI_DEBUG_MASK_PROTOCOL mDebugMaskProtocol
EFI_STATUS EFIAPI DxeDebugPrintErrorLevelLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
BOOLEAN mGlobalErrorLevelInitialized
EFI_SYSTEM_TABLE * mSystemTable
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define EFI_NOT_AVAILABLE_YET
Definition: PiMultiPhase.h:54
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define EFI_VARIABLE_NON_VOLATILE
EFI_BOOT_SERVICES * BootServices
Definition: UefiSpec.h:2083
EFI_RUNTIME_SERVICES * RuntimeServices
Definition: UefiSpec.h:2079