1 /** @file
2   Internal include file of Status Code Runtime DXE Driver.
3 
4   Copyright (c) 2006 - 2009, 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 
15 #ifndef __STATUS_CODE_RUNTIME_DXE_H__
16 #define __STATUS_CODE_RUNTIME_DXE_H__
17 
18 
19 #include <FrameworkDxe.h>
20 #include <Guid/DataHubStatusCodeRecord.h>
21 #include <Protocol/DataHub.h>
22 #include <Guid/MemoryStatusCodeRecord.h>
23 #include <Protocol/StatusCode.h>
24 #include <Guid/StatusCodeDataTypeId.h>
25 #include <Guid/StatusCodeDataTypeDebug.h>
26 #include <Guid/EventGroup.h>
27 
28 #include <Library/BaseLib.h>
29 #include <Library/SynchronizationLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/ReportStatusCodeLib.h>
33 #include <Library/PrintLib.h>
34 #include <Library/PcdLib.h>
35 #include <Library/HobLib.h>
36 #include <Library/UefiDriverEntryPoint.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/UefiLib.h>
39 #include <Library/MemoryAllocationLib.h>
40 #include <Library/UefiRuntimeLib.h>
41 #include <Library/SerialPortLib.h>
42 #include <Library/OemHookStatusCodeLib.h>
43 
44 //
45 // Data hub worker definition
46 //
47 #define DATAHUB_STATUS_CODE_SIGNATURE             SIGNATURE_32 ('B', 'D', 'H', 'S')
48 
49 typedef struct {
50   UINTN       Signature;
51   LIST_ENTRY  Node;
52   UINT8       Data[sizeof(DATA_HUB_STATUS_CODE_DATA_RECORD) + EFI_STATUS_CODE_DATA_MAX_SIZE];
53 } DATAHUB_STATUSCODE_RECORD;
54 
55 
56 //
57 // Runtime memory status code worker definition
58 //
59 typedef struct {
60   UINT32   RecordIndex;
61   UINT32   NumberOfRecords;
62   UINT32   MaxRecordsNumber;
63 } RUNTIME_MEMORY_STATUSCODE_HEADER;
64 
65 extern RUNTIME_MEMORY_STATUSCODE_HEADER  *mRtMemoryStatusCodeTable;
66 
67 /**
68   Report status code to all supported device.
69 
70   This function implements EFI_STATUS_CODE_PROTOCOL.ReportStatusCode().
71   It calls into the workers which dispatches the platform specific listeners.
72 
73   @param  CodeType         Indicates the type of status code being reported.
74   @param  Value            Describes the current status of a hardware or software entity.
75                            This included information about the class and subclass that is used to
76                            classify the entity as well as an operation.
77   @param  Instance         The enumeration of a hardware or software entity within
78                            the system. Valid instance numbers start with 1.
79   @param  CallerId         This optional parameter may be used to identify the caller.
80                            This parameter allows the status code driver to apply different rules to
81                            different callers.
82   @param  Data             This optional parameter may be used to pass additional data.
83 
84   @retval EFI_SUCCESS      The function completed successfully
85   @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
86 
87 **/
88 EFI_STATUS
89 EFIAPI
90 ReportDispatcher (
91   IN EFI_STATUS_CODE_TYPE     CodeType,
92   IN EFI_STATUS_CODE_VALUE    Value,
93   IN UINT32                   Instance,
94   IN EFI_GUID                 *CallerId  OPTIONAL,
95   IN EFI_STATUS_CODE_DATA     *Data      OPTIONAL
96   );
97 
98 /**
99   Dispatch initialization request to sub status code devices based on
100   customized feature flags.
101 
102 **/
103 VOID
104 InitializationDispatcherWorker (
105   VOID
106   );
107 
108 
109 /**
110   Locates Serial I/O Protocol as initialization for serial status code worker.
111 
112   @retval EFI_SUCCESS  Serial I/O Protocol is successfully located.
113 
114 **/
115 EFI_STATUS
116 EfiSerialStatusCodeInitializeWorker (
117   VOID
118   );
119 
120 
121 /**
122   Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
123 
124   @param  CodeType         Indicates the type of status code being reported.
125   @param  Value            Describes the current status of a hardware or software entity.
126                            This included information about the class and subclass that is used to
127                            classify the entity as well as an operation.
128   @param  Instance         The enumeration of a hardware or software entity within
129                            the system. Valid instance numbers start with 1.
130   @param  CallerId         This optional parameter may be used to identify the caller.
131                            This parameter allows the status code driver to apply different rules to
132                            different callers.
133   @param  Data             This optional parameter may be used to pass additional data.
134 
135   @retval EFI_SUCCESS      Status code reported to serial I/O successfully.
136   @retval EFI_DEVICE_ERROR EFI serial device cannot work after ExitBootService() is called.
137   @retval EFI_DEVICE_ERROR EFI serial device cannot work with TPL higher than TPL_CALLBACK.
138 
139 **/
140 EFI_STATUS
141 SerialStatusCodeReportWorker (
142   IN EFI_STATUS_CODE_TYPE     CodeType,
143   IN EFI_STATUS_CODE_VALUE    Value,
144   IN UINT32                   Instance,
145   IN EFI_GUID                 *CallerId,
146   IN EFI_STATUS_CODE_DATA     *Data OPTIONAL
147   );
148 
149 /**
150   Initialize runtime memory status code table as initialization for runtime memory status code worker
151 
152   @retval EFI_SUCCESS  Runtime memory status code table successfully initialized.
153 
154 **/
155 EFI_STATUS
156 RtMemoryStatusCodeInitializeWorker (
157   VOID
158   );
159 
160 /**
161   Report status code into runtime memory. If the runtime pool is full, roll back to the
162   first record and overwrite it.
163 
164   @param  CodeType                Indicates the type of status code being reported.
165   @param  Value                   Describes the current status of a hardware or software entity.
166                                   This included information about the class and subclass that is used to
167                                   classify the entity as well as an operation.
168   @param  Instance                The enumeration of a hardware or software entity within
169                                   the system. Valid instance numbers start with 1.
170 
171   @retval EFI_SUCCESS             Status code successfully recorded in runtime memory status code table.
172 
173 **/
174 EFI_STATUS
175 RtMemoryStatusCodeReportWorker (
176   IN EFI_STATUS_CODE_TYPE               CodeType,
177   IN EFI_STATUS_CODE_VALUE              Value,
178   IN UINT32                             Instance
179   );
180 
181 /**
182   Locate Data Hub Protocol and create event for logging data
183   as initialization for data hub status code worker.
184 
185   @retval EFI_SUCCESS  Initialization is successful.
186 
187 **/
188 EFI_STATUS
189 DataHubStatusCodeInitializeWorker (
190   VOID
191   );
192 
193 
194 /**
195   Report status code into DataHub.
196 
197   @param  CodeType             Indicates the type of status code being reported.
198   @param  Value                Describes the current status of a hardware or software entity.
199                                This included information about the class and subclass that is used to
200                                classify the entity as well as an operation.
201   @param  Instance             The enumeration of a hardware or software entity within
202                                the system. Valid instance numbers start with 1.
203   @param  CallerId             This optional parameter may be used to identify the caller.
204                                This parameter allows the status code driver to apply different rules to
205                                different callers.
206   @param  Data                 This optional parameter may be used to pass additional data.
207 
208   @retval EFI_SUCCESS          The function completed successfully.
209   @retval EFI_DEVICE_ERROR     Function is reentered.
210   @retval EFI_DEVICE_ERROR     Function is called at runtime.
211   @retval EFI_OUT_OF_RESOURCES Fail to allocate memory for free record buffer.
212 
213 **/
214 EFI_STATUS
215 DataHubStatusCodeReportWorker (
216   IN EFI_STATUS_CODE_TYPE     CodeType,
217   IN EFI_STATUS_CODE_VALUE    Value,
218   IN UINT32                   Instance,
219   IN EFI_GUID                 *CallerId,
220   IN EFI_STATUS_CODE_DATA     *Data OPTIONAL
221   );
222 
223 
224 /**
225   Virtual address change notification call back. It converts global pointer
226   to virtual address.
227 
228   @param  Event         Event whose notification function is being invoked.
229   @param  Context       Pointer to the notification function's context, which is
230                         always zero in current implementation.
231 
232 **/
233 VOID
234 EFIAPI
235 VirtualAddressChangeCallBack (
236   IN EFI_EVENT  Event,
237   IN VOID       *Context
238   );
239 
240 #endif
241