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