]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/tbinstal.c
ACPICA: Tables: Cleanup ACPI_TABLE_ORIGIN_xxx flags.
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / tbinstal.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
4 *
5 *****************************************************************************/
6
7/*
fbb7a2dc 8 * Copyright (C) 2000 - 2014, 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>
e2f7a777
LB
45#include "accommon.h"
46#include "acnamesp.h"
47#include "actables.h"
1da177e4 48
1da177e4 49#define _COMPONENT ACPI_TABLES
4be44fcd 50ACPI_MODULE_NAME("tbinstal")
1da177e4 51
86dfc6f3
LZ
52/* Local prototypes */
53static acpi_status
54acpi_tb_acquire_temporal_table(struct acpi_table_desc *table_desc,
55 acpi_physical_address address, u8 flags);
56
57static void acpi_tb_release_temporal_table(struct acpi_table_desc *table_desc);
58
59static acpi_status acpi_tb_acquire_root_table_entry(u32 *table_index);
60
61static u8
62acpi_tb_is_equivalent_table(struct acpi_table_desc *table_desc,
63 u32 table_index);
64
7f9fc99c 65/*******************************************************************************
1da177e4 66 *
7f9fc99c 67 * FUNCTION: acpi_tb_acquire_table
1da177e4 68 *
7f9fc99c
LZ
69 * PARAMETERS: table_desc - Table descriptor
70 * table_ptr - Where table is returned
71 * table_length - Where table length is returned
72 * table_flags - Where table allocation flags are returned
1da177e4
LT
73 *
74 * RETURN: Status
75 *
7f9fc99c
LZ
76 * DESCRIPTION: Acquire a table. It can be used for tables not maintained in
77 * acpi_gbl_root_table_list.
1da177e4 78 *
7f9fc99c 79 ******************************************************************************/
86dfc6f3 80
7f9fc99c
LZ
81acpi_status
82acpi_tb_acquire_table(struct acpi_table_desc *table_desc,
83 struct acpi_table_header **table_ptr,
84 u32 *table_length, u8 *table_flags)
1da177e4 85{
7f9fc99c 86 struct acpi_table_header *table = NULL;
1da177e4 87
7f9fc99c 88 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
8a216d7f 89 case ACPI_TABLE_ORIGIN_INTERN_PHYSICAL:
1da177e4 90
7f9fc99c
LZ
91 table =
92 acpi_os_map_memory(table_desc->address, table_desc->length);
93 break;
44f6c012 94
8a216d7f
LZ
95 case ACPI_TABLE_ORIGIN_INTERN_VIRTUAL:
96 case ACPI_TABLE_ORIGIN_EXTERN_VIRTUAL:
dc156adf 97
7f9fc99c
LZ
98 table =
99 ACPI_CAST_PTR(struct acpi_table_header,
100 table_desc->address);
101 break;
dc156adf 102
7f9fc99c 103 default:
dc156adf 104
7f9fc99c
LZ
105 break;
106 }
dc156adf 107
7f9fc99c 108 /* Table is not valid yet */
dc156adf 109
7f9fc99c
LZ
110 if (!table) {
111 return (AE_NO_MEMORY);
112 }
113
114 /* Fill the return values */
115
116 *table_ptr = table;
117 *table_length = table_desc->length;
118 *table_flags = table_desc->flags;
119
120 return (AE_OK);
121}
122
123/*******************************************************************************
124 *
125 * FUNCTION: acpi_tb_release_table
126 *
127 * PARAMETERS: table - Pointer for the table
128 * table_length - Length for the table
129 * table_flags - Allocation flags for the table
130 *
131 * RETURN: None
132 *
133 * DESCRIPTION: Release a table. The reversal of acpi_tb_acquire_table().
134 *
135 ******************************************************************************/
136
137void
138acpi_tb_release_table(struct acpi_table_header *table,
139 u32 table_length, u8 table_flags)
140{
141 switch (table_flags & ACPI_TABLE_ORIGIN_MASK) {
8a216d7f 142 case ACPI_TABLE_ORIGIN_INTERN_PHYSICAL:
7f9fc99c
LZ
143
144 acpi_os_unmap_memory(table, table_length);
145 break;
146
8a216d7f
LZ
147 case ACPI_TABLE_ORIGIN_INTERN_VIRTUAL:
148 case ACPI_TABLE_ORIGIN_EXTERN_VIRTUAL:
7f9fc99c
LZ
149 default:
150
151 break;
152 }
153}
154
155/******************************************************************************
156 *
157 * FUNCTION: acpi_tb_validate_table
158 *
159 * PARAMETERS: table_desc - Table descriptor
160 *
161 * RETURN: Status
162 *
86dfc6f3
LZ
163 * DESCRIPTION: This function is called to validate the table, the returned
164 * table descriptor is in "VALIDATED" state.
7f9fc99c
LZ
165 *
166 *****************************************************************************/
5582982d 167
7f9fc99c
LZ
168acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc)
169{
170 acpi_status status = AE_OK;
171
172 ACPI_FUNCTION_TRACE(tb_validate_table);
173
174 /* Validate the table if necessary */
175
176 if (!table_desc->pointer) {
177 status = acpi_tb_acquire_table(table_desc, &table_desc->pointer,
178 &table_desc->length,
179 &table_desc->flags);
86dfc6f3
LZ
180 if (!table_desc->pointer) {
181 status = AE_NO_MEMORY;
1da177e4 182 }
f3d2e786 183 }
1da177e4 184
c5fc42ac 185 return_ACPI_STATUS(status);
1da177e4
LT
186}
187
7f9fc99c
LZ
188/*******************************************************************************
189 *
190 * FUNCTION: acpi_tb_invalidate_table
191 *
192 * PARAMETERS: table_desc - Table descriptor
193 *
194 * RETURN: None
195 *
196 * DESCRIPTION: Invalidate one internal ACPI table, this is reversal of
197 * acpi_tb_validate_table().
198 *
199 ******************************************************************************/
200
201void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc)
202{
203
204 ACPI_FUNCTION_TRACE(tb_invalidate_table);
205
206 /* Table must be validated */
207
208 if (!table_desc->pointer) {
209 return_VOID;
210 }
211
212 acpi_tb_release_table(table_desc->pointer, table_desc->length,
213 table_desc->flags);
214 table_desc->pointer = NULL;
215
216 return_VOID;
217}
218
86dfc6f3 219/******************************************************************************
1da177e4 220 *
86dfc6f3 221 * FUNCTION: acpi_tb_verify_table
1da177e4 222 *
428f2112 223 * PARAMETERS: table_desc - Table descriptor
86dfc6f3 224 * signature - Table signature to verify
1da177e4
LT
225 *
226 * RETURN: Status
227 *
86dfc6f3
LZ
228 * DESCRIPTION: This function is called to validate and verify the table, the
229 * returned table descriptor is in "VALIDATED" state.
1da177e4 230 *
86dfc6f3 231 *****************************************************************************/
1da177e4 232
f3d2e786 233acpi_status
86dfc6f3 234acpi_tb_verify_table(struct acpi_table_desc *table_desc, char *signature)
1da177e4 235{
f3d2e786 236 acpi_status status = AE_OK;
1da177e4 237
86dfc6f3 238 ACPI_FUNCTION_TRACE(tb_verify_table);
1da177e4 239
86dfc6f3
LZ
240 /* Validate the table */
241
242 status = acpi_tb_validate_table(table_desc);
243 if (ACPI_FAILURE(status)) {
244 return_ACPI_STATUS(AE_NO_MEMORY);
428f2112
AS
245 }
246
86dfc6f3
LZ
247 /* If a particular signature is expected (DSDT/FACS), it must match */
248
249 if (signature && !ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
3b3ea775 250 ACPI_BIOS_ERROR((AE_INFO,
86dfc6f3
LZ
251 "Invalid signature 0x%X for ACPI table, expected [%s]",
252 table_desc->signature.integer, signature));
253 status = AE_BAD_SIGNATURE;
254 goto invalidate_and_exit;
c8cefe30 255 }
428f2112 256
86dfc6f3 257 /* Verify the checksum */
1da177e4 258
86dfc6f3
LZ
259 status =
260 acpi_tb_verify_checksum(table_desc->pointer, table_desc->length);
261 if (ACPI_FAILURE(status)) {
262 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
263 "%4.4s " ACPI_PRINTF_UINT
264 " Attempted table install failed",
265 acpi_ut_valid_acpi_name(table_desc->signature.
266 ascii) ? table_desc->
267 signature.ascii : "????",
268 ACPI_FORMAT_TO_UINT(table_desc->address)));
269 goto invalidate_and_exit;
270 }
f3d2e786 271
86dfc6f3 272 return_ACPI_STATUS(AE_OK);
f3d2e786 273
86dfc6f3
LZ
274invalidate_and_exit:
275 acpi_tb_invalidate_table(table_desc);
276 return_ACPI_STATUS(status);
277}
278
279/*******************************************************************************
280 *
281 * FUNCTION: acpi_tb_install_table
282 *
283 * PARAMETERS: table_desc - Table descriptor
284 * address - Physical address of the table
285 * flags - Allocation flags of the table
286 * table - Pointer to the table
287 *
288 * RETURN: None
289 *
290 * DESCRIPTION: Install an ACPI table into the global data structure.
291 *
292 ******************************************************************************/
293
294void
295acpi_tb_install_table(struct acpi_table_desc *table_desc,
296 acpi_physical_address address,
297 u8 flags, struct acpi_table_header *table)
298{
299 /*
300 * Initialize the table entry. Set the pointer to NULL, since the
301 * table is not fully mapped at this time.
302 */
303 ACPI_MEMSET(table_desc, 0, sizeof(struct acpi_table_desc));
304 table_desc->address = address;
305 table_desc->length = table->length;
306 table_desc->flags = flags;
307 ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
308}
309
310/*******************************************************************************
311 *
312 * FUNCTION: acpi_tb_acquire_temporal_table
313 *
314 * PARAMETERS: table_desc - Table descriptor to be acquired
315 * address - Address of the table
316 * flags - Allocation flags of the table
317 *
318 * RETURN: Status
319 *
320 * DESCRIPTION: This function validates the table header to obtain the length
321 * of a table and fills the table descriptor to make its state as
322 * "INSTALLED". Such table descriptor is only used for verified
323 * installation.
324 *
325 ******************************************************************************/
326
327static acpi_status
328acpi_tb_acquire_temporal_table(struct acpi_table_desc *table_desc,
329 acpi_physical_address address, u8 flags)
330{
331 struct acpi_table_header *table_header;
332
333 switch (flags & ACPI_TABLE_ORIGIN_MASK) {
8a216d7f 334 case ACPI_TABLE_ORIGIN_INTERN_PHYSICAL:
86dfc6f3
LZ
335
336 /* Try to obtain the length of the table */
337
338 table_header =
339 acpi_os_map_memory(address,
340 sizeof(struct acpi_table_header));
341 if (!table_header) {
342 return (AE_NO_MEMORY);
a6f30539 343 }
86dfc6f3
LZ
344 acpi_tb_install_table(table_desc, address, flags, table_header);
345 acpi_os_unmap_memory(table_header,
346 sizeof(struct acpi_table_header));
347 return (AE_OK);
348
8a216d7f
LZ
349 case ACPI_TABLE_ORIGIN_INTERN_VIRTUAL:
350 case ACPI_TABLE_ORIGIN_EXTERN_VIRTUAL:
e56f5617 351
86dfc6f3
LZ
352 table_header = ACPI_CAST_PTR(struct acpi_table_header, address);
353 if (!table_header) {
354 return (AE_NO_MEMORY);
f3d2e786 355 }
86dfc6f3
LZ
356 acpi_tb_install_table(table_desc, address, flags, table_header);
357 return (AE_OK);
f3d2e786 358
86dfc6f3
LZ
359 default:
360
361 break;
362 }
e56f5617 363
86dfc6f3
LZ
364 /* Table is not valid yet */
365
366 return (AE_NO_MEMORY);
367}
e56f5617 368
86dfc6f3
LZ
369/*******************************************************************************
370 *
371 * FUNCTION: acpi_tb_release_temporal_table
372 *
373 * PARAMETERS: table_desc - Table descriptor to be released
374 *
375 * RETURN: Status
376 *
377 * DESCRIPTION: The reversal of acpi_tb_acquire_temporal_table().
378 *
379 ******************************************************************************/
e56f5617 380
86dfc6f3
LZ
381static void acpi_tb_release_temporal_table(struct acpi_table_desc *table_desc)
382{
383 /*
384 * Note that the .Address is maintained by the callers of
385 * acpi_tb_acquire_temporal_table(), thus do not invoke acpi_tb_uninstall_table()
386 * where .Address will be freed.
387 */
388 acpi_tb_invalidate_table(table_desc);
389}
e56f5617 390
86dfc6f3
LZ
391/*******************************************************************************
392 *
393 * FUNCTION: acpi_tb_install_and_override_table
394 *
395 * PARAMETERS: table_index - Index into root table array
396 * new_table_desc - New table descriptor to install
397 *
398 * RETURN: None
399 *
400 * DESCRIPTION: Install an ACPI table into the global data structure. The
401 * table override mechanism is called to allow the host
402 * OS to replace any table before it is installed in the root
403 * table array.
404 *
405 ******************************************************************************/
406
407void
408acpi_tb_install_and_override_table(u32 table_index,
409 struct acpi_table_desc *new_table_desc)
410{
411 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
412 return;
1da177e4
LT
413 }
414
d3ccaff8
BM
415 /*
416 * ACPI Table Override:
86dfc6f3
LZ
417 *
418 * Before we install the table, let the host OS override it with a new
419 * one if desired. Any table within the RSDT/XSDT can be replaced,
420 * including the DSDT which is pointed to by the FADT.
d3ccaff8 421 */
86dfc6f3 422 acpi_tb_override_table(new_table_desc);
7f9fc99c 423
86dfc6f3
LZ
424 acpi_tb_install_table(&acpi_gbl_root_table_list.tables[table_index],
425 new_table_desc->address, new_table_desc->flags,
426 new_table_desc->pointer);
7f9fc99c 427
86dfc6f3
LZ
428 acpi_tb_print_table_header(new_table_desc->address,
429 new_table_desc->pointer);
430
431 /* Set the global integer width (based upon revision of the DSDT) */
432
433 if (table_index == ACPI_TABLE_INDEX_DSDT) {
434 acpi_ut_set_integer_width(new_table_desc->pointer->revision);
435 }
436}
437
438/*******************************************************************************
439 *
440 * FUNCTION: acpi_tb_install_fixed_table
441 *
442 * PARAMETERS: address - Physical address of DSDT or FACS
443 * signature - Table signature, NULL if no need to
444 * match
445 * table_index - Index into root table array
446 *
447 * RETURN: Status
448 *
449 * DESCRIPTION: Install a fixed ACPI table (DSDT/FACS) into the global data
450 * structure.
451 *
452 ******************************************************************************/
453
454acpi_status
455acpi_tb_install_fixed_table(acpi_physical_address address,
456 char *signature, u32 table_index)
457{
458 struct acpi_table_desc new_table_desc;
459 acpi_status status;
460
461 ACPI_FUNCTION_TRACE(tb_install_fixed_table);
462
463 if (!address) {
464 ACPI_ERROR((AE_INFO,
465 "Null physical address for ACPI table [%s]",
466 signature));
467 return (AE_NO_MEMORY);
468 }
469
470 /* Fill a table descriptor for validation */
471
472 status = acpi_tb_acquire_temporal_table(&new_table_desc, address,
8a216d7f 473 ACPI_TABLE_ORIGIN_INTERN_PHYSICAL);
86dfc6f3
LZ
474 if (ACPI_FAILURE(status)) {
475 ACPI_ERROR((AE_INFO, "Could not acquire table length at %p",
476 ACPI_CAST_PTR(void, address)));
477 return_ACPI_STATUS(status);
478 }
479
480 /* Validate and verify a table before installation */
481
482 status = acpi_tb_verify_table(&new_table_desc, signature);
483 if (ACPI_FAILURE(status)) {
484 goto release_and_exit;
485 }
486
487 acpi_tb_install_and_override_table(table_index, &new_table_desc);
488
489release_and_exit:
490
491 /* Release the temporal table descriptor */
492
493 acpi_tb_release_temporal_table(&new_table_desc);
494 return_ACPI_STATUS(status);
495}
496
497/*******************************************************************************
498 *
499 * FUNCTION: acpi_tb_is_equivalent_table
500 *
501 * PARAMETERS: table_desc - Table 1 descriptor to be compared
502 * table_index - Index of table 2 to be compared
503 *
504 * RETURN: TRUE if 2 tables are equivalent
505 *
506 * DESCRIPTION: This function is called to compare a table with what have
507 * already been installed in the root table list.
508 *
509 ******************************************************************************/
510
511static u8
512acpi_tb_is_equivalent_table(struct acpi_table_desc *table_desc, u32 table_index)
513{
514 acpi_status status = AE_OK;
515 u8 is_equivalent;
516 struct acpi_table_header *table;
517 u32 table_length;
518 u8 table_flags;
519
520 status =
521 acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
522 &table, &table_length, &table_flags);
523 if (ACPI_FAILURE(status)) {
524 return (FALSE);
525 }
526
527 /*
528 * Check for a table match on the entire table length,
529 * not just the header.
530 */
531 is_equivalent = (u8)((table_desc->length != table_length ||
532 ACPI_MEMCMP(table_desc->pointer, table,
533 table_length)) ? FALSE : TRUE);
534
535 /* Release the acquired table */
536
537 acpi_tb_release_table(table, table_length, table_flags);
538
539 return (is_equivalent);
540}
541
542/*******************************************************************************
543 *
544 * FUNCTION: acpi_tb_install_non_fixed_table
545 *
8a216d7f 546 * PARAMETERS: address - Address of the table (might be a virtual
86dfc6f3
LZ
547 * address depending on the table_flags)
548 * flags - Flags for the table
549 * reload - Whether reload should be performed
550 * table_index - Where the table index is returned
551 *
552 * RETURN: Status
553 *
554 * DESCRIPTION: This function is called to install an ACPI table that is
555 * neither DSDT nor FACS.
556 * When this function is called by "Load" or "LoadTable" opcodes,
557 * or by acpi_load_table() API, the "Reload" parameter is set.
558 * After sucessfully returning from this function, table is
559 * "INSTALLED" but not "VALIDATED".
560 *
561 ******************************************************************************/
562
563acpi_status
564acpi_tb_install_non_fixed_table(acpi_physical_address address,
565 u8 flags, u8 reload, u32 *table_index)
566{
567 u32 i;
568 acpi_status status = AE_OK;
569 struct acpi_table_desc new_table_desc;
570
571 ACPI_FUNCTION_TRACE(tb_install_non_fixed_table);
572
573 /* Acquire a temporal table descriptor for validation */
574
575 status =
576 acpi_tb_acquire_temporal_table(&new_table_desc, address, flags);
577 if (ACPI_FAILURE(status)) {
578 ACPI_ERROR((AE_INFO, "Could not acquire table length at %p",
579 ACPI_CAST_PTR(void, address)));
580 return_ACPI_STATUS(status);
581 }
582
583 /* Validate and verify a table before installation */
584
585 status = acpi_tb_verify_table(&new_table_desc, NULL);
586 if (ACPI_FAILURE(status)) {
587 goto release_and_exit;
588 }
589
590 if (reload) {
591 /*
592 * Validate the incoming table signature.
593 *
594 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
595 * 2) We added support for OEMx tables, signature "OEM".
596 * 3) Valid tables were encountered with a null signature, so we just
597 * gave up on validating the signature, (05/2008).
598 * 4) We encountered non-AML tables such as the MADT, which caused
599 * interpreter errors and kernel faults. So now, we once again allow
600 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
601 */
602 if ((new_table_desc.signature.ascii[0] != 0x00) &&
603 (!ACPI_COMPARE_NAME
604 (&new_table_desc.signature, ACPI_SIG_SSDT))
605 && (ACPI_STRNCMP(new_table_desc.signature.ascii, "OEM", 3)))
606 {
607 ACPI_BIOS_ERROR((AE_INFO,
608 "Table has invalid signature [%4.4s] (0x%8.8X), "
609 "must be SSDT or OEMx",
610 acpi_ut_valid_acpi_name(new_table_desc.
611 signature.
612 ascii) ?
613 new_table_desc.signature.
614 ascii : "????",
615 new_table_desc.signature.integer));
616
617 status = AE_BAD_SIGNATURE;
618 goto release_and_exit;
619 }
620
621 /* Check if table is already registered */
622
623 for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
624 ++i) {
625 /*
626 * Check for a table match on the entire table length,
627 * not just the header.
628 */
629 if (!acpi_tb_is_equivalent_table(&new_table_desc, i)) {
630 continue;
631 }
632
633 /*
634 * Note: the current mechanism does not unregister a table if it is
635 * dynamically unloaded. The related namespace entries are deleted,
636 * but the table remains in the root table list.
637 *
638 * The assumption here is that the number of different tables that
639 * will be loaded is actually small, and there is minimal overhead
640 * in just keeping the table in case it is needed again.
641 *
642 * If this assumption changes in the future (perhaps on large
643 * machines with many table load/unload operations), tables will
644 * need to be unregistered when they are unloaded, and slots in the
645 * root table list should be reused when empty.
646 */
647 if (acpi_gbl_root_table_list.tables[i].
648 flags & ACPI_TABLE_IS_LOADED) {
649
650 /* Table is still loaded, this is an error */
651
652 status = AE_ALREADY_EXISTS;
653 goto release_and_exit;
654 } else {
655 /*
656 * Table was unloaded, allow it to be reloaded.
657 * As we are going to return AE_OK to the caller, we should
658 * take the responsibility of freeing the input descriptor.
659 * Refill the input descriptor to ensure
660 * acpi_tb_install_and_override_table() can be called again to
661 * indicate the re-installation.
662 */
663 acpi_tb_uninstall_table(&new_table_desc);
664 *table_index = i;
665 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
666 return_ACPI_STATUS(AE_OK);
667 }
668 }
7f9fc99c 669 }
d3ccaff8 670
e56f5617
BM
671 /* Add the table to the global root table list */
672
86dfc6f3 673 status = acpi_tb_acquire_root_table_entry(&i);
4be44fcd 674 if (ACPI_FAILURE(status)) {
86dfc6f3 675 goto release_and_exit;
0c9938cc 676 }
86dfc6f3
LZ
677 *table_index = i;
678 acpi_tb_install_and_override_table(i, &new_table_desc);
679
680release_and_exit:
0c9938cc 681
86dfc6f3 682 /* Release the temporal table descriptor */
1da177e4 683
86dfc6f3 684 acpi_tb_release_temporal_table(&new_table_desc);
4be44fcd 685 return_ACPI_STATUS(status);
1da177e4
LT
686}
687
f7b004a1
BM
688/*******************************************************************************
689 *
7f9fc99c 690 * FUNCTION: acpi_tb_override_table
f7b004a1 691 *
86dfc6f3
LZ
692 * PARAMETERS: old_table_desc - Validated table descriptor to be
693 * overridden
f7b004a1 694 *
86dfc6f3 695 * RETURN: None
f7b004a1
BM
696 *
697 * DESCRIPTION: Attempt table override by calling the OSL override functions.
698 * Note: If the table is overridden, then the entire new table
7f9fc99c 699 * is acquired and returned by this function.
86dfc6f3
LZ
700 * Before/after invocation, the table descriptor is in a state
701 * that is "VALIDATED".
f7b004a1
BM
702 *
703 ******************************************************************************/
704
86dfc6f3 705void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
f7b004a1
BM
706{
707 acpi_status status;
f7b004a1 708 char *override_type;
7f9fc99c 709 struct acpi_table_desc new_table_desc;
86dfc6f3
LZ
710 struct acpi_table_header *table;
711 acpi_physical_address address;
712 u32 length;
f7b004a1
BM
713
714 /* (1) Attempt logical override (returns a logical address) */
715
86dfc6f3
LZ
716 status = acpi_os_table_override(old_table_desc->pointer, &table);
717 if (ACPI_SUCCESS(status) && table) {
718 acpi_tb_acquire_temporal_table(&new_table_desc,
719 ACPI_PTR_TO_PHYSADDR(table),
8a216d7f 720 ACPI_TABLE_ORIGIN_EXTERN_VIRTUAL);
f7b004a1
BM
721 override_type = "Logical";
722 goto finish_override;
723 }
724
725 /* (2) Attempt physical override (returns a physical address) */
726
86dfc6f3
LZ
727 status = acpi_os_physical_table_override(old_table_desc->pointer,
728 &address, &length);
729 if (ACPI_SUCCESS(status) && address && length) {
730 acpi_tb_acquire_temporal_table(&new_table_desc, address,
8a216d7f 731 ACPI_TABLE_ORIGIN_INTERN_PHYSICAL);
f7b004a1 732 override_type = "Physical";
f7b004a1
BM
733 goto finish_override;
734 }
735
86dfc6f3 736 return; /* There was no override */
f7b004a1 737
10622bf8 738finish_override:
f7b004a1 739
86dfc6f3
LZ
740 /* Validate and verify a table before overriding */
741
742 status = acpi_tb_verify_table(&new_table_desc, NULL);
7f9fc99c 743 if (ACPI_FAILURE(status)) {
86dfc6f3 744 return;
7f9fc99c
LZ
745 }
746
2e19f8d0
BM
747 ACPI_INFO((AE_INFO, "%4.4s " ACPI_PRINTF_UINT
748 " %s table override, new table: " ACPI_PRINTF_UINT,
86dfc6f3
LZ
749 old_table_desc->signature.ascii,
750 ACPI_FORMAT_TO_UINT(old_table_desc->address),
7f9fc99c 751 override_type, ACPI_FORMAT_TO_UINT(new_table_desc.address)));
f7b004a1 752
86dfc6f3 753 /* We can now uninstall the original table */
f7b004a1 754
86dfc6f3 755 acpi_tb_uninstall_table(old_table_desc);
f7b004a1 756
86dfc6f3
LZ
757 /*
758 * Replace the original table descriptor and keep its state as
759 * "VALIDATED".
760 */
761 acpi_tb_install_table(old_table_desc, new_table_desc.address,
762 new_table_desc.flags, new_table_desc.pointer);
763 acpi_tb_validate_table(old_table_desc);
f7b004a1 764
86dfc6f3 765 /* Release the temporal table descriptor */
f7b004a1 766
86dfc6f3 767 acpi_tb_release_temporal_table(&new_table_desc);
f7b004a1
BM
768}
769
1da177e4
LT
770/*******************************************************************************
771 *
f3d2e786 772 * FUNCTION: acpi_tb_resize_root_table_list
1da177e4 773 *
f3d2e786 774 * PARAMETERS: None
1da177e4
LT
775 *
776 * RETURN: Status
777 *
f3d2e786 778 * DESCRIPTION: Expand the size of global table array
1da177e4
LT
779 *
780 ******************************************************************************/
781
f3d2e786 782acpi_status acpi_tb_resize_root_table_list(void)
1da177e4 783{
f3d2e786 784 struct acpi_table_desc *tables;
2bc198c1 785 u32 table_count;
1da177e4 786
f3d2e786 787 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
1da177e4 788
f3d2e786 789 /* allow_resize flag is a parameter to acpi_initialize_tables */
1da177e4 790
c5fc42ac 791 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
f3d2e786
BM
792 ACPI_ERROR((AE_INFO,
793 "Resize of Root Table Array is not allowed"));
794 return_ACPI_STATUS(AE_SUPPORT);
1da177e4
LT
795 }
796
f3d2e786
BM
797 /* Increase the Table Array size */
798
2bc198c1
LZ
799 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
800 table_count = acpi_gbl_root_table_list.max_table_count;
801 } else {
802 table_count = acpi_gbl_root_table_list.current_table_count;
803 }
804
805 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) table_count +
ec41f193
BM
806 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
807 sizeof(struct acpi_table_desc));
f3d2e786
BM
808 if (!tables) {
809 ACPI_ERROR((AE_INFO,
810 "Could not allocate new root table array"));
811 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
812 }
813
f3d2e786
BM
814 /* Copy and free the previous table array */
815
816 if (acpi_gbl_root_table_list.tables) {
817 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
2bc198c1
LZ
818 (acpi_size) table_count *
819 sizeof(struct acpi_table_desc));
f3d2e786 820
c5fc42ac 821 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
f3d2e786
BM
822 ACPI_FREE(acpi_gbl_root_table_list.tables);
823 }
1da177e4
LT
824 }
825
f3d2e786 826 acpi_gbl_root_table_list.tables = tables;
2bc198c1
LZ
827 acpi_gbl_root_table_list.max_table_count =
828 table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
829 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
1da177e4 830
f3d2e786 831 return_ACPI_STATUS(AE_OK);
1da177e4
LT
832}
833
1da177e4
LT
834/*******************************************************************************
835 *
86dfc6f3 836 * FUNCTION: acpi_tb_acquire_root_table_entry
1da177e4 837 *
86dfc6f3 838 * PARAMETERS: table_index - Where table index is returned
1da177e4 839 *
f3d2e786 840 * RETURN: Status and table index.
1da177e4 841 *
86dfc6f3 842 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
1da177e4
LT
843 *
844 ******************************************************************************/
845
86dfc6f3 846static acpi_status acpi_tb_acquire_root_table_entry(u32 *table_index)
1da177e4 847{
b9ee2043 848 acpi_status status;
1da177e4 849
f3d2e786 850 /* Ensure that there is room for the table in the Root Table List */
f9f4601f 851
b9ee2043
BM
852 if (acpi_gbl_root_table_list.current_table_count >=
853 acpi_gbl_root_table_list.max_table_count) {
f3d2e786
BM
854 status = acpi_tb_resize_root_table_list();
855 if (ACPI_FAILURE(status)) {
856 return (status);
857 }
f9f4601f
RM
858 }
859
86dfc6f3
LZ
860 *table_index = acpi_gbl_root_table_list.current_table_count;
861 acpi_gbl_root_table_list.current_table_count++;
862 return (AE_OK);
863}
b9ee2043 864
86dfc6f3
LZ
865/*******************************************************************************
866 *
867 * FUNCTION: acpi_tb_store_table
868 *
869 * PARAMETERS: address - Table address
870 * table - Table header
871 * length - Table length
872 * flags - flags
873 *
874 * RETURN: Status and table index.
875 *
876 * DESCRIPTION: Add an ACPI table to the global table list
877 *
878 ******************************************************************************/
879
880acpi_status
881acpi_tb_store_table(acpi_physical_address address,
882 struct acpi_table_header * table,
883 u32 length, u8 flags, u32 *table_index)
884{
885 acpi_status status;
886 struct acpi_table_desc *table_desc;
887
888 status = acpi_tb_acquire_root_table_entry(table_index);
889 if (ACPI_FAILURE(status)) {
890 return (status);
891 }
f3d2e786 892
86dfc6f3 893 /* Initialize added table */
b9ee2043 894
86dfc6f3
LZ
895 table_desc = &acpi_gbl_root_table_list.tables[*table_index];
896 acpi_tb_install_table(table_desc, address, flags, table);
897 table_desc->pointer = table;
b9ee2043 898
b9ee2043 899 return (AE_OK);
f3d2e786 900}
1da177e4 901
f3d2e786
BM
902/*******************************************************************************
903 *
7f9fc99c 904 * FUNCTION: acpi_tb_uninstall_table
f3d2e786 905 *
7f9fc99c 906 * PARAMETERS: table_desc - Table descriptor
f3d2e786
BM
907 *
908 * RETURN: None
909 *
910 * DESCRIPTION: Delete one internal ACPI table
911 *
912 ******************************************************************************/
1da177e4 913
7f9fc99c 914void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
f3d2e786 915{
5582982d 916
7f9fc99c 917 ACPI_FUNCTION_TRACE(tb_uninstall_table);
5582982d 918
7f9fc99c 919 /* Table must be installed */
5582982d 920
7f9fc99c
LZ
921 if (!table_desc->address) {
922 return_VOID;
923 }
f7b004a1 924
7f9fc99c 925 acpi_tb_invalidate_table(table_desc);
1d1ea1b7 926
7f9fc99c 927 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
8a216d7f 928 ACPI_TABLE_ORIGIN_INTERN_VIRTUAL) {
7f9fc99c 929 ACPI_FREE(ACPI_CAST_PTR(void, table_desc->address));
1da177e4
LT
930 }
931
7f9fc99c
LZ
932 table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
933
934 return_VOID;
1da177e4
LT
935}
936
1da177e4
LT
937/*******************************************************************************
938 *
f3d2e786 939 * FUNCTION: acpi_tb_terminate
1da177e4 940 *
f3d2e786 941 * PARAMETERS: None
1da177e4 942 *
f3d2e786 943 * RETURN: None
1da177e4
LT
944 *
945 * DESCRIPTION: Delete all internal ACPI tables
946 *
947 ******************************************************************************/
948
f3d2e786 949void acpi_tb_terminate(void)
1da177e4 950{
67a119f9 951 u32 i;
f3d2e786
BM
952
953 ACPI_FUNCTION_TRACE(tb_terminate);
954
955 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
956
957 /* Delete the individual tables */
958
b9ee2043 959 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
7f9fc99c 960 acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]);
f3d2e786 961 }
1da177e4
LT
962
963 /*
f3d2e786
BM
964 * Delete the root table array if allocated locally. Array cannot be
965 * mapped, so we don't need to check for that flag.
1da177e4 966 */
c5fc42ac 967 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
f3d2e786 968 ACPI_FREE(acpi_gbl_root_table_list.tables);
1da177e4 969 }
f3d2e786
BM
970
971 acpi_gbl_root_table_list.tables = NULL;
972 acpi_gbl_root_table_list.flags = 0;
b9ee2043 973 acpi_gbl_root_table_list.current_table_count = 0;
f3d2e786
BM
974
975 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
976 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
68aafc35
BM
977
978 return_VOID;
1da177e4
LT
979}
980
1da177e4
LT
981/*******************************************************************************
982 *
f3d2e786 983 * FUNCTION: acpi_tb_delete_namespace_by_owner
1da177e4 984 *
f3d2e786 985 * PARAMETERS: table_index - Table index
1da177e4 986 *
8a335a23 987 * RETURN: Status
1da177e4 988 *
f3d2e786 989 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
1da177e4
LT
990 *
991 ******************************************************************************/
992
8a335a23 993acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
1da177e4 994{
f3d2e786 995 acpi_owner_id owner_id;
8a335a23
BM
996 acpi_status status;
997
998 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
999
1000 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
1001 if (ACPI_FAILURE(status)) {
1002 return_ACPI_STATUS(status);
1003 }
1004
b9ee2043 1005 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
8a335a23
BM
1006
1007 /* The table index does not exist */
1da177e4 1008
f3d2e786 1009 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
8a335a23 1010 return_ACPI_STATUS(AE_NOT_EXIST);
1da177e4
LT
1011 }
1012
8a335a23
BM
1013 /* Get the owner ID for this table, used to delete namespace nodes */
1014
1015 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
f3d2e786 1016 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
8a335a23
BM
1017
1018 /*
1019 * Need to acquire the namespace writer lock to prevent interference
1020 * with any concurrent namespace walks. The interpreter must be
1021 * released during the deletion since the acquisition of the deletion
1022 * lock may block, and also since the execution of a namespace walk
1023 * must be allowed to use the interpreter.
1024 */
e4c1ebfc 1025 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
8a335a23
BM
1026 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
1027
f3d2e786 1028 acpi_ns_delete_namespace_by_owner(owner_id);
8a335a23
BM
1029 if (ACPI_FAILURE(status)) {
1030 return_ACPI_STATUS(status);
1031 }
1032
1033 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
1034
1035 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
1036 return_ACPI_STATUS(status);
f3d2e786 1037}
1da177e4 1038
f3d2e786
BM
1039/*******************************************************************************
1040 *
1041 * FUNCTION: acpi_tb_allocate_owner_id
1042 *
1043 * PARAMETERS: table_index - Table index
1044 *
1045 * RETURN: Status
1046 *
1047 * DESCRIPTION: Allocates owner_id in table_desc
1048 *
1049 ******************************************************************************/
1da177e4 1050
67a119f9 1051acpi_status acpi_tb_allocate_owner_id(u32 table_index)
f3d2e786
BM
1052{
1053 acpi_status status = AE_BAD_PARAMETER;
1da177e4 1054
f3d2e786 1055 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
1da177e4 1056
f3d2e786 1057 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
b9ee2043 1058 if (table_index < acpi_gbl_root_table_list.current_table_count) {
f3d2e786
BM
1059 status = acpi_ut_allocate_owner_id
1060 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
1da177e4
LT
1061 }
1062
4be44fcd 1063 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
f3d2e786 1064 return_ACPI_STATUS(status);
1da177e4
LT
1065}
1066
1da177e4
LT
1067/*******************************************************************************
1068 *
f3d2e786 1069 * FUNCTION: acpi_tb_release_owner_id
1da177e4 1070 *
f3d2e786 1071 * PARAMETERS: table_index - Table index
1da177e4 1072 *
f3d2e786 1073 * RETURN: Status
1da177e4 1074 *
f3d2e786 1075 * DESCRIPTION: Releases owner_id in table_desc
1da177e4
LT
1076 *
1077 ******************************************************************************/
1078
67a119f9 1079acpi_status acpi_tb_release_owner_id(u32 table_index)
1da177e4 1080{
f3d2e786 1081 acpi_status status = AE_BAD_PARAMETER;
1da177e4 1082
f3d2e786 1083 ACPI_FUNCTION_TRACE(tb_release_owner_id);
1da177e4 1084
f3d2e786 1085 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
b9ee2043 1086 if (table_index < acpi_gbl_root_table_list.current_table_count) {
f3d2e786
BM
1087 acpi_ut_release_owner_id(&
1088 (acpi_gbl_root_table_list.
1089 tables[table_index].owner_id));
1090 status = AE_OK;
1da177e4
LT
1091 }
1092
f3d2e786
BM
1093 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1094 return_ACPI_STATUS(status);
1da177e4
LT
1095}
1096
1da177e4
LT
1097/*******************************************************************************
1098 *
f3d2e786 1099 * FUNCTION: acpi_tb_get_owner_id
1da177e4 1100 *
f3d2e786
BM
1101 * PARAMETERS: table_index - Table index
1102 * owner_id - Where the table owner_id is returned
1da177e4 1103 *
f3d2e786 1104 * RETURN: Status
1da177e4 1105 *
f3d2e786 1106 * DESCRIPTION: returns owner_id for the ACPI table
1da177e4
LT
1107 *
1108 ******************************************************************************/
1109
5582982d 1110acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id * owner_id)
1da177e4 1111{
f3d2e786 1112 acpi_status status = AE_BAD_PARAMETER;
1da177e4 1113
f3d2e786 1114 ACPI_FUNCTION_TRACE(tb_get_owner_id);
1da177e4 1115
f3d2e786 1116 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
b9ee2043 1117 if (table_index < acpi_gbl_root_table_list.current_table_count) {
f3d2e786
BM
1118 *owner_id =
1119 acpi_gbl_root_table_list.tables[table_index].owner_id;
1120 status = AE_OK;
1da177e4
LT
1121 }
1122
f3d2e786
BM
1123 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1124 return_ACPI_STATUS(status);
1125}
1da177e4 1126
f3d2e786
BM
1127/*******************************************************************************
1128 *
1129 * FUNCTION: acpi_tb_is_table_loaded
1130 *
1131 * PARAMETERS: table_index - Table index
1132 *
1133 * RETURN: Table Loaded Flag
1134 *
1135 ******************************************************************************/
1da177e4 1136
67a119f9 1137u8 acpi_tb_is_table_loaded(u32 table_index)
f3d2e786
BM
1138{
1139 u8 is_loaded = FALSE;
1da177e4 1140
f3d2e786 1141 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
b9ee2043 1142 if (table_index < acpi_gbl_root_table_list.current_table_count) {
f3d2e786 1143 is_loaded = (u8)
ec41f193
BM
1144 (acpi_gbl_root_table_list.tables[table_index].flags &
1145 ACPI_TABLE_IS_LOADED);
1da177e4
LT
1146 }
1147
f3d2e786
BM
1148 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1149 return (is_loaded);
1150}
f6dd9221 1151
f3d2e786
BM
1152/*******************************************************************************
1153 *
1154 * FUNCTION: acpi_tb_set_table_loaded_flag
1155 *
1156 * PARAMETERS: table_index - Table index
1157 * is_loaded - TRUE if table is loaded, FALSE otherwise
1158 *
1159 * RETURN: None
1160 *
1161 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
1162 *
1163 ******************************************************************************/
1da177e4 1164
67a119f9 1165void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
f3d2e786 1166{
1da177e4 1167
f3d2e786 1168 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
b9ee2043 1169 if (table_index < acpi_gbl_root_table_list.current_table_count) {
f3d2e786
BM
1170 if (is_loaded) {
1171 acpi_gbl_root_table_list.tables[table_index].flags |=
c5fc42ac 1172 ACPI_TABLE_IS_LOADED;
f3d2e786
BM
1173 } else {
1174 acpi_gbl_root_table_list.tables[table_index].flags &=
c5fc42ac 1175 ~ACPI_TABLE_IS_LOADED;
f3d2e786
BM
1176 }
1177 }
1da177e4 1178
f3d2e786 1179 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1da177e4 1180}