summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Hpet/HpetParser.c
blob: 1b4c38f2af9542f3bdf2dbdb58ea458f59704347 (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
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
/** @file
  HPET table parser

  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
  SPDX-License-Identifier: BSD-2-Clause-Patent

  @par Reference(s):
    - HPET spec, version 1.0a
**/

#include <Library/UefiLib.h>
#include "AcpiParser.h"

STATIC ACPI_DESCRIPTION_HEADER_INFO  AcpiHdrInfo;

/**
  This function prints HPET page protection flags.
  If no format string is specified the Format must be NULL.

  @param [in] Format  Optional format string for tracing the data.
  @param [in] Ptr     Pointer to the start of the buffer.
**/
VOID
EFIAPI
DumpHpetPageProtectionFlag (
  IN CONST CHAR16  *Format OPTIONAL,
  IN UINT8         *Ptr
  )
{
  if (Format != NULL) {
    Print (Format, *(UINT8 *)Ptr);
    return;
  }

  Print (L"0x%X ", *(UINT8 *)Ptr);
  switch (*Ptr) {
    case 0:
      Print (L"(no guarantee for page protection)");
      break;
    case 1:
      Print (L"(4K page protection)");
      break;
    case 2:
      Print (L"(64K page protection)");
      break;
    default:
      IncrementErrorCount ();
      Print (L"(OEM Reserved)");
      break;
  }

  return;
}

/**
  An ACPI_PARSER array describing the ACPI HPET flags.
**/
STATIC CONST ACPI_PARSER  DumpHpetFlagParser[] = {
  { L"Page Protection Flag", 4, 0, NULL,    DumpHpetPageProtectionFlag, NULL, NULL, NULL },
  { L"OEM Attributes",       4, 4, L"0x%x", NULL,                       NULL, NULL, NULL }
};

/**
  This function prints HPET Flags fields.
  If no format string is specified the Format must be NULL.

  @param [in] Format  Optional format string for tracing the data.
  @param [in] Ptr     Pointer to the start of the buffer.
**/
VOID
EFIAPI
DumpHpetFlag (
  IN CONST CHAR16  *Format OPTIONAL,
  IN UINT8         *Ptr
  )
{
  if (Format != NULL) {
    Print (Format, *(UINT8 *)Ptr);
    return;
  }

  Print (L"0x%X\n", *(UINT8 *)Ptr);
  ParseAcpiBitFields (
    TRUE,
    2,
    NULL,
    Ptr,
    4,
    PARSER_PARAMS (DumpHpetFlagParser)
    );
}

/**
  This function prints HPET Counter size fields.
  If no format string is specified the Format must be NULL.

  @param [in] Format  Optional format string for tracing the data.
  @param [in] Ptr     Pointer to the start of the buffer.
**/
VOID
EFIAPI
DumpCounterSize (
  IN CONST CHAR16  *Format OPTIONAL,
  IN UINT8         *Ptr
  )
{
  if (Format != NULL) {
    Print (Format, *(UINT32 *)Ptr);
    return;
  }

  Print (L"0x%X ", *(UINT32 *)Ptr);
  if (*Ptr == 0) {
    Print (L"(Max 32-bit counter size)");
  } else {
    Print (L"(Max 64-bit counter size)");
  }
}

/**
  This function validates the 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
ValidateHpetRevId (
  IN UINT8  *Ptr,
  IN VOID   *Context
  )
{
  if ((*(UINT8 *)Ptr) == 0) {
    IncrementErrorCount ();
    Print (
      L"\nERROR: HPET Hardware Rev ID must be set."
      );
  }
}

/**
  An ACPI_PARSER array describing the ACPI HPET Event Timer Block ID.
**/
STATIC CONST ACPI_PARSER  HpetEventTimerBlockIdFlagParser[] = {
  { L"Hardware Rev ID",                  8,  0,  L"0x%x", NULL,            NULL, ValidateHpetRevId, NULL },
  { L"Comparators in 1st Timer Block",   5,  8,  L"0x%x", NULL,            NULL, NULL,              NULL },
  { L"Counter max size",                 1,  13, NULL,    DumpCounterSize, NULL, NULL,              NULL },
  { L"Reserved",                         1,  14, L"%d",   NULL,            NULL, NULL,              NULL },
  { L"LegacyReplacement IRQ Routing",    1,  15, L"%d",   NULL,            NULL, NULL,              NULL },
  { L"PCI Vendor ID of 1st Timer Block", 16, 16, L"0x%x", NULL,            NULL, NULL,              NULL }
};

/**
  This function prints Hardware ID of HPET Event timer block.
  If no format string is specified the Format must be NULL.

  @param [in] Format  Optional format string for tracing the data.
  @param [in] Ptr     Pointer to the start of the buffer.
**/
VOID
EFIAPI
DumpHpetEventTimerBlockId (
  IN CONST CHAR16  *Format OPTIONAL,
  IN UINT8         *Ptr
  )
{
  if (Format != NULL) {
    Print (Format, *(UINT32 *)Ptr);
    return;
  }

  Print (L"0x%X\n", *(UINT32 *)Ptr);
  ParseAcpiBitFields (
    TRUE,
    2,
    NULL,
    Ptr,
    4,
    PARSER_PARAMS (HpetEventTimerBlockIdFlagParser)
    );
}

/**
  An ACPI_PARSER array describing the ACPI HPET Table.
**/
STATIC CONST ACPI_PARSER  HpetParser[] = {
  PARSE_ACPI_HEADER (&AcpiHdrInfo),
  { L"Event Timer Block ID",       4,   36, NULL,    DumpHpetEventTimerBlockId, NULL, NULL, NULL },
  { L"Base Address",               12,  40, NULL,    DumpGas,                   NULL, NULL, NULL },
  { L"HPET Number",                1,   52, L"0x%x", NULL,                      NULL, NULL, NULL },
  { L"Minimum Clock Ticks",        2,   53, L"0x%x", NULL,                      NULL, NULL, NULL },
  { L"Page Protection and OEM Attributes",1,   55, NULL,    DumpHpetFlag,              NULL, NULL, NULL }
};

/**
  This function parses the ACPI HPET table.

  @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
ParseAcpiHpet (
  IN BOOLEAN  Trace,
  IN UINT8    *Ptr,
  IN UINT32   AcpiTableLength,
  IN UINT8    AcpiTableRevision
  )
{
  ParseAcpi (
    Trace,
    0,
    "HPET",
    Ptr,
    AcpiTableLength,
    PARSER_PARAMS (HpetParser)
    );
}