Linux Audio

Check our new training course

Loading...
v3.1
  1/******************************************************************************
  2 *
  3 * Module Name: tbinstal - ACPI table installation and removal
  4 *
  5 *****************************************************************************/
  6
  7/*
  8 * Copyright (C) 2000 - 2011, Intel Corp.
  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
 44#include <acpi/acpi.h>
 45#include "accommon.h"
 46#include "acnamesp.h"
 47#include "actables.h"
 48
 49#define _COMPONENT          ACPI_TABLES
 50ACPI_MODULE_NAME("tbinstal")
 51
 52/******************************************************************************
 
 
 
 
 53 *
 54 * FUNCTION:    acpi_tb_verify_table
 55 *
 56 * PARAMETERS:  table_desc          - table
 
 57 *
 58 * RETURN:      Status
 59 *
 60 * DESCRIPTION: this function is called to verify and map table
 
 61 *
 62 *****************************************************************************/
 63acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
 
 
 64{
 65	acpi_status status = AE_OK;
 66
 67	ACPI_FUNCTION_TRACE(tb_verify_table);
 68
 69	/* Map the table if necessary */
 70
 71	if (!table_desc->pointer) {
 72		if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
 73		    ACPI_TABLE_ORIGIN_MAPPED) {
 74			table_desc->pointer =
 75			    acpi_os_map_memory(table_desc->address,
 76					       table_desc->length);
 77		}
 78		if (!table_desc->pointer) {
 79			return_ACPI_STATUS(AE_NO_MEMORY);
 80		}
 81	}
 82
 83	/* FACS is the odd table, has no standard ACPI header and no checksum */
 84
 85	if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
 86
 87		/* Always calculate checksum, ignore bad checksum if requested */
 
 
 88
 89		status =
 90		    acpi_tb_verify_checksum(table_desc->pointer,
 91					    table_desc->length);
 92	}
 93
 94	return_ACPI_STATUS(status);
 
 95}
 96
 97/*******************************************************************************
 98 *
 99 * FUNCTION:    acpi_tb_add_table
100 *
101 * PARAMETERS:  table_desc          - Table descriptor
102 *              table_index         - Where the table index is returned
 
103 *
104 * RETURN:      Status
105 *
106 * DESCRIPTION: This function is called to add an ACPI table. It is used to
107 *              dynamically load tables via the Load and load_table AML
108 *              operators.
 
109 *
110 ******************************************************************************/
111
112acpi_status
113acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
 
114{
115	u32 i;
116	acpi_status status = AE_OK;
117	struct acpi_table_header *override_table = NULL;
118
119	ACPI_FUNCTION_TRACE(tb_add_table);
120
121	if (!table_desc->pointer) {
122		status = acpi_tb_verify_table(table_desc);
123		if (ACPI_FAILURE(status) || !table_desc->pointer) {
124			return_ACPI_STATUS(status);
125		}
126	}
127
128	/*
129	 * Validate the incoming table signature.
130	 *
131	 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
132	 * 2) We added support for OEMx tables, signature "OEM".
133	 * 3) Valid tables were encountered with a null signature, so we just
134	 *    gave up on validating the signature, (05/2008).
135	 * 4) We encountered non-AML tables such as the MADT, which caused
136	 *    interpreter errors and kernel faults. So now, we once again allow
137	 *    only "SSDT", "OEMx", and now, also a null signature. (05/2011).
138	 */
139	if ((table_desc->pointer->signature[0] != 0x00) &&
140	    (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT))
141	    && (ACPI_STRNCMP(table_desc->pointer->signature, "OEM", 3))) {
142		ACPI_ERROR((AE_INFO,
143			    "Table has invalid signature [%4.4s] (0x%8.8X), must be SSDT or OEMx",
144			    acpi_ut_valid_acpi_name(*(u32 *)table_desc->
145						    pointer->
146						    signature) ? table_desc->
147			    pointer->signature : "????",
148			    *(u32 *)table_desc->pointer->signature));
149
150		return_ACPI_STATUS(AE_BAD_SIGNATURE);
151	}
152
153	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
 
 
 
