]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
ShellPkg: Apply uncrustify changes
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Slit / SlitParser.c
CommitLineData
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
47d20b54
MK
18STATIC CONST UINT64 *SlitSystemLocalityCount;\r
19STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;\r
ee4dc24f 20\r
a6eaba4d
DB
21/**\r
22 An ACPI_PARSER array describing the ACPI SLIT table.\r
23**/\r
47d20b54 24STATIC CONST ACPI_PARSER SlitParser[] = {\r
ee4dc24f 25 PARSE_ACPI_HEADER (&AcpiHdrInfo),\r
47d20b54
MK
26 { L"Number of System Localities", 8, 36, L"0x%lx", NULL,\r
27 (VOID **)&SlitSystemLocalityCount,NULL, NULL }\r
ee4dc24f
RN
28};\r
29\r
a6eaba4d
DB
30/**\r
31 Macro to get the value of a System Locality\r
32**/\r
47d20b54 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
50VOID\r
51EFIAPI\r
52ParseAcpiSlit (\r
47d20b54
MK
53 IN BOOLEAN Trace,\r
54 IN UINT8 *Ptr,\r
55 IN UINT32 AcpiTableLength,\r
56 IN UINT8 AcpiTableRevision\r
ee4dc24f
RN
57 )\r
58{\r
47d20b54
MK
59 UINT32 Offset;\r
60 UINT32 Count;\r
61 UINT32 Index;\r
62 UINT32 LocalityCount;\r
63 UINT8 *LocalityPtr;\r
64 CHAR16 Buffer[80]; // Used for AsciiName param of ParseAcpi\r
ee4dc24f
RN
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
47d20b54
MK
106 L"in the SLIT table. SlitSystemLocalityCount = %ld. " \\r
107 L"MaxLocalityCountAllowed = %d.\n",\r
eb9db72c
KK
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
47d20b54 121 L"SlitSystemLocalityCount = %ld. AcpiTableLength = %d.\n",\r
eb9db72c
KK
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 146 }\r
47d20b54 147\r
ee4dc24f 148 Print (L"\n");\r
47d20b54 149 for (Count = 0; Count < LocalityCount; Count++) {\r
f75c7478
DB
150 Print (L" (%3d) ", Count);\r
151 for (Index = 0; Index < LocalityCount; Index++) {\r
152 Print (L" %3d ", SLIT_ELEMENT (LocalityPtr, Count, Index));\r
ee4dc24f 153 }\r
47d20b54 154\r
ee4dc24f
RN
155 Print (L"\n");\r
156 }\r
157 }\r
158\r
159 // Validate\r
f75c7478
DB
160 for (Count = 0; Count < LocalityCount; Count++) {\r
161 for (Index = 0; Index < LocalityCount; Index++) {\r
ee4dc24f 162 // Element[x][x] must be equal to 10\r
47d20b54 163 if ((Count == Index) && (SLIT_ELEMENT (LocalityPtr, Count, Index) != 10)) {\r
ee4dc24f
RN
164 IncrementErrorCount ();\r
165 Print (\r
166 L"ERROR: Diagonal Element[0x%lx][0x%lx] (%3d)."\r
47d20b54 167 L" Normalized Value is not 10\n",\r
f75c7478
DB
168 Count,\r
169 Index,\r
170 SLIT_ELEMENT (LocalityPtr, Count, Index)\r
ee4dc24f
RN
171 );\r
172 }\r
47d20b54 173\r
ee4dc24f 174 // Element[i][j] must be equal to Element[j][i]\r
f75c7478 175 if (SLIT_ELEMENT (LocalityPtr, Count, Index) !=\r
47d20b54
MK
176 SLIT_ELEMENT (LocalityPtr, Index, Count))\r
177 {\r
ee4dc24f
RN
178 IncrementErrorCount ();\r
179 Print (\r
180 L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) and \n"\r
47d20b54 181 L"Element[0x%lx][0x%lx] (%3d) do not match.\n",\r
f75c7478
DB
182 Count,\r
183 Index,\r
184 SLIT_ELEMENT (LocalityPtr, Count, Index),\r
185 Index,\r
186 Count,\r
187 SLIT_ELEMENT (LocalityPtr, Index, Count)\r
ee4dc24f
RN
188 );\r
189 }\r
190 }\r
191 }\r
192}\r