]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/StatusCode/RuntimeDxe/SerialStatusCodeWorker.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / RuntimeDxe / SerialStatusCodeWorker.c
CommitLineData
ad1a1798 1/** @file\r
2 Serial I/O status code reporting worker.\r
3\r
0a6f4824 4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
c0a00b14 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
ad1a1798 6\r
ad1a1798 7**/\r
8\r
20e7a774 9#include "StatusCodeRuntimeDxe.h"\r
ad1a1798 10\r
ad1a1798 11/**\r
12 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.\r
0a6f4824 13\r
a8cbf345 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
ad1a1798 28\r
29**/\r
30EFI_STATUS\r
31SerialStatusCodeReportWorker (\r
32 IN EFI_STATUS_CODE_TYPE CodeType,\r
33 IN EFI_STATUS_CODE_VALUE Value,\r
34 IN UINT32 Instance,\r
35 IN EFI_GUID *CallerId,\r
36 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
37 )\r
38{\r
39 CHAR8 *Filename;\r
40 CHAR8 *Description;\r
41 CHAR8 *Format;\r
42 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
43 UINT32 ErrorLevel;\r
44 UINT32 LineNumber;\r
45 UINTN CharCount;\r
ca9938b8 46 BASE_LIST Marker;\r
ad1a1798 47\r
ad1a1798 48 Buffer[0] = '\0';\r
49\r
50 if (Data != NULL &&\r
51 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
52 //\r
53 // Print ASSERT() information into output buffer.\r
54 //\r
55 CharCount = AsciiSPrint (\r
56 Buffer,\r
1ca88083 57 sizeof (Buffer),\r
ad1a1798 58 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",\r
59 Filename,\r
60 LineNumber,\r
61 Description\r
62 );\r
63 } else if (Data != NULL &&\r
64 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
65 //\r
66 // Print DEBUG() information into output buffer.\r
67 //\r
ca9938b8 68 CharCount = AsciiBSPrint (\r
0a6f4824
LG
69 Buffer,\r
70 sizeof (Buffer),\r
71 Format,\r
ad1a1798 72 Marker\r
73 );\r
ad1a1798 74 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
75 //\r
76 // Print ERROR information into output buffer.\r
77 //\r
78 CharCount = AsciiSPrint (\r
0a6f4824
LG
79 Buffer,\r
80 sizeof (Buffer),\r
81 "ERROR: C%08x:V%08x I%x",\r
82 CodeType,\r
83 Value,\r
ad1a1798 84 Instance\r
85 );\r
0a6f4824 86\r
ad1a1798 87 if (CallerId != NULL) {\r
88 CharCount += AsciiSPrint (\r
af03df86 89 &Buffer[CharCount],\r
1ca88083 90 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
ad1a1798 91 " %g",\r
92 CallerId\r
93 );\r
94 }\r
95\r
96 if (Data != NULL) {\r
97 CharCount += AsciiSPrint (\r
af03df86 98 &Buffer[CharCount],\r
1ca88083 99 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
ad1a1798 100 " %x",\r
101 Data\r
102 );\r
103 }\r
104\r
105 CharCount += AsciiSPrint (\r
af03df86 106 &Buffer[CharCount],\r
1ca88083 107 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
ad1a1798 108 "\n\r"\r
109 );\r
110 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
a8cbf345 111 //\r
112 // Print PROGRESS information into output buffer.\r
113 //\r
ad1a1798 114 CharCount = AsciiSPrint (\r
0a6f4824
LG
115 Buffer,\r
116 sizeof (Buffer),\r
117 "PROGRESS CODE: V%08x I%x\n\r",\r
118 Value,\r
ad1a1798 119 Instance\r
120 );\r
10c9a2e3 121 } else if (Data != NULL &&\r
122 CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) &&\r
5d4a0dbc 123 ((EFI_STATUS_CODE_STRING_DATA *) Data)->StringType == EfiStringAscii) {\r
124 //\r
125 // EFI_STATUS_CODE_STRING_DATA\r
126 //\r
127 CharCount = AsciiSPrint (\r
128 Buffer,\r
129 sizeof (Buffer),\r
130 "%a\n\r",\r
131 ((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii\r
132 );\r
ad1a1798 133 } else {\r
a8cbf345 134 //\r
135 // Code type is not defined.\r
136 //\r
ad1a1798 137 CharCount = AsciiSPrint (\r
0a6f4824
LG
138 Buffer,\r
139 sizeof (Buffer),\r
140 "Undefined: C%08x:V%08x I%x\n\r",\r
141 CodeType,\r
142 Value,\r
ad1a1798 143 Instance\r
144 );\r
145 }\r
146\r
d2c315e6
LG
147 //\r
148 // Call SerialPort Lib function to do print.\r
149 //\r
150 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
ad1a1798 151\r
152 return EFI_SUCCESS;\r
153}\r
bcd70414 154\r