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