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