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