tbxfroot.c revision 1.3.2.2 1 1.3.2.2 bouyer /******************************************************************************
2 1.3.2.2 bouyer *
3 1.3.2.2 bouyer * Module Name: tbxfroot - Find the root ACPI table (RSDT)
4 1.3.2.2 bouyer *
5 1.3.2.2 bouyer *****************************************************************************/
6 1.3.2.2 bouyer
7 1.3.2.2 bouyer /*
8 1.3.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.3.2.2 bouyer * All rights reserved.
10 1.3.2.2 bouyer *
11 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.3.2.2 bouyer * are met:
14 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.3.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.3.2.2 bouyer * without modification.
17 1.3.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.3.2.2 bouyer * binary redistribution.
22 1.3.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.3.2.2 bouyer * from this software without specific prior written permission.
25 1.3.2.2 bouyer *
26 1.3.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.3.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3.2.2 bouyer * Software Foundation.
29 1.3.2.2 bouyer *
30 1.3.2.2 bouyer * NO WARRANTY
31 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.3.2.2 bouyer */
43 1.3.2.2 bouyer
44 1.3.2.2 bouyer #define __TBXFROOT_C__
45 1.3.2.2 bouyer
46 1.3.2.2 bouyer #include "acpi.h"
47 1.3.2.2 bouyer #include "accommon.h"
48 1.3.2.2 bouyer #include "actables.h"
49 1.3.2.2 bouyer
50 1.3.2.2 bouyer
51 1.3.2.2 bouyer #define _COMPONENT ACPI_TABLES
52 1.3.2.2 bouyer ACPI_MODULE_NAME ("tbxfroot")
53 1.3.2.2 bouyer
54 1.3.2.2 bouyer /* Local prototypes */
55 1.3.2.2 bouyer
56 1.3.2.2 bouyer static UINT8 *
57 1.3.2.2 bouyer AcpiTbScanMemoryForRsdp (
58 1.3.2.2 bouyer UINT8 *StartAddress,
59 1.3.2.2 bouyer UINT32 Length);
60 1.3.2.2 bouyer
61 1.3.2.2 bouyer static ACPI_STATUS
62 1.3.2.2 bouyer AcpiTbValidateRsdp (
63 1.3.2.2 bouyer ACPI_TABLE_RSDP *Rsdp);
64 1.3.2.2 bouyer
65 1.3.2.2 bouyer
66 1.3.2.2 bouyer /*******************************************************************************
67 1.3.2.2 bouyer *
68 1.3.2.2 bouyer * FUNCTION: AcpiTbValidateRsdp
69 1.3.2.2 bouyer *
70 1.3.2.2 bouyer * PARAMETERS: Rsdp - Pointer to unvalidated RSDP
71 1.3.2.2 bouyer *
72 1.3.2.2 bouyer * RETURN: Status
73 1.3.2.2 bouyer *
74 1.3.2.2 bouyer * DESCRIPTION: Validate the RSDP (ptr)
75 1.3.2.2 bouyer *
76 1.3.2.2 bouyer ******************************************************************************/
77 1.3.2.2 bouyer
78 1.3.2.2 bouyer static ACPI_STATUS
79 1.3.2.2 bouyer AcpiTbValidateRsdp (
80 1.3.2.2 bouyer ACPI_TABLE_RSDP *Rsdp)
81 1.3.2.2 bouyer {
82 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
83 1.3.2.2 bouyer
84 1.3.2.2 bouyer
85 1.3.2.2 bouyer /*
86 1.3.2.2 bouyer * The signature and checksum must both be correct
87 1.3.2.2 bouyer *
88 1.3.2.2 bouyer * Note: Sometimes there exists more than one RSDP in memory; the valid
89 1.3.2.2 bouyer * RSDP has a valid checksum, all others have an invalid checksum.
90 1.3.2.2 bouyer */
91 1.3.2.2 bouyer if (ACPI_STRNCMP ((char *) Rsdp, ACPI_SIG_RSDP,
92 1.3.2.2 bouyer sizeof (ACPI_SIG_RSDP)-1) != 0)
93 1.3.2.2 bouyer {
94 1.3.2.2 bouyer /* Nope, BAD Signature */
95 1.3.2.2 bouyer
96 1.3.2.2 bouyer return (AE_BAD_SIGNATURE);
97 1.3.2.2 bouyer }
98 1.3.2.2 bouyer
99 1.3.2.2 bouyer /* Check the standard checksum */
100 1.3.2.2 bouyer
101 1.3.2.2 bouyer if (AcpiTbChecksum ((UINT8 *) Rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
102 1.3.2.2 bouyer {
103 1.3.2.2 bouyer return (AE_BAD_CHECKSUM);
104 1.3.2.2 bouyer }
105 1.3.2.2 bouyer
106 1.3.2.2 bouyer /* Check extended checksum if table version >= 2 */
107 1.3.2.2 bouyer
108 1.3.2.2 bouyer if ((Rsdp->Revision >= 2) &&
109 1.3.2.2 bouyer (AcpiTbChecksum ((UINT8 *) Rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0))
110 1.3.2.2 bouyer {
111 1.3.2.2 bouyer return (AE_BAD_CHECKSUM);
112 1.3.2.2 bouyer }
113 1.3.2.2 bouyer
114 1.3.2.2 bouyer return (AE_OK);
115 1.3.2.2 bouyer }
116 1.3.2.2 bouyer
117 1.3.2.2 bouyer
118 1.3.2.2 bouyer /*******************************************************************************
119 1.3.2.2 bouyer *
120 1.3.2.2 bouyer * FUNCTION: AcpiFindRootPointer
121 1.3.2.2 bouyer *
122 1.3.2.2 bouyer * PARAMETERS: TableAddress - Where the table pointer is returned
123 1.3.2.2 bouyer *
124 1.3.2.2 bouyer * RETURN: Status, RSDP physical address
125 1.3.2.2 bouyer *
126 1.3.2.2 bouyer * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
127 1.3.2.2 bouyer * pointer structure. If it is found, set *RSDP to point to it.
128 1.3.2.2 bouyer *
129 1.3.2.2 bouyer * NOTE1: The RSDP must be either in the first 1K of the Extended
130 1.3.2.2 bouyer * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
131 1.3.2.2 bouyer * Only a 32-bit physical address is necessary.
132 1.3.2.2 bouyer *
133 1.3.2.2 bouyer * NOTE2: This function is always available, regardless of the
134 1.3.2.2 bouyer * initialization state of the rest of ACPI.
135 1.3.2.2 bouyer *
136 1.3.2.2 bouyer ******************************************************************************/
137 1.3.2.2 bouyer
138 1.3.2.2 bouyer ACPI_STATUS
139 1.3.2.2 bouyer AcpiFindRootPointer (
140 1.3.2.2 bouyer ACPI_SIZE *TableAddress)
141 1.3.2.2 bouyer {
142 1.3.2.2 bouyer UINT8 *TablePtr;
143 1.3.2.2 bouyer UINT8 *MemRover;
144 1.3.2.2 bouyer UINT32 PhysicalAddress;
145 1.3.2.2 bouyer
146 1.3.2.2 bouyer
147 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiFindRootPointer);
148 1.3.2.2 bouyer
149 1.3.2.2 bouyer
150 1.3.2.2 bouyer /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
151 1.3.2.2 bouyer
152 1.3.2.2 bouyer TablePtr = AcpiOsMapMemory (
153 1.3.2.2 bouyer (ACPI_PHYSICAL_ADDRESS) ACPI_EBDA_PTR_LOCATION,
154 1.3.2.2 bouyer ACPI_EBDA_PTR_LENGTH);
155 1.3.2.2 bouyer if (!TablePtr)
156 1.3.2.2 bouyer {
157 1.3.2.2 bouyer ACPI_ERROR ((AE_INFO,
158 1.3.2.2 bouyer "Could not map memory at 0x%8.8X for length %u",
159 1.3.2.2 bouyer ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
160 1.3.2.2 bouyer
161 1.3.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
162 1.3.2.2 bouyer }
163 1.3.2.2 bouyer
164 1.3.2.2 bouyer ACPI_MOVE_16_TO_32 (&PhysicalAddress, TablePtr);
165 1.3.2.2 bouyer
166 1.3.2.2 bouyer /* Convert segment part to physical address */
167 1.3.2.2 bouyer
168 1.3.2.2 bouyer PhysicalAddress <<= 4;
169 1.3.2.2 bouyer AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_PTR_LENGTH);
170 1.3.2.2 bouyer
171 1.3.2.2 bouyer /* EBDA present? */
172 1.3.2.2 bouyer
173 1.3.2.2 bouyer if (PhysicalAddress > 0x400)
174 1.3.2.2 bouyer {
175 1.3.2.2 bouyer /*
176 1.3.2.2 bouyer * 1b) Search EBDA paragraphs (EBDA is required to be a
177 1.3.2.2 bouyer * minimum of 1K length)
178 1.3.2.2 bouyer */
179 1.3.2.2 bouyer TablePtr = AcpiOsMapMemory (
180 1.3.2.2 bouyer (ACPI_PHYSICAL_ADDRESS) PhysicalAddress,
181 1.3.2.2 bouyer ACPI_EBDA_WINDOW_SIZE);
182 1.3.2.2 bouyer if (!TablePtr)
183 1.3.2.2 bouyer {
184 1.3.2.2 bouyer ACPI_ERROR ((AE_INFO,
185 1.3.2.2 bouyer "Could not map memory at 0x%8.8X for length %u",
186 1.3.2.2 bouyer PhysicalAddress, ACPI_EBDA_WINDOW_SIZE));
187 1.3.2.2 bouyer
188 1.3.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
189 1.3.2.2 bouyer }
190 1.3.2.2 bouyer
191 1.3.2.2 bouyer MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_EBDA_WINDOW_SIZE);
192 1.3.2.2 bouyer AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_WINDOW_SIZE);
193 1.3.2.2 bouyer
194 1.3.2.2 bouyer if (MemRover)
195 1.3.2.2 bouyer {
196 1.3.2.2 bouyer /* Return the physical address */
197 1.3.2.2 bouyer
198 1.3.2.2 bouyer PhysicalAddress += (UINT32) ACPI_PTR_DIFF (MemRover, TablePtr);
199 1.3.2.2 bouyer
200 1.3.2.2 bouyer *TableAddress = PhysicalAddress;
201 1.3.2.2 bouyer return_ACPI_STATUS (AE_OK);
202 1.3.2.2 bouyer }
203 1.3.2.2 bouyer }
204 1.3.2.2 bouyer
205 1.3.2.2 bouyer /*
206 1.3.2.2 bouyer * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
207 1.3.2.2 bouyer */
208 1.3.2.2 bouyer TablePtr = AcpiOsMapMemory (
209 1.3.2.2 bouyer (ACPI_PHYSICAL_ADDRESS) ACPI_HI_RSDP_WINDOW_BASE,
210 1.3.2.2 bouyer ACPI_HI_RSDP_WINDOW_SIZE);
211 1.3.2.2 bouyer
212 1.3.2.2 bouyer if (!TablePtr)
213 1.3.2.2 bouyer {
214 1.3.2.2 bouyer ACPI_ERROR ((AE_INFO,
215 1.3.2.2 bouyer "Could not map memory at 0x%8.8X for length %u",
216 1.3.2.2 bouyer ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
217 1.3.2.2 bouyer
218 1.3.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
219 1.3.2.2 bouyer }
220 1.3.2.2 bouyer
221 1.3.2.2 bouyer MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
222 1.3.2.2 bouyer AcpiOsUnmapMemory (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
223 1.3.2.2 bouyer
224 1.3.2.2 bouyer if (MemRover)
225 1.3.2.2 bouyer {
226 1.3.2.2 bouyer /* Return the physical address */
227 1.3.2.2 bouyer
228 1.3.2.2 bouyer PhysicalAddress = (UINT32)
229 1.3.2.2 bouyer (ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (MemRover, TablePtr));
230 1.3.2.2 bouyer
231 1.3.2.2 bouyer *TableAddress = PhysicalAddress;
232 1.3.2.2 bouyer return_ACPI_STATUS (AE_OK);
233 1.3.2.2 bouyer }
234 1.3.2.2 bouyer
235 1.3.2.2 bouyer /* A valid RSDP was not found */
236 1.3.2.2 bouyer
237 1.3.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "A valid RSDP was not found"));
238 1.3.2.2 bouyer return_ACPI_STATUS (AE_NOT_FOUND);
239 1.3.2.2 bouyer }
240 1.3.2.2 bouyer
241 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiFindRootPointer)
242 1.3.2.2 bouyer
243 1.3.2.2 bouyer
244 1.3.2.2 bouyer /*******************************************************************************
245 1.3.2.2 bouyer *
246 1.3.2.2 bouyer * FUNCTION: AcpiTbScanMemoryForRsdp
247 1.3.2.2 bouyer *
248 1.3.2.2 bouyer * PARAMETERS: StartAddress - Starting pointer for search
249 1.3.2.2 bouyer * Length - Maximum length to search
250 1.3.2.2 bouyer *
251 1.3.2.2 bouyer * RETURN: Pointer to the RSDP if found, otherwise NULL.
252 1.3.2.2 bouyer *
253 1.3.2.2 bouyer * DESCRIPTION: Search a block of memory for the RSDP signature
254 1.3.2.2 bouyer *
255 1.3.2.2 bouyer ******************************************************************************/
256 1.3.2.2 bouyer
257 1.3.2.2 bouyer static UINT8 *
258 1.3.2.2 bouyer AcpiTbScanMemoryForRsdp (
259 1.3.2.2 bouyer UINT8 *StartAddress,
260 1.3.2.2 bouyer UINT32 Length)
261 1.3.2.2 bouyer {
262 1.3.2.2 bouyer ACPI_STATUS Status;
263 1.3.2.2 bouyer UINT8 *MemRover;
264 1.3.2.2 bouyer UINT8 *EndAddress;
265 1.3.2.2 bouyer
266 1.3.2.2 bouyer
267 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (TbScanMemoryForRsdp);
268 1.3.2.2 bouyer
269 1.3.2.2 bouyer
270 1.3.2.2 bouyer EndAddress = StartAddress + Length;
271 1.3.2.2 bouyer
272 1.3.2.2 bouyer /* Search from given start address for the requested length */
273 1.3.2.2 bouyer
274 1.3.2.2 bouyer for (MemRover = StartAddress; MemRover < EndAddress;
275 1.3.2.2 bouyer MemRover += ACPI_RSDP_SCAN_STEP)
276 1.3.2.2 bouyer {
277 1.3.2.2 bouyer /* The RSDP signature and checksum must both be correct */
278 1.3.2.2 bouyer
279 1.3.2.2 bouyer Status = AcpiTbValidateRsdp (ACPI_CAST_PTR (ACPI_TABLE_RSDP, MemRover));
280 1.3.2.2 bouyer if (ACPI_SUCCESS (Status))
281 1.3.2.2 bouyer {
282 1.3.2.2 bouyer /* Sig and checksum valid, we have found a real RSDP */
283 1.3.2.2 bouyer
284 1.3.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
285 1.3.2.2 bouyer "RSDP located at physical address %p\n", MemRover));
286 1.3.2.2 bouyer return_PTR (MemRover);
287 1.3.2.2 bouyer }
288 1.3.2.2 bouyer
289 1.3.2.2 bouyer /* No sig match or bad checksum, keep searching */
290 1.3.2.2 bouyer }
291 1.3.2.2 bouyer
292 1.3.2.2 bouyer /* Searched entire block, no RSDP was found */
293 1.3.2.2 bouyer
294 1.3.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
295 1.3.2.2 bouyer "Searched entire block from %p, valid RSDP was not found\n",
296 1.3.2.2 bouyer StartAddress));
297 1.3.2.2 bouyer return_PTR (NULL);
298 1.3.2.2 bouyer }
299 1.3.2.2 bouyer
300