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