4 Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 - ACPI 6.2 Specification - Errata A, September 2017
11 #include <IndustryStandard/Acpi.h>
12 #include <Library/PrintLib.h>
13 #include <Library/UefiLib.h>
14 #include "AcpiParser.h"
15 #include "AcpiTableParser.h"
18 STATIC CONST UINT8
* SratRAType
;
19 STATIC CONST UINT8
* SratRALength
;
20 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo
;
23 This function validates the Reserved field in the SRAT table header.
25 @param [in] Ptr Pointer to the start of the field data.
26 @param [in] Context Pointer to context specific information e.g. this
27 could be a pointer to the ACPI table header.
32 ValidateSratReserved (
37 if (*(UINT32
*)Ptr
!= 1) {
38 IncrementErrorCount ();
39 Print (L
"\nERROR: Reserved should be 1 for backward compatibility.\n");
44 This function traces the APIC Proximity Domain field.
46 @param [in] Format Format string for tracing the data.
47 @param [in] Ptr Pointer to the start of the buffer.
52 DumpSratApicProximity (
53 IN CONST CHAR16
* Format
,
57 UINT32 ProximityDomain
;
59 ProximityDomain
= Ptr
[0] | (Ptr
[1] << 8) | (Ptr
[2] << 16);
61 Print (Format
, ProximityDomain
);
65 An ACPI_PARSER array describing the SRAT Table.
67 STATIC CONST ACPI_PARSER SratParser
[] = {
68 PARSE_ACPI_HEADER (&AcpiHdrInfo
),
69 {L
"Reserved", 4, 36, L
"0x%x", NULL
, NULL
, ValidateSratReserved
, NULL
},
70 {L
"Reserved", 8, 40, L
"0x%lx", NULL
, NULL
, NULL
, NULL
}
74 An ACPI_PARSER array describing the Resource Allocation structure header.
76 STATIC CONST ACPI_PARSER SratResourceAllocationParser
[] = {
77 {L
"Type", 1, 0, NULL
, NULL
, (VOID
**)&SratRAType
, NULL
, NULL
},
78 {L
"Length", 1, 1, NULL
, NULL
, (VOID
**)&SratRALength
, NULL
, NULL
}
82 An ACPI_PARSER array describing the GICC Affinity structure.
84 STATIC CONST ACPI_PARSER SratGicCAffinityParser
[] = {
85 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
86 {L
"Length", 1, 1, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
88 {L
"Proximity Domain", 4, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
89 {L
"ACPI Processor UID", 4, 6, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
90 {L
"Flags", 4, 10, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
91 {L
"Clock Domain", 4, 14, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
95 An ACPI_PARSER array describing the GIC ITS Affinity structure.
97 STATIC CONST ACPI_PARSER SratGicITSAffinityParser
[] = {
98 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
99 {L
"Length", 1, 1, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
101 {L
"Proximity Domain", 4, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
102 {L
"Reserved", 2, 6, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
103 {L
"ITS Id", 4, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
107 An ACPI_PARSER array describing the Memory Affinity structure.
109 STATIC CONST ACPI_PARSER SratMemAffinityParser
[] = {
110 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
111 {L
"Length", 1, 1, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
113 {L
"Proximity Domain", 4, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
114 {L
"Reserved", 2, 6, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
115 {L
"Base Address Low", 4, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
116 {L
"Base Address High", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
117 {L
"Length Low", 4, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
118 {L
"Length High", 4, 20, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
119 {L
"Reserved", 4, 24, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
120 {L
"Flags", 4, 28, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
121 {L
"Reserved", 8, 32, L
"0x%lx", NULL
, NULL
, NULL
, NULL
}
125 An ACPI_PARSER array describing the APIC/SAPIC Affinity structure.
127 STATIC CONST ACPI_PARSER SratApciSapicAffinityParser
[] = {
128 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
129 {L
"Length", 1, 1, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
131 {L
"Proximity Domain [7:0]", 1, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
132 {L
"APIC ID", 1, 3, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
133 {L
"Flags", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
134 {L
"Local SAPIC EID", 1, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
135 {L
"Proximity Domain [31:8]", 3, 9, L
"0x%x", DumpSratApicProximity
,
137 {L
"Clock Domain", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
141 An ACPI_PARSER array describing the Processor Local x2APIC Affinity structure.
143 STATIC CONST ACPI_PARSER SratX2ApciAffinityParser
[] = {
144 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
145 {L
"Length", 1, 1, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
147 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
148 {L
"Proximity Domain", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
149 {L
"X2APIC ID", 4, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
150 {L
"Flags", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
151 {L
"Clock Domain", 4, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
152 {L
"Reserved", 4, 20, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
156 This function parses the ACPI SRAT table.
157 When trace is enabled this function parses the SRAT table and
158 traces the ACPI table fields.
160 This function parses the following Resource Allocation Structures:
161 - Processor Local APIC/SAPIC Affinity Structure
162 - Memory Affinity Structure
163 - Processor Local x2APIC Affinity Structure
164 - GICC Affinity Structure
166 This function also performs validation of the ACPI table fields.
168 @param [in] Trace If TRUE, trace the ACPI fields.
169 @param [in] Ptr Pointer to the start of the buffer.
170 @param [in] AcpiTableLength Length of the ACPI table.
171 @param [in] AcpiTableRevision Revision of the ACPI table.
178 IN UINT32 AcpiTableLength
,
179 IN UINT8 AcpiTableRevision
184 UINT32 GicCAffinityIndex
;
185 UINT32 GicITSAffinityIndex
;
186 UINT32 MemoryAffinityIndex
;
187 UINT32 ApicSapicAffinityIndex
;
188 UINT32 X2ApicAffinityIndex
;
189 CHAR8 Buffer
[80]; // Used for AsciiName param of ParseAcpi
191 GicCAffinityIndex
= 0;
192 GicITSAffinityIndex
= 0;
193 MemoryAffinityIndex
= 0;
194 ApicSapicAffinityIndex
= 0;
195 X2ApicAffinityIndex
= 0;
207 PARSER_PARAMS (SratParser
)
210 ResourcePtr
= Ptr
+ Offset
;
212 while (Offset
< AcpiTableLength
) {
218 AcpiTableLength
- Offset
,
219 PARSER_PARAMS (SratResourceAllocationParser
)
222 // Make sure the SRAT structure lies inside the table
223 if ((Offset
+ *SratRALength
) > AcpiTableLength
) {
224 IncrementErrorCount ();
226 L
"ERROR: Invalid SRAT structure length. SratRALength = %d. " \
227 L
"RemainingTableBufferLength = %d. SRAT parsing aborted.\n",
229 AcpiTableLength
- Offset
234 switch (*SratRAType
) {
235 case EFI_ACPI_6_2_GICC_AFFINITY
:
239 "GICC Affinity Structure [%d]",
248 PARSER_PARAMS (SratGicCAffinityParser
)
252 case EFI_ACPI_6_2_GIC_ITS_AFFINITY
:
256 "GIC ITS Affinity Structure [%d]",
257 GicITSAffinityIndex
++
265 PARSER_PARAMS (SratGicITSAffinityParser
)
269 case EFI_ACPI_6_2_MEMORY_AFFINITY
:
273 "Memory Affinity Structure [%d]",
274 MemoryAffinityIndex
++
282 PARSER_PARAMS (SratMemAffinityParser
)
286 case EFI_ACPI_6_2_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY
:
290 "APIC/SAPIC Affinity Structure [%d]",
291 ApicSapicAffinityIndex
++
299 PARSER_PARAMS (SratApciSapicAffinityParser
)
303 case EFI_ACPI_6_2_PROCESSOR_LOCAL_X2APIC_AFFINITY
:
307 "X2APIC Affinity Structure [%d]",
308 X2ApicAffinityIndex
++
316 PARSER_PARAMS (SratX2ApciAffinityParser
)
321 IncrementErrorCount ();
322 Print (L
"ERROR: Unknown SRAT Affinity type = 0x%x\n", *SratRAType
);
326 ResourcePtr
+= (*SratRALength
);
327 Offset
+= (*SratRALength
);