195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
295b482a8SLen Brown /******************************************************************************
395b482a8SLen Brown *
495b482a8SLen Brown * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
595b482a8SLen Brown *
6*612c2932SBob Moore * Copyright (C) 2000 - 2023, Intel Corp.
795b482a8SLen Brown *
895857638SErik Schmauss *****************************************************************************/
995b482a8SLen Brown
1095b482a8SLen Brown #include <acpi/acpi.h>
11e2f7a777SLen Brown #include "accommon.h"
12e2f7a777SLen Brown #include "acinterp.h"
13e2f7a777SLen Brown #include "acnamesp.h"
14e2f7a777SLen Brown #include "actables.h"
15e2f7a777SLen Brown #include "acdispat.h"
163c59f960SBob Moore #include "acevents.h"
17528a412cSBob Moore #include "amlcode.h"
1895b482a8SLen Brown
1995b482a8SLen Brown #define _COMPONENT ACPI_EXECUTER
2095b482a8SLen Brown ACPI_MODULE_NAME("exconfig")
2195b482a8SLen Brown
2295b482a8SLen Brown /* Local prototypes */
2395b482a8SLen Brown static acpi_status
24ac0f06ebSLv Zheng acpi_ex_add_table(u32 table_index, union acpi_operand_object **ddb_handle);
2595b482a8SLen Brown
263c59f960SBob Moore static acpi_status
273c59f960SBob Moore acpi_ex_region_read(union acpi_operand_object *obj_desc,
283c59f960SBob Moore u32 length, u8 *buffer);
293c59f960SBob Moore
3095b482a8SLen Brown /*******************************************************************************
3195b482a8SLen Brown *
3295b482a8SLen Brown * FUNCTION: acpi_ex_add_table
3395b482a8SLen Brown *
34ba494beeSBob Moore * PARAMETERS: table - Pointer to raw table
3595b482a8SLen Brown * parent_node - Where to load the table (scope)
3695b482a8SLen Brown * ddb_handle - Where to return the table handle.
3795b482a8SLen Brown *
3895b482a8SLen Brown * RETURN: Status
3995b482a8SLen Brown *
4095b482a8SLen Brown * DESCRIPTION: Common function to Install and Load an ACPI table with a
4195b482a8SLen Brown * returned table handle.
4295b482a8SLen Brown *
4395b482a8SLen Brown ******************************************************************************/
4495b482a8SLen Brown
4595b482a8SLen Brown static acpi_status
acpi_ex_add_table(u32 table_index,union acpi_operand_object ** ddb_handle)46ac0f06ebSLv Zheng acpi_ex_add_table(u32 table_index, union acpi_operand_object **ddb_handle)
4795b482a8SLen Brown {
4895b482a8SLen Brown union acpi_operand_object *obj_desc;
4995b482a8SLen Brown
5095b482a8SLen Brown ACPI_FUNCTION_TRACE(ex_add_table);
5195b482a8SLen Brown
5295b482a8SLen Brown /* Create an object to be the table handle */
5395b482a8SLen Brown
5495b482a8SLen Brown obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
5595b482a8SLen Brown if (!obj_desc) {
5695b482a8SLen Brown return_ACPI_STATUS(AE_NO_MEMORY);
5795b482a8SLen Brown }
5895b482a8SLen Brown
5995b482a8SLen Brown /* Init the table handle */
6095b482a8SLen Brown
61e0be6f5aSLin Ming obj_desc->common.flags |= AOPOBJ_DATA_VALID;
6295b482a8SLen Brown obj_desc->reference.class = ACPI_REFCLASS_TABLE;
6395b482a8SLen Brown obj_desc->reference.value = table_index;
64ac0f06ebSLv Zheng *ddb_handle = obj_desc;
65186c307fSBob Moore return_ACPI_STATUS(AE_OK);
6695b482a8SLen Brown }
6795b482a8SLen Brown
6895b482a8SLen Brown /*******************************************************************************
6995b482a8SLen Brown *
7095b482a8SLen Brown * FUNCTION: acpi_ex_load_table_op
7195b482a8SLen Brown *
7295b482a8SLen Brown * PARAMETERS: walk_state - Current state with operands
7395b482a8SLen Brown * return_desc - Where to store the return object
7495b482a8SLen Brown *
7595b482a8SLen Brown * RETURN: Status
7695b482a8SLen Brown *
7795b482a8SLen Brown * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
7895b482a8SLen Brown *
7995b482a8SLen Brown ******************************************************************************/
8095b482a8SLen Brown
8195b482a8SLen Brown acpi_status
acpi_ex_load_table_op(struct acpi_walk_state * walk_state,union acpi_operand_object ** return_desc)8295b482a8SLen Brown acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
8395b482a8SLen Brown union acpi_operand_object **return_desc)
8495b482a8SLen Brown {
8595b482a8SLen Brown acpi_status status;
8695b482a8SLen Brown union acpi_operand_object **operand = &walk_state->operands[0];
8795b482a8SLen Brown struct acpi_namespace_node *parent_node;
8895b482a8SLen Brown struct acpi_namespace_node *start_node;
8995b482a8SLen Brown struct acpi_namespace_node *parameter_node = NULL;
90e468e39fSBob Moore union acpi_operand_object *return_obj;
9195b482a8SLen Brown union acpi_operand_object *ddb_handle;
9295b482a8SLen Brown u32 table_index;
9395b482a8SLen Brown
9495b482a8SLen Brown ACPI_FUNCTION_TRACE(ex_load_table_op);
9595b482a8SLen Brown
96e468e39fSBob Moore /* Create the return object */
97e468e39fSBob Moore
98e468e39fSBob Moore return_obj = acpi_ut_create_integer_object((u64)0);
99e468e39fSBob Moore if (!return_obj) {
100e468e39fSBob Moore return_ACPI_STATUS(AE_NO_MEMORY);
101e468e39fSBob Moore }
102e468e39fSBob Moore
103e468e39fSBob Moore *return_desc = return_obj;
104e468e39fSBob Moore
10595b482a8SLen Brown /* Find the ACPI table in the RSDT/XSDT */
10695b482a8SLen Brown
107ac0f06ebSLv Zheng acpi_ex_exit_interpreter();
10895b482a8SLen Brown status = acpi_tb_find_table(operand[0]->string.pointer,
10995b482a8SLen Brown operand[1]->string.pointer,
11095b482a8SLen Brown operand[2]->string.pointer, &table_index);
111ac0f06ebSLv Zheng acpi_ex_enter_interpreter();
11295b482a8SLen Brown if (ACPI_FAILURE(status)) {
11395b482a8SLen Brown if (status != AE_NOT_FOUND) {
11495b482a8SLen Brown return_ACPI_STATUS(status);
11595b482a8SLen Brown }
11695b482a8SLen Brown
11795b482a8SLen Brown /* Table not found, return an Integer=0 and AE_OK */
11895b482a8SLen Brown
11995b482a8SLen Brown return_ACPI_STATUS(AE_OK);
12095b482a8SLen Brown }
12195b482a8SLen Brown
12295b482a8SLen Brown /* Default nodes */
12395b482a8SLen Brown
12495b482a8SLen Brown start_node = walk_state->scope_info->scope.node;
12595b482a8SLen Brown parent_node = acpi_gbl_root_node;
12695b482a8SLen Brown
12795b482a8SLen Brown /* root_path (optional parameter) */
12895b482a8SLen Brown
12995b482a8SLen Brown if (operand[3]->string.length > 0) {
13095b482a8SLen Brown /*
13195b482a8SLen Brown * Find the node referenced by the root_path_string. This is the
13295b482a8SLen Brown * location within the namespace where the table will be loaded.
13395b482a8SLen Brown */
13474f51b80SLv Zheng status = acpi_ns_get_node_unlocked(start_node,
13574f51b80SLv Zheng operand[3]->string.pointer,
13674f51b80SLv Zheng ACPI_NS_SEARCH_PARENT,
13774f51b80SLv Zheng &parent_node);
13895b482a8SLen Brown if (ACPI_FAILURE(status)) {
13995b482a8SLen Brown return_ACPI_STATUS(status);
14095b482a8SLen Brown }
14195b482a8SLen Brown }
14295b482a8SLen Brown
14395b482a8SLen Brown /* parameter_path (optional parameter) */
14495b482a8SLen Brown
14595b482a8SLen Brown if (operand[4]->string.length > 0) {
146528a412cSBob Moore if ((operand[4]->string.pointer[0] != AML_ROOT_PREFIX) &&
147528a412cSBob Moore (operand[4]->string.pointer[0] != AML_PARENT_PREFIX)) {
14895b482a8SLen Brown /*
14995b482a8SLen Brown * Path is not absolute, so it will be relative to the node
15095b482a8SLen Brown * referenced by the root_path_string (or the NS root if omitted)
15195b482a8SLen Brown */
15295b482a8SLen Brown start_node = parent_node;
15395b482a8SLen Brown }
15495b482a8SLen Brown
15595b482a8SLen Brown /* Find the node referenced by the parameter_path_string */
15695b482a8SLen Brown
15774f51b80SLv Zheng status = acpi_ns_get_node_unlocked(start_node,
15874f51b80SLv Zheng operand[4]->string.pointer,
15974f51b80SLv Zheng ACPI_NS_SEARCH_PARENT,
16074f51b80SLv Zheng ¶meter_node);
16195b482a8SLen Brown if (ACPI_FAILURE(status)) {
16295b482a8SLen Brown return_ACPI_STATUS(status);
16395b482a8SLen Brown }
16495b482a8SLen Brown }
16595b482a8SLen Brown
16695b482a8SLen Brown /* Load the table into the namespace */
16795b482a8SLen Brown
168ac0f06ebSLv Zheng ACPI_INFO(("Dynamic OEM Table Load:"));
169ac0f06ebSLv Zheng acpi_ex_exit_interpreter();
170ac0f06ebSLv Zheng status = acpi_tb_load_table(table_index, parent_node);
171ac0f06ebSLv Zheng acpi_ex_enter_interpreter();
172ac0f06ebSLv Zheng if (ACPI_FAILURE(status)) {
173ac0f06ebSLv Zheng return_ACPI_STATUS(status);
174ac0f06ebSLv Zheng }
175ac0f06ebSLv Zheng
176ac0f06ebSLv Zheng status = acpi_ex_add_table(table_index, &ddb_handle);
17795b482a8SLen Brown if (ACPI_FAILURE(status)) {
17895b482a8SLen Brown return_ACPI_STATUS(status);
17995b482a8SLen Brown }
18095b482a8SLen Brown
181d1fb5b2fSErik Schmauss /* Complete the initialization/resolution of new objects */
1827b34c0fbSBob Moore
183d1fb5b2fSErik Schmauss acpi_ex_exit_interpreter();
184d1fb5b2fSErik Schmauss acpi_ns_initialize_objects();
185d1fb5b2fSErik Schmauss acpi_ex_enter_interpreter();
1867b34c0fbSBob Moore
18795b482a8SLen Brown /* Parameter Data (optional) */
18895b482a8SLen Brown
18995b482a8SLen Brown if (parameter_node) {
19095b482a8SLen Brown
19195b482a8SLen Brown /* Store the parameter data into the optional parameter object */
19295b482a8SLen Brown
19395b482a8SLen Brown status = acpi_ex_store(operand[5],
19495b482a8SLen Brown ACPI_CAST_PTR(union acpi_operand_object,
19595b482a8SLen Brown parameter_node),
19695b482a8SLen Brown walk_state);
19795b482a8SLen Brown if (ACPI_FAILURE(status)) {
19895b482a8SLen Brown (void)acpi_ex_unload_table(ddb_handle);
19906366c14SLin Ming
20006366c14SLin Ming acpi_ut_remove_reference(ddb_handle);
20195b482a8SLen Brown return_ACPI_STATUS(status);
20295b482a8SLen Brown }
20395b482a8SLen Brown }
20495b482a8SLen Brown
205e468e39fSBob Moore /* Remove the reference to ddb_handle created by acpi_ex_add_table above */
206e468e39fSBob Moore
207e468e39fSBob Moore acpi_ut_remove_reference(ddb_handle);
208e468e39fSBob Moore
209e468e39fSBob Moore /* Return -1 (non-zero) indicates success */
210e468e39fSBob Moore
211e468e39fSBob Moore return_obj->integer.value = 0xFFFFFFFFFFFFFFFF;
21295b482a8SLen Brown return_ACPI_STATUS(status);
21395b482a8SLen Brown }
21495b482a8SLen Brown
21595b482a8SLen Brown /*******************************************************************************
21695b482a8SLen Brown *
2173c59f960SBob Moore * FUNCTION: acpi_ex_region_read
2183c59f960SBob Moore *
2193c59f960SBob Moore * PARAMETERS: obj_desc - Region descriptor
220ba494beeSBob Moore * length - Number of bytes to read
221ba494beeSBob Moore * buffer - Pointer to where to put the data
2223c59f960SBob Moore *
2233c59f960SBob Moore * RETURN: Status
2243c59f960SBob Moore *
2253c59f960SBob Moore * DESCRIPTION: Read data from an operation region. The read starts from the
2263c59f960SBob Moore * beginning of the region.
2273c59f960SBob Moore *
2283c59f960SBob Moore ******************************************************************************/
2293c59f960SBob Moore
2303c59f960SBob Moore static acpi_status
acpi_ex_region_read(union acpi_operand_object * obj_desc,u32 length,u8 * buffer)2313c59f960SBob Moore acpi_ex_region_read(union acpi_operand_object *obj_desc, u32 length, u8 *buffer)
2323c59f960SBob Moore {
2333c59f960SBob Moore acpi_status status;
2345df7e6cbSBob Moore u64 value;
235f5407af3SBob Moore u32 region_offset = 0;
2363c59f960SBob Moore u32 i;
2373c59f960SBob Moore
2383c59f960SBob Moore /* Bytewise reads */
2393c59f960SBob Moore
2403c59f960SBob Moore for (i = 0; i < length; i++) {
2419ce81784SBob Moore status =
2429ce81784SBob Moore acpi_ev_address_space_dispatch(obj_desc, NULL, ACPI_READ,
2439ce81784SBob Moore region_offset, 8, &value);
2443c59f960SBob Moore if (ACPI_FAILURE(status)) {
2459c0d7939SLv Zheng return (status);
2463c59f960SBob Moore }
2473c59f960SBob Moore
2483c59f960SBob Moore *buffer = (u8)value;
2493c59f960SBob Moore buffer++;
250f5407af3SBob Moore region_offset++;
2513c59f960SBob Moore }
2523c59f960SBob Moore
2539c0d7939SLv Zheng return (AE_OK);
2543c59f960SBob Moore }
2553c59f960SBob Moore
2563c59f960SBob Moore /*******************************************************************************
2573c59f960SBob Moore *
25895b482a8SLen Brown * FUNCTION: acpi_ex_load_op
25995b482a8SLen Brown *
26095b482a8SLen Brown * PARAMETERS: obj_desc - Region or Buffer/Field where the table will be
26195b482a8SLen Brown * obtained
26239ea1bbfSBob Moore * target - Where the status of the load will be stored
26395b482a8SLen Brown * walk_state - Current state
26495b482a8SLen Brown *
26595b482a8SLen Brown * RETURN: Status
26695b482a8SLen Brown *
26795b482a8SLen Brown * DESCRIPTION: Load an ACPI table from a field or operation region
26895b482a8SLen Brown *
26995b482a8SLen Brown * NOTE: Region Fields (Field, bank_field, index_fields) are resolved to buffer
27095b482a8SLen Brown * objects before this code is reached.
27195b482a8SLen Brown *
27295b482a8SLen Brown * If source is an operation region, it must refer to system_memory, as
27395b482a8SLen Brown * per the ACPI specification.
27495b482a8SLen Brown *
27595b482a8SLen Brown ******************************************************************************/
27695b482a8SLen Brown
27795b482a8SLen Brown acpi_status
acpi_ex_load_op(union acpi_operand_object * obj_desc,union acpi_operand_object * target,struct acpi_walk_state * walk_state)27895b482a8SLen Brown acpi_ex_load_op(union acpi_operand_object *obj_desc,
27995b482a8SLen Brown union acpi_operand_object *target,
28095b482a8SLen Brown struct acpi_walk_state *walk_state)
28195b482a8SLen Brown {
28295b482a8SLen Brown union acpi_operand_object *ddb_handle;
28386dfc6f3SLv Zheng struct acpi_table_header *table_header;
28495b482a8SLen Brown struct acpi_table_header *table;
28595b482a8SLen Brown u32 table_index;
28695b482a8SLen Brown acpi_status status;
28795b482a8SLen Brown u32 length;
28895b482a8SLen Brown
28995b482a8SLen Brown ACPI_FUNCTION_TRACE(ex_load_op);
29095b482a8SLen Brown
29139ea1bbfSBob Moore if (target->common.descriptor_type == ACPI_DESC_TYPE_NAMED) {
29239ea1bbfSBob Moore target =
29339ea1bbfSBob Moore acpi_ns_get_attached_object(ACPI_CAST_PTR
29439ea1bbfSBob Moore (struct acpi_namespace_node,
29539ea1bbfSBob Moore target));
29639ea1bbfSBob Moore }
29739ea1bbfSBob Moore if (target->common.type != ACPI_TYPE_INTEGER) {
2985620fe64SRafael J. Wysocki ACPI_ERROR((AE_INFO, "Type not integer: %X",
2995620fe64SRafael J. Wysocki target->common.type));
30039ea1bbfSBob Moore return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
30139ea1bbfSBob Moore }
30239ea1bbfSBob Moore
30339ea1bbfSBob Moore target->integer.value = 0;
30439ea1bbfSBob Moore
30595b482a8SLen Brown /* Source Object can be either an op_region or a Buffer/Field */
30695b482a8SLen Brown
3073371c19cSBob Moore switch (obj_desc->common.type) {
30895b482a8SLen Brown case ACPI_TYPE_REGION:
30995b482a8SLen Brown
31095b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
31195b482a8SLen Brown "Load table from Region %p\n", obj_desc));
31295b482a8SLen Brown
31395b482a8SLen Brown /* Region must be system_memory (from ACPI spec) */
31495b482a8SLen Brown
31595b482a8SLen Brown if (obj_desc->region.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
31695b482a8SLen Brown return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
31795b482a8SLen Brown }
31895b482a8SLen Brown
31995b482a8SLen Brown /*
3201fad8738SBob Moore * If the Region Address and Length have not been previously
3211fad8738SBob Moore * evaluated, evaluate them now and save the results.
32295b482a8SLen Brown */
32395b482a8SLen Brown if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
32495b482a8SLen Brown status = acpi_ds_get_region_arguments(obj_desc);
32595b482a8SLen Brown if (ACPI_FAILURE(status)) {
32695b482a8SLen Brown return_ACPI_STATUS(status);
32795b482a8SLen Brown }
32895b482a8SLen Brown }
32995b482a8SLen Brown
3303c59f960SBob Moore /* Get the table header first so we can get the table length */
3313c59f960SBob Moore
33286dfc6f3SLv Zheng table_header = ACPI_ALLOCATE(sizeof(struct acpi_table_header));
33386dfc6f3SLv Zheng if (!table_header) {
33495b482a8SLen Brown return_ACPI_STATUS(AE_NO_MEMORY);
33595b482a8SLen Brown }
33695b482a8SLen Brown
3373c59f960SBob Moore status =
3383c59f960SBob Moore acpi_ex_region_read(obj_desc,
3393c59f960SBob Moore sizeof(struct acpi_table_header),
34086dfc6f3SLv Zheng ACPI_CAST_PTR(u8, table_header));
34186dfc6f3SLv Zheng length = table_header->length;
34286dfc6f3SLv Zheng ACPI_FREE(table_header);
3433c59f960SBob Moore
3443c59f960SBob Moore if (ACPI_FAILURE(status)) {
3453c59f960SBob Moore return_ACPI_STATUS(status);
3463c59f960SBob Moore }
34795b482a8SLen Brown
34895b482a8SLen Brown /* Must have at least an ACPI table header */
34995b482a8SLen Brown
35095b482a8SLen Brown if (length < sizeof(struct acpi_table_header)) {
35195b482a8SLen Brown return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
35295b482a8SLen Brown }
35395b482a8SLen Brown
35495b482a8SLen Brown /*
3553c59f960SBob Moore * The original implementation simply mapped the table, with no copy.
3563c59f960SBob Moore * However, the memory region is not guaranteed to remain stable and
3573c59f960SBob Moore * we must copy the table to a local buffer. For example, the memory
3583c59f960SBob Moore * region is corrupted after suspend on some machines. Dynamically
3593c59f960SBob Moore * loaded tables are usually small, so this overhead is minimal.
3603c59f960SBob Moore *
3613c59f960SBob Moore * The latest implementation (5/2009) does not use a mapping at all.
3623c59f960SBob Moore * We use the low-level operation region interface to read the table
3633c59f960SBob Moore * instead of the obvious optimization of using a direct mapping.
3643c59f960SBob Moore * This maintains a consistent use of operation regions across the
3653c59f960SBob Moore * entire subsystem. This is important if additional processing must
3663c59f960SBob Moore * be performed in the (possibly user-installed) operation region
3673c59f960SBob Moore * handler. For example, acpi_exec and ASLTS depend on this.
36895b482a8SLen Brown */
36995b482a8SLen Brown
37095b482a8SLen Brown /* Allocate a buffer for the table */
37195b482a8SLen Brown
37286dfc6f3SLv Zheng table = ACPI_ALLOCATE(length);
37386dfc6f3SLv Zheng if (!table) {
37495b482a8SLen Brown return_ACPI_STATUS(AE_NO_MEMORY);
37595b482a8SLen Brown }
37695b482a8SLen Brown
3773c59f960SBob Moore /* Read the entire table */
37895b482a8SLen Brown
3793c59f960SBob Moore status = acpi_ex_region_read(obj_desc, length,
38086dfc6f3SLv Zheng ACPI_CAST_PTR(u8, table));
3813c59f960SBob Moore if (ACPI_FAILURE(status)) {
38286dfc6f3SLv Zheng ACPI_FREE(table);
3833c59f960SBob Moore return_ACPI_STATUS(status);
38495b482a8SLen Brown }
38595b482a8SLen Brown break;
38695b482a8SLen Brown
38795b482a8SLen Brown case ACPI_TYPE_BUFFER: /* Buffer or resolved region_field */
38895b482a8SLen Brown
38995b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
39095b482a8SLen Brown "Load table from Buffer or Field %p\n",
39195b482a8SLen Brown obj_desc));
39295b482a8SLen Brown
39395b482a8SLen Brown /* Must have at least an ACPI table header */
39495b482a8SLen Brown
39595b482a8SLen Brown if (obj_desc->buffer.length < sizeof(struct acpi_table_header)) {
39695b482a8SLen Brown return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
39795b482a8SLen Brown }
39895b482a8SLen Brown
39995b482a8SLen Brown /* Get the actual table length from the table header */
40095b482a8SLen Brown
40186dfc6f3SLv Zheng table_header =
40295b482a8SLen Brown ACPI_CAST_PTR(struct acpi_table_header,
40395b482a8SLen Brown obj_desc->buffer.pointer);
40486dfc6f3SLv Zheng length = table_header->length;
40595b482a8SLen Brown
40695b482a8SLen Brown /* Table cannot extend beyond the buffer */
40795b482a8SLen Brown
40895b482a8SLen Brown if (length > obj_desc->buffer.length) {
40995b482a8SLen Brown return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
41095b482a8SLen Brown }
41195b482a8SLen Brown if (length < sizeof(struct acpi_table_header)) {
41295b482a8SLen Brown return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
41395b482a8SLen Brown }
41495b482a8SLen Brown
41595b482a8SLen Brown /*
4161fad8738SBob Moore * Copy the table from the buffer because the buffer could be
4171fad8738SBob Moore * modified or even deleted in the future
41895b482a8SLen Brown */
41986dfc6f3SLv Zheng table = ACPI_ALLOCATE(length);
42086dfc6f3SLv Zheng if (!table) {
42195b482a8SLen Brown return_ACPI_STATUS(AE_NO_MEMORY);
42295b482a8SLen Brown }
42395b482a8SLen Brown
4244fa4616eSBob Moore memcpy(table, table_header, length);
42595b482a8SLen Brown break;
42695b482a8SLen Brown
42795b482a8SLen Brown default:
4281d1ea1b7SChao Guan
42995b482a8SLen Brown return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
43095b482a8SLen Brown }
43195b482a8SLen Brown
43295b482a8SLen Brown /* Install the new table into the local data structures */
43395b482a8SLen Brown
43405fb04b5SBob Moore ACPI_INFO(("Dynamic OEM Table Load:"));
435ac0f06ebSLv Zheng acpi_ex_exit_interpreter();
43642cc87a5SLv Zheng status = acpi_tb_install_and_load_table(ACPI_PTR_TO_PHYSADDR(table),
437ed6f1d44SBob Moore ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
4385d6e5966SJessica Clarke table, TRUE, &table_index);
439ac0f06ebSLv Zheng acpi_ex_enter_interpreter();
44095b482a8SLen Brown if (ACPI_FAILURE(status)) {
4412147d3f0SBob Moore
4422147d3f0SBob Moore /* Delete allocated table buffer */
4432147d3f0SBob Moore
44486dfc6f3SLv Zheng ACPI_FREE(table);
44586dfc6f3SLv Zheng return_ACPI_STATUS(status);
44686dfc6f3SLv Zheng }
44786dfc6f3SLv Zheng
44886dfc6f3SLv Zheng /*
44995b482a8SLen Brown * Add the table to the namespace.
45095b482a8SLen Brown *
45195b482a8SLen Brown * Note: Load the table objects relative to the root of the namespace.
45295b482a8SLen Brown * This appears to go against the ACPI specification, but we do it for
45395b482a8SLen Brown * compatibility with other ACPI implementations.
45495b482a8SLen Brown */
455ac0f06ebSLv Zheng status = acpi_ex_add_table(table_index, &ddb_handle);
45695b482a8SLen Brown if (ACPI_FAILURE(status)) {
45795b482a8SLen Brown return_ACPI_STATUS(status);
45895b482a8SLen Brown }
45995b482a8SLen Brown
460d1fb5b2fSErik Schmauss /* Complete the initialization/resolution of new objects */
4617b34c0fbSBob Moore
462d1fb5b2fSErik Schmauss acpi_ex_exit_interpreter();
463d1fb5b2fSErik Schmauss acpi_ns_initialize_objects();
464d1fb5b2fSErik Schmauss acpi_ex_enter_interpreter();
4657b34c0fbSBob Moore
46639ea1bbfSBob Moore /* Remove the reference to ddb_handle created by acpi_ex_add_table above */
46795b482a8SLen Brown
46895b482a8SLen Brown acpi_ut_remove_reference(ddb_handle);
46995b482a8SLen Brown
47039ea1bbfSBob Moore /* Return -1 (non-zero) indicates success */
47106366c14SLin Ming
47239ea1bbfSBob Moore target->integer.value = 0xFFFFFFFFFFFFFFFF;
47395b482a8SLen Brown return_ACPI_STATUS(status);
47495b482a8SLen Brown }
47595b482a8SLen Brown
47695b482a8SLen Brown /*******************************************************************************
47795b482a8SLen Brown *
47895b482a8SLen Brown * FUNCTION: acpi_ex_unload_table
47995b482a8SLen Brown *
48095b482a8SLen Brown * PARAMETERS: ddb_handle - Handle to a previously loaded table
48195b482a8SLen Brown *
48295b482a8SLen Brown * RETURN: Status
48395b482a8SLen Brown *
48495b482a8SLen Brown * DESCRIPTION: Unload an ACPI table
48595b482a8SLen Brown *
48695b482a8SLen Brown ******************************************************************************/
48795b482a8SLen Brown
acpi_ex_unload_table(union acpi_operand_object * ddb_handle)48895b482a8SLen Brown acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
48995b482a8SLen Brown {
49095b482a8SLen Brown acpi_status status = AE_OK;
49195b482a8SLen Brown union acpi_operand_object *table_desc = ddb_handle;
49295b482a8SLen Brown u32 table_index;
49395b482a8SLen Brown
49495b482a8SLen Brown ACPI_FUNCTION_TRACE(ex_unload_table);
49595b482a8SLen Brown
49695b482a8SLen Brown /*
49743d1a62dSBob Moore * Temporarily emit a warning so that the ASL for the machine can be
49843d1a62dSBob Moore * hopefully obtained. This is to say that the Unload() operator is
49943d1a62dSBob Moore * extremely rare if not completely unused.
50043d1a62dSBob Moore */
50143d1a62dSBob Moore ACPI_WARNING((AE_INFO, "Received request to unload an ACPI table"));
50243d1a62dSBob Moore
50343d1a62dSBob Moore /*
5047aa8a236SBob Moore * May 2018: Unload is no longer supported for the following reasons:
5057aa8a236SBob Moore * 1) A correct implementation on some hosts may not be possible.
5067aa8a236SBob Moore * 2) Other ACPI implementations do not correctly/fully support it.
5077aa8a236SBob Moore * 3) It requires host device driver support which does not exist.
5087aa8a236SBob Moore * (To properly support namespace unload out from underneath.)
5097aa8a236SBob Moore * 4) This AML operator has never been seen in the field.
5107aa8a236SBob Moore */
5117aa8a236SBob Moore ACPI_EXCEPTION((AE_INFO, AE_NOT_IMPLEMENTED,
5127aa8a236SBob Moore "AML Unload operator is not supported"));
5137aa8a236SBob Moore
5147aa8a236SBob Moore /*
51595b482a8SLen Brown * Validate the handle
516e0be6f5aSLin Ming * Although the handle is partially validated in acpi_ex_reconfiguration()
51795b482a8SLen Brown * when it calls acpi_ex_resolve_operands(), the handle is more completely
51895b482a8SLen Brown * validated here.
519e0be6f5aSLin Ming *
520e0be6f5aSLin Ming * Handle must be a valid operand object of type reference. Also, the
521e0be6f5aSLin Ming * ddb_handle must still be marked valid (table has not been previously
522e0be6f5aSLin Ming * unloaded)
52395b482a8SLen Brown */
52495b482a8SLen Brown if ((!ddb_handle) ||
52595b482a8SLen Brown (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
526e0be6f5aSLin Ming (ddb_handle->common.type != ACPI_TYPE_LOCAL_REFERENCE) ||
527e0be6f5aSLin Ming (!(ddb_handle->common.flags & AOPOBJ_DATA_VALID))) {
528f6f57f60SBob Moore return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
52995b482a8SLen Brown }
53095b482a8SLen Brown
53195b482a8SLen Brown /* Get the table index from the ddb_handle */
53295b482a8SLen Brown
53395b482a8SLen Brown table_index = table_desc->reference.value;
53495b482a8SLen Brown
5359febcdc0SLv Zheng /*
5369febcdc0SLv Zheng * Release the interpreter lock so that the table lock won't have
5379febcdc0SLv Zheng * strict order requirement against it.
5389febcdc0SLv Zheng */
5399febcdc0SLv Zheng acpi_ex_exit_interpreter();
540170564d9SLv Zheng status = acpi_tb_unload_table(table_index);
5419febcdc0SLv Zheng acpi_ex_enter_interpreter();
5429febcdc0SLv Zheng
543e0be6f5aSLin Ming /*
544e0be6f5aSLin Ming * Invalidate the handle. We do this because the handle may be stored
545e0be6f5aSLin Ming * in a named object and may not be actually deleted until much later.
546e0be6f5aSLin Ming */
5479febcdc0SLv Zheng if (ACPI_SUCCESS(status)) {
548e0be6f5aSLin Ming ddb_handle->common.flags &= ~AOPOBJ_DATA_VALID;
5499febcdc0SLv Zheng }
5509febcdc0SLv Zheng return_ACPI_STATUS(status);
55195b482a8SLen Brown }
552