psxface.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /******************************************************************************
  2. *
  3. * Module Name: psxface - Parser external interfaces
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acparser.h>
  44. #include <acpi/acdispat.h>
  45. #include <acpi/acinterp.h>
  46. #include <acpi/acnamesp.h>
  47. #define _COMPONENT ACPI_PARSER
  48. ACPI_MODULE_NAME ("psxface")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_psx_execute
  52. *
  53. * PARAMETERS: Info - Method info block, contains:
  54. * Node - Method Node to execute
  55. * Parameters - List of parameters to pass to the method,
  56. * terminated by NULL. Params itself may be
  57. * NULL if no parameters are being passed.
  58. * return_object - Where to put method's return value (if
  59. * any). If NULL, no value is returned.
  60. * parameter_type - Type of Parameter list
  61. * return_object - Where to put method's return value (if
  62. * any). If NULL, no value is returned.
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: Execute a control method
  67. *
  68. ******************************************************************************/
  69. acpi_status
  70. acpi_psx_execute (
  71. struct acpi_parameter_info *info)
  72. {
  73. acpi_status status;
  74. union acpi_operand_object *obj_desc;
  75. u32 i;
  76. union acpi_parse_object *op;
  77. struct acpi_walk_state *walk_state;
  78. ACPI_FUNCTION_TRACE ("psx_execute");
  79. /* Validate the Node and get the attached object */
  80. if (!info || !info->node) {
  81. return_ACPI_STATUS (AE_NULL_ENTRY);
  82. }
  83. obj_desc = acpi_ns_get_attached_object (info->node);
  84. if (!obj_desc) {
  85. return_ACPI_STATUS (AE_NULL_OBJECT);
  86. }
  87. /* Init for new method, wait on concurrency semaphore */
  88. status = acpi_ds_begin_method_execution (info->node, obj_desc, NULL);
  89. if (ACPI_FAILURE (status)) {
  90. return_ACPI_STATUS (status);
  91. }
  92. if ((info->parameter_type == ACPI_PARAM_ARGS) &&
  93. (info->parameters)) {
  94. /*
  95. * The caller "owns" the parameters, so give each one an extra
  96. * reference
  97. */
  98. for (i = 0; info->parameters[i]; i++) {
  99. acpi_ut_add_reference (info->parameters[i]);
  100. }
  101. }
  102. /*
  103. * 1) Perform the first pass parse of the method to enter any
  104. * named objects that it creates into the namespace
  105. */
  106. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  107. "**** Begin Method Parse **** Entry=%p obj=%p\n",
  108. info->node, obj_desc));
  109. /* Create and init a Root Node */
  110. op = acpi_ps_create_scope_op ();
  111. if (!op) {
  112. status = AE_NO_MEMORY;
  113. goto cleanup1;
  114. }
  115. /*
  116. * Get a new owner_id for objects created by this method. Namespace
  117. * objects (such as Operation Regions) can be created during the
  118. * first pass parse.
  119. */
  120. obj_desc->method.owning_id = acpi_ut_allocate_owner_id (ACPI_OWNER_TYPE_METHOD);
  121. /* Create and initialize a new walk state */
  122. walk_state = acpi_ds_create_walk_state (obj_desc->method.owning_id,
  123. NULL, NULL, NULL);
  124. if (!walk_state) {
  125. status = AE_NO_MEMORY;
  126. goto cleanup2;
  127. }
  128. status = acpi_ds_init_aml_walk (walk_state, op, info->node,
  129. obj_desc->method.aml_start,
  130. obj_desc->method.aml_length, NULL, 1);
  131. if (ACPI_FAILURE (status)) {
  132. goto cleanup3;
  133. }
  134. /* Parse the AML */
  135. status = acpi_ps_parse_aml (walk_state);
  136. acpi_ps_delete_parse_tree (op);
  137. if (ACPI_FAILURE (status)) {
  138. goto cleanup1; /* Walk state is already deleted */
  139. }
  140. /*
  141. * 2) Execute the method. Performs second pass parse simultaneously
  142. */
  143. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  144. "**** Begin Method Execution **** Entry=%p obj=%p\n",
  145. info->node, obj_desc));
  146. /* Create and init a Root Node */
  147. op = acpi_ps_create_scope_op ();
  148. if (!op) {
  149. status = AE_NO_MEMORY;
  150. goto cleanup1;
  151. }
  152. /* Init new op with the method name and pointer back to the NS node */
  153. acpi_ps_set_name (op, info->node->name.integer);
  154. op->common.node = info->node;
  155. /* Create and initialize a new walk state */
  156. walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
  157. if (!walk_state) {
  158. status = AE_NO_MEMORY;
  159. goto cleanup2;
  160. }
  161. status = acpi_ds_init_aml_walk (walk_state, op, info->node,
  162. obj_desc->method.aml_start,
  163. obj_desc->method.aml_length, info, 3);
  164. if (ACPI_FAILURE (status)) {
  165. goto cleanup3;
  166. }
  167. /* The walk of the parse tree is where we actually execute the method */
  168. status = acpi_ps_parse_aml (walk_state);
  169. goto cleanup2; /* Walk state already deleted */
  170. cleanup3:
  171. acpi_ds_delete_walk_state (walk_state);
  172. cleanup2:
  173. acpi_ps_delete_parse_tree (op);
  174. cleanup1:
  175. if ((info->parameter_type == ACPI_PARAM_ARGS) &&
  176. (info->parameters)) {
  177. /* Take away the extra reference that we gave the parameters above */
  178. for (i = 0; info->parameters[i]; i++) {
  179. /* Ignore errors, just do them all */
  180. (void) acpi_ut_update_object_reference (
  181. info->parameters[i], REF_DECREMENT);
  182. }
  183. }
  184. if (ACPI_FAILURE (status)) {
  185. return_ACPI_STATUS (status);
  186. }
  187. /*
  188. * If the method has returned an object, signal this to the caller with
  189. * a control exception code
  190. */
  191. if (info->return_object) {
  192. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned obj_desc=%p\n",
  193. info->return_object));
  194. ACPI_DUMP_STACK_ENTRY (info->return_object);
  195. status = AE_CTRL_RETURN_VALUE;
  196. }
  197. return_ACPI_STATUS (status);
  198. }