1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2007, R. Byron Moore
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/actables.h>
49 #define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME("tbxface")
52 /* Local prototypes */
53 static acpi_status
acpi_tb_load_namespace(void);
55 /*******************************************************************************
57 * FUNCTION: acpi_allocate_root_table
59 * PARAMETERS: initial_table_count - Size of initial_table_array, in number of
60 * struct acpi_table_desc structures
64 * DESCRIPTION: Allocate a root table array. Used by i_aSL compiler and
65 * acpi_initialize_tables.
67 ******************************************************************************/
69 acpi_status
acpi_allocate_root_table(u32 initial_table_count
)
72 acpi_gbl_root_table_list
.size
= initial_table_count
;
73 acpi_gbl_root_table_list
.flags
= ACPI_ROOT_ALLOW_RESIZE
;
75 return (acpi_tb_resize_root_table_list());
78 /*******************************************************************************
80 * FUNCTION: acpi_initialize_tables
82 * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated
83 * struct acpi_table_desc structures. If NULL, the
84 * array is dynamically allocated.
85 * initial_table_count - Size of initial_table_array, in number of
86 * struct acpi_table_desc structures
87 * allow_realloc - Flag to tell Table Manager if resize of
88 * pre-allocated array is allowed. Ignored
89 * if initial_table_array is NULL.
93 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
95 * NOTE: Allows static allocation of the initial table array in order
96 * to avoid the use of dynamic memory in confined environments
97 * such as the kernel boot sequence where it may not be available.
99 * If the host OS memory managers are initialized, use NULL for
100 * initial_table_array, and the table will be dynamically allocated.
102 ******************************************************************************/
105 acpi_initialize_tables(struct acpi_table_desc
* initial_table_array
,
106 u32 initial_table_count
, u8 allow_resize
)
108 acpi_physical_address rsdp_address
;
111 ACPI_FUNCTION_TRACE(acpi_initialize_tables
);
114 * Set up the Root Table Array
115 * Allocate the table array if requested
117 if (!initial_table_array
) {
118 status
= acpi_allocate_root_table(initial_table_count
);
119 if (ACPI_FAILURE(status
)) {
120 return_ACPI_STATUS(status
);
123 /* Root Table Array has been statically allocated by the host */
125 ACPI_MEMSET(initial_table_array
, 0,
126 initial_table_count
*
127 sizeof(struct acpi_table_desc
));
129 acpi_gbl_root_table_list
.tables
= initial_table_array
;
130 acpi_gbl_root_table_list
.size
= initial_table_count
;
131 acpi_gbl_root_table_list
.flags
= ACPI_ROOT_ORIGIN_UNKNOWN
;
133 acpi_gbl_root_table_list
.flags
|=
134 ACPI_ROOT_ALLOW_RESIZE
;
138 /* Get the address of the RSDP */
140 rsdp_address
= acpi_os_get_root_pointer();
142 return_ACPI_STATUS(AE_NOT_FOUND
);
146 * Get the root table (RSDT or XSDT) and extract all entries to the local
147 * Root Table Array. This array contains the information of the RSDT/XSDT
148 * in a common, more useable format.
151 acpi_tb_parse_root_table(rsdp_address
, ACPI_TABLE_ORIGIN_MAPPED
);
152 return_ACPI_STATUS(status
);
155 /*******************************************************************************
157 * FUNCTION: acpi_reallocate_root_table
163 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
164 * root list from the previously provided scratch area. Should
165 * be called once dynamic memory allocation is available in the
168 ******************************************************************************/
169 acpi_status
acpi_reallocate_root_table(void)
171 struct acpi_table_desc
*tables
;
174 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table
);
177 * Only reallocate the root table if the host provided a static buffer
178 * for the table array in the call to acpi_initialize_tables.
180 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
181 return_ACPI_STATUS(AE_SUPPORT
);
185 (acpi_gbl_root_table_list
.count
+
186 ACPI_ROOT_TABLE_SIZE_INCREMENT
) * sizeof(struct acpi_table_desc
);
188 /* Create new array and copy the old array */
190 tables
= ACPI_ALLOCATE_ZEROED(new_size
);
192 return_ACPI_STATUS(AE_NO_MEMORY
);
195 ACPI_MEMCPY(tables
, acpi_gbl_root_table_list
.tables
, new_size
);
197 acpi_gbl_root_table_list
.size
= acpi_gbl_root_table_list
.count
;
198 acpi_gbl_root_table_list
.tables
= tables
;
199 acpi_gbl_root_table_list
.flags
=
200 ACPI_ROOT_ORIGIN_ALLOCATED
| ACPI_ROOT_ALLOW_RESIZE
;
202 return_ACPI_STATUS(AE_OK
);
204 /*******************************************************************************
206 * FUNCTION: acpi_load_table
208 * PARAMETERS: table_ptr - pointer to a buffer containing the entire
213 * DESCRIPTION: This function is called to load a table from the caller's
214 * buffer. The buffer must contain an entire ACPI Table including
215 * a valid header. The header fields will be verified, and if it
216 * is determined that the table is invalid, the call will fail.
218 ******************************************************************************/
219 acpi_status
acpi_load_table(struct acpi_table_header
*table_ptr
)
222 acpi_native_uint table_index
;
223 struct acpi_table_desc table_desc
;
226 return AE_BAD_PARAMETER
;
228 ACPI_MEMSET(&table_desc
, 0, sizeof(struct acpi_table_desc
));
229 table_desc
.pointer
= table_ptr
;
230 table_desc
.length
= table_ptr
->length
;
231 table_desc
.flags
= ACPI_TABLE_ORIGIN_UNKNOWN
;
234 * Install the new table into the local data structures
236 status
= acpi_tb_add_table(&table_desc
, &table_index
);
237 if (ACPI_FAILURE(status
)) {
240 status
= acpi_ns_load_table(table_index
, acpi_gbl_root_node
);
244 ACPI_EXPORT_SYMBOL(acpi_load_table
)
246 /******************************************************************************
248 * FUNCTION: acpi_get_table_header
250 * PARAMETERS: Signature - ACPI signature of needed table
251 * Instance - Which instance (for SSDTs)
252 * out_table_header - The pointer to the table header to fill
254 * RETURN: Status and pointer to mapped table header
256 * DESCRIPTION: Finds an ACPI table header.
258 * NOTE: Caller is responsible in unmapping the header with
259 * acpi_os_unmap_memory
261 *****************************************************************************/
263 acpi_get_table_header(char *signature
,
264 acpi_native_uint instance
,
265 struct acpi_table_header
*out_table_header
)
269 struct acpi_table_header
*header
;
271 /* Parameter validation */
273 if (!signature
|| !out_table_header
) {
274 return (AE_BAD_PARAMETER
);
278 * Walk the root table list
280 for (i
= 0, j
= 0; i
< acpi_gbl_root_table_list
.count
; i
++) {
281 if (!ACPI_COMPARE_NAME
282 (&(acpi_gbl_root_table_list
.tables
[i
].signature
),
287 if (++j
< instance
) {
291 if (!acpi_gbl_root_table_list
.tables
[i
].pointer
) {
292 if ((acpi_gbl_root_table_list
.tables
[i
].
293 flags
& ACPI_TABLE_ORIGIN_MASK
) ==
294 ACPI_TABLE_ORIGIN_MAPPED
) {
296 acpi_os_map_memory(acpi_gbl_root_table_list
.
303 ACPI_MEMCPY(out_table_header
, header
,
304 sizeof(struct acpi_table_header
));
305 acpi_os_unmap_memory(header
,
312 ACPI_MEMCPY(out_table_header
,
313 acpi_gbl_root_table_list
.tables
[i
].pointer
,
314 sizeof(struct acpi_table_header
));
319 return (AE_NOT_FOUND
);
322 ACPI_EXPORT_SYMBOL(acpi_get_table_header
)
325 /******************************************************************************
327 * FUNCTION: acpi_unload_table_id
329 * PARAMETERS: id - Owner ID of the table to be removed.
333 * DESCRIPTION: This routine is used to force the unload of a table (by id)
335 ******************************************************************************/
336 acpi_status
acpi_unload_table_id(acpi_owner_id id
)
339 acpi_status status
= AE_NOT_EXIST
;
341 ACPI_FUNCTION_TRACE(acpi_unload_table
);
343 /* Find table from the requested type list */
344 for (i
= 0; i
< acpi_gbl_root_table_list
.count
; ++i
) {
345 if (id
!= acpi_gbl_root_table_list
.tables
[i
].owner_id
) {
349 * Delete all namespace objects owned by this table. Note that these
350 * objects can appear anywhere in the namespace by virtue of the AML
351 * "Scope" operator. Thus, we need to track ownership by an ID, not
352 * simply a position within the hierarchy
354 acpi_tb_delete_namespace_by_owner(i
);
355 acpi_tb_release_owner_id(i
);
356 acpi_tb_set_table_loaded_flag(i
, FALSE
);
358 return_ACPI_STATUS(status
);
361 ACPI_EXPORT_SYMBOL(acpi_unload_table_id
)
363 /*******************************************************************************
365 * FUNCTION: acpi_get_table
367 * PARAMETERS: Signature - ACPI signature of needed table
368 * Instance - Which instance (for SSDTs)
369 * out_table - Where the pointer to the table is returned
371 * RETURN: Status and pointer to table
373 * DESCRIPTION: Finds and verifies an ACPI table.
375 *****************************************************************************/
377 acpi_get_table(char *signature
,
378 acpi_native_uint instance
, struct acpi_table_header
** out_table
)
384 /* Parameter validation */
386 if (!signature
|| !out_table
) {
387 return (AE_BAD_PARAMETER
);
391 * Walk the root table list
393 for (i
= 0, j
= 0; i
< acpi_gbl_root_table_list
.count
; i
++) {
394 if (!ACPI_COMPARE_NAME
395 (&(acpi_gbl_root_table_list
.tables
[i
].signature
),
400 if (++j
< instance
) {
405 acpi_tb_verify_table(&acpi_gbl_root_table_list
.tables
[i
]);
406 if (ACPI_SUCCESS(status
)) {
407 *out_table
= acpi_gbl_root_table_list
.tables
[i
].pointer
;
410 if (!acpi_gbl_permanent_mmap
) {
411 acpi_gbl_root_table_list
.tables
[i
].pointer
= NULL
;
417 return (AE_NOT_FOUND
);
420 ACPI_EXPORT_SYMBOL(acpi_get_table
)
422 /*******************************************************************************
424 * FUNCTION: acpi_get_table_by_index
426 * PARAMETERS: table_index - Table index
427 * Table - Where the pointer to the table is returned
429 * RETURN: Status and pointer to the table
431 * DESCRIPTION: Obtain a table by an index into the global table list.
433 ******************************************************************************/
435 acpi_get_table_by_index(acpi_native_uint table_index
,
436 struct acpi_table_header
** table
)
440 ACPI_FUNCTION_TRACE(acpi_get_table_by_index
);
442 /* Parameter validation */
445 return_ACPI_STATUS(AE_BAD_PARAMETER
);
448 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
452 if (table_index
>= acpi_gbl_root_table_list
.count
) {
453 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
454 return_ACPI_STATUS(AE_BAD_PARAMETER
);
457 if (!acpi_gbl_root_table_list
.tables
[table_index
].pointer
) {
459 /* Table is not mapped, map it */
462 acpi_tb_verify_table(&acpi_gbl_root_table_list
.
463 tables
[table_index
]);
464 if (ACPI_FAILURE(status
)) {
465 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
466 return_ACPI_STATUS(status
);
470 *table
= acpi_gbl_root_table_list
.tables
[table_index
].pointer
;
471 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
472 return_ACPI_STATUS(AE_OK
);
475 ACPI_EXPORT_SYMBOL(acpi_get_table_by_index
)
477 /*******************************************************************************
479 * FUNCTION: acpi_tb_load_namespace
485 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
488 ******************************************************************************/
489 static acpi_status
acpi_tb_load_namespace(void)
492 struct acpi_table_header
*table
;
495 ACPI_FUNCTION_TRACE(tb_load_namespace
);
497 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
500 * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
503 if (!acpi_gbl_root_table_list
.count
||
505 (acpi_gbl_root_table_list
.
506 tables
[ACPI_TABLE_INDEX_DSDT
].signature
),
509 ACPI_FAILURE(acpi_tb_verify_table
510 (&acpi_gbl_root_table_list
.
511 tables
[ACPI_TABLE_INDEX_DSDT
]))) {
512 status
= AE_NO_ACPI_TABLES
;
513 goto unlock_and_exit
;
520 acpi_os_table_override(acpi_gbl_root_table_list
.
521 tables
[ACPI_TABLE_INDEX_DSDT
].pointer
,
523 if (ACPI_SUCCESS(status
) && table
) {
525 * DSDT table has been found
527 acpi_tb_delete_table(&acpi_gbl_root_table_list
.
528 tables
[ACPI_TABLE_INDEX_DSDT
]);
529 acpi_gbl_root_table_list
.tables
[ACPI_TABLE_INDEX_DSDT
].pointer
=
531 acpi_gbl_root_table_list
.tables
[ACPI_TABLE_INDEX_DSDT
].length
=
533 acpi_gbl_root_table_list
.tables
[ACPI_TABLE_INDEX_DSDT
].flags
=
534 ACPI_TABLE_ORIGIN_UNKNOWN
;
536 ACPI_INFO((AE_INFO
, "Table DSDT replaced by host OS"));
537 acpi_tb_print_table_header(0, table
);
541 acpi_tb_verify_table(&acpi_gbl_root_table_list
.
542 tables
[ACPI_TABLE_INDEX_DSDT
]);
543 if (ACPI_FAILURE(status
)) {
545 /* A valid DSDT is required */
547 status
= AE_NO_ACPI_TABLES
;
548 goto unlock_and_exit
;
551 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
554 * Load and parse tables.
556 status
= acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT
, acpi_gbl_root_node
);
557 if (ACPI_FAILURE(status
)) {
558 return_ACPI_STATUS(status
);
562 * Load any SSDT or PSDT tables. Note: Loop leaves tables locked
564 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
565 for (i
= 0; i
< acpi_gbl_root_table_list
.count
; ++i
) {
566 if ((!ACPI_COMPARE_NAME
567 (&(acpi_gbl_root_table_list
.tables
[i
].signature
),
571 (acpi_gbl_root_table_list
.tables
[i
].
572 signature
), ACPI_SIG_PSDT
))
574 ACPI_FAILURE(acpi_tb_verify_table
575 (&acpi_gbl_root_table_list
.tables
[i
]))) {
579 /* Ignore errors while loading tables, get as many as possible */
581 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
582 (void)acpi_ns_load_table(i
, acpi_gbl_root_node
);
583 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
586 ACPI_DEBUG_PRINT((ACPI_DB_INIT
, "ACPI Tables successfully acquired\n"));
589 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
590 return_ACPI_STATUS(status
);
593 /*******************************************************************************
595 * FUNCTION: acpi_load_tables
601 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
603 ******************************************************************************/
605 acpi_status
acpi_load_tables(void)
609 ACPI_FUNCTION_TRACE(acpi_load_tables
);
612 * Load the namespace from the tables
614 status
= acpi_tb_load_namespace();
615 if (ACPI_FAILURE(status
)) {
616 ACPI_EXCEPTION((AE_INFO
, status
,
617 "While loading namespace from ACPI tables"));
620 return_ACPI_STATUS(status
);
623 ACPI_EXPORT_SYMBOL(acpi_load_tables
)