]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/StatusCode/Pei/SerialStatusCodeWorker.c
049e4ef778e33001c7f64262494a2c3e40cf5294
[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. 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 /**
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 (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "ERROR: C%x:V%x I%x", CodeType, Value, Instance);
107
108 //
109 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
110 //
111
112 if (CallerId != NULL) {
113 CharCount += AsciiSPrint (
114 &Buffer[CharCount - 1],
115 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
116 " %g",
117 CallerId
118 );
119 }
120
121 if (Data) {
122 CharCount += AsciiSPrint (
123 &Buffer[CharCount - 1],
124 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
125 " %x",
126 Data
127 );
128 }
129
130 CharCount += AsciiSPrint (
131 &Buffer[CharCount - 1],
132 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
133 "\n\r"
134 );
135 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
136 CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "PROGRESS CODE: V%x I%x\n\r", Value, Instance);
137 } else {
138 CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "Undefined: C%x:V%x I%x\n\r", CodeType, Value, Instance);
139 }
140
141 //
142 // Callout to SerialPort Lib function to do print.
143 //
144 SerialPortWrite ((UINT8 *) Buffer, CharCount);
145
146 return EFI_SUCCESS;
147 }