]>
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 | |
28 | EFI_STATUS\r | |
29 | EFIAPI\r | |
30 | GetDebugMask (\r | |
31 | IN EFI_DEBUG_MASK_PROTOCOL *This, \r | |
32 | IN OUT UINTN *CurrentDebugMask \r | |
33 | );\r | |
34 | \r | |
35 | EFI_STATUS\r | |
36 | EFIAPI\r | |
37 | SetDebugMask (\r | |
38 | IN EFI_DEBUG_MASK_PROTOCOL *This,\r | |
39 | IN UINTN NewDebugMask\r | |
40 | );\r | |
41 | \r | |
42 | ///\r | |
43 | /// Debug Mask Protocol instance\r | |
44 | ///\r | |
45 | EFI_DEBUG_MASK_PROTOCOL mDebugMaskProtocol = {\r | |
46 | EFI_DEBUG_MASK_REVISION,\r | |
47 | GetDebugMask,\r | |
48 | SetDebugMask\r | |
49 | };\r | |
50 | \r | |
51 | ///\r | |
52 | /// Global variable that is set to TRUE after the first attempt is made to \r | |
53 | /// retrieve the global error level mask through the EFI Varibale Services.\r | |
54 | /// This variable prevents the EFI Variable Services from being called fort\r | |
55 | /// every DEBUG() macro.\r | |
56 | ///\r | |
57 | BOOLEAN mGlobalErrorLevelInitialized = FALSE;\r | |
58 | \r | |
59 | ///\r | |
60 | /// Global variable that contains the current debug error level mask for the\r | |
61 | /// module that is using this library instance. This variable is initially\r | |
62 | /// set to the PcdDebugPrintErrorLevel value. If the EFI Variable exists that\r | |
63 | /// contains the global debug print error level mask, then that override the\r | |
64 | /// PcdDebugPrintErrorLevel value. If the Debug Mask Protocol SetDebugMask()\r | |
65 | /// service is called, then that overrides bit the PcdDebugPrintErrorLevel and\r | |
66 | /// the EFI Variable setting.\r | |
67 | ///\r | |
68 | UINT32 mDebugPrintErrorLevel = 0;\r | |
69 | \r | |
70 | ///\r | |
71 | /// Global variable that is used to cache a pointer to the EFI System Table\r | |
72 | /// that is required to access the EFI Variable Services to get and set\r | |
73 | /// the global debug print error level mask value. The UefiBootServicesTableLib\r | |
74 | /// is not used to prevent a circular dependency between these libraries.\r | |
75 | ///\r | |
76 | EFI_SYSTEM_TABLE *mST = NULL;\r | |
77 | \r | |
78 | /**\r | |
79 | The constructor function caches the PCI Express Base Address and creates a \r | |
80 | Set Virtual Address Map event to convert physical address to virtual addresses.\r | |
81 | \r | |
82 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
83 | @param SystemTable A pointer to the EFI System Table.\r | |
84 | \r | |
85 | @retval EFI_SUCCESS The constructor completed successfully.\r | |
86 | @retval Other value The constructor did not complete successfully.\r | |
87 | \r | |
88 | **/\r | |
89 | EFI_STATUS\r | |
90 | EFIAPI\r | |
91 | DxeDebugPrintErrorLevelLibConstructor (\r | |
92 | IN EFI_HANDLE ImageHandle,\r | |
93 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
94 | )\r | |
95 | {\r | |
96 | EFI_STATUS Status;\r | |
97 | \r | |
98 | //\r | |
99 | // Initialize the error level mask from PCD setting.\r | |
100 | //\r | |
101 | mDebugPrintErrorLevel = PcdGet32 (PcdDebugPrintErrorLevel);\r | |
102 | \r | |
103 | //\r | |
104 | // Install Debug Mask Protocol onto ImageHandle\r | |
105 | // \r | |
106 | mST = SystemTable;\r | |
107 | Status = SystemTable->BootServices->InstallMultipleProtocolInterfaces (\r | |
108 | &ImageHandle,\r | |
109 | &gEfiDebugMaskProtocolGuid, &mDebugMaskProtocol,\r | |
110 | NULL\r | |
111 | );\r | |
112 | \r | |
113 | //\r | |
114 | // Attempt to retrieve the global debug print error level mask from the EFI Variable\r | |
115 | // If the EFI Variable can not be accessed when this module's library constructors are\r | |
116 | // executed, then the EFI Variable access will be reattempted on every DEBUG() print\r | |
117 | // from this module until the EFI Variable services are available.\r | |
118 | //\r | |
119 | GetDebugPrintErrorLevel ();\r | |
120 | \r | |
121 | return Status;\r | |
122 | }\r | |
123 | \r | |
124 | /**\r | |
125 | The destructor function frees any allocated buffers and closes the Set Virtual \r | |
126 | Address Map event.\r | |
127 | \r | |
128 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
129 | @param SystemTable A pointer to the EFI System Table.\r | |
130 | \r | |
131 | @retval EFI_SUCCESS The destructor completed successfully.\r | |
132 | @retval Other value The destructor did not complete successfully.\r | |
133 | \r | |
134 | **/\r | |
135 | EFI_STATUS\r | |
136 | EFIAPI\r | |
137 | DxeDebugPrintErrorLevelLibDestructor (\r | |
138 | IN EFI_HANDLE ImageHandle,\r | |
139 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
140 | )\r | |
141 | {\r | |
142 | //\r | |
143 | // Uninstall the Debug Mask Protocol from ImageHandle\r | |
144 | // \r | |
145 | return SystemTable->BootServices->UninstallMultipleProtocolInterfaces (\r | |
146 | ImageHandle,\r | |
147 | &gEfiDebugMaskProtocolGuid, &mDebugMaskProtocol,\r | |
148 | NULL\r | |
149 | );\r | |
150 | }\r | |
151 | \r | |
152 | /**\r | |
153 | Returns the debug print error level mask for the current module.\r | |
154 | \r | |
155 | @return Debug print error level mask for the current module.\r | |
156 | \r | |
157 | **/\r | |
158 | UINT32\r | |
159 | EFIAPI\r | |
160 | GetDebugPrintErrorLevel (\r | |
161 | VOID\r | |
162 | )\r | |
163 | {\r | |
164 | EFI_STATUS Status;\r | |
165 | EFI_TPL CurrentTpl;\r | |
166 | UINTN Size;\r | |
167 | UINTN GlobalErrorLevel;\r | |
168 | \r | |
169 | //\r | |
170 | // If the constructor has not been executed yet, then just return the PCD value.\r | |
171 | // This case should only occur if debug print is generated by a library\r | |
172 | // constructor for this module\r | |
173 | //\r | |
174 | if (mST == NULL) {\r | |
175 | return PcdGet32 (PcdDebugPrintErrorLevel);\r | |
176 | }\r | |
177 | \r | |
178 | //\r | |
179 | // Check to see if an attempt has been mde to retrieve the global debug print \r | |
180 | // error level mask. Since this libtrary instance stores the global debug print\r | |
181 | // error level mask in an EFI Variable, the EFI Variable should only be accessed\r | |
182 | // once to reduce the overhead of reading the EFI Variable on every debug print\r | |
183 | // \r | |
184 | if (!mGlobalErrorLevelInitialized) {\r | |
185 | //\r | |
186 | // Make sure the TPL Level is low enough for EFI Variable Services to be called\r | |
187 | //\r | |
188 | CurrentTpl = mST->BootServices->RaiseTPL (TPL_HIGH_LEVEL);\r | |
189 | mST->BootServices->RestoreTPL (CurrentTpl);\r | |
190 | if (CurrentTpl <= TPL_CALLBACK) {\r | |
191 | //\r | |
192 | // Attempt to retrieve the global debug print error level mask from the \r | |
193 | // EFI Variable\r | |
194 | //\r | |
195 | Size = sizeof (GlobalErrorLevel);\r | |
196 | Status = mST->RuntimeServices->GetVariable (\r | |
197 | DEBUG_MASK_VARIABLE_NAME, \r | |
198 | &gEfiGenericVariableGuid, \r | |
199 | NULL, \r | |
200 | &Size, \r | |
201 | &GlobalErrorLevel\r | |
202 | );\r | |
203 | if (Status != EFI_NOT_AVAILABLE_YET) {\r | |
204 | //\r | |
205 | // If EFI Variable Services are available, then set a flag so the EFI\r | |
206 | // Variable will not be read again by this module.\r | |
207 | //\r | |
208 | mGlobalErrorLevelInitialized = TRUE;\r | |
209 | if (!EFI_ERROR (Status)) {\r | |
210 | //\r | |
211 | // If the EFI Varible exists, then set this module's module's mask to\r | |
212 | // the global debug print error level mask value.\r | |
213 | //\r | |
214 | mDebugPrintErrorLevel = (UINT32)GlobalErrorLevel;\r | |
215 | }\r | |
216 | }\r | |
217 | }\r | |
218 | }\r | |
219 | \r | |
220 | //\r | |
221 | // Return the current mask value for this module.\r | |
222 | //\r | |
223 | return mDebugPrintErrorLevel;\r | |
224 | }\r | |
225 | \r | |
226 | /**\r | |
227 | Sets the global debug print error level mask fpr the entire platform.\r | |
228 | \r | |
229 | @retval TRUE The debug print error level mask was sucessfully set.\r | |
230 | @retval FALSE The debug print error level mask could not be set.\r | |
231 | \r | |
232 | **/\r | |
233 | BOOLEAN\r | |
234 | EFIAPI\r | |
235 | SetDebugPrintErrorLevel (\r | |
236 | UINT32 ErrorLevel\r | |
237 | )\r | |
238 | {\r | |
239 | EFI_STATUS Status;\r | |
240 | EFI_TPL CurrentTpl;\r | |
241 | UINTN Size;\r | |
242 | UINTN GlobalErrorLevel;\r | |
243 | \r | |
244 | //\r | |
245 | // Make sure the constructor has been executed\r | |
246 | //\r | |
247 | if (mST != NULL) {\r | |
248 | //\r | |
249 | // Make sure the TPL Level is low enough for EFI Variable Services\r | |
250 | //\r | |
251 | CurrentTpl = mST->BootServices->RaiseTPL (TPL_HIGH_LEVEL);\r | |
252 | mST->BootServices->RestoreTPL (CurrentTpl);\r | |
253 | if (CurrentTpl <= TPL_CALLBACK) {\r | |
254 | //\r | |
255 | // Attempt to store the global debug print error level mask in an EFI Variable\r | |
256 | //\r | |
257 | GlobalErrorLevel = (UINTN)ErrorLevel;\r | |
258 | Size = sizeof (GlobalErrorLevel);\r | |
259 | Status = mST->RuntimeServices->SetVariable (\r | |
260 | DEBUG_MASK_VARIABLE_NAME, \r | |
261 | &gEfiGenericVariableGuid, \r | |
262 | (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS),\r | |
263 | Size,\r | |
264 | &GlobalErrorLevel\r | |
265 | );\r | |
266 | if (!EFI_ERROR (Status)) {\r | |
267 | //\r | |
268 | // If the EFI Variable was updated, then update the mask value for this \r | |
269 | // module and return TRUE.\r | |
270 | //\r | |
271 | mGlobalErrorLevelInitialized = TRUE; \r | |
272 | mDebugPrintErrorLevel = ErrorLevel;\r | |
273 | return TRUE;\r | |
274 | }\r | |
275 | }\r | |
276 | }\r | |
277 | //\r | |
278 | // Return FALSE since the EFI Variable could not be updated.\r | |
279 | //\r | |
280 | return FALSE;\r | |
281 | }\r | |
282 | \r | |
283 | /**\r | |
284 | Retrieves the current debug print error level mask for a module are returns\r | |
285 | it in CurrentDebugMask.\r | |
286 | \r | |
287 | @param This The protocol instance pointer.\r | |
288 | @param CurrentDebugMask Pointer to the debug print error level mask that \r | |
289 | is returned.\r | |
290 | \r | |
291 | @retval EFI_SUCCESS The current debug print error level mask was\r | |
292 | returned in CurrentDebugMask.\r | |
293 | @retval EFI_INVALID_PARAMETER CurrentDebugMask is NULL.\r | |
294 | @retval EFI_DEVICE_ERROR The current debug print error level mask could\r | |
295 | not be retrieved.\r | |
296 | \r | |
297 | **/\r | |
298 | EFI_STATUS\r | |
299 | EFIAPI\r | |
300 | GetDebugMask (\r | |
301 | IN EFI_DEBUG_MASK_PROTOCOL *This, \r | |
302 | IN OUT UINTN *CurrentDebugMask \r | |
303 | )\r | |
304 | {\r | |
305 | if (CurrentDebugMask == NULL) {\r | |
306 | return EFI_INVALID_PARAMETER;\r | |
307 | }\r | |
308 | \r | |
309 | //\r | |
310 | // Retrieve the current debug mask from mDebugPrintErrorLevel\r | |
311 | //\r | |
312 | *CurrentDebugMask = (UINTN)mDebugPrintErrorLevel;\r | |
313 | return EFI_SUCCESS;\r | |
314 | }\r | |
315 | \r | |
316 | /**\r | |
317 | Sets the current debug print error level mask for a module to the value\r | |
318 | specified by NewDebugMask.\r | |
319 | \r | |
320 | @param This The protocol instance pointer.\r | |
321 | @param NewDebugMask The new debug print error level mask for this module.\r | |
322 | \r | |
323 | @retval EFI_SUCCESS The current debug print error level mask was\r | |
324 | set to the value specified by NewDebugMask.\r | |
325 | @retval EFI_DEVICE_ERROR The current debug print error level mask could\r | |
326 | not be set to the value specified by NewDebugMask.\r | |
327 | \r | |
328 | **/\r | |
329 | EFI_STATUS\r | |
330 | EFIAPI\r | |
331 | SetDebugMask (\r | |
332 | IN EFI_DEBUG_MASK_PROTOCOL *This,\r | |
333 | IN UINTN NewDebugMask\r | |
334 | )\r | |
335 | {\r | |
336 | //\r | |
337 | // Store the new debug mask into mDebugPrintErrorLevel\r | |
338 | //\r | |
339 | mDebugPrintErrorLevel = (UINT32)NewDebugMask;\r | |
340 | return EFI_SUCCESS;\r | |
341 | }\r |