TianoCore EDK2 master
Loading...
Searching...
No Matches
SlitParser.c
Go to the documentation of this file.
1
12#include <Library/PrintLib.h>
13#include <Library/UefiLib.h>
14#include "AcpiParser.h"
15#include "AcpiTableParser.h"
16
17// Local Variables
18STATIC CONST UINT64 *SlitSystemLocalityCount;
20
25 PARSE_ACPI_HEADER (&AcpiHdrInfo),
26 { L"Number of System Localities", 8, 36, L"0x%lx", NULL,
27 (VOID **)&SlitSystemLocalityCount,NULL, NULL }
28};
29
33#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j)
34
50VOID
51EFIAPI
53 IN BOOLEAN Trace,
54 IN UINT8 *Ptr,
55 IN UINT32 AcpiTableLength,
56 IN UINT8 AcpiTableRevision
57 )
58{
59 UINT32 Offset;
60 UINT32 Count;
61 UINT32 Index;
62 UINT32 LocalityCount;
63 UINT8 *LocalityPtr;
64 CHAR16 Buffer[80]; // Used for AsciiName param of ParseAcpi
65
66 if (!Trace) {
67 return;
68 }
69
70 Offset = ParseAcpi (
71 TRUE,
72 0,
73 "SLIT",
74 Ptr,
75 AcpiTableLength,
77 );
78
79 // Check if the values used to control the parsing logic have been
80 // successfully read.
81 if (SlitSystemLocalityCount == NULL) {
83 Print (
84 L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
85 AcpiTableLength
86 );
87 return;
88 }
89
90 /*
91 Despite the 'Number of System Localities' being a 64-bit field in SLIT,
92 the maximum number of localities that can be represented in SLIT is limited
93 by the 'Length' field of the ACPI table.
94
95 Since the ACPI table length field is 32-bit wide. The maximum number of
96 localities that can be represented in SLIT can be calculated as:
97
98 MaxLocality = sqrt (MAX_UINT32 - sizeof (EFI_ACPI_6_3_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER))
99 = 65535
100 = MAX_UINT16
101 */
102 if (*SlitSystemLocalityCount > MAX_UINT16) {
104 Print (
105 L"ERROR: The Number of System Localities provided can't be represented " \
106 L"in the SLIT table. SlitSystemLocalityCount = %ld. " \
107 L"MaxLocalityCountAllowed = %d.\n",
108 *SlitSystemLocalityCount,
109 MAX_UINT16
110 );
111 return;
112 }
113
114 LocalityCount = (UINT32)*SlitSystemLocalityCount;
115
116 // Make sure system localities fit in the table buffer provided
117 if (Offset + (LocalityCount * LocalityCount) > AcpiTableLength) {
119 Print (
120 L"ERROR: Invalid Number of System Localities. " \
121 L"SlitSystemLocalityCount = %ld. AcpiTableLength = %d.\n",
122 *SlitSystemLocalityCount,
123 AcpiTableLength
124 );
125 return;
126 }
127
128 LocalityPtr = Ptr + Offset;
129
130 // We only print the Localities if the count is less than 16
131 // If the locality count is more than 16 then refer to the
132 // raw data dump.
133 if (LocalityCount < 16) {
135 Buffer,
136 sizeof (Buffer),
137 L"Entry[0x%lx][0x%lx]",
138 LocalityCount,
139 LocalityCount
140 );
141 PrintFieldName (0, Buffer);
142 Print (L"\n");
143 Print (L" ");
144 for (Index = 0; Index < LocalityCount; Index++) {
145 Print (L" (%3d) ", Index);
146 }
147
148 Print (L"\n");
149 for (Count = 0; Count < LocalityCount; Count++) {
150 Print (L" (%3d) ", Count);
151 for (Index = 0; Index < LocalityCount; Index++) {
152 Print (L" %3d ", SLIT_ELEMENT (LocalityPtr, Count, Index));
153 }
154
155 Print (L"\n");
156 }
157 }
158
159 // Validate
160 for (Count = 0; Count < LocalityCount; Count++) {
161 for (Index = 0; Index < LocalityCount; Index++) {
162 // Element[x][x] must be equal to 10
163 if ((Count == Index) && (SLIT_ELEMENT (LocalityPtr, Count, Index) != 10)) {
165 Print (
166 L"ERROR: Diagonal Element[0x%lx][0x%lx] (%3d)."
167 L" Normalized Value is not 10\n",
168 Count,
169 Index,
170 SLIT_ELEMENT (LocalityPtr, Count, Index)
171 );
172 }
173
174 // Element[i][j] must be equal to Element[j][i]
175 if (SLIT_ELEMENT (LocalityPtr, Count, Index) !=
176 SLIT_ELEMENT (LocalityPtr, Index, Count))
177 {
179 Print (
180 L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) and \n"
181 L"Element[0x%lx][0x%lx] (%3d) do not match.\n",
182 Count,
183 Index,
184 SLIT_ELEMENT (LocalityPtr, Count, Index),
185 Index,
186 Count,
187 SLIT_ELEMENT (LocalityPtr, Index, Count)
188 );
189 }
190 }
191 }
192}
VOID EFIAPI PrintFieldName(IN UINT32 Indent, IN CONST CHAR16 *FieldName)
Definition: AcpiParser.c:641
VOID EFIAPI IncrementErrorCount(VOID)
Definition: AcpiParser.c:83
UINT32 EFIAPI ParseAcpi(IN BOOLEAN Trace, IN UINT32 Indent, IN CONST CHAR8 *AsciiName OPTIONAL, IN UINT8 *Ptr, IN UINT32 Length, IN CONST ACPI_PARSER *Parser, IN UINT32 ParserItems)
Definition: AcpiParser.c:683
#define PARSER_PARAMS(Parser)
Definition: AcpiParser.h:494
#define PARSE_ACPI_HEADER(Info)
Definition: AcpiParser.h:501
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define IN
Definition: Base.h:279
VOID EFIAPI ParseAcpiSlit(IN BOOLEAN Trace, IN UINT8 *Ptr, IN UINT32 AcpiTableLength, IN UINT8 AcpiTableRevision)
Definition: SlitParser.c:52
#define SLIT_ELEMENT(Ptr, i, j)
Definition: SlitParser.c:33
STATIC CONST ACPI_PARSER SlitParser[]
Definition: SlitParser.c:24
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113