]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
ShellPkg/UefiShellAcpiViewCommandLib: Fix ECC issues
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Slit / SlitParser.c
1 /** @file
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 /**
28 An ACPI_PARSER array describing the ACPI SLIT table.
29 **/
30 STATIC CONST ACPI_PARSER SlitParser[] = {
31 PARSE_ACPI_HEADER (&AcpiHdrInfo),
32 {L"Number of System Localities", 8, 36, L"0x%lx", NULL,
33 (VOID**)&SlitSystemLocalityCount, NULL, NULL}
34 };
35
36 /**
37 Macro to get the value of a System Locality
38 **/
39 #define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j)
40
41 /**
42 This function parses the ACPI SLIT table.
43 When trace is enabled this function parses the SLIT table and
44 traces the ACPI table fields.
45
46 This function also validates System Localities for the following:
47 - Diagonal elements have a normalized value of 10
48 - Relative distance from System Locality at i*N+j is same as
49 j*N+i
50
51 @param [in] Trace If TRUE, trace the ACPI fields.
52 @param [in] Ptr Pointer to the start of the buffer.
53 @param [in] AcpiTableLength Length of the ACPI table.
54 @param [in] AcpiTableRevision Revision of the ACPI table.
55 **/
56 VOID
57 EFIAPI
58 ParseAcpiSlit (
59 IN BOOLEAN Trace,
60 IN UINT8* Ptr,
61 IN UINT32 AcpiTableLength,
62 IN UINT8 AcpiTableRevision
63 )
64 {
65 UINT32 Offset;
66 UINT64 i;
67 UINT64 j;
68 UINT64 LocalityCount;
69 UINT8* LocalityPtr;
70 CHAR16 Buffer[80]; // Used for AsciiName param of ParseAcpi
71
72 if (!Trace) {
73 return;
74 }
75
76 Offset = ParseAcpi (
77 TRUE,
78 0,
79 "SLIT",
80 Ptr,
81 AcpiTableLength,
82 PARSER_PARAMS (SlitParser)
83 );
84 LocalityPtr = Ptr + Offset;
85
86 LocalityCount = *SlitSystemLocalityCount;
87 // We only print the Localities if the count is less than 16
88 // If the locality count is more than 16 then refer to the
89 // raw data dump.
90 if (LocalityCount < 16) {
91 UnicodeSPrint (
92 Buffer,
93 sizeof (Buffer),
94 L"Entry[0x%lx][0x%lx]",
95 LocalityCount,
96 LocalityCount
97 );
98 PrintFieldName (0, Buffer);
99 Print (L"\n");
100 Print (L" ");
101 for (j = 0; j < LocalityCount; j++) {
102 Print (L" (%3d) ", j);
103 }
104 Print (L"\n");
105 for (i = 0; i < LocalityCount; i++) {
106 Print (L" (%3d) ", i);
107 for (j = 0; j < LocalityCount; j++) {
108 Print (L" %3d ", SLIT_ELEMENT (LocalityPtr, i, j));
109 }
110 Print (L"\n");
111 }
112 }
113
114 // Validate
115 for (i = 0; i < LocalityCount; i++) {
116 for (j = 0; j < LocalityCount; j++) {
117 // Element[x][x] must be equal to 10
118 if ((i == j) && (SLIT_ELEMENT (LocalityPtr, i, j) != 10)) {
119 IncrementErrorCount ();
120 Print (
121 L"ERROR: Diagonal Element[0x%lx][0x%lx] (%3d)."
122 " Normalized Value is not 10\n",
123 i,
124 j,
125 SLIT_ELEMENT (LocalityPtr, i, j)
126 );
127 }
128 // Element[i][j] must be equal to Element[j][i]
129 if (SLIT_ELEMENT (LocalityPtr, i, j) !=
130 SLIT_ELEMENT (LocalityPtr, j, i)) {
131 IncrementErrorCount ();
132 Print (
133 L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) and \n"
134 "Element[0x%lx][0x%lx] (%3d) do not match.\n",
135 i,
136 j,
137 SLIT_ELEMENT (LocalityPtr, i, j),
138 j,
139 i,
140 SLIT_ELEMENT (LocalityPtr, j, i)
141 );
142 }
143 }
144 }
145 }