xref: /openbmc/linux/drivers/acpi/acpica/tbinstal.c (revision 7a37052adb5e843bcfff6c98aee9b60bb087b910)
195b482a8SLen Brown /******************************************************************************
295b482a8SLen Brown  *
395b482a8SLen Brown  * Module Name: tbinstal - ACPI table installation and removal
495b482a8SLen Brown  *
595b482a8SLen Brown  *****************************************************************************/
695b482a8SLen Brown 
795b482a8SLen Brown /*
8c8100dc4SBob Moore  * Copyright (C) 2000 - 2016, Intel Corp.
995b482a8SLen Brown  * All rights reserved.
1095b482a8SLen Brown  *
1195b482a8SLen Brown  * Redistribution and use in source and binary forms, with or without
1295b482a8SLen Brown  * modification, are permitted provided that the following conditions
1395b482a8SLen Brown  * are met:
1495b482a8SLen Brown  * 1. Redistributions of source code must retain the above copyright
1595b482a8SLen Brown  *    notice, this list of conditions, and the following disclaimer,
1695b482a8SLen Brown  *    without modification.
1795b482a8SLen Brown  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1895b482a8SLen Brown  *    substantially similar to the "NO WARRANTY" disclaimer below
1995b482a8SLen Brown  *    ("Disclaimer") and any redistribution must be conditioned upon
2095b482a8SLen Brown  *    including a substantially similar Disclaimer requirement for further
2195b482a8SLen Brown  *    binary redistribution.
2295b482a8SLen Brown  * 3. Neither the names of the above-listed copyright holders nor the names
2395b482a8SLen Brown  *    of any contributors may be used to endorse or promote products derived
2495b482a8SLen Brown  *    from this software without specific prior written permission.
2595b482a8SLen Brown  *
2695b482a8SLen Brown  * Alternatively, this software may be distributed under the terms of the
2795b482a8SLen Brown  * GNU General Public License ("GPL") version 2 as published by the Free
2895b482a8SLen Brown  * Software Foundation.
2995b482a8SLen Brown  *
3095b482a8SLen Brown  * NO WARRANTY
3195b482a8SLen Brown  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3295b482a8SLen Brown  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3395b482a8SLen Brown  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3495b482a8SLen Brown  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3595b482a8SLen Brown  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3695b482a8SLen Brown  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3795b482a8SLen Brown  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3895b482a8SLen Brown  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3995b482a8SLen Brown  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4095b482a8SLen Brown  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4195b482a8SLen Brown  * POSSIBILITY OF SUCH DAMAGES.
4295b482a8SLen Brown  */
4395b482a8SLen Brown 
4495b482a8SLen Brown #include <acpi/acpi.h>
45e2f7a777SLen Brown #include "accommon.h"
46e2f7a777SLen Brown #include "actables.h"
4795b482a8SLen Brown 
4895b482a8SLen Brown #define _COMPONENT          ACPI_TABLES
4995b482a8SLen Brown ACPI_MODULE_NAME("tbinstal")
5095b482a8SLen Brown 
5186dfc6f3SLv Zheng /* Local prototypes */
52c418ce19SBob Moore static u8
53c418ce19SBob Moore acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index);
5486dfc6f3SLv Zheng 
55c418ce19SBob Moore /*******************************************************************************
56c418ce19SBob Moore  *
57c418ce19SBob Moore  * FUNCTION:    acpi_tb_compare_tables
58c418ce19SBob Moore  *
59c418ce19SBob Moore  * PARAMETERS:  table_desc          - Table 1 descriptor to be compared
60c418ce19SBob Moore  *              table_index         - Index of table 2 to be compared
61c418ce19SBob Moore  *
62c418ce19SBob Moore  * RETURN:      TRUE if both tables are identical.
63c418ce19SBob Moore  *
64c418ce19SBob Moore  * DESCRIPTION: This function compares a table with another table that has
65c418ce19SBob Moore  *              already been installed in the root table list.
66c418ce19SBob Moore  *
67c418ce19SBob Moore  ******************************************************************************/
6886dfc6f3SLv Zheng 
6986dfc6f3SLv Zheng static u8
70c418ce19SBob Moore acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
717f9fc99cSLv Zheng {
727f9fc99cSLv Zheng 	acpi_status status = AE_OK;
73c418ce19SBob Moore 	u8 is_identical;
74c418ce19SBob Moore 	struct acpi_table_header *table;
75c418ce19SBob Moore 	u32 table_length;
76c418ce19SBob Moore 	u8 table_flags;
7786dfc6f3SLv Zheng 
7886dfc6f3SLv Zheng 	status =
79c418ce19SBob Moore 	    acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
80c418ce19SBob Moore 				  &table, &table_length, &table_flags);
8186dfc6f3SLv Zheng 	if (ACPI_FAILURE(status)) {
82c418ce19SBob Moore 		return (FALSE);
8386dfc6f3SLv Zheng 	}
8486dfc6f3SLv Zheng 
8586dfc6f3SLv Zheng 	/*
86c418ce19SBob Moore 	 * Check for a table match on the entire table length,
87c418ce19SBob Moore 	 * not just the header.
8886dfc6f3SLv Zheng 	 */
89c418ce19SBob Moore 	is_identical = (u8)((table_desc->length != table_length ||
904fa4616eSBob Moore 			     memcmp(table_desc->pointer, table, table_length)) ?
914fa4616eSBob Moore 			    FALSE : TRUE);
9286dfc6f3SLv Zheng 
93c418ce19SBob Moore 	/* Release the acquired table */
9486dfc6f3SLv Zheng 
95c418ce19SBob Moore 	acpi_tb_release_table(table, table_length, table_flags);
96c418ce19SBob Moore 	return (is_identical);
9786dfc6f3SLv Zheng }
9886dfc6f3SLv Zheng 
9986dfc6f3SLv Zheng /*******************************************************************************
10086dfc6f3SLv Zheng  *
101ed6f1d44SBob Moore  * FUNCTION:    acpi_tb_install_table_with_override
10286dfc6f3SLv Zheng  *
1038ec3f459SLv Zheng  * PARAMETERS:  new_table_desc          - New table descriptor to install
104caf4a15cSLv Zheng  *              override                - Whether override should be performed
1058ec3f459SLv Zheng  *              table_index             - Where the table index is returned
10686dfc6f3SLv Zheng  *
10786dfc6f3SLv Zheng  * RETURN:      None
10886dfc6f3SLv Zheng  *
10986dfc6f3SLv Zheng  * DESCRIPTION: Install an ACPI table into the global data structure. The
11086dfc6f3SLv Zheng  *              table override mechanism is called to allow the host
11186dfc6f3SLv Zheng  *              OS to replace any table before it is installed in the root
11286dfc6f3SLv Zheng  *              table array.
11386dfc6f3SLv Zheng  *
11486dfc6f3SLv Zheng  ******************************************************************************/
11586dfc6f3SLv Zheng 
11686dfc6f3SLv Zheng void
1178ec3f459SLv Zheng acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
1188ec3f459SLv Zheng 				    u8 override, u32 *table_index)
11986dfc6f3SLv Zheng {
1208ec3f459SLv Zheng 	u32 i;
1218ec3f459SLv Zheng 	acpi_status status;
122ed6f1d44SBob Moore 
1238ec3f459SLv Zheng 	status = acpi_tb_get_next_table_descriptor(&i, NULL);
1248ec3f459SLv Zheng 	if (ACPI_FAILURE(status)) {
12586dfc6f3SLv Zheng 		return;
12686dfc6f3SLv Zheng 	}
12786dfc6f3SLv Zheng 
12886dfc6f3SLv Zheng 	/*
12986dfc6f3SLv Zheng 	 * ACPI Table Override:
13086dfc6f3SLv Zheng 	 *
13186dfc6f3SLv Zheng 	 * Before we install the table, let the host OS override it with a new
13286dfc6f3SLv Zheng 	 * one if desired. Any table within the RSDT/XSDT can be replaced,
13386dfc6f3SLv Zheng 	 * including the DSDT which is pointed to by the FADT.
13486dfc6f3SLv Zheng 	 */
135caf4a15cSLv Zheng 	if (override) {
13686dfc6f3SLv Zheng 		acpi_tb_override_table(new_table_desc);
137caf4a15cSLv Zheng 	}
13886dfc6f3SLv Zheng 
1398ec3f459SLv Zheng 	acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i],
140ed6f1d44SBob Moore 				      new_table_desc->address,
141ed6f1d44SBob Moore 				      new_table_desc->flags,
14286dfc6f3SLv Zheng 				      new_table_desc->pointer);
14386dfc6f3SLv Zheng 
14486dfc6f3SLv Zheng 	acpi_tb_print_table_header(new_table_desc->address,
14586dfc6f3SLv Zheng 				   new_table_desc->pointer);
14686dfc6f3SLv Zheng 
1478ec3f459SLv Zheng 	/* This synchronizes acpi_gbl_dsdt_index */
1488ec3f459SLv Zheng 
1498ec3f459SLv Zheng 	*table_index = i;
1508ec3f459SLv Zheng 
15186dfc6f3SLv Zheng 	/* Set the global integer width (based upon revision of the DSDT) */
15286dfc6f3SLv Zheng 
1538ec3f459SLv Zheng 	if (i == acpi_gbl_dsdt_index) {
15486dfc6f3SLv Zheng 		acpi_ut_set_integer_width(new_table_desc->pointer->revision);
15586dfc6f3SLv Zheng 	}
15686dfc6f3SLv Zheng }
15786dfc6f3SLv Zheng 
15886dfc6f3SLv Zheng /*******************************************************************************
15986dfc6f3SLv Zheng  *
160ed6f1d44SBob Moore  * FUNCTION:    acpi_tb_install_standard_table
16186dfc6f3SLv Zheng  *
1628a216d7fSLv Zheng  * PARAMETERS:  address             - Address of the table (might be a virtual
16386dfc6f3SLv Zheng  *                                    address depending on the table_flags)
16486dfc6f3SLv Zheng  *              flags               - Flags for the table
16586dfc6f3SLv Zheng  *              reload              - Whether reload should be performed
166caf4a15cSLv Zheng  *              override            - Whether override should be performed
16786dfc6f3SLv Zheng  *              table_index         - Where the table index is returned
16886dfc6f3SLv Zheng  *
16986dfc6f3SLv Zheng  * RETURN:      Status
17086dfc6f3SLv Zheng  *
171752db101SLv Zheng  * DESCRIPTION: This function is called to verify and install an ACPI table.
17286dfc6f3SLv Zheng  *              When this function is called by "Load" or "LoadTable" opcodes,
17386dfc6f3SLv Zheng  *              or by acpi_load_table() API, the "Reload" parameter is set.
17486dfc6f3SLv Zheng  *              After sucessfully returning from this function, table is
17586dfc6f3SLv Zheng  *              "INSTALLED" but not "VALIDATED".
17686dfc6f3SLv Zheng  *
17786dfc6f3SLv Zheng  ******************************************************************************/
17886dfc6f3SLv Zheng 
17986dfc6f3SLv Zheng acpi_status
180ed6f1d44SBob Moore acpi_tb_install_standard_table(acpi_physical_address address,
181caf4a15cSLv Zheng 			       u8 flags,
182caf4a15cSLv Zheng 			       u8 reload, u8 override, u32 *table_index)
18395b482a8SLen Brown {
18495b482a8SLen Brown 	u32 i;
18595b482a8SLen Brown 	acpi_status status = AE_OK;
18686dfc6f3SLv Zheng 	struct acpi_table_desc new_table_desc;
18795b482a8SLen Brown 
188ed6f1d44SBob Moore 	ACPI_FUNCTION_TRACE(tb_install_standard_table);
18995b482a8SLen Brown 
190ed6f1d44SBob Moore 	/* Acquire a temporary table descriptor for validation */
19186dfc6f3SLv Zheng 
192ed6f1d44SBob Moore 	status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags);
19386dfc6f3SLv Zheng 	if (ACPI_FAILURE(status)) {
194cc2080b0SLv Zheng 		ACPI_ERROR((AE_INFO,
195cc2080b0SLv Zheng 			    "Could not acquire table length at %8.8X%8.8X",
196cc2080b0SLv Zheng 			    ACPI_FORMAT_UINT64(address)));
19795b482a8SLen Brown 		return_ACPI_STATUS(status);
19895b482a8SLen Brown 	}
19986dfc6f3SLv Zheng 
200a94e88cdSLv Zheng 	/*
201a94e88cdSLv Zheng 	 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
202a94e88cdSLv Zheng 	 * be useful for debugging ACPI problems on some machines.
203a94e88cdSLv Zheng 	 */
204ed6f1d44SBob Moore 	if (!reload &&
205ed6f1d44SBob Moore 	    acpi_gbl_disable_ssdt_table_install &&
206a94e88cdSLv Zheng 	    ACPI_COMPARE_NAME(&new_table_desc.signature, ACPI_SIG_SSDT)) {
20705fb04b5SBob Moore 		ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
2086d3fd3ccSLv Zheng 			   new_table_desc.signature.ascii,
209cc2080b0SLv Zheng 			   ACPI_FORMAT_UINT64(address)));
210a94e88cdSLv Zheng 		goto release_and_exit;
211a94e88cdSLv Zheng 	}
212a94e88cdSLv Zheng 
21386dfc6f3SLv Zheng 	/* Validate and verify a table before installation */
21486dfc6f3SLv Zheng 
21547d68c7fSLv Zheng 	status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
21686dfc6f3SLv Zheng 	if (ACPI_FAILURE(status)) {
21786dfc6f3SLv Zheng 		goto release_and_exit;
21895b482a8SLen Brown 	}
21995b482a8SLen Brown 
220*7a37052aSLv Zheng 	/* Acquire the table lock */
221*7a37052aSLv Zheng 
222*7a37052aSLv Zheng 	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
223*7a37052aSLv Zheng 
22486dfc6f3SLv Zheng 	if (reload) {
22595b482a8SLen Brown 		/*
226c8cefe30SBob Moore 		 * Validate the incoming table signature.
227c8cefe30SBob Moore 		 *
228c8cefe30SBob Moore 		 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
229c8cefe30SBob Moore 		 * 2) We added support for OEMx tables, signature "OEM".
230c8cefe30SBob Moore 		 * 3) Valid tables were encountered with a null signature, so we just
231c8cefe30SBob Moore 		 *    gave up on validating the signature, (05/2008).
232c8cefe30SBob Moore 		 * 4) We encountered non-AML tables such as the MADT, which caused
233c8cefe30SBob Moore 		 *    interpreter errors and kernel faults. So now, we once again allow
234c8cefe30SBob Moore 		 *    only "SSDT", "OEMx", and now, also a null signature. (05/2011).
23595b482a8SLen Brown 		 */
23686dfc6f3SLv Zheng 		if ((new_table_desc.signature.ascii[0] != 0x00) &&
23786dfc6f3SLv Zheng 		    (!ACPI_COMPARE_NAME
23886dfc6f3SLv Zheng 		     (&new_table_desc.signature, ACPI_SIG_SSDT))
2394fa4616eSBob Moore 		    && (strncmp(new_table_desc.signature.ascii, "OEM", 3))) {
2403b3ea775SBob Moore 			ACPI_BIOS_ERROR((AE_INFO,
2413b3ea775SBob Moore 					 "Table has invalid signature [%4.4s] (0x%8.8X), "
2423b3ea775SBob Moore 					 "must be SSDT or OEMx",
2436a0df32cSBob Moore 					 acpi_ut_valid_nameseg(new_table_desc.
24486dfc6f3SLv Zheng 							       signature.
24586dfc6f3SLv Zheng 							       ascii) ?
24686dfc6f3SLv Zheng 					 new_table_desc.signature.
24786dfc6f3SLv Zheng 					 ascii : "????",
24886dfc6f3SLv Zheng 					 new_table_desc.signature.integer));
249c8cefe30SBob Moore 
25086dfc6f3SLv Zheng 			status = AE_BAD_SIGNATURE;
251*7a37052aSLv Zheng 			goto unlock_and_exit;
252c8cefe30SBob Moore 		}
25395b482a8SLen Brown 
25495b482a8SLen Brown 		/* Check if table is already registered */
25595b482a8SLen Brown 
25686dfc6f3SLv Zheng 		for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
25786dfc6f3SLv Zheng 		     ++i) {
25895b482a8SLen Brown 			/*
25995b482a8SLen Brown 			 * Check for a table match on the entire table length,
26095b482a8SLen Brown 			 * not just the header.
26195b482a8SLen Brown 			 */
262c418ce19SBob Moore 			if (!acpi_tb_compare_tables(&new_table_desc, i)) {
26395b482a8SLen Brown 				continue;
26495b482a8SLen Brown 			}
26595b482a8SLen Brown 
26695b482a8SLen Brown 			/*
26795b482a8SLen Brown 			 * Note: the current mechanism does not unregister a table if it is
26895b482a8SLen Brown 			 * dynamically unloaded. The related namespace entries are deleted,
26995b482a8SLen Brown 			 * but the table remains in the root table list.
27095b482a8SLen Brown 			 *
27195b482a8SLen Brown 			 * The assumption here is that the number of different tables that
27295b482a8SLen Brown 			 * will be loaded is actually small, and there is minimal overhead
27395b482a8SLen Brown 			 * in just keeping the table in case it is needed again.
27495b482a8SLen Brown 			 *
27595b482a8SLen Brown 			 * If this assumption changes in the future (perhaps on large
27695b482a8SLen Brown 			 * machines with many table load/unload operations), tables will
27795b482a8SLen Brown 			 * need to be unregistered when they are unloaded, and slots in the
27895b482a8SLen Brown 			 * root table list should be reused when empty.
27995b482a8SLen Brown 			 */
2801fad8738SBob Moore 			if (acpi_gbl_root_table_list.tables[i].flags &
2811fad8738SBob Moore 			    ACPI_TABLE_IS_LOADED) {
28295b482a8SLen Brown 
28395b482a8SLen Brown 				/* Table is still loaded, this is an error */
28495b482a8SLen Brown 
28595b482a8SLen Brown 				status = AE_ALREADY_EXISTS;
286*7a37052aSLv Zheng 				goto unlock_and_exit;
28795b482a8SLen Brown 			} else {
288d3ccaff8SBob Moore 				/*
28986dfc6f3SLv Zheng 				 * Table was unloaded, allow it to be reloaded.
29086dfc6f3SLv Zheng 				 * As we are going to return AE_OK to the caller, we should
29186dfc6f3SLv Zheng 				 * take the responsibility of freeing the input descriptor.
29286dfc6f3SLv Zheng 				 * Refill the input descriptor to ensure
293ed6f1d44SBob Moore 				 * acpi_tb_install_table_with_override() can be called again to
29486dfc6f3SLv Zheng 				 * indicate the re-installation.
295d3ccaff8SBob Moore 				 */
29686dfc6f3SLv Zheng 				acpi_tb_uninstall_table(&new_table_desc);
297*7a37052aSLv Zheng 				(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
29886dfc6f3SLv Zheng 				*table_index = i;
29986dfc6f3SLv Zheng 				return_ACPI_STATUS(AE_OK);
30086dfc6f3SLv Zheng 			}
30186dfc6f3SLv Zheng 		}
3027f9fc99cSLv Zheng 	}
303d3ccaff8SBob Moore 
30495b482a8SLen Brown 	/* Add the table to the global root table list */
30595b482a8SLen Brown 
3068ec3f459SLv Zheng 	acpi_tb_install_table_with_override(&new_table_desc, override,
3078ec3f459SLv Zheng 					    table_index);
30895b482a8SLen Brown 
309bdbe5df0SLv Zheng 	/* Invoke table handler if present */
310bdbe5df0SLv Zheng 
311*7a37052aSLv Zheng 	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
312bdbe5df0SLv Zheng 	if (acpi_gbl_table_handler) {
313bdbe5df0SLv Zheng 		(void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_INSTALL,
314bdbe5df0SLv Zheng 					     new_table_desc.pointer,
315bdbe5df0SLv Zheng 					     acpi_gbl_table_handler_context);
316bdbe5df0SLv Zheng 	}
317*7a37052aSLv Zheng 	(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
318*7a37052aSLv Zheng 
319*7a37052aSLv Zheng unlock_and_exit:
320*7a37052aSLv Zheng 
321*7a37052aSLv Zheng 	/* Release the table lock */
322*7a37052aSLv Zheng 
323*7a37052aSLv Zheng 	(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
324bdbe5df0SLv Zheng 
32586dfc6f3SLv Zheng release_and_exit:
32695b482a8SLen Brown 
327ed6f1d44SBob Moore 	/* Release the temporary table descriptor */
32886dfc6f3SLv Zheng 
329ed6f1d44SBob Moore 	acpi_tb_release_temp_table(&new_table_desc);
33095b482a8SLen Brown 	return_ACPI_STATUS(status);
33195b482a8SLen Brown }
33295b482a8SLen Brown 
33395b482a8SLen Brown /*******************************************************************************
33495b482a8SLen Brown  *
3357f9fc99cSLv Zheng  * FUNCTION:    acpi_tb_override_table
336f7b004a1SBob Moore  *
33786dfc6f3SLv Zheng  * PARAMETERS:  old_table_desc      - Validated table descriptor to be
33886dfc6f3SLv Zheng  *                                    overridden
339f7b004a1SBob Moore  *
34086dfc6f3SLv Zheng  * RETURN:      None
341f7b004a1SBob Moore  *
342f7b004a1SBob Moore  * DESCRIPTION: Attempt table override by calling the OSL override functions.
343f7b004a1SBob Moore  *              Note: If the table is overridden, then the entire new table
3447f9fc99cSLv Zheng  *              is acquired and returned by this function.
34586dfc6f3SLv Zheng  *              Before/after invocation, the table descriptor is in a state
34686dfc6f3SLv Zheng  *              that is "VALIDATED".
347f7b004a1SBob Moore  *
348f7b004a1SBob Moore  ******************************************************************************/
349f7b004a1SBob Moore 
35086dfc6f3SLv Zheng void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
351f7b004a1SBob Moore {
352f7b004a1SBob Moore 	acpi_status status;
353f7b004a1SBob Moore 	char *override_type;
3547f9fc99cSLv Zheng 	struct acpi_table_desc new_table_desc;
35586dfc6f3SLv Zheng 	struct acpi_table_header *table;
35686dfc6f3SLv Zheng 	acpi_physical_address address;
35786dfc6f3SLv Zheng 	u32 length;
358f7b004a1SBob Moore 
359f7b004a1SBob Moore 	/* (1) Attempt logical override (returns a logical address) */
360f7b004a1SBob Moore 
36186dfc6f3SLv Zheng 	status = acpi_os_table_override(old_table_desc->pointer, &table);
36286dfc6f3SLv Zheng 	if (ACPI_SUCCESS(status) && table) {
363ed6f1d44SBob Moore 		acpi_tb_acquire_temp_table(&new_table_desc,
36486dfc6f3SLv Zheng 					   ACPI_PTR_TO_PHYSADDR(table),
365ed6f1d44SBob Moore 					   ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
366f7b004a1SBob Moore 		override_type = "Logical";
367f7b004a1SBob Moore 		goto finish_override;
368f7b004a1SBob Moore 	}
369f7b004a1SBob Moore 
370f7b004a1SBob Moore 	/* (2) Attempt physical override (returns a physical address) */
371f7b004a1SBob Moore 
37286dfc6f3SLv Zheng 	status = acpi_os_physical_table_override(old_table_desc->pointer,
37386dfc6f3SLv Zheng 						 &address, &length);
37486dfc6f3SLv Zheng 	if (ACPI_SUCCESS(status) && address && length) {
375ed6f1d44SBob Moore 		acpi_tb_acquire_temp_table(&new_table_desc, address,
376ed6f1d44SBob Moore 					   ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
377f7b004a1SBob Moore 		override_type = "Physical";
378f7b004a1SBob Moore 		goto finish_override;
379f7b004a1SBob Moore 	}
380f7b004a1SBob Moore 
38186dfc6f3SLv Zheng 	return;			/* There was no override */
382f7b004a1SBob Moore 
383f7b004a1SBob Moore finish_override:
384f7b004a1SBob Moore 
38586dfc6f3SLv Zheng 	/* Validate and verify a table before overriding */
38686dfc6f3SLv Zheng 
38747d68c7fSLv Zheng 	status = acpi_tb_verify_temp_table(&new_table_desc, NULL);
3887f9fc99cSLv Zheng 	if (ACPI_FAILURE(status)) {
38986dfc6f3SLv Zheng 		return;
3907f9fc99cSLv Zheng 	}
3917f9fc99cSLv Zheng 
39205fb04b5SBob Moore 	ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
3931d0a0b2fSLv Zheng 		   " %s table override, new table: 0x%8.8X%8.8X",
39486dfc6f3SLv Zheng 		   old_table_desc->signature.ascii,
3951d0a0b2fSLv Zheng 		   ACPI_FORMAT_UINT64(old_table_desc->address),
3961d0a0b2fSLv Zheng 		   override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
397f7b004a1SBob Moore 
39886dfc6f3SLv Zheng 	/* We can now uninstall the original table */
399f7b004a1SBob Moore 
40086dfc6f3SLv Zheng 	acpi_tb_uninstall_table(old_table_desc);
401f7b004a1SBob Moore 
40286dfc6f3SLv Zheng 	/*
40386dfc6f3SLv Zheng 	 * Replace the original table descriptor and keep its state as
40486dfc6f3SLv Zheng 	 * "VALIDATED".
40586dfc6f3SLv Zheng 	 */
406ed6f1d44SBob Moore 	acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
407ed6f1d44SBob Moore 				      new_table_desc.flags,
408ed6f1d44SBob Moore 				      new_table_desc.pointer);
40947d68c7fSLv Zheng 	acpi_tb_validate_temp_table(old_table_desc);
410f7b004a1SBob Moore 
411ed6f1d44SBob Moore 	/* Release the temporary table descriptor */
412f7b004a1SBob Moore 
413ed6f1d44SBob Moore 	acpi_tb_release_temp_table(&new_table_desc);
414f7b004a1SBob Moore }
415f7b004a1SBob Moore 
416f7b004a1SBob Moore /*******************************************************************************
417f7b004a1SBob Moore  *
4187f9fc99cSLv Zheng  * FUNCTION:    acpi_tb_uninstall_table
41995b482a8SLen Brown  *
4207f9fc99cSLv Zheng  * PARAMETERS:  table_desc          - Table descriptor
42195b482a8SLen Brown  *
42295b482a8SLen Brown  * RETURN:      None
42395b482a8SLen Brown  *
42495b482a8SLen Brown  * DESCRIPTION: Delete one internal ACPI table
42595b482a8SLen Brown  *
42695b482a8SLen Brown  ******************************************************************************/
42795b482a8SLen Brown 
4287f9fc99cSLv Zheng void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
42995b482a8SLen Brown {
4305582982dSLv Zheng 
4317f9fc99cSLv Zheng 	ACPI_FUNCTION_TRACE(tb_uninstall_table);
4325582982dSLv Zheng 
4337f9fc99cSLv Zheng 	/* Table must be installed */
4347f9fc99cSLv Zheng 
4357f9fc99cSLv Zheng 	if (!table_desc->address) {
4367f9fc99cSLv Zheng 		return_VOID;
43795b482a8SLen Brown 	}
4385582982dSLv Zheng 
4397f9fc99cSLv Zheng 	acpi_tb_invalidate_table(table_desc);
4401d1ea1b7SChao Guan 
4417f9fc99cSLv Zheng 	if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
442ed6f1d44SBob Moore 	    ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
4436d3fd3ccSLv Zheng 		ACPI_FREE(ACPI_PHYSADDR_TO_PTR(table_desc->address));
4447f9fc99cSLv Zheng 	}
4451d1ea1b7SChao Guan 
446dc156adfSLv Zheng 	table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
4477f9fc99cSLv Zheng 	return_VOID;
44895b482a8SLen Brown }
449