1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
118 #define __TBXFACE_C__
121 #include "acnamesp.h"
122 #include "actables.h"
124 #define _COMPONENT ACPI_TABLES
125 ACPI_MODULE_NAME ("tbxface")
127 /* Local prototypes */
130 AcpiTbLoadNamespace (
134 /*******************************************************************************
136 * FUNCTION: AcpiAllocateRootTable
138 * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
139 * ACPI_TABLE_DESC structures
143 * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
144 * AcpiInitializeTables.
146 ******************************************************************************/
149 AcpiAllocateRootTable (
150 UINT32 InitialTableCount
)
153 AcpiGbl_RootTableList
.Size
= InitialTableCount
;
154 AcpiGbl_RootTableList
.Flags
= ACPI_ROOT_ALLOW_RESIZE
;
156 return (AcpiTbResizeRootTableList ());
160 /*******************************************************************************
162 * FUNCTION: AcpiInitializeTables
164 * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
165 * ACPI_TABLE_DESC structures. If NULL, the
166 * array is dynamically allocated.
167 * InitialTableCount - Size of InitialTableArray, in number of
168 * ACPI_TABLE_DESC structures
169 * AllowRealloc - Flag to tell Table Manager if resize of
170 * pre-allocated array is allowed. Ignored
171 * if InitialTableArray is NULL.
175 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
177 * NOTE: Allows static allocation of the initial table array in order
178 * to avoid the use of dynamic memory in confined environments
179 * such as the kernel boot sequence where it may not be available.
181 * If the host OS memory managers are initialized, use NULL for
182 * InitialTableArray, and the table will be dynamically allocated.
184 ******************************************************************************/
187 AcpiInitializeTables (
188 ACPI_TABLE_DESC
*InitialTableArray
,
189 UINT32 InitialTableCount
,
192 ACPI_PHYSICAL_ADDRESS RsdpAddress
;
196 ACPI_FUNCTION_TRACE (AcpiInitializeTables
);
200 * Set up the Root Table Array
201 * Allocate the table array if requested
203 if (!InitialTableArray
)
205 Status
= AcpiAllocateRootTable (InitialTableCount
);
206 if (ACPI_FAILURE (Status
))
208 return_ACPI_STATUS (Status
);
213 /* Root Table Array has been statically allocated by the host */
215 ACPI_MEMSET (InitialTableArray
, 0,
216 InitialTableCount
* sizeof (ACPI_TABLE_DESC
));
218 AcpiGbl_RootTableList
.Tables
= InitialTableArray
;
219 AcpiGbl_RootTableList
.Size
= InitialTableCount
;
220 AcpiGbl_RootTableList
.Flags
= ACPI_ROOT_ORIGIN_UNKNOWN
;
223 AcpiGbl_RootTableList
.Flags
|= ACPI_ROOT_ALLOW_RESIZE
;
227 /* Get the address of the RSDP */
229 RsdpAddress
= AcpiOsGetRootPointer ();
232 return_ACPI_STATUS (AE_NOT_FOUND
);
236 * Get the root table (RSDT or XSDT) and extract all entries to the local
237 * Root Table Array. This array contains the information of the RSDT/XSDT
238 * in a common, more useable format.
240 Status
= AcpiTbParseRootTable (RsdpAddress
, ACPI_TABLE_ORIGIN_MAPPED
);
241 return_ACPI_STATUS (Status
);
244 ACPI_EXPORT_SYMBOL (AcpiInitializeTables
)
247 /*******************************************************************************
249 * FUNCTION: AcpiReallocateRootTable
255 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
256 * root list from the previously provided scratch area. Should
257 * be called once dynamic memory allocation is available in the
260 ******************************************************************************/
263 AcpiReallocateRootTable (
266 ACPI_TABLE_DESC
*Tables
;
270 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable
);
274 * Only reallocate the root table if the host provided a static buffer
275 * for the table array in the call to AcpiInitializeTables.
277 if (AcpiGbl_RootTableList
.Flags
& ACPI_ROOT_ORIGIN_ALLOCATED
)
279 return_ACPI_STATUS (AE_SUPPORT
);
282 NewSize
= (AcpiGbl_RootTableList
.Count
+ ACPI_ROOT_TABLE_SIZE_INCREMENT
) *
283 sizeof (ACPI_TABLE_DESC
);
285 /* Create new array and copy the old array */
287 Tables
= ACPI_ALLOCATE_ZEROED (NewSize
);
290 return_ACPI_STATUS (AE_NO_MEMORY
);
293 ACPI_MEMCPY (Tables
, AcpiGbl_RootTableList
.Tables
, NewSize
);
295 AcpiGbl_RootTableList
.Size
= AcpiGbl_RootTableList
.Count
;
296 AcpiGbl_RootTableList
.Tables
= Tables
;
297 AcpiGbl_RootTableList
.Flags
=
298 ACPI_ROOT_ORIGIN_ALLOCATED
| ACPI_ROOT_ALLOW_RESIZE
;
300 return_ACPI_STATUS (AE_OK
);
303 ACPI_EXPORT_SYMBOL (AcpiReallocateRootTable
)
306 /******************************************************************************
308 * FUNCTION: AcpiGetTableHeader
310 * PARAMETERS: Signature - ACPI signature of needed table
311 * Instance - Which instance (for SSDTs)
312 * OutTableHeader - The pointer to the table header to fill
314 * RETURN: Status and pointer to mapped table header
316 * DESCRIPTION: Finds an ACPI table header.
318 * NOTE: Caller is responsible in unmapping the header with
321 *****************************************************************************/
326 ACPI_NATIVE_UINT Instance
,
327 ACPI_TABLE_HEADER
*OutTableHeader
)
331 ACPI_TABLE_HEADER
*Header
;
334 /* Parameter validation */
336 if (!Signature
|| !OutTableHeader
)
338 return (AE_BAD_PARAMETER
);
342 * Walk the root table list
344 for (i
= 0, j
= 0; i
< AcpiGbl_RootTableList
.Count
; i
++)
346 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList
.Tables
[i
].Signature
),
357 if (!AcpiGbl_RootTableList
.Tables
[i
].Pointer
)
359 if ((AcpiGbl_RootTableList
.Tables
[i
].Flags
& ACPI_TABLE_ORIGIN_MASK
) ==
360 ACPI_TABLE_ORIGIN_MAPPED
)
362 Header
= AcpiOsMapMemory (AcpiGbl_RootTableList
.Tables
[i
].Address
,
363 sizeof (ACPI_TABLE_HEADER
));
369 ACPI_MEMCPY (OutTableHeader
, Header
, sizeof(ACPI_TABLE_HEADER
));
370 AcpiOsUnmapMemory (Header
, sizeof(ACPI_TABLE_HEADER
));
381 ACPI_MEMCPY (OutTableHeader
, AcpiGbl_RootTableList
.Tables
[i
].Pointer
,
382 sizeof(ACPI_TABLE_HEADER
));
388 return (AE_NOT_FOUND
);
391 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader
)
394 /******************************************************************************
396 * FUNCTION: AcpiGetTable
398 * PARAMETERS: Signature - ACPI signature of needed table
399 * Instance - Which instance (for SSDTs)
400 * OutTable - Where the pointer to the table is returned
402 * RETURN: Status and pointer to table
404 * DESCRIPTION: Finds and verifies an ACPI table.
406 *****************************************************************************/
411 ACPI_NATIVE_UINT Instance
,
412 ACPI_TABLE_HEADER
**OutTable
)
419 /* Parameter validation */
421 if (!Signature
|| !OutTable
)
423 return (AE_BAD_PARAMETER
);
427 * Walk the root table list
429 for (i
= 0, j
= 0; i
< AcpiGbl_RootTableList
.Count
; i
++)
431 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList
.Tables
[i
].Signature
),
442 Status
= AcpiTbVerifyTable (&AcpiGbl_RootTableList
.Tables
[i
]);
443 if (ACPI_SUCCESS (Status
))
445 *OutTable
= AcpiGbl_RootTableList
.Tables
[i
].Pointer
;
451 return (AE_NOT_FOUND
);
454 ACPI_EXPORT_SYMBOL (AcpiGetTable
)
457 /*******************************************************************************
459 * FUNCTION: AcpiGetTableByIndex
461 * PARAMETERS: TableIndex - Table index
462 * Table - Where the pointer to the table is returned
464 * RETURN: Status and pointer to the table
466 * DESCRIPTION: Obtain a table by an index into the global table list.
468 ******************************************************************************/
471 AcpiGetTableByIndex (
472 ACPI_NATIVE_UINT TableIndex
,
473 ACPI_TABLE_HEADER
**Table
)
478 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex
);
481 /* Parameter validation */
485 return_ACPI_STATUS (AE_BAD_PARAMETER
);
488 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
492 if (TableIndex
>= AcpiGbl_RootTableList
.Count
)
494 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
495 return_ACPI_STATUS (AE_BAD_PARAMETER
);
498 if (!AcpiGbl_RootTableList
.Tables
[TableIndex
].Pointer
)
500 /* Table is not mapped, map it */
502 Status
= AcpiTbVerifyTable (&AcpiGbl_RootTableList
.Tables
[TableIndex
]);
503 if (ACPI_FAILURE (Status
))
505 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
506 return_ACPI_STATUS (Status
);
510 *Table
= AcpiGbl_RootTableList
.Tables
[TableIndex
].Pointer
;
511 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
512 return_ACPI_STATUS (AE_OK
);
515 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex
)
518 /*******************************************************************************
520 * FUNCTION: AcpiTbLoadNamespace
526 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
529 ******************************************************************************/
532 AcpiTbLoadNamespace (
536 ACPI_TABLE_HEADER
*Table
;
540 ACPI_FUNCTION_TRACE (TbLoadNamespace
);
543 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
546 * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
549 if (!AcpiGbl_RootTableList
.Count
||
550 !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList
.Tables
[ACPI_TABLE_INDEX_DSDT
].Signature
),
552 ACPI_FAILURE (AcpiTbVerifyTable(&AcpiGbl_RootTableList
.Tables
[ACPI_TABLE_INDEX_DSDT
])))
554 Status
= AE_NO_ACPI_TABLES
;
561 Status
= AcpiOsTableOverride (
562 AcpiGbl_RootTableList
.Tables
[ACPI_TABLE_INDEX_DSDT
].Pointer
, &Table
);
563 if (ACPI_SUCCESS (Status
) && Table
)
566 * DSDT table has been found
568 AcpiTbDeleteTable (ACPI_TABLE_INDEX_DSDT
);
569 AcpiGbl_RootTableList
.Tables
[ACPI_TABLE_INDEX_DSDT
].Pointer
= Table
;
570 AcpiGbl_RootTableList
.Tables
[ACPI_TABLE_INDEX_DSDT
].Length
= Table
->Length
;
571 AcpiGbl_RootTableList
.Tables
[ACPI_TABLE_INDEX_DSDT
].Flags
= ACPI_TABLE_ORIGIN_UNKNOWN
;
573 ACPI_INFO ((AE_INFO
, "Table DSDT replaced by host OS"));
574 AcpiTbPrintTableHeader (0, Table
);
577 Status
= AcpiTbVerifyTable (&AcpiGbl_RootTableList
.Tables
[ACPI_TABLE_INDEX_DSDT
]);
578 if (ACPI_FAILURE (Status
))
580 /* A valid DSDT is required */
582 Status
= AE_NO_ACPI_TABLES
;
586 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
589 * Load and parse tables.
591 Status
= AcpiNsLoadTable (ACPI_TABLE_INDEX_DSDT
, AcpiGbl_RootNode
);
592 if (ACPI_FAILURE (Status
))
594 return_ACPI_STATUS (Status
);
598 * Load any SSDT or PSDT tables. Note: Loop leaves tables locked
600 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
601 for (i
= 0; i
< AcpiGbl_RootTableList
.Count
; ++i
)
603 if ((!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList
.Tables
[i
].Signature
),
605 !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList
.Tables
[i
].Signature
),
607 ACPI_FAILURE (AcpiTbVerifyTable (&AcpiGbl_RootTableList
.Tables
[i
])))
612 /* Ignore errors while loading tables, get as many as possible */
614 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
615 (void) AcpiNsLoadTable (i
, AcpiGbl_RootNode
);
616 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
619 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
, "ACPI Tables successfully acquired\n"));
622 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
623 return_ACPI_STATUS (Status
);
627 /*******************************************************************************
629 * FUNCTION: AcpiLoadTables
635 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
637 ******************************************************************************/
646 ACPI_FUNCTION_TRACE (AcpiLoadTables
);
650 * Load the namespace from the tables
652 Status
= AcpiTbLoadNamespace ();
653 if (ACPI_FAILURE (Status
))
655 ACPI_EXCEPTION ((AE_INFO
, Status
, "While loading namespace from ACPI tables"));
658 return_ACPI_STATUS (Status
);
661 ACPI_EXPORT_SYMBOL (AcpiLoadTables
)