exoparg3.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acinterp.h"
  45. #include "acparser.h"
  46. #include "amlcode.h"
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME("exoparg3")
  49. /*!
  50. * Naming convention for AML interpreter execution routines.
  51. *
  52. * The routines that begin execution of AML opcodes are named with a common
  53. * convention based upon the number of arguments, the number of target operands,
  54. * and whether or not a value is returned:
  55. *
  56. * AcpiExOpcode_xA_yT_zR
  57. *
  58. * Where:
  59. *
  60. * xA - ARGUMENTS: The number of arguments (input operands) that are
  61. * required for this opcode type (1 through 6 args).
  62. * yT - TARGETS: The number of targets (output operands) that are required
  63. * for this opcode type (0, 1, or 2 targets).
  64. * zR - RETURN VALUE: Indicates whether this opcode type returns a value
  65. * as the function return (0 or 1).
  66. *
  67. * The AcpiExOpcode* functions are called via the Dispatcher component with
  68. * fully resolved operands.
  69. !*/
  70. /*******************************************************************************
  71. *
  72. * FUNCTION: acpi_ex_opcode_3A_0T_0R
  73. *
  74. * PARAMETERS: walk_state - Current walk state
  75. *
  76. * RETURN: Status
  77. *
  78. * DESCRIPTION: Execute Triadic operator (3 operands)
  79. *
  80. ******************************************************************************/
  81. acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
  82. {
  83. union acpi_operand_object **operand = &walk_state->operands[0];
  84. struct acpi_signal_fatal_info *fatal;
  85. acpi_status status = AE_OK;
  86. ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
  87. acpi_ps_get_opcode_name(walk_state->opcode));
  88. switch (walk_state->opcode) {
  89. case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
  90. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  91. "FatalOp: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
  92. (u32) operand[0]->integer.value,
  93. (u32) operand[1]->integer.value,
  94. (u32) operand[2]->integer.value));
  95. fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
  96. if (fatal) {
  97. fatal->type = (u32) operand[0]->integer.value;
  98. fatal->code = (u32) operand[1]->integer.value;
  99. fatal->argument = (u32) operand[2]->integer.value;
  100. }
  101. /* Always signal the OS! */
  102. status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
  103. /* Might return while OS is shutting down, just continue */
  104. ACPI_FREE(fatal);
  105. break;
  106. default:
  107. ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
  108. walk_state->opcode));
  109. status = AE_AML_BAD_OPCODE;
  110. goto cleanup;
  111. }
  112. cleanup:
  113. return_ACPI_STATUS(status);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_ex_opcode_3A_1T_1R
  118. *
  119. * PARAMETERS: walk_state - Current walk state
  120. *
  121. * RETURN: Status
  122. *
  123. * DESCRIPTION: Execute Triadic operator (3 operands)
  124. *
  125. ******************************************************************************/
  126. acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
  127. {
  128. union acpi_operand_object **operand = &walk_state->operands[0];
  129. union acpi_operand_object *return_desc = NULL;
  130. char *buffer = NULL;
  131. acpi_status status = AE_OK;
  132. u64 index;
  133. acpi_size length;
  134. ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
  135. acpi_ps_get_opcode_name(walk_state->opcode));
  136. switch (walk_state->opcode) {
  137. case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
  138. /*
  139. * Create the return object. The Source operand is guaranteed to be
  140. * either a String or a Buffer, so just use its type.
  141. */
  142. return_desc = acpi_ut_create_internal_object((operand[0])->
  143. common.type);
  144. if (!return_desc) {
  145. status = AE_NO_MEMORY;
  146. goto cleanup;
  147. }
  148. /* Get the Integer values from the objects */
  149. index = operand[1]->integer.value;
  150. length = (acpi_size) operand[2]->integer.value;
  151. /*
  152. * If the index is beyond the length of the String/Buffer, or if the
  153. * requested length is zero, return a zero-length String/Buffer
  154. */
  155. if (index >= operand[0]->string.length) {
  156. length = 0;
  157. }
  158. /* Truncate request if larger than the actual String/Buffer */
  159. else if ((index + length) > operand[0]->string.length) {
  160. length = (acpi_size) operand[0]->string.length -
  161. (acpi_size) index;
  162. }
  163. /* Strings always have a sub-pointer, not so for buffers */
  164. switch ((operand[0])->common.type) {
  165. case ACPI_TYPE_STRING:
  166. /* Always allocate a new buffer for the String */
  167. buffer = ACPI_ALLOCATE_ZEROED((acpi_size) length + 1);
  168. if (!buffer) {
  169. status = AE_NO_MEMORY;
  170. goto cleanup;
  171. }
  172. break;
  173. case ACPI_TYPE_BUFFER:
  174. /* If the requested length is zero, don't allocate a buffer */
  175. if (length > 0) {
  176. /* Allocate a new buffer for the Buffer */
  177. buffer = ACPI_ALLOCATE_ZEROED(length);
  178. if (!buffer) {
  179. status = AE_NO_MEMORY;
  180. goto cleanup;
  181. }
  182. }
  183. break;
  184. default: /* Should not happen */
  185. status = AE_AML_OPERAND_TYPE;
  186. goto cleanup;
  187. }
  188. if (buffer) {
  189. /* We have a buffer, copy the portion requested */
  190. ACPI_MEMCPY(buffer, operand[0]->string.pointer + index,
  191. length);
  192. }
  193. /* Set the length of the new String/Buffer */
  194. return_desc->string.pointer = buffer;
  195. return_desc->string.length = (u32) length;
  196. /* Mark buffer initialized */
  197. return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
  198. break;
  199. default:
  200. ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
  201. walk_state->opcode));
  202. status = AE_AML_BAD_OPCODE;
  203. goto cleanup;
  204. }
  205. /* Store the result in the target */
  206. status = acpi_ex_store(return_desc, operand[3], walk_state);
  207. cleanup:
  208. /* Delete return object on error */
  209. if (ACPI_FAILURE(status) || walk_state->result_obj) {
  210. acpi_ut_remove_reference(return_desc);
  211. walk_state->result_obj = NULL;
  212. }
  213. /* Set the return object and exit */
  214. else {
  215. walk_state->result_obj = return_desc;
  216. }
  217. return_ACPI_STATUS(status);
  218. }