1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
117 #define __TBXFACE_C__
119 #include <contrib/dev/acpica/include/acpi.h>
120 #include <contrib/dev/acpica/include/accommon.h>
121 #include <contrib/dev/acpica/include/acnamesp.h>
122 #include <contrib/dev/acpica/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 (ACPI_SIZE) 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);
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;
268 ACPI_SIZE CurrentSize;
271 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
275 * Only reallocate the root table if the host provided a static buffer
276 * for the table array in the call to AcpiInitializeTables.
278 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
280 return_ACPI_STATUS (AE_SUPPORT);
284 * Get the current size of the root table and add the default
285 * increment to create the new table size.
287 CurrentSize = (ACPI_SIZE)
288 AcpiGbl_RootTableList.Count * sizeof (ACPI_TABLE_DESC);
290 NewSize = CurrentSize +
291 (ACPI_ROOT_TABLE_SIZE_INCREMENT * sizeof (ACPI_TABLE_DESC));
293 /* Create new array and copy the old array */
295 Tables = ACPI_ALLOCATE_ZEROED (NewSize);
298 return_ACPI_STATUS (AE_NO_MEMORY);
301 ACPI_MEMCPY (Tables, AcpiGbl_RootTableList.Tables, CurrentSize);
304 * Update the root table descriptor. The new size will be the current
305 * number of tables plus the increment, independent of the reserved
306 * size of the original table list.
308 AcpiGbl_RootTableList.Tables = Tables;
309 AcpiGbl_RootTableList.Size =
310 AcpiGbl_RootTableList.Count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
311 AcpiGbl_RootTableList.Flags =
312 ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
314 return_ACPI_STATUS (AE_OK);
317 ACPI_EXPORT_SYMBOL (AcpiReallocateRootTable)
320 /*******************************************************************************
322 * FUNCTION: AcpiGetTableHeader
324 * PARAMETERS: Signature - ACPI signature of needed table
325 * Instance - Which instance (for SSDTs)
326 * OutTableHeader - The pointer to the table header to fill
328 * RETURN: Status and pointer to mapped table header
330 * DESCRIPTION: Finds an ACPI table header.
332 * NOTE: Caller is responsible in unmapping the header with
335 ******************************************************************************/
341 ACPI_TABLE_HEADER *OutTableHeader)
345 ACPI_TABLE_HEADER *Header;
348 /* Parameter validation */
350 if (!Signature || !OutTableHeader)
352 return (AE_BAD_PARAMETER);
355 /* Walk the root table list */
357 for (i = 0, j = 0; i < AcpiGbl_RootTableList.Count; i++)
359 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
370 if (!AcpiGbl_RootTableList.Tables[i].Pointer)
372 if ((AcpiGbl_RootTableList.Tables[i].Flags &
373 ACPI_TABLE_ORIGIN_MASK) ==
374 ACPI_TABLE_ORIGIN_MAPPED)
376 Header = AcpiOsMapMemory (
377 AcpiGbl_RootTableList.Tables[i].Address,
378 sizeof (ACPI_TABLE_HEADER));
384 ACPI_MEMCPY (OutTableHeader, Header, sizeof(ACPI_TABLE_HEADER));
385 AcpiOsUnmapMemory (Header, sizeof(ACPI_TABLE_HEADER));
394 ACPI_MEMCPY (OutTableHeader,
395 AcpiGbl_RootTableList.Tables[i].Pointer,
396 sizeof(ACPI_TABLE_HEADER));
402 return (AE_NOT_FOUND);
405 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
408 /*******************************************************************************
410 * FUNCTION: AcpiGetTable
412 * PARAMETERS: Signature - ACPI signature of needed table
413 * Instance - Which instance (for SSDTs)
414 * OutTable - Where the pointer to the table is returned
416 * RETURN: Status and pointer to table
418 * DESCRIPTION: Finds and verifies an ACPI table.
420 ******************************************************************************/
426 ACPI_TABLE_HEADER **OutTable)
433 /* Parameter validation */
435 if (!Signature || !OutTable)
437 return (AE_BAD_PARAMETER);
440 /* Walk the root table list */
442 for (i = 0, j = 0; i < AcpiGbl_RootTableList.Count; i++)
444 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
455 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]);
456 if (ACPI_SUCCESS (Status))
458 *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer;
464 return (AE_NOT_FOUND);
467 ACPI_EXPORT_SYMBOL (AcpiGetTable)
470 /*******************************************************************************
472 * FUNCTION: AcpiGetTableByIndex
474 * PARAMETERS: TableIndex - Table index
475 * Table - Where the pointer to the table is returned
477 * RETURN: Status and pointer to the table
479 * DESCRIPTION: Obtain a table by an index into the global table list.
481 ******************************************************************************/
484 AcpiGetTableByIndex (
486 ACPI_TABLE_HEADER **Table)
491 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
494 /* Parameter validation */
498 return_ACPI_STATUS (AE_BAD_PARAMETER);
501 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
505 if (TableIndex >= AcpiGbl_RootTableList.Count)
507 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
508 return_ACPI_STATUS (AE_BAD_PARAMETER);
511 if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer)
513 /* Table is not mapped, map it */
515 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[TableIndex]);
516 if (ACPI_FAILURE (Status))
518 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
519 return_ACPI_STATUS (Status);
523 *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer;
524 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
525 return_ACPI_STATUS (AE_OK);
528 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
531 /*******************************************************************************
533 * FUNCTION: AcpiTbLoadNamespace
539 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
542 ******************************************************************************/
545 AcpiTbLoadNamespace (
550 ACPI_TABLE_HEADER *NewDsdt;
553 ACPI_FUNCTION_TRACE (TbLoadNamespace);
556 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
559 * Load the namespace. The DSDT is required, but any SSDT and
560 * PSDT tables are optional. Verify the DSDT.
562 if (!AcpiGbl_RootTableList.Count ||
564 &(AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Signature),
566 ACPI_FAILURE (AcpiTbVerifyTable (
567 &AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT])))
569 Status = AE_NO_ACPI_TABLES;
574 * Save the DSDT pointer for simple access. This is the mapped memory
575 * address. We must take care here because the address of the .Tables
576 * array can change dynamically as tables are loaded at run-time. Note:
577 * .Pointer field is not validated until after call to AcpiTbVerifyTable.
579 AcpiGbl_DSDT = AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Pointer;
582 * Optionally copy the entire DSDT to local memory (instead of simply
583 * mapping it.) There are some BIOSs that corrupt or replace the original
584 * DSDT, creating the need for this option. Default is FALSE, do not copy
587 if (AcpiGbl_CopyDsdtLocally)
589 NewDsdt = AcpiTbCopyDsdt (ACPI_TABLE_INDEX_DSDT);
592 AcpiGbl_DSDT = NewDsdt;
597 * Save the original DSDT header for detection of table corruption
598 * and/or replacement of the DSDT from outside the OS.
600 ACPI_MEMCPY (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
601 sizeof (ACPI_TABLE_HEADER));
603 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
605 /* Load and parse tables */
607 Status = AcpiNsLoadTable (ACPI_TABLE_INDEX_DSDT, AcpiGbl_RootNode);
608 if (ACPI_FAILURE (Status))
610 return_ACPI_STATUS (Status);
613 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
615 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
616 for (i = 2; i < AcpiGbl_RootTableList.Count; ++i)
618 if ((!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
620 !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
622 ACPI_FAILURE (AcpiTbVerifyTable (
623 &AcpiGbl_RootTableList.Tables[i])))
628 /* Skip SSDT when DSDT is overriden */
630 if (ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
632 (AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Flags &
633 ACPI_TABLE_ORIGIN_OVERRIDE))
638 /* Ignore errors while loading tables, get as many as possible */
640 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
641 (void) AcpiNsLoadTable (i, AcpiGbl_RootNode);
642 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
645 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
648 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
649 return_ACPI_STATUS (Status);
653 /*******************************************************************************
655 * FUNCTION: AcpiLoadTables
661 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
663 ******************************************************************************/
672 ACPI_FUNCTION_TRACE (AcpiLoadTables);
675 /* Load the namespace from the tables */
677 Status = AcpiTbLoadNamespace ();
678 if (ACPI_FAILURE (Status))
680 ACPI_EXCEPTION ((AE_INFO, Status,
681 "While loading namespace from ACPI tables"));
684 return_ACPI_STATUS (Status);
687 ACPI_EXPORT_SYMBOL (AcpiLoadTables)
690 /*******************************************************************************
692 * FUNCTION: AcpiInstallTableHandler
694 * PARAMETERS: Handler - Table event handler
695 * Context - Value passed to the handler on each event
699 * DESCRIPTION: Install table event handler
701 ******************************************************************************/
704 AcpiInstallTableHandler (
705 ACPI_TABLE_HANDLER Handler,
711 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
716 return_ACPI_STATUS (AE_BAD_PARAMETER);
719 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
720 if (ACPI_FAILURE (Status))
722 return_ACPI_STATUS (Status);
725 /* Don't allow more than one handler */
727 if (AcpiGbl_TableHandler)
729 Status = AE_ALREADY_EXISTS;
733 /* Install the handler */
735 AcpiGbl_TableHandler = Handler;
736 AcpiGbl_TableHandlerContext = Context;
739 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
740 return_ACPI_STATUS (Status);
743 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
746 /*******************************************************************************
748 * FUNCTION: AcpiRemoveTableHandler
750 * PARAMETERS: Handler - Table event handler that was installed
755 * DESCRIPTION: Remove table event handler
757 ******************************************************************************/
760 AcpiRemoveTableHandler (
761 ACPI_TABLE_HANDLER Handler)
766 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
769 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
770 if (ACPI_FAILURE (Status))
772 return_ACPI_STATUS (Status);
775 /* Make sure that the installed handler is the same */
778 Handler != AcpiGbl_TableHandler)
780 Status = AE_BAD_PARAMETER;
784 /* Remove the handler */
786 AcpiGbl_TableHandler = NULL;
789 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
790 return_ACPI_STATUS (Status);
793 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)