]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/tables/tbinstal.c
ACPICA: Fix to allow zero-length ASL field declarations
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / tables / tbinstal.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
4 *
5 *****************************************************************************/
6
7/*
75a44ce0 8 * Copyright (C) 2000 - 2008, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
1da177e4 44#include <acpi/acpi.h>
f3d2e786 45#include <acpi/acnamesp.h>
1da177e4
LT
46#include <acpi/actables.h>
47
1da177e4 48#define _COMPONENT ACPI_TABLES
4be44fcd 49ACPI_MODULE_NAME("tbinstal")
1da177e4 50
f3d2e786 51/******************************************************************************
1da177e4 52 *
f3d2e786 53 * FUNCTION: acpi_tb_verify_table
1da177e4 54 *
f3d2e786 55 * PARAMETERS: table_desc - table
1da177e4
LT
56 *
57 * RETURN: Status
58 *
f3d2e786 59 * DESCRIPTION: this function is called to verify and map table
1da177e4 60 *
f3d2e786
BM
61 *****************************************************************************/
62acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
1da177e4 63{
428f2112 64 acpi_status status = AE_OK;
1da177e4 65
f3d2e786 66 ACPI_FUNCTION_TRACE(tb_verify_table);
1da177e4 67
f3d2e786 68 /* Map the table if necessary */
44f6c012 69
f3d2e786 70 if (!table_desc->pointer) {
428f2112
AS
71 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
72 ACPI_TABLE_ORIGIN_MAPPED) {
73 table_desc->pointer =
74 acpi_os_map_memory(table_desc->address,
75 table_desc->length);
76 }
f3d2e786
BM
77 if (!table_desc->pointer) {
78 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4 79 }
f3d2e786 80 }
1da177e4 81
f3d2e786 82 /* FACS is the odd table, has no standard ACPI header and no checksum */
52fc0b02 83
428f2112 84 if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
1da177e4 85
428f2112
AS
86 /* Always calculate checksum, ignore bad checksum if requested */
87
88 status =
89 acpi_tb_verify_checksum(table_desc->pointer,
90 table_desc->length);
91 }
1da177e4 92
c5fc42ac 93 return_ACPI_STATUS(status);
1da177e4
LT
94}
95
1da177e4
LT
96/*******************************************************************************
97 *
f3d2e786 98 * FUNCTION: acpi_tb_add_table
1da177e4 99 *
428f2112 100 * PARAMETERS: table_desc - Table descriptor
f3d2e786 101 * table_index - Where the table index is returned
1da177e4
LT
102 *
103 * RETURN: Status
104 *
f3d2e786 105 * DESCRIPTION: This function is called to add the ACPI table
1da177e4
LT
106 *
107 ******************************************************************************/
108
f3d2e786 109acpi_status
428f2112 110acpi_tb_add_table(struct acpi_table_desc *table_desc,
f3d2e786 111 acpi_native_uint * table_index)
1da177e4 112{
f3d2e786
BM
113 acpi_native_uint i;
114 acpi_native_uint length;
115 acpi_status status = AE_OK;
1da177e4 116
f3d2e786 117 ACPI_FUNCTION_TRACE(tb_add_table);
1da177e4 118
428f2112
AS
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);
123 }
124 }
125
0efabac9 126 /* The table must be either an SSDT or a PSDT or an OEMx */
428f2112 127
5eb69180
BM
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));
137 } else {
138 ACPI_ERROR((AE_INFO, "Table has invalid signature "
139 "(0x%8.8X), must be SSDT or PSDT",
140 *(u32 *) table_desc->pointer->signature));
141 }
428f2112
AS
142 return_ACPI_STATUS(AE_BAD_SIGNATURE);
143 }
144
f3d2e786 145 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
1da177e4 146
f3d2e786
BM
147 /* Check if table is already registered */
148
149 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
150 if (!acpi_gbl_root_table_list.tables[i].pointer) {
151 status =
152 acpi_tb_verify_table(&acpi_gbl_root_table_list.
153 tables[i]);
154 if (ACPI_FAILURE(status)
155 || !acpi_gbl_root_table_list.tables[i].pointer) {
156 continue;
157 }
158 }
159
428f2112
AS
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,
164 length)) {
f3d2e786
BM
165 continue;
166 }
167
168 /* Table is already registered */
169
428f2112 170 acpi_tb_delete_table(table_desc);
f3d2e786 171 *table_index = i;
200cce6a 172 status = AE_ALREADY_EXISTS;
f3d2e786 173 goto release;
1da177e4
LT
174 }
175
0c9938cc 176 /*
f3d2e786 177 * Add the table to the global table list
0c9938cc 178 */
428f2112
AS
179 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
180 table_desc->length, table_desc->flags,
181 table_index);
4be44fcd 182 if (ACPI_FAILURE(status)) {
f3d2e786 183 goto release;
0c9938cc
RM
184 }
185
428f2112 186 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
1da177e4 187
f3d2e786 188 release:
4be44fcd
LB
189 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
190 return_ACPI_STATUS(status);
1da177e4
LT
191}
192
1da177e4
LT
193/*******************************************************************************
194 *
f3d2e786 195 * FUNCTION: acpi_tb_resize_root_table_list
1da177e4 196 *
f3d2e786 197 * PARAMETERS: None
1da177e4
LT
198 *
199 * RETURN: Status
200 *
f3d2e786 201 * DESCRIPTION: Expand the size of global table array
1da177e4
LT
202 *
203 ******************************************************************************/
204
f3d2e786 205acpi_status acpi_tb_resize_root_table_list(void)
1da177e4 206{
f3d2e786 207 struct acpi_table_desc *tables;
1da177e4 208
f3d2e786 209 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
1da177e4 210
f3d2e786 211 /* allow_resize flag is a parameter to acpi_initialize_tables */
1da177e4 212
c5fc42ac 213 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
f3d2e786
BM
214 ACPI_ERROR((AE_INFO,
215 "Resize of Root Table Array is not allowed"));
216 return_ACPI_STATUS(AE_SUPPORT);
1da177e4
LT
217 }
218
f3d2e786
BM
219 /* Increase the Table Array size */
220
221 tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size +
222 ACPI_ROOT_TABLE_SIZE_INCREMENT)
223 * sizeof(struct acpi_table_desc));
224 if (!tables) {
225 ACPI_ERROR((AE_INFO,
226 "Could not allocate new root table array"));
227 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
228 }
229
f3d2e786
BM
230 /* Copy and free the previous table array */
231
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));
236
c5fc42ac 237 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
f3d2e786
BM
238 ACPI_FREE(acpi_gbl_root_table_list.tables);
239 }
1da177e4
LT
240 }
241
f3d2e786
BM
242 acpi_gbl_root_table_list.tables = tables;
243 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
c5fc42ac 244 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
1da177e4 245
f3d2e786 246 return_ACPI_STATUS(AE_OK);
1da177e4
LT
247}
248
1da177e4
LT
249/*******************************************************************************
250 *
f3d2e786 251 * FUNCTION: acpi_tb_store_table
1da177e4 252 *
f3d2e786
BM
253 * PARAMETERS: Address - Table address
254 * Table - Table header
255 * Length - Table length
256 * Flags - flags
1da177e4 257 *
f3d2e786 258 * RETURN: Status and table index.
1da177e4 259 *
f3d2e786 260 * DESCRIPTION: Add an ACPI table to the global table list
1da177e4
LT
261 *
262 ******************************************************************************/
263
264acpi_status
f3d2e786
BM
265acpi_tb_store_table(acpi_physical_address address,
266 struct acpi_table_header *table,
267 u32 length, u8 flags, acpi_native_uint * table_index)
1da177e4 268{
f3d2e786 269 acpi_status status = AE_OK;
1da177e4 270
f3d2e786 271 /* Ensure that there is room for the table in the Root Table List */
f9f4601f 272
f3d2e786
BM
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)) {
276 return (status);
277 }
f9f4601f
RM
278 }
279
f3d2e786
BM
280 /* Initialize added table */
281
282 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
283 address = address;
284 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
285 pointer = table;
286 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
287 length;
288 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
289 owner_id = 0;
290 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
291 flags;
292
293 ACPI_MOVE_32_TO_32(&
294 (acpi_gbl_root_table_list.
295 tables[acpi_gbl_root_table_list.count].signature),
296 table->signature);
297
298 *table_index = acpi_gbl_root_table_list.count;
299 acpi_gbl_root_table_list.count++;
300 return (status);
301}
1da177e4 302
f3d2e786
BM
303/*******************************************************************************
304 *
305 * FUNCTION: acpi_tb_delete_table
306 *
307 * PARAMETERS: table_index - Table index
308 *
309 * RETURN: None
310 *
311 * DESCRIPTION: Delete one internal ACPI table
312 *
313 ******************************************************************************/
1da177e4 314
428f2112 315void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
f3d2e786 316{
f3d2e786 317 /* Table must be mapped or allocated */
f3d2e786
BM
318 if (!table_desc->pointer) {
319 return;
1da177e4 320 }
428f2112
AS
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);
324 break;
325 case ACPI_TABLE_ORIGIN_ALLOCATED:
f3d2e786 326 ACPI_FREE(table_desc->pointer);
428f2112
AS
327 break;
328 default:;
1da177e4
LT
329 }
330
f3d2e786 331 table_desc->pointer = NULL;
1da177e4
LT
332}
333
1da177e4
LT
334/*******************************************************************************
335 *
f3d2e786 336 * FUNCTION: acpi_tb_terminate
1da177e4 337 *
f3d2e786 338 * PARAMETERS: None
1da177e4 339 *
f3d2e786 340 * RETURN: None
1da177e4
LT
341 *
342 * DESCRIPTION: Delete all internal ACPI tables
343 *
344 ******************************************************************************/
345
f3d2e786 346void acpi_tb_terminate(void)
1da177e4 347{
f3d2e786
BM
348 acpi_native_uint i;
349
350 ACPI_FUNCTION_TRACE(tb_terminate);
351
352 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
353
354 /* Delete the individual tables */
355
356 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
428f2112 357 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
f3d2e786 358 }
1da177e4
LT
359
360 /*
f3d2e786
BM
361 * Delete the root table array if allocated locally. Array cannot be
362 * mapped, so we don't need to check for that flag.
1da177e4 363 */
c5fc42ac 364 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
f3d2e786 365 ACPI_FREE(acpi_gbl_root_table_list.tables);
1da177e4 366 }
f3d2e786
BM
367
368 acpi_gbl_root_table_list.tables = NULL;
369 acpi_gbl_root_table_list.flags = 0;
370 acpi_gbl_root_table_list.count = 0;
371
372 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
373 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1da177e4
LT
374}
375
1da177e4
LT
376/*******************************************************************************
377 *
f3d2e786 378 * FUNCTION: acpi_tb_delete_namespace_by_owner
1da177e4 379 *
f3d2e786 380 * PARAMETERS: table_index - Table index
1da177e4 381 *
f3d2e786 382 * RETURN: None
1da177e4 383 *
f3d2e786 384 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
1da177e4
LT
385 *
386 ******************************************************************************/
387
f3d2e786 388void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index)
1da177e4 389{
f3d2e786 390 acpi_owner_id owner_id;
1da177e4 391
f3d2e786
BM
392 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
393 if (table_index < acpi_gbl_root_table_list.count) {
394 owner_id =
395 acpi_gbl_root_table_list.tables[table_index].owner_id;
396 } else {
397 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1da177e4
LT
398 return;
399 }
400
f3d2e786
BM
401 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
402 acpi_ns_delete_namespace_by_owner(owner_id);
403}
1da177e4 404
f3d2e786
BM
405/*******************************************************************************
406 *
407 * FUNCTION: acpi_tb_allocate_owner_id
408 *
409 * PARAMETERS: table_index - Table index
410 *
411 * RETURN: Status
412 *
413 * DESCRIPTION: Allocates owner_id in table_desc
414 *
415 ******************************************************************************/
1da177e4 416
f3d2e786
BM
417acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index)
418{
419 acpi_status status = AE_BAD_PARAMETER;
1da177e4 420
f3d2e786 421 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
1da177e4 422
f3d2e786
BM
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));
1da177e4
LT
427 }
428
4be44fcd 429 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
f3d2e786 430 return_ACPI_STATUS(status);
1da177e4
LT
431}
432
1da177e4
LT
433/*******************************************************************************
434 *
f3d2e786 435 * FUNCTION: acpi_tb_release_owner_id
1da177e4 436 *
f3d2e786 437 * PARAMETERS: table_index - Table index
1da177e4 438 *
f3d2e786 439 * RETURN: Status
1da177e4 440 *
f3d2e786 441 * DESCRIPTION: Releases owner_id in table_desc
1da177e4
LT
442 *
443 ******************************************************************************/
444
f3d2e786 445acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index)
1da177e4 446{
f3d2e786 447 acpi_status status = AE_BAD_PARAMETER;
1da177e4 448
f3d2e786 449 ACPI_FUNCTION_TRACE(tb_release_owner_id);
1da177e4 450
f3d2e786
BM
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));
456 status = AE_OK;
1da177e4
LT
457 }
458
f3d2e786
BM
459 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
460 return_ACPI_STATUS(status);
1da177e4
LT
461}
462
1da177e4
LT
463/*******************************************************************************
464 *
f3d2e786 465 * FUNCTION: acpi_tb_get_owner_id
1da177e4 466 *
f3d2e786
BM
467 * PARAMETERS: table_index - Table index
468 * owner_id - Where the table owner_id is returned
1da177e4 469 *
f3d2e786 470 * RETURN: Status
1da177e4 471 *
f3d2e786 472 * DESCRIPTION: returns owner_id for the ACPI table
1da177e4
LT
473 *
474 ******************************************************************************/
475
f3d2e786
BM
476acpi_status
477acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
1da177e4 478{
f3d2e786 479 acpi_status status = AE_BAD_PARAMETER;
1da177e4 480
f3d2e786 481 ACPI_FUNCTION_TRACE(tb_get_owner_id);
1da177e4 482
f3d2e786
BM
483 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
484 if (table_index < acpi_gbl_root_table_list.count) {
485 *owner_id =
486 acpi_gbl_root_table_list.tables[table_index].owner_id;
487 status = AE_OK;
1da177e4
LT
488 }
489
f3d2e786
BM
490 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
491 return_ACPI_STATUS(status);
492}
1da177e4 493
f3d2e786
BM
494/*******************************************************************************
495 *
496 * FUNCTION: acpi_tb_is_table_loaded
497 *
498 * PARAMETERS: table_index - Table index
499 *
500 * RETURN: Table Loaded Flag
501 *
502 ******************************************************************************/
1da177e4 503
f3d2e786
BM
504u8 acpi_tb_is_table_loaded(acpi_native_uint table_index)
505{
506 u8 is_loaded = FALSE;
1da177e4 507
f3d2e786
BM
508 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
509 if (table_index < acpi_gbl_root_table_list.count) {
510 is_loaded = (u8)
511 (acpi_gbl_root_table_list.tables[table_index].
c5fc42ac 512 flags & ACPI_TABLE_IS_LOADED);
1da177e4
LT
513 }
514
f3d2e786
BM
515 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
516 return (is_loaded);
517}
f6dd9221 518
f3d2e786
BM
519/*******************************************************************************
520 *
521 * FUNCTION: acpi_tb_set_table_loaded_flag
522 *
523 * PARAMETERS: table_index - Table index
524 * is_loaded - TRUE if table is loaded, FALSE otherwise
525 *
526 * RETURN: None
527 *
528 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
529 *
530 ******************************************************************************/
1da177e4 531
f3d2e786
BM
532void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded)
533{
1da177e4 534
f3d2e786
BM
535 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
536 if (table_index < acpi_gbl_root_table_list.count) {
537 if (is_loaded) {
538 acpi_gbl_root_table_list.tables[table_index].flags |=
c5fc42ac 539 ACPI_TABLE_IS_LOADED;
f3d2e786
BM
540 } else {
541 acpi_gbl_root_table_list.tables[table_index].flags &=
c5fc42ac 542 ~ACPI_TABLE_IS_LOADED;
f3d2e786
BM
543 }
544 }
1da177e4 545
f3d2e786 546 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1da177e4 547}