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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
/** @file
EINJ table parser
Copyright (c) 2024, Arm Limited.
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Specification Reference:
- ACPI 6.5, Table 18.3.2 ACPI Error Source
**/
#include <IndustryStandard/Acpi.h>
#include <Library/UefiLib.h>
#include "AcpiParser.h"
#include "AcpiTableParser.h"
#include "AcpiView.h"
STATIC ACPI_DESCRIPTION_HEADER_INFO mAcpiHdrInfo;
STATIC UINT32 *mEinjInjectionHdrSize;
STATIC UINT32 *mEinjInjectionEntryCnt;
STATIC CONST CHAR16 *InstNameTable[] = {
L"READ_REGISTER",
L"READ_REGISTER_VALUE",
L"WRITE_REGISTER",
L"WRITE_REGISTER_VALUE",
L"NOOP",
};
/**
This function validates the flags field in the EINJ injection header.
@param [in] Ptr Pointer to the start of the field data.
@param [in] Length Length of the field.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
ValidateInjectionFlags (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 Flags;
Flags = *(UINT8 *)Ptr;
if (Flags != 0) {
IncrementErrorCount ();
Print (L"\nERROR: Injection Flags must be zero...");
}
}
/**
An ACPI_PARSER array describing the ACPI EINJ Table.
**/
STATIC CONST ACPI_PARSER EinjParser[] = {
PARSE_ACPI_HEADER (&mAcpiHdrInfo),
{ L"Injection Header Size", 4, 36, L"%d", NULL, (VOID **)&mEinjInjectionHdrSize,
NULL, NULL },
{ L"Injection Flags", 1, 40, L"0x%x", NULL, NULL, ValidateInjectionFlags,NULL },
{ L"Reserved", 3, 41, NULL, NULL, NULL, NULL, NULL },
{ L"Injection Entry Count", 4, 44, L"%d", NULL, (VOID **)&mEinjInjectionEntryCnt,
NULL, NULL },
/// Injection Action Table.
/// ...
};
/**
This function validates the injection action field in
the EINJ injection instruction entry.
@param [in] Ptr Pointer to the start of the field data.
@param [in] Length Length of the field.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
ValidateInjectionAction (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 InjectionAction;
UINT8 MaxInjectionAction;
InjectionAction = *(UINT8 *)Ptr;
/**
* EFI_ACPI_6_5_EINJ_TRIGGER_ERROR is only used Trigger Action Table
* not used in Injection Action Table in EINJ.
* Cf ACPI 6.5 Table 18.24 - Error Injection Table
* Cf ACPI 6.5 Table 18.36 - Trigger Error Action
*/
if (*mAcpiHdrInfo.Revision < EFI_ACPI_6_5_ERROR_INJECTION_TABLE_REVISION) {
MaxInjectionAction = EFI_ACPI_6_5_EINJ_GET_EXECUTE_OPERATION_TIMINGS;
} else {
MaxInjectionAction = EFI_ACPI_6_5_EINJ_EINJV2_GET_ERROR_TYPE;
}
if ((InjectionAction < EFI_ACPI_6_5_EINJ_BEGIN_INJECTION_OPERATION) ||
(InjectionAction > MaxInjectionAction))
{
IncrementErrorCount ();
Print (L"\nERROR: Invalid Injection Action(0x%x)...", InjectionAction);
}
}
/**
This function validates the instruction field in
the EINJ injection instruction entry.
@param [in] Ptr Pointer to the start of the field data.
@param [in] Length Length of the field.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
ValidateInstruction (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
UINT8 Inst;
Inst = *Ptr;
if (*mAcpiHdrInfo.Revision <= EFI_ACPI_6_5_ERROR_INJECTION_TABLE_REVISION) {
if (Inst > EFI_ACPI_6_5_EINJ_NOOP) {
IncrementErrorCount ();
Print (L"\nERROR: Invalid Instruction(0x%x)...", Inst);
}
}
}
/**
This function validates the register region field in
the EINJ injection instruction entry.
@param [in] Ptr Pointer to the start of the field data.
@param [in] Length Length of the field.
@param [in] Context Pointer to context specific information e.g. this
could be a pointer to the ACPI table header.
**/
STATIC
VOID
EFIAPI
ValidateRegisterRegion (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE *RegisterRegion;
RegisterRegion = (EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE *)Ptr;
if ((RegisterRegion->AddressSpaceId != EFI_ACPI_6_5_SYSTEM_MEMORY) &&
(RegisterRegion->AddressSpaceId != EFI_ACPI_6_5_SYSTEM_IO))
{
IncrementErrorCount ();
Print (L"\nERROR: Register Region Must be SYSTEM_MEMORY or SYSTEM_IO...");
}
}
/**
Dumps the injection action fields in injection instruction entry.
@param [in] Format Optional format string for tracing the data.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the field.
**/
STATIC
VOID
EFIAPI
DumpInjectionInstAction (
IN CONST CHAR16 *Format OPTIONAL,
IN UINT8 *Ptr,
IN UINT32 Length
)
{
UINT8 InjectionAction;
CONST CHAR16 *ActionName;
InjectionAction = *Ptr;
switch (InjectionAction) {
case EFI_ACPI_6_5_EINJ_BEGIN_INJECTION_OPERATION:
ActionName = L"BEGIN_INJECTION_OPERATION";
break;
case EFI_ACPI_6_5_EINJ_GET_TRIGGER_ERROR_ACTION_TABLE:
ActionName = L"GET_TRIGGER_ERROR_ACTION_TABLE";
break;
case EFI_ACPI_6_5_EINJ_SET_ERROR_TYPE:
ActionName = L"SET_ERROR_TYPE";
break;
case EFI_ACPI_6_5_EINJ_GET_ERROR_TYPE:
ActionName = L"GET_ERROR_TYPE";
break;
case EFI_ACPI_6_5_EINJ_END_OPERATION:
ActionName = L"END_OPERATION";
break;
case EFI_ACPI_6_5_EINJ_EXECUTE_OPERATION:
ActionName = L"EXECUTE_OPERATION";
break;
case EFI_ACPI_6_5_EINJ_CHECK_BUSY_STATUS:
ActionName = L"CHECK_BUSY_STATUS";
break;
case EFI_ACPI_6_5_EINJ_GET_COMMAND_STATUS:
ActionName = L"GET_COMMAND_STATUS";
break;
case EFI_ACPI_6_5_EINJ_SET_ERROR_TYPE_WITH_ADDRESS:
ActionName = L"SET_ERROR_TYPE_WITH_ADDRESS";
break;
case EFI_ACPI_6_5_EINJ_GET_EXECUTE_OPERATION_TIMINGS:
ActionName = L"GET_EXECUTE_OPERATION_TIMINGS";
break;
case EFI_ACPI_6_5_EINJ_EINJV2_SET_ERROR_TYPE:
ActionName = L"EINJV2_SET_ERROR_TYPE";
break;
case EFI_ACPI_6_5_EINJ_EINJV2_GET_ERROR_TYPE:
ActionName = L"EINJV2_GET_ERROR_TYPE";
break;
case EFI_ACPI_6_5_EINJ_TRIGGER_ERROR:
ActionName = L"TRIGGER_ERROR";
break;
default:
IncrementErrorCount ();
ActionName = L"UNKNOWN";
}
Print (L"%s(0x%x)", ActionName, InjectionAction);
}
/**
Dumps the instruction fields in injection instruction entry.
@param [in] Format Optional format string for tracing the data.
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Length Length of the field.
**/
STATIC
VOID
EFIAPI
DumpInstruction (
IN CONST CHAR16 *Format OPTIONAL,
IN UINT8 *Ptr,
IN UINT32 Length
)
{
UINT8 Inst;
CONST CHAR16 *InstName;
Inst = *Ptr;
if (Inst < ARRAY_SIZE (InstNameTable)) {
InstName = InstNameTable[Inst];
} else {
IncrementErrorCount ();
InstName = L"UNKNOWN";
}
Print (L"%s(0x%x)", InstName, Inst);
}
/**
An ACPI_PARSER array describing the EINJ Injection instruction entry.
**/
STATIC CONST ACPI_PARSER EinjInjectionInstEntryParser[] = {
{ L"Injection Action", 1, 0, NULL, DumpInjectionInstAction, NULL,
ValidateInjectionAction, NULL },
{ L"Instruction", 1, 1, NULL, DumpInstruction, NULL,
ValidateInstruction, NULL },
{ L"Flags", 1, 2, L"0x%x", NULL, NULL,NULL, NULL },
{ L"Reserved", 1, 3, NULL, NULL, NULL,NULL, NULL },
{ L"Register Region", 12, 4, NULL, DumpGas, NULL,
ValidateRegisterRegion, NULL },
{ L"Value", 8, 16, L"0x%x", NULL, NULL,NULL, NULL },
{ L"Mask", 8, 24, L"0x%x", NULL, NULL,NULL, NULL },
};
/**
This function parses the EINJ table.
When trace is enabled this function parses the EINJ 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
ParseAcpiEinj (
IN BOOLEAN Trace,
IN UINT8 *Ptr,
IN UINT32 AcpiTableLength,
IN UINT8 AcpiTableRevision
)
{
UINT32 Offset;
UINT8 *InjInstEntryPtr;
UINT32 InjInstEntrySize;
if (!Trace) {
return;
}
Offset = ParseAcpi (
TRUE,
0,
"EINJ",
Ptr,
AcpiTableLength,
PARSER_PARAMS (EinjParser)
);
// Validate Error Source Descriptors Count.
if ((mEinjInjectionHdrSize == NULL) || (*mEinjInjectionHdrSize != Offset)) {
IncrementErrorCount ();
Print (L"ERROR: Invalid Injection Header...\n");
return;
}
if ((mEinjInjectionEntryCnt == NULL) || (*mEinjInjectionEntryCnt == 0)) {
IncrementErrorCount ();
Print (L"ERROR: Injection Instruction Entry should be presented...\n");
return;
}
InjInstEntrySize = sizeof (EFI_ACPI_6_5_EINJ_INJECTION_INSTRUCTION_ENTRY);
if ((*mEinjInjectionEntryCnt * InjInstEntrySize) != (AcpiTableLength - Offset)) {
IncrementErrorCount ();
Print (
L"ERROR: Incorrect count for Injection Instruction Entry.\n" \
L" Injection Entry Count= %d.\n" \
L" Present Count= %d.\n",
*mEinjInjectionEntryCnt,
(AcpiTableLength - Offset) / InjInstEntrySize
);
}
while (Offset < AcpiTableLength) {
InjInstEntryPtr = Ptr + Offset;
// Get Injection Instruction Entry.
ParseAcpi (
TRUE,
2,
"Injection Instruction Entry",
InjInstEntryPtr,
AcpiTableLength - Offset,
PARSER_PARAMS (EinjInjectionInstEntryParser)
);
Offset += InjInstEntrySize;
} // while
}
|