]>
Commit | Line | Data |
---|---|---|
a6eaba4d | 1 | /** @file\r |
ee4dc24f RN |
2 | SLIT table parser\r |
3 | \r | |
a4826c86 | 4 | Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.\r |
56ba3746 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
ee4dc24f RN |
6 | \r |
7 | @par Reference(s):\r | |
8 | - ACPI 6.2 Specification - Errata A, September 2017\r | |
9 | **/\r | |
10 | \r | |
11 | #include <IndustryStandard/Acpi.h>\r | |
12 | #include <Library/PrintLib.h>\r | |
13 | #include <Library/UefiLib.h>\r | |
14 | #include "AcpiParser.h"\r | |
15 | #include "AcpiTableParser.h"\r | |
16 | \r | |
17 | // Local Variables\r | |
18 | STATIC CONST UINT64* SlitSystemLocalityCount;\r | |
19 | STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;\r | |
20 | \r | |
a6eaba4d DB |
21 | /**\r |
22 | An ACPI_PARSER array describing the ACPI SLIT table.\r | |
23 | **/\r | |
ee4dc24f RN |
24 | STATIC CONST ACPI_PARSER SlitParser[] = {\r |
25 | PARSE_ACPI_HEADER (&AcpiHdrInfo),\r | |
26 | {L"Number of System Localities", 8, 36, L"0x%lx", NULL,\r | |
27 | (VOID**)&SlitSystemLocalityCount, NULL, NULL}\r | |
28 | };\r | |
29 | \r | |
a6eaba4d DB |
30 | /**\r |
31 | Macro to get the value of a System Locality\r | |
32 | **/\r | |
eb9db72c | 33 | #define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j)\r |
ee4dc24f | 34 | \r |
a6eaba4d DB |
35 | /**\r |
36 | This function parses the ACPI SLIT table.\r | |
ee4dc24f RN |
37 | When trace is enabled this function parses the SLIT table and\r |
38 | traces the ACPI table fields.\r | |
39 | \r | |
40 | This function also validates System Localities for the following:\r | |
41 | - Diagonal elements have a normalized value of 10\r | |
42 | - Relative distance from System Locality at i*N+j is same as\r | |
43 | j*N+i\r | |
44 | \r | |
45 | @param [in] Trace If TRUE, trace the ACPI fields.\r | |
46 | @param [in] Ptr Pointer to the start of the buffer.\r | |
47 | @param [in] AcpiTableLength Length of the ACPI table.\r | |
48 | @param [in] AcpiTableRevision Revision of the ACPI table.\r | |
a6eaba4d | 49 | **/\r |
ee4dc24f RN |
50 | VOID\r |
51 | EFIAPI\r | |
52 | ParseAcpiSlit (\r | |
53 | IN BOOLEAN Trace,\r | |
54 | IN UINT8* Ptr,\r | |
55 | IN UINT32 AcpiTableLength,\r | |
56 | IN UINT8 AcpiTableRevision\r | |
57 | )\r | |
58 | {\r | |
59 | UINT32 Offset;\r | |
eb9db72c KK |
60 | UINT32 Count;\r |
61 | UINT32 Index;\r | |
62 | UINT32 LocalityCount;\r | |
ee4dc24f RN |
63 | UINT8* LocalityPtr;\r |
64 | CHAR16 Buffer[80]; // Used for AsciiName param of ParseAcpi\r | |
65 | \r | |
66 | if (!Trace) {\r | |
67 | return;\r | |
68 | }\r | |
69 | \r | |
70 | Offset = ParseAcpi (\r | |
71 | TRUE,\r | |
72 | 0,\r | |
73 | "SLIT",\r | |
74 | Ptr,\r | |
75 | AcpiTableLength,\r | |
76 | PARSER_PARAMS (SlitParser)\r | |
77 | );\r | |
ee4dc24f | 78 | \r |
a4826c86 KK |
79 | // Check if the values used to control the parsing logic have been\r |
80 | // successfully read.\r | |
81 | if (SlitSystemLocalityCount == NULL) {\r | |
82 | IncrementErrorCount ();\r | |
83 | Print (\r | |
84 | L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",\r | |
85 | AcpiTableLength\r | |
86 | );\r | |
87 | return;\r | |
88 | }\r | |
89 | \r | |
eb9db72c KK |
90 | /*\r |
91 | Despite the 'Number of System Localities' being a 64-bit field in SLIT,\r | |
92 | the maximum number of localities that can be represented in SLIT is limited\r | |
93 | by the 'Length' field of the ACPI table.\r | |
94 | \r | |
95 | Since the ACPI table length field is 32-bit wide. The maximum number of\r | |
96 | localities that can be represented in SLIT can be calculated as:\r | |
97 | \r | |
98 | MaxLocality = sqrt (MAX_UINT32 - sizeof (EFI_ACPI_6_3_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER))\r | |
99 | = 65535\r | |
100 | = MAX_UINT16\r | |
101 | */\r | |
102 | if (*SlitSystemLocalityCount > MAX_UINT16) {\r | |
103 | IncrementErrorCount ();\r | |
104 | Print (\r | |
105 | L"ERROR: The Number of System Localities provided can't be represented " \\r | |
106 | L"in the SLIT table. SlitSystemLocalityCount = %ld. " \\r | |
107 | L"MaxLocalityCountAllowed = %d.\n",\r | |
108 | *SlitSystemLocalityCount,\r | |
109 | MAX_UINT16\r | |
110 | );\r | |
111 | return;\r | |
112 | }\r | |
113 | \r | |
114 | LocalityCount = (UINT32)*SlitSystemLocalityCount;\r | |
115 | \r | |
116 | // Make sure system localities fit in the table buffer provided\r | |
117 | if (Offset + (LocalityCount * LocalityCount) > AcpiTableLength) {\r | |
118 | IncrementErrorCount ();\r | |
119 | Print (\r | |
120 | L"ERROR: Invalid Number of System Localities. " \\r | |
121 | L"SlitSystemLocalityCount = %ld. AcpiTableLength = %d.\n",\r | |
122 | *SlitSystemLocalityCount,\r | |
123 | AcpiTableLength\r | |
124 | );\r | |
125 | return;\r | |
126 | }\r | |
127 | \r | |
a4826c86 | 128 | LocalityPtr = Ptr + Offset;\r |
a4826c86 | 129 | \r |
ee4dc24f RN |
130 | // We only print the Localities if the count is less than 16\r |
131 | // If the locality count is more than 16 then refer to the\r | |
132 | // raw data dump.\r | |
133 | if (LocalityCount < 16) {\r | |
134 | UnicodeSPrint (\r | |
135 | Buffer,\r | |
136 | sizeof (Buffer),\r | |
137 | L"Entry[0x%lx][0x%lx]",\r | |
138 | LocalityCount,\r | |
139 | LocalityCount\r | |
140 | );\r | |
141 | PrintFieldName (0, Buffer);\r | |
142 | Print (L"\n");\r | |
143 | Print (L" ");\r | |
f75c7478 DB |
144 | for (Index = 0; Index < LocalityCount; Index++) {\r |
145 | Print (L" (%3d) ", Index);\r | |
ee4dc24f RN |
146 | }\r |
147 | Print (L"\n");\r | |
f75c7478 DB |
148 | for (Count = 0; Count< LocalityCount; Count++) {\r |
149 | Print (L" (%3d) ", Count);\r | |
150 | for (Index = 0; Index < LocalityCount; Index++) {\r | |
151 | Print (L" %3d ", SLIT_ELEMENT (LocalityPtr, Count, Index));\r | |
ee4dc24f RN |
152 | }\r |
153 | Print (L"\n");\r | |
154 | }\r | |
155 | }\r | |
156 | \r | |
157 | // Validate\r | |
f75c7478 DB |
158 | for (Count = 0; Count < LocalityCount; Count++) {\r |
159 | for (Index = 0; Index < LocalityCount; Index++) {\r | |
ee4dc24f | 160 | // Element[x][x] must be equal to 10\r |
f75c7478 | 161 | if ((Count == Index) && (SLIT_ELEMENT (LocalityPtr, Count,Index) != 10)) {\r |
ee4dc24f RN |
162 | IncrementErrorCount ();\r |
163 | Print (\r | |
164 | L"ERROR: Diagonal Element[0x%lx][0x%lx] (%3d)."\r | |
e6f958d1 | 165 | L" Normalized Value is not 10\n",\r |
f75c7478 DB |
166 | Count,\r |
167 | Index,\r | |
168 | SLIT_ELEMENT (LocalityPtr, Count, Index)\r | |
ee4dc24f RN |
169 | );\r |
170 | }\r | |
171 | // Element[i][j] must be equal to Element[j][i]\r | |
f75c7478 DB |
172 | if (SLIT_ELEMENT (LocalityPtr, Count, Index) !=\r |
173 | SLIT_ELEMENT (LocalityPtr, Index, Count)) {\r | |
ee4dc24f RN |
174 | IncrementErrorCount ();\r |
175 | Print (\r | |
176 | L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) and \n"\r | |
e6f958d1 | 177 | L"Element[0x%lx][0x%lx] (%3d) do not match.\n",\r |
f75c7478 DB |
178 | Count,\r |
179 | Index,\r | |
180 | SLIT_ELEMENT (LocalityPtr, Count, Index),\r | |
181 | Index,\r | |
182 | Count,\r | |
183 | SLIT_ELEMENT (LocalityPtr, Index, Count)\r | |
ee4dc24f RN |
184 | );\r |
185 | }\r | |
186 | }\r | |
187 | }\r | |
188 | }\r |