aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2014-04-04 00:38:57 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-04-20 16:59:39 -0400
commit86dfc6f339886559d80ee0d4bd20fe5ee90450f0 (patch)
treeb48cad330e23ed4815bd45af185dddea4af7abae /drivers/acpi
parenteb0c65bd2c276b4b346db545d938d4113e1a4e9c (diff)
ACPICA: Tables: Fix table checksums verification before installation.
The original table handling code does not always verify checksums before installing a table, this is because code to achieve this must be implemented here and there in the redundant code blocks. There are two stages during table initialization: 1. "INSTALLED" after acpi_tb_install_table() and acpi_tb_override_table(), struct acpi_table_desc.Pointer is ensured to be NULL. This can be safely used during OSPM's early boot stage. 2. "VALIDATED" after acpi_tb_validate_table(), struct acpi_table_desc.Pointer is ensured to be not NULL. This must not be used during OSPM's early boot stage. This patch changes acpi_tb_add_table() into an early boot safe API to reduce code redundancies by changing the table state that is returned by this function from "VALIDATED" to "INSTALLED". Then the table verification code can be done in a single place. Originally, the acpi_tb_add_table() can only be used by dynamic table loadings that are executed after early boot stage, it cannot be used by static table loadings that are executed in early boot stage as: 1. The address of the table is a virtual address either maintained by OSPMs who call acpi_load_table() or by ACPICA whenever "Load" or "LoadTable" opcodes are executed, while during early boot stage, physical address of the table should be used for table loading. 2. The API will ensure the state of the loaded table to be "VALIDATED" while during early boot stage, tables maintained by root table list should be kept as "INSTALLED". To achieve this: 1. Rename acpi_tb_install_table() to acpi_tb_install_fixed_table() as it only applies to DSDT/FACS installation. Rename acpi_tb_add_table() to acpi_tb_install_non_fixed_table() as it will be applied to the installation of the rest kinds of tables. 2. Introduce acpi_tb_install_table(), acpi_tb_install_and_override_table to collect redudant code where their invocations actually have slight differences. 1. acpi_tb_install_table() is used to fill an struct acpi_table_desc where the table length is known to the caller. 2. acpi_tb_install_and_override_table() is used to perform necessary overriding before installation. 3. Change a parameter of acpi_tb_install_non_fixed_table() from struct acpi_table_desc to acpi_physical_address to allow it to be invoked by static table loadings. Also cleanup acpi_ex_load_op() and acpi_load_table() to accomodate to the parameter change. 4. Invoke acpi_tb_install_non_fixed_table() for all table loadings other than DSDT/FACS in acpi_tb_parse_root_table() to improve code maintainability (logics are collected in the single function). Also delete useless code from acpi_tb_parse_root_table(). 5. Remove all acpi_tb_validate_table() from acpi_tb_install_non_fixed_table() and acpi_tb_install_fixed_table() so that the table descriptor is kept in the state of "INSTALLED" but not "VALIDATED" after returning from these functions. 6. Introduce temporary struct acpi_table_desc (new_table_desc/old_table_desc) into the functions to indicate a table descriptor that is not maintained by acpi_gbl_root_table_list. Introduce acpi_tb_acquire_temporal_table() and acpi_tb_release_temporal_table() to handle the use cases of such temporal tables. They are only used for verified installation. 7. Introduce acpi_tb_verify_table() to validate table and verify table checksum, also remove table checksum verification from acpi_tb_validate_table(). Invoke acpi_tb_validate_table() in the functions that will convert a table into "LOADED" state or invoke it from acpi_get_table_XXX() APIs. Invoke acpi_tb_verify_table() on temporary struct acpi_table_desc(s) that are going to be "INSTALLED". 8. Change acpi_tb_override_table() logic so that a temporary struct acpi_table_desc will be overridden before installtion, this makes code simpler. After applying the patch, tables are always installed after being overridden and the table checksums are always verified before installation. Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Bob Moore <robert.moore@intel.com> [rjw: Subject] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/acpica/actables.h24
-rw-r--r--drivers/acpi/acpica/exconfig.c75
-rw-r--r--drivers/acpi/acpica/tbfadt.c10
-rw-r--r--drivers/acpi/acpica/tbinstal.c708
-rw-r--r--drivers/acpi/acpica/tbutils.c173
-rw-r--r--drivers/acpi/acpica/tbxfload.c26
6 files changed, 607 insertions, 409 deletions
diff --git a/drivers/acpi/acpica/actables.h b/drivers/acpi/acpica/actables.h
index c569eab774b1..32aec48eb2d8 100644
--- a/drivers/acpi/acpica/actables.h
+++ b/drivers/acpi/acpica/actables.h
@@ -76,10 +76,10 @@ acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc);
76 76
77void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc); 77void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc);
78 78
79struct acpi_table_header *acpi_tb_override_table(struct acpi_table_header 79acpi_status
80 *table_header, 80acpi_tb_verify_table(struct acpi_table_desc *table_desc, char *signature);
81 struct acpi_table_desc 81
82 *table_desc); 82void acpi_tb_override_table(struct acpi_table_desc *old_table_desc);
83 83
84acpi_status 84acpi_status
85acpi_tb_acquire_table(struct acpi_table_desc *table_desc, 85acpi_tb_acquire_table(struct acpi_table_desc *table_desc,
@@ -91,7 +91,8 @@ acpi_tb_release_table(struct acpi_table_header *table,
91 u32 table_length, u8 table_flags); 91 u32 table_length, u8 table_flags);
92 92
93acpi_status 93acpi_status
94acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index); 94acpi_tb_install_non_fixed_table(acpi_physical_address address,
95 u8 flags, u8 reload, u32 *table_index);
95 96
96acpi_status 97acpi_status
97acpi_tb_store_table(acpi_physical_address address, 98acpi_tb_store_table(acpi_physical_address address,
@@ -135,8 +136,17 @@ void acpi_tb_check_dsdt_header(void);
135struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index); 136struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index);
136 137
137void 138void
138acpi_tb_install_table(acpi_physical_address address, 139acpi_tb_install_table(struct acpi_table_desc *table_desc,
139 char *signature, u32 table_index); 140 acpi_physical_address address,
141 u8 flags, struct acpi_table_header *table);
142
143void
144acpi_tb_install_and_override_table(u32 table_index,
145 struct acpi_table_desc *new_table_desc);
146
147acpi_status
148acpi_tb_install_fixed_table(acpi_physical_address address,
149 char *signature, u32 table_index);
140 150
141acpi_status acpi_tb_parse_root_table(acpi_physical_address rsdp_address); 151acpi_status acpi_tb_parse_root_table(acpi_physical_address rsdp_address);
142 152
diff --git a/drivers/acpi/acpica/exconfig.c b/drivers/acpi/acpica/exconfig.c
index 11a014ca3935..52ea900c41a1 100644
--- a/drivers/acpi/acpica/exconfig.c
+++ b/drivers/acpi/acpica/exconfig.c
@@ -343,16 +343,14 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
343 struct acpi_walk_state *walk_state) 343 struct acpi_walk_state *walk_state)
344{ 344{
345 union acpi_operand_object *ddb_handle; 345 union acpi_operand_object *ddb_handle;
346 struct acpi_table_header *table_header;
346 struct acpi_table_header *table; 347 struct acpi_table_header *table;
347 struct acpi_table_desc table_desc;
348 u32 table_index; 348 u32 table_index;
349 acpi_status status; 349 acpi_status status;
350 u32 length; 350 u32 length;
351 351
352 ACPI_FUNCTION_TRACE(ex_load_op); 352 ACPI_FUNCTION_TRACE(ex_load_op);
353 353
354 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
355
356 /* Source Object can be either an op_region or a Buffer/Field */ 354 /* Source Object can be either an op_region or a Buffer/Field */
357 355
358 switch (obj_desc->common.type) { 356 switch (obj_desc->common.type) {
@@ -380,17 +378,17 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
380 378
381 /* Get the table header first so we can get the table length */ 379 /* Get the table header first so we can get the table length */
382 380
383 table = ACPI_ALLOCATE(sizeof(struct acpi_table_header)); 381 table_header = ACPI_ALLOCATE(sizeof(struct acpi_table_header));
384 if (!table) { 382 if (!table_header) {
385 return_ACPI_STATUS(AE_NO_MEMORY); 383 return_ACPI_STATUS(AE_NO_MEMORY);
386 } 384 }
387 385
388 status = 386 status =
389 acpi_ex_region_read(obj_desc, 387 acpi_ex_region_read(obj_desc,
390 sizeof(struct acpi_table_header), 388 sizeof(struct acpi_table_header),
391 ACPI_CAST_PTR(u8, table)); 389 ACPI_CAST_PTR(u8, table_header));
392 length = table->length; 390 length = table_header->length;
393 ACPI_FREE(table); 391 ACPI_FREE(table_header);
394 392
395 if (ACPI_FAILURE(status)) { 393 if (ACPI_FAILURE(status)) {
396 return_ACPI_STATUS(status); 394 return_ACPI_STATUS(status);
@@ -420,22 +418,19 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
420 418
421 /* Allocate a buffer for the table */ 419 /* Allocate a buffer for the table */
422 420
423 table_desc.pointer = ACPI_ALLOCATE(length); 421 table = ACPI_ALLOCATE(length);
424 if (!table_desc.pointer) { 422 if (!table) {
425 return_ACPI_STATUS(AE_NO_MEMORY); 423 return_ACPI_STATUS(AE_NO_MEMORY);
426 } 424 }
427 425
428 /* Read the entire table */ 426 /* Read the entire table */
429 427
430 status = acpi_ex_region_read(obj_desc, length, 428 status = acpi_ex_region_read(obj_desc, length,
431 ACPI_CAST_PTR(u8, 429 ACPI_CAST_PTR(u8, table));
432 table_desc.pointer));
433 if (ACPI_FAILURE(status)) { 430 if (ACPI_FAILURE(status)) {
434 ACPI_FREE(table_desc.pointer); 431 ACPI_FREE(table);
435 return_ACPI_STATUS(status); 432 return_ACPI_STATUS(status);
436 } 433 }
437
438 table_desc.address = ACPI_PTR_TO_PHYSADDR(table_desc.pointer);
439 break; 434 break;
440 435
441 case ACPI_TYPE_BUFFER: /* Buffer or resolved region_field */ 436 case ACPI_TYPE_BUFFER: /* Buffer or resolved region_field */
@@ -452,10 +447,10 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
452 447
453 /* Get the actual table length from the table header */ 448 /* Get the actual table length from the table header */
454 449
455 table = 450 table_header =
456 ACPI_CAST_PTR(struct acpi_table_header, 451 ACPI_CAST_PTR(struct acpi_table_header,
457 obj_desc->buffer.pointer); 452 obj_desc->buffer.pointer);
458 length = table->length; 453 length = table_header->length;
459 454
460 /* Table cannot extend beyond the buffer */ 455 /* Table cannot extend beyond the buffer */
461 456
@@ -470,13 +465,12 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
470 * Copy the table from the buffer because the buffer could be modified 465 * Copy the table from the buffer because the buffer could be modified
471 * or even deleted in the future 466 * or even deleted in the future
472 */ 467 */
473 table_desc.pointer = ACPI_ALLOCATE(length); 468 table = ACPI_ALLOCATE(length);
474 if (!table_desc.pointer) { 469 if (!table) {
475 return_ACPI_STATUS(AE_NO_MEMORY); 470 return_ACPI_STATUS(AE_NO_MEMORY);
476 } 471 }
477 472
478 ACPI_MEMCPY(table_desc.pointer, table, length); 473 ACPI_MEMCPY(table, table_header, length);
479 table_desc.address = ACPI_PTR_TO_PHYSADDR(table_desc.pointer);
480 break; 474 break;
481 475
482 default: 476 default:
@@ -484,27 +478,30 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
484 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 478 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
485 } 479 }
486 480
487 /* Validate table checksum (will not get validated in tb_add_table) */
488
489 status = acpi_tb_verify_checksum(table_desc.pointer, length);
490 if (ACPI_FAILURE(status)) {
491 ACPI_FREE(table_desc.pointer);
492 return_ACPI_STATUS(status);
493 }
494
495 /* Complete the table descriptor */
496
497 table_desc.length = length;
498 table_desc.flags = ACPI_TABLE_ORIGIN_ALLOCATED;
499
500 /* Install the new table into the local data structures */ 481 /* Install the new table into the local data structures */
501 482
502 status = acpi_tb_add_table(&table_desc, &table_index); 483 ACPI_INFO((AE_INFO, "Dynamic OEM Table Load:"));
484 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
485 status = acpi_tb_install_non_fixed_table(ACPI_PTR_TO_PHYSADDR(table),
486 ACPI_TABLE_ORIGIN_ALLOCATED,
487 TRUE, &table_index);
488 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
503 if (ACPI_FAILURE(status)) { 489 if (ACPI_FAILURE(status)) {
504 490
505 /* Delete allocated table buffer */ 491 /* Delete allocated table buffer */
506 492
507 ACPI_FREE(table_desc.pointer); 493 ACPI_FREE(table);
494 return_ACPI_STATUS(status);
495 }
496
497 /*
498 * Note: Now table is "INSTALLED", it must be validated before
499 * loading.
500 */
501 status =
502 acpi_tb_validate_table(&acpi_gbl_root_table_list.
503 tables[table_index]);
504 if (ACPI_FAILURE(status)) {
508 return_ACPI_STATUS(status); 505 return_ACPI_STATUS(status);
509 } 506 }
510 507
@@ -536,9 +533,6 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
536 return_ACPI_STATUS(status); 533 return_ACPI_STATUS(status);
537 } 534 }
538 535
539 ACPI_INFO((AE_INFO, "Dynamic OEM Table Load:"));
540 acpi_tb_print_table_header(0, table_desc.pointer);
541
542 /* Remove the reference by added by acpi_ex_store above */ 536 /* Remove the reference by added by acpi_ex_store above */
543 537
544 acpi_ut_remove_reference(ddb_handle); 538 acpi_ut_remove_reference(ddb_handle);
@@ -546,8 +540,7 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
546 /* Invoke table handler if present */ 540 /* Invoke table handler if present */
547 541
548 if (acpi_gbl_table_handler) { 542 if (acpi_gbl_table_handler) {
549 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, 543 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
550 table_desc.pointer,
551 acpi_gbl_table_handler_context); 544 acpi_gbl_table_handler_context);
552 } 545 }
553 546
diff --git a/drivers/acpi/acpica/tbfadt.c b/drivers/acpi/acpica/tbfadt.c
index ec14588254d4..a37af164b8c8 100644
--- a/drivers/acpi/acpica/tbfadt.c
+++ b/drivers/acpi/acpica/tbfadt.c
@@ -332,15 +332,15 @@ void acpi_tb_parse_fadt(u32 table_index)
332 332
333 /* Obtain the DSDT and FACS tables via their addresses within the FADT */ 333 /* Obtain the DSDT and FACS tables via their addresses within the FADT */
334 334
335 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt, 335 acpi_tb_install_fixed_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
336 ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT); 336 ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
337 337
338 /* If Hardware Reduced flag is set, there is no FACS */ 338 /* If Hardware Reduced flag is set, there is no FACS */
339 339
340 if (!acpi_gbl_reduced_hardware) { 340 if (!acpi_gbl_reduced_hardware) {
341 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT. 341 acpi_tb_install_fixed_table((acpi_physical_address)
342 Xfacs, ACPI_SIG_FACS, 342 acpi_gbl_FADT.Xfacs, ACPI_SIG_FACS,
343 ACPI_TABLE_INDEX_FACS); 343 ACPI_TABLE_INDEX_FACS);
344 } 344 }
345} 345}
346 346
diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c
index d3e1db225cb2..099e678edcb2 100644
--- a/drivers/acpi/acpica/tbinstal.c
+++ b/drivers/acpi/acpica/tbinstal.c
@@ -49,6 +49,19 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50ACPI_MODULE_NAME("tbinstal") 50ACPI_MODULE_NAME("tbinstal")
51 51
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
52/******************************************************************************* 65/*******************************************************************************
53 * 66 *
54 * FUNCTION: acpi_tb_acquire_table 67 * FUNCTION: acpi_tb_acquire_table
@@ -64,6 +77,7 @@ ACPI_MODULE_NAME("tbinstal")
64 * acpi_gbl_root_table_list. 77 * acpi_gbl_root_table_list.
65 * 78 *
66 ******************************************************************************/ 79 ******************************************************************************/
80
67acpi_status 81acpi_status
68acpi_tb_acquire_table(struct acpi_table_desc *table_desc, 82acpi_tb_acquire_table(struct acpi_table_desc *table_desc,
69 struct acpi_table_header **table_ptr, 83 struct acpi_table_header **table_ptr,
@@ -148,8 +162,8 @@ acpi_tb_release_table(struct acpi_table_header *table,
148 * 162 *
149 * RETURN: Status 163 * RETURN: Status
150 * 164 *
151 * DESCRIPTION: This function is called to validate (ensure Pointer is valid) 165 * DESCRIPTION: This function is called to validate the table, the returned
152 * and verify the table. 166 * table descriptor is in "VALIDATED" state.
153 * 167 *
154 *****************************************************************************/ 168 *****************************************************************************/
155 169
@@ -165,16 +179,11 @@ acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc)
165 status = acpi_tb_acquire_table(table_desc, &table_desc->pointer, 179 status = acpi_tb_acquire_table(table_desc, &table_desc->pointer,
166 &table_desc->length, 180 &table_desc->length,
167 &table_desc->flags); 181 &table_desc->flags);
168 if (ACPI_FAILURE(status) || !table_desc->pointer) { 182 if (!table_desc->pointer) {
169 return_ACPI_STATUS(AE_NO_MEMORY); 183 status = AE_NO_MEMORY;
170 } 184 }
171 } 185 }
172 186
173 /* Always calculate checksum, ignore bad checksum if requested */
174
175 status =
176 acpi_tb_verify_checksum(table_desc->pointer, table_desc->length);
177
178 return_ACPI_STATUS(status); 187 return_ACPI_STATUS(status);
179} 188}
180 189
@@ -209,157 +218,473 @@ void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc)
209 return_VOID; 218 return_VOID;
210} 219}
211 220
212/******************************************************************************* 221/******************************************************************************
213 * 222 *
214 * FUNCTION: acpi_tb_add_table 223 * FUNCTION: acpi_tb_verify_table
215 * 224 *
216 * PARAMETERS: table_desc - Table descriptor 225 * PARAMETERS: table_desc - Table descriptor
217 * table_index - Where the table index is returned 226 * signature - Table signature to verify
218 * 227 *
219 * RETURN: Status 228 * RETURN: Status
220 * 229 *
221 * DESCRIPTION: This function is called to add an ACPI table. It is used to 230 * DESCRIPTION: This function is called to validate and verify the table, the
222 * dynamically load tables via the Load and load_table AML 231 * returned table descriptor is in "VALIDATED" state.
223 * operators.
224 * 232 *
225 ******************************************************************************/ 233 *****************************************************************************/
226 234
227acpi_status 235acpi_status
228acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index) 236acpi_tb_verify_table(struct acpi_table_desc *table_desc, char *signature)
229{ 237{
230 u32 i;
231 acpi_status status = AE_OK; 238 acpi_status status = AE_OK;
232 struct acpi_table_header *final_table;
233 239
234 ACPI_FUNCTION_TRACE(tb_add_table); 240 ACPI_FUNCTION_TRACE(tb_verify_table);
235 241
236 if (!table_desc->pointer) { 242 /* Validate the table */
237 status = acpi_tb_validate_table(table_desc); 243
238 if (ACPI_FAILURE(status) || !table_desc->pointer) { 244 status = acpi_tb_validate_table(table_desc);
239 acpi_tb_invalidate_table(table_desc); 245 if (ACPI_FAILURE(status)) {
240 return_ACPI_STATUS(status); 246 return_ACPI_STATUS(AE_NO_MEMORY);
241 }
242 } 247 }
243 248
244 /* 249 /* If a particular signature is expected (DSDT/FACS), it must match */
245 * Validate the incoming table signature. 250
246 * 251 if (signature && !ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
247 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
248 * 2) We added support for OEMx tables, signature "OEM".
249 * 3) Valid tables were encountered with a null signature, so we just
250 * gave up on validating the signature, (05/2008).
251 * 4) We encountered non-AML tables such as the MADT, which caused
252 * interpreter errors and kernel faults. So now, we once again allow
253 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
254 */
255 if ((table_desc->pointer->signature[0] != 0x00) &&
256 (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT))
257 && (ACPI_STRNCMP(table_desc->pointer->signature, "OEM", 3))) {
258 ACPI_BIOS_ERROR((AE_INFO, 252 ACPI_BIOS_ERROR((AE_INFO,
259 "Table has invalid signature [%4.4s] (0x%8.8X), " 253 "Invalid signature 0x%X for ACPI table, expected [%s]",
260 "must be SSDT or OEMx", 254 table_desc->signature.integer, signature));
261 acpi_ut_valid_acpi_name(table_desc->pointer-> 255 status = AE_BAD_SIGNATURE;
262 signature) ? 256 goto invalidate_and_exit;
263 table_desc->pointer->signature : "????", 257 }
264 *(u32 *)table_desc->pointer->signature)); 258
259 /* Verify the checksum */
265 260
266 return_ACPI_STATUS(AE_BAD_SIGNATURE); 261 status =
262 acpi_tb_verify_checksum(table_desc->pointer, table_desc->length);
263 if (ACPI_FAILURE(status)) {
264 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
265 "%4.4s " ACPI_PRINTF_UINT
266 " Attempted table install failed",
267 acpi_ut_valid_acpi_name(table_desc->signature.
268 ascii) ? table_desc->
269 signature.ascii : "????",
270 ACPI_FORMAT_TO_UINT(table_desc->address)));
271 goto invalidate_and_exit;
267 } 272 }
268 273
269 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 274 return_ACPI_STATUS(AE_OK);
270 275
271 /* Check if table is already registered */ 276invalidate_and_exit:
277 acpi_tb_invalidate_table(table_desc);
278 return_ACPI_STATUS(status);
279}
272 280
273 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { 281/*******************************************************************************
274 if (!acpi_gbl_root_table_list.tables[i].pointer) { 282 *
275 status = 283 * FUNCTION: acpi_tb_install_table
276 acpi_tb_validate_table(&acpi_gbl_root_table_list. 284 *
277 tables[i]); 285 * PARAMETERS: table_desc - Table descriptor
278 if (ACPI_FAILURE(status) 286 * address - Physical address of the table
279 || !acpi_gbl_root_table_list.tables[i].pointer) { 287 * flags - Allocation flags of the table
280 continue; 288 * table - Pointer to the table
281 } 289 *
282 } 290 * RETURN: None
291 *
292 * DESCRIPTION: Install an ACPI table into the global data structure.
293 *
294 ******************************************************************************/
283 295
284 /* 296void
285 * Check for a table match on the entire table length, 297acpi_tb_install_table(struct acpi_table_desc *table_desc,
286 * not just the header. 298 acpi_physical_address address,
287 */ 299 u8 flags, struct acpi_table_header *table)
288 if (table_desc->length != 300{
289 acpi_gbl_root_table_list.tables[i].length) { 301 /*
290 continue; 302 * Initialize the table entry. Set the pointer to NULL, since the
303 * table is not fully mapped at this time.
304 */
305 ACPI_MEMSET(table_desc, 0, sizeof(struct acpi_table_desc));
306 table_desc->address = address;
307 table_desc->length = table->length;
308 table_desc->flags = flags;
309 ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
310}
311
312/*******************************************************************************
313 *
314 * FUNCTION: acpi_tb_acquire_temporal_table
315 *
316 * PARAMETERS: table_desc - Table descriptor to be acquired
317 * address - Address of the table
318 * flags - Allocation flags of the table
319 *
320 * RETURN: Status
321 *
322 * DESCRIPTION: This function validates the table header to obtain the length
323 * of a table and fills the table descriptor to make its state as
324 * "INSTALLED". Such table descriptor is only used for verified
325 * installation.
326 *
327 ******************************************************************************/
328
329static acpi_status
330acpi_tb_acquire_temporal_table(struct acpi_table_desc *table_desc,
331 acpi_physical_address address, u8 flags)
332{
333 struct acpi_table_header *table_header;
334
335 switch (flags & ACPI_TABLE_ORIGIN_MASK) {
336 case ACPI_TABLE_ORIGIN_MAPPED:
337
338 /* Try to obtain the length of the table */
339
340 table_header =
341 acpi_os_map_memory(address,
342 sizeof(struct acpi_table_header));
343 if (!table_header) {
344 return (AE_NO_MEMORY);
291 } 345 }
346 acpi_tb_install_table(table_desc, address, flags, table_header);
347 acpi_os_unmap_memory(table_header,
348 sizeof(struct acpi_table_header));
349 return (AE_OK);
292 350
293 if (ACPI_MEMCMP(table_desc->pointer, 351 case ACPI_TABLE_ORIGIN_ALLOCATED:
294 acpi_gbl_root_table_list.tables[i].pointer, 352 case ACPI_TABLE_ORIGIN_UNKNOWN:
295 acpi_gbl_root_table_list.tables[i].length)) { 353 case ACPI_TABLE_ORIGIN_OVERRIDE:
296 continue; 354
355 table_header = ACPI_CAST_PTR(struct acpi_table_header, address);
356 if (!table_header) {
357 return (AE_NO_MEMORY);
297 } 358 }
359 acpi_tb_install_table(table_desc, address, flags, table_header);
360 return (AE_OK);
298 361
299 /* 362 default:
300 * Note: the current mechanism does not unregister a table if it is
301 * dynamically unloaded. The related namespace entries are deleted,
302 * but the table remains in the root table list.
303 *
304 * The assumption here is that the number of different tables that
305 * will be loaded is actually small, and there is minimal overhead
306 * in just keeping the table in case it is needed again.
307 *
308 * If this assumption changes in the future (perhaps on large
309 * machines with many table load/unload operations), tables will
310 * need to be unregistered when they are unloaded, and slots in the
311 * root table list should be reused when empty.
312 */
313 *table_index = i;
314 363
315 if (acpi_gbl_root_table_list.tables[i]. 364 break;
316 flags & ACPI_TABLE_IS_LOADED) { 365 }
317 366
318 /* Table is still loaded, this is an error */ 367 /* Table is not valid yet */
319 368
320 status = AE_ALREADY_EXISTS; 369 return (AE_NO_MEMORY);
321 goto release; 370}
322 } else { 371
323 /* Table was unloaded, allow it to be reloaded */ 372/*******************************************************************************
324 373 *
325 acpi_tb_uninstall_table(table_desc); 374 * FUNCTION: acpi_tb_release_temporal_table
326 table_desc->pointer = 375 *
327 acpi_gbl_root_table_list.tables[i].pointer; 376 * PARAMETERS: table_desc - Table descriptor to be released
328 table_desc->address = 377 *
329 acpi_gbl_root_table_list.tables[i].address; 378 * RETURN: Status
330 status = AE_OK; 379 *
331 goto print_header; 380 * DESCRIPTION: The reversal of acpi_tb_acquire_temporal_table().
332 } 381 *
382 ******************************************************************************/
383
384static void acpi_tb_release_temporal_table(struct acpi_table_desc *table_desc)
385{
386 /*
387 * Note that the .Address is maintained by the callers of
388 * acpi_tb_acquire_temporal_table(), thus do not invoke acpi_tb_uninstall_table()
389 * where .Address will be freed.
390 */
391 acpi_tb_invalidate_table(table_desc);
392}
393
394/*******************************************************************************
395 *
396 * FUNCTION: acpi_tb_install_and_override_table
397 *
398 * PARAMETERS: table_index - Index into root table array
399 * new_table_desc - New table descriptor to install
400 *
401 * RETURN: None
402 *
403 * DESCRIPTION: Install an ACPI table into the global data structure. The
404 * table override mechanism is called to allow the host
405 * OS to replace any table before it is installed in the root
406 * table array.
407 *
408 ******************************************************************************/
409
410void
411acpi_tb_install_and_override_table(u32 table_index,
412 struct acpi_table_desc *new_table_desc)
413{
414 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
415 return;
333 } 416 }
334 417
335 /* 418 /*
336 * ACPI Table Override: 419 * ACPI Table Override:
337 * Allow the host to override dynamically loaded tables. 420 *
338 * NOTE: the table is fully mapped at this point, and the mapping will 421 * Before we install the table, let the host OS override it with a new
339 * be deleted by acpi_tb_override_table if the table is actually overridden. 422 * one if desired. Any table within the RSDT/XSDT can be replaced,
423 * including the DSDT which is pointed to by the FADT.
340 */ 424 */
341 final_table = acpi_tb_override_table(table_desc->pointer, table_desc); 425 acpi_tb_override_table(new_table_desc);
342 if (final_table) { 426
427 acpi_tb_install_table(&acpi_gbl_root_table_list.tables[table_index],
428 new_table_desc->address, new_table_desc->flags,
429 new_table_desc->pointer);
343 430
344 /* Ensure table descriptor is in "VALIDATED" state */ 431 acpi_tb_print_table_header(new_table_desc->address,
432 new_table_desc->pointer);
345 433
346 table_desc->pointer = final_table; 434 /* Set the global integer width (based upon revision of the DSDT) */
435
436 if (table_index == ACPI_TABLE_INDEX_DSDT) {
437 acpi_ut_set_integer_width(new_table_desc->pointer->revision);
438 }
439}
440
441/*******************************************************************************
442 *
443 * FUNCTION: acpi_tb_install_fixed_table
444 *
445 * PARAMETERS: address - Physical address of DSDT or FACS
446 * signature - Table signature, NULL if no need to
447 * match
448 * table_index - Index into root table array
449 *
450 * RETURN: Status
451 *
452 * DESCRIPTION: Install a fixed ACPI table (DSDT/FACS) into the global data
453 * structure.
454 *
455 ******************************************************************************/
456
457acpi_status
458acpi_tb_install_fixed_table(acpi_physical_address address,
459 char *signature, u32 table_index)
460{
461 struct acpi_table_desc new_table_desc;
462 acpi_status status;
463
464 ACPI_FUNCTION_TRACE(tb_install_fixed_table);
465
466 if (!address) {
467 ACPI_ERROR((AE_INFO,
468 "Null physical address for ACPI table [%s]",
469 signature));
470 return (AE_NO_MEMORY);
471 }
472
473 /* Fill a table descriptor for validation */
474
475 status = acpi_tb_acquire_temporal_table(&new_table_desc, address,
476 ACPI_TABLE_ORIGIN_MAPPED);
477 if (ACPI_FAILURE(status)) {
478 ACPI_ERROR((AE_INFO, "Could not acquire table length at %p",
479 ACPI_CAST_PTR(void, address)));
480 return_ACPI_STATUS(status);
481 }
482
483 /* Validate and verify a table before installation */
484
485 status = acpi_tb_verify_table(&new_table_desc, signature);
486 if (ACPI_FAILURE(status)) {
487 goto release_and_exit;
488 }
489
490 acpi_tb_install_and_override_table(table_index, &new_table_desc);
491
492release_and_exit:
493
494 /* Release the temporal table descriptor */
495
496 acpi_tb_release_temporal_table(&new_table_desc);
497 return_ACPI_STATUS(status);
498}
499
500/*******************************************************************************
501 *
502 * FUNCTION: acpi_tb_is_equivalent_table
503 *
504 * PARAMETERS: table_desc - Table 1 descriptor to be compared
505 * table_index - Index of table 2 to be compared
506 *
507 * RETURN: TRUE if 2 tables are equivalent
508 *
509 * DESCRIPTION: This function is called to compare a table with what have
510 * already been installed in the root table list.
511 *
512 ******************************************************************************/
513
514static u8
515acpi_tb_is_equivalent_table(struct acpi_table_desc *table_desc, u32 table_index)
516{
517 acpi_status status = AE_OK;
518 u8 is_equivalent;
519 struct acpi_table_header *table;
520 u32 table_length;
521 u8 table_flags;
522
523 status =
524 acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
525 &table, &table_length, &table_flags);
526 if (ACPI_FAILURE(status)) {
527 return (FALSE);
528 }
529
530 /*
531 * Check for a table match on the entire table length,
532 * not just the header.
533 */
534 is_equivalent = (u8)((table_desc->length != table_length ||
535 ACPI_MEMCMP(table_desc->pointer, table,
536 table_length)) ? FALSE : TRUE);
537
538 /* Release the acquired table */
539
540 acpi_tb_release_table(table, table_length, table_flags);
541
542 return (is_equivalent);
543}
544
545/*******************************************************************************
546 *
547 * FUNCTION: acpi_tb_install_non_fixed_table
548 *
549 * PARAMETERS: address - Address of the table (might be a logical
550 * address depending on the table_flags)
551 * flags - Flags for the table
552 * reload - Whether reload should be performed
553 * table_index - Where the table index is returned
554 *
555 * RETURN: Status
556 *
557 * DESCRIPTION: This function is called to install an ACPI table that is
558 * neither DSDT nor FACS.
559 * When this function is called by "Load" or "LoadTable" opcodes,
560 * or by acpi_load_table() API, the "Reload" parameter is set.
561 * After sucessfully returning from this function, table is
562 * "INSTALLED" but not "VALIDATED".
563 *
564 ******************************************************************************/
565
566acpi_status
567acpi_tb_install_non_fixed_table(acpi_physical_address address,
568 u8 flags, u8 reload, u32 *table_index)
569{
570 u32 i;
571 acpi_status status = AE_OK;
572 struct acpi_table_desc new_table_desc;
573
574 ACPI_FUNCTION_TRACE(tb_install_non_fixed_table);
575
576 /* Acquire a temporal table descriptor for validation */
577
578 status =
579 acpi_tb_acquire_temporal_table(&new_table_desc, address, flags);
580 if (ACPI_FAILURE(status)) {
581 ACPI_ERROR((AE_INFO, "Could not acquire table length at %p",
582 ACPI_CAST_PTR(void, address)));
583 return_ACPI_STATUS(status);
584 }
585
586 /* Validate and verify a table before installation */
587
588 status = acpi_tb_verify_table(&new_table_desc, NULL);
589 if (ACPI_FAILURE(status)) {
590 goto release_and_exit;
591 }
592
593 if (reload) {
594 /*
595 * Validate the incoming table signature.
596 *
597 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
598 * 2) We added support for OEMx tables, signature "OEM".
599 * 3) Valid tables were encountered with a null signature, so we just
600 * gave up on validating the signature, (05/2008).
601 * 4) We encountered non-AML tables such as the MADT, which caused
602 * interpreter errors and kernel faults. So now, we once again allow
603 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
604 */
605 if ((new_table_desc.signature.ascii[0] != 0x00) &&
606 (!ACPI_COMPARE_NAME
607 (&new_table_desc.signature, ACPI_SIG_SSDT))
608 && (ACPI_STRNCMP(new_table_desc.signature.ascii, "OEM", 3)))
609 {
610 ACPI_BIOS_ERROR((AE_INFO,
611 "Table has invalid signature [%4.4s] (0x%8.8X), "
612 "must be SSDT or OEMx",
613 acpi_ut_valid_acpi_name(new_table_desc.
614 signature.
615 ascii) ?
616 new_table_desc.signature.
617 ascii : "????",
618 new_table_desc.signature.integer));
619
620 status = AE_BAD_SIGNATURE;
621 goto release_and_exit;
622 }
623
624 /* Check if table is already registered */
625
626 for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
627 ++i) {
628 /*
629 * Check for a table match on the entire table length,
630 * not just the header.
631 */
632 if (!acpi_tb_is_equivalent_table(&new_table_desc, i)) {
633 continue;
634 }
635
636 /*
637 * Note: the current mechanism does not unregister a table if it is
638 * dynamically unloaded. The related namespace entries are deleted,
639 * but the table remains in the root table list.
640 *
641 * The assumption here is that the number of different tables that
642 * will be loaded is actually small, and there is minimal overhead
643 * in just keeping the table in case it is needed again.
644 *
645 * If this assumption changes in the future (perhaps on large
646 * machines with many table load/unload operations), tables will
647 * need to be unregistered when they are unloaded, and slots in the
648 * root table list should be reused when empty.
649 */
650 if (acpi_gbl_root_table_list.tables[i].
651 flags & ACPI_TABLE_IS_LOADED) {
652
653 /* Table is still loaded, this is an error */
654
655 status = AE_ALREADY_EXISTS;
656 goto release_and_exit;
657 } else {
658 /*
659 * Table was unloaded, allow it to be reloaded.
660 * As we are going to return AE_OK to the caller, we should
661 * take the responsibility of freeing the input descriptor.
662 * Refill the input descriptor to ensure
663 * acpi_tb_install_and_override_table() can be called again to
664 * indicate the re-installation.
665 */
666 acpi_tb_uninstall_table(&new_table_desc);
667 *table_index = i;
668 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
669 return_ACPI_STATUS(AE_OK);
670 }
671 }
347 } 672 }
348 673
349 /* Add the table to the global root table list */ 674 /* Add the table to the global root table list */
350 675
351 status = acpi_tb_store_table(table_desc->address, table_desc->pointer, 676 status = acpi_tb_acquire_root_table_entry(&i);
352 table_desc->length, table_desc->flags,
353 table_index);
354 if (ACPI_FAILURE(status)) { 677 if (ACPI_FAILURE(status)) {
355 goto release; 678 goto release_and_exit;
356 } 679 }
680 *table_index = i;
681 acpi_tb_install_and_override_table(i, &new_table_desc);
357 682
358print_header: 683release_and_exit:
359 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
360 684
361release: 685 /* Release the temporal table descriptor */
362 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 686
687 acpi_tb_release_temporal_table(&new_table_desc);
363 return_ACPI_STATUS(status); 688 return_ACPI_STATUS(status);
364} 689}
365 690
@@ -367,97 +692,82 @@ release:
367 * 692 *
368 * FUNCTION: acpi_tb_override_table 693 * FUNCTION: acpi_tb_override_table
369 * 694 *
370 * PARAMETERS: table_header - Header for the original table 695 * PARAMETERS: old_table_desc - Validated table descriptor to be
371 * table_desc - Table descriptor initialized for the 696 * overridden
372 * original table. May or may not be mapped.
373 * 697 *
374 * RETURN: Pointer to the entire new table. NULL if table not overridden. 698 * RETURN: None
375 * If overridden, installs the new table within the input table
376 * descriptor.
377 * 699 *
378 * DESCRIPTION: Attempt table override by calling the OSL override functions. 700 * DESCRIPTION: Attempt table override by calling the OSL override functions.
379 * Note: If the table is overridden, then the entire new table 701 * Note: If the table is overridden, then the entire new table
380 * is acquired and returned by this function. 702 * is acquired and returned by this function.
381 * After invocation, the table descriptor is in a state that is 703 * Before/after invocation, the table descriptor is in a state
382 * "INSTALLED" but not "VALIDATED", thus the "Pointer" member is 704 * that is "VALIDATED".
383 * kept NULL.
384 * 705 *
385 ******************************************************************************/ 706 ******************************************************************************/
386 707
387struct acpi_table_header *acpi_tb_override_table(struct acpi_table_header 708void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
388 *table_header,
389 struct acpi_table_desc
390 *table_desc)
391{ 709{
392 acpi_status status; 710 acpi_status status;
393 struct acpi_table_header *new_table;
394 u32 new_table_length;
395 u8 new_flags;
396 char *override_type; 711 char *override_type;
397 struct acpi_table_desc new_table_desc; 712 struct acpi_table_desc new_table_desc;
398 713 struct acpi_table_header *table;
399 ACPI_MEMSET(&new_table_desc, 0, sizeof(struct acpi_table_desc)); 714 acpi_physical_address address;
715 u32 length;
400 716
401 /* (1) Attempt logical override (returns a logical address) */ 717 /* (1) Attempt logical override (returns a logical address) */
402 718
403 status = acpi_os_table_override(table_header, &new_table_desc.pointer); 719 status = acpi_os_table_override(old_table_desc->pointer, &table);
404 if (ACPI_SUCCESS(status) && new_table_desc.pointer) { 720 if (ACPI_SUCCESS(status) && table) {
405 new_table_desc.address = 721 acpi_tb_acquire_temporal_table(&new_table_desc,
406 ACPI_PTR_TO_PHYSADDR(new_table_desc.pointer); 722 ACPI_PTR_TO_PHYSADDR(table),
407 new_table_desc.length = new_table_desc.pointer->length; 723 ACPI_TABLE_ORIGIN_OVERRIDE);
408 new_table_desc.flags = ACPI_TABLE_ORIGIN_OVERRIDE;
409 override_type = "Logical"; 724 override_type = "Logical";
410 goto finish_override; 725 goto finish_override;
411 } 726 }
412 727
413 /* (2) Attempt physical override (returns a physical address) */ 728 /* (2) Attempt physical override (returns a physical address) */
414 729
415 status = acpi_os_physical_table_override(table_header, 730 status = acpi_os_physical_table_override(old_table_desc->pointer,
416 &new_table_desc.address, 731 &address, &length);
417 &new_table_desc.length); 732 if (ACPI_SUCCESS(status) && address && length) {
418 if (ACPI_SUCCESS(status) && new_table_desc.address 733 acpi_tb_acquire_temporal_table(&new_table_desc, address,
419 && new_table_desc.length) { 734 ACPI_TABLE_ORIGIN_MAPPED);
420 override_type = "Physical"; 735 override_type = "Physical";
421 new_table_desc.flags = ACPI_TABLE_ORIGIN_MAPPED;
422 goto finish_override; 736 goto finish_override;
423 } 737 }
424 738
425 return (NULL); /* There was no override */ 739 return; /* There was no override */
426 740
427finish_override: 741finish_override:
428 742
429 /* 743 /* Validate and verify a table before overriding */
430 * Acquire the entire new table to indicate overridden. 744
431 * Note that this is required by the callers of this function. 745 status = acpi_tb_verify_table(&new_table_desc, NULL);
432 */
433 status = acpi_tb_acquire_table(&new_table_desc, &new_table,
434 &new_table_length, &new_flags);
435 if (ACPI_FAILURE(status)) { 746 if (ACPI_FAILURE(status)) {
436 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, 747 return;
437 "%4.4s " ACPI_PRINTF_UINT
438 " Attempted table override failed",
439 table_header->signature,
440 ACPI_FORMAT_TO_UINT(table_desc->address)));
441 return (NULL);
442 } 748 }
443 749
444 ACPI_INFO((AE_INFO, "%4.4s " ACPI_PRINTF_UINT 750 ACPI_INFO((AE_INFO, "%4.4s " ACPI_PRINTF_UINT
445 " %s table override, new table: " ACPI_PRINTF_UINT, 751 " %s table override, new table: " ACPI_PRINTF_UINT,
446 table_header->signature, 752 old_table_desc->signature.ascii,
447 ACPI_FORMAT_TO_UINT(table_desc->address), 753 ACPI_FORMAT_TO_UINT(old_table_desc->address),
448 override_type, ACPI_FORMAT_TO_UINT(new_table_desc.address))); 754 override_type, ACPI_FORMAT_TO_UINT(new_table_desc.address)));
449 755
450 /* We can now uninstall the original table (if fully mapped) */ 756 /* We can now uninstall the original table */
451 757
452 acpi_tb_uninstall_table(table_desc); 758 acpi_tb_uninstall_table(old_table_desc);
453 759
454 /* Install the new table */ 760 /*
761 * Replace the original table descriptor and keep its state as
762 * "VALIDATED".
763 */
764 acpi_tb_install_table(old_table_desc, new_table_desc.address,
765 new_table_desc.flags, new_table_desc.pointer);
766 acpi_tb_validate_table(old_table_desc);
455 767
456 table_desc->address = new_table_desc.address; 768 /* Release the temporal table descriptor */
457 table_desc->length = new_table_desc.length;
458 table_desc->flags = new_table_desc.flags;
459 769
460 return (new_table); 770 acpi_tb_release_temporal_table(&new_table_desc);
461} 771}
462 772
463/******************************************************************************* 773/*******************************************************************************
@@ -526,26 +836,19 @@ acpi_status acpi_tb_resize_root_table_list(void)
526 836
527/******************************************************************************* 837/*******************************************************************************
528 * 838 *
529 * FUNCTION: acpi_tb_store_table 839 * FUNCTION: acpi_tb_acquire_root_table_entry
530 * 840 *
531 * PARAMETERS: address - Table address 841 * PARAMETERS: table_index - Where table index is returned
532 * table - Table header
533 * length - Table length
534 * flags - flags
535 * 842 *
536 * RETURN: Status and table index. 843 * RETURN: Status and table index.
537 * 844 *
538 * DESCRIPTION: Add an ACPI table to the global table list 845 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
539 * 846 *
540 ******************************************************************************/ 847 ******************************************************************************/
541 848
542acpi_status 849static acpi_status acpi_tb_acquire_root_table_entry(u32 *table_index)
543acpi_tb_store_table(acpi_physical_address address,
544 struct acpi_table_header *table,
545 u32 length, u8 flags, u32 *table_index)
546{ 850{
547 acpi_status status; 851 acpi_status status;
548 struct acpi_table_desc *new_table;
549 852
550 /* Ensure that there is room for the table in the Root Table List */ 853 /* Ensure that there is room for the table in the Root Table List */
551 854
@@ -557,22 +860,45 @@ acpi_tb_store_table(acpi_physical_address address,
557 } 860 }
558 } 861 }
559 862
560 new_table = 863 *table_index = acpi_gbl_root_table_list.current_table_count;
561 &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list. 864 acpi_gbl_root_table_list.current_table_count++;
562 current_table_count]; 865 return (AE_OK);
866}
563 867
564 /* Initialize added table */ 868/*******************************************************************************
869 *
870 * FUNCTION: acpi_tb_store_table
871 *
872 * PARAMETERS: address - Table address
873 * table - Table header
874 * length - Table length
875 * flags - flags
876 *
877 * RETURN: Status and table index.
878 *
879 * DESCRIPTION: Add an ACPI table to the global table list
880 *
881 ******************************************************************************/
882
883acpi_status
884acpi_tb_store_table(acpi_physical_address address,
885 struct acpi_table_header * table,
886 u32 length, u8 flags, u32 *table_index)
887{
888 acpi_status status;
889 struct acpi_table_desc *table_desc;
890
891 status = acpi_tb_acquire_root_table_entry(table_index);
892 if (ACPI_FAILURE(status)) {
893 return (status);
894 }
565 895
566 new_table->address = address; 896 /* Initialize added table */
567 new_table->pointer = table;
568 new_table->length = length;
569 new_table->owner_id = 0;
570 new_table->flags = flags;
571 897
572 ACPI_MOVE_32_TO_32(&new_table->signature, table->signature); 898 table_desc = &acpi_gbl_root_table_list.tables[*table_index];
899 acpi_tb_install_table(table_desc, address, flags, table);
900 table_desc->pointer = table;
573 901
574 *table_index = acpi_gbl_root_table_list.current_table_count;
575 acpi_gbl_root_table_list.current_table_count++;
576 return (AE_OK); 902 return (AE_OK);
577} 903}
578 904
diff --git a/drivers/acpi/acpica/tbutils.c b/drivers/acpi/acpica/tbutils.c
index c61432fa4332..e58dfbf9dd3e 100644
--- a/drivers/acpi/acpica/tbutils.c
+++ b/drivers/acpi/acpica/tbutils.c
@@ -179,9 +179,10 @@ struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
179 179
180 ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length); 180 ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length);
181 acpi_tb_uninstall_table(table_desc); 181 acpi_tb_uninstall_table(table_desc);
182 table_desc->address = ACPI_PTR_TO_PHYSADDR(new_table); 182 acpi_tb_install_table(&acpi_gbl_root_table_list.
183 table_desc->pointer = new_table; 183 tables[ACPI_TABLE_INDEX_DSDT],
184 table_desc->flags = ACPI_TABLE_ORIGIN_ALLOCATED; 184 ACPI_PTR_TO_PHYSADDR(new_table),
185 ACPI_TABLE_ORIGIN_ALLOCATED, new_table);
185 186
186 ACPI_INFO((AE_INFO, 187 ACPI_INFO((AE_INFO,
187 "Forced DSDT copy: length 0x%05X copied locally, original unmapped", 188 "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
@@ -192,121 +193,6 @@ struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
192 193
193/******************************************************************************* 194/*******************************************************************************
194 * 195 *
195 * FUNCTION: acpi_tb_install_table
196 *
197 * PARAMETERS: address - Physical address of DSDT or FACS
198 * signature - Table signature, NULL if no need to
199 * match
200 * table_index - Index into root table array
201 *
202 * RETURN: None
203 *
204 * DESCRIPTION: Install an ACPI table into the global data structure. The
205 * table override mechanism is called to allow the host
206 * OS to replace any table before it is installed in the root
207 * table array.
208 *
209 ******************************************************************************/
210
211void
212acpi_tb_install_table(acpi_physical_address address,
213 char *signature, u32 table_index)
214{
215 struct acpi_table_header *table;
216 struct acpi_table_header *final_table;
217 struct acpi_table_desc *table_desc;
218
219 if (!address) {
220 ACPI_ERROR((AE_INFO,
221 "Null physical address for ACPI table [%s]",
222 signature));
223 return;
224 }
225
226 /* Map just the table header */
227
228 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
229 if (!table) {
230 ACPI_ERROR((AE_INFO,
231 "Could not map memory for table [%s] at %p",
232 signature, ACPI_CAST_PTR(void, address)));
233 return;
234 }
235
236 /* If a particular signature is expected (DSDT/FACS), it must match */
237
238 if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
239 ACPI_BIOS_ERROR((AE_INFO,
240 "Invalid signature 0x%X for ACPI table, expected [%s]",
241 *ACPI_CAST_PTR(u32, table->signature),
242 signature));
243 goto unmap_and_exit;
244 }
245
246 /*
247 * Initialize the table entry. Set the pointer to NULL, since the
248 * table is not fully mapped at this time.
249 */
250 table_desc = &acpi_gbl_root_table_list.tables[table_index];
251
252 table_desc->address = address;
253 table_desc->pointer = NULL;
254 table_desc->length = table->length;
255 table_desc->flags = ACPI_TABLE_ORIGIN_MAPPED;
256 ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
257
258 /*
259 * ACPI Table Override:
260 *
261 * Before we install the table, let the host OS override it with a new
262 * one if desired. Any table within the RSDT/XSDT can be replaced,
263 * including the DSDT which is pointed to by the FADT.
264 *
265 * NOTE: If the table is overridden, then final_table will contain a
266 * mapped pointer to the full new table. If the table is not overridden,
267 * or if there has been a physical override, then the table will be
268 * fully mapped later (in verify table). In any case, we must
269 * unmap the header that was mapped above.
270 */
271 final_table = acpi_tb_override_table(table, table_desc);
272 if (!final_table) {
273 final_table = table; /* There was no override */
274 }
275
276 acpi_tb_print_table_header(table_desc->address, final_table);
277
278 /* Set the global integer width (based upon revision of the DSDT) */
279
280 if (table_index == ACPI_TABLE_INDEX_DSDT) {
281 acpi_ut_set_integer_width(final_table->revision);
282 }
283
284 /*
285 * If we have a physical override during this early loading of the ACPI
286 * tables, unmap the table for now. It will be mapped again later when
287 * it is actually used. This supports very early loading of ACPI tables,
288 * before virtual memory is fully initialized and running within the
289 * host OS. Note: A logical override has the ACPI_TABLE_ORIGIN_OVERRIDE
290 * flag set and will not be deleted below.
291 */
292 if (final_table != table) {
293 /*
294 * Table is in "INSTALLED" state, the final_table pointer is not
295 * maintained in the root table list.
296 */
297 acpi_tb_release_table(final_table, table_desc->length,
298 table_desc->flags);
299 }
300
301unmap_and_exit:
302
303 /* Always unmap the table header that we mapped above */
304
305 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
306}
307
308/*******************************************************************************
309 *
310 * FUNCTION: acpi_tb_get_root_table_entry 196 * FUNCTION: acpi_tb_get_root_table_entry
311 * 197 *
312 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry 198 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
@@ -470,6 +356,7 @@ acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
470 u32 length; 356 u32 length;
471 u8 *table_entry; 357 u8 *table_entry;
472 acpi_status status; 358 acpi_status status;
359 u32 table_index;
473 360
474 ACPI_FUNCTION_TRACE(tb_parse_root_table); 361 ACPI_FUNCTION_TRACE(tb_parse_root_table);
475 362
@@ -579,31 +466,24 @@ acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
579 /* Initialize the root table array from the RSDT/XSDT */ 466 /* Initialize the root table array from the RSDT/XSDT */
580 467
581 for (i = 0; i < table_count; i++) { 468 for (i = 0; i < table_count; i++) {
582 if (acpi_gbl_root_table_list.current_table_count >=
583 acpi_gbl_root_table_list.max_table_count) {
584
585 /* There is no more room in the root table array, attempt resize */
586
587 status = acpi_tb_resize_root_table_list();
588 if (ACPI_FAILURE(status)) {
589 ACPI_WARNING((AE_INFO,
590 "Truncating %u table entries!",
591 (unsigned)(table_count -
592 (acpi_gbl_root_table_list.
593 current_table_count -
594 2))));
595 break;
596 }
597 }
598 469
599 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */ 470 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
600 471
601 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list. 472 status =
602 current_table_count].address = 473 acpi_tb_install_non_fixed_table(acpi_tb_get_root_table_entry
603 acpi_tb_get_root_table_entry(table_entry, table_entry_size); 474 (table_entry,
475 table_entry_size),
476 ACPI_TABLE_ORIGIN_MAPPED,
477 FALSE, &table_index);
478
479 if (ACPI_SUCCESS(status) &&
480 ACPI_COMPARE_NAME(&acpi_gbl_root_table_list.
481 tables[table_index].signature,
482 ACPI_SIG_FADT)) {
483 acpi_tb_parse_fadt(table_index);
484 }
604 485
605 table_entry += table_entry_size; 486 table_entry += table_entry_size;
606 acpi_gbl_root_table_list.current_table_count++;
607 } 487 }
608 488
609 /* 489 /*
@@ -612,22 +492,5 @@ acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
612 */ 492 */
613 acpi_os_unmap_memory(table, length); 493 acpi_os_unmap_memory(table, length);
614 494
615 /*
616 * Complete the initialization of the root table array by examining
617 * the header of each table
618 */
619 for (i = 2; i < acpi_gbl_root_table_list.current_table_count; i++) {
620 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
621 address, NULL, i);
622
623 /* Special case for FADT - validate it then get the DSDT and FACS */
624
625 if (ACPI_COMPARE_NAME
626 (&acpi_gbl_root_table_list.tables[i].signature,
627 ACPI_SIG_FADT)) {
628 acpi_tb_parse_fadt(i);
629 }
630 }
631
632 return_ACPI_STATUS(AE_OK); 495 return_ACPI_STATUS(AE_OK);
633} 496}
diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
index a2899b0cab23..77e8d269e491 100644
--- a/drivers/acpi/acpica/tbxfload.c
+++ b/drivers/acpi/acpica/tbxfload.c
@@ -226,7 +226,6 @@ unlock_and_exit:
226acpi_status acpi_load_table(struct acpi_table_header *table) 226acpi_status acpi_load_table(struct acpi_table_header *table)
227{ 227{
228 acpi_status status; 228 acpi_status status;
229 struct acpi_table_desc table_desc;
230 u32 table_index; 229 u32 table_index;
231 230
232 ACPI_FUNCTION_TRACE(acpi_load_table); 231 ACPI_FUNCTION_TRACE(acpi_load_table);
@@ -237,14 +236,6 @@ acpi_status acpi_load_table(struct acpi_table_header *table)
237 return_ACPI_STATUS(AE_BAD_PARAMETER); 236 return_ACPI_STATUS(AE_BAD_PARAMETER);
238 } 237 }
239 238
240 /* Init local table descriptor */
241
242 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
243 table_desc.address = ACPI_PTR_TO_PHYSADDR(table);
244 table_desc.pointer = table;
245 table_desc.length = table->length;
246 table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN;
247
248 /* Must acquire the interpreter lock during this operation */ 239 /* Must acquire the interpreter lock during this operation */
249 240
250 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); 241 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
@@ -255,7 +246,22 @@ acpi_status acpi_load_table(struct acpi_table_header *table)
255 /* Install the table and load it into the namespace */ 246 /* Install the table and load it into the namespace */
256 247
257 ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:")); 248 ACPI_INFO((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
258 status = acpi_tb_add_table(&table_desc, &table_index); 249 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
250 status = acpi_tb_install_non_fixed_table(ACPI_PTR_TO_PHYSADDR(table),
251 ACPI_TABLE_ORIGIN_UNKNOWN,
252 TRUE, &table_index);
253 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
254 if (ACPI_FAILURE(status)) {
255 goto unlock_and_exit;
256 }
257
258 /*
259 * Note: Now table is "INSTALLED", it must be validated before
260 * using.
261 */
262 status =
263 acpi_tb_validate_table(&acpi_gbl_root_table_list.
264 tables[table_index]);
259 if (ACPI_FAILURE(status)) { 265 if (ACPI_FAILURE(status)) {
260 goto unlock_and_exit; 266 goto unlock_and_exit;
261 } 267 }