summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Apmt/ApmtParser.c
blob: ad64adbb0a6c999c98fed3d20d46e3ffe19bbdfe (plain)
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
/** @file
  APMT table parser

  Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
  Copyright (c) 2017 - 2018, ARM Limited. All rights reserved.
  SPDX-License-Identifier: BSD-2-Clause-Patent

  @par Reference(s):
    - ACPI 6.2 Specification - Errata A, September 2017
**/

#include <IndustryStandard/Acpi.h>
#include <IndustryStandard/ArmPerformanceMonitoringUnitTable.h>
#include <Library/UefiLib.h>
#include "AcpiParser.h"
#include "AcpiTableParser.h"

// Local variables
STATIC ACPI_DESCRIPTION_HEADER_INFO  AcpiHdrInfo;
STATIC CONST UINT16                  *NodeLength;

/**
  An ACPI_PARSER array describing the ACPI APMT Table.
**/
STATIC CONST ACPI_PARSER  ApmtParser[] = {
  PARSE_ACPI_HEADER (&AcpiHdrInfo)
};

/**
  An ACPI_PARSER array describing the ACPI Arm PMU Node.
**/
STATIC CONST ACPI_PARSER  ArmPmuNodeParser[] = {
  { L"Length",                   2, 0,  L"0x%x",  NULL, (VOID **)&NodeLength, NULL, NULL },
  { L"Node flags",               1, 2,  L"0x%x",  NULL, NULL,                 NULL, NULL },
  { L"Node type",                1, 3,  L"0x%x",  NULL, NULL,                 NULL, NULL },
  { L"Identifier",               4, 4,  L"0x%x",  NULL, NULL,                 NULL, NULL },
  { L"Node Instance primary",    8, 8,  L"0x%lx", NULL, NULL,                 NULL, NULL },
  { L"Node Instance secondary",  4, 16, L"0x%x",  NULL, NULL,                 NULL, NULL },
  { L"Base address 0",           8, 20, L"0x%lx", NULL, NULL,                 NULL, NULL },
  { L"Base address 1",           8, 28, L"0x%lx", NULL, NULL,                 NULL, NULL },
  { L"Overflow interrupt",       4, 36, L"0x%x",  NULL, NULL,                 NULL, NULL },
  { L"Reserved1",                4, 40, L"0x%x",  NULL, NULL,                 NULL, NULL },
  { L"Overflow interrupt flags", 4, 44, L"0x%x",  NULL, NULL,                 NULL, NULL },
  { L"Processor affinity",       4, 48, L"0x%x",  NULL, NULL,                 NULL, NULL },
  { L"Implementation ID",        4, 52, L"0x%x",  NULL, NULL,                 NULL, NULL }
};

/**
  This function parses the ACPI APMT table.
  When trace is enabled this function parses the APMT 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
ParseAcpiApmt (
  IN BOOLEAN  Trace,
  IN UINT8    *Ptr,
  IN UINT32   AcpiTableLength,
  IN UINT8    AcpiTableRevision
  )
{
  UINT32  Offset;

  if (!Trace) {
    return;
  }

  ParseAcpi (
    Trace,
    0,
    "APMT",
    Ptr,
    AcpiTableLength,
    PARSER_PARAMS (ApmtParser)
    );
  Offset = sizeof (EFI_ACPI_DESCRIPTION_HEADER);

  while (Offset < AcpiTableLength) {
    ParseAcpi (
      Trace,
      2,
      "Arm PMU node",
      Ptr + Offset,
      (AcpiTableLength - Offset),
      PARSER_PARAMS (ArmPmuNodeParser)
      );
    if (NodeLength == NULL) {
      Print (
        L"ERROR: Insufficient remaining table buffer length to read the " \
        L"Node structure. Length = %d.\n",
        (AcpiTableLength - Offset)
        );
      IncrementErrorCount ();
      break;
    }

    Offset += *NodeLength;
  }
}