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