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