ExSerialStatusCodeWorker.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /** @file
  2. @copyright
  3. Copyright 2017 - 2021 Intel Corporation. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "ExStatusCodeHandlerPei.h"
  7. /**
  8. Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
  9. @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
  10. @param CodeType Indicates the type of status code being reported.
  11. @param Value Describes the current status of a hardware or
  12. software entity. This includes information about the class and
  13. subclass that is used to classify the entity as well as an operation.
  14. For progress codes, the operation is the current activity.
  15. For error codes, it is the exception.For debug codes,it is not defined at this time.
  16. @param Instance The enumeration of a hardware or software entity within
  17. the system. A system may contain multiple entities that match a class/subclass
  18. pairing. The instance differentiates between them. An instance of 0 indicates
  19. that instance information is unavailable, not meaningful, or not relevant.
  20. Valid instance numbers start with 1.
  21. @param CallerId This optional parameter may be used to identify the caller.
  22. This parameter allows the status code driver to apply different rules to
  23. different callers.
  24. @param Data This optional parameter may be used to pass additional data.
  25. @retval EFI_SUCCESS Status code reported to serial I/O successfully.
  26. **/
  27. EFI_STATUS
  28. EFIAPI
  29. ExSerialStatusCodeReportWorker (
  30. IN CONST EFI_PEI_SERVICES **PeiServices,
  31. IN EFI_STATUS_CODE_TYPE CodeType,
  32. IN EFI_STATUS_CODE_VALUE Value,
  33. IN UINT32 Instance,
  34. IN CONST EFI_GUID *CallerId,
  35. IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
  36. )
  37. {
  38. CHAR8 *Filename;
  39. CHAR8 *Description;
  40. CHAR8 *Format;
  41. CHAR8 Buffer[MAX_EX_DEBUG_STR_LEN];
  42. CHAR8 *BufferPtr;
  43. UINT32 ErrorLevel;
  44. UINT32 LineNumber;
  45. UINTN CharCount;
  46. BASE_LIST Marker;
  47. EX_DEBUG_INFO *ExDebugInfo = NULL;
  48. Buffer[0] = '\0';
  49. CharCount = 0;
  50. if (Data != NULL &&
  51. CompareGuid (&Data->Type, &gStatusCodeDataTypeExDebugGuid)) {
  52. ExDebugInfo = (EX_DEBUG_INFO*)(Data + 1);
  53. } else if (Data != NULL &&
  54. ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
  55. //
  56. // Print ASSERT() information into output buffer.
  57. //
  58. CharCount = AsciiSPrint (
  59. Buffer,
  60. sizeof (Buffer),
  61. "\n\rPEI_ASSERT!: %a (%d): %a\n\r",
  62. Filename,
  63. LineNumber,
  64. Description
  65. );
  66. } else if (Data != NULL &&
  67. ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
  68. //
  69. // Print DEBUG() information into output buffer.
  70. //
  71. CharCount = AsciiBSPrint (
  72. Buffer,
  73. sizeof (Buffer),
  74. Format,
  75. Marker
  76. );
  77. } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
  78. //
  79. // Print ERROR information into output buffer.
  80. //
  81. CharCount = AsciiSPrint (
  82. Buffer,
  83. sizeof (Buffer),
  84. "ERROR: C%08x:V%08x I%x",
  85. CodeType,
  86. Value,
  87. Instance
  88. );
  89. ASSERT(CharCount > 0);
  90. if (CallerId != NULL) {
  91. CharCount += AsciiSPrint (
  92. &Buffer[CharCount],
  93. (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
  94. " %g",
  95. CallerId
  96. );
  97. }
  98. if (Data != NULL) {
  99. CharCount += AsciiSPrint (
  100. &Buffer[CharCount],
  101. (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
  102. " %x",
  103. Data
  104. );
  105. }
  106. CharCount += AsciiSPrint (
  107. &Buffer[CharCount],
  108. (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
  109. "\n\r"
  110. );
  111. } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
  112. //
  113. // Print PROGRESS information into output buffer.
  114. //
  115. CharCount = AsciiSPrint (
  116. Buffer,
  117. sizeof (Buffer),
  118. "PROGRESS CODE: V%08x I%x\n\r",
  119. Value,
  120. Instance
  121. );
  122. } else if (Data != NULL &&
  123. CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) &&
  124. ((EFI_STATUS_CODE_STRING_DATA *) Data)->StringType == EfiStringAscii) {
  125. //
  126. // EFI_STATUS_CODE_STRING_DATA
  127. //
  128. CharCount = AsciiSPrint (
  129. Buffer,
  130. sizeof (Buffer),
  131. "%a\n\r",
  132. ((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii
  133. );
  134. } else {
  135. //
  136. // Code type is not defined.
  137. //
  138. CharCount = AsciiSPrint (
  139. Buffer,
  140. sizeof (Buffer),
  141. "Undefined: C%08x:V%08x I%x\n\r",
  142. CodeType,
  143. Value,
  144. Instance
  145. );
  146. }
  147. //
  148. // No EX info, just print and exit.
  149. //
  150. if (ExDebugInfo == NULL) {
  151. SerialPortWrite ((UINT8*)Buffer, CharCount);
  152. return EFI_SUCCESS;
  153. }
  154. //
  155. // EX handling here - point at correct string and then take action.
  156. // Acquire print, process buffer, write to serial, release print.
  157. // Skip any if not requested.
  158. //
  159. CharCount = ExDebugInfo->DebugStringLen;
  160. BufferPtr = ExDebugInfo->DebugString;
  161. if (ExDebugInfo->PrintSyncAcquire != NULL) {
  162. ExDebugInfo->PrintSyncAcquire ();
  163. }
  164. if (ExDebugInfo->ProcessBuffer != NULL) {
  165. BufferPtr = ExDebugInfo->ProcessBuffer (
  166. ExDebugInfo->ProcessDataPtr,
  167. Buffer,
  168. &CharCount
  169. );
  170. }
  171. if (BufferPtr != NULL) {
  172. SerialPortWrite ((UINT8*)BufferPtr, CharCount);
  173. }
  174. if (ExDebugInfo != NULL && ExDebugInfo->PrintSyncRelease != NULL) {
  175. ExDebugInfo->PrintSyncRelease ();
  176. }
  177. return EFI_SUCCESS;
  178. }