1 /******************************************************************************
3 * Module Name: tbxface - ACPI table-oriented external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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.
44 #define EXPORT_ACPI_INTERFACES
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 ******************************************************************************/
106 ACPI_STATUS ACPI_INIT_FUNCTION
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 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_INIT (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 ******************************************************************************/
182 ACPI_STATUS ACPI_INIT_FUNCTION
183 AcpiReallocateRootTable (
190 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable
);
194 * Only reallocate the root table if the host provided a static buffer
195 * for the table array in the call to AcpiInitializeTables.
197 if (AcpiGbl_RootTableList
.Flags
& ACPI_ROOT_ORIGIN_ALLOCATED
)
199 return_ACPI_STATUS (AE_SUPPORT
);
203 * Ensure OS early boot logic, which is required by some hosts. If the
204 * table state is reported to be wrong, developers should fix the
205 * issue by invoking AcpiPutTable() for the reported table during the
208 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
210 if (AcpiGbl_RootTableList
.Tables
[i
].Pointer
)
212 ACPI_ERROR ((AE_INFO
,
213 "Table [%4.4s] is not invalidated during early boot stage",
214 AcpiGbl_RootTableList
.Tables
[i
].Signature
.Ascii
));
218 AcpiGbl_RootTableList
.Flags
|= ACPI_ROOT_ALLOW_RESIZE
;
220 Status
= AcpiTbResizeRootTableList ();
221 return_ACPI_STATUS (Status
);
224 ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable
)
227 /*******************************************************************************
229 * FUNCTION: AcpiGetTableHeader
231 * PARAMETERS: Signature - ACPI signature of needed table
232 * Instance - Which instance (for SSDTs)
233 * OutTableHeader - The pointer to the table header to fill
235 * RETURN: Status and pointer to mapped table header
237 * DESCRIPTION: Finds an ACPI table header.
239 * NOTE: Caller is responsible in unmapping the header with
242 ******************************************************************************/
248 ACPI_TABLE_HEADER
*OutTableHeader
)
252 ACPI_TABLE_HEADER
*Header
;
255 /* Parameter validation */
257 if (!Signature
|| !OutTableHeader
)
259 return (AE_BAD_PARAMETER
);
262 /* Walk the root table list */
264 for (i
= 0, j
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
266 if (!ACPI_COMPARE_NAME (
267 &(AcpiGbl_RootTableList
.Tables
[i
].Signature
), Signature
))
277 if (!AcpiGbl_RootTableList
.Tables
[i
].Pointer
)
279 if ((AcpiGbl_RootTableList
.Tables
[i
].Flags
&
280 ACPI_TABLE_ORIGIN_MASK
) ==
281 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
)
283 Header
= AcpiOsMapMemory (
284 AcpiGbl_RootTableList
.Tables
[i
].Address
,
285 sizeof (ACPI_TABLE_HEADER
));
288 return (AE_NO_MEMORY
);
291 memcpy (OutTableHeader
, Header
, sizeof (ACPI_TABLE_HEADER
));
292 AcpiOsUnmapMemory (Header
, sizeof (ACPI_TABLE_HEADER
));
296 return (AE_NOT_FOUND
);
301 memcpy (OutTableHeader
,
302 AcpiGbl_RootTableList
.Tables
[i
].Pointer
,
303 sizeof (ACPI_TABLE_HEADER
));
309 return (AE_NOT_FOUND
);
312 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader
)
315 /*******************************************************************************
317 * FUNCTION: AcpiGetTable
319 * PARAMETERS: Signature - ACPI signature of needed table
320 * Instance - Which instance (for SSDTs)
321 * OutTable - Where the pointer to the table is returned
323 * RETURN: Status and pointer to the requested table
325 * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
327 * Note that an early stage AcpiGetTable() call must be paired
328 * with an early stage AcpiPutTable() call. otherwise the table
329 * pointer mapped by the early stage mapping implementation may be
330 * erroneously unmapped by the late stage unmapping implementation
331 * in an AcpiPutTable() invoked during the late stage.
333 ******************************************************************************/
339 ACPI_TABLE_HEADER
**OutTable
)
343 ACPI_STATUS Status
= AE_NOT_FOUND
;
344 ACPI_TABLE_DESC
*TableDesc
;
347 /* Parameter validation */
349 if (!Signature
|| !OutTable
)
351 return (AE_BAD_PARAMETER
);
355 * Note that the following line is required by some OSPMs, they only
356 * check if the returned table is NULL instead of the returned status
357 * to determined if this function is succeeded.
361 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
363 /* Walk the root table list */
365 for (i
= 0, j
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
367 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
369 if (!ACPI_COMPARE_NAME (&TableDesc
->Signature
, Signature
))
379 Status
= AcpiTbGetTable (TableDesc
, OutTable
);
383 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
387 ACPI_EXPORT_SYMBOL (AcpiGetTable
)
390 /*******************************************************************************
392 * FUNCTION: AcpiPutTable
394 * PARAMETERS: Table - The pointer to the table
398 * DESCRIPTION: Release a table returned by AcpiGetTable() and its clones.
399 * Note that it is not safe if this function was invoked after an
400 * uninstallation happened to the original table descriptor.
401 * Currently there is no OSPMs' requirement to handle such
404 ******************************************************************************/
408 ACPI_TABLE_HEADER
*Table
)
411 ACPI_TABLE_DESC
*TableDesc
;
414 ACPI_FUNCTION_TRACE (AcpiPutTable
);
417 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
419 /* Walk the root table list */
421 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
423 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
425 if (TableDesc
->Pointer
!= Table
)
430 AcpiTbPutTable (TableDesc
);
434 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
438 ACPI_EXPORT_SYMBOL (AcpiPutTable
)
441 /*******************************************************************************
443 * FUNCTION: AcpiGetTableByIndex
445 * PARAMETERS: TableIndex - Table index
446 * OutTable - Where the pointer to the table is returned
448 * RETURN: Status and pointer to the requested table
450 * DESCRIPTION: Obtain a table by an index into the global table list. Used
453 ******************************************************************************/
456 AcpiGetTableByIndex (
458 ACPI_TABLE_HEADER
**OutTable
)
463 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex
);
466 /* Parameter validation */
470 return_ACPI_STATUS (AE_BAD_PARAMETER
);
474 * Note that the following line is required by some OSPMs, they only
475 * check if the returned table is NULL instead of the returned status
476 * to determined if this function is succeeded.
480 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
484 if (TableIndex
>= AcpiGbl_RootTableList
.CurrentTableCount
)
486 Status
= AE_BAD_PARAMETER
;
490 Status
= AcpiTbGetTable (
491 &AcpiGbl_RootTableList
.Tables
[TableIndex
], OutTable
);
494 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
495 return_ACPI_STATUS (Status
);
498 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex
)
501 /*******************************************************************************
503 * FUNCTION: AcpiInstallTableHandler
505 * PARAMETERS: Handler - Table event handler
506 * Context - Value passed to the handler on each event
510 * DESCRIPTION: Install a global table event handler.
512 ******************************************************************************/
515 AcpiInstallTableHandler (
516 ACPI_TABLE_HANDLER Handler
,
522 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler
);
527 return_ACPI_STATUS (AE_BAD_PARAMETER
);
530 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
531 if (ACPI_FAILURE (Status
))
533 return_ACPI_STATUS (Status
);
536 /* Don't allow more than one handler */
538 if (AcpiGbl_TableHandler
)
540 Status
= AE_ALREADY_EXISTS
;
544 /* Install the handler */
546 AcpiGbl_TableHandler
= Handler
;
547 AcpiGbl_TableHandlerContext
= Context
;
550 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
551 return_ACPI_STATUS (Status
);
554 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler
)
557 /*******************************************************************************
559 * FUNCTION: AcpiRemoveTableHandler
561 * PARAMETERS: Handler - Table event handler that was installed
566 * DESCRIPTION: Remove a table event handler
568 ******************************************************************************/
571 AcpiRemoveTableHandler (
572 ACPI_TABLE_HANDLER Handler
)
577 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler
);
580 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
581 if (ACPI_FAILURE (Status
))
583 return_ACPI_STATUS (Status
);
586 /* Make sure that the installed handler is the same */
589 Handler
!= AcpiGbl_TableHandler
)
591 Status
= AE_BAD_PARAMETER
;
595 /* Remove the handler */
597 AcpiGbl_TableHandler
= NULL
;
600 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
601 return_ACPI_STATUS (Status
);
604 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler
)