]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/StatusCode/RuntimeDxe/SerialStatusCodeWorker.c
Reviewed the code comments in the Include/Protocol directory for typos, grammar issue...
[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
a8cbf345 4 Copyright (c) 2006 - 2009, Intel Corporation \r
ad1a1798 5 All rights reserved. This program and the accompanying materials \r
6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php \r
9 \r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
ad1a1798 13**/\r
14\r
20e7a774 15#include "StatusCodeRuntimeDxe.h"\r
ad1a1798 16\r
ad1a1798 17EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol;\r
18\r
19/**\r
a8cbf345 20 Locates Serial I/O Protocol as initialization for serial status code worker.\r
ad1a1798 21 \r
a8cbf345 22 @retval EFI_SUCCESS Serial I/O Protocol is successfully located.\r
ad1a1798 23\r
24**/\r
25EFI_STATUS\r
26EfiSerialStatusCodeInitializeWorker (\r
27 VOID\r
28 )\r
29{\r
30 EFI_STATUS Status;\r
31\r
32 Status = gBS->LocateProtocol (\r
33 &gEfiSerialIoProtocolGuid,\r
34 NULL,\r
35 (VOID **) &mSerialIoProtocol\r
36 );\r
37\r
38 ASSERT_EFI_ERROR (Status);\r
39\r
40 return EFI_SUCCESS;\r
41}\r
42\r
43\r
44/**\r
45 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.\r
46 \r
a8cbf345 47 @param CodeType Indicates the type of status code being reported.\r
48 @param Value Describes the current status of a hardware or software entity.\r
49 This included information about the class and subclass that is used to\r
50 classify the entity as well as an operation.\r
51 @param Instance The enumeration of a hardware or software entity within\r
52 the system. Valid instance numbers start with 1.\r
53 @param CallerId This optional parameter may be used to identify the caller.\r
54 This parameter allows the status code driver to apply different rules to\r
55 different callers.\r
56 @param Data This optional parameter may be used to pass additional data.\r
57\r
58 @retval EFI_SUCCESS Status code reported to serial I/O successfully.\r
59 @retval EFI_DEVICE_ERROR EFI serial device cannot work after ExitBootService() is called.\r
60 @retval EFI_DEVICE_ERROR EFI serial device cannot work with TPL higher than TPL_CALLBACK.\r
ad1a1798 61\r
62**/\r
63EFI_STATUS\r
64SerialStatusCodeReportWorker (\r
65 IN EFI_STATUS_CODE_TYPE CodeType,\r
66 IN EFI_STATUS_CODE_VALUE Value,\r
67 IN UINT32 Instance,\r
68 IN EFI_GUID *CallerId,\r
69 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
70 )\r
71{\r
72 CHAR8 *Filename;\r
73 CHAR8 *Description;\r
74 CHAR8 *Format;\r
75 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
76 UINT32 ErrorLevel;\r
77 UINT32 LineNumber;\r
78 UINTN CharCount;\r
ca9938b8 79 BASE_LIST Marker;\r
ad1a1798 80\r
81 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {\r
82 if (EfiAtRuntime ()) {\r
83 return EFI_DEVICE_ERROR;\r
84 }\r
a8cbf345 85 if (EfiGetCurrentTpl () > TPL_CALLBACK ) {\r
ad1a1798 86 return EFI_DEVICE_ERROR;\r
87 }\r
88 }\r
89\r
90 Buffer[0] = '\0';\r
91\r
92 if (Data != NULL &&\r
93 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
94 //\r
95 // Print ASSERT() information into output buffer.\r
96 //\r
97 CharCount = AsciiSPrint (\r
98 Buffer,\r
1ca88083 99 sizeof (Buffer),\r
ad1a1798 100 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",\r
101 Filename,\r
102 LineNumber,\r
103 Description\r
104 );\r
105 } else if (Data != NULL &&\r
106 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
107 //\r
108 // Print DEBUG() information into output buffer.\r
109 //\r
ca9938b8 110 CharCount = AsciiBSPrint (\r
ad1a1798 111 Buffer, \r
1ca88083 112 sizeof (Buffer), \r
ad1a1798 113 Format, \r
114 Marker\r
115 );\r
ad1a1798 116 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
117 //\r
118 // Print ERROR information into output buffer.\r
119 //\r
120 CharCount = AsciiSPrint (\r
121 Buffer, \r
1ca88083 122 sizeof (Buffer), \r
ad1a1798 123 "ERROR: C%x:V%x I%x", \r
124 CodeType, \r
125 Value, \r
126 Instance\r
127 );\r
a8cbf345 128 \r
ad1a1798 129 if (CallerId != NULL) {\r
130 CharCount += AsciiSPrint (\r
131 &Buffer[CharCount - 1],\r
1ca88083 132 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
ad1a1798 133 " %g",\r
134 CallerId\r
135 );\r
136 }\r
137\r
138 if (Data != NULL) {\r
139 CharCount += AsciiSPrint (\r
140 &Buffer[CharCount - 1],\r
1ca88083 141 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
ad1a1798 142 " %x",\r
143 Data\r
144 );\r
145 }\r
146\r
147 CharCount += AsciiSPrint (\r
148 &Buffer[CharCount - 1],\r
1ca88083 149 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
ad1a1798 150 "\n\r"\r
151 );\r
152 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
a8cbf345 153 //\r
154 // Print PROGRESS information into output buffer.\r
155 //\r
ad1a1798 156 CharCount = AsciiSPrint (\r
157 Buffer, \r
1ca88083 158 sizeof (Buffer), \r
ad1a1798 159 "PROGRESS CODE: V%x I%x\n\r", \r
160 Value, \r
161 Instance\r
162 );\r
163 } else {\r
a8cbf345 164 //\r
165 // Code type is not defined.\r
166 //\r
ad1a1798 167 CharCount = AsciiSPrint (\r
168 Buffer, \r
1ca88083 169 sizeof (Buffer), \r
ad1a1798 170 "Undefined: C%x:V%x I%x\n\r", \r
171 CodeType, \r
172 Value, \r
173 Instance\r
174 );\r
175 }\r
176\r
177\r
178 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {\r
179 //\r
a8cbf345 180 // Call SerialPort Lib function to do print.\r
ad1a1798 181 //\r
182 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
183 }\r
184 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {\r
185 mSerialIoProtocol->Write (\r
186 mSerialIoProtocol,\r
187 &CharCount,\r
188 Buffer\r
189 );\r
190 }\r
191\r
192 return EFI_SUCCESS;\r
193}\r
bcd70414 194\r