]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
ShellPkg/UefiShellAcpiViewCommandLib: Fix ECC issues
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Rsdp / RsdpParser.c
CommitLineData
a6eaba4d 1/** @file\r
ee4dc24f
RN
2 RSDP 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 <Library/UefiLib.h>\r
18#include "AcpiParser.h"\r
19#include "AcpiTableParser.h"\r
20\r
21// Local Variables\r
22STATIC CONST UINT64* XsdtAddress;\r
23\r
a6eaba4d
DB
24/**\r
25 This function validates the RSDT Address.\r
ee4dc24f
RN
26\r
27 @param [in] Ptr Pointer to the start of the field data.\r
28 @param [in] Context Pointer to context specific information e.g. this\r
29 could be a pointer to the ACPI table header.\r
a6eaba4d 30**/\r
ee4dc24f
RN
31STATIC\r
32VOID\r
33EFIAPI\r
34ValidateRsdtAddress (\r
35 IN UINT8* Ptr,\r
36 IN VOID* Context\r
37 );\r
38\r
a6eaba4d
DB
39/**\r
40 This function validates the XSDT Address.\r
ee4dc24f
RN
41\r
42 @param [in] Ptr Pointer to the start of the field data.\r
43 @param [in] Context Pointer to context specific information e.g. this\r
44 could be a pointer to the ACPI table header.\r
a6eaba4d 45**/\r
ee4dc24f
RN
46STATIC\r
47VOID\r
48EFIAPI\r
49ValidateXsdtAddress (\r
50 IN UINT8* Ptr,\r
51 IN VOID* Context\r
52 );\r
53\r
a6eaba4d
DB
54/**\r
55 An array describing the ACPI RSDP Table.\r
56**/\r
ee4dc24f
RN
57STATIC CONST ACPI_PARSER RsdpParser[] = {\r
58 {L"Signature", 8, 0, NULL, Dump8Chars, NULL, NULL, NULL},\r
59 {L"Checksum", 1, 8, L"0x%x", NULL, NULL, NULL, NULL},\r
60 {L"Oem ID", 6, 9, NULL, Dump6Chars, NULL, NULL, NULL},\r
61 {L"Revision", 1, 15, L"%d", NULL, NULL, NULL, NULL},\r
62 {L"RSDT Address", 4, 16, L"0x%x", NULL, NULL, ValidateRsdtAddress, NULL},\r
63 {L"Length", 4, 20, L"%d", NULL, NULL, NULL, NULL},\r
64 {L"XSDT Address", 8, 24, L"0x%lx", NULL, (VOID**)&XsdtAddress,\r
65 ValidateXsdtAddress, NULL},\r
66 {L"Extended Checksum", 1, 32, L"0x%x", NULL, NULL, NULL, NULL},\r
67 {L"Reserved", 3, 33, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}\r
68};\r
69\r
a6eaba4d
DB
70/**\r
71 This function validates the RSDT Address.\r
ee4dc24f
RN
72\r
73 @param [in] Ptr Pointer to the start of the field data.\r
74 @param [in] Context Pointer to context specific information e.g. this\r
75 could be a pointer to the ACPI table header.\r
a6eaba4d 76**/\r
ee4dc24f
RN
77STATIC\r
78VOID\r
79EFIAPI\r
80ValidateRsdtAddress (\r
81 IN UINT8* Ptr,\r
82 IN VOID* Context\r
83 )\r
84{\r
85#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)\r
86 // Reference: Server Base Boot Requirements System Software on ARM Platforms\r
87 // Section: 4.2.1.1 RSDP\r
88 // Root System Description Pointer (RSDP), ACPI ? 5.2.5.\r
89 // - Within the RSDP, the RsdtAddress field must be null (zero) and the\r
90 // XsdtAddresss MUST be a valid, non-null, 64-bit value.\r
91 UINT32 RsdtAddr = *(UINT32*)Ptr;\r
92 if (RsdtAddr != 0) {\r
93 IncrementErrorCount ();\r
94 Print (\r
95 L"\nERROR: Rsdt Address = 0x%p. This must be NULL on ARM Platforms.",\r
96 RsdtAddr\r
97 );\r
98 }\r
99#endif\r
100}\r
101\r
a6eaba4d
DB
102/**\r
103 This function validates the XSDT Address.\r
ee4dc24f
RN
104\r
105 @param [in] Ptr Pointer to the start of the field data.\r
106 @param [in] Context Pointer to context specific information e.g. this\r
107 could be a pointer to the ACPI table header.\r
a6eaba4d 108**/\r
ee4dc24f
RN
109STATIC\r
110VOID\r
111EFIAPI\r
112ValidateXsdtAddress (\r
113 IN UINT8* Ptr,\r
114 IN VOID* Context\r
115 )\r
116{\r
117#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)\r
118 // Reference: Server Base Boot Requirements System Software on ARM Platforms\r
119 // Section: 4.2.1.1 RSDP\r
120 // Root System Description Pointer (RSDP), ACPI ? 5.2.5.\r
121 // - Within the RSDP, the RsdtAddress field must be null (zero) and the\r
122 // XsdtAddresss MUST be a valid, non-null, 64-bit value.\r
123 UINT64 XsdtAddr = *(UINT64*)Ptr;\r
124 if (XsdtAddr == 0) {\r
125 IncrementErrorCount ();\r
126 Print (\r
127 L"\nERROR: Xsdt Address = 0x%p. This must not be NULL on ARM Platforms.",\r
128 XsdtAddr\r
129 );\r
130 }\r
131#endif\r
132}\r
133\r
a6eaba4d
DB
134/**\r
135 This function parses the ACPI RSDP table.\r
ee4dc24f
RN
136\r
137 This function invokes the parser for the XSDT table.\r
138 * Note - This function does not support parsing of RSDT table.\r
139\r
140 This function also performs a RAW dump of the ACPI table and\r
141 validates the checksum.\r
142\r
143 @param [in] Trace If TRUE, trace the ACPI fields.\r
144 @param [in] Ptr Pointer to the start of the buffer.\r
145 @param [in] AcpiTableLength Length of the ACPI table.\r
146 @param [in] AcpiTableRevision Revision of the ACPI table.\r
a6eaba4d 147**/\r
ee4dc24f
RN
148VOID\r
149EFIAPI\r
150ParseAcpiRsdp (\r
151 IN BOOLEAN Trace,\r
152 IN UINT8* Ptr,\r
153 IN UINT32 AcpiTableLength,\r
154 IN UINT8 AcpiTableRevision\r
155 )\r
156{\r
157 if (Trace) {\r
158 DumpRaw (Ptr, AcpiTableLength);\r
159 VerifyChecksum (TRUE, Ptr, AcpiTableLength);\r
160 }\r
161\r
162 ParseAcpi (Trace, 0, "RSDP", Ptr, AcpiTableLength, PARSER_PARAMS (RsdpParser));\r
163\r
164 // This code currently supports parsing of XSDT table only\r
165 // and does not parse the RSDT table. Platforms provide the\r
166 // RSDT to enable compatibility with ACPI 1.0 operating systems.\r
167 // Therefore the RSDT should not be used on ARM platforms.\r
168 if ((*XsdtAddress) == 0) {\r
169 IncrementErrorCount ();\r
170 Print (L"ERROR: XSDT Pointer is not set.\n");\r
171 return;\r
172 }\r
173\r
174 ProcessAcpiTable ((UINT8*)(UINTN)(*XsdtAddress));\r
175}\r