1 /******************************************************************************
3 * Module Name: tbxface - ACPI table-oriented external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/actables.h>
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbxface")
54 /*******************************************************************************
56 * FUNCTION: AcpiAllocateRootTable
58 * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
59 * ACPI_TABLE_DESC structures
63 * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
64 * AcpiInitializeTables.
66 ******************************************************************************/
69 AcpiAllocateRootTable (
70 UINT32 InitialTableCount)
73 AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
74 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
76 return (AcpiTbResizeRootTableList ());
80 /*******************************************************************************
82 * FUNCTION: AcpiInitializeTables
84 * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
85 * ACPI_TABLE_DESC structures. If NULL, the
86 * array is dynamically allocated.
87 * InitialTableCount - Size of InitialTableArray, in number of
88 * ACPI_TABLE_DESC structures
89 * AllowResize - Flag to tell Table Manager if resize of
90 * pre-allocated array is allowed. Ignored
91 * if InitialTableArray is NULL.
95 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
97 * NOTE: Allows static allocation of the initial table array in order
98 * to avoid the use of dynamic memory in confined environments
99 * such as the kernel boot sequence where it may not be available.
101 * If the host OS memory managers are initialized, use NULL for
102 * InitialTableArray, and the table will be dynamically allocated.
104 ******************************************************************************/
107 AcpiInitializeTables (
108 ACPI_TABLE_DESC *InitialTableArray,
109 UINT32 InitialTableCount,
112 ACPI_PHYSICAL_ADDRESS RsdpAddress;
116 ACPI_FUNCTION_TRACE (AcpiInitializeTables);
120 * Setup the Root Table Array and allocate the table array
123 if (!InitialTableArray)
125 Status = AcpiAllocateRootTable (InitialTableCount);
126 if (ACPI_FAILURE (Status))
128 return_ACPI_STATUS (Status);
133 /* Root Table Array has been statically allocated by the host */
135 ACPI_MEMSET (InitialTableArray, 0,
136 (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
138 AcpiGbl_RootTableList.Tables = InitialTableArray;
139 AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
140 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
143 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
147 /* Get the address of the RSDP */
149 RsdpAddress = AcpiOsGetRootPointer ();
152 return_ACPI_STATUS (AE_NOT_FOUND);
156 * Get the root table (RSDT or XSDT) and extract all entries to the local
157 * Root Table Array. This array contains the information of the RSDT/XSDT
158 * in a common, more useable format.
160 Status = AcpiTbParseRootTable (RsdpAddress);
161 return_ACPI_STATUS (Status);
164 ACPI_EXPORT_SYMBOL (AcpiInitializeTables)
167 /*******************************************************************************
169 * FUNCTION: AcpiReallocateRootTable
175 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
176 * root list from the previously provided scratch area. Should
177 * be called once dynamic memory allocation is available in the
180 ******************************************************************************/
183 AcpiReallocateRootTable (
189 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
193 * Only reallocate the root table if the host provided a static buffer
194 * for the table array in the call to AcpiInitializeTables.
196 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
198 return_ACPI_STATUS (AE_SUPPORT);
201 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
203 Status = AcpiTbResizeRootTableList ();
204 return_ACPI_STATUS (Status);
207 ACPI_EXPORT_SYMBOL (AcpiReallocateRootTable)
210 /*******************************************************************************
212 * FUNCTION: AcpiGetTableHeader
214 * PARAMETERS: Signature - ACPI signature of needed table
215 * Instance - Which instance (for SSDTs)
216 * OutTableHeader - The pointer to the table header to fill
218 * RETURN: Status and pointer to mapped table header
220 * DESCRIPTION: Finds an ACPI table header.
222 * NOTE: Caller is responsible in unmapping the header with
225 ******************************************************************************/
231 ACPI_TABLE_HEADER *OutTableHeader)
235 ACPI_TABLE_HEADER *Header;
238 /* Parameter validation */
240 if (!Signature || !OutTableHeader)
242 return (AE_BAD_PARAMETER);
245 /* Walk the root table list */
247 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
249 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
260 if (!AcpiGbl_RootTableList.Tables[i].Pointer)
262 if ((AcpiGbl_RootTableList.Tables[i].Flags &
263 ACPI_TABLE_ORIGIN_MASK) ==
264 ACPI_TABLE_ORIGIN_MAPPED)
266 Header = AcpiOsMapMemory (
267 AcpiGbl_RootTableList.Tables[i].Address,
268 sizeof (ACPI_TABLE_HEADER));
271 return (AE_NO_MEMORY);
274 ACPI_MEMCPY (OutTableHeader, Header,
275 sizeof (ACPI_TABLE_HEADER));
276 AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
280 return (AE_NOT_FOUND);
285 ACPI_MEMCPY (OutTableHeader,
286 AcpiGbl_RootTableList.Tables[i].Pointer,
287 sizeof (ACPI_TABLE_HEADER));
293 return (AE_NOT_FOUND);
296 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
299 /*******************************************************************************
301 * FUNCTION: AcpiGetTable
303 * PARAMETERS: Signature - ACPI signature of needed table
304 * Instance - Which instance (for SSDTs)
305 * OutTable - Where the pointer to the table is returned
307 * RETURN: Status and pointer to the requested table
309 * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
312 ******************************************************************************/
318 ACPI_TABLE_HEADER **OutTable)
325 /* Parameter validation */
327 if (!Signature || !OutTable)
329 return (AE_BAD_PARAMETER);
332 /* Walk the root table list */
334 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
336 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
347 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]);
348 if (ACPI_SUCCESS (Status))
350 *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer;
356 return (AE_NOT_FOUND);
359 ACPI_EXPORT_SYMBOL (AcpiGetTable)
362 /*******************************************************************************
364 * FUNCTION: AcpiGetTableByIndex
366 * PARAMETERS: TableIndex - Table index
367 * Table - Where the pointer to the table is returned
369 * RETURN: Status and pointer to the requested table
371 * DESCRIPTION: Obtain a table by an index into the global table list. Used
374 ******************************************************************************/
377 AcpiGetTableByIndex (
379 ACPI_TABLE_HEADER **Table)
384 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
387 /* Parameter validation */
391 return_ACPI_STATUS (AE_BAD_PARAMETER);
394 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
398 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
400 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
401 return_ACPI_STATUS (AE_BAD_PARAMETER);
404 if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer)
406 /* Table is not mapped, map it */
408 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[TableIndex]);
409 if (ACPI_FAILURE (Status))
411 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
412 return_ACPI_STATUS (Status);
416 *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer;
417 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
418 return_ACPI_STATUS (AE_OK);
421 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
424 /*******************************************************************************
426 * FUNCTION: AcpiInstallTableHandler
428 * PARAMETERS: Handler - Table event handler
429 * Context - Value passed to the handler on each event
433 * DESCRIPTION: Install a global table event handler.
435 ******************************************************************************/
438 AcpiInstallTableHandler (
439 ACPI_TABLE_HANDLER Handler,
445 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
450 return_ACPI_STATUS (AE_BAD_PARAMETER);
453 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
454 if (ACPI_FAILURE (Status))
456 return_ACPI_STATUS (Status);
459 /* Don't allow more than one handler */
461 if (AcpiGbl_TableHandler)
463 Status = AE_ALREADY_EXISTS;
467 /* Install the handler */
469 AcpiGbl_TableHandler = Handler;
470 AcpiGbl_TableHandlerContext = Context;
473 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
474 return_ACPI_STATUS (Status);
477 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
480 /*******************************************************************************
482 * FUNCTION: AcpiRemoveTableHandler
484 * PARAMETERS: Handler - Table event handler that was installed
489 * DESCRIPTION: Remove a table event handler
491 ******************************************************************************/
494 AcpiRemoveTableHandler (
495 ACPI_TABLE_HANDLER Handler)
500 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
503 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
504 if (ACPI_FAILURE (Status))
506 return_ACPI_STATUS (Status);
509 /* Make sure that the installed handler is the same */
512 Handler != AcpiGbl_TableHandler)
514 Status = AE_BAD_PARAMETER;
518 /* Remove the handler */
520 AcpiGbl_TableHandler = NULL;
523 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
524 return_ACPI_STATUS (Status);
527 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)