]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
ShellPkg/AcpiView: Fix IA32 link error
[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
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
18STATIC CONST UINT64* SlitSystemLocalityCount;\r
19STATIC 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
24STATIC 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
eb2a1ed5 33#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (MultU64x64 (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
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
f75c7478
DB
60 UINT64 Count;\r
61 UINT64 Index;\r
ee4dc24f
RN
62 UINT64 LocalityCount;\r
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
78 LocalityPtr = Ptr + Offset;\r
79\r
80 LocalityCount = *SlitSystemLocalityCount;\r
81 // We only print the Localities if the count is less than 16\r
82 // If the locality count is more than 16 then refer to the\r
83 // raw data dump.\r
84 if (LocalityCount < 16) {\r
85 UnicodeSPrint (\r
86 Buffer,\r
87 sizeof (Buffer),\r
88 L"Entry[0x%lx][0x%lx]",\r
89 LocalityCount,\r
90 LocalityCount\r
91 );\r
92 PrintFieldName (0, Buffer);\r
93 Print (L"\n");\r
94 Print (L" ");\r
f75c7478
DB
95 for (Index = 0; Index < LocalityCount; Index++) {\r
96 Print (L" (%3d) ", Index);\r
ee4dc24f
RN
97 }\r
98 Print (L"\n");\r
f75c7478
DB
99 for (Count = 0; Count< LocalityCount; Count++) {\r
100 Print (L" (%3d) ", Count);\r
101 for (Index = 0; Index < LocalityCount; Index++) {\r
102 Print (L" %3d ", SLIT_ELEMENT (LocalityPtr, Count, Index));\r
ee4dc24f
RN
103 }\r
104 Print (L"\n");\r
105 }\r
106 }\r
107\r
108 // Validate\r
f75c7478
DB
109 for (Count = 0; Count < LocalityCount; Count++) {\r
110 for (Index = 0; Index < LocalityCount; Index++) {\r
ee4dc24f 111 // Element[x][x] must be equal to 10\r
f75c7478 112 if ((Count == Index) && (SLIT_ELEMENT (LocalityPtr, Count,Index) != 10)) {\r
ee4dc24f
RN
113 IncrementErrorCount ();\r
114 Print (\r
115 L"ERROR: Diagonal Element[0x%lx][0x%lx] (%3d)."\r
e6f958d1 116 L" Normalized Value is not 10\n",\r
f75c7478
DB
117 Count,\r
118 Index,\r
119 SLIT_ELEMENT (LocalityPtr, Count, Index)\r
ee4dc24f
RN
120 );\r
121 }\r
122 // Element[i][j] must be equal to Element[j][i]\r
f75c7478
DB
123 if (SLIT_ELEMENT (LocalityPtr, Count, Index) !=\r
124 SLIT_ELEMENT (LocalityPtr, Index, Count)) {\r
ee4dc24f
RN
125 IncrementErrorCount ();\r
126 Print (\r
127 L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) and \n"\r
e6f958d1 128 L"Element[0x%lx][0x%lx] (%3d) do not match.\n",\r
f75c7478
DB
129 Count,\r
130 Index,\r
131 SLIT_ELEMENT (LocalityPtr, Count, Index),\r
132 Index,\r
133 Count,\r
134 SLIT_ELEMENT (LocalityPtr, Index, Count)\r
ee4dc24f
RN
135 );\r
136 }\r
137 }\r
138 }\r
139}\r