1 /******************************************************************************
3 * Module Name: tbxface - ACPI table-oriented external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2017, 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 (
187 ACPI_TABLE_DESC
*TableDesc
;
191 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable
);
195 * Only reallocate the root table if the host provided a static buffer
196 * for the table array in the call to AcpiInitializeTables.
198 if (AcpiGbl_RootTableList
.Flags
& ACPI_ROOT_ORIGIN_ALLOCATED
)
200 return_ACPI_STATUS (AE_SUPPORT
);
203 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
206 * Ensure OS early boot logic, which is required by some hosts. If the
207 * table state is reported to be wrong, developers should fix the
208 * issue by invoking AcpiPutTable() for the reported table during the
211 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
213 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
214 if (TableDesc
->Pointer
)
216 ACPI_ERROR ((AE_INFO
,
217 "Table [%4.4s] is not invalidated during early boot stage",
218 TableDesc
->Signature
.Ascii
));
222 if (!AcpiGbl_EnableTableValidation
)
225 * Now it's safe to do full table validation. We can do deferred
226 * table initilization here once the flag is set.
228 AcpiGbl_EnableTableValidation
= TRUE
;
229 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
231 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
232 if (!(TableDesc
->Flags
& ACPI_TABLE_IS_VERIFIED
))
234 Status
= AcpiTbVerifyTempTable (TableDesc
, NULL
, NULL
);
235 if (ACPI_FAILURE (Status
))
237 AcpiTbUninstallTable (TableDesc
);
243 AcpiGbl_RootTableList
.Flags
|= ACPI_ROOT_ALLOW_RESIZE
;
244 Status
= AcpiTbResizeRootTableList ();
245 AcpiGbl_RootTableList
.Flags
|= ACPI_ROOT_ORIGIN_ALLOCATED
;
247 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
248 return_ACPI_STATUS (Status
);
251 ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable
)
254 /*******************************************************************************
256 * FUNCTION: AcpiGetTableHeader
258 * PARAMETERS: Signature - ACPI signature of needed table
259 * Instance - Which instance (for SSDTs)
260 * OutTableHeader - The pointer to the table header to fill
262 * RETURN: Status and pointer to mapped table header
264 * DESCRIPTION: Finds an ACPI table header.
266 * NOTE: Caller is responsible in unmapping the header with
269 ******************************************************************************/
275 ACPI_TABLE_HEADER
*OutTableHeader
)
279 ACPI_TABLE_HEADER
*Header
;
282 /* Parameter validation */
284 if (!Signature
|| !OutTableHeader
)
286 return (AE_BAD_PARAMETER
);
289 /* Walk the root table list */
291 for (i
= 0, j
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
293 if (!ACPI_COMPARE_NAME (
294 &(AcpiGbl_RootTableList
.Tables
[i
].Signature
), Signature
))
304 if (!AcpiGbl_RootTableList
.Tables
[i
].Pointer
)
306 if ((AcpiGbl_RootTableList
.Tables
[i
].Flags
&
307 ACPI_TABLE_ORIGIN_MASK
) ==
308 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
)
310 Header
= AcpiOsMapMemory (
311 AcpiGbl_RootTableList
.Tables
[i
].Address
,
312 sizeof (ACPI_TABLE_HEADER
));
315 return (AE_NO_MEMORY
);
318 memcpy (OutTableHeader
, Header
, sizeof (ACPI_TABLE_HEADER
));
319 AcpiOsUnmapMemory (Header
, sizeof (ACPI_TABLE_HEADER
));
323 return (AE_NOT_FOUND
);
328 memcpy (OutTableHeader
,
329 AcpiGbl_RootTableList
.Tables
[i
].Pointer
,
330 sizeof (ACPI_TABLE_HEADER
));
336 return (AE_NOT_FOUND
);
339 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader
)
342 /*******************************************************************************
344 * FUNCTION: AcpiGetTable
346 * PARAMETERS: Signature - ACPI signature of needed table
347 * Instance - Which instance (for SSDTs)
348 * OutTable - Where the pointer to the table is returned
350 * RETURN: Status and pointer to the requested table
352 * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
354 * Note that an early stage AcpiGetTable() call must be paired
355 * with an early stage AcpiPutTable() call. otherwise the table
356 * pointer mapped by the early stage mapping implementation may be
357 * erroneously unmapped by the late stage unmapping implementation
358 * in an AcpiPutTable() invoked during the late stage.
360 ******************************************************************************/
366 ACPI_TABLE_HEADER
**OutTable
)
370 ACPI_STATUS Status
= AE_NOT_FOUND
;
371 ACPI_TABLE_DESC
*TableDesc
;
374 /* Parameter validation */
376 if (!Signature
|| !OutTable
)
378 return (AE_BAD_PARAMETER
);
382 * Note that the following line is required by some OSPMs, they only
383 * check if the returned table is NULL instead of the returned status
384 * to determined if this function is succeeded.
388 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
390 /* Walk the root table list */
392 for (i
= 0, j
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
394 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
396 if (!ACPI_COMPARE_NAME (&TableDesc
->Signature
, Signature
))
406 Status
= AcpiTbGetTable (TableDesc
, OutTable
);
410 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
414 ACPI_EXPORT_SYMBOL (AcpiGetTable
)
417 /*******************************************************************************
419 * FUNCTION: AcpiPutTable
421 * PARAMETERS: Table - The pointer to the table
425 * DESCRIPTION: Release a table returned by AcpiGetTable() and its clones.
426 * Note that it is not safe if this function was invoked after an
427 * uninstallation happened to the original table descriptor.
428 * Currently there is no OSPMs' requirement to handle such
431 ******************************************************************************/
435 ACPI_TABLE_HEADER
*Table
)
438 ACPI_TABLE_DESC
*TableDesc
;
441 ACPI_FUNCTION_TRACE (AcpiPutTable
);
449 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
451 /* Walk the root table list */
453 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
455 TableDesc
= &AcpiGbl_RootTableList
.Tables
[i
];
457 if (TableDesc
->Pointer
!= Table
)
462 AcpiTbPutTable (TableDesc
);
466 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
470 ACPI_EXPORT_SYMBOL (AcpiPutTable
)
473 /*******************************************************************************
475 * FUNCTION: AcpiGetTableByIndex
477 * PARAMETERS: TableIndex - Table index
478 * OutTable - Where the pointer to the table is returned
480 * RETURN: Status and pointer to the requested table
482 * DESCRIPTION: Obtain a table by an index into the global table list. Used
485 ******************************************************************************/
488 AcpiGetTableByIndex (
490 ACPI_TABLE_HEADER
**OutTable
)
495 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex
);
498 /* Parameter validation */
502 return_ACPI_STATUS (AE_BAD_PARAMETER
);
506 * Note that the following line is required by some OSPMs, they only
507 * check if the returned table is NULL instead of the returned status
508 * to determined if this function is succeeded.
512 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
516 if (TableIndex
>= AcpiGbl_RootTableList
.CurrentTableCount
)
518 Status
= AE_BAD_PARAMETER
;
522 Status
= AcpiTbGetTable (
523 &AcpiGbl_RootTableList
.Tables
[TableIndex
], OutTable
);
526 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
527 return_ACPI_STATUS (Status
);
530 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex
)
533 /*******************************************************************************
535 * FUNCTION: AcpiInstallTableHandler
537 * PARAMETERS: Handler - Table event handler
538 * Context - Value passed to the handler on each event
542 * DESCRIPTION: Install a global table event handler.
544 ******************************************************************************/
547 AcpiInstallTableHandler (
548 ACPI_TABLE_HANDLER Handler
,
554 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler
);
559 return_ACPI_STATUS (AE_BAD_PARAMETER
);
562 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
563 if (ACPI_FAILURE (Status
))
565 return_ACPI_STATUS (Status
);
568 /* Don't allow more than one handler */
570 if (AcpiGbl_TableHandler
)
572 Status
= AE_ALREADY_EXISTS
;
576 /* Install the handler */
578 AcpiGbl_TableHandler
= Handler
;
579 AcpiGbl_TableHandlerContext
= Context
;
582 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
583 return_ACPI_STATUS (Status
);
586 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler
)
589 /*******************************************************************************
591 * FUNCTION: AcpiRemoveTableHandler
593 * PARAMETERS: Handler - Table event handler that was installed
598 * DESCRIPTION: Remove a table event handler
600 ******************************************************************************/
603 AcpiRemoveTableHandler (
604 ACPI_TABLE_HANDLER Handler
)
609 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler
);
612 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
613 if (ACPI_FAILURE (Status
))
615 return_ACPI_STATUS (Status
);
618 /* Make sure that the installed handler is the same */
621 Handler
!= AcpiGbl_TableHandler
)
623 Status
= AE_BAD_PARAMETER
;
627 /* Remove the handler */
629 AcpiGbl_TableHandler
= NULL
;
632 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
633 return_ACPI_STATUS (Status
);
636 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler
)