1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, R. Byron Moore
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)
66 ACPI_FUNCTION_TRACE(tb_verify_table);
68 /* Map the table if necessary */
70 if (!table_desc->pointer) {
72 acpi_tb_map(table_desc->address, table_desc->length,
73 table_desc->flags & ACPI_TABLE_ORIGIN_MASK);
74 if (!table_desc->pointer) {
75 return_ACPI_STATUS(AE_NO_MEMORY);
79 /* FACS is the odd table, has no standard ACPI header and no checksum */
81 if (ACPI_COMPARE_NAME(&(table_desc->signature), ACPI_SIG_FACS)) {
82 return_ACPI_STATUS(AE_OK);
85 /* Always calculate checksum, ignore bad checksum if requested */
88 acpi_tb_verify_checksum(table_desc->pointer, table_desc->length);
89 return_ACPI_STATUS(status);
92 /*******************************************************************************
94 * FUNCTION: acpi_tb_add_table
96 * PARAMETERS: Table - Pointer to the table header
97 * table_index - Where the table index is returned
101 * DESCRIPTION: This function is called to add the ACPI table
103 ******************************************************************************/
106 acpi_tb_add_table(struct acpi_table_header *table,
107 acpi_native_uint * table_index)
110 acpi_native_uint length;
111 acpi_status status = AE_OK;
113 ACPI_FUNCTION_TRACE(tb_add_table);
115 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
117 /* Check if table is already registered */
119 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
120 if (!acpi_gbl_root_table_list.tables[i].pointer) {
122 acpi_tb_verify_table(&acpi_gbl_root_table_list.
124 if (ACPI_FAILURE(status)
125 || !acpi_gbl_root_table_list.tables[i].pointer) {
130 length = ACPI_MIN(table->length,
131 acpi_gbl_root_table_list.tables[i].pointer->
134 (table, acpi_gbl_root_table_list.tables[i].pointer,
139 /* Table is already registered */
147 * Add the table to the global table list
149 status = acpi_tb_store_table(ACPI_TO_INTEGER(table),
150 table, table->length,
151 ACPI_TABLE_ORIGIN_ALLOCATED, table_index);
152 if (ACPI_FAILURE(status)) {
156 acpi_tb_print_table_header(0, table);
159 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
160 return_ACPI_STATUS(status);
163 /*******************************************************************************
165 * FUNCTION: acpi_tb_resize_root_table_list
171 * DESCRIPTION: Expand the size of global table array
173 ******************************************************************************/
175 acpi_status acpi_tb_resize_root_table_list(void)
177 struct acpi_table_desc *tables;
179 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
181 /* allow_resize flag is a parameter to acpi_initialize_tables */
183 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
185 "Resize of Root Table Array is not allowed"));
186 return_ACPI_STATUS(AE_SUPPORT);
189 /* Increase the Table Array size */
191 tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size +
192 ACPI_ROOT_TABLE_SIZE_INCREMENT)
193 * sizeof(struct acpi_table_desc));
196 "Could not allocate new root table array"));
197 return_ACPI_STATUS(AE_NO_MEMORY);
200 /* Copy and free the previous table array */
202 if (acpi_gbl_root_table_list.tables) {
203 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
204 acpi_gbl_root_table_list.size *
205 sizeof(struct acpi_table_desc));
207 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
208 ACPI_FREE(acpi_gbl_root_table_list.tables);
212 acpi_gbl_root_table_list.tables = tables;
213 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
214 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
216 return_ACPI_STATUS(AE_OK);
219 /*******************************************************************************
221 * FUNCTION: acpi_tb_store_table
223 * PARAMETERS: Address - Table address
224 * Table - Table header
225 * Length - Table length
228 * RETURN: Status and table index.
230 * DESCRIPTION: Add an ACPI table to the global table list
232 ******************************************************************************/
235 acpi_tb_store_table(acpi_physical_address address,
236 struct acpi_table_header *table,
237 u32 length, u8 flags, acpi_native_uint * table_index)
239 acpi_status status = AE_OK;
241 /* Ensure that there is room for the table in the Root Table List */
243 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
244 status = acpi_tb_resize_root_table_list();
245 if (ACPI_FAILURE(status)) {
250 /* Initialize added table */
252 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
254 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
256 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
258 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
260 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
264 (acpi_gbl_root_table_list.
265 tables[acpi_gbl_root_table_list.count].signature),
268 *table_index = acpi_gbl_root_table_list.count;
269 acpi_gbl_root_table_list.count++;
273 /*******************************************************************************
275 * FUNCTION: acpi_tb_delete_table
277 * PARAMETERS: table_index - Table index
281 * DESCRIPTION: Delete one internal ACPI table
283 ******************************************************************************/
285 void acpi_tb_delete_table(acpi_native_uint table_index)
287 struct acpi_table_desc *table_desc;
289 /* table_index assumed valid */
291 table_desc = &acpi_gbl_root_table_list.tables[table_index];
293 /* Table must be mapped or allocated */
295 if (!table_desc->pointer) {
299 if (table_desc->flags & ACPI_TABLE_ORIGIN_MAPPED) {
300 acpi_tb_unmap(table_desc->pointer, table_desc->length,
301 table_desc->flags & ACPI_TABLE_ORIGIN_MASK);
302 } else if (table_desc->flags & ACPI_TABLE_ORIGIN_ALLOCATED) {
303 ACPI_FREE(table_desc->pointer);
306 table_desc->pointer = NULL;
309 /*******************************************************************************
311 * FUNCTION: acpi_tb_terminate
317 * DESCRIPTION: Delete all internal ACPI tables
319 ******************************************************************************/
321 void acpi_tb_terminate(void)
325 ACPI_FUNCTION_TRACE(tb_terminate);
327 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
329 /* Delete the individual tables */
331 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
332 acpi_tb_delete_table(i);
336 * Delete the root table array if allocated locally. Array cannot be
337 * mapped, so we don't need to check for that flag.
339 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
340 ACPI_FREE(acpi_gbl_root_table_list.tables);
343 acpi_gbl_root_table_list.tables = NULL;
344 acpi_gbl_root_table_list.flags = 0;
345 acpi_gbl_root_table_list.count = 0;
347 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
348 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
351 /*******************************************************************************
353 * FUNCTION: acpi_tb_delete_namespace_by_owner
355 * PARAMETERS: table_index - Table index
359 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
361 ******************************************************************************/
363 void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index)
365 acpi_owner_id owner_id;
367 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
368 if (table_index < acpi_gbl_root_table_list.count) {
370 acpi_gbl_root_table_list.tables[table_index].owner_id;
372 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
376 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
377 acpi_ns_delete_namespace_by_owner(owner_id);
380 /*******************************************************************************
382 * FUNCTION: acpi_tb_allocate_owner_id
384 * PARAMETERS: table_index - Table index
388 * DESCRIPTION: Allocates owner_id in table_desc
390 ******************************************************************************/
392 acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index)
394 acpi_status status = AE_BAD_PARAMETER;
396 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
398 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
399 if (table_index < acpi_gbl_root_table_list.count) {
400 status = acpi_ut_allocate_owner_id
401 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
404 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
405 return_ACPI_STATUS(status);
408 /*******************************************************************************
410 * FUNCTION: acpi_tb_release_owner_id
412 * PARAMETERS: table_index - Table index
416 * DESCRIPTION: Releases owner_id in table_desc
418 ******************************************************************************/
420 acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index)
422 acpi_status status = AE_BAD_PARAMETER;
424 ACPI_FUNCTION_TRACE(tb_release_owner_id);
426 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
427 if (table_index < acpi_gbl_root_table_list.count) {
428 acpi_ut_release_owner_id(&
429 (acpi_gbl_root_table_list.
430 tables[table_index].owner_id));
434 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
435 return_ACPI_STATUS(status);
438 /*******************************************************************************
440 * FUNCTION: acpi_tb_get_owner_id
442 * PARAMETERS: table_index - Table index
443 * owner_id - Where the table owner_id is returned
447 * DESCRIPTION: returns owner_id for the ACPI table
449 ******************************************************************************/
452 acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
454 acpi_status status = AE_BAD_PARAMETER;
456 ACPI_FUNCTION_TRACE(tb_get_owner_id);
458 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
459 if (table_index < acpi_gbl_root_table_list.count) {
461 acpi_gbl_root_table_list.tables[table_index].owner_id;
465 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
466 return_ACPI_STATUS(status);
469 /*******************************************************************************
471 * FUNCTION: acpi_tb_is_table_loaded
473 * PARAMETERS: table_index - Table index
475 * RETURN: Table Loaded Flag
477 ******************************************************************************/
479 u8 acpi_tb_is_table_loaded(acpi_native_uint table_index)
481 u8 is_loaded = FALSE;
483 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
484 if (table_index < acpi_gbl_root_table_list.count) {
486 (acpi_gbl_root_table_list.tables[table_index].
487 flags & ACPI_TABLE_IS_LOADED);
490 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
494 /*******************************************************************************
496 * FUNCTION: acpi_tb_set_table_loaded_flag
498 * PARAMETERS: table_index - Table index
499 * is_loaded - TRUE if table is loaded, FALSE otherwise
503 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
505 ******************************************************************************/
507 void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded)
510 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
511 if (table_index < acpi_gbl_root_table_list.count) {
513 acpi_gbl_root_table_list.tables[table_index].flags |=
514 ACPI_TABLE_IS_LOADED;
516 acpi_gbl_root_table_list.tables[table_index].flags &=
517 ~ACPI_TABLE_IS_LOADED;
521 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);