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