exresnte.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /******************************************************************************
  2.  *
  3.  * Module Name: exresnte - AML Interpreter object resolution
  4.  *              $Revision: 43 $
  5.  *
  6.  *****************************************************************************/
  7. /*
  8.  *  Copyright (C) 2000, 2001 R. Byron Moore
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23.  */
  24. #include "acpi.h"
  25. #include "amlcode.h"
  26. #include "acparser.h"
  27. #include "acdispat.h"
  28. #include "acinterp.h"
  29. #include "acnamesp.h"
  30. #include "actables.h"
  31. #include "acevents.h"
  32. #define _COMPONENT          ACPI_EXECUTER
  33.  MODULE_NAME         ("exresnte")
  34. /*******************************************************************************
  35.  *
  36.  * FUNCTION:    Acpi_ex_resolve_node_to_value
  37.  *
  38.  * PARAMETERS:  Object_ptr      - Pointer to a location that contains
  39.  *                                a pointer to a NS node, and will receive a
  40.  *                                pointer to the resolved object.
  41.  *              Walk_state      - Current state.  Valid only if executing AML
  42.  *                                code.  NULL if simply resolving an object
  43.  *
  44.  * RETURN:      Status
  45.  *
  46.  * DESCRIPTION: Resolve a Namespace node to a valued object
  47.  *
  48.  * Note: for some of the data types, the pointer attached to the Node
  49.  * can be either a pointer to an actual internal object or a pointer into the
  50.  * AML stream itself.  These types are currently:
  51.  *
  52.  *      ACPI_TYPE_INTEGER
  53.  *      ACPI_TYPE_STRING
  54.  *      ACPI_TYPE_BUFFER
  55.  *      ACPI_TYPE_MUTEX
  56.  *      ACPI_TYPE_PACKAGE
  57.  *
  58.  ******************************************************************************/
  59. acpi_status
  60. acpi_ex_resolve_node_to_value (
  61. acpi_namespace_node     **object_ptr,
  62. acpi_walk_state         *walk_state)
  63. {
  64. acpi_status             status = AE_OK;
  65. acpi_operand_object     *source_desc;
  66. acpi_operand_object     *obj_desc = NULL;
  67. acpi_namespace_node     *node;
  68. acpi_object_type8       entry_type;
  69. acpi_integer            temp_val;
  70. FUNCTION_TRACE ("Ex_resolve_node_to_value");
  71. /*
  72.  * The stack pointer points to a acpi_namespace_node (Node).  Get the
  73.  * object that is attached to the Node.
  74.  */
  75. node      = *object_ptr;
  76. source_desc  = acpi_ns_get_attached_object (node);
  77. entry_type = acpi_ns_get_type ((acpi_handle) node);
  78. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p Source_desc=%p Type=%Xn",
  79.  node, source_desc, entry_type));
  80. /*
  81.  * Several object types require no further processing:
  82.  * 1) Devices rarely have an attached object, return the Node
  83.  * 2) Method locals and arguments have a pseudo-Node
  84.  */
  85. if (entry_type == ACPI_TYPE_DEVICE ||
  86. (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
  87. return_ACPI_STATUS (AE_OK);
  88. }
  89. if (!source_desc) {
  90. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object attached to node %pn",
  91. node));
  92. return_ACPI_STATUS (AE_AML_NO_OPERAND);
  93. }
  94. /*
  95.  * Action is based on the type of the Node, which indicates the type
  96.  * of the attached object or pointer
  97.  */
  98. switch (entry_type) {
  99. case ACPI_TYPE_PACKAGE:
  100. if (ACPI_TYPE_PACKAGE != source_desc->common.type) {
  101. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Package, type %sn",
  102. acpi_ut_get_type_name (source_desc->common.type)));
  103. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  104. }
  105. /* Return an additional reference to the object */
  106. obj_desc = source_desc;
  107. acpi_ut_add_reference (obj_desc);
  108. break;
  109. case ACPI_TYPE_BUFFER:
  110. if (ACPI_TYPE_BUFFER != source_desc->common.type) {
  111. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Buffer, type %sn",
  112. acpi_ut_get_type_name (source_desc->common.type)));
  113. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  114. }
  115. /* Return an additional reference to the object */
  116. obj_desc = source_desc;
  117. acpi_ut_add_reference (obj_desc);
  118. break;
  119. case ACPI_TYPE_STRING:
  120. if (ACPI_TYPE_STRING != source_desc->common.type) {
  121. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a String, type %sn",
  122. acpi_ut_get_type_name (source_desc->common.type)));
  123. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  124. }
  125. /* Return an additional reference to the object */
  126. obj_desc = source_desc;
  127. acpi_ut_add_reference (obj_desc);
  128. break;
  129. case ACPI_TYPE_INTEGER:
  130. if (ACPI_TYPE_INTEGER != source_desc->common.type) {
  131. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Integer, type %sn",
  132. acpi_ut_get_type_name (source_desc->common.type)));
  133. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  134. }
  135. /* Return an additional reference to the object */
  136. obj_desc = source_desc;
  137. acpi_ut_add_reference (obj_desc);
  138. break;
  139. case ACPI_TYPE_BUFFER_FIELD:
  140. case INTERNAL_TYPE_REGION_FIELD:
  141. case INTERNAL_TYPE_BANK_FIELD:
  142. case INTERNAL_TYPE_INDEX_FIELD:
  143. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Field_read Node=%p Source_desc=%p Type=%Xn",
  144. node, source_desc, entry_type));
  145. status = acpi_ex_read_data_from_field (source_desc, &obj_desc);
  146. break;
  147. /*
  148.  * For these objects, just return the object attached to the Node
  149.  */
  150. case ACPI_TYPE_MUTEX:
  151. case ACPI_TYPE_METHOD:
  152. case ACPI_TYPE_POWER:
  153. case ACPI_TYPE_PROCESSOR:
  154. case ACPI_TYPE_THERMAL:
  155. case ACPI_TYPE_EVENT:
  156. case ACPI_TYPE_REGION:
  157. /* Return an additional reference to the object */
  158. obj_desc = source_desc;
  159. acpi_ut_add_reference (obj_desc);
  160. break;
  161. /* TYPE_Any is untyped, and thus there is no object associated with it */
  162. case ACPI_TYPE_ANY:
  163. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Untyped entry %p, no attached object!n",
  164. node));
  165. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);  /* Cannot be AE_TYPE */
  166. break;
  167. /*
  168.  * The only named references allowed are named constants
  169.  *   e.g. -- Name (OSFL, Ones)
  170.  */
  171. case INTERNAL_TYPE_REFERENCE:
  172. switch (source_desc->reference.opcode) {
  173. case AML_ZERO_OP:
  174. temp_val = 0;
  175. break;
  176. case AML_ONE_OP:
  177. temp_val = 1;
  178. break;
  179. case AML_ONES_OP:
  180. temp_val = ACPI_INTEGER_MAX;
  181. break;
  182. case AML_REVISION_OP:
  183. temp_val = ACPI_CA_SUPPORT_LEVEL;
  184. break;
  185. default:
  186. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unsupported reference opcode %Xn",
  187. source_desc->reference.opcode));
  188. return_ACPI_STATUS (AE_AML_BAD_OPCODE);
  189. }
  190. /* Create object for result */
  191. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
  192. if (!obj_desc) {
  193. return_ACPI_STATUS (AE_NO_MEMORY);
  194. }
  195. obj_desc->integer.value = temp_val;
  196. /*
  197.  * Truncate value if we are executing from a 32-bit ACPI table
  198.  * AND actually executing AML code.  If we are resolving
  199.  * an object in the namespace via an external call to the
  200.  * subsystem, we will have a null Walk_state
  201.  */
  202. if (walk_state) {
  203. acpi_ex_truncate_for32bit_table (obj_desc, walk_state);
  204. }
  205. break;
  206. /* Default case is for unknown types */
  207. default:
  208. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Node %p - Unknown object type %Xn",
  209. node, entry_type));
  210. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  211. } /* switch (Entry_type) */
  212. /* Put the object descriptor on the stack */
  213. *object_ptr = (void *) obj_desc;
  214. return_ACPI_STATUS (status);
  215. }