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
);
126 /* The table must be either an SSDT or a PSDT or an OEMx */
128 if (!ACPI_COMPARE_NAME(table_desc
->pointer
->signature
, ACPI_SIG_PSDT
)&&
129 !ACPI_COMPARE_NAME(table_desc
->pointer
->signature
, ACPI_SIG_SSDT
)&&
130 strncmp(table_desc
->pointer
->signature
, "OEM", 3)) {
131 /* Check for a printable name */
132 if (acpi_ut_valid_acpi_name(
133 *(u32
*) table_desc
->pointer
->signature
)) {
134 ACPI_ERROR((AE_INFO
, "Table has invalid signature "
135 "[%4.4s], must be SSDT or PSDT",
136 table_desc
->pointer
->signature
));
138 ACPI_ERROR((AE_INFO
, "Table has invalid signature "
139 "(0x%8.8X), must be SSDT or PSDT",
140 *(u32
*) table_desc
->pointer
->signature
));
142 return_ACPI_STATUS(AE_BAD_SIGNATURE
);
145 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
147 /* Check if table is already registered */
149 for (i
= 0; i
< acpi_gbl_root_table_list
.count
; ++i
) {
150 if (!acpi_gbl_root_table_list
.tables
[i
].pointer
) {
152 acpi_tb_verify_table(&acpi_gbl_root_table_list
.
154 if (ACPI_FAILURE(status
)
155 || !acpi_gbl_root_table_list
.tables
[i
].pointer
) {
160 length
= ACPI_MIN(table_desc
->length
,
161 acpi_gbl_root_table_list
.tables
[i
].length
);
162 if (ACPI_MEMCMP(table_desc
->pointer
,
163 acpi_gbl_root_table_list
.tables
[i
].pointer
,
168 /* Table is already registered */
170 acpi_tb_delete_table(table_desc
);
172 status
= AE_ALREADY_EXISTS
;
177 * Add the table to the global table list
179 status
= acpi_tb_store_table(table_desc
->address
, table_desc
->pointer
,
180 table_desc
->length
, table_desc
->flags
,
182 if (ACPI_FAILURE(status
)) {
186 acpi_tb_print_table_header(table_desc
->address
, table_desc
->pointer
);
189 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
190 return_ACPI_STATUS(status
);
193 /*******************************************************************************
195 * FUNCTION: acpi_tb_resize_root_table_list
201 * DESCRIPTION: Expand the size of global table array
203 ******************************************************************************/
205 acpi_status
acpi_tb_resize_root_table_list(void)
207 struct acpi_table_desc
*tables
;
209 ACPI_FUNCTION_TRACE(tb_resize_root_table_list
);
211 /* allow_resize flag is a parameter to acpi_initialize_tables */
213 if (!(acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ALLOW_RESIZE
)) {
215 "Resize of Root Table Array is not allowed"));
216 return_ACPI_STATUS(AE_SUPPORT
);
219 /* Increase the Table Array size */
221 tables
= ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list
.size
+
222 ACPI_ROOT_TABLE_SIZE_INCREMENT
)
223 * sizeof(struct acpi_table_desc
));
226 "Could not allocate new root table array"));
227 return_ACPI_STATUS(AE_NO_MEMORY
);
230 /* Copy and free the previous table array */
232 if (acpi_gbl_root_table_list
.tables
) {
233 ACPI_MEMCPY(tables
, acpi_gbl_root_table_list
.tables
,
234 acpi_gbl_root_table_list
.size
*
235 sizeof(struct acpi_table_desc
));
237 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
238 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
242 acpi_gbl_root_table_list
.tables
= tables
;
243 acpi_gbl_root_table_list
.size
+= ACPI_ROOT_TABLE_SIZE_INCREMENT
;
244 acpi_gbl_root_table_list
.flags
|= (u8
) ACPI_ROOT_ORIGIN_ALLOCATED
;
246 return_ACPI_STATUS(AE_OK
);
249 /*******************************************************************************
251 * FUNCTION: acpi_tb_store_table
253 * PARAMETERS: Address - Table address
254 * Table - Table header
255 * Length - Table length
258 * RETURN: Status and table index.
260 * DESCRIPTION: Add an ACPI table to the global table list
262 ******************************************************************************/
265 acpi_tb_store_table(acpi_physical_address address
,
266 struct acpi_table_header
*table
,
267 u32 length
, u8 flags
, acpi_native_uint
* table_index
)
269 acpi_status status
= AE_OK
;
271 /* Ensure that there is room for the table in the Root Table List */
273 if (acpi_gbl_root_table_list
.count
>= acpi_gbl_root_table_list
.size
) {
274 status
= acpi_tb_resize_root_table_list();
275 if (ACPI_FAILURE(status
)) {
280 /* Initialize added table */
282 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
284 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
286 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].length
=
288 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].
290 acpi_gbl_root_table_list
.tables
[acpi_gbl_root_table_list
.count
].flags
=
294 (acpi_gbl_root_table_list
.
295 tables
[acpi_gbl_root_table_list
.count
].signature
),
298 *table_index
= acpi_gbl_root_table_list
.count
;
299 acpi_gbl_root_table_list
.count
++;
303 /*******************************************************************************
305 * FUNCTION: acpi_tb_delete_table
307 * PARAMETERS: table_index - Table index
311 * DESCRIPTION: Delete one internal ACPI table
313 ******************************************************************************/
315 void acpi_tb_delete_table(struct acpi_table_desc
*table_desc
)
317 /* Table must be mapped or allocated */
318 if (!table_desc
->pointer
) {
321 switch (table_desc
->flags
& ACPI_TABLE_ORIGIN_MASK
) {
322 case ACPI_TABLE_ORIGIN_MAPPED
:
323 acpi_os_unmap_memory(table_desc
->pointer
, table_desc
->length
);
325 case ACPI_TABLE_ORIGIN_ALLOCATED
:
326 ACPI_FREE(table_desc
->pointer
);
331 table_desc
->pointer
= NULL
;
334 /*******************************************************************************
336 * FUNCTION: acpi_tb_terminate
342 * DESCRIPTION: Delete all internal ACPI tables
344 ******************************************************************************/
346 void acpi_tb_terminate(void)
350 ACPI_FUNCTION_TRACE(tb_terminate
);
352 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
354 /* Delete the individual tables */
356 for (i
= 0; i
< acpi_gbl_root_table_list
.count
; ++i
) {
357 acpi_tb_delete_table(&acpi_gbl_root_table_list
.tables
[i
]);
361 * Delete the root table array if allocated locally. Array cannot be
362 * mapped, so we don't need to check for that flag.
364 if (acpi_gbl_root_table_list
.flags
& ACPI_ROOT_ORIGIN_ALLOCATED
) {
365 ACPI_FREE(acpi_gbl_root_table_list
.tables
);
368 acpi_gbl_root_table_list
.tables
= NULL
;
369 acpi_gbl_root_table_list
.flags
= 0;
370 acpi_gbl_root_table_list
.count
= 0;
372 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "ACPI Tables freed\n"));
373 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
376 /*******************************************************************************
378 * FUNCTION: acpi_tb_delete_namespace_by_owner
380 * PARAMETERS: table_index - Table index
384 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
386 ******************************************************************************/
388 void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index
)
390 acpi_owner_id owner_id
;
392 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
393 if (table_index
< acpi_gbl_root_table_list
.count
) {
395 acpi_gbl_root_table_list
.tables
[table_index
].owner_id
;
397 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
401 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
402 acpi_ns_delete_namespace_by_owner(owner_id
);
405 /*******************************************************************************
407 * FUNCTION: acpi_tb_allocate_owner_id
409 * PARAMETERS: table_index - Table index
413 * DESCRIPTION: Allocates owner_id in table_desc
415 ******************************************************************************/
417 acpi_status
acpi_tb_allocate_owner_id(acpi_native_uint table_index
)
419 acpi_status status
= AE_BAD_PARAMETER
;
421 ACPI_FUNCTION_TRACE(tb_allocate_owner_id
);
423 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
424 if (table_index
< acpi_gbl_root_table_list
.count
) {
425 status
= acpi_ut_allocate_owner_id
426 (&(acpi_gbl_root_table_list
.tables
[table_index
].owner_id
));
429 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
430 return_ACPI_STATUS(status
);
433 /*******************************************************************************
435 * FUNCTION: acpi_tb_release_owner_id
437 * PARAMETERS: table_index - Table index
441 * DESCRIPTION: Releases owner_id in table_desc
443 ******************************************************************************/
445 acpi_status
acpi_tb_release_owner_id(acpi_native_uint table_index
)
447 acpi_status status
= AE_BAD_PARAMETER
;
449 ACPI_FUNCTION_TRACE(tb_release_owner_id
);
451 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
452 if (table_index
< acpi_gbl_root_table_list
.count
) {
453 acpi_ut_release_owner_id(&
454 (acpi_gbl_root_table_list
.
455 tables
[table_index
].owner_id
));
459 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
460 return_ACPI_STATUS(status
);
463 /*******************************************************************************
465 * FUNCTION: acpi_tb_get_owner_id
467 * PARAMETERS: table_index - Table index
468 * owner_id - Where the table owner_id is returned
472 * DESCRIPTION: returns owner_id for the ACPI table
474 ******************************************************************************/
477 acpi_tb_get_owner_id(acpi_native_uint table_index
, acpi_owner_id
* owner_id
)
479 acpi_status status
= AE_BAD_PARAMETER
;
481 ACPI_FUNCTION_TRACE(tb_get_owner_id
);
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
].owner_id
;
490 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
491 return_ACPI_STATUS(status
);
494 /*******************************************************************************
496 * FUNCTION: acpi_tb_is_table_loaded
498 * PARAMETERS: table_index - Table index
500 * RETURN: Table Loaded Flag
502 ******************************************************************************/
504 u8
acpi_tb_is_table_loaded(acpi_native_uint table_index
)
506 u8 is_loaded
= FALSE
;
508 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
509 if (table_index
< acpi_gbl_root_table_list
.count
) {
511 (acpi_gbl_root_table_list
.tables
[table_index
].
512 flags
& ACPI_TABLE_IS_LOADED
);
515 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
519 /*******************************************************************************
521 * FUNCTION: acpi_tb_set_table_loaded_flag
523 * PARAMETERS: table_index - Table index
524 * is_loaded - TRUE if table is loaded, FALSE otherwise
528 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
530 ******************************************************************************/
532 void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index
, u8 is_loaded
)
535 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
536 if (table_index
< acpi_gbl_root_table_list
.count
) {
538 acpi_gbl_root_table_list
.tables
[table_index
].flags
|=
539 ACPI_TABLE_IS_LOADED
;
541 acpi_gbl_root_table_list
.tables
[table_index
].flags
&=
542 ~ACPI_TABLE_IS_LOADED
;
546 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);