]>
Commit | Line | Data |
---|---|---|
62a5bf63 | 1 | /** @file\r |
2 | Debug Print Error Level library instance that provide compatibility with the \r | |
3 | "err" shell command. This includes support for the Debug Mask Protocol\r | |
4 | supports for global debug print error level mask stored in an EFI Variable.\r | |
5 | This library instance only support DXE Phase modules.\r | |
6 | \r | |
7 | Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
8 | This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php.\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include <PiDxe.h>\r | |
19 | \r | |
20 | #include <Library/DebugPrintErrorLevelLib.h>\r | |
21 | #include <Library/PcdLib.h>\r | |
22 | \r | |
23 | #include <Guid/DebugMask.h>\r | |
24 | \r | |
25 | ///\r | |
26 | /// Debug Mask Protocol function prototypes\r | |
27 | ///\r | |
d4e0afd8 ED |
28 | \r |
29 | /**\r | |
30 | Retrieves the current debug print error level mask for a module are returns\r | |
31 | it in CurrentDebugMask.\r | |
32 | \r | |
33 | @param This The protocol instance pointer.\r | |
34 | @param CurrentDebugMask Pointer to the debug print error level mask that \r | |
35 | is returned.\r | |
36 | \r | |
37 | @retval EFI_SUCCESS The current debug print error level mask was\r | |
38 | returned in CurrentDebugMask.\r | |
39 | @retval EFI_INVALID_PARAMETER CurrentDebugMask is NULL.\r | |
40 | @retval EFI_DEVICE_ERROR The current debug print error level mask could\r | |
41 | not be retrieved.\r | |
42 | \r | |
43 | **/\r | |
62a5bf63 | 44 | EFI_STATUS\r |
45 | EFIAPI\r | |
46 | GetDebugMask (\r | |
47 | IN EFI_DEBUG_MASK_PROTOCOL *This, \r | |
48 | IN OUT UINTN *CurrentDebugMask \r | |
49 | );\r | |
50 | \r | |
d4e0afd8 ED |
51 | /**\r |
52 | Sets the current debug print error level mask for a module to the value\r | |
53 | specified by NewDebugMask.\r | |
54 | \r | |
55 | @param This The protocol instance pointer.\r | |
56 | @param NewDebugMask The new debug print error level mask for this module.\r | |
57 | \r | |
58 | @retval EFI_SUCCESS The current debug print error level mask was\r | |
59 | set to the value specified by NewDebugMask.\r | |
60 | @retval EFI_DEVICE_ERROR The current debug print error level mask could\r | |
61 | not be set to the value specified by NewDebugMask.\r | |
62 | \r | |
63 | **/\r | |
62a5bf63 | 64 | EFI_STATUS\r |
65 | EFIAPI\r | |
66 | SetDebugMask (\r | |
67 | IN EFI_DEBUG_MASK_PROTOCOL *This,\r | |
68 | IN UINTN NewDebugMask\r | |
69 | );\r | |
70 | \r | |
71 | ///\r | |
72 | /// Debug Mask Protocol instance\r | |
73 | ///\r | |
74 | EFI_DEBUG_MASK_PROTOCOL mDebugMaskProtocol = {\r | |
75 | EFI_DEBUG_MASK_REVISION,\r | |
76 | GetDebugMask,\r | |
77 | SetDebugMask\r | |
78 | };\r | |
79 | \r | |
80 | ///\r | |
81 | /// Global variable that is set to TRUE after the first attempt is made to \r | |
82 | /// retrieve the global error level mask through the EFI Varibale Services.\r | |
83 | /// This variable prevents the EFI Variable Services from being called fort\r | |
84 | /// every DEBUG() macro.\r | |
85 | ///\r | |
86 | BOOLEAN mGlobalErrorLevelInitialized = FALSE;\r | |
87 | \r | |
88 | ///\r | |
89 | /// Global variable that contains the current debug error level mask for the\r | |
90 | /// module that is using this library instance. This variable is initially\r | |
91 | /// set to the PcdDebugPrintErrorLevel value. If the EFI Variable exists that\r | |
92 | /// contains the global debug print error level mask, then that override the\r | |
93 | /// PcdDebugPrintErrorLevel value. If the Debug Mask Protocol SetDebugMask()\r | |
94 | /// service is called, then that overrides bit the PcdDebugPrintErrorLevel and\r | |
95 | /// the EFI Variable setting.\r | |
96 | ///\r | |
97 | UINT32 mDebugPrintErrorLevel = 0;\r | |
98 | \r | |
99 | ///\r | |
100 | /// Global variable that is used to cache a pointer to the EFI System Table\r | |
101 | /// that is required to access the EFI Variable Services to get and set\r | |
102 | /// the global debug print error level mask value. The UefiBootServicesTableLib\r | |
103 | /// is not used to prevent a circular dependency between these libraries.\r | |
104 | ///\r | |
d4e0afd8 | 105 | EFI_SYSTEM_TABLE *mSystemTable = NULL;\r |
62a5bf63 | 106 | \r |
107 | /**\r | |
108 | The constructor function caches the PCI Express Base Address and creates a \r | |
109 | Set Virtual Address Map event to convert physical address to virtual addresses.\r | |
110 | \r | |
111 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
112 | @param SystemTable A pointer to the EFI System Table.\r | |
113 | \r | |
114 | @retval EFI_SUCCESS The constructor completed successfully.\r | |
115 | @retval Other value The constructor did not complete successfully.\r | |
116 | \r | |
117 | **/\r | |
118 | EFI_STATUS\r | |
119 | EFIAPI\r | |
120 | DxeDebugPrintErrorLevelLibConstructor (\r | |
121 | IN EFI_HANDLE ImageHandle,\r | |
122 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
123 | )\r | |
124 | {\r | |
125 | EFI_STATUS Status;\r | |
126 | \r | |
127 | //\r | |
128 | // Initialize the error level mask from PCD setting.\r | |
129 | //\r | |
130 | mDebugPrintErrorLevel = PcdGet32 (PcdDebugPrintErrorLevel);\r | |
131 | \r | |
132 | //\r | |
133 | // Install Debug Mask Protocol onto ImageHandle\r | |
134 | // \r | |
d4e0afd8 | 135 | mSystemTable = SystemTable;\r |
62a5bf63 | 136 | Status = SystemTable->BootServices->InstallMultipleProtocolInterfaces (\r |
137 | &ImageHandle,\r | |
138 | &gEfiDebugMaskProtocolGuid, &mDebugMaskProtocol,\r | |
139 | NULL\r | |
140 | );\r | |
141 | \r | |
142 | //\r | |
143 | // Attempt to retrieve the global debug print error level mask from the EFI Variable\r | |
144 | // If the EFI Variable can not be accessed when this module's library constructors are\r | |
145 | // executed, then the EFI Variable access will be reattempted on every DEBUG() print\r | |
146 | // from this module until the EFI Variable services are available.\r | |
147 | //\r | |
148 | GetDebugPrintErrorLevel ();\r | |
149 | \r | |
150 | return Status;\r | |
151 | }\r | |
152 | \r | |
153 | /**\r | |
154 | The destructor function frees any allocated buffers and closes the Set Virtual \r | |
155 | Address Map event.\r | |
156 | \r | |
157 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
158 | @param SystemTable A pointer to the EFI System Table.\r | |
159 | \r | |
160 | @retval EFI_SUCCESS The destructor completed successfully.\r | |
161 | @retval Other value The destructor did not complete successfully.\r | |
162 | \r | |
163 | **/\r | |
164 | EFI_STATUS\r | |
165 | EFIAPI\r | |
166 | DxeDebugPrintErrorLevelLibDestructor (\r | |
167 | IN EFI_HANDLE ImageHandle,\r | |
168 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
169 | )\r | |
170 | {\r | |
171 | //\r | |
172 | // Uninstall the Debug Mask Protocol from ImageHandle\r | |
173 | // \r | |
174 | return SystemTable->BootServices->UninstallMultipleProtocolInterfaces (\r | |
175 | ImageHandle,\r | |
176 | &gEfiDebugMaskProtocolGuid, &mDebugMaskProtocol,\r | |
177 | NULL\r | |
178 | );\r | |
179 | }\r | |
180 | \r | |
181 | /**\r | |
182 | Returns the debug print error level mask for the current module.\r | |
183 | \r | |
184 | @return Debug print error level mask for the current module.\r | |
185 | \r | |
186 | **/\r | |
187 | UINT32\r | |
188 | EFIAPI\r | |
189 | GetDebugPrintErrorLevel (\r | |
190 | VOID\r | |
191 | )\r | |
192 | {\r | |
193 | EFI_STATUS Status;\r | |
194 | EFI_TPL CurrentTpl;\r | |
195 | UINTN Size;\r | |
196 | UINTN GlobalErrorLevel;\r | |
197 | \r | |
198 | //\r | |
199 | // If the constructor has not been executed yet, then just return the PCD value.\r | |
200 | // This case should only occur if debug print is generated by a library\r | |
201 | // constructor for this module\r | |
202 | //\r | |
d4e0afd8 | 203 | if (mSystemTable == NULL) {\r |
62a5bf63 | 204 | return PcdGet32 (PcdDebugPrintErrorLevel);\r |
205 | }\r | |
206 | \r | |
207 | //\r | |
208 | // Check to see if an attempt has been mde to retrieve the global debug print \r | |
209 | // error level mask. Since this libtrary instance stores the global debug print\r | |
210 | // error level mask in an EFI Variable, the EFI Variable should only be accessed\r | |
211 | // once to reduce the overhead of reading the EFI Variable on every debug print\r | |
212 | // \r | |
213 | if (!mGlobalErrorLevelInitialized) {\r | |
214 | //\r | |
215 | // Make sure the TPL Level is low enough for EFI Variable Services to be called\r | |
216 | //\r | |
d4e0afd8 ED |
217 | CurrentTpl = mSystemTable->BootServices->RaiseTPL (TPL_HIGH_LEVEL);\r |
218 | mSystemTable->BootServices->RestoreTPL (CurrentTpl);\r | |
62a5bf63 | 219 | if (CurrentTpl <= TPL_CALLBACK) {\r |
220 | //\r | |
221 | // Attempt to retrieve the global debug print error level mask from the \r | |
222 | // EFI Variable\r | |
223 | //\r | |
224 | Size = sizeof (GlobalErrorLevel);\r | |
d4e0afd8 | 225 | Status = mSystemTable->RuntimeServices->GetVariable (\r |
62a5bf63 | 226 | DEBUG_MASK_VARIABLE_NAME, \r |
227 | &gEfiGenericVariableGuid, \r | |
228 | NULL, \r | |
229 | &Size, \r | |
230 | &GlobalErrorLevel\r | |
231 | );\r | |
232 | if (Status != EFI_NOT_AVAILABLE_YET) {\r | |
233 | //\r | |
234 | // If EFI Variable Services are available, then set a flag so the EFI\r | |
235 | // Variable will not be read again by this module.\r | |
236 | //\r | |
237 | mGlobalErrorLevelInitialized = TRUE;\r | |
238 | if (!EFI_ERROR (Status)) {\r | |
239 | //\r | |
240 | // If the EFI Varible exists, then set this module's module's mask to\r | |
241 | // the global debug print error level mask value.\r | |
242 | //\r | |
243 | mDebugPrintErrorLevel = (UINT32)GlobalErrorLevel;\r | |
244 | }\r | |
245 | }\r | |
246 | }\r | |
247 | }\r | |
248 | \r | |
249 | //\r | |
250 | // Return the current mask value for this module.\r | |
251 | //\r | |
252 | return mDebugPrintErrorLevel;\r | |
253 | }\r | |
254 | \r | |
255 | /**\r | |
256 | Sets the global debug print error level mask fpr the entire platform.\r | |
d4e0afd8 ED |
257 | \r |
258 | @param ErrorLevel Global debug print error level\r | |
259 | \r | |
260 | @retval TRUE The debug print error level mask was sucessfully set.\r | |
261 | @retval FALSE The debug print error level mask could not be set.\r | |
62a5bf63 | 262 | \r |
263 | **/\r | |
264 | BOOLEAN\r | |
265 | EFIAPI\r | |
266 | SetDebugPrintErrorLevel (\r | |
267 | UINT32 ErrorLevel\r | |
268 | )\r | |
269 | {\r | |
270 | EFI_STATUS Status;\r | |
271 | EFI_TPL CurrentTpl;\r | |
272 | UINTN Size;\r | |
273 | UINTN GlobalErrorLevel;\r | |
274 | \r | |
275 | //\r | |
276 | // Make sure the constructor has been executed\r | |
277 | //\r | |
d4e0afd8 | 278 | if (mSystemTable != NULL) {\r |
62a5bf63 | 279 | //\r |
280 | // Make sure the TPL Level is low enough for EFI Variable Services\r | |
281 | //\r | |
d4e0afd8 ED |
282 | CurrentTpl = mSystemTable->BootServices->RaiseTPL (TPL_HIGH_LEVEL);\r |
283 | mSystemTable->BootServices->RestoreTPL (CurrentTpl);\r | |
62a5bf63 | 284 | if (CurrentTpl <= TPL_CALLBACK) {\r |
285 | //\r | |
286 | // Attempt to store the global debug print error level mask in an EFI Variable\r | |
287 | //\r | |
288 | GlobalErrorLevel = (UINTN)ErrorLevel;\r | |
289 | Size = sizeof (GlobalErrorLevel);\r | |
d4e0afd8 | 290 | Status = mSystemTable->RuntimeServices->SetVariable (\r |
62a5bf63 | 291 | DEBUG_MASK_VARIABLE_NAME, \r |
292 | &gEfiGenericVariableGuid, \r | |
293 | (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS),\r | |
294 | Size,\r | |
295 | &GlobalErrorLevel\r | |
296 | );\r | |
297 | if (!EFI_ERROR (Status)) {\r | |
298 | //\r | |
299 | // If the EFI Variable was updated, then update the mask value for this \r | |
300 | // module and return TRUE.\r | |
301 | //\r | |
302 | mGlobalErrorLevelInitialized = TRUE; \r | |
303 | mDebugPrintErrorLevel = ErrorLevel;\r | |
304 | return TRUE;\r | |
305 | }\r | |
306 | }\r | |
307 | }\r | |
308 | //\r | |
309 | // Return FALSE since the EFI Variable could not be updated.\r | |
310 | //\r | |
311 | return FALSE;\r | |
312 | }\r | |
313 | \r | |
314 | /**\r | |
315 | Retrieves the current debug print error level mask for a module are returns\r | |
316 | it in CurrentDebugMask.\r | |
317 | \r | |
318 | @param This The protocol instance pointer.\r | |
319 | @param CurrentDebugMask Pointer to the debug print error level mask that \r | |
320 | is returned.\r | |
321 | \r | |
322 | @retval EFI_SUCCESS The current debug print error level mask was\r | |
323 | returned in CurrentDebugMask.\r | |
324 | @retval EFI_INVALID_PARAMETER CurrentDebugMask is NULL.\r | |
325 | @retval EFI_DEVICE_ERROR The current debug print error level mask could\r | |
326 | not be retrieved.\r | |
327 | \r | |
328 | **/\r | |
329 | EFI_STATUS\r | |
330 | EFIAPI\r | |
331 | GetDebugMask (\r | |
332 | IN EFI_DEBUG_MASK_PROTOCOL *This, \r | |
333 | IN OUT UINTN *CurrentDebugMask \r | |
334 | )\r | |
335 | {\r | |
336 | if (CurrentDebugMask == NULL) {\r | |
337 | return EFI_INVALID_PARAMETER;\r | |
338 | }\r | |
339 | \r | |
340 | //\r | |
341 | // Retrieve the current debug mask from mDebugPrintErrorLevel\r | |
342 | //\r | |
343 | *CurrentDebugMask = (UINTN)mDebugPrintErrorLevel;\r | |
344 | return EFI_SUCCESS;\r | |
345 | }\r | |
346 | \r | |
347 | /**\r | |
348 | Sets the current debug print error level mask for a module to the value\r | |
349 | specified by NewDebugMask.\r | |
350 | \r | |
351 | @param This The protocol instance pointer.\r | |
352 | @param NewDebugMask The new debug print error level mask for this module.\r | |
353 | \r | |
354 | @retval EFI_SUCCESS The current debug print error level mask was\r | |
355 | set to the value specified by NewDebugMask.\r | |
356 | @retval EFI_DEVICE_ERROR The current debug print error level mask could\r | |
357 | not be set to the value specified by NewDebugMask.\r | |
358 | \r | |
359 | **/\r | |
360 | EFI_STATUS\r | |
361 | EFIAPI\r | |
362 | SetDebugMask (\r | |
363 | IN EFI_DEBUG_MASK_PROTOCOL *This,\r | |
364 | IN UINTN NewDebugMask\r | |
365 | )\r | |
366 | {\r | |
367 | //\r | |
368 | // Store the new debug mask into mDebugPrintErrorLevel\r | |
369 | //\r | |
370 | mDebugPrintErrorLevel = (UINT32)NewDebugMask;\r | |
371 | return EFI_SUCCESS;\r | |
372 | }\r |