1. add EdkSerialPortLibNull.inf
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Pei / SerialStatusCodeWorker.c
1
2 /** @file
3 Serial I/O status code reporting worker.
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 Module Name: SerialStatusCodeWorker.c
15
16 **/
17
18 //
19 // Include common header file for this module.
20 //
21 #include "CommonHeader.h"
22
23 #include "PeiStatusCode.h"
24
25 /**
26 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
27
28 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
29
30 @param Value Describes the current status of a hardware or software entity.
31 This included information about the class and subclass that is used to classify the entity
32 as well as an operation. For progress codes, the operation is the current activity.
33 For error codes, it is the exception. For debug codes, it is not defined at this time.
34 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
35 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
36
37 @param Instance The enumeration of a hardware or software entity within the system.
38 A system may contain multiple entities that match a class/subclass pairing.
39 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
40 not meaningful, or not relevant. Valid instance numbers start with 1.
41
42
43 @param CallerId This optional parameter may be used to identify the caller.
44 This parameter allows the status code driver to apply different rules to different callers.
45 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
46
47
48 @param Data This optional parameter may be used to pass additional data
49
50 @return The function always return EFI_SUCCESS.
51
52 **/
53 EFI_STATUS
54 SerialStatusCodeReportWorker (
55 IN EFI_STATUS_CODE_TYPE CodeType,
56 IN EFI_STATUS_CODE_VALUE Value,
57 IN UINT32 Instance,
58 IN EFI_GUID *CallerId,
59 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
60 )
61 {
62 CHAR8 *Filename;
63 CHAR8 *Description;
64 CHAR8 *Format;
65 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
66 UINT32 ErrorLevel;
67 UINT32 LineNumber;
68 UINTN CharCount;
69 VA_LIST Marker;
70 EFI_DEBUG_INFO *DebugInfo;
71
72 Buffer[0] = '\0';
73
74 if (Data != NULL &&
75 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
76 //
77 // Print ASSERT() information into output buffer.
78 //
79 CharCount = AsciiSPrint (
80 Buffer,
81 EFI_STATUS_CODE_DATA_MAX_SIZE,
82 "\n\rPEI_ASSERT!: %a (%d): %a\n\r",
83 Filename,
84 LineNumber,
85 Description
86 );
87 } else if (Data != NULL &&
88 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
89 //
90 // Print DEBUG() information into output buffer.
91 //
92 CharCount = AsciiVSPrint (
93 Buffer,
94 EFI_STATUS_CODE_DATA_MAX_SIZE,
95 Format,
96 Marker
97 );
98 } else if (Data != NULL &&
99 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
100 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
101 //
102 // Print specific data into output buffer.
103 //
104 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
105 Marker = (VA_LIST) (DebugInfo + 1);
106 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
107
108 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
109 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
110 //
111 // Print ERROR information into output buffer.
112 //
113 CharCount = AsciiSPrint (
114 Buffer,
115 EFI_STATUS_CODE_DATA_MAX_SIZE,
116 "ERROR: C%x:V%x I%x",
117 CodeType,
118 Value,
119 Instance
120 );
121
122 //
123 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
124 //
125
126 if (CallerId != NULL) {
127 CharCount += AsciiSPrint (
128 &Buffer[CharCount - 1],
129 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
130 " %g",
131 CallerId
132 );
133 }
134
135 if (Data != NULL) {
136 CharCount += AsciiSPrint (
137 &Buffer[CharCount - 1],
138 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
139 " %x",
140 Data
141 );
142 }
143
144 CharCount += AsciiSPrint (
145 &Buffer[CharCount - 1],
146 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
147 "\n\r"
148 );
149 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
150 CharCount = AsciiSPrint (
151 Buffer,
152 EFI_STATUS_CODE_DATA_MAX_SIZE,
153 "PROGRESS CODE: V%x I%x\n\r",
154 Value,
155 Instance
156 );
157 } else {
158 CharCount = AsciiSPrint (
159 Buffer,
160 EFI_STATUS_CODE_DATA_MAX_SIZE,
161 "Undefined: C%x:V%x I%x\n\r",
162 CodeType,
163 Value,
164 Instance
165 );
166 }
167
168 //
169 // Callout to SerialPort Lib function to do print.
170 //
171 SerialPortWrite ((UINT8 *) Buffer, CharCount);
172
173 return EFI_SUCCESS;
174 }