git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1436 6f19259b...
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / Pei / PeiStatusCode.c
1
2 /** @file
3 Generic PeiStatusCode Module.
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 Module Name: PeiStatusCode.c
15
16 **/
17
18 #include "PeiStatusCode.h"
19
20 /**
21 Report status code to all supported device.
22
23
24 @param PeiServices
25
26 @param Type Indicates the type of status code being reported.
27 The type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
28 @param Value Describes the current status of a hardware or software entity.
29 This includes information about the class and subclass that is used to classify the entity
30 as well as an operation. For progress codes, the operation is the current activity.
31 For error codes, it is the exception. For debug codes, it is not defined at this time.
32 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
33 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
34 @param Instance The enumeration of a hardware or software entity within the system.
35 A system may contain multiple entities that match a class/subclass pairing.
36 The instance differentiates between them. An instance of 0 indicates that instance
37 information is unavailable, not meaningful, or not relevant. Valid instance numbers start with 1.
38 @param CallerId This optional parameter may be used to identify the caller.
39 This parameter allows the status code driver to apply different rules to different callers.
40 @param Data This optional parameter may be used to pass additional data.
41 Type EFI_STATUS_CODE_DATA is defined in "Related Definitions" below.
42 The contents of this data type may have additional GUID-specific data. The standard GUIDs and
43 their associated data structures are defined in the Intel? Platform Innovation Framework for EFI Status Codes Specification.
44
45 @return Always return EFI_SUCCESS.
46
47 **/
48 EFI_STATUS
49 EFIAPI
50 ReportDispatcher (
51 IN EFI_PEI_SERVICES **PeiServices,
52 IN EFI_STATUS_CODE_TYPE Type,
53 IN EFI_STATUS_CODE_VALUE Value,
54 IN UINT32 Instance,
55 IN EFI_GUID *CallerId OPTIONAL,
56 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
57 );
58
59 STATIC
60 EFI_PEI_PROGRESS_CODE_PPI mStatusCodePpi = {
61 ReportDispatcher
62 };
63
64 STATIC
65 EFI_PEI_PPI_DESCRIPTOR mStatusCodePpiDescriptor = {
66 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
67 &gEfiPeiStatusCodePpiGuid,
68 &mStatusCodePpi
69 };
70
71 /**
72 Report status code to all supported device.
73
74
75 @param PeiServices
76
77 @param CodeType Indicates the type of status code being reported.
78 The type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
79 @param Value Describes the current status of a hardware or software entity.
80 This includes information about the class and subclass that is used to classify the entity
81 as well as an operation. For progress codes, the operation is the current activity.
82 For error codes, it is the exception. For debug codes, it is not defined at this time.
83 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
84 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
85 @param Instance The enumeration of a hardware or software entity within the system.
86 A system may contain multiple entities that match a class/subclass pairing.
87 The instance differentiates between them. An instance of 0 indicates that instance
88 information is unavailable, not meaningful, or not relevant. Valid instance numbers start with 1.
89 @param CallerId This optional parameter may be used to identify the caller.
90 This parameter allows the status code driver to apply different rules to different callers.
91 @param Data This optional parameter may be used to pass additional data.
92 Type EFI_STATUS_CODE_DATA is defined in "Related Definitions" below.
93 The contents of this data type may have additional GUID-specific data. The standard GUIDs and
94 their associated data structures are defined in the Intel? Platform Innovation Framework for EFI Status Codes Specification.
95
96 @return Always return EFI_SUCCESS.
97
98 **/
99 EFI_STATUS
100 EFIAPI
101 ReportDispatcher (
102 IN EFI_PEI_SERVICES **PeiServices,
103 IN EFI_STATUS_CODE_TYPE CodeType,
104 IN EFI_STATUS_CODE_VALUE Value,
105 IN UINT32 Instance,
106 IN EFI_GUID *CallerId OPTIONAL,
107 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
108 )
109 {
110 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {
111 SerialStatusCodeReportWorker (
112 CodeType,
113 Value,
114 Instance,
115 CallerId,
116 Data
117 );
118 }
119 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {
120 MemoryStatusCodeReportWorker (
121 CodeType,
122 Value,
123 Instance
124 );
125 }
126 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {
127 OemHookStatusCodeReport (
128 CodeType,
129 Value,
130 Instance,
131 CallerId,
132 Data
133 );
134 }
135
136 return EFI_SUCCESS;
137 }
138
139 /**
140 Initialize PEI status codes and publish the status code
141 PPI.
142
143 @param FfsHeader FV this PEIM was loaded from.
144 @param PeiServices General purpose services available to every PEIM.
145
146 @return The function always returns success.
147
148 **/
149 EFI_STATUS
150 PeiStatusCodeDriverEntry (
151 IN EFI_FFS_FILE_HEADER *FfsHeader,
152 IN EFI_PEI_SERVICES **PeiServices
153 )
154 {
155 EFI_STATUS Status;
156
157 //
158 // Dispatch initialization request to sub-statuscode-devices.
159 // If enable UseSerial, then initialize serial port.
160 // if enable UseMemory, then initialize memory status code worker.
161 // if enable UseOEM, then initialize Oem status code.
162 //
163 if (FeaturePcdGet (PcdStatusCodeUseSerial)) {
164 Status = SerialPortInitialize();
165 ASSERT_EFI_ERROR (Status);
166 }
167 if (FeaturePcdGet (PcdStatusCodeUseMemory)) {
168 Status = MemoryStatusCodeInitializeWorker ();
169 ASSERT_EFI_ERROR (Status);
170 }
171 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {
172 Status = OemHookStatusCodeInitialize ();
173 ASSERT_EFI_ERROR (Status);
174 }
175
176 //
177 // Install PeiStatusCodePpi.
178 // PeiServices use this Ppi to output status code.
179 // use library
180 Status = PeiServicesInstallPpi (&mStatusCodePpiDescriptor);
181 ASSERT_EFI_ERROR (Status);
182
183 return EFI_SUCCESS;
184 }
185