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