154
155	/* Check if table is already registered */
 
156
157	for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
158		if (!acpi_gbl_root_table_list.tables[i].pointer) {
159			status =
160			    acpi_tb_verify_table(&acpi_gbl_root_table_list.
161						 tables[i]);
162			if (ACPI_FAILURE(status)
163			    || !acpi_gbl_root_table_list.tables[i].pointer) {
164				continue;
165			}
166		}
167
168		/*
169		 * Check for a table match on the entire table length,
170		 * not just the header.
171		 */
172		if (table_desc->length !=
173		    acpi_gbl_root_table_list.tables[i].length) {
174			continue;
175		}
176
177		if (ACPI_MEMCMP(table_desc->pointer,
178				acpi_gbl_root_table_list.tables[i].pointer,
179				acpi_gbl_root_table_list.tables[i].length)) {
180			continue;
181		}
182
183		/*
184		 * Note: the current mechanism does not unregister a table if it is
185		 * dynamically unloaded. The related namespace entries are deleted,
186		 * but the table remains in the root table list.
187		 *
188		 * The assumption here is that the number of different tables that
189		 * will be loaded is actually small, and there is minimal overhead
190		 * in just keeping the table in case it is needed again.
191		 *
192		 * If this assumption changes in the future (perhaps on large
193		 * machines with many table load/unload operations), tables will
194		 * need to be unregistered when they are unloaded, and slots in the
195		 * root table list should be reused when empty.
196		 */
197
198		/*
199		 * Table is already registered.
200		 * We can delete the table that was passed as a parameter.
201		 */
202		acpi_tb_delete_table(table_desc);
203		*table_index = i;
204
205		if (acpi_gbl_root_table_list.tables[i].
206		    flags & ACPI_TABLE_IS_LOADED) {
207
208			/* Table is still loaded, this is an error */
209
210			status = AE_ALREADY_EXISTS;
211			goto release;
212		} else {
213			/* Table was unloaded, allow it to be reloaded */
214
215			table_desc->pointer =
216			    acpi_gbl_root_table_list.tables[i].pointer;
217			table_desc->address =
218			    acpi_gbl_root_table_list.tables[i].address;
219			status = AE_OK;
220			goto print_header;
221		}
222	}
223
224	/*
225	 * ACPI Table Override:
226	 * Allow the host to override dynamically loaded tables.
227	 */
228	status = acpi_os_table_override(table_desc->pointer, &override_table);
229	if (ACPI_SUCCESS(status) && override_table) {
230		ACPI_INFO((AE_INFO,
231			   "%4.4s @ 0x%p Table override, replaced with:",
232			   table_desc->pointer->signature,
233			   ACPI_CAST_PTR(void, table_desc->address)));
234
235		/* We can delete the table that was passed as a parameter */
236
237		acpi_tb_delete_table(table_desc);
238
239		/* Setup descriptor for the new table */
240
241		table_desc->address = ACPI_PTR_TO_PHYSADDR(override_table);
242		table_desc->pointer = override_table;
243		table_desc->length = override_table->length;
244		table_desc->flags = ACPI_TABLE_ORIGIN_OVERRIDE;
245	}
246
247	/* Add the table to the global root table list */
248
249	status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
250				     table_desc->length, table_desc->flags,
251				     table_index);
252	if (ACPI_FAILURE(status)) {
253		goto release;
254	}
255
256      print_header:
257	acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
258
259      release:
260	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
261	return_ACPI_STATUS(status);
262}
263
264/*******************************************************************************
265 *
266 * FUNCTION:    acpi_tb_resize_root_table_list
267 *
268 * PARAMETERS:  None
 
 
 
 
 
269 *
270 * RETURN:      Status
271 *
272 * DESCRIPTION: Expand the size of global table array
 
 
 
 
273 *
274 ******************************************************************************/
275
276acpi_status acpi_tb_resize_root_table_list(void)
 
 
 
