Exemple #1
0
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)
{
	union acpi_operand_object *actual_src_desc;
	acpi_status status = AE_OK;

	ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc);

	actual_src_desc = source_desc;
	if (!dest_desc) {
		/*
		 * There is no destination object (An uninitialized node or
		 * package element), so we can simply copy the source object
		 * creating a new destination object
		 */
		status =
		    acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc,
						    walk_state);
		return_ACPI_STATUS(status);
	}

	if (ACPI_GET_OBJECT_TYPE(source_desc) !=
	    ACPI_GET_OBJECT_TYPE(dest_desc)) {
		/*
		 * The source type does not match the type of the destination.
		 * Perform the "implicit conversion" of the source to the current type
		 * of the target as per the ACPI specification.
		 *
		 * If no conversion performed, actual_src_desc = source_desc.
		 * Otherwise, actual_src_desc is a temporary object to hold the
		 * converted object.
		 */
		status =
		    acpi_ex_convert_to_target_type(ACPI_GET_OBJECT_TYPE
						   (dest_desc), source_desc,
						   &actual_src_desc,
						   walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
		}

		if (source_desc == actual_src_desc) {
			/*
			 * No conversion was performed. Return the source_desc as the
			 * new object.
			 */
			*new_desc = source_desc;
			return_ACPI_STATUS(AE_OK);
		}
	}

	/*
	 * We now have two objects of identical types, and we can perform a
	 * copy of the *value* of the source object.
	 */
	switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
	case ACPI_TYPE_INTEGER:

		dest_desc->integer.value = actual_src_desc->integer.value;

		/* Truncate value if we are executing from a 32-bit ACPI table */

		acpi_ex_truncate_for32bit_table(dest_desc);
		break;

	case ACPI_TYPE_STRING:

		status =
		    acpi_ex_store_string_to_string(actual_src_desc, dest_desc);
		break;

	case ACPI_TYPE_BUFFER:

		status =
		    acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc);
		break;

	case ACPI_TYPE_PACKAGE:

		status =
		    acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc,
						    walk_state);
		break;

	default:
		/*
		 * All other types come here.
		 */
		ACPI_WARNING((AE_INFO, "Store into type %s not implemented",
			      acpi_ut_get_object_type_name(dest_desc)));

		status = AE_NOT_IMPLEMENTED;
		break;
	}

	if (actual_src_desc != source_desc) {

		/* Delete the intermediate (temporary) source object */

		acpi_ut_remove_reference(actual_src_desc);
	}

	*new_desc = dest_desc;
	return_ACPI_STATUS(status);
}
acpi_status
acpi_ds_store_object_to_local (
    u16                     opcode,
    u32                     index,
    acpi_operand_object     *src_desc,
    acpi_walk_state         *walk_state)
{
    acpi_status             status;
    acpi_operand_object     **entry;


    FUNCTION_TRACE ("Ds_method_data_set_value");
    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%d Idx=%d Obj=%p\n",
                       opcode, index, src_desc));


    /* Parameter validation */

    if (!src_desc) {
        return_ACPI_STATUS (AE_BAD_PARAMETER);
    }


    /* Get a pointer to the requested method stack entry */

    status = acpi_ds_method_data_get_entry (opcode, index, walk_state, &entry);
    if (ACPI_FAILURE (status)) {
        goto cleanup;
    }

    if (*entry == src_desc) {
        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n", src_desc));
        goto cleanup;
    }


    /*
     * If there is an object already in this slot, we either
     * have to delete it, or if this is an argument and there
     * is an object reference stored there, we have to do
     * an indirect store!
     */
    if (*entry) {
        /*
         * Check for an indirect store if an argument
         * contains an object reference (stored as an Node).
         * We don't allow this automatic dereferencing for
         * locals, since a store to a local should overwrite
         * anything there, including an object reference.
         *
         * If both Arg0 and Local0 contain Ref_of (Local4):
         *
         * Store (1, Arg0)             - Causes indirect store to local4
         * Store (1, Local0)           - Stores 1 in local0, overwriting
         *                                  the reference to local4
         * Store (1, De_refof (Local0)) - Causes indirect store to local4
         *
         * Weird, but true.
         */
        if ((opcode == AML_ARG_OP) &&
                (VALID_DESCRIPTOR_TYPE (*entry, ACPI_DESC_TYPE_NAMED))) {
            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
                               "Arg (%p) is an Obj_ref(Node), storing in %p\n",
                               src_desc, *entry));

            /* Detach an existing object from the Node */

            acpi_ns_detach_object ((acpi_namespace_node *) *entry);

            /*
             * Store this object into the Node
             * (do the indirect store)
             */
            status = acpi_ns_attach_object ((acpi_namespace_node *) *entry, src_desc,
                                            src_desc->common.type);
            return_ACPI_STATUS (status);
        }


#ifdef ACPI_ENABLE_IMPLICIT_CONVERSION
        /*
         * Perform "Implicit conversion" of the new object to the type of the
         * existing object
         */
        status = acpi_ex_convert_to_target_type ((*entry)->common.type, &src_desc, walk_state);
        if (ACPI_FAILURE (status)) {
            goto cleanup;
        }
#endif

        /*
         * Delete the existing object
         * before storing the new one
         */
        acpi_ds_method_data_delete_value (opcode, index, walk_state);
    }


    /*
     * Install the Obj_stack descriptor (*Src_desc) into
     * the descriptor for the Arg or Local.
     * Install the new object in the stack entry
     * (increments the object reference count by one)
     */
    status = acpi_ds_method_data_set_entry (opcode, index, src_desc, walk_state);
    if (ACPI_FAILURE (status)) {
        goto cleanup;
    }

    /* Normal exit */

    return_ACPI_STATUS (AE_OK);


    /* Error exit */

cleanup:

    return_ACPI_STATUS (status);
}