1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, 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 #include <acpi/acpi.h>
45 #include <acpi/acnamesp.h>
46 #include <acpi/actables.h>
48 #define _COMPONENT ACPI_TABLES
49 ACPI_MODULE_NAME("tbinstal")
51 /******************************************************************************
53 * FUNCTION: acpi_tb_verify_table
55 * PARAMETERS: table_desc - table
59 * DESCRIPTION: this function is called to verify and map table
61 *****************************************************************************/
62 acpi_status
acpi_tb_verify_table(struct acpi_table_desc
*table_desc
)
64 acpi_status status
= AE_OK
;
66 ACPI_FUNCTION_TRACE(tb_verify_table
);
68 /* Map the table if necessary */
70 if (!table_desc
->pointer
) {
71 if ((table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) ==
72 ACPI_TABLE_ORIGIN_MAPPED
) {
74 acpi_os_map_memory(table_desc
->address
,
77 if (!table_desc
->pointer
) {
78 return_ACPI_STATUS(AE_NO_MEMORY
);
82 /* FACS is the odd table, has no standard ACPI header and no checksum */
84 if (!ACPI_COMPARE_NAME(&table_desc
->signature
, ACPI_SIG_FACS
)) {
86 /* Always calculate checksum, ignore bad checksum if requested */
89 acpi_tb_verify_checksum(table_desc
->pointer
,
93 return_ACPI_STATUS(status
);
96 /*******************************************************************************
98 * FUNCTION: acpi_tb_add_table
100 * PARAMETERS: table_desc - Table descriptor
101 * table_index - Where the table index is returned
105 * DESCRIPTION: This function is called to add the ACPI table
107 ******************************************************************************/
110 acpi_tb_add_table(struct acpi_table_desc
*table_desc
,
111 acpi_native_uint
* table_index
)
114 acpi_native_uint length
;
115 acpi_status status
= AE_OK
;
117 ACPI_FUNCTION_TRACE(tb_add_table
);
119 if (!table_desc
->pointer
) {
120 status
= acpi_tb_verify_table(table_desc
);
121 if (ACPI_FAILURE(status
) || !table_desc
->pointer
) {
122 return_ACPI_STATUS(status
);
127 * Originally, we checked the table signature for "SSDT" or "PSDT" here.
128 * Next, we added support for OEMx tables, signature "OEM".
129 * Valid tables were encountered with a null signature, so we've just
130 * given up on validating the signature, since it seems to be a waste
131 * of code. The original code was removed (05/2008).
134 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
136 /* Check if table is already registered */
138 for (i
= 0; i
< acpi_gbl_root_table_list
.count
; ++i
) {
139 if (!acpi_gbl_root_table_list
.tables
[i
].pointer
) {
141 acpi_tb_verify_table(&acpi_gbl_root_table_list
.
143 if (ACPI_FAILURE(status
)
144 || !acpi_gbl_root_table_list
.tables
[i
].pointer
) {
149 length
= ACPI_MIN(table_desc
->length
,
150 acpi_gbl_root_table_list
.tables
[i
].length
);
151 if (ACPI_MEMCMP(table_desc
->pointer
,
152 acpi_gbl_root_table_list
.tables
[i
].pointer
,
157 /* Table is already registered */
159 acpi_tb_delete_table(table_desc
);
161 status
= AE_ALREADY_EXISTS
;
166 * Add the table to the global table list
168 status
= acpi_tb_store_table(table_desc
->address
, table_desc
->pointer
,
169 table_desc
->length
, table_desc
->flags
,
171 if (ACPI_FAILURE(status
)) {
175 acpi_tb_print_table_header(table_desc
->address
, table_desc
->pointer
);
178 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
179 return_ACPI_STATUS(status
);
182 /*******************************************************************************
184 * FUNCTION: acpi_tb_resize_root_table_list
190 * DESCRIPTION: Expand the size of global table array
192 ******************************************************************************/
194 acpi_status
acpi_tb_resize_root_table_list(void)
196 struct acpi_table_desc
*tables
;
198 ACPI_FUNCTION_TRACE(tb_resize_root_table_list
);
200 /* allow_resize flag is a parameter to acpi_initialize_tables */
202 if (!(acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ALLOW_RESIZE
)) {
204 "Resize of Root Table Array is not allowed"));
205 return_ACPI_STATUS(AE_SUPPORT
);
208 /* Increase the Table Array size */
210 tables
= ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list
.size
+
211 ACPI_ROOT_TABLE_SIZE_INCREMENT
)
212 * sizeof(struct acpi_table_desc
));
215 "Could not allocate new root table array"));
216 return_ACPI_STATUS(AE_NO_MEMORY
);
219 /* Copy and free the previous table array */
221 if (acpi_gbl_root_table_list
.tables
) {
222 ACPI_MEMCPY(tables
, acpi_gbl_root_table_list
.tables
,
223 acpi_gbl_root_table_list
.size
*
224 sizeof(struct acpi_table_desc
));
226 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
227 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
231 acpi_gbl_root_table_list
.tables
= tables
;
232 acpi_gbl_root_table_list
.size
+= ACPI_ROOT_TABLE_SIZE_INCREMENT
;
233 acpi_gbl_root_table_list
.flags
|= (u8
) ACPI_ROOT_ORIGIN_ALLOCATED
;
235 return_ACPI_STATUS(AE_OK
);
238 /*******************************************************************************
240 * FUNCTION: acpi_tb_store_table
242 * PARAMETERS: Address - Table address
243 * Table - Table header
244 * Length - Table length
247 * RETURN: Status and table index.
249 * DESCRIPTION: Add an ACPI table to the global table list
251 ******************************************************************************/
254 acpi_tb_store_table(acpi_physical_address address
,
255 struct acpi_table_header
*table
,
256 u32 length
, u8 flags
, acpi_native_uint
* table_index
)
258 acpi_status status
= AE_OK
;
260 /* Ensure that there is room for the table in the Root Table List */
262 if (acpi_gbl_root_table_list
.count
>= acpi_gbl_root_table_list
.size
) {
263 status
= acpi_tb_resize_root_table_list();
264 if (ACPI_FAILURE(status
)) {
269 /* Initialize added table */
271 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
273 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
275 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].length
=
277 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
279 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].flags
=
283 (acpi_gbl_root_table_list
.
284 tables
[acpi_gbl_root_table_list
.count
].signature
),
287 *table_index
= acpi_gbl_root_table_list
.count
;
288 acpi_gbl_root_table_list
.count
++;
292 /*******************************************************************************
294 * FUNCTION: acpi_tb_delete_table
296 * PARAMETERS: table_index - Table index
300 * DESCRIPTION: Delete one internal ACPI table
302 ******************************************************************************/
304 void acpi_tb_delete_table(struct acpi_table_desc
*table_desc
)
306 /* Table must be mapped or allocated */
307 if (!table_desc
->pointer
) {
310 switch (table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) {
311 case ACPI_TABLE_ORIGIN_MAPPED
:
312 acpi_os_unmap_memory(table_desc
->pointer
, table_desc
->length
);
314 case ACPI_TABLE_ORIGIN_ALLOCATED
:
315 ACPI_FREE(table_desc
->pointer
);
320 table_desc
->pointer
= NULL
;
323 /*******************************************************************************
325 * FUNCTION: acpi_tb_terminate
331 * DESCRIPTION: Delete all internal ACPI tables
333 ******************************************************************************/
335 void acpi_tb_terminate(void)
339 ACPI_FUNCTION_TRACE(tb_terminate
);
341 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
343 /* Delete the individual tables */
345 for (i
= 0; i
< acpi_gbl_root_table_list
.count
; ++i
) {
346 acpi_tb_delete_table(&acpi_gbl_root_table_list
.tables
[i
]);
350 * Delete the root table array if allocated locally. Array cannot be
351 * mapped, so we don't need to check for that flag.
353 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
354 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
357 acpi_gbl_root_table_list
.tables
= NULL
;
358 acpi_gbl_root_table_list
.flags
= 0;
359 acpi_gbl_root_table_list
.count
= 0;
361 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "ACPI Tables freed\n"));
362 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
365 /*******************************************************************************
367 * FUNCTION: acpi_tb_delete_namespace_by_owner
369 * PARAMETERS: table_index - Table index
373 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
375 ******************************************************************************/
377 void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index
)
379 acpi_owner_id owner_id
;
381 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
382 if (table_index
< acpi_gbl_root_table_list
.count
) {
384 acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
386 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
390 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
391 acpi_ns_delete_namespace_by_owner(owner_id
);
394 /*******************************************************************************
396 * FUNCTION: acpi_tb_allocate_owner_id
398 * PARAMETERS: table_index - Table index
402 * DESCRIPTION: Allocates owner_id in table_desc
404 ******************************************************************************/
406 acpi_status
acpi_tb_allocate_owner_id(acpi_native_uint table_index
)
408 acpi_status status
= AE_BAD_PARAMETER
;
410 ACPI_FUNCTION_TRACE(tb_allocate_owner_id
);
412 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
413 if (table_index
< acpi_gbl_root_table_list
.count
) {
414 status
= acpi_ut_allocate_owner_id
415 (&(acpi_gbl_root_table_list
.tables
[table_index
].owner_id
));
418 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
419 return_ACPI_STATUS(status
);
422 /*******************************************************************************
424 * FUNCTION: acpi_tb_release_owner_id
426 * PARAMETERS: table_index - Table index
430 * DESCRIPTION: Releases owner_id in table_desc
432 ******************************************************************************/
434 acpi_status
acpi_tb_release_owner_id(acpi_native_uint table_index
)
436 acpi_status status
= AE_BAD_PARAMETER
;
438 ACPI_FUNCTION_TRACE(tb_release_owner_id
);
440 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
441 if (table_index
< acpi_gbl_root_table_list
.count
) {
442 acpi_ut_release_owner_id(&
443 (acpi_gbl_root_table_list
.
444 tables
[table_index
].owner_id
));
448 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
449 return_ACPI_STATUS(status
);
452 /*******************************************************************************
454 * FUNCTION: acpi_tb_get_owner_id
456 * PARAMETERS: table_index - Table index
457 * owner_id - Where the table owner_id is returned
461 * DESCRIPTION: returns owner_id for the ACPI table
463 ******************************************************************************/
466 acpi_tb_get_owner_id(acpi_native_uint table_index
, acpi_owner_id
* owner_id
)
468 acpi_status status
= AE_BAD_PARAMETER
;
470 ACPI_FUNCTION_TRACE(tb_get_owner_id
);
472 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
473 if (table_index
< acpi_gbl_root_table_list
.count
) {
475 acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
479 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
480 return_ACPI_STATUS(status
);
483 /*******************************************************************************
485 * FUNCTION: acpi_tb_is_table_loaded
487 * PARAMETERS: table_index - Table index
489 * RETURN: Table Loaded Flag
491 ******************************************************************************/
493 u8
acpi_tb_is_table_loaded(acpi_native_uint table_index
)
495 u8 is_loaded
= FALSE
;
497 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
498 if (table_index
< acpi_gbl_root_table_list
.count
) {
500 (acpi_gbl_root_table_list
.tables
[table_index
].
501 flags
& ACPI_TABLE_IS_LOADED
);
504 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
508 /*******************************************************************************
510 * FUNCTION: acpi_tb_set_table_loaded_flag
512 * PARAMETERS: table_index - Table index
513 * is_loaded - TRUE if table is loaded, FALSE otherwise
517 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
519 ******************************************************************************/
521 void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index
, u8 is_loaded
)
524 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
525 if (table_index
< acpi_gbl_root_table_list
.count
) {
527 acpi_gbl_root_table_list
.tables
[table_index
].flags
|=
528 ACPI_TABLE_IS_LOADED
;
530 acpi_gbl_root_table_list
.tables
[table_index
].flags
&=
531 ~ACPI_TABLE_IS_LOADED
;
535 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);