277{
278	struct acpi_table_desc *tables;
 
 
279
280	ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
281
282	/* allow_resize flag is a parameter to acpi_initialize_tables */
283
284	if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
 
285		ACPI_ERROR((AE_INFO,
286			    "Resize of Root Table Array is not allowed"));
287		return_ACPI_STATUS(AE_SUPPORT);
 
288	}
289
290	/* Increase the Table Array size */
291
292	tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
293				       max_table_count +
294				       ACPI_ROOT_TABLE_SIZE_INCREMENT) *
295				      sizeof(struct acpi_table_desc));
296	if (!tables) {
297		ACPI_ERROR((AE_INFO,
298			    "Could not allocate new root table array"));
299		return_ACPI_STATUS(AE_NO_MEMORY);
 
300	}
301
302	/* Copy and free the previous table array */
303
304	if (acpi_gbl_root_table_list.tables) {
305		ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
306			    (acpi_size) acpi_gbl_root_table_list.
307			    max_table_count * sizeof(struct acpi_table_desc));
308
309		if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
310			ACPI_FREE(acpi_gbl_root_table_list.tables);
311		}
312	}
313
314	acpi_gbl_root_table_list.tables = tables;
315	acpi_gbl_root_table_list.max_table_count +=
316	    ACPI_ROOT_TABLE_SIZE_INCREMENT;
317	acpi_gbl_root_table_list.flags |= (u8)ACPI_ROOT_ORIGIN_ALLOCATED;
318
319	return_ACPI_STATUS(AE_OK);
320}
321
322/*******************************************************************************
323 *
324 * FUNCTION:    acpi_tb_store_table
325 *
326 * PARAMETERS:  Address             - Table address
327 *              Table               - Table header
328 *              Length              - Table length
329 *              Flags               - flags
330 *
331 * RETURN:      Status and table index.
332 *
333 * DESCRIPTION: Add an ACPI table to the global table list
334 *
335 ******************************************************************************/
336
337acpi_status
338acpi_tb_store_table(acpi_physical_address address,
339		    struct acpi_table_header *table,
340		    u32 length, u8 flags, u32 *table_index)
341{
342	acpi_status status;
343	struct acpi_table_desc *new_table;
344
345	/* Ensure that there is room for the table in the Root Table List */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
347	if (acpi_gbl_root_table_list.current_table_count >=
348	    acpi_gbl_root_table_list.max_table_count) {
349		status = acpi_tb_resize_root_table_list();
350		if (ACPI_FAILURE(status)) {
351			return (status);
352		}
353	}
354
355	new_table =
356	    &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
357					     current_table_count];
358
359	/* Initialize added table */
360
361	new_table->address = address;
362	new_table->pointer = table;
363	new_table->length = length;
364	new_table->owner_id = 0;
365	new_table->flags = flags;
366
367	ACPI_MOVE_32_TO_32(&new_table->signature, table->signature);
368
369	*table_index = acpi_gbl_root_table_list.current_table_count;
370	acpi_gbl_root_table_list.current_table_count++;
371	return (AE_OK);
372}
373
374/*******************************************************************************
375 *
376 * FUNCTION:    acpi_tb_delete_table
377 *
378 * PARAMETERS:  table_index         - Table index
379 *
380 * RETURN:      None
381 *
382 * DESCRIPTION: Delete one internal ACPI table
383 *
384 ******************************************************************************/
385
386void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
387{
388	/* Table must be mapped or allocated */
389	if (!table_desc->pointer) {
390		return;
391	}
392	switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
393	case ACPI_TABLE_ORIGIN_MAPPED:
394		acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
395		break;
396	case ACPI_TABLE_ORIGIN_ALLOCATED:
397		ACPI_FREE(table_desc->pointer);
398		break;
399	default:;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400	}
401
402	table_desc->pointer = NULL;
403}
404
405/*******************************************************************************
406 *
407 * FUNCTION:    acpi_tb_terminate
408 *
409 * PARAMETERS:  None
410 *
411 * RETURN:      None
412 *
413 * DESCRIPTION: Delete all internal ACPI tables
414 *
415 ******************************************************************************/
416
417void acpi_tb_terminate(void)
418{
419	u32 i;
420
421	ACPI_FUNCTION_TRACE(tb_terminate);
422
 
 
 
 
 
 
423	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
424
425	/* Delete the individual tables */
426
427	for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
428		acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
429	}
430
431	/*
432	 * Delete the root table array if allocated locally. Array cannot be
433	 * mapped, so we don't need to check for that flag.
434	 */
435	if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
436		ACPI_FREE(acpi_gbl_root_table_list.tables);
437	}
438
439	acpi_gbl_root_table_list.tables = NULL;
440	acpi_gbl_root_table_list.flags = 0;
441	acpi_gbl_root_table_list.current_table_count = 0;
442
443	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
444	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
 
 
445}
446
447/*******************************************************************************
448 *
449 * FUNCTION:    acpi_tb_delete_namespace_by_owner
450 *
451 * PARAMETERS:  table_index         - Table index
 
452 *
453 * RETURN:      Status
454 *
455 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
 
 
 
 
456 *
457 ******************************************************************************/
458
459acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
460{
461	acpi_owner_id owner_id;
462	acpi_status status;
 
 
 
 
 
463
464	ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
465
466	status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
467	if (ACPI_FAILURE(status)) {
468		return_ACPI_STATUS(status);
 
 
 
 
469	}
470
471	if (table_index >= acpi_gbl_root_table_list.current_table_count) {
472
473		/* The table index does not exist */
474
475		(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
476		return_ACPI_STATUS(AE_NOT_EXIST);
 
 
 
477	}
478
479	/* Get the owner ID for this table, used to delete namespace nodes */
480
481	owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
482	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
483
484	/*
485	 * Need to acquire the namespace writer lock to prevent interference
486	 * with any concurrent namespace walks. The interpreter must be
487	 * released during the deletion since the acquisition of the deletion
488	 * lock may block, and also since the execution of a namespace walk
489	 * must be allowed to use the interpreter.
490	 */
491	(void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
492	status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
493
494	acpi_ns_delete_namespace_by_owner(owner_id);
495	if (ACPI_FAILURE(status)) {
496		return_ACPI_STATUS(status);
497	}
498
499	acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
 
 
 
 
500
501	status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
502	return_ACPI_STATUS(status);
503}
504
505/*******************************************************************************
506 *
507 * FUNCTION:    acpi_tb_allocate_owner_id
508 *
509 * PARAMETERS:  table_index         - Table index
510 *
511 * RETURN:      Status
512 *
513 * DESCRIPTION: Allocates owner_id in table_desc
514 *
515 ******************************************************************************/
516
517acpi_status acpi_tb_allocate_owner_id(u32 table_index)
518{
519	acpi_status status = AE_BAD_PARAMETER;
520
521	ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
522
523	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
524	if (table_index < acpi_gbl_root_table_list.current_table_count) {
525		status = acpi_ut_allocate_owner_id
526		    (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
527	}
528
529	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
530	return_ACPI_STATUS(status);
531}
532
533/*******************************************************************************
534 *
535 * FUNCTION:    acpi_tb_release_owner_id
536 *
537 * PARAMETERS:  table_index         - Table index
538 *
539 * RETURN:      Status
540 *
541 * DESCRIPTION: Releases owner_id in table_desc
542 *
543 ******************************************************************************/
544
545acpi_status acpi_tb_release_owner_id(u32 table_index)
546{
547	acpi_status status = AE_BAD_PARAMETER;
548
549	ACPI_FUNCTION_TRACE(tb_release_owner_id);
550
551	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
552	if (table_index < acpi_gbl_root_table_list.current_table_count) {
553		acpi_ut_release_owner_id(&
554					 (acpi_gbl_root_table_list.
555					  tables[table_index].owner_id));
556		status = AE_OK;
557	}
558
559	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
560	return_ACPI_STATUS(status);
561}
562
563/*******************************************************************************
564 *
565 * FUNCTION:    acpi_tb_get_owner_id
566 *
567 * PARAMETERS:  table_index         - Table index
568 *              owner_id            - Where the table owner_id is returned
569 *
570 * RETURN:      Status
571 *
572 * DESCRIPTION: returns owner_id for the ACPI table
573 *
574 ******************************************************************************/
575
576acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
577{
578	acpi_status status = AE_BAD_PARAMETER;
579
580	ACPI_FUNCTION_TRACE(tb_get_owner_id);
581
582	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
583	if (table_index < acpi_gbl_root_table_list.current_table_count) {
584		*owner_id =
585		    acpi_gbl_root_table_list.tables[table_index].owner_id;
586		status = AE_OK;
587	}
588
589	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
590	return_ACPI_STATUS(status);
591}
592
593/*******************************************************************************
594 *
595 * FUNCTION:    acpi_tb_is_table_loaded
596 *
597 * PARAMETERS:  table_index         - Table index
598 *
599 * RETURN:      Table Loaded Flag
600 *
601 ******************************************************************************/
602
603u8 acpi_tb_is_table_loaded(u32 table_index)
604{
605	u8 is_loaded = FALSE;
606
607	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
608	if (table_index < acpi_gbl_root_table_list.current_table_count) {
609		is_loaded = (u8)
610		    (acpi_gbl_root_table_list.tables[table_index].flags &
611		     ACPI_TABLE_IS_LOADED);
612	}
613
614	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
615	return (is_loaded);
616}
617
618/*******************************************************************************
619 *
620 * FUNCTION:    acpi_tb_set_table_loaded_flag
621 *
622 * PARAMETERS:  table_index         - Table index
623 *              is_loaded           - TRUE if table is loaded, FALSE otherwise
624 *
625 * RETURN:      None
626 *
627 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
628 *
629 ******************************************************************************/
630
631void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
632{
633
634	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
635	if (table_index < acpi_gbl_root_table_list.current_table_count) {
636		if (is_loaded) {
637			acpi_gbl_root_table_list.tables[table_index].flags |=
638			    ACPI_TABLE_IS_LOADED;
639		} else {
640			acpi_gbl_root_table_list.tables[table_index].flags &=
641			    ~ACPI_TABLE_IS_LOADED;
642		}
643	}
644
645	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
 
646}
v4.10.11
  1/******************************************************************************
  2 *
  3 * Module Name: tbinstal - ACPI table installation and removal
  4 *
  5 *****************************************************************************/
  6
  7/*
  8 * Copyright (C) 2000 - 2016, Intel Corp.
  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
 44#include <acpi/acpi.h>
 45#include "accommon.h"
 
 46#include "actables.h"
 47
 48#define _COMPONENT          ACPI_TABLES
 49ACPI_MODULE_NAME("tbinstal")
 50
 51/* Local prototypes */
 52static u8
 53acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index);
 54
 55/*******************************************************************************
 56 *
 57 * FUNCTION:    acpi_tb_compare_tables
 58 *
 59 * PARAMETERS:  table_desc          - Table 1 descriptor to be compared
 60 *              table_index         - Index of table 2 to be compared
 61 *
 62 * RETURN:      TRUE if both tables are identical.
 63 *
 64 * DESCRIPTION: This function compares a table with another table that has
 65 *              already been installed in the root table list.
 66 *
 67 ******************************************************************************/
 68
 69static u8
 70acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
 71{
 72	acpi_status status = AE_OK;
 73	u8 is_identical;
 74	struct acpi_table_header *table;
 75	u32 table_length;
 76	u8 table_flags;
 77
 78	status =
 79	    acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
 80				  &table, &table_length, &table_flags);
 81	if (ACPI_FAILURE(status)) {
 82		return (FALSE);
 
 
 
 
 
 83	}
 84
 85	/*
 86	 * Check for a table match on the entire table length,
 87	 * not just the header.
 88	 */
 89	is_identical = (u8)((table_desc->length != table_length ||
 90			     memcmp(table_desc->pointer, table, table_length)) ?
 91			    FALSE : TRUE);
 92
 93	/* Release the acquired table */
 
 
 
 94
 95	acpi_tb_release_table(table, table_length, table_flags);
 96	return (is_identical);
 97}
 98
 99/*******************************************************************************
100 *
101 * FUNCTION:    acpi_tb_install_table_with_override
102 *
103 * PARAMETERS:  new_table_desc          - New table descriptor to install
104 *              override                - Whether override should be performed
105 *              table_index             - Where the table index is returned
106 *
107 * RETURN:      None
108 *
109 * DESCRIPTION: Install an ACPI table into the global data structure. The
110 *              table override mechanism is called to allow the host
111 *              OS to replace any table before it is installed in the root
112 *              table array.
113 *
114 ******************************************************************************/
115
116void
117acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
118				    u8 override, u32 *table_index)
119{
120	u32 i;
121	acpi_status status;
 
 
 
122
123	status = acpi_tb_get_next_table_descriptor(&i, NULL);
124	if (ACPI_FAILURE(status)) {
125		return;
 
 
126	}
127
128	/*
129	 * ACPI Table Override:
130	 *
131	 * Before we install the table, let the host OS override it with a new
132	 * one if desired. Any table within the RSDT/XSDT can be replaced,
133	 * including the DSDT which is pointed to by the FADT.
 
 
 
 
134	 */
135	if (override) {
136		acpi_tb_override_table(new_table_desc);
 
 
 
 
 
 
 
 
 
 
137	}
138
139	acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i],
140				      new_table_desc->address,
141				      new_table_desc->flags,
142				      new_table_desc->pointer);
143
144	acpi_tb_print_table_header(new_table_desc->address,
145				   new_table_desc->pointer);
146
147	/* This synchronizes acpi_gbl_dsdt_index */
 
 
 
 
 
 
 
 
 
