tbutils.c revision 1.25 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.4 christos * Module Name: tbutils - ACPI Table utilities
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.24 christos /******************************************************************************
8 1.24 christos *
9 1.24 christos * 1. Copyright Notice
10 1.24 christos *
11 1.25 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.24 christos * 2. License
15 1.24 christos *
16 1.24 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.24 christos * rights. You may have additional license terms from the party that provided
18 1.24 christos * you this software, covering your right to use that party's intellectual
19 1.24 christos * property rights.
20 1.24 christos *
21 1.24 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.24 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.24 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.24 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.24 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.24 christos * Code in any form, with the right to sublicense such rights; and
27 1.24 christos *
28 1.24 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.24 christos * license (with the right to sublicense), under only those claims of Intel
30 1.24 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.24 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.24 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.24 christos * license, and in no event shall the patent license extend to any additions
34 1.24 christos * to or modifications of the Original Intel Code. No other license or right
35 1.24 christos * is granted directly or by implication, estoppel or otherwise;
36 1.24 christos *
37 1.24 christos * The above copyright and patent license is granted only if the following
38 1.24 christos * conditions are met:
39 1.24 christos *
40 1.24 christos * 3. Conditions
41 1.24 christos *
42 1.24 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.24 christos * Redistribution of source code of any substantial portion of the Covered
44 1.24 christos * Code or modification with rights to further distribute source must include
45 1.24 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.24 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.24 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.24 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.24 christos * Code and the date of any change. Licensee must include in that file the
50 1.24 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.24 christos * must include a prominent statement that the modification is derived,
52 1.24 christos * directly or indirectly, from Original Intel Code.
53 1.24 christos *
54 1.24 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.24 christos * Redistribution of source code of any substantial portion of the Covered
56 1.24 christos * Code or modification without rights to further distribute source must
57 1.24 christos * include the following Disclaimer and Export Compliance provision in the
58 1.24 christos * documentation and/or other materials provided with distribution. In
59 1.24 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.24 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.24 christos * license from Licensee to its licensee is limited to the intellectual
62 1.24 christos * property embodied in the software Licensee provides to its licensee, and
63 1.24 christos * not to intellectual property embodied in modifications its licensee may
64 1.24 christos * make.
65 1.24 christos *
66 1.24 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.24 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.24 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.24 christos * provision in the documentation and/or other materials provided with the
70 1.24 christos * distribution.
71 1.24 christos *
72 1.24 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.24 christos * Intel Code.
74 1.24 christos *
75 1.24 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.24 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.24 christos * other dealings in products derived from or relating to the Covered Code
78 1.24 christos * without prior written authorization from Intel.
79 1.24 christos *
80 1.24 christos * 4. Disclaimer and Export Compliance
81 1.24 christos *
82 1.24 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.24 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.24 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.24 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.24 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.24 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.24 christos * PARTICULAR PURPOSE.
89 1.24 christos *
90 1.24 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.24 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.24 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.24 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.24 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.24 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.24 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.24 christos * LIMITED REMEDY.
98 1.24 christos *
99 1.24 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.24 christos * software or system incorporating such software without first obtaining any
101 1.24 christos * required license or other approval from the U. S. Department of Commerce or
102 1.24 christos * any other agency or department of the United States Government. In the
103 1.24 christos * event Licensee exports any such software from the United States or
104 1.24 christos * re-exports any such software from a foreign destination, Licensee shall
105 1.24 christos * ensure that the distribution and export/re-export of the software is in
106 1.24 christos * compliance with all laws, regulations, orders, or other restrictions of the
107 1.24 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.24 christos * any of its subsidiaries will export/re-export any technical data, process,
109 1.24 christos * software, or service, directly or indirectly, to any country for which the
110 1.24 christos * United States government or any agency thereof requires an export license,
111 1.24 christos * other governmental approval, or letter of assurance, without first obtaining
112 1.24 christos * such license, approval or letter.
113 1.24 christos *
114 1.24 christos *****************************************************************************
115 1.24 christos *
116 1.24 christos * Alternatively, you may choose to be licensed under the terms of the
117 1.24 christos * following license:
118 1.24 christos *
119 1.3 jruoho * Redistribution and use in source and binary forms, with or without
120 1.3 jruoho * modification, are permitted provided that the following conditions
121 1.3 jruoho * are met:
122 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
123 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
124 1.3 jruoho * without modification.
125 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
127 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
128 1.3 jruoho * including a substantially similar Disclaimer requirement for further
129 1.3 jruoho * binary redistribution.
130 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
131 1.3 jruoho * of any contributors may be used to endorse or promote products derived
132 1.3 jruoho * from this software without specific prior written permission.
133 1.3 jruoho *
134 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 1.18 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 1.24 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 1.24 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 1.24 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 1.24 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 1.24 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 1.24 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 1.24 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 1.24 christos *
146 1.24 christos * Alternatively, you may choose to be licensed under the terms of the
147 1.24 christos * GNU General Public License ("GPL") version 2 as published by the Free
148 1.24 christos * Software Foundation.
149 1.24 christos *
150 1.24 christos *****************************************************************************/
151 1.1 jruoho
152 1.1 jruoho #include "acpi.h"
153 1.1 jruoho #include "accommon.h"
154 1.1 jruoho #include "actables.h"
155 1.1 jruoho
156 1.1 jruoho #define _COMPONENT ACPI_TABLES
157 1.1 jruoho ACPI_MODULE_NAME ("tbutils")
158 1.1 jruoho
159 1.4 christos
160 1.1 jruoho /* Local prototypes */
161 1.1 jruoho
162 1.1 jruoho static ACPI_PHYSICAL_ADDRESS
163 1.1 jruoho AcpiTbGetRootTableEntry (
164 1.1 jruoho UINT8 *TableEntry,
165 1.1 jruoho UINT32 TableEntrySize);
166 1.1 jruoho
167 1.1 jruoho
168 1.24 christos #if (!ACPI_REDUCED_HARDWARE)
169 1.1 jruoho /*******************************************************************************
170 1.1 jruoho *
171 1.1 jruoho * FUNCTION: AcpiTbInitializeFacs
172 1.1 jruoho *
173 1.1 jruoho * PARAMETERS: None
174 1.1 jruoho *
175 1.1 jruoho * RETURN: Status
176 1.1 jruoho *
177 1.1 jruoho * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
178 1.1 jruoho * for accessing the Global Lock and Firmware Waking Vector
179 1.1 jruoho *
180 1.1 jruoho ******************************************************************************/
181 1.1 jruoho
182 1.1 jruoho ACPI_STATUS
183 1.1 jruoho AcpiTbInitializeFacs (
184 1.1 jruoho void)
185 1.1 jruoho {
186 1.9 christos ACPI_TABLE_FACS *Facs;
187 1.9 christos
188 1.24 christos
189 1.24 christos /* If Hardware Reduced flag is set, there is no FACS */
190 1.24 christos
191 1.24 christos if (AcpiGbl_ReducedHardware)
192 1.24 christos {
193 1.24 christos AcpiGbl_FACS = NULL;
194 1.24 christos return (AE_OK);
195 1.24 christos }
196 1.24 christos else if (AcpiGbl_FADT.XFacs &&
197 1.9 christos (!AcpiGbl_FADT.Facs || !AcpiGbl_Use32BitFacsAddresses))
198 1.8 christos {
199 1.9 christos (void) AcpiGetTableByIndex (AcpiGbl_XFacsIndex,
200 1.9 christos ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &Facs));
201 1.9 christos AcpiGbl_FACS = Facs;
202 1.9 christos }
203 1.9 christos else if (AcpiGbl_FADT.Facs)
204 1.9 christos {
205 1.9 christos (void) AcpiGetTableByIndex (AcpiGbl_FacsIndex,
206 1.9 christos ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &Facs));
207 1.9 christos AcpiGbl_FACS = Facs;
208 1.8 christos }
209 1.8 christos
210 1.8 christos /* If there is no FACS, just continue. There was already an error msg */
211 1.8 christos
212 1.8 christos return (AE_OK);
213 1.1 jruoho }
214 1.24 christos #endif /* !ACPI_REDUCED_HARDWARE */
215 1.1 jruoho
216 1.1 jruoho
217 1.1 jruoho /*******************************************************************************
218 1.1 jruoho *
219 1.1 jruoho * FUNCTION: AcpiTbCheckDsdtHeader
220 1.1 jruoho *
221 1.1 jruoho * PARAMETERS: None
222 1.1 jruoho *
223 1.1 jruoho * RETURN: None
224 1.1 jruoho *
225 1.1 jruoho * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
226 1.1 jruoho * if the DSDT has been replaced from outside the OS and/or if
227 1.1 jruoho * the DSDT header has been corrupted.
228 1.1 jruoho *
229 1.1 jruoho ******************************************************************************/
230 1.1 jruoho
231 1.1 jruoho void
232 1.1 jruoho AcpiTbCheckDsdtHeader (
233 1.1 jruoho void)
234 1.1 jruoho {
235 1.1 jruoho
236 1.1 jruoho /* Compare original length and checksum to current values */
237 1.1 jruoho
238 1.1 jruoho if (AcpiGbl_OriginalDsdtHeader.Length != AcpiGbl_DSDT->Length ||
239 1.1 jruoho AcpiGbl_OriginalDsdtHeader.Checksum != AcpiGbl_DSDT->Checksum)
240 1.1 jruoho {
241 1.4 christos ACPI_BIOS_ERROR ((AE_INFO,
242 1.4 christos "The DSDT has been corrupted or replaced - "
243 1.4 christos "old, new headers below"));
244 1.9 christos
245 1.1 jruoho AcpiTbPrintTableHeader (0, &AcpiGbl_OriginalDsdtHeader);
246 1.1 jruoho AcpiTbPrintTableHeader (0, AcpiGbl_DSDT);
247 1.1 jruoho
248 1.1 jruoho /* Disable further error messages */
249 1.1 jruoho
250 1.1 jruoho AcpiGbl_OriginalDsdtHeader.Length = AcpiGbl_DSDT->Length;
251 1.1 jruoho AcpiGbl_OriginalDsdtHeader.Checksum = AcpiGbl_DSDT->Checksum;
252 1.1 jruoho }
253 1.1 jruoho }
254 1.1 jruoho
255 1.1 jruoho
256 1.1 jruoho /*******************************************************************************
257 1.1 jruoho *
258 1.1 jruoho * FUNCTION: AcpiTbCopyDsdt
259 1.1 jruoho *
260 1.13 christos * PARAMETERS: TableIndex - Index of installed table to copy
261 1.1 jruoho *
262 1.13 christos * RETURN: The copied DSDT
263 1.1 jruoho *
264 1.1 jruoho * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
265 1.1 jruoho * Some very bad BIOSs are known to either corrupt the DSDT or
266 1.1 jruoho * install a new, bad DSDT. This copy works around the problem.
267 1.1 jruoho *
268 1.1 jruoho ******************************************************************************/
269 1.1 jruoho
270 1.1 jruoho ACPI_TABLE_HEADER *
271 1.1 jruoho AcpiTbCopyDsdt (
272 1.1 jruoho UINT32 TableIndex)
273 1.1 jruoho {
274 1.1 jruoho ACPI_TABLE_HEADER *NewTable;
275 1.1 jruoho ACPI_TABLE_DESC *TableDesc;
276 1.1 jruoho
277 1.1 jruoho
278 1.1 jruoho TableDesc = &AcpiGbl_RootTableList.Tables[TableIndex];
279 1.1 jruoho
280 1.1 jruoho NewTable = ACPI_ALLOCATE (TableDesc->Length);
281 1.1 jruoho if (!NewTable)
282 1.1 jruoho {
283 1.1 jruoho ACPI_ERROR ((AE_INFO, "Could not copy DSDT of length 0x%X",
284 1.1 jruoho TableDesc->Length));
285 1.1 jruoho return (NULL);
286 1.1 jruoho }
287 1.1 jruoho
288 1.8 christos memcpy (NewTable, TableDesc->Pointer, TableDesc->Length);
289 1.6 christos AcpiTbUninstallTable (TableDesc);
290 1.6 christos
291 1.6 christos AcpiTbInitTableDescriptor (
292 1.9 christos &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex],
293 1.9 christos ACPI_PTR_TO_PHYSADDR (NewTable),
294 1.9 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, NewTable);
295 1.1 jruoho
296 1.10 christos ACPI_INFO ((
297 1.1 jruoho "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
298 1.1 jruoho NewTable->Length));
299 1.1 jruoho
300 1.1 jruoho return (NewTable);
301 1.1 jruoho }
302 1.1 jruoho
303 1.1 jruoho
304 1.1 jruoho /*******************************************************************************
305 1.1 jruoho *
306 1.1 jruoho * FUNCTION: AcpiTbGetRootTableEntry
307 1.1 jruoho *
308 1.1 jruoho * PARAMETERS: TableEntry - Pointer to the RSDT/XSDT table entry
309 1.1 jruoho * TableEntrySize - sizeof 32 or 64 (RSDT or XSDT)
310 1.1 jruoho *
311 1.1 jruoho * RETURN: Physical address extracted from the root table
312 1.1 jruoho *
313 1.1 jruoho * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
314 1.1 jruoho * both 32-bit and 64-bit platforms
315 1.1 jruoho *
316 1.1 jruoho * NOTE: ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on
317 1.1 jruoho * 64-bit platforms.
318 1.1 jruoho *
319 1.1 jruoho ******************************************************************************/
320 1.1 jruoho
321 1.1 jruoho static ACPI_PHYSICAL_ADDRESS
322 1.1 jruoho AcpiTbGetRootTableEntry (
323 1.1 jruoho UINT8 *TableEntry,
324 1.1 jruoho UINT32 TableEntrySize)
325 1.1 jruoho {
326 1.22 christos UINT32 Address32;
327 1.1 jruoho UINT64 Address64;
328 1.1 jruoho
329 1.1 jruoho
330 1.1 jruoho /*
331 1.1 jruoho * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
332 1.1 jruoho * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
333 1.1 jruoho */
334 1.4 christos if (TableEntrySize == ACPI_RSDT_ENTRY_SIZE)
335 1.1 jruoho {
336 1.1 jruoho /*
337 1.1 jruoho * 32-bit platform, RSDT: Return 32-bit table entry
338 1.1 jruoho * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
339 1.1 jruoho */
340 1.22 christos ACPI_MOVE_32_TO_32(&Address32, TableEntry);
341 1.22 christos return Address32;
342 1.1 jruoho }
343 1.1 jruoho else
344 1.1 jruoho {
345 1.1 jruoho /*
346 1.1 jruoho * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
347 1.1 jruoho * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
348 1.1 jruoho * return 64-bit
349 1.1 jruoho */
350 1.1 jruoho ACPI_MOVE_64_TO_64 (&Address64, TableEntry);
351 1.1 jruoho
352 1.1 jruoho #if ACPI_MACHINE_WIDTH == 32
353 1.1 jruoho if (Address64 > ACPI_UINT32_MAX)
354 1.1 jruoho {
355 1.1 jruoho /* Will truncate 64-bit address to 32 bits, issue warning */
356 1.1 jruoho
357 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
358 1.1 jruoho "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
359 1.1 jruoho " truncating",
360 1.1 jruoho ACPI_FORMAT_UINT64 (Address64)));
361 1.1 jruoho }
362 1.1 jruoho #endif
363 1.1 jruoho return ((ACPI_PHYSICAL_ADDRESS) (Address64));
364 1.1 jruoho }
365 1.1 jruoho }
366 1.1 jruoho
367 1.1 jruoho
368 1.1 jruoho /*******************************************************************************
369 1.1 jruoho *
370 1.1 jruoho * FUNCTION: AcpiTbParseRootTable
371 1.1 jruoho *
372 1.13 christos * PARAMETERS: RsdpAddress - Pointer to the RSDP
373 1.1 jruoho *
374 1.1 jruoho * RETURN: Status
375 1.1 jruoho *
376 1.1 jruoho * DESCRIPTION: This function is called to parse the Root System Description
377 1.1 jruoho * Table (RSDT or XSDT)
378 1.1 jruoho *
379 1.1 jruoho * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
380 1.1 jruoho * be mapped and cannot be copied because it contains the actual
381 1.1 jruoho * memory location of the ACPI Global Lock.
382 1.1 jruoho *
383 1.1 jruoho ******************************************************************************/
384 1.1 jruoho
385 1.11 christos ACPI_STATUS ACPI_INIT_FUNCTION
386 1.1 jruoho AcpiTbParseRootTable (
387 1.1 jruoho ACPI_PHYSICAL_ADDRESS RsdpAddress)
388 1.1 jruoho {
389 1.1 jruoho ACPI_TABLE_RSDP *Rsdp;
390 1.1 jruoho UINT32 TableEntrySize;
391 1.1 jruoho UINT32 i;
392 1.1 jruoho UINT32 TableCount;
393 1.1 jruoho ACPI_TABLE_HEADER *Table;
394 1.1 jruoho ACPI_PHYSICAL_ADDRESS Address;
395 1.1 jruoho UINT32 Length;
396 1.1 jruoho UINT8 *TableEntry;
397 1.1 jruoho ACPI_STATUS Status;
398 1.6 christos UINT32 TableIndex;
399 1.1 jruoho
400 1.1 jruoho
401 1.1 jruoho ACPI_FUNCTION_TRACE (TbParseRootTable);
402 1.1 jruoho
403 1.1 jruoho
404 1.4 christos /* Map the entire RSDP and extract the address of the RSDT or XSDT */
405 1.4 christos
406 1.1 jruoho Rsdp = AcpiOsMapMemory (RsdpAddress, sizeof (ACPI_TABLE_RSDP));
407 1.1 jruoho if (!Rsdp)
408 1.1 jruoho {
409 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
410 1.1 jruoho }
411 1.1 jruoho
412 1.1 jruoho AcpiTbPrintTableHeader (RsdpAddress,
413 1.1 jruoho ACPI_CAST_PTR (ACPI_TABLE_HEADER, Rsdp));
414 1.1 jruoho
415 1.4 christos /* Use XSDT if present and not overridden. Otherwise, use RSDT */
416 1.1 jruoho
417 1.4 christos if ((Rsdp->Revision > 1) &&
418 1.4 christos Rsdp->XsdtPhysicalAddress &&
419 1.4 christos !AcpiGbl_DoNotUseXsdt)
420 1.1 jruoho {
421 1.1 jruoho /*
422 1.4 christos * RSDP contains an XSDT (64-bit physical addresses). We must use
423 1.4 christos * the XSDT if the revision is > 1 and the XSDT pointer is present,
424 1.4 christos * as per the ACPI specification.
425 1.1 jruoho */
426 1.1 jruoho Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->XsdtPhysicalAddress;
427 1.4 christos TableEntrySize = ACPI_XSDT_ENTRY_SIZE;
428 1.1 jruoho }
429 1.1 jruoho else
430 1.1 jruoho {
431 1.1 jruoho /* Root table is an RSDT (32-bit physical addresses) */
432 1.1 jruoho
433 1.1 jruoho Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->RsdtPhysicalAddress;
434 1.4 christos TableEntrySize = ACPI_RSDT_ENTRY_SIZE;
435 1.1 jruoho }
436 1.1 jruoho
437 1.1 jruoho /*
438 1.5 riastrad * It is not possible to map more than one entry in some environments,
439 1.5 riastrad * so unmap the RSDP here before mapping other tables
440 1.5 riastrad */
441 1.5 riastrad AcpiOsUnmapMemory (Rsdp, sizeof (ACPI_TABLE_RSDP));
442 1.5 riastrad
443 1.1 jruoho /* Map the RSDT/XSDT table header to get the full table length */
444 1.1 jruoho
445 1.1 jruoho Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
446 1.1 jruoho if (!Table)
447 1.1 jruoho {
448 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
449 1.1 jruoho }
450 1.1 jruoho
451 1.1 jruoho AcpiTbPrintTableHeader (Address, Table);
452 1.1 jruoho
453 1.4 christos /*
454 1.4 christos * Validate length of the table, and map entire table.
455 1.4 christos * Minimum length table must contain at least one entry.
456 1.4 christos */
457 1.1 jruoho Length = Table->Length;
458 1.1 jruoho AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
459 1.1 jruoho
460 1.4 christos if (Length < (sizeof (ACPI_TABLE_HEADER) + TableEntrySize))
461 1.1 jruoho {
462 1.4 christos ACPI_BIOS_ERROR ((AE_INFO,
463 1.4 christos "Invalid table length 0x%X in RSDT/XSDT", Length));
464 1.1 jruoho return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
465 1.1 jruoho }
466 1.1 jruoho
467 1.1 jruoho Table = AcpiOsMapMemory (Address, Length);
468 1.1 jruoho if (!Table)
469 1.1 jruoho {
470 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
471 1.1 jruoho }
472 1.1 jruoho
473 1.1 jruoho /* Validate the root table checksum */
474 1.1 jruoho
475 1.21 christos Status = AcpiUtVerifyChecksum (Table, Length);
476 1.1 jruoho if (ACPI_FAILURE (Status))
477 1.1 jruoho {
478 1.1 jruoho AcpiOsUnmapMemory (Table, Length);
479 1.1 jruoho return_ACPI_STATUS (Status);
480 1.1 jruoho }
481 1.1 jruoho
482 1.4 christos /* Get the number of entries and pointer to first entry */
483 1.1 jruoho
484 1.1 jruoho TableCount = (UINT32) ((Table->Length - sizeof (ACPI_TABLE_HEADER)) /
485 1.1 jruoho TableEntrySize);
486 1.4 christos TableEntry = ACPI_ADD_PTR (UINT8, Table, sizeof (ACPI_TABLE_HEADER));
487 1.1 jruoho
488 1.4 christos /* Initialize the root table array from the RSDT/XSDT */
489 1.4 christos
490 1.1 jruoho for (i = 0; i < TableCount; i++)
491 1.1 jruoho {
492 1.6 christos /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
493 1.6 christos
494 1.6 christos Address = AcpiTbGetRootTableEntry (TableEntry, TableEntrySize);
495 1.6 christos
496 1.6 christos /* Skip NULL entries in RSDT/XSDT */
497 1.6 christos
498 1.6 christos if (!Address)
499 1.1 jruoho {
500 1.6 christos goto NextTable;
501 1.6 christos }
502 1.6 christos
503 1.6 christos Status = AcpiTbInstallStandardTable (Address,
504 1.19 christos ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, TRUE,
505 1.19 christos &TableIndex);
506 1.1 jruoho
507 1.6 christos if (ACPI_SUCCESS (Status) &&
508 1.15 christos ACPI_COMPARE_NAMESEG (
509 1.9 christos &AcpiGbl_RootTableList.Tables[TableIndex].Signature,
510 1.6 christos ACPI_SIG_FADT))
511 1.6 christos {
512 1.9 christos AcpiGbl_FadtIndex = TableIndex;
513 1.9 christos AcpiTbParseFadt ();
514 1.1 jruoho }
515 1.1 jruoho
516 1.6 christos NextTable:
517 1.1 jruoho
518 1.1 jruoho TableEntry += TableEntrySize;
519 1.1 jruoho }
520 1.1 jruoho
521 1.1 jruoho AcpiOsUnmapMemory (Table, Length);
522 1.9 christos return_ACPI_STATUS (AE_OK);
523 1.9 christos }
524 1.12 christos
525 1.12 christos
526 1.12 christos /*******************************************************************************
527 1.12 christos *
528 1.12 christos * FUNCTION: AcpiTbGetTable
529 1.12 christos *
530 1.12 christos * PARAMETERS: TableDesc - Table descriptor
531 1.12 christos * OutTable - Where the pointer to the table is returned
532 1.12 christos *
533 1.12 christos * RETURN: Status and pointer to the requested table
534 1.12 christos *
535 1.12 christos * DESCRIPTION: Increase a reference to a table descriptor and return the
536 1.12 christos * validated table pointer.
537 1.12 christos * If the table descriptor is an entry of the root table list,
538 1.12 christos * this API must be invoked with ACPI_MTX_TABLES acquired.
539 1.12 christos *
540 1.12 christos ******************************************************************************/
541 1.12 christos
542 1.12 christos ACPI_STATUS
543 1.12 christos AcpiTbGetTable (
544 1.12 christos ACPI_TABLE_DESC *TableDesc,
545 1.12 christos ACPI_TABLE_HEADER **OutTable)
546 1.12 christos {
547 1.12 christos ACPI_STATUS Status;
548 1.12 christos
549 1.12 christos
550 1.12 christos ACPI_FUNCTION_TRACE (AcpiTbGetTable);
551 1.12 christos
552 1.12 christos
553 1.12 christos if (TableDesc->ValidationCount == 0)
554 1.12 christos {
555 1.12 christos /* Table need to be "VALIDATED" */
556 1.12 christos
557 1.12 christos Status = AcpiTbValidateTable (TableDesc);
558 1.12 christos if (ACPI_FAILURE (Status))
559 1.12 christos {
560 1.12 christos return_ACPI_STATUS (Status);
561 1.12 christos }
562 1.12 christos }
563 1.12 christos
564 1.13 christos if (TableDesc->ValidationCount < ACPI_MAX_TABLE_VALIDATIONS)
565 1.12 christos {
566 1.13 christos TableDesc->ValidationCount++;
567 1.13 christos
568 1.13 christos /*
569 1.13 christos * Detect ValidationCount overflows to ensure that the warning
570 1.13 christos * message will only be printed once.
571 1.13 christos */
572 1.13 christos if (TableDesc->ValidationCount >= ACPI_MAX_TABLE_VALIDATIONS)
573 1.13 christos {
574 1.13 christos ACPI_WARNING((AE_INFO,
575 1.13 christos "Table %p, Validation count overflows\n", TableDesc));
576 1.13 christos }
577 1.12 christos }
578 1.12 christos
579 1.12 christos *OutTable = TableDesc->Pointer;
580 1.12 christos return_ACPI_STATUS (AE_OK);
581 1.12 christos }
582 1.12 christos
583 1.12 christos
584 1.12 christos /*******************************************************************************
585 1.12 christos *
586 1.12 christos * FUNCTION: AcpiTbPutTable
587 1.12 christos *
588 1.12 christos * PARAMETERS: TableDesc - Table descriptor
589 1.12 christos *
590 1.12 christos * RETURN: None
591 1.12 christos *
592 1.12 christos * DESCRIPTION: Decrease a reference to a table descriptor and release the
593 1.12 christos * validated table pointer if no references.
594 1.12 christos * If the table descriptor is an entry of the root table list,
595 1.12 christos * this API must be invoked with ACPI_MTX_TABLES acquired.
596 1.12 christos *
597 1.12 christos ******************************************************************************/
598 1.12 christos
599 1.12 christos void
600 1.12 christos AcpiTbPutTable (
601 1.12 christos ACPI_TABLE_DESC *TableDesc)
602 1.12 christos {
603 1.12 christos
604 1.12 christos ACPI_FUNCTION_TRACE (AcpiTbPutTable);
605 1.12 christos
606 1.12 christos
607 1.13 christos if (TableDesc->ValidationCount < ACPI_MAX_TABLE_VALIDATIONS)
608 1.12 christos {
609 1.13 christos TableDesc->ValidationCount--;
610 1.13 christos
611 1.13 christos /*
612 1.13 christos * Detect ValidationCount underflows to ensure that the warning
613 1.13 christos * message will only be printed once.
614 1.13 christos */
615 1.13 christos if (TableDesc->ValidationCount >= ACPI_MAX_TABLE_VALIDATIONS)
616 1.13 christos {
617 1.13 christos ACPI_WARNING ((AE_INFO,
618 1.13 christos "Table %p, Validation count underflows\n", TableDesc));
619 1.13 christos return_VOID;
620 1.13 christos }
621 1.12 christos }
622 1.12 christos
623 1.12 christos if (TableDesc->ValidationCount == 0)
624 1.12 christos {
625 1.12 christos /* Table need to be "INVALIDATED" */
626 1.12 christos
627 1.12 christos AcpiTbInvalidateTable (TableDesc);
628 1.12 christos }
629 1.12 christos
630 1.12 christos return_VOID;
631 1.12 christos }
632