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