148
149	*table_index = i;
 
 
 
 
 
 
 
150
151	/* Set the global integer width (based upon revision of the DSDT) */
 
 
 
 
152
153	if (i == acpi_gbl_dsdt_index) {
154		acpi_ut_set_integer_width(new_table_desc->pointer->revision);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155	}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156}
157
158/*******************************************************************************
159 *
160 * FUNCTION:    acpi_tb_install_standard_table
161 *
162 * PARAMETERS:  address             - Address of the table (might be a virtual
163 *                                    address depending on the table_flags)
164 *              flags               - Flags for the table
165 *              reload              - Whether reload should be performed
166 *              override            - Whether override should be performed
167 *              table_index         - Where the table index is returned
168 *
169 * RETURN:      Status
170 *
171 * DESCRIPTION: This function is called to verify and install an ACPI table.
172 *              When this function is called by "Load" or "LoadTable" opcodes,
173 *              or by acpi_load_table() API, the "Reload" parameter is set.
174 *              After sucessfully returning from this function, table is
175 *              "INSTALLED" but not "VALIDATED".
176 *
177 ******************************************************************************/
178
179acpi_status
180acpi_tb_install_standard_table(acpi_physical_address address,
181			       u8 flags,
182			       u8 reload, u8 override, u32 *table_index)
183{
184	u32 i;
185	acpi_status status = AE_OK;
186	struct acpi_table_desc new_table_desc;
187
188	ACPI_FUNCTION_TRACE(tb_install_standard_table);
189
190	/* Acquire a temporary table descriptor for validation */
191
192	status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags);
193	if (ACPI_FAILURE(status)) {
194		ACPI_ERROR((AE_INFO,
195			    "Could not acquire table length at %8.8X%8.8X",
196			    ACPI_FORMAT_UINT64(address)));
197		return_ACPI_STATUS(status);
198	}
199
200	/*
201	 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
202	 * be useful for debugging ACPI problems on some machines.
203	 */
204	if (!reload &&
205	    acpi_gbl_disable_ssdt_table_install &&
206	    ACPI_COMPARE_NAME(&new_table_desc.signature, ACPI_SIG_SSDT)) {
207		ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
208			   new_table_desc.signature.ascii,
209			   ACPI_FORMAT_UINT64(address)));
210		goto release_and_exit;
211	}
212
213	/* Validate and verify a table before installation */
 
 
 
 
 
