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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /******************************************************************************
  2.  *
  3.  * Module Name: exstoren - AML Interpreter object store support,
  4.  *                        Store to Node (namespace object)
  5.  *              $Revision: 40 $
  6.  *
  7.  *****************************************************************************/
  8. /*
  9.  *  Copyright (C) 2000, 2001 R. Byron Moore
  10.  *
  11.  *  This program is free software; you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License as published by
  13.  *  the Free Software Foundation; either version 2 of the License, or
  14.  *  (at your option) any later version.
  15.  *
  16.  *  This program is distributed in the hope that it will be useful,
  17.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *  GNU General Public License for more details.
  20.  *
  21.  *  You should have received a copy of the GNU General Public License
  22.  *  along with this program; if not, write to the Free Software
  23.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  24.  */
  25. #include "acpi.h"
  26. #include "acparser.h"
  27. #include "acdispat.h"
  28. #include "acinterp.h"
  29. #include "amlcode.h"
  30. #include "acnamesp.h"
  31. #include "actables.h"
  32. #define _COMPONENT          ACPI_EXECUTER
  33.  MODULE_NAME         ("exstoren")
  34. /*******************************************************************************
  35.  *
  36.  * FUNCTION:    Acpi_ex_resolve_object
  37.  *
  38.  * PARAMETERS:  Source_desc_ptr     - Pointer to the source object
  39.  *              Target_type         - Current type of the target
  40.  *              Walk_state          - Current walk state
  41.  *
  42.  * RETURN:      Status, resolved object in Source_desc_ptr.
  43.  *
  44.  * DESCRIPTION: Resolve an object.  If the object is a reference, dereference
  45.  *              it and return the actual object in the Source_desc_ptr.
  46.  *
  47.  ******************************************************************************/
  48. acpi_status
  49. acpi_ex_resolve_object (
  50. acpi_operand_object     **source_desc_ptr,
  51. acpi_object_type8       target_type,
  52. acpi_walk_state         *walk_state)
  53. {
  54. acpi_operand_object     *source_desc = *source_desc_ptr;
  55. acpi_status             status = AE_OK;
  56. FUNCTION_TRACE ("Ex_resolve_object");
  57. /*
  58.  * Ensure we have a Source that can be stored in the target
  59.  */
  60. switch (target_type) {
  61. /* This case handles the "interchangeable" types Integer, String, and Buffer. */
  62. /*
  63.  * These cases all require only Integers or values that
  64.  * can be converted to Integers (Strings or Buffers)
  65.  */
  66. case ACPI_TYPE_BUFFER_FIELD:
  67. case INTERNAL_TYPE_REGION_FIELD:
  68. case INTERNAL_TYPE_BANK_FIELD:
  69. case INTERNAL_TYPE_INDEX_FIELD:
  70. /*
  71.  * Stores into a Field/Region or into a Buffer/String
  72.  * are all essentially the same.
  73.  */
  74. case ACPI_TYPE_INTEGER:
  75. case ACPI_TYPE_STRING:
  76. case ACPI_TYPE_BUFFER:
  77. /* TBD: FIX - check for source==REF, resolve, then check type */
  78. /*
  79.  * If Source_desc is not a valid type, try to resolve it to one.
  80.  */
  81. if ((source_desc->common.type != ACPI_TYPE_INTEGER)    &&
  82. (source_desc->common.type != ACPI_TYPE_BUFFER)     &&
  83. (source_desc->common.type != ACPI_TYPE_STRING)) {
  84. /*
  85.  * Initially not a valid type, convert
  86.  */
  87. status = acpi_ex_resolve_to_value (source_desc_ptr, walk_state);
  88. if (ACPI_SUCCESS (status) &&
  89. (source_desc->common.type != ACPI_TYPE_INTEGER)    &&
  90. (source_desc->common.type != ACPI_TYPE_BUFFER)     &&
  91. (source_desc->common.type != ACPI_TYPE_STRING)) {
  92. /*
  93.  * Conversion successful but still not a valid type
  94.  */
  95. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  96. "Cannot assign type %s to %s (must be type Int/Str/Buf)n",
  97. acpi_ut_get_type_name ((*source_desc_ptr)->common.type),
  98. acpi_ut_get_type_name (target_type)));
  99. status = AE_AML_OPERAND_TYPE;
  100. }
  101. }
  102. break;
  103. case INTERNAL_TYPE_ALIAS:
  104. /*
  105.  * Aliases are resolved by Acpi_ex_prep_operands
  106.  */
  107. ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Store into Alias - should never happenn"));
  108. status = AE_AML_INTERNAL;
  109. break;
  110. case ACPI_TYPE_PACKAGE:
  111. default:
  112. /*
  113.  * All other types than Alias and the various Fields come here,
  114.  * including the untyped case - ACPI_TYPE_ANY.
  115.  */
  116. break;
  117. }
  118. return_ACPI_STATUS (status);
  119. }
  120. /*******************************************************************************
  121.  *
  122.  * FUNCTION:    Acpi_ex_store_object
  123.  *
  124.  * PARAMETERS:  Source_desc         - Object to store
  125.  *              Target_type         - Current type of the target
  126.  *              Target_desc_ptr     - Pointer to the target
  127.  *              Walk_state          - Current walk state
  128.  *
  129.  * RETURN:      Status
  130.  *
  131.  * DESCRIPTION: "Store" an object to another object.  This may include
  132.  *              converting the source type to the target type (implicit
  133.  *              conversion), and a copy of the value of the source to
  134.  *              the target.
  135.  *
  136.  ******************************************************************************/
  137. acpi_status
  138. acpi_ex_store_object (
  139. acpi_operand_object     *source_desc,
  140. acpi_object_type8       target_type,
  141. acpi_operand_object     **target_desc_ptr,
  142. acpi_walk_state         *walk_state)
  143. {
  144. acpi_operand_object     *target_desc = *target_desc_ptr;
  145. acpi_status             status = AE_OK;
  146. FUNCTION_TRACE ("Ex_store_object");
  147. /*
  148.  * Perform the "implicit conversion" of the source to the current type
  149.  * of the target - As per the ACPI specification.
  150.  *
  151.  * If no conversion performed, Source_desc is left alone, otherwise it
  152.  * is updated with a new object.
  153.  */
  154. status = acpi_ex_convert_to_target_type (target_type, &source_desc, walk_state);
  155. if (ACPI_FAILURE (status)) {
  156. return_ACPI_STATUS (status);
  157. }
  158. /*
  159.  * We now have two objects of identical types, and we can perform a
  160.  * copy of the *value* of the source object.
  161.  */
  162. switch (target_type) {
  163. case ACPI_TYPE_ANY:
  164. case INTERNAL_TYPE_DEF_ANY:
  165. /*
  166.  * The target namespace node is uninitialized (has no target object),
  167.  * and will take on the type of the source object
  168.  */
  169. *target_desc_ptr = source_desc;
  170. break;
  171. case ACPI_TYPE_INTEGER:
  172. target_desc->integer.value = source_desc->integer.value;
  173. /* Truncate value if we are executing from a 32-bit ACPI table */
  174. acpi_ex_truncate_for32bit_table (target_desc, walk_state);
  175. break;
  176. case ACPI_TYPE_STRING:
  177. status = acpi_ex_copy_string_to_string (source_desc, target_desc);
  178. break;
  179. case ACPI_TYPE_BUFFER:
  180. status = acpi_ex_copy_buffer_to_buffer (source_desc, target_desc);
  181. break;
  182. case ACPI_TYPE_PACKAGE:
  183. /*
  184.  * TBD: [Unhandled] Not real sure what to do here
  185.  */
  186. status = AE_NOT_IMPLEMENTED;
  187. break;
  188. default:
  189. /*
  190.  * All other types come here.
  191.  */
  192. ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Store into type %s not implementedn",
  193. acpi_ut_get_type_name (target_type)));
  194. status = AE_NOT_IMPLEMENTED;
  195. break;
  196. }
  197. return_ACPI_STATUS (status);
  198. }