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