1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
/** @file
ERST table parser
Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
- ACPI 6.5 Specification - August 2022
**/
#include <IndustryStandard/Acpi.h>
#include <Library/UefiLib.h>
#include "AcpiParser.h"
#include "AcpiTableParser.h"
// Local variables
STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
STATIC UINT32 *InstructionEntryCount;
/**
An array of strings describing the Erst actions
**/
STATIC CONST CHAR16 *ErstActionTable[] = {
L"BEGIN_WRITE_OPERATION",
L"BEGIN_READ_OPERATION",
L"BEGIN_CLEAR_OPERATION",
L"END_OPERATION",
L"SET_RECORD_OFFSET",
L"EXECUTE_OPERATION",
L"CHECK_BUSY_STATUS",
L"GET_COMMAND_STATUS",
L"GET_RECORD_IDENTIFIER",
L"SET_RECORD_IDENTIFIER",
L"GET_RECORD_COUNT",
L"BEGIN_DUMMY_WRITE_OPERATION",
L"RESERVED",
L"GET_ERROR_LOG_ADDRESS_RANGE",
L"GET_ERROR_LOG_ADDRESS_RANGE_LENGTH",
L"GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES",
L"GET_EXECUTE_OPERATION_TIMINGS"
};
/**
An array of strings describing the Erst instructions
**/
STATIC CONST CHAR16 *ErstInstructionTable[] = {
L"READ_REGISTER",
L"READ_REGISTER_VALUE",
L"WRITE_REGISTER",
L"WRITE_REGISTER_VALUE",
L"NOOP",
L"LOAD_VAR1",
L"LOAD_VAR2",
L"STORE_VAR1",
L"ADD",
L"SUBTRACT",
L"ADD_VALUE",
L"SUBTRACT_VALUE",
L"STALL",
L"STALL_WHILE_TRUE",
L"SKIP_NEXT_INSTRUCTION_IF_TRUE",
L"GOTO",
L"SET_SRC_ADDRESS_BASE",
L"SET_DST_ADDRESS_BASE",
L"MOVE_DATA"
};
/**
Validate Erst action.
@param [in] Ptr Pointer to the start of the field data.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
ValidateErstAction (
IN UINT8 *Ptr,
IN VOID *Context
)
{
if (*Ptr > EFI_ACPI_6_4_ERST_GET_EXECUTE_OPERATION_TIMINGS) {
IncrementErrorCount ();
Print (L"\nError: 0x%02x is not a valid action encoding", *Ptr);
}
}
/**
Validate Erst instruction.
@param [in] Ptr Pointer to the start of the field data.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
ValidateErstInstruction (
IN UINT8 *Ptr,
IN VOID *Context
)
{
if (*Ptr > EFI_ACPI_6_4_ERST_MOVE_DATA) {
IncrementErrorCount ();
Print (L"\nError: 0x%02x is not a valid instruction encoding", *Ptr);
}
}
/**
Validate Erst flags.
@param [in] Ptr Pointer to the start of the field data.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
ValidateErstFlags (
IN UINT8 *Ptr,
IN VOID *Context
)
{
if ((*Ptr & 0xfe) != 0) {
IncrementErrorCount ();
Print (L"\nError: Reserved Flag bits not set to 0");
}
}
/**
Looks up and prints the string corresponding to the index.
@param [in] Table Lookup table.
@param [in] Index Entry to print.
@param [in] NumEntries Number of valid entries in the table.
**/
STATIC
VOID
EFIAPI
FormatByte (
IN CONST CHAR16 *Table[],
IN UINT8 Index,
IN UINT8 NumEntries
)
{
CONST CHAR16 *String;
if (Index < NumEntries) {
String = Table[Index];
} else {
String = L"**INVALID**";
}
Print (
L"0x%02x (%s)",
Index,
String
);
}
/**
Prints the Erst Action.
@param [in] Format Optional format string for tracing the data.
@param [in] Ptr Pointer to the Action byte.
**/
STATIC
VOID
EFIAPI
DumpErstAction (
IN CONST CHAR16 *Format OPTIONAL,
IN UINT8 *Ptr
)
{
FormatByte (ErstActionTable, *Ptr, ARRAY_SIZE (ErstActionTable));
}
/**
Prints the Erst Instruction.
@param [in] Format Optional format string for tracing the data.
@param [in] Ptr Pointer to the Instruction byte.
**/
STATIC
VOID
EFIAPI
DumpErstInstruction (
IN CONST CHAR16 *Format OPTIONAL,
IN UINT8 *Ptr
)
{
FormatByte (ErstInstructionTable, *Ptr, ARRAY_SIZE (ErstInstructionTable));
}
/**
An ACPI_PARSER array describing the ACPI ERST Table.
**/
STATIC CONST ACPI_PARSER ErstParser[] = {
PARSE_ACPI_HEADER (&AcpiHdrInfo),
{ L"Serialization Header Size", 4, 36, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 4, 40, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Instruction Entry Count", 4, 44, L"0x%x", NULL, (VOID **)&InstructionEntryCount, NULL, NULL }
};
/**
An ACPI_PARSER array describing the Serialization Instruction Entry structure.
**/
STATIC CONST ACPI_PARSER SerializationInstructionEntryParser[] = {
{ L"Serialization Action", 1, 0, L"0x%x", DumpErstAction, NULL, ValidateErstAction, NULL },
{ L"Instruction", 1, 1, L"0x%x", DumpErstInstruction, NULL, ValidateErstInstruction, NULL },
{ L"Flags", 1, 2, L"0x%x", NULL, NULL, ValidateErstFlags, NULL },
{ L"Reserved", 1, 3, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Register Region", 12, 4, NULL, DumpGas, NULL, NULL, NULL },
{ L"Value", 8, 16, L"0x%llx", NULL, NULL, NULL, NULL },
{ L"Mask", 8, 24, L"0x%llx", NULL, NULL, NULL, NULL }
};
/**
This function parses the ACPI ERST table.
When trace is enabled this function parses the ERST table and
traces the ACPI table fields.
This function also performs validation of the ACPI table fields.
@param [in] Trace If TRUE, trace the ACPI fields.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] AcpiTableLength Length of the ACPI table.
@param [in] AcpiTableRevision Revision of the ACPI table.
**/
VOID
EFIAPI
ParseAcpiErst (
IN BOOLEAN Trace,
IN UINT8 *Ptr,
IN UINT32 AcpiTableLength,
IN UINT8 AcpiTableRevision
)
{
UINT32 Offset;
if (!Trace) {
return;
}
Offset = ParseAcpi (
Trace,
0,
"ERST",
Ptr,
AcpiTableLength,
PARSER_PARAMS (ErstParser)
);
if (sizeof (EFI_ACPI_6_4_ERST_SERIALIZATION_INSTRUCTION_ENTRY)*(*InstructionEntryCount) != (AcpiTableLength - Offset)) {
IncrementErrorCount ();
Print (
L"ERROR: Invalid InstructionEntryCount. " \
L"Count = %d. Offset = %d. AcpiTableLength = %d.\n",
*InstructionEntryCount,
Offset,
AcpiTableLength
);
return;
}
while (Offset < AcpiTableLength) {
Offset += ParseAcpi (
Trace,
2,
"Serialization Action",
Ptr + Offset,
(AcpiTableLength - Offset),
PARSER_PARAMS (SerializationInstructionEntryParser)
);
}
}
|