📄 amdyadic.c
字号:
/******************************************************************************
*
* Module Name: amdyadic - ACPI AML (p-code) execution for dyadic operators
* $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 ("amdyadic")
/*******************************************************************************
*
* FUNCTION: Acpi_aml_do_concatenate
*
* PARAMETERS: *Obj_desc - Object to be converted. Must be an
* Integer, Buffer, or String
*
* RETURN: Status
*
* DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_do_concatenate (
ACPI_OPERAND_OBJECT *obj_desc,
ACPI_OPERAND_OBJECT *obj_desc2,
ACPI_OPERAND_OBJECT **actual_ret_desc,
ACPI_WALK_STATE *walk_state)
{
ACPI_STATUS status;
u32 i;
ACPI_INTEGER this_integer;
ACPI_OPERAND_OBJECT *ret_desc;
NATIVE_CHAR *new_buf;
u32 integer_size = sizeof (ACPI_INTEGER);
/*
* There are three cases to handle:
* 1) Two Integers concatenated to produce a buffer
* 2) Two Strings concatenated to produce a string
* 3) Two Buffers concatenated to produce a buffer
*/
switch (obj_desc->common.type) {
case ACPI_TYPE_INTEGER:
/* Handle both ACPI 1.0 and ACPI 2.0 Integer widths */
if (walk_state->method_node->flags & ANOBJ_DATA_WIDTH_32) {
/*
* We are running a method that exists in a 32-bit ACPI table.
* Truncate the value to 32 bits by zeroing out the upper
* 32-bit field
*/
integer_size = sizeof (u32);
}
/* Result of two integers is a buffer */
ret_desc = acpi_cm_create_internal_object (ACPI_TYPE_BUFFER);
if (!ret_desc) {
return (AE_NO_MEMORY);
}
/* Need enough space for two integers */
ret_desc->buffer.length = integer_size * 2;
new_buf = acpi_cm_callocate (ret_desc->buffer.length);
if (!new_buf) {
REPORT_ERROR
(("Aml_exec_dyadic2_r/Concat_op: Buffer allocation failure\n"));
status = AE_NO_MEMORY;
goto cleanup;
}
ret_desc->buffer.pointer = (u8 *) new_buf;
/* Convert the first integer */
this_integer = obj_desc->integer.value;
for (i = 0; i < integer_size; i++) {
new_buf[i] = (u8) this_integer;
this_integer >>= 8;
}
/* Convert the second integer */
this_integer = obj_desc2->integer.value;
for (; i < (integer_size * 2); i++) {
new_buf[i] = (u8) this_integer;
this_integer >>= 8;
}
break;
case ACPI_TYPE_STRING:
ret_desc = acpi_cm_create_internal_object (ACPI_TYPE_STRING);
if (!ret_desc) {
return (AE_NO_MEMORY);
}
/* Operand1 is string */
new_buf = acpi_cm_allocate (obj_desc->string.length +
obj_desc2->string.length + 1);
if (!new_buf) {
REPORT_ERROR
(("Aml_exec_dyadic2_r/Concat_op: String allocation failure\n"));
status = AE_NO_MEMORY;
goto cleanup;
}
STRCPY (new_buf, obj_desc->string.pointer);
STRCPY (new_buf + obj_desc->string.length,
obj_desc2->string.pointer);
/* Point the return object to the new string */
ret_desc->string.pointer = new_buf;
ret_desc->string.length = obj_desc->string.length +=
obj_desc2->string.length;
break;
case ACPI_TYPE_BUFFER:
/* Operand1 is a buffer */
ret_desc = acpi_cm_create_internal_object (ACPI_TYPE_BUFFER);
if (!ret_desc) {
return (AE_NO_MEMORY);
}
new_buf = acpi_cm_allocate (obj_desc->buffer.length +
obj_desc2->buffer.length);
if (!new_buf) {
REPORT_ERROR
(("Aml_exec_dyadic2_r/Concat_op: Buffer allocation failure\n"));
status = AE_NO_MEMORY;
goto cleanup;
}
MEMCPY (new_buf, obj_desc->buffer.pointer,
obj_desc->buffer.length);
MEMCPY (new_buf + obj_desc->buffer.length, obj_desc2->buffer.pointer,
obj_desc2->buffer.length);
/*
* Point the return object to the new buffer
*/
ret_desc->buffer.pointer = (u8 *) new_buf;
ret_desc->buffer.length = obj_desc->buffer.length +
obj_desc2->buffer.length;
break;
default:
status = AE_AML_INTERNAL;
ret_desc = NULL;
}
*actual_ret_desc = ret_desc;
return (AE_OK);
cleanup:
acpi_cm_remove_reference (ret_desc);
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_exec_dyadic1
*
* PARAMETERS: Opcode - The opcode to be executed
*
* RETURN: Status
*
* DESCRIPTION: Execute Type 1 dyadic operator with numeric operands:
* Notify_op
*
* ALLOCATION: Deletes both operands
*
******************************************************************************/
ACPI_STATUS
acpi_aml_exec_dyadic1 (
u16 opcode,
ACPI_WALK_STATE *walk_state)
{
ACPI_OPERAND_OBJECT *obj_desc = NULL;
ACPI_OPERAND_OBJECT *val_desc = NULL;
ACPI_NAMESPACE_NODE *node;
ACPI_STATUS status = AE_OK;
/* Resolve all operands */
status = acpi_aml_resolve_operands (opcode, WALK_OPERANDS, walk_state);
/* Get the operands */
status |= acpi_ds_obj_stack_pop_object (&val_desc, walk_state);
status |= acpi_ds_obj_stack_pop_object (&obj_desc, walk_state);
if (ACPI_FAILURE (status)) {
/* Invalid parameters on object stack */
goto cleanup;
}
/* Examine the opcode */
switch (opcode) {
/* Def_notify := Notify_op Notify_object Notify_value */
case AML_NOTIFY_OP:
/* The Obj_desc is actually an Node */
node = (ACPI_NAMESPACE_NODE *) obj_desc;
obj_desc = NULL;
/* Object must be a device or thermal zone */
if (node && val_desc) {
switch (node->type) {
case ACPI_TYPE_DEVICE:
case ACPI_TYPE_THERMAL:
/*
* Dispatch the notify to the appropriate handler
* NOTE: the request is queued for execution after this method
* completes. The notify handlers are NOT invoked synchronously
* from this thread -- because handlers may in turn run other
* control methods.
*/
status = acpi_ev_queue_notify_request (node,
(u32) val_desc->integer.value);
break;
default:
status = AE_AML_OPERAND_TYPE;
break;
}
}
break;
default:
REPORT_ERROR (("Acpi_aml_exec_dyadic1: Unknown dyadic opcode %X\n",
opcode));
status = AE_AML_BAD_OPCODE;
}
cleanup:
/* Always delete both operands */
acpi_cm_remove_reference (val_desc);
acpi_cm_remove_reference (obj_desc);
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_exec_dyadic2_r
*
* PARAMETERS: Opcode - The opcode to be executed
*
* RETURN: Status
*
* DESCRIPTION: Execute Type 2 dyadic operator with numeric operands and
* one or two result operands.
*
* ALLOCATION: Deletes one operand descriptor -- other remains on stack
*
******************************************************************************/
ACPI_STATUS
acpi_aml_exec_dyadic2_r (
u16 opcode,
ACPI_WALK_STATE *walk_state,
ACPI_OPERAND_OBJECT **return_desc)
{
ACPI_OPERAND_OBJECT *obj_desc = NULL;
ACPI_OPERAND_OBJECT *obj_desc2 = NULL;
ACPI_OPERAND_OBJECT *res_desc = NULL;
ACPI_OPERAND_OBJECT *res_desc2 = NULL;
ACPI_OPERAND_OBJECT *ret_desc = NULL;
ACPI_OPERAND_OBJECT *ret_desc2 = NULL;
ACPI_STATUS status = AE_OK;
u32 num_operands = 3;
/* Resolve all operands */
status = acpi_aml_resolve_operands (opcode, WALK_OPERANDS, walk_state);
/* Get all operands */
if (AML_DIVIDE_OP == opcode) {
num_operands = 4;
status |= acpi_ds_obj_stack_pop_object (&res_desc2, walk_state);
}
status |= acpi_ds_obj_stack_pop_object (&res_desc, walk_state);
status |= acpi_ds_obj_stack_pop_object (&obj_desc2, walk_state);
status |= acpi_ds_obj_stack_pop_object (&obj_desc, walk_state);
if (ACPI_FAILURE (status)) {
goto cleanup;
}
/* Create an internal return object if necessary */
switch (opcode) {
case AML_ADD_OP:
case AML_BIT_AND_OP:
case AML_BIT_NAND_OP:
case AML_BIT_OR_OP:
case AML_BIT_NOR_OP:
case AML_BIT_XOR_OP:
case AML_DIVIDE_OP:
case AML_MULTIPLY_OP:
case AML_SHIFT_LEFT_OP:
case AML_SHIFT_RIGHT_OP:
case AML_SUBTRACT_OP:
ret_desc = acpi_cm_create_internal_object (ACPI_TYPE_INTEGER);
if (!ret_desc) {
status = AE_NO_MEMORY;
goto cleanup;
}
break;
}
/*
* Execute the opcode
*/
switch (opcode) {
/* Def_add := Add_op Operand1 Operand2 Result */
case AML_ADD_OP:
ret_desc->integer.value = obj_desc->integer.value +
obj_desc2->integer.value;
break;
/* Def_and := And_op Operand1 Operand2 Result */
case AML_BIT_AND_OP:
ret_desc->integer.value = obj_desc->integer.value &
obj_desc2->integer.value;
break;
/* Def_nAnd := NAnd_op Operand1 Operand2 Result */
case AML_BIT_NAND_OP:
ret_desc->integer.value = ~(obj_desc->integer.value &
obj_desc2->integer.value);
break;
/* Def_or := Or_op Operand1 Operand2 Result */
case AML_BIT_OR_OP:
ret_desc->integer.value = obj_desc->integer.value |
obj_desc2->integer.value;
break;
/* Def_nOr := NOr_op Operand1 Operand2 Result */
case AML_BIT_NOR_OP:
ret_desc->integer.value = ~(obj_desc->integer.value |
obj_desc2->integer.value);
break;
/* Def_xOr := XOr_op Operand1 Operand2 Result */
case AML_BIT_XOR_OP:
ret_desc->integer.value = obj_desc->integer.value ^
obj_desc2->integer.value;
break;
/* Def_divide := Divide_op Dividend Divisor Remainder Quotient */
case AML_DIVIDE_OP:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -