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 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
|
/** @file
HMAT table parser
Copyright (c) 2020 - 2024, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
- ACPI 6.3 Specification - January 2019
@par Glossary:
- MPDA - Memory Proximity Domain Attributes
- SLLBI - System Locality Latency and Bandwidth Information
- MSCI - Memory Side Cache Information
- Dom - Domain
**/
#include <Library/PrintLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiLib.h>
#include "AcpiParser.h"
#include "AcpiView.h"
// Maximum Memory Domain matrix print size.
#define MAX_MEMORY_DOMAIN_TARGET_PRINT_MATRIX 10
// Local variables
STATIC CONST UINT16 *HmatStructureType;
STATIC CONST UINT32 *HmatStructureLength;
STATIC CONST UINT32 *NumberInitiatorProximityDomain;
STATIC CONST UINT32 *NumberTargetProximityDomain;
STATIC CONST
EFI_ACPI_6_4_HMAT_STRUCTURE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO_FLAGS *
SllbiFlags;
STATIC CONST UINT8 *SllbiDataType;
STATIC CONST UINT16 *NumberSMBIOSHandles;
STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
/**
Names of System Locality Latency Bandwidth Information (SLLBI) data types
**/
STATIC CONST CHAR16 *SllbiNames[] = {
L"Access %sLatency%s",
L"Read %sLatency%s",
L"Write %sLatency%s",
L"Access %sBandwidth%s",
L"Read %sBandwidth%s",
L"Write %sBandwidth%s"
};
/**
This function validates the Cache Attributes field.
@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
ValidateCacheAttributes (
IN UINT8 *Ptr,
IN UINT32 Length,
IN VOID *Context
)
{
EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_SIDE_CACHE_INFO_CACHE_ATTRIBUTES *
Attributes;
Attributes =
(EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_SIDE_CACHE_INFO_CACHE_ATTRIBUTES *)Ptr;
if (Attributes->TotalCacheLevels > 0x3) {
IncrementErrorCount ();
Print (
L"\nERROR: Attributes bits [3:0] have invalid value: 0x%x",
Attributes->TotalCacheLevels
);
}
if (Attributes->CacheLevel > 0x3) {
IncrementErrorCount ();
Print (
L"\nERROR: Attributes bits [7:4] have invalid value: 0x%x",
Attributes->CacheLevel
);
}
if (Attributes->CacheAssociativity > 0x2) {
IncrementErrorCount ();
Print (
L"\nERROR: Attributes bits [11:8] have invalid value: 0x%x",
Attributes->CacheAssociativity
);
}
if (Attributes->WritePolicy > 0x2) {
IncrementErrorCount ();
Print (
L"\nERROR: Attributes bits [15:12] have invalid value: 0x%x",
Attributes->WritePolicy
);
}
}
/**
Dumps the cache attributes field
@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
DumpCacheAttributes (
IN CONST CHAR16 *Format OPTIONAL,
IN UINT8 *Ptr,
IN UINT32 Length
)
{
EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_SIDE_CACHE_INFO_CACHE_ATTRIBUTES *
Attributes;
Attributes =
(EFI_ACPI_6_4_HMAT_STRUCTURE_MEMORY_SIDE_CACHE_INFO_CACHE_ATTRIBUTES *)Ptr;
Print (L"\n");
PrintFieldName (4, L"Total Cache Levels");
Print (L"%d\n", Attributes->TotalCacheLevels);
PrintFieldName (4, L"Cache Level");
Print (L"%d\n", Attributes->CacheLevel);
PrintFieldName (4, L"Cache Associativity");
Print (L"%d\n", Attributes->CacheAssociativity);
PrintFieldName (4, L"Write Policy");
Print (L"%d\n", Attributes->WritePolicy);
PrintFieldName (4, L"Cache Line Size");
Print (L"%d\n", Attributes->CacheLineSize);
}
/**
An ACPI_PARSER array describing the ACPI HMAT Table.
*/
STATIC CONST ACPI_PARSER HmatParser[] = {
PARSE_ACPI_HEADER (&AcpiHdrInfo),
{ L"Reserved", 4,36, NULL, NULL, NULL, NULL, NULL }
};
/**
An ACPI_PARSER array describing the HMAT structure header.
*/
STATIC CONST ACPI_PARSER HmatStructureHeaderParser[] = {
{ L"Type", 2, 0, NULL, NULL, (VOID **)&HmatStructureType, NULL, NULL },
{ L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL },
{ L"Length", 4, 4, NULL, NULL, (VOID **)&HmatStructureLength, NULL, NULL }
};
/**
An ACPI PARSER array describing the Memory Proximity Domain Attributes
Structure - Type 0.
*/
STATIC CONST ACPI_PARSER MemProximityDomainAttributeParser[] = {
{ L"Type", 2, 0, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Length", 4, 4, L"%d", NULL, NULL, NULL, NULL },
{ L"Flags", 2, 8, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 2, 10, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Proximity Dom for initiator", 4, 12, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Proximity Dom for memory", 4, 16, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 8, 24, L"0x%lx", NULL, NULL, NULL, NULL },
{ L"Reserved", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL }
};
/**
An ACPI PARSER array describing the System Locality Latency and Bandwidth
Information Structure - Type 1.
*/
STATIC CONST ACPI_PARSER SllbiParser[] = {
{ L"Type", 2, 0, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Length", 4, 4, L"%d", NULL, NULL, NULL, NULL },
{ L"Flags", 1, 8, L"0x%x", NULL, (VOID **)&SllbiFlags, NULL, NULL },
{ L"Data type", 1, 9, L"0x%x", NULL, (VOID **)&SllbiDataType, NULL, NULL },
{ L"Min Transfer Size", 1, 10, L"%d", NULL, NULL, NULL, NULL },
{ L"Reserved", 1, 11, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Initiator Proximity Dom Count", 4, 12, L"%d", NULL,
(VOID **)&NumberInitiatorProximityDomain, NULL, NULL },
{ L"Target Proximity Dom Count", 4, 16, L"%d", NULL,
(VOID **)&NumberTargetProximityDomain, NULL, NULL },
{ L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Entry Base Unit", 8, 24, L"0x%lx", NULL, NULL, NULL, NULL }
// initiator Proximity Domain list ...
// target Proximity Domain list ...
// Latency/Bandwidth matrix ...
};
/**
An ACPI PARSER array describing the Memory Side Cache Information
Structure - Type 2.
*/
STATIC CONST ACPI_PARSER MemSideCacheInfoParser[] = {
{ L"Type", 2, 0, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Length", 4, 4, L"%d", NULL, NULL, NULL, NULL },
{ L"Proximity Dom for memory", 4, 8, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 4, 12, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Memory Side Cache Size", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL },
{ L"Cache Attributes", 4, 24, NULL, DumpCacheAttributes, NULL,
ValidateCacheAttributes, NULL },
{ L"Reserved", 2, 28, L"0x%x", NULL, NULL, NULL, NULL },
{ L"SMBIOS Handle Count", 2, 30, L"%d", NULL,
(VOID **)&NumberSMBIOSHandles, NULL, NULL }
// SMBIOS handles List ...
};
/**
This function parses the Memory Proximity Domain Attributes
Structure (Type 0).
@param [in] Ptr Pointer to the start of the Memory Proximity Domain
Attributes Structure data.
@param [in] Length Length of the Memory Proximity Domain Attributes
Structure.
**/
STATIC
VOID
DumpMpda (
IN UINT8 *Ptr,
IN UINT32 Length
)
{
ParseAcpi (
TRUE,
2,
"Memory Proximity Domain Attributes Structure",
Ptr,
Length,
PARSER_PARAMS (MemProximityDomainAttributeParser)
);
}
/**
This function parses the System Locality Latency and Bandwidth Information
Structure (Type 1).
@param [in] Ptr Pointer to the start of the System Locality Latency and
Bandwidth Information Structure data.
@param [in] Length Length of the System Locality Latency and Bandwidth
Information Structure.
**/
STATIC
VOID
DumpSllbi (
IN UINT8 *Ptr,
IN UINT32 Length
)
{
CONST UINT32 *InitiatorProximityDomainList;
CONST UINT32 *TargetProximityDomainList;
CONST UINT16 *LatencyBandwidthMatrix;
UINT32 Offset;
CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
CHAR16 SecondBuffer[OUTPUT_FIELD_COLUMN_WIDTH];
UINT32 RequiredTableSize;
UINT32 Index;
UINT32 IndexInitiator;
UINT32 IndexTarget;
UINT32 TargetStartOffset;
Offset = ParseAcpi (
TRUE,
2,
"System Locality Latency and Bandwidth Information Structure",
Ptr,
Length,
PARSER_PARAMS (SllbiParser)
);
// Check if the values used to control the parsing logic have been
// successfully read.
if ((SllbiFlags == NULL) ||
(SllbiDataType == NULL) ||
(NumberInitiatorProximityDomain == NULL) ||
(NumberTargetProximityDomain == NULL))
{
IncrementErrorCount ();
Print (
L"ERROR: Insufficient remaining table buffer length to read the " \
L"SLLBI structure header. Length = %d.\n",
Length
);
return;
}
RequiredTableSize = (*NumberInitiatorProximityDomain * sizeof (UINT32)) +
(*NumberTargetProximityDomain * sizeof (UINT32)) +
(*NumberInitiatorProximityDomain *
*NumberTargetProximityDomain * sizeof (UINT16)) +
Offset;
if (RequiredTableSize > Length) {
IncrementErrorCount ();
Print (
L"ERROR: Insufficient System Locality Latency and Bandwidth" \
L"Information Structure length. TableLength = %d. " \
L"RequiredTableLength = %d.\n",
Length,
RequiredTableSize
);
return;
}
InitiatorProximityDomainList = (UINT32 *)(Ptr + Offset);
TargetProximityDomainList = InitiatorProximityDomainList +
*NumberInitiatorProximityDomain;
LatencyBandwidthMatrix = (UINT16 *)(TargetProximityDomainList +
*NumberTargetProximityDomain);
// Display each element of the Initiator Proximity Domain list
for (Index = 0; Index < *NumberInitiatorProximityDomain; Index++) {
UnicodeSPrint (
Buffer,
sizeof (Buffer),
L"Initiator Proximity Dom [%d]",
Index
);
PrintFieldName (4, Buffer);
Print (
L"0x%x\n",
InitiatorProximityDomainList[Index]
);
}
// Display each element of the Target Proximity Domain list
for (Index = 0; Index < *NumberTargetProximityDomain; Index++) {
UnicodeSPrint (
Buffer,
sizeof (Buffer),
L"Target Proximity Dom [%d]",
Index
);
PrintFieldName (4, Buffer);
Print (
L"0x%x\n",
TargetProximityDomainList[Index]
);
}
// Create base name depending on Data Type in this Structure
if (*SllbiDataType >= ARRAY_SIZE (SllbiNames)) {
IncrementErrorCount ();
Print (L"Error: Unkown Data Type. DataType = 0x%x.\n", *SllbiDataType);
return;
}
StrCpyS (Buffer, sizeof (Buffer), SllbiNames[*SllbiDataType]);
// Adjust base name depending on Memory Hierarchy in this Structure
switch (SllbiFlags->MemoryHierarchy) {
case 0:
UnicodeSPrint (
SecondBuffer,
sizeof (SecondBuffer),
Buffer,
L"",
L"%s"
);
break;
case 1:
case 2:
case 3:
UnicodeSPrint (
SecondBuffer,
sizeof (SecondBuffer),
Buffer,
L"Hit ",
L"%s"
);
break;
default:
IncrementErrorCount ();
Print (
L"Error: Invalid Memory Hierarchy. MemoryHierarchy = %d.\n",
SllbiFlags->MemoryHierarchy
);
return;
} // switch
if (*NumberTargetProximityDomain <= MAX_MEMORY_DOMAIN_TARGET_PRINT_MATRIX) {
// Display the latency/bandwidth matrix as a matrix
UnicodeSPrint (
Buffer,
sizeof (Buffer),
SecondBuffer,
L""
);
PrintFieldName (4, Buffer);
Print (L"\n Target : X-axis (Horizontal)");
Print (L"\n Initiator : Y-axis (Vertical)");
Print (L"\n |");
for (IndexTarget = 0;
IndexTarget < *NumberTargetProximityDomain;
IndexTarget++)
{
Print (L" %2d", IndexTarget);
}
Print (L"\n ---+");
for (IndexTarget = 0;
IndexTarget < *NumberTargetProximityDomain;
IndexTarget++)
{
Print (L"------");
}
Print (L"\n");
TargetStartOffset = 0;
for (IndexInitiator = 0;
IndexInitiator < *NumberInitiatorProximityDomain;
IndexInitiator++)
{
Print (L" %2d |", IndexInitiator);
for (IndexTarget = 0;
IndexTarget < *NumberTargetProximityDomain;
IndexTarget++)
{
Print (
L" %5d",
LatencyBandwidthMatrix[TargetStartOffset + IndexTarget]
);
} // for Target
Print (L"\n");
TargetStartOffset += (*NumberTargetProximityDomain);
} // for Initiator
Print (L"\n");
} else {
// Display the latency/bandwidth matrix as a list
UnicodeSPrint (
Buffer,
sizeof (Buffer),
SecondBuffer,
L" [%d][%d]"
);
TargetStartOffset = 0;
for (IndexInitiator = 0;
IndexInitiator < *NumberInitiatorProximityDomain;
IndexInitiator++)
{
for (IndexTarget = 0;
IndexTarget < *NumberTargetProximityDomain;
IndexTarget++)
{
UnicodeSPrint (
SecondBuffer,
sizeof (SecondBuffer),
Buffer,
IndexInitiator,
IndexTarget
);
PrintFieldName (4, SecondBuffer);
Print (
L"%d\n",
LatencyBandwidthMatrix[TargetStartOffset + IndexTarget]
);
} // for Target
TargetStartOffset += (*NumberTargetProximityDomain);
} // for Initiator
}
}
/**
This function parses the Memory Side Cache Information Structure (Type 2).
@param [in] Ptr Pointer to the start of the Memory Side Cache Information
Structure data.
@param [in] Length Length of the Memory Side Cache Information Structure.
**/
STATIC
VOID
DumpMsci (
IN UINT8 *Ptr,
IN UINT32 Length
)
{
CONST UINT16 *SMBIOSHandlesList;
CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
UINT32 Offset;
UINT16 Index;
Offset = ParseAcpi (
TRUE,
2,
"Memory Side Cache Information Structure",
Ptr,
Length,
PARSER_PARAMS (MemSideCacheInfoParser)
);
// Check if the values used to control the parsing logic have been
// successfully read.
if (NumberSMBIOSHandles == NULL) {
IncrementErrorCount ();
Print (
L"ERROR: Insufficient remaining table buffer length to read the " \
L"MSCI structure header. Length = %d.\n",
Length
);
return;
}
if ((*NumberSMBIOSHandles * sizeof (UINT16)) > (Length - Offset)) {
IncrementErrorCount ();
Print (
L"ERROR: Invalid Number of SMBIOS Handles. SMBIOSHandlesCount = %d." \
L"RemainingBufferLength = %d.\n",
*NumberSMBIOSHandles,
Length - Offset
);
return;
}
SMBIOSHandlesList = (UINT16 *)(Ptr + Offset);
for (Index = 0; Index < *NumberSMBIOSHandles; Index++) {
UnicodeSPrint (
Buffer,
sizeof (Buffer),
L"SMBIOS Handles [%d]",
Index
);
PrintFieldName (4, Buffer);
Print (
L"0x%x\n",
SMBIOSHandlesList[Index]
);
}
}
/**
This function parses the ACPI HMAT table.
When trace is enabled this function parses the HMAT table and
traces the ACPI table fields.
This function parses the following HMAT structures:
- Memory Proximity Domain Attributes Structure (Type 0)
- System Locality Latency and Bandwidth Info Structure (Type 1)
- Memory Side Cache Info structure (Type 2)
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
ParseAcpiHmat (
IN BOOLEAN Trace,
IN UINT8 *Ptr,
IN UINT32 AcpiTableLength,
IN UINT8 AcpiTableRevision
)
{
UINT32 Offset;
UINT8 *HmatStructurePtr;
if (!Trace) {
return;
}
Offset = ParseAcpi (
Trace,
0,
"HMAT",
Ptr,
AcpiTableLength,
PARSER_PARAMS (HmatParser)
);
HmatStructurePtr = Ptr + Offset;
while (Offset < AcpiTableLength) {
// Parse HMAT Structure Header to obtain Type and Length.
ParseAcpi (
FALSE,
0,
NULL,
HmatStructurePtr,
AcpiTableLength - Offset,
PARSER_PARAMS (HmatStructureHeaderParser)
);
// Check if the values used to control the parsing logic have been
// successfully read.
if ((HmatStructureType == NULL) ||
(HmatStructureLength == NULL))
{
IncrementErrorCount ();
Print (
L"ERROR: Insufficient remaining table buffer length to read the " \
L"HMAT structure header. Length = %d.\n",
AcpiTableLength - Offset
);
return;
}
// Validate HMAT Structure length.
if ((*HmatStructureLength == 0) ||
((Offset + (*HmatStructureLength)) > AcpiTableLength))
{
IncrementErrorCount ();
Print (
L"ERROR: Invalid HMAT Structure length. " \
L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
*HmatStructureLength,
Offset,
AcpiTableLength
);
return;
}
switch (*HmatStructureType) {
case EFI_ACPI_6_4_HMAT_TYPE_MEMORY_PROXIMITY_DOMAIN_ATTRIBUTES:
DumpMpda (
HmatStructurePtr,
*HmatStructureLength
);
break;
case EFI_ACPI_6_4_HMAT_TYPE_SYSTEM_LOCALITY_LATENCY_AND_BANDWIDTH_INFO:
DumpSllbi (
HmatStructurePtr,
*HmatStructureLength
);
break;
case EFI_ACPI_6_4_HMAT_TYPE_MEMORY_SIDE_CACHE_INFO:
DumpMsci (
HmatStructurePtr,
*HmatStructureLength
);
break;
default:
IncrementErrorCount ();
Print (
L"ERROR: Unknown HMAT structure:"
L" Type = %d, Length = %d\n",
*HmatStructureType,
*HmatStructureLength
);
break;
} // switch
HmatStructurePtr += *HmatStructureLength;
Offset += *HmatStructureLength;
} // while
}
|