]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
ShellPkg/UefiShellAcpiViewCommandLib: Fix ECC issues
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Slit / SlitParser.c
CommitLineData
a6eaba4d 1/** @file\r
ee4dc24f
RN
2 SLIT table parser\r
3\r
4 Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 @par Reference(s):\r
14 - ACPI 6.2 Specification - Errata A, September 2017\r
15**/\r
16\r
17#include <IndustryStandard/Acpi.h>\r
18#include <Library/PrintLib.h>\r
19#include <Library/UefiLib.h>\r
20#include "AcpiParser.h"\r
21#include "AcpiTableParser.h"\r
22\r
23// Local Variables\r
24STATIC CONST UINT64* SlitSystemLocalityCount;\r
25STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;\r
26\r
a6eaba4d
DB
27/**\r
28 An ACPI_PARSER array describing the ACPI SLIT table.\r
29**/\r
ee4dc24f
RN
30STATIC CONST ACPI_PARSER SlitParser[] = {\r
31 PARSE_ACPI_HEADER (&AcpiHdrInfo),\r
32 {L"Number of System Localities", 8, 36, L"0x%lx", NULL,\r
33 (VOID**)&SlitSystemLocalityCount, NULL, NULL}\r
34};\r
35\r
a6eaba4d
DB
36/**\r
37 Macro to get the value of a System Locality\r
38**/\r
ee4dc24f
RN
39#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j)\r
40\r
a6eaba4d
DB
41/**\r
42 This function parses the ACPI SLIT table.\r
ee4dc24f
RN
43 When trace is enabled this function parses the SLIT table and\r
44 traces the ACPI table fields.\r
45\r
46 This function also validates System Localities for the following:\r
47 - Diagonal elements have a normalized value of 10\r
48 - Relative distance from System Locality at i*N+j is same as\r
49 j*N+i\r
50\r
51 @param [in] Trace If TRUE, trace the ACPI fields.\r
52 @param [in] Ptr Pointer to the start of the buffer.\r
53 @param [in] AcpiTableLength Length of the ACPI table.\r
54 @param [in] AcpiTableRevision Revision of the ACPI table.\r
a6eaba4d 55**/\r
ee4dc24f
RN
56VOID\r
57EFIAPI\r
58ParseAcpiSlit (\r
59 IN BOOLEAN Trace,\r
60 IN UINT8* Ptr,\r
61 IN UINT32 AcpiTableLength,\r
62 IN UINT8 AcpiTableRevision\r
63 )\r
64{\r
65 UINT32 Offset;\r
66 UINT64 i;\r
67 UINT64 j;\r
68 UINT64 LocalityCount;\r
69 UINT8* LocalityPtr;\r
70 CHAR16 Buffer[80]; // Used for AsciiName param of ParseAcpi\r
71\r
72 if (!Trace) {\r
73 return;\r
74 }\r
75\r
76 Offset = ParseAcpi (\r
77 TRUE,\r
78 0,\r
79 "SLIT",\r
80 Ptr,\r
81 AcpiTableLength,\r
82 PARSER_PARAMS (SlitParser)\r
83 );\r
84 LocalityPtr = Ptr + Offset;\r
85\r
86 LocalityCount = *SlitSystemLocalityCount;\r
87 // We only print the Localities if the count is less than 16\r
88 // If the locality count is more than 16 then refer to the\r
89 // raw data dump.\r
90 if (LocalityCount < 16) {\r
91 UnicodeSPrint (\r
92 Buffer,\r
93 sizeof (Buffer),\r
94 L"Entry[0x%lx][0x%lx]",\r
95 LocalityCount,\r
96 LocalityCount\r
97 );\r
98 PrintFieldName (0, Buffer);\r
99 Print (L"\n");\r
100 Print (L" ");\r
101 for (j = 0; j < LocalityCount; j++) {\r
102 Print (L" (%3d) ", j);\r
103 }\r
104 Print (L"\n");\r
105 for (i = 0; i < LocalityCount; i++) {\r
106 Print (L" (%3d) ", i);\r
107 for (j = 0; j < LocalityCount; j++) {\r
108 Print (L" %3d ", SLIT_ELEMENT (LocalityPtr, i, j));\r
109 }\r
110 Print (L"\n");\r
111 }\r
112 }\r
113\r
114 // Validate\r
115 for (i = 0; i < LocalityCount; i++) {\r
116 for (j = 0; j < LocalityCount; j++) {\r
117 // Element[x][x] must be equal to 10\r
118 if ((i == j) && (SLIT_ELEMENT (LocalityPtr, i, j) != 10)) {\r
119 IncrementErrorCount ();\r
120 Print (\r
121 L"ERROR: Diagonal Element[0x%lx][0x%lx] (%3d)."\r
122 " Normalized Value is not 10\n",\r
123 i,\r
124 j,\r
125 SLIT_ELEMENT (LocalityPtr, i, j)\r
126 );\r
127 }\r
128 // Element[i][j] must be equal to Element[j][i]\r
129 if (SLIT_ELEMENT (LocalityPtr, i, j) !=\r
130 SLIT_ELEMENT (LocalityPtr, j, i)) {\r
131 IncrementErrorCount ();\r
132 Print (\r
133 L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) and \n"\r
134 "Element[0x%lx][0x%lx] (%3d) do not match.\n",\r
135 i,\r
136 j,\r
137 SLIT_ELEMENT (LocalityPtr, i, j),\r
138 j,\r
139 i,\r
140 SLIT_ELEMENT (LocalityPtr, j, i)\r
141 );\r
142 }\r
143 }\r
144 }\r
145}\r