amstore.c

来自「一个类似windows」· C语言 代码 · 共 564 行 · 第 1/2 页

C
564
字号
						  walk_state);
				if (ACPI_FAILURE (status)) {
					/*
					 * An error occurrered when copying the internal object
					 * so delete the reference.
					 */
					return (AE_AML_OPERAND_TYPE);
				}
			}
		}
		break;


	case ACPI_TYPE_BUFFER_FIELD:
		/*
		 * Storing into a buffer at a location defined by an Index.
		 *
		 * Each 8-bit element of the source object is written to the
		 * 8-bit Buffer Field of the Index destination object.
		 */

		/*
		 * Set the Obj_desc to the destination object and type check.
		 */
		obj_desc = dest_desc->reference.object;
		if (obj_desc->common.type != ACPI_TYPE_BUFFER) {
			return (AE_AML_OPERAND_TYPE);
		}

		/*
		 * The assignment of the individual elements will be slightly
		 * different for each source type.
		 */

		switch (val_desc->common.type) {
		/*
		 * If the type is Integer, assign bytewise
		 * This loop to assign each of the elements is somewhat
		 * backward because of the Big Endian-ness of IA-64
		 */
		case ACPI_TYPE_INTEGER:
			length = sizeof (ACPI_INTEGER);
			for (i = length; i != 0; i--) {
				value = (u8)(val_desc->integer.value >> (MUL_8 (i - 1)));
				obj_desc->buffer.pointer[dest_desc->reference.offset] = value;
			}
			break;

		/*
		 * If the type is Buffer, the Length is in the structure.
		 * Just loop through the elements and assign each one in turn.
		 */
		case ACPI_TYPE_BUFFER:
			length = val_desc->buffer.length;
			for (i = 0; i < length; i++) {
				value = *(val_desc->buffer.pointer + i);
				obj_desc->buffer.pointer[dest_desc->reference.offset] = value;
			}
			break;

		/*
		 * If the type is String, the Length is in the structure.
		 * Just loop through the elements and assign each one in turn.
		 */
		case ACPI_TYPE_STRING:
			length = val_desc->string.length;
			for (i = 0; i < length; i++) {
				value = *(val_desc->string.pointer + i);
				obj_desc->buffer.pointer[dest_desc->reference.offset] = value;
			}
			break;

		/*
		 * If source is not a valid type so return an error.
		 */
		default:
			status = AE_AML_OPERAND_TYPE;
			break;
		}
		break;


	default:
		status = AE_AML_OPERAND_TYPE;
		break;
	}


	return (status);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_aml_store_object_to_node
 *
 * PARAMETERS:  *Source_desc           - Value to be stored
 *              *Node                  - Named object to receive the value
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Store the object to the named object.
 *
 *              The Assignment of an object to a named object is handled here
 *              The val passed in will replace the current value (if any)
 *              with the input value.
 *
 *              When storing into an object the data is converted to the
 *              target object type then stored in the object.  This means
 *              that the target object type (for an initialized target) will
 *              not be changed by a store operation.
 *
 *              NOTE: the global lock is acquired early.  This will result
 *              in the global lock being held a bit longer.  Also, if the
 *              function fails during set up we may get the lock when we
 *              don't really need it.  I don't think we care.
 *
 ******************************************************************************/

ACPI_STATUS
acpi_aml_store_object_to_node (
	ACPI_OPERAND_OBJECT     *source_desc,
	ACPI_NAMESPACE_NODE     *node,
	ACPI_WALK_STATE         *walk_state)
{
	ACPI_STATUS             status = AE_OK;
	ACPI_OPERAND_OBJECT     *target_desc;
	OBJECT_TYPE_INTERNAL    target_type = ACPI_TYPE_ANY;


	/*
	 * Assuming the parameters were already validated
	 */
	ACPI_ASSERT((node) && (source_desc));


	/*
	 * Get current type of the node, and object attached to Node
	 */
	target_type = acpi_ns_get_type (node);
	target_desc = acpi_ns_get_attached_object (node);


	/*
	 * Resolve the source object to an actual value
	 * (If it is a reference object)
	 */
	status = acpi_aml_resolve_object (&source_desc, target_type, walk_state);
	if (ACPI_FAILURE (status)) {
		return (status);
	}


	/*
	 * Do the actual store operation
	 */
	switch (target_type) {
	case INTERNAL_TYPE_DEF_FIELD:

		/* Raw data copy for target types Integer/String/Buffer */

		status = acpi_aml_copy_data_to_named_field (source_desc, node);
		break;


	case ACPI_TYPE_INTEGER:
	case ACPI_TYPE_STRING:
	case ACPI_TYPE_BUFFER:
	case INTERNAL_TYPE_BANK_FIELD:
	case INTERNAL_TYPE_INDEX_FIELD:
	case ACPI_TYPE_FIELD_UNIT:

		/*
		 * These target types are all of type Integer/String/Buffer, and
		 * therefore support implicit conversion before the store.
		 *
		 * Copy and/or convert the source object to a new target object
		 */
		status = acpi_aml_store_object (source_desc, target_type, &target_desc, walk_state);
		if (ACPI_FAILURE (status)) {
			return (status);
		}

		/*
		 * Store the new Target_desc as the new value of the Name, and set
		 * the Name's type to that of the value being stored in it.
		 * Source_desc reference count is incremented by Attach_object.
		 */
		status = acpi_ns_attach_object (node, target_desc, target_type);
		break;


	default:

		/* No conversions for all other types.  Just attach the source object */

		status = acpi_ns_attach_object (node, source_desc, source_desc->common.type);

		break;
	}


	return (status);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_aml_store_object_to_object
 *
 * PARAMETERS:  *Source_desc           - Value to be stored
 *              *Dest_desc          - Object to receive the value
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Store an object to another object.
 *
 *              The Assignment of an object to another (not named) object
 *              is handled here.
 *              The val passed in will replace the current value (if any)
 *              with the input value.
 *
 *              When storing into an object the data is converted to the
 *              target object type then stored in the object.  This means
 *              that the target object type (for an initialized target) will
 *              not be changed by a store operation.
 *
 *              This module allows destination types of Number, String,
 *              and Buffer.
 *
 ******************************************************************************/

ACPI_STATUS
acpi_aml_store_object_to_object (
	ACPI_OPERAND_OBJECT     *source_desc,
	ACPI_OPERAND_OBJECT     *dest_desc,
	ACPI_WALK_STATE         *walk_state)
{
	ACPI_STATUS             status = AE_OK;
	OBJECT_TYPE_INTERNAL    destination_type = dest_desc->common.type;


	/*
	 *  Assuming the parameters are valid!
	 */
	ACPI_ASSERT((dest_desc) && (source_desc));


	/*
	 * From this interface, we only support Integers/Strings/Buffers
	 */
	switch (destination_type) {
	case ACPI_TYPE_INTEGER:
	case ACPI_TYPE_STRING:
	case ACPI_TYPE_BUFFER:
		break;

	default:
		return (AE_NOT_IMPLEMENTED);
	}


	/*
	 * Resolve the source object to an actual value
	 * (If it is a reference object)
	 */
	status = acpi_aml_resolve_object (&source_desc, destination_type, walk_state);
	if (ACPI_FAILURE (status)) {
		return (status);
	}


	/*
	 * Copy and/or convert the source object to the destination object
	 */
	status = acpi_aml_store_object (source_desc, destination_type, &dest_desc, walk_state);


	return (status);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?