1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acnamesp.h>
50 #include <contrib/dev/acpica/include/actables.h>
52 #define _COMPONENT ACPI_TABLES
53 ACPI_MODULE_NAME ("tbxface")
55 /* Local prototypes */
62 /*******************************************************************************
64 * FUNCTION: AcpiAllocateRootTable
66 * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
67 * ACPI_TABLE_DESC structures
71 * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
72 * AcpiInitializeTables.
74 ******************************************************************************/
77 AcpiAllocateRootTable (
78 UINT32 InitialTableCount)
81 AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
82 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
84 return (AcpiTbResizeRootTableList ());
88 /*******************************************************************************
90 * FUNCTION: AcpiInitializeTables
92 * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
93 * ACPI_TABLE_DESC structures. If NULL, the
94 * array is dynamically allocated.
95 * InitialTableCount - Size of InitialTableArray, in number of
96 * ACPI_TABLE_DESC structures
97 * AllowRealloc - Flag to tell Table Manager if resize of
98 * pre-allocated array is allowed. Ignored
99 * if InitialTableArray is NULL.
103 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
105 * NOTE: Allows static allocation of the initial table array in order
106 * to avoid the use of dynamic memory in confined environments
107 * such as the kernel boot sequence where it may not be available.
109 * If the host OS memory managers are initialized, use NULL for
110 * InitialTableArray, and the table will be dynamically allocated.
112 ******************************************************************************/
115 AcpiInitializeTables (
116 ACPI_TABLE_DESC *InitialTableArray,
117 UINT32 InitialTableCount,
120 ACPI_PHYSICAL_ADDRESS RsdpAddress;
124 ACPI_FUNCTION_TRACE (AcpiInitializeTables);
128 * Set up the Root Table Array
129 * Allocate the table array if requested
131 if (!InitialTableArray)
133 Status = AcpiAllocateRootTable (InitialTableCount);
134 if (ACPI_FAILURE (Status))
136 return_ACPI_STATUS (Status);
141 /* Root Table Array has been statically allocated by the host */
143 ACPI_MEMSET (InitialTableArray, 0,
144 (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
146 AcpiGbl_RootTableList.Tables = InitialTableArray;
147 AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
148 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
151 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
155 /* Get the address of the RSDP */
157 RsdpAddress = AcpiOsGetRootPointer ();
160 return_ACPI_STATUS (AE_NOT_FOUND);
164 * Get the root table (RSDT or XSDT) and extract all entries to the local
165 * Root Table Array. This array contains the information of the RSDT/XSDT
166 * in a common, more useable format.
168 Status = AcpiTbParseRootTable (RsdpAddress);
169 return_ACPI_STATUS (Status);
172 ACPI_EXPORT_SYMBOL (AcpiInitializeTables)
175 /*******************************************************************************
177 * FUNCTION: AcpiReallocateRootTable
183 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
184 * root list from the previously provided scratch area. Should
185 * be called once dynamic memory allocation is available in the
188 ******************************************************************************/
191 AcpiReallocateRootTable (
194 ACPI_TABLE_DESC *Tables;
196 ACPI_SIZE CurrentSize;
199 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
203 * Only reallocate the root table if the host provided a static buffer
204 * for the table array in the call to AcpiInitializeTables.
206 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
208 return_ACPI_STATUS (AE_SUPPORT);
212 * Get the current size of the root table and add the default
213 * increment to create the new table size.
215 CurrentSize = (ACPI_SIZE)
216 AcpiGbl_RootTableList.CurrentTableCount * sizeof (ACPI_TABLE_DESC);
218 NewSize = CurrentSize +
219 (ACPI_ROOT_TABLE_SIZE_INCREMENT * sizeof (ACPI_TABLE_DESC));
221 /* Create new array and copy the old array */
223 Tables = ACPI_ALLOCATE_ZEROED (NewSize);
226 return_ACPI_STATUS (AE_NO_MEMORY);
229 ACPI_MEMCPY (Tables, AcpiGbl_RootTableList.Tables, CurrentSize);
232 * Update the root table descriptor. The new size will be the current
233 * number of tables plus the increment, independent of the reserved
234 * size of the original table list.
236 AcpiGbl_RootTableList.Tables = Tables;
237 AcpiGbl_RootTableList.MaxTableCount =
238 AcpiGbl_RootTableList.CurrentTableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
239 AcpiGbl_RootTableList.Flags =
240 ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
242 return_ACPI_STATUS (AE_OK);
245 ACPI_EXPORT_SYMBOL (AcpiReallocateRootTable)
248 /*******************************************************************************
250 * FUNCTION: AcpiGetTableHeader
252 * PARAMETERS: Signature - ACPI signature of needed table
253 * Instance - Which instance (for SSDTs)
254 * OutTableHeader - The pointer to the table header to fill
256 * RETURN: Status and pointer to mapped table header
258 * DESCRIPTION: Finds an ACPI table header.
260 * NOTE: Caller is responsible in unmapping the header with
263 ******************************************************************************/
269 ACPI_TABLE_HEADER *OutTableHeader)
273 ACPI_TABLE_HEADER *Header;
276 /* Parameter validation */
278 if (!Signature || !OutTableHeader)
280 return (AE_BAD_PARAMETER);
283 /* Walk the root table list */
285 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
287 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
298 if (!AcpiGbl_RootTableList.Tables[i].Pointer)
300 if ((AcpiGbl_RootTableList.Tables[i].Flags &
301 ACPI_TABLE_ORIGIN_MASK) ==
302 ACPI_TABLE_ORIGIN_MAPPED)
304 Header = AcpiOsMapMemory (
305 AcpiGbl_RootTableList.Tables[i].Address,
306 sizeof (ACPI_TABLE_HEADER));
312 ACPI_MEMCPY (OutTableHeader, Header, sizeof(ACPI_TABLE_HEADER));
313 AcpiOsUnmapMemory (Header, sizeof(ACPI_TABLE_HEADER));
322 ACPI_MEMCPY (OutTableHeader,
323 AcpiGbl_RootTableList.Tables[i].Pointer,
324 sizeof(ACPI_TABLE_HEADER));
330 return (AE_NOT_FOUND);
333 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
336 /*******************************************************************************
338 * FUNCTION: AcpiGetTable
340 * PARAMETERS: Signature - ACPI signature of needed table
341 * Instance - Which instance (for SSDTs)
342 * OutTable - Where the pointer to the table is returned
344 * RETURN: Status and pointer to table
346 * DESCRIPTION: Finds and verifies an ACPI table.
348 ******************************************************************************/
354 ACPI_TABLE_HEADER **OutTable)
361 /* Parameter validation */
363 if (!Signature || !OutTable)
365 return (AE_BAD_PARAMETER);
368 /* Walk the root table list */
370 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
372 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
383 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]);
384 if (ACPI_SUCCESS (Status))
386 *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer;
392 return (AE_NOT_FOUND);
395 ACPI_EXPORT_SYMBOL (AcpiGetTable)
398 /*******************************************************************************
400 * FUNCTION: AcpiGetTableByIndex
402 * PARAMETERS: TableIndex - Table index
403 * Table - Where the pointer to the table is returned
405 * RETURN: Status and pointer to the table
407 * DESCRIPTION: Obtain a table by an index into the global table list.
409 ******************************************************************************/
412 AcpiGetTableByIndex (
414 ACPI_TABLE_HEADER **Table)
419 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
422 /* Parameter validation */
426 return_ACPI_STATUS (AE_BAD_PARAMETER);
429 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
433 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
435 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
436 return_ACPI_STATUS (AE_BAD_PARAMETER);
439 if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer)
441 /* Table is not mapped, map it */
443 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[TableIndex]);
444 if (ACPI_FAILURE (Status))
446 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
447 return_ACPI_STATUS (Status);
451 *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer;
452 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
453 return_ACPI_STATUS (AE_OK);
456 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
459 /*******************************************************************************
461 * FUNCTION: AcpiTbLoadNamespace
467 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
470 ******************************************************************************/
473 AcpiTbLoadNamespace (
478 ACPI_TABLE_HEADER *NewDsdt;
481 ACPI_FUNCTION_TRACE (TbLoadNamespace);
484 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
487 * Load the namespace. The DSDT is required, but any SSDT and
488 * PSDT tables are optional. Verify the DSDT.
490 if (!AcpiGbl_RootTableList.CurrentTableCount ||
492 &(AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Signature),
494 ACPI_FAILURE (AcpiTbVerifyTable (
495 &AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT])))
497 Status = AE_NO_ACPI_TABLES;
502 * Save the DSDT pointer for simple access. This is the mapped memory
503 * address. We must take care here because the address of the .Tables
504 * array can change dynamically as tables are loaded at run-time. Note:
505 * .Pointer field is not validated until after call to AcpiTbVerifyTable.
507 AcpiGbl_DSDT = AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Pointer;
510 * Optionally copy the entire DSDT to local memory (instead of simply
511 * mapping it.) There are some BIOSs that corrupt or replace the original
512 * DSDT, creating the need for this option. Default is FALSE, do not copy
515 if (AcpiGbl_CopyDsdtLocally)
517 NewDsdt = AcpiTbCopyDsdt (ACPI_TABLE_INDEX_DSDT);
520 AcpiGbl_DSDT = NewDsdt;
525 * Save the original DSDT header for detection of table corruption
526 * and/or replacement of the DSDT from outside the OS.
528 ACPI_MEMCPY (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
529 sizeof (ACPI_TABLE_HEADER));
531 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
533 /* Load and parse tables */
535 Status = AcpiNsLoadTable (ACPI_TABLE_INDEX_DSDT, AcpiGbl_RootNode);
536 if (ACPI_FAILURE (Status))
538 return_ACPI_STATUS (Status);
541 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
543 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
544 for (i = 2; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
546 if ((!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
548 !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
550 ACPI_FAILURE (AcpiTbVerifyTable (
551 &AcpiGbl_RootTableList.Tables[i])))
556 /* Skip SSDT when DSDT is overriden */
558 if (ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
560 (AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Flags &
561 ACPI_TABLE_ORIGIN_OVERRIDE))
566 /* Ignore errors while loading tables, get as many as possible */
568 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
569 (void) AcpiNsLoadTable (i, AcpiGbl_RootNode);
570 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
573 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
576 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
577 return_ACPI_STATUS (Status);
581 /*******************************************************************************
583 * FUNCTION: AcpiLoadTables
589 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
591 ******************************************************************************/
600 ACPI_FUNCTION_TRACE (AcpiLoadTables);
603 /* Load the namespace from the tables */
605 Status = AcpiTbLoadNamespace ();
606 if (ACPI_FAILURE (Status))
608 ACPI_EXCEPTION ((AE_INFO, Status,
609 "While loading namespace from ACPI tables"));
612 return_ACPI_STATUS (Status);
615 ACPI_EXPORT_SYMBOL (AcpiLoadTables)
618 /*******************************************************************************
620 * FUNCTION: AcpiInstallTableHandler
622 * PARAMETERS: Handler - Table event handler
623 * Context - Value passed to the handler on each event
627 * DESCRIPTION: Install table event handler
629 ******************************************************************************/
632 AcpiInstallTableHandler (
633 ACPI_TABLE_HANDLER Handler,
639 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
644 return_ACPI_STATUS (AE_BAD_PARAMETER);
647 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
648 if (ACPI_FAILURE (Status))
650 return_ACPI_STATUS (Status);
653 /* Don't allow more than one handler */
655 if (AcpiGbl_TableHandler)
657 Status = AE_ALREADY_EXISTS;
661 /* Install the handler */
663 AcpiGbl_TableHandler = Handler;
664 AcpiGbl_TableHandlerContext = Context;
667 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
668 return_ACPI_STATUS (Status);
671 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
674 /*******************************************************************************
676 * FUNCTION: AcpiRemoveTableHandler
678 * PARAMETERS: Handler - Table event handler that was installed
683 * DESCRIPTION: Remove table event handler
685 ******************************************************************************/
688 AcpiRemoveTableHandler (
689 ACPI_TABLE_HANDLER Handler)
694 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
697 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
698 if (ACPI_FAILURE (Status))
700 return_ACPI_STATUS (Status);
703 /* Make sure that the installed handler is the same */
706 Handler != AcpiGbl_TableHandler)
708 Status = AE_BAD_PARAMETER;
712 /* Remove the handler */
714 AcpiGbl_TableHandler = NULL;
717 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
718 return_ACPI_STATUS (Status);
721 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)