195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
295b482a8SLen Brown /******************************************************************************
395b482a8SLen Brown *
495b482a8SLen Brown * Module Name: exstoren - AML Interpreter object store support,
595b482a8SLen Brown * Store to Node (namespace object)
695b482a8SLen Brown *
7*612c2932SBob Moore * Copyright (C) 2000 - 2023, Intel Corp.
895b482a8SLen Brown *
995857638SErik Schmauss *****************************************************************************/
1095b482a8SLen Brown
1195b482a8SLen Brown #include <acpi/acpi.h>
12e2f7a777SLen Brown #include "accommon.h"
13e2f7a777SLen Brown #include "acinterp.h"
14e2f7a777SLen Brown #include "amlcode.h"
1595b482a8SLen Brown
1695b482a8SLen Brown #define _COMPONENT ACPI_EXECUTER
1795b482a8SLen Brown ACPI_MODULE_NAME("exstoren")
1895b482a8SLen Brown
1995b482a8SLen Brown /*******************************************************************************
2095b482a8SLen Brown *
2195b482a8SLen Brown * FUNCTION: acpi_ex_resolve_object
2295b482a8SLen Brown *
2395b482a8SLen Brown * PARAMETERS: source_desc_ptr - Pointer to the source object
2495b482a8SLen Brown * target_type - Current type of the target
2595b482a8SLen Brown * walk_state - Current walk state
2695b482a8SLen Brown *
2795b482a8SLen Brown * RETURN: Status, resolved object in source_desc_ptr.
2895b482a8SLen Brown *
2995b482a8SLen Brown * DESCRIPTION: Resolve an object. If the object is a reference, dereference
3095b482a8SLen Brown * it and return the actual object in the source_desc_ptr.
3195b482a8SLen Brown *
3295b482a8SLen Brown ******************************************************************************/
3395b482a8SLen Brown acpi_status
acpi_ex_resolve_object(union acpi_operand_object ** source_desc_ptr,acpi_object_type target_type,struct acpi_walk_state * walk_state)3495b482a8SLen Brown acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
3595b482a8SLen Brown acpi_object_type target_type,
3695b482a8SLen Brown struct acpi_walk_state *walk_state)
3795b482a8SLen Brown {
3895b482a8SLen Brown union acpi_operand_object *source_desc = *source_desc_ptr;
3995b482a8SLen Brown acpi_status status = AE_OK;
4095b482a8SLen Brown
4195b482a8SLen Brown ACPI_FUNCTION_TRACE(ex_resolve_object);
4295b482a8SLen Brown
4395b482a8SLen Brown /* Ensure we have a Target that can be stored to */
4495b482a8SLen Brown
4595b482a8SLen Brown switch (target_type) {
4695b482a8SLen Brown case ACPI_TYPE_BUFFER_FIELD:
4795b482a8SLen Brown case ACPI_TYPE_LOCAL_REGION_FIELD:
4895b482a8SLen Brown case ACPI_TYPE_LOCAL_BANK_FIELD:
4995b482a8SLen Brown case ACPI_TYPE_LOCAL_INDEX_FIELD:
5095b482a8SLen Brown /*
5195b482a8SLen Brown * These cases all require only Integers or values that
5295b482a8SLen Brown * can be converted to Integers (Strings or Buffers)
5395b482a8SLen Brown */
5495b482a8SLen Brown case ACPI_TYPE_INTEGER:
5595b482a8SLen Brown case ACPI_TYPE_STRING:
5695b482a8SLen Brown case ACPI_TYPE_BUFFER:
5795b482a8SLen Brown /*
5895b482a8SLen Brown * Stores into a Field/Region or into a Integer/Buffer/String
5995b482a8SLen Brown * are all essentially the same. This case handles the
6095b482a8SLen Brown * "interchangeable" types Integer, String, and Buffer.
6195b482a8SLen Brown */
623371c19cSBob Moore if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
6395b482a8SLen Brown
6495b482a8SLen Brown /* Resolve a reference object first */
6595b482a8SLen Brown
6695b482a8SLen Brown status =
6795b482a8SLen Brown acpi_ex_resolve_to_value(source_desc_ptr,
6895b482a8SLen Brown walk_state);
6995b482a8SLen Brown if (ACPI_FAILURE(status)) {
7095b482a8SLen Brown break;
7195b482a8SLen Brown }
7295b482a8SLen Brown }
7395b482a8SLen Brown
7495b482a8SLen Brown /* For copy_object, no further validation necessary */
7595b482a8SLen Brown
769ff5a21aSBob Moore if (walk_state->opcode == AML_COPY_OBJECT_OP) {
7795b482a8SLen Brown break;
7895b482a8SLen Brown }
7995b482a8SLen Brown
8095b482a8SLen Brown /* Must have a Integer, Buffer, or String */
8195b482a8SLen Brown
823371c19cSBob Moore if ((source_desc->common.type != ACPI_TYPE_INTEGER) &&
833371c19cSBob Moore (source_desc->common.type != ACPI_TYPE_BUFFER) &&
843371c19cSBob Moore (source_desc->common.type != ACPI_TYPE_STRING) &&
853371c19cSBob Moore !((source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
863371c19cSBob Moore (source_desc->reference.class == ACPI_REFCLASS_TABLE))) {
8795b482a8SLen Brown
8895b482a8SLen Brown /* Conversion successful but still not a valid type */
8995b482a8SLen Brown
9095b482a8SLen Brown ACPI_ERROR((AE_INFO,
91a5922a1fSBob Moore "Cannot assign type [%s] to [%s] (must be type Int/Str/Buf)",
9295b482a8SLen Brown acpi_ut_get_object_type_name(source_desc),
9395b482a8SLen Brown acpi_ut_get_type_name(target_type)));
94a5922a1fSBob Moore
9595b482a8SLen Brown status = AE_AML_OPERAND_TYPE;
9695b482a8SLen Brown }
9795b482a8SLen Brown break;
9895b482a8SLen Brown
9995b482a8SLen Brown case ACPI_TYPE_LOCAL_ALIAS:
10095b482a8SLen Brown case ACPI_TYPE_LOCAL_METHOD_ALIAS:
10195b482a8SLen Brown /*
10295b482a8SLen Brown * All aliases should have been resolved earlier, during the
10395b482a8SLen Brown * operand resolution phase.
10495b482a8SLen Brown */
10595b482a8SLen Brown ACPI_ERROR((AE_INFO, "Store into an unresolved Alias object"));
10695b482a8SLen Brown status = AE_AML_INTERNAL;
10795b482a8SLen Brown break;
10895b482a8SLen Brown
10995b482a8SLen Brown case ACPI_TYPE_PACKAGE:
11095b482a8SLen Brown default:
11195b482a8SLen Brown /*
11295b482a8SLen Brown * All other types than Alias and the various Fields come here,
11395b482a8SLen Brown * including the untyped case - ACPI_TYPE_ANY.
11495b482a8SLen Brown */
11595b482a8SLen Brown break;
11695b482a8SLen Brown }
11795b482a8SLen Brown
11895b482a8SLen Brown return_ACPI_STATUS(status);
11995b482a8SLen Brown }
12095b482a8SLen Brown
12195b482a8SLen Brown /*******************************************************************************
12295b482a8SLen Brown *
12395b482a8SLen Brown * FUNCTION: acpi_ex_store_object_to_object
12495b482a8SLen Brown *
12595b482a8SLen Brown * PARAMETERS: source_desc - Object to store
12695b482a8SLen Brown * dest_desc - Object to receive a copy of the source
12795b482a8SLen Brown * new_desc - New object if dest_desc is obsoleted
12895b482a8SLen Brown * walk_state - Current walk state
12995b482a8SLen Brown *
13095b482a8SLen Brown * RETURN: Status
13195b482a8SLen Brown *
13295b482a8SLen Brown * DESCRIPTION: "Store" an object to another object. This may include
13395b482a8SLen Brown * converting the source type to the target type (implicit
13495b482a8SLen Brown * conversion), and a copy of the value of the source to
13595b482a8SLen Brown * the target.
13695b482a8SLen Brown *
13795b482a8SLen Brown * The Assignment of an object to another (not named) object
13895b482a8SLen Brown * is handled here.
13995b482a8SLen Brown * The Source passed in will replace the current value (if any)
14095b482a8SLen Brown * with the input value.
14195b482a8SLen Brown *
14295b482a8SLen Brown * When storing into an object the data is converted to the
14395b482a8SLen Brown * target object type then stored in the object. This means
14495b482a8SLen Brown * that the target object type (for an initialized target) will
14595b482a8SLen Brown * not be changed by a store operation.
14695b482a8SLen Brown *
14795b482a8SLen Brown * This module allows destination types of Number, String,
14895b482a8SLen Brown * Buffer, and Package.
14995b482a8SLen Brown *
15095b482a8SLen Brown * Assumes parameters are already validated. NOTE: source_desc
15195b482a8SLen Brown * resolution (from a reference object) must be performed by
15295b482a8SLen Brown * the caller if necessary.
15395b482a8SLen Brown *
15495b482a8SLen Brown ******************************************************************************/
15595b482a8SLen Brown
15695b482a8SLen Brown acpi_status
acpi_ex_store_object_to_object(union acpi_operand_object * source_desc,union acpi_operand_object * dest_desc,union acpi_operand_object ** new_desc,struct acpi_walk_state * walk_state)15795b482a8SLen Brown acpi_ex_store_object_to_object(union acpi_operand_object *source_desc,
15895b482a8SLen Brown union acpi_operand_object *dest_desc,
15995b482a8SLen Brown union acpi_operand_object **new_desc,
16095b482a8SLen Brown struct acpi_walk_state *walk_state)
16195b482a8SLen Brown {
16295b482a8SLen Brown union acpi_operand_object *actual_src_desc;
16395b482a8SLen Brown acpi_status status = AE_OK;
16495b482a8SLen Brown
16595b482a8SLen Brown ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc);
16695b482a8SLen Brown
16795b482a8SLen Brown actual_src_desc = source_desc;
16895b482a8SLen Brown if (!dest_desc) {
16995b482a8SLen Brown /*
17095b482a8SLen Brown * There is no destination object (An uninitialized node or
17195b482a8SLen Brown * package element), so we can simply copy the source object
17295b482a8SLen Brown * creating a new destination object
17395b482a8SLen Brown */
17495b482a8SLen Brown status =
17595b482a8SLen Brown acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc,
17695b482a8SLen Brown walk_state);
17795b482a8SLen Brown return_ACPI_STATUS(status);
17895b482a8SLen Brown }
17995b482a8SLen Brown
1803371c19cSBob Moore if (source_desc->common.type != dest_desc->common.type) {
18195b482a8SLen Brown /*
18295b482a8SLen Brown * The source type does not match the type of the destination.
18395b482a8SLen Brown * Perform the "implicit conversion" of the source to the current type
18495b482a8SLen Brown * of the target as per the ACPI specification.
18595b482a8SLen Brown *
18695b482a8SLen Brown * If no conversion performed, actual_src_desc = source_desc.
18795b482a8SLen Brown * Otherwise, actual_src_desc is a temporary object to hold the
18895b482a8SLen Brown * converted object.
18995b482a8SLen Brown */
1903371c19cSBob Moore status = acpi_ex_convert_to_target_type(dest_desc->common.type,
1913371c19cSBob Moore source_desc,
19295b482a8SLen Brown &actual_src_desc,
19395b482a8SLen Brown walk_state);
19495b482a8SLen Brown if (ACPI_FAILURE(status)) {
19595b482a8SLen Brown return_ACPI_STATUS(status);
19695b482a8SLen Brown }
19795b482a8SLen Brown
19895b482a8SLen Brown if (source_desc == actual_src_desc) {
19995b482a8SLen Brown /*
20095b482a8SLen Brown * No conversion was performed. Return the source_desc as the
20195b482a8SLen Brown * new object.
20295b482a8SLen Brown */
20395b482a8SLen Brown *new_desc = source_desc;
20495b482a8SLen Brown return_ACPI_STATUS(AE_OK);
20595b482a8SLen Brown }
20695b482a8SLen Brown }
20795b482a8SLen Brown
20895b482a8SLen Brown /*
20995b482a8SLen Brown * We now have two objects of identical types, and we can perform a
21095b482a8SLen Brown * copy of the *value* of the source object.
21195b482a8SLen Brown */
2123371c19cSBob Moore switch (dest_desc->common.type) {
21395b482a8SLen Brown case ACPI_TYPE_INTEGER:
21495b482a8SLen Brown
21595b482a8SLen Brown dest_desc->integer.value = actual_src_desc->integer.value;
21695b482a8SLen Brown
21795b482a8SLen Brown /* Truncate value if we are executing from a 32-bit ACPI table */
21895b482a8SLen Brown
219ef42e53fSBob Moore (void)acpi_ex_truncate_for32bit_table(dest_desc);
22095b482a8SLen Brown break;
22195b482a8SLen Brown
22295b482a8SLen Brown case ACPI_TYPE_STRING:
22395b482a8SLen Brown
22495b482a8SLen Brown status =
22595b482a8SLen Brown acpi_ex_store_string_to_string(actual_src_desc, dest_desc);
22695b482a8SLen Brown break;
22795b482a8SLen Brown
22895b482a8SLen Brown case ACPI_TYPE_BUFFER:
22995b482a8SLen Brown
23095b482a8SLen Brown status =
23195b482a8SLen Brown acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc);
23295b482a8SLen Brown break;
23395b482a8SLen Brown
23495b482a8SLen Brown case ACPI_TYPE_PACKAGE:
23595b482a8SLen Brown
23695b482a8SLen Brown status =
23795b482a8SLen Brown acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc,
23895b482a8SLen Brown walk_state);
23995b482a8SLen Brown break;
24095b482a8SLen Brown
24195b482a8SLen Brown default:
24295b482a8SLen Brown /*
24395b482a8SLen Brown * All other types come here.
24495b482a8SLen Brown */
245a5922a1fSBob Moore ACPI_WARNING((AE_INFO, "Store into type [%s] not implemented",
24695b482a8SLen Brown acpi_ut_get_object_type_name(dest_desc)));
24795b482a8SLen Brown
24895b482a8SLen Brown status = AE_NOT_IMPLEMENTED;
24995b482a8SLen Brown break;
25095b482a8SLen Brown }
25195b482a8SLen Brown
25295b482a8SLen Brown if (actual_src_desc != source_desc) {
25395b482a8SLen Brown
25495b482a8SLen Brown /* Delete the intermediate (temporary) source object */
25595b482a8SLen Brown
25695b482a8SLen Brown acpi_ut_remove_reference(actual_src_desc);
25795b482a8SLen Brown }
25895b482a8SLen Brown
25995b482a8SLen Brown *new_desc = dest_desc;
26095b482a8SLen Brown return_ACPI_STATUS(status);
26195b482a8SLen Brown }
262