1 /** @file 2 Provides services to log status code records. 3 4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials are licensed and made available under 6 the terms and conditions of the BSD License that accompanies this distribution. 7 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 #ifndef __REPORT_STATUS_CODE_LIB_H__ 16 #define __REPORT_STATUS_CODE_LIB_H__ 17 18 #include <Uefi/UefiBaseType.h> 19 #include <Pi/PiStatusCode.h> 20 #include <Protocol/DevicePath.h> 21 22 // 23 // Declare bits for PcdReportStatusCodePropertyMask 24 // 25 #define REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED 0x00000001 26 #define REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED 0x00000002 27 #define REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED 0x00000004 28 29 /** 30 Converts a status code to an 8-bit POST code value. 31 32 Converts the status code specified by CodeType and Value to an 8-bit POST code 33 and returns the 8-bit POST code in PostCode. If CodeType is an 34 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode 35 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits 36 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned. 37 38 If PostCode is NULL, then ASSERT(). 39 40 @param CodeType The type of status code being converted. 41 @param Value The status code value being converted. 42 @param PostCode A pointer to the 8-bit POST code value to return. 43 44 @retval TRUE The status code specified by CodeType and Value was converted 45 to an 8-bit POST code and returned in PostCode. 46 @retval FALSE The status code specified by CodeType and Value could not be 47 converted to an 8-bit POST code value. 48 49 **/ 50 BOOLEAN 51 EFIAPI 52 CodeTypeToPostCode ( 53 IN EFI_STATUS_CODE_TYPE CodeType, 54 IN EFI_STATUS_CODE_VALUE Value, 55 OUT UINT8 *PostCode 56 ); 57 58 59 /** 60 Extracts ASSERT() information from a status code structure. 61 62 Converts the status code specified by CodeType, Value, and Data to the ASSERT() 63 arguments specified by Filename, Description, and LineNumber. If CodeType is 64 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and 65 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract 66 Filename, Description, and LineNumber from the optional data area of the 67 status code buffer specified by Data. The optional data area of Data contains 68 a Null-terminated ASCII string for the FileName, followed by a Null-terminated 69 ASCII string for the Description, followed by a 32-bit LineNumber. If the 70 ASSERT() information could be extracted from Data, then return TRUE. 71 Otherwise, FALSE is returned. 72 73 If Data is NULL, then ASSERT(). 74 If Filename is NULL, then ASSERT(). 75 If Description is NULL, then ASSERT(). 76 If LineNumber is NULL, then ASSERT(). 77 78 @param CodeType The type of status code being converted. 79 @param Value The status code value being converted. 80 @param Data The pointer to status code data buffer. 81 @param Filename The pointer to the source file name that generated the ASSERT(). 82 @param Description The pointer to the description of the ASSERT(). 83 @param LineNumber The pointer to source line number that generated the ASSERT(). 84 85 @retval TRUE The status code specified by CodeType, Value, and Data was 86 converted ASSERT() arguments specified by Filename, Description, 87 and LineNumber. 88 @retval FALSE The status code specified by CodeType, Value, and Data could 89 not be converted to ASSERT() arguments. 90 91 **/ 92 BOOLEAN 93 EFIAPI 94 ReportStatusCodeExtractAssertInfo ( 95 IN EFI_STATUS_CODE_TYPE CodeType, 96 IN EFI_STATUS_CODE_VALUE Value, 97 IN CONST EFI_STATUS_CODE_DATA *Data, 98 OUT CHAR8 **Filename, 99 OUT CHAR8 **Description, 100 OUT UINT32 *LineNumber 101 ); 102 103 104 /** 105 Extracts DEBUG() information from a status code structure. 106 107 Converts the status code specified by Data to the DEBUG() arguments specified 108 by ErrorLevel, Marker, and Format. If type GUID in Data is 109 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and 110 Format from the optional data area of the status code buffer specified by Data. 111 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker 112 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for 113 the Format. If the DEBUG() information could be extracted from Data, then 114 return TRUE. Otherwise, FALSE is returned. 115 116 If Data is NULL, then ASSERT(). 117 If ErrorLevel is NULL, then ASSERT(). 118 If Marker is NULL, then ASSERT(). 119 If Format is NULL, then ASSERT(). 120 121 @param Data The pointer to status code data buffer. 122 @param ErrorLevel The pointer to error level mask for a debug message. 123 @param Marker The pointer to the variable argument list associated with Format. 124 @param Format The pointer to a Null-terminated ASCII format string of a 125 debug message. 126 127 @retval TRUE The status code specified by Data was converted DEBUG() arguments 128 specified by ErrorLevel, Marker, and Format. 129 @retval FALSE The status code specified by Data could not be converted to 130 DEBUG() arguments. 131 132 **/ 133 BOOLEAN 134 EFIAPI 135 ReportStatusCodeExtractDebugInfo ( 136 IN CONST EFI_STATUS_CODE_DATA *Data, 137 OUT UINT32 *ErrorLevel, 138 OUT BASE_LIST *Marker, 139 OUT CHAR8 **Format 140 ); 141 142 143 /** 144 Reports a status code. 145 146 Reports the status code specified by the parameters Type and Value. Status 147 code also require an instance, caller ID, and extended data. This function 148 passed in a zero instance, NULL extended data, and a caller ID of 149 gEfiCallerIdGuid, which is the GUID for the module. 150 151 ReportStatusCode()must actively prevent recursion. If ReportStatusCode() 152 is called while processing another any other Report Status Code Library function, 153 then ReportStatusCode() must return immediately. 154 155 @param Type Status code type. 156 @param Value Status code value. 157 158 @retval EFI_SUCCESS The status code was reported. 159 @retval EFI_DEVICE_ERROR There status code could not be reported due to a 160 device error. 161 @retval EFI_UNSUPPORTED The report status code is not supported. 162 163 **/ 164 EFI_STATUS 165 EFIAPI 166 ReportStatusCode ( 167 IN EFI_STATUS_CODE_TYPE Type, 168 IN EFI_STATUS_CODE_VALUE Value 169 ); 170 171 172 /** 173 Reports a status code with a Device Path Protocol as the extended data. 174 175 Allocates and fills in the extended data section of a status code with the 176 Device Path Protocol specified by DevicePath. This function is responsible 177 for allocating a buffer large enough for the standard header and the device 178 path. The standard header is filled in with an implementation dependent GUID. 179 The status code is reported with a zero instance and a caller ID of gEfiCallerIdGuid. 180 181 ReportStatusCodeWithDevicePath()must actively prevent recursion. If 182 ReportStatusCodeWithDevicePath() is called while processing another any other 183 Report Status Code Library function, then ReportStatusCodeWithDevicePath() 184 must return EFI_DEVICE_ERROR immediately. 185 186 If DevicePath is NULL, then ASSERT(). 187 188 @param Type The status code type. 189 @param Value The status code value. 190 @param DevicePath The pointer to the Device Path Protocol to be reported. 191 192 @retval EFI_SUCCESS The status code was reported with the extended 193 data specified by DevicePath. 194 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the 195 extended data section. 196 @retval EFI_UNSUPPORTED The report status code is not supported. 197 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function 198 is already in progress. 199 200 **/ 201 EFI_STATUS 202 EFIAPI 203 ReportStatusCodeWithDevicePath ( 204 IN EFI_STATUS_CODE_TYPE Type, 205 IN EFI_STATUS_CODE_VALUE Value, 206 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath 207 ); 208 209 210 /** 211 Reports a status code with an extended data buffer. 212 213 Allocates and fills in the extended data section of a status code with the 214 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData 215 is assumed to be one of the data structures specified in Related Definitions. 216 These data structure do not have the standard header, so this function is 217 responsible for allocating a buffer large enough for the standard header and 218 the extended data passed into this function. The standard header is filled 219 in with an implementation dependent GUID. The status code is reported 220 with a zero instance and a caller ID of gEfiCallerIdGuid. 221 222 ReportStatusCodeWithExtendedData()must actively prevent recursion. If 223 ReportStatusCodeWithExtendedData() is called while processing another any other 224 Report Status Code Library function, then ReportStatusCodeWithExtendedData() 225 must return EFI_DEVICE_ERROR immediately. 226 227 If ExtendedData is NULL, then ASSERT(). 228 If ExtendedDataSize is 0, then ASSERT(). 229 230 @param Type The status code type. 231 @param Value The status code value. 232 @param ExtendedData The pointer to the extended data buffer to be reported. 233 @param ExtendedDataSize The size, in bytes, of the extended data buffer to 234 be reported. 235 236 @retval EFI_SUCCESS The status code was reported with the extended 237 data specified by ExtendedData and ExtendedDataSize. 238 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the 239 extended data section. 240 @retval EFI_UNSUPPORTED The report status code is not supported. 241 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function 242 is already in progress. 243 244 **/ 245 EFI_STATUS 246 EFIAPI 247 ReportStatusCodeWithExtendedData ( 248 IN EFI_STATUS_CODE_TYPE Type, 249 IN EFI_STATUS_CODE_VALUE Value, 250 IN CONST VOID *ExtendedData, 251 IN UINTN ExtendedDataSize 252 ); 253 254 255 /** 256 Reports a status code with full parameters. 257 258 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize 259 is 0, then an extended data buffer is not reported. If ExtendedData is not 260 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated. 261 ExtendedData is assumed not have the standard status code header, so this function 262 is responsible for allocating a buffer large enough for the standard header and 263 the extended data passed into this function. The standard header is filled in 264 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a 265 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with 266 an instance specified by Instance and a caller ID specified by CallerId. If 267 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used. 268 269 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx() 270 is called while processing another any other Report Status Code Library function, 271 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately. 272 273 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT(). 274 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT(). 275 276 @param Type The status code type. 277 @param Value The status code value. 278 @param Instance The status code instance number. 279 @param CallerId The pointer to a GUID that identifies the caller of this 280 function. If this parameter is NULL, then a caller 281 ID of gEfiCallerIdGuid is used. 282 @param ExtendedDataGuid The pointer to the GUID for the extended data buffer. 283 If this parameter is NULL, then a the status code 284 standard header is filled in with an implementation dependent GUID. 285 @param ExtendedData The pointer to the extended data buffer. This is an 286 optional parameter that may be NULL. 287 @param ExtendedDataSize The size, in bytes, of the extended data buffer. 288 289 @retval EFI_SUCCESS The status code was reported. 290 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate 291 the extended data section if it was specified. 292 @retval EFI_UNSUPPORTED The report status code is not supported. 293 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function 294 is already in progress. 295 296 **/ 297 EFI_STATUS 298 EFIAPI 299 ReportStatusCodeEx ( 300 IN EFI_STATUS_CODE_TYPE Type, 301 IN EFI_STATUS_CODE_VALUE Value, 302 IN UINT32 Instance, 303 IN CONST EFI_GUID *CallerId OPTIONAL, 304 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL, 305 IN CONST VOID *ExtendedData OPTIONAL, 306 IN UINTN ExtendedDataSize 307 ); 308 309 310 /** 311 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled 312 313 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED 314 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned. 315 316 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of 317 PcdReportStatusCodeProperyMask is set. 318 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of 319 PcdReportStatusCodeProperyMask is clear. 320 321 **/ 322 BOOLEAN 323 EFIAPI 324 ReportProgressCodeEnabled ( 325 VOID 326 ); 327 328 329 /** 330 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled 331 332 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED 333 bit of PcdReportStatusCodeProperyMask is set. Otherwise, FALSE is returned. 334 335 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of 336 PcdReportStatusCodeProperyMask is set. 337 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of 338 PcdReportStatusCodeProperyMask is clear. 339 340 **/ 341 BOOLEAN 342 EFIAPI 343 ReportErrorCodeEnabled ( 344 VOID 345 ); 346 347 348 /** 349 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled 350 351 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED 352 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned. 353 354 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of 355 PcdReportStatusCodeProperyMask is set. 356 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of 357 PcdReportStatusCodeProperyMask is clear. 358 359 **/ 360 BOOLEAN 361 EFIAPI 362 ReportDebugCodeEnabled ( 363 VOID 364 ); 365 366 367 /** 368 Reports a status code with minimal parameters if the status code type is enabled. 369 370 If the status code type specified by Type is enabled in 371 PcdReportStatusCodeProperyMask, then call ReportStatusCode() passing in Type 372 and Value. 373 374 @param Type The status code type. 375 @param Value The status code value. 376 377 @retval EFI_SUCCESS The status code was reported. 378 @retval EFI_DEVICE_ERROR There status code could not be reported due to a device error. 379 @retval EFI_UNSUPPORTED Report status code is not supported. 380 381 **/ 382 #define REPORT_STATUS_CODE(Type,Value) \ 383 (ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ? \ 384 ReportStatusCode(Type,Value) : \ 385 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ? \ 386 ReportStatusCode(Type,Value) : \ 387 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) ? \ 388 ReportStatusCode(Type,Value) : \ 389 EFI_UNSUPPORTED 390 391 392 /** 393 Reports a status code with a Device Path Protocol as the extended data if the 394 status code type is enabled. 395 396 If the status code type specified by Type is enabled in 397 PcdReportStatusCodeProperyMask, then call ReportStatusCodeWithDevicePath() 398 passing in Type, Value, and DevicePath. 399 400 @param Type The status code type. 401 @param Value The status code value. 402 @param DevicePath Pointer to the Device Path Protocol to be reported. 403 404 @retval EFI_SUCCESS The status code was reported with the extended 405 data specified by DevicePath. 406 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the 407 extended data section. 408 @retval EFI_UNSUPPORTED The report status code is not supported. 409 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function 410 is already in progress. 411 412 **/ 413 #define REPORT_STATUS_CODE_WITH_DEVICE_PATH(Type,Value,DevicePathParameter) \ 414 (ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ? \ 415 ReportStatusCodeWithDevicePath(Type,Value,DevicePathParameter) : \ 416 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ? \ 417 ReportStatusCodeWithDevicePath(Type,Value,DevicePathParameter) : \ 418 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) ? \ 419 ReportStatusCodeWithDevicePath(Type,Value,DevicePathParameter) : \ 420 EFI_UNSUPPORTED 421 422 423 /** 424 Reports a status code with an extended data buffer if the status code type 425 is enabled. 426 427 If the status code type specified by Type is enabled in 428 PcdReportStatusCodeProperyMask, then call ReportStatusCodeWithExtendedData() 429 passing in Type, Value, ExtendedData, and ExtendedDataSize. 430 431 @param Type The status code type. 432 @param Value The status code value. 433 @param ExtendedData The pointer to the extended data buffer to be reported. 434 @param ExtendedDataSize The size, in bytes, of the extended data buffer to 435 be reported. 436 437 @retval EFI_SUCCESS The status code was reported with the extended 438 data specified by ExtendedData and ExtendedDataSize. 439 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the 440 extended data section. 441 @retval EFI_UNSUPPORTED The report status code is not supported. 442 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function 443 is already in progress. 444 445 **/ 446 #define REPORT_STATUS_CODE_WITH_EXTENDED_DATA(Type,Value,ExtendedData,ExtendedDataSize) \ 447 (ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ? \ 448 ReportStatusCodeWithExtendedData(Type,Value,ExtendedData,ExtendedDataSize) : \ 449 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ? \ 450 ReportStatusCodeWithExtendedData(Type,Value,ExtendedData,ExtendedDataSize) : \ 451 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) ? \ 452 ReportStatusCodeWithExtendedData(Type,Value,ExtendedData,ExtendedDataSize) : \ 453 EFI_UNSUPPORTED 454 455 /** 456 Reports a status code specifying all parameters if the status code type is enabled. 457 458 If the status code type specified by Type is enabled in 459 PcdReportStatusCodeProperyMask, then call ReportStatusCodeEx() passing in Type, 460 Value, Instance, CallerId, ExtendedDataGuid, ExtendedData, and ExtendedDataSize. 461 462 @param Type The status code type. 463 @param Value The status code value. 464 @param Instance The status code instance number. 465 @param CallerId The pointer to a GUID that identifies the caller of this 466 function. If this parameter is NULL, then a caller 467 ID of gEfiCallerIdGuid is used. 468 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer. 469 If this parameter is NULL, then a the status code 470 standard header is filled in with an implementation dependent GUID. 471 @param ExtendedData Pointer to the extended data buffer. This is an 472 optional parameter that may be NULL. 473 @param ExtendedDataSize The size, in bytes, of the extended data buffer. 474 475 @retval EFI_SUCCESS The status code was reported. 476 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the 477 extended data section if it was specified. 478 @retval EFI_UNSUPPORTED The report status code is not supported. 479 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function 480 is already in progress. 481 482 **/ 483 #define REPORT_STATUS_CODE_EX(Type,Value,Instance,CallerId,ExtendedDataGuid,ExtendedData,ExtendedDataSize) \ 484 (ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ? \ 485 ReportStatusCodeEx(Type,Value,Instance,CallerId,ExtendedDataGuid,ExtendedData,ExtendedDataSize) : \ 486 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ? \ 487 ReportStatusCodeEx(Type,Value,Instance,CallerId,ExtendedDataGuid,ExtendedData,ExtendedDataSize) : \ 488 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) ? \ 489 ReportStatusCodeEx(Type,Value,Instance,CallerId,ExtendedDataGuid,ExtendedData,ExtendedDataSize) : \ 490 EFI_UNSUPPORTED 491 492 #endif 493