1 /** @file
2   Serial I/O status code reporting worker.
3 
4   Copyright (c) 2006 - 2014, 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
SerialStatusCodeReportWorker(IN CONST EFI_PEI_SERVICES ** PeiServices,IN EFI_STATUS_CODE_TYPE CodeType,IN EFI_STATUS_CODE_VALUE Value,IN UINT32 Instance,IN CONST EFI_GUID * CallerId,IN CONST EFI_STATUS_CODE_DATA * Data OPTIONAL)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[MAX_DEBUG_MESSAGE_LENGTH];
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%08x:V%08x I%x",
93                   CodeType,
94                   Value,
95                   Instance
96                   );
97 
98     ASSERT(CharCount > 0);
99 
100     if (CallerId != NULL) {
101       CharCount += AsciiSPrint (
102                      &Buffer[CharCount],
103                      (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
104                      " %g",
105                      CallerId
106                      );
107     }
108 
109     if (Data != NULL) {
110       CharCount += AsciiSPrint (
111                      &Buffer[CharCount],
112                      (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
113                      " %x",
114                      Data
115                      );
116     }
117 
118     CharCount += AsciiSPrint (
119                    &Buffer[CharCount],
120                    (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
121                    "\n\r"
122                    );
123   } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
124     //
125     // Print PROGRESS information into output buffer.
126     //
127     CharCount = AsciiSPrint (
128                   Buffer,
129                   sizeof (Buffer),
130                   "PROGRESS CODE: V%08x I%x\n\r",
131                   Value,
132                   Instance
133                   );
134   } else if (Data != NULL &&
135              CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) &&
136              ((EFI_STATUS_CODE_STRING_DATA *) Data)->StringType == EfiStringAscii) {
137     //
138     // EFI_STATUS_CODE_STRING_DATA
139     //
140     CharCount = AsciiSPrint (
141                   Buffer,
142                   sizeof (Buffer),
143                   "%a\n\r",
144                   ((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii
145                   );
146   } else {
147     //
148     // Code type is not defined.
149     //
150     CharCount = AsciiSPrint (
151                   Buffer,
152                   sizeof (Buffer),
153                   "Undefined: C%08x:V%08x I%x\n\r",
154                   CodeType,
155                   Value,
156                   Instance
157                   );
158   }
159 
160   //
161   // Call SerialPort Lib function to do print.
162   //
163   SerialPortWrite ((UINT8 *) Buffer, CharCount);
164 
165   return EFI_SUCCESS;
166 }
167 
168