amcreate.c
来自「一个类似windows」· C语言 代码 · 共 715 行 · 第 1/2 页
C
715 行
/******************************************************************************
*
* Module Name: amcreate - Named object creation
* $Revision: 1.1 $
*
*****************************************************************************/
/*
* Copyright (C) 2000, 2001 R. Byron Moore
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <acpi.h>
#define _COMPONENT ACPI_EXECUTER
MODULE_NAME ("amcreate")
/*******************************************************************************
*
* FUNCTION: Acpi_aml_exec_create_field
*
* PARAMETERS: Opcode - The opcode to be executed
* Operands - List of operands for the opcode
*
* RETURN: Status
*
* DESCRIPTION: Execute Create_field operators: Create_bit_field_op,
* Create_byte_field_op, Create_word_field_op, Create_dWord_field_op,
* Create_field_op (which define fields in buffers)
*
* ALLOCATION: Deletes Create_field_op's count operand descriptor
*
*
* ACPI SPECIFICATION REFERENCES:
* Def_create_bit_field := Create_bit_field_op Src_buf Bit_idx Name_string
* Def_create_byte_field := Create_byte_field_op Src_buf Byte_idx Name_string
* Def_create_dWord_field := Create_dWord_field_op Src_buf Byte_idx Name_string
* Def_create_field := Create_field_op Src_buf Bit_idx Num_bits Name_string
* Def_create_word_field := Create_word_field_op Src_buf Byte_idx Name_string
* Bit_index := Term_arg=>Integer
* Byte_index := Term_arg=>Integer
* Num_bits := Term_arg=>Integer
* Source_buff := Term_arg=>Buffer
*
******************************************************************************/
ACPI_STATUS
acpi_aml_exec_create_field (
u8 *aml_ptr,
u32 aml_length,
ACPI_NAMESPACE_NODE *node,
ACPI_WALK_STATE *walk_state)
{
ACPI_STATUS status;
ACPI_OPERAND_OBJECT *obj_desc;
ACPI_OPERAND_OBJECT *tmp_desc;
/* Create the region descriptor */
obj_desc = acpi_cm_create_internal_object (ACPI_TYPE_FIELD_UNIT);
if (!obj_desc) {
status = AE_NO_MEMORY;
goto cleanup;
}
/* Construct the field object */
obj_desc->field_unit.access = (u8) ACCESS_ANY_ACC;
obj_desc->field_unit.lock_rule = (u8) GLOCK_NEVER_LOCK;
obj_desc->field_unit.update_rule = (u8) UPDATE_PRESERVE;
/*
* Allocate a method object for this field unit
*/
obj_desc->field_unit.extra = acpi_cm_create_internal_object (
INTERNAL_TYPE_EXTRA);
if (!obj_desc->field_unit.extra) {
status = AE_NO_MEMORY;
goto cleanup;
}
/*
* Remember location in AML stream of the field unit
* opcode and operands -- since the buffer and index
* operands must be evaluated.
*/
obj_desc->field_unit.extra->extra.pcode = aml_ptr;
obj_desc->field_unit.extra->extra.pcode_length = aml_length;
obj_desc->field_unit.node = node;
/*
* This operation is supposed to cause the destination Name to refer
* to the defined Field_unit -- it must not store the constructed
* Field_unit object (or its current value) in some location that the
* Name may already be pointing to. So, if the Name currently contains
* a reference which would cause Acpi_aml_exec_store() to perform an indirect
* store rather than setting the value of the Name itself, clobber that
* reference before calling Acpi_aml_exec_store().
*/
/* Type of Name's existing value */
switch (acpi_ns_get_type (node)) {
case ACPI_TYPE_FIELD_UNIT:
case INTERNAL_TYPE_ALIAS:
case INTERNAL_TYPE_BANK_FIELD:
case INTERNAL_TYPE_DEF_FIELD:
case INTERNAL_TYPE_INDEX_FIELD:
tmp_desc = acpi_ns_get_attached_object (node);
if (tmp_desc) {
/*
* There is an existing object here; delete it and zero out the
* object field within the Node
*/
acpi_cm_remove_reference (tmp_desc);
acpi_ns_attach_object ((ACPI_NAMESPACE_NODE *) node, NULL,
ACPI_TYPE_ANY);
}
/* Set the type to ANY (or the store below will fail) */
((ACPI_NAMESPACE_NODE *) node)->type = ACPI_TYPE_ANY;
break;
default:
break;
}
/* Store constructed field descriptor in result location */
status = acpi_aml_exec_store (obj_desc, (ACPI_OPERAND_OBJECT *) node, walk_state);
/*
* If the field descriptor was not physically stored (or if a failure
* above), we must delete it
*/
if (obj_desc->common.reference_count <= 1) {
acpi_cm_remove_reference (obj_desc);
}
return (AE_OK);
cleanup:
/* Delete region object and method subobject */
if (obj_desc) {
/* Remove deletes both objects! */
acpi_cm_remove_reference (obj_desc);
obj_desc = NULL;
}
return (status);
}
/*****************************************************************************
*
* FUNCTION: Acpi_aml_exec_create_alias
*
* PARAMETERS: Operands - List of operands for the opcode
*
* RETURN: Status
*
* DESCRIPTION: Create a new named alias
*
****************************************************************************/
ACPI_STATUS
acpi_aml_exec_create_alias (
ACPI_WALK_STATE *walk_state)
{
ACPI_NAMESPACE_NODE *source_node;
ACPI_NAMESPACE_NODE *alias_node;
ACPI_STATUS status;
/* Get the source/alias operands (both NTEs) */
status = acpi_ds_obj_stack_pop_object ((ACPI_OPERAND_OBJECT **) &source_node,
walk_state);
if (ACPI_FAILURE (status)) {
return (status);
}
/*
* Don't pop it, it gets removed in the calling routine
*/
alias_node = acpi_ds_obj_stack_get_value (0, walk_state);
/* Add an additional reference to the object */
acpi_cm_add_reference (source_node->object);
/*
* Attach the original source Node to the new Alias Node.
*/
status = acpi_ns_attach_object (alias_node, source_node->object,
source_node->type);
/*
* The new alias assumes the type of the source, but it points
* to the same object. The reference count of the object has two
* additional references to prevent deletion out from under either the
* source or the alias Node
*/
/* Since both operands are NTEs, we don't need to delete them */
return (status);
}
/*****************************************************************************
*
* FUNCTION: Acpi_aml_exec_create_event
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Create a new event object
*
****************************************************************************/
ACPI_STATUS
acpi_aml_exec_create_event (
ACPI_WALK_STATE *walk_state)
{
ACPI_STATUS status;
ACPI_OPERAND_OBJECT *obj_desc;
BREAKPOINT3;
obj_desc = acpi_cm_create_internal_object (ACPI_TYPE_EVENT);
if (!obj_desc) {
status = AE_NO_MEMORY;
goto cleanup;
}
/* Create the actual OS semaphore */
/* TBD: [Investigate] should be created with 0 or 1 units? */
status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 1,
&obj_desc->event.semaphore);
if (ACPI_FAILURE (status)) {
acpi_cm_remove_reference (obj_desc);
goto cleanup;
}
/* Attach object to the Node */
status = acpi_ns_attach_object (acpi_ds_obj_stack_get_value (0, walk_state),
obj_desc, (u8) ACPI_TYPE_EVENT);
if (ACPI_FAILURE (status)) {
acpi_os_delete_semaphore (obj_desc->event.semaphore);
acpi_cm_remove_reference (obj_desc);
goto cleanup;
}
cleanup:
return (status);
}
/*****************************************************************************
*
* FUNCTION: Acpi_aml_exec_create_mutex
*
* PARAMETERS: Interpreter_mode - Current running mode (load1/Load2/Exec)
* Operands - List of operands for the opcode
*
* RETURN: Status
*
* DESCRIPTION: Create a new mutex object
*
****************************************************************************/
ACPI_STATUS
acpi_aml_exec_create_mutex (
ACPI_WALK_STATE *walk_state)
{
ACPI_STATUS status = AE_OK;
ACPI_OPERAND_OBJECT *sync_desc;
ACPI_OPERAND_OBJECT *obj_desc;
/* Get the operand */
status = acpi_ds_obj_stack_pop_object (&sync_desc, walk_state);
if (ACPI_FAILURE (status)) {
return (status);
}
/* Attempt to allocate a new object */
obj_desc = acpi_cm_create_internal_object (ACPI_TYPE_MUTEX);
if (!obj_desc) {
status = AE_NO_MEMORY;
goto cleanup;
}
/* Create the actual OS semaphore */
status = acpi_os_create_semaphore (1, 1, &obj_desc->mutex.semaphore);
if (ACPI_FAILURE (status)) {
acpi_cm_remove_reference (obj_desc);
goto cleanup;
}
obj_desc->mutex.sync_level = (u8) sync_desc->integer.value;
/* Obj_desc was on the stack top, and the name is below it */
status = acpi_ns_attach_object (acpi_ds_obj_stack_get_value (0, walk_state),
obj_desc, (u8) ACPI_TYPE_MUTEX);
if (ACPI_FAILURE (status)) {
acpi_os_delete_semaphore (obj_desc->mutex.semaphore);
acpi_cm_remove_reference (obj_desc);
goto cleanup;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?