]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/StatusCode/Dxe/SerialStatusCodeWorker.c
Fix bug which define different PCD with same token number in EdkModulePkg.spd.
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / Dxe / SerialStatusCodeWorker.c
1
2 /** @file
3 Serial I/O status code reporting worker.
4
5 Copyright (c) 2006, Intel Corporation. All rights reserved.
6 This software and associated documentation (if any) is furnished
7 under a license and may only be used or copied in accordance
8 with the terms of the license. Except as permitted by such
9 license, no part of this software or documentation may be
10 reproduced, stored in a retrieval system, or transmitted in any
11 form or by any means without the express written consent of
12 Intel Corporation.
13
14 Module Name: SerialStatusCodeWorker.c
15
16 **/
17
18 EFI_SERIAL_IO_PROTOCOL *SerialIoProtocol;
19
20 /**
21 Initialize serial status code worker.
22
23 @return The function always return EFI_SUCCESS
24
25 **/
26 EFI_STATUS
27 EfiSerialStatusCodeInitializeWorker (
28 VOID
29 )
30 {
31 EFI_STATUS Status;
32
33 Status = gBS->LocateProtocol (
34 &gEfiSerialIoProtocolGuid,
35 NULL,
36 (VOID **) &SerialIoProtocol
37 );
38
39 ASSERT_EFI_ERROR (Status);
40
41 return EFI_SUCCESS;
42 }
43
44
45 /**
46 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
47
48 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.
49
50 @param Value Describes the current status of a hardware or software entity.
51 This included information about the class and subclass that is used to classify the entity
52 as well as an operation. For progress codes, the operation is the current activity.
53 For error codes, it is the exception. For debug codes, it is not defined at this time.
54 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
55 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
56
57 @param Instance The enumeration of a hardware or software entity within the system.
58 A system may contain multiple entities that match a class/subclass pairing.
59 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
60 not meaningful, or not relevant. Valid instance numbers start with 1.
61
62
63 @param CallerId This optional parameter may be used to identify the caller.
64 This parameter allows the status code driver to apply different rules to different callers.
65 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
66
67
68 @param Data This optional parameter may be used to pass additional data
69
70 @return The function always return EFI_SUCCESS.
71
72 **/
73 EFI_STATUS
74 SerialStatusCodeReportWorker (
75 IN EFI_STATUS_CODE_TYPE CodeType,
76 IN EFI_STATUS_CODE_VALUE Value,
77 IN UINT32 Instance,
78 IN EFI_GUID *CallerId,
79 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
80 )
81 {
82 CHAR8 *Filename;
83 CHAR8 *Description;
84 CHAR8 *Format;
85 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
86 UINT32 ErrorLevel;
87 UINT32 LineNumber;
88 UINTN CharCount;
89 VA_LIST Marker;
90 EFI_DEBUG_INFO *DebugInfo;
91
92 Buffer[0] = '\0';
93
94 if (Data != NULL &&
95 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
96 //
97 // Print ASSERT() information into output buffer.
98 //
99 CharCount = AsciiSPrint (
100 Buffer,
101 EFI_STATUS_CODE_DATA_MAX_SIZE,
102 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
103 Filename,
104 LineNumber,
105 Description
106 );
107 } else if (Data != NULL &&
108 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
109 //
110 // Print DEBUG() information into output buffer.
111 //
112 CharCount = AsciiVSPrint (
113 Buffer,
114 EFI_STATUS_CODE_DATA_MAX_SIZE,
115 Format,
116 Marker
117 );
118 } else if (Data != NULL &&
119 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
120 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
121 //
122 // Print specific data into output buffer.
123 //
124 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
125 Marker = (VA_LIST) (DebugInfo + 1);
126 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
127
128 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
129 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
130 //
131 // Print ERROR information into output buffer.
132 //
133 CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "ERROR: C%x:V%x I%x", CodeType, Value, Instance);
134
135 //
136 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
137 //
138
139 if (CallerId != NULL) {
140 CharCount += AsciiSPrint (
141 &Buffer[CharCount - 1],
142 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
143 " %g",
144 CallerId
145 );
146 }
147
148 if (Data) {
149 CharCount += AsciiSPrint (
150 &Buffer[CharCount - 1],
151 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
152 " %x",
153 Data
154 );
155 }
156
157 CharCount += AsciiSPrint (
158 &Buffer[CharCount - 1],
159 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
160 "\n\r"
161 );
162 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
163 CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "PROGRESS CODE: V%x I%x\n\r", Value, Instance);
164 } else {
165 CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "Undefined: C%x:V%x I%x\n\r", CodeType, Value, Instance);
166 }
167
168
169 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
170 //
171 // Callout to SerialPort Lib function to do print.
172 //
173 SerialPortWrite ((UINT8 *) Buffer, CharCount);
174 }
175 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
176 SerialIoProtocol->Write (
177 SerialIoProtocol,
178 &CharCount,
179 Buffer
180 );
181 }
182
183 return EFI_SUCCESS;
184 }