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 */
87 checksum = acpi_tb_checksum(ACPI_CAST_PTR(void, table_desc->pointer),
90 #if (ACPI_CHECKSUM_ABORT)
93 return_ACPI_STATUS(AE_BAD_CHECKSUM);
97 return_ACPI_STATUS(AE_OK);
100 /*******************************************************************************
102 * FUNCTION: acpi_tb_add_table
104 * PARAMETERS: Table - Pointer to the table header
105 * table_index - Where the table index is returned
109 * DESCRIPTION: This function is called to add the ACPI table
111 ******************************************************************************/
114 acpi_tb_add_table(struct acpi_table_header *table,
115 acpi_native_uint * table_index)
118 acpi_native_uint length;
119 acpi_status status = AE_OK;
121 ACPI_FUNCTION_TRACE(tb_add_table);
123 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
125 /* Check if table is already registered */
127 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
128 if (!acpi_gbl_root_table_list.tables[i].pointer) {
130 acpi_tb_verify_table(&acpi_gbl_root_table_list.
132 if (ACPI_FAILURE(status)
133 || !acpi_gbl_root_table_list.tables[i].pointer) {
138 length = ACPI_MIN(table->length,
139 acpi_gbl_root_table_list.tables[i].pointer->
142 (table, acpi_gbl_root_table_list.tables[i].pointer,
147 /* Table is already registered */
155 * Add the table to the global table list
157 status = acpi_tb_store_table(ACPI_TO_INTEGER(table),
158 table, table->length,
159 ACPI_TABLE_ORIGIN_ALLOCATED, table_index);
160 if (ACPI_FAILURE(status)) {
164 acpi_tb_print_table_header(0, table);
167 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
168 return_ACPI_STATUS(status);
171 /*******************************************************************************
173 * FUNCTION: acpi_tb_resize_root_table_list
179 * DESCRIPTION: Expand the size of global table array
181 ******************************************************************************/
183 acpi_status acpi_tb_resize_root_table_list(void)
185 struct acpi_table_desc *tables;
187 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
189 /* allow_resize flag is a parameter to acpi_initialize_tables */
191 if (!(acpi_gbl_root_table_list.flags & ACPI_TABLE_FLAGS_ALLOW_RESIZE)) {
193 "Resize of Root Table Array is not allowed"));
194 return_ACPI_STATUS(AE_SUPPORT);
197 /* Increase the Table Array size */
199 tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size +
200 ACPI_ROOT_TABLE_SIZE_INCREMENT)
201 * sizeof(struct acpi_table_desc));
204 "Could not allocate new root table array"));
205 return_ACPI_STATUS(AE_NO_MEMORY);
208 /* Copy and free the previous table array */
210 if (acpi_gbl_root_table_list.tables) {
211 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
212 acpi_gbl_root_table_list.size *
213 sizeof(struct acpi_table_desc));
215 if (acpi_gbl_root_table_list.flags & ACPI_TABLE_ORIGIN_MASK ==
216 ACPI_TABLE_ORIGIN_ALLOCATED) {
217 ACPI_FREE(acpi_gbl_root_table_list.tables);
221 acpi_gbl_root_table_list.tables = tables;
222 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
223 acpi_gbl_root_table_list.flags = (u8) (ACPI_TABLE_ORIGIN_ALLOCATED |
224 (acpi_gbl_root_table_list.
226 ~ACPI_TABLE_ORIGIN_MASK));
228 return_ACPI_STATUS(AE_OK);
231 /*******************************************************************************
233 * FUNCTION: acpi_tb_store_table
235 * PARAMETERS: Address - Table address
236 * Table - Table header
237 * Length - Table length
240 * RETURN: Status and table index.
242 * DESCRIPTION: Add an ACPI table to the global table list
244 ******************************************************************************/
247 acpi_tb_store_table(acpi_physical_address address,
248 struct acpi_table_header *table,
249 u32 length, u8 flags, acpi_native_uint * table_index)
251 acpi_status status = AE_OK;
253 /* Ensure that there is room for the table in the Root Table List */
255 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
256 status = acpi_tb_resize_root_table_list();
257 if (ACPI_FAILURE(status)) {
262 /* Initialize added table */
264 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
266 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
268 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
270 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
272 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
276 (acpi_gbl_root_table_list.
277 tables[acpi_gbl_root_table_list.count].signature),
280 *table_index = acpi_gbl_root_table_list.count;
281 acpi_gbl_root_table_list.count++;
285 /*******************************************************************************
287 * FUNCTION: acpi_tb_delete_table
289 * PARAMETERS: table_index - Table index
293 * DESCRIPTION: Delete one internal ACPI table
295 ******************************************************************************/
297 void acpi_tb_delete_table(acpi_native_uint table_index)
299 struct acpi_table_desc *table_desc;
301 /* table_index assumed valid */
303 table_desc = &acpi_gbl_root_table_list.tables[table_index];
305 /* Table must be mapped or allocated */
307 if (!table_desc->pointer) {
311 if (table_desc->flags & ACPI_TABLE_ORIGIN_MAPPED) {
312 acpi_tb_unmap(table_desc->pointer, table_desc->length,
313 table_desc->flags & ACPI_TABLE_ORIGIN_MASK);
314 } else if (table_desc->flags & ACPI_TABLE_ORIGIN_ALLOCATED) {
315 ACPI_FREE(table_desc->pointer);
318 table_desc->pointer = NULL;
321 /*******************************************************************************
323 * FUNCTION: acpi_tb_terminate
329 * DESCRIPTION: Delete all internal ACPI tables
331 ******************************************************************************/
333 void acpi_tb_terminate(void)
337 ACPI_FUNCTION_TRACE(tb_terminate);
339 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
341 /* Delete the individual tables */
343 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
344 acpi_tb_delete_table(i);
348 * Delete the root table array if allocated locally. Array cannot be
349 * mapped, so we don't need to check for that flag.
351 if ((acpi_gbl_root_table_list.flags & ACPI_TABLE_ORIGIN_MASK) ==
352 ACPI_TABLE_ORIGIN_ALLOCATED) {
353 ACPI_FREE(acpi_gbl_root_table_list.tables);
356 acpi_gbl_root_table_list.tables = NULL;
357 acpi_gbl_root_table_list.flags = 0;
358 acpi_gbl_root_table_list.count = 0;
360 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
361 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
364 /*******************************************************************************
366 * FUNCTION: acpi_tb_delete_namespace_by_owner
368 * PARAMETERS: table_index - Table index
372 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
374 ******************************************************************************/
376 void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index)
378 acpi_owner_id owner_id;
380 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
381 if (table_index < acpi_gbl_root_table_list.count) {
383 acpi_gbl_root_table_list.tables[table_index].owner_id;
385 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
389 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
390 acpi_ns_delete_namespace_by_owner(owner_id);
393 /*******************************************************************************
395 * FUNCTION: acpi_tb_allocate_owner_id
397 * PARAMETERS: table_index - Table index
401 * DESCRIPTION: Allocates owner_id in table_desc
403 ******************************************************************************/
405 acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index)
407 acpi_status status = AE_BAD_PARAMETER;
409 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
411 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
412 if (table_index < acpi_gbl_root_table_list.count) {
413 status = acpi_ut_allocate_owner_id
414 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
417 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
418 return_ACPI_STATUS(status);
421 /*******************************************************************************
423 * FUNCTION: acpi_tb_release_owner_id
425 * PARAMETERS: table_index - Table index
429 * DESCRIPTION: Releases owner_id in table_desc
431 ******************************************************************************/
433 acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index)
435 acpi_status status = AE_BAD_PARAMETER;
437 ACPI_FUNCTION_TRACE(tb_release_owner_id);
439 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
440 if (table_index < acpi_gbl_root_table_list.count) {
441 acpi_ut_release_owner_id(&
442 (acpi_gbl_root_table_list.
443 tables[table_index].owner_id));
447 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
448 return_ACPI_STATUS(status);
451 /*******************************************************************************
453 * FUNCTION: acpi_tb_get_owner_id
455 * PARAMETERS: table_index - Table index
456 * owner_id - Where the table owner_id is returned
460 * DESCRIPTION: returns owner_id for the ACPI table
462 ******************************************************************************/
465 acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
467 acpi_status status = AE_BAD_PARAMETER;
469 ACPI_FUNCTION_TRACE(tb_get_owner_id);
471 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
472 if (table_index < acpi_gbl_root_table_list.count) {
474 acpi_gbl_root_table_list.tables[table_index].owner_id;
478 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
479 return_ACPI_STATUS(status);
482 /*******************************************************************************
484 * FUNCTION: acpi_tb_is_table_loaded
486 * PARAMETERS: table_index - Table index
488 * RETURN: Table Loaded Flag
490 ******************************************************************************/
492 u8 acpi_tb_is_table_loaded(acpi_native_uint table_index)
494 u8 is_loaded = FALSE;
496 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
497 if (table_index < acpi_gbl_root_table_list.count) {
499 (acpi_gbl_root_table_list.tables[table_index].
500 flags & ACPI_TABLE_FLAGS_LOADED);
503 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
507 /*******************************************************************************
509 * FUNCTION: acpi_tb_set_table_loaded_flag
511 * PARAMETERS: table_index - Table index
512 * is_loaded - TRUE if table is loaded, FALSE otherwise
516 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
518 ******************************************************************************/
520 void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded)
523 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
524 if (table_index < acpi_gbl_root_table_list.count) {
526 acpi_gbl_root_table_list.tables[table_index].flags |=
527 ACPI_TABLE_FLAGS_LOADED;
529 acpi_gbl_root_table_list.tables[table_index].flags &=
530 ~ACPI_TABLE_FLAGS_LOADED;
534 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);