214
215	status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
216	if (ACPI_FAILURE(status)) {
217		goto release_and_exit;
218	}
219
220	/* Acquire the table lock */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
222	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
 
 
 
 
 
 
223
224	if (reload) {
225		/*
226		 * Validate the incoming table signature.
227		 *
228		 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
229		 * 2) We added support for OEMx tables, signature "OEM".
230		 * 3) Valid tables were encountered with a null signature, so we just
231		 *    gave up on validating the signature, (05/2008).
232		 * 4) We encountered non-AML tables such as the MADT, which caused
233		 *    interpreter errors and kernel faults. So now, we once again allow
234		 *    only "SSDT", "OEMx", and now, also a null signature. (05/2011).
235		 */
236		if ((new_table_desc.signature.ascii[0] != 0x00) &&
237		    (!ACPI_COMPARE_NAME
238		     (&new_table_desc.signature, ACPI_SIG_SSDT))
239		    && (strncmp(new_table_desc.signature.ascii, "OEM", 3))) {
240			ACPI_BIOS_ERROR((AE_INFO,
241					 "Table has invalid signature [%4.4s] (0x%8.8X), "
242					 "must be SSDT or OEMx",
243					 acpi_ut_valid_nameseg(new_table_desc.
244							       signature.
245							       ascii) ?
246					 new_table_desc.signature.
247					 ascii : "????",
248					 new_table_desc.signature.integer));
249
250			status = AE_BAD_SIGNATURE;
251			goto unlock_and_exit;
 
 
 
252		}
 
253
254		/* Check if table is already registered */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
256		for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
257		     ++i) {
258			/*
259			 * Check for a table match on the entire table length,
260			 * not just the header.
261			 */
262			if (!acpi_tb_compare_tables(&new_table_desc, i)) {
263				continue;
264			}
 
 
265
266			/*
267			 * Note: the current mechanism does not unregister a table if it is
268			 * dynamically unloaded. The related namespace entries are deleted,
269			 * but the table remains in the root table list.
270			 *
271			 * The assumption here is that the number of different tables that
272			 * will be loaded is actually small, and there is minimal overhead
273			 * in just keeping the table in case it is needed again.
274			 *
275			 * If this assumption changes in the future (perhaps on large
276			 * machines with many table load/unload operations), tables will
277			 * need to be unregistered when they are unloaded, and slots in the
278			 * root table list should be reused when empty.
279			 */
280			if (acpi_gbl_root_table_list.tables[i].flags &
281			    ACPI_TABLE_IS_LOADED) {
282
283				/* Table is still loaded, this is an error */
284
285				status = AE_ALREADY_EXISTS;
286				goto unlock_and_exit;
287			} else {
288				/*
289				 * Table was unloaded, allow it to be reloaded.
290				 * As we are going to return AE_OK to the caller, we should
291				 * take the responsibility of freeing the input descriptor.
292				 * Refill the input descriptor to ensure
293				 * acpi_tb_install_table_with_override() can be called again to
294				 * indicate the re-installation.
295				 */
296				acpi_tb_uninstall_table(&new_table_desc);
297				(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
298				*table_index = i;
299				return_ACPI_STATUS(AE_OK);
300			}
301		}
302	}
303
304	/* Add the table to the global root table list */
 
 
 
 
 
 
 
 
 
 
 
 
 
