Linux Audio

Check our new training course

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