]> 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 = *(UINT32*)Ptr;
92 if (RsdtAddr != 0) {
93 IncrementErrorCount ();
94 Print (
95 L"\nERROR: Rsdt Address = 0x%p. This must be NULL on ARM Platforms.",
96 RsdtAddr
97 );
98 }
99 #endif
100 }
101
102 /**
103 This function validates the XSDT Address.
104
105 @param [in] Ptr Pointer to the start of the field data.
106 @param [in] Context Pointer to context specific information e.g. this
107 could be a pointer to the ACPI table header.
108 **/
109 STATIC
110 VOID
111 EFIAPI
112 ValidateXsdtAddress (
113 IN UINT8* Ptr,
114 IN VOID* Context
115 )
116 {
117 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
118 // Reference: Server Base Boot Requirements System Software on ARM Platforms
119 // Section: 4.2.1.1 RSDP
120 // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
121 // - Within the RSDP, the RsdtAddress field must be null (zero) and the
122 // XsdtAddresss MUST be a valid, non-null, 64-bit value.
123 UINT64 XsdtAddr = *(UINT64*)Ptr;
124 if (XsdtAddr == 0) {
125 IncrementErrorCount ();
126 Print (
127 L"\nERROR: Xsdt Address = 0x%p. This must not be NULL on ARM Platforms.",
128 XsdtAddr
129 );
130 }
131 #endif
132 }
133
134 /**
135 This function parses the ACPI RSDP table.
136
137 This function invokes the parser for the XSDT table.
138 * Note - This function does not support parsing of RSDT table.
139
140 This function also performs a RAW dump of the ACPI table and
141 validates the checksum.
142
143 @param [in] Trace If TRUE, trace the ACPI fields.
144 @param [in] Ptr Pointer to the start of the buffer.
145 @param [in] AcpiTableLength Length of the ACPI table.
146 @param [in] AcpiTableRevision Revision of the ACPI table.
147 **/
148 VOID
149 EFIAPI
150 ParseAcpiRsdp (
151 IN BOOLEAN Trace,
152 IN UINT8* Ptr,
153 IN UINT32 AcpiTableLength,
154 IN UINT8 AcpiTableRevision
155 )
156 {
157 if (Trace) {
158 DumpRaw (Ptr, AcpiTableLength);
159 VerifyChecksum (TRUE, Ptr, AcpiTableLength);
160 }
161
162 ParseAcpi (Trace, 0, "RSDP", Ptr, AcpiTableLength, PARSER_PARAMS (RsdpParser));
163
164 // This code currently supports parsing of XSDT table only
165 // and does not parse the RSDT table. Platforms provide the
166 // RSDT to enable compatibility with ACPI 1.0 operating systems.
167 // Therefore the RSDT should not be used on ARM platforms.
168 if ((*XsdtAddress) == 0) {
169 IncrementErrorCount ();
170 Print (L"ERROR: XSDT Pointer is not set.\n");
171 return;
172 }
173
174 ProcessAcpiTable ((UINT8*)(UINTN)(*XsdtAddress));
175 }