]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / RuntimeDxe / 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\r
9#include "StatusCodeHandlerRuntimeDxe.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
1436aea4
MK
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
3af9b388 38 )\r
39{\r
1436aea4
MK
40 CHAR8 *Filename;\r
41 CHAR8 *Description;\r
42 CHAR8 *Format;\r
43 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
44 UINT32 ErrorLevel;\r
45 UINT32 LineNumber;\r
46 UINTN CharCount;\r
47 BASE_LIST Marker;\r
3af9b388 48\r
49 Buffer[0] = '\0';\r
50\r
1436aea4
MK
51 if ((Data != NULL) &&\r
52 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber))\r
53 {\r
3af9b388 54 //\r
55 // Print ASSERT() information into output buffer.\r
56 //\r
57 CharCount = AsciiSPrint (\r
58 Buffer,\r
59 sizeof (Buffer),\r
60 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",\r
61 Filename,\r
62 LineNumber,\r
63 Description\r
64 );\r
1436aea4
MK
65 } else if ((Data != NULL) &&\r
66 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format))\r
67 {\r
3af9b388 68 //\r
69 // Print DEBUG() information into output buffer.\r
70 //\r
71 CharCount = AsciiBSPrint (\r
d1102dba
LG
72 Buffer,\r
73 sizeof (Buffer),\r
74 Format,\r
3af9b388 75 Marker\r
76 );\r
77 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
78 //\r
79 // Print ERROR information into output buffer.\r
80 //\r
81 CharCount = AsciiSPrint (\r
d1102dba
LG
82 Buffer,\r
83 sizeof (Buffer),\r
84 "ERROR: C%08x:V%08x I%x",\r
85 CodeType,\r
86 Value,\r
3af9b388 87 Instance\r
88 );\r
fbe12b79 89 ASSERT (CharCount > 0);\r
d1102dba 90\r
3af9b388 91 if (CallerId != NULL) {\r
92 CharCount += AsciiSPrint (\r
30d636c8 93 &Buffer[CharCount],\r
3af9b388 94 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
95 " %g",\r
96 CallerId\r
97 );\r
98 }\r
99\r
100 if (Data != NULL) {\r
101 CharCount += AsciiSPrint (\r
30d636c8 102 &Buffer[CharCount],\r
3af9b388 103 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
104 " %x",\r
105 Data\r
106 );\r
107 }\r
108\r
109 CharCount += AsciiSPrint (\r
30d636c8 110 &Buffer[CharCount],\r
3af9b388 111 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
112 "\n\r"\r
113 );\r
114 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
115 //\r
116 // Print PROGRESS information into output buffer.\r
117 //\r
118 CharCount = AsciiSPrint (\r
d1102dba
LG
119 Buffer,\r
120 sizeof (Buffer),\r
121 "PROGRESS CODE: V%08x I%x\n\r",\r
122 Value,\r
3af9b388 123 Instance\r
124 );\r
1436aea4 125 } else if ((Data != NULL) &&\r
bc369e79 126 CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) &&\r
1436aea4
MK
127 (((EFI_STATUS_CODE_STRING_DATA *)Data)->StringType == EfiStringAscii))\r
128 {\r
96a25163 129 //\r
130 // EFI_STATUS_CODE_STRING_DATA\r
131 //\r
132 CharCount = AsciiSPrint (\r
133 Buffer,\r
134 sizeof (Buffer),\r
58ae92a9 135 "%a",\r
1436aea4 136 ((EFI_STATUS_CODE_STRING_DATA *)Data)->String.Ascii\r
96a25163 137 );\r
3af9b388 138 } else {\r
139 //\r
140 // Code type is not defined.\r
141 //\r
142 CharCount = AsciiSPrint (\r
d1102dba
LG
143 Buffer,\r
144 sizeof (Buffer),\r
145 "Undefined: C%08x:V%08x I%x\n\r",\r
146 CodeType,\r
147 Value,\r
3af9b388 148 Instance\r
149 );\r
150 }\r
151\r
152 //\r
153 // Call SerialPort Lib function to do print.\r
154 //\r
1436aea4 155 SerialPortWrite ((UINT8 *)Buffer, CharCount);\r
3af9b388 156\r
d4945b10
MT
157 //\r
158 // If register an unregister function of gEfiEventExitBootServicesGuid,\r
159 // then some log called in ExitBootServices() will be lost,\r
160 // so unregister the handler after receive the value of exit boot service.\r
161 //\r
1436aea4
MK
162 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) &&\r
163 (Value == (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)))\r
164 {\r
165 UnregisterSerialBootTimeHandlers ();\r
d4945b10
MT
166 }\r
167\r
3af9b388 168 return EFI_SUCCESS;\r
169}\r