305
306	acpi_tb_install_table_with_override(&new_table_desc, override,
307					    table_index);
 
308
309	/* Invoke table handler if present */
310
311	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
312	if (acpi_gbl_table_handler) {
313		(void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_INSTALL,
314					     new_table_desc.pointer,
315					     acpi_gbl_table_handler_context);
316	}
317	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
318
319unlock_and_exit:
320
321	/* Release the table lock */
 
 
322
323	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
 
 
 
 
 
 
324
325release_and_exit:
 
 
326
327	/* Release the temporary table descriptor */
328
329	acpi_tb_release_temp_table(&new_table_desc);
330	return_ACPI_STATUS(status);
331}
332
333/*******************************************************************************
334 *
335 * FUNCTION:    acpi_tb_override_table
336 *
337 * PARAMETERS:  old_table_desc      - Validated table descriptor to be
338 *                                    overridden
339 *
340 * RETURN:      None
341 *
342 * DESCRIPTION: Attempt table override by calling the OSL override functions.
343 *              Note: If the table is overridden, then the entire new table
344 *              is acquired and returned by this function.
345 *              Before/after invocation, the table descriptor is in a state
346 *              that is "VALIDATED".
347 *
348 ******************************************************************************/
349
350void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
351{
 
352	acpi_status status;
353	char *override_type;
354	struct acpi_table_desc new_table_desc;
355	struct acpi_table_header *table;
356	acpi_physical_address address;
357	u32 length;
358
359	/* (1) Attempt logical override (returns a logical address) */
360
361	status = acpi_os_table_override(old_table_desc->pointer, &table);
362	if (ACPI_SUCCESS(status) && table) {
363		acpi_tb_acquire_temp_table(&new_table_desc,
364					   ACPI_PTR_TO_PHYSADDR(table),
365					   ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
366		override_type = "Logical";
367		goto finish_override;
368	}
369
370	/* (2) Attempt physical override (returns a physical address) */
371
372	status = acpi_os_physical_table_override(old_table_desc->pointer,
373						 &address, &length);
374	if (ACPI_SUCCESS(status) && address && length) {
375		acpi_tb_acquire_temp_table(&new_table_desc, address,
376					   ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
377		override_type = "Physical";
378		goto finish_override;
379	}
380
381	return;			/* There was no override */
382
383finish_override:
 
384
385	/* Validate and verify a table before overriding */
 
 
 
 
 
 
 
 
386
387	status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
388	if (ACPI_FAILURE(status)) {
389		return;
390	}
391
392	ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
393		   " %s table override, new table: 0x%8.8X%8.8X",
394		   old_table_desc->signature.ascii,
395		   ACPI_FORMAT_UINT64(old_table_desc->address),
396		   override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
397
398	/* We can now uninstall the original table */
 
 
399
400	acpi_tb_uninstall_table(old_table_desc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
402	/*
403	 * Replace the original table descriptor and keep its state as
404	 * "VALIDATED".
405	 */
406	acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
407				      new_table_desc.flags,
408				      new_table_desc.pointer);
409	acpi_tb_validate_temp_table(old_table_desc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
411	/* Release the temporary table descriptor */
412
413	acpi_tb_release_temp_table(&new_table_desc);
 
 
 
 
 
 
 
 
 
414}
415
416/*******************************************************************************
417 *
418 * FUNCTION:    acpi_tb_uninstall_table
419 *
420 * PARAMETERS:  table_desc          - Table descriptor
 
421 *
422 * RETURN:      None
423 *
424 * DESCRIPTION: Delete one internal ACPI table
425 *
426 ******************************************************************************/
427
428void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
429{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
431	ACPI_FUNCTION_TRACE(tb_uninstall_table);
 
 
 
 
 
 
 
 
432
433	/* Table must be installed */
 
 
434
435	if (!table_desc->address) {
436		return_VOID;
 
 
 
437	}
438
439	acpi_tb_invalidate_table(table_desc);
 
 
440
441	if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
442	    ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
443		ACPI_FREE(ACPI_PHYSADDR_TO_PTR(table_desc->address));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444	}
445
446	table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
447	return_VOID;
448}