psxface.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. #define _COMPONENT ACPI_PARSER
  47. ACPI_MODULE_NAME("psxface")
  48. /* Local Prototypes */
  49. static acpi_status acpi_ps_execute_pass(struct acpi_parameter_info *info);
  50. static void
  51. acpi_ps_update_parameter_list(struct acpi_parameter_info *info, u16 action);
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_ps_execute_method
  55. *
  56. * PARAMETERS: Info - Method info block, contains:
  57. * Node - Method Node to execute
  58. * obj_desc - Method object
  59. * Parameters - List of parameters to pass to the method,
  60. * terminated by NULL. Params itself may be
  61. * NULL if no parameters are being passed.
  62. * return_object - Where to put method's return value (if
  63. * any). If NULL, no value is returned.
  64. * parameter_type - Type of Parameter list
  65. * return_object - Where to put method's return value (if
  66. * any). If NULL, no value is returned.
  67. * pass_number - Parse or execute pass
  68. *
  69. * RETURN: Status
  70. *
  71. * DESCRIPTION: Execute a control method
  72. *
  73. ******************************************************************************/
  74. acpi_status acpi_ps_execute_method(struct acpi_parameter_info *info)
  75. {
  76. acpi_status status;
  77. ACPI_FUNCTION_TRACE("ps_execute_method");
  78. /* Validate the Info and method Node */
  79. if (!info || !info->node) {
  80. return_ACPI_STATUS(AE_NULL_ENTRY);
  81. }
  82. /* Init for new method, wait on concurrency semaphore */
  83. status =
  84. acpi_ds_begin_method_execution(info->node, info->obj_desc, NULL);
  85. if (ACPI_FAILURE(status)) {
  86. return_ACPI_STATUS(status);
  87. }
  88. /*
  89. * Get a new owner_id for objects created by this method. Namespace
  90. * objects (such as Operation Regions) can be created during the
  91. * first pass parse.
  92. */
  93. status = acpi_ut_allocate_owner_id(&info->obj_desc->method.owner_id);
  94. if (ACPI_FAILURE(status)) {
  95. return_ACPI_STATUS(status);
  96. }
  97. /*
  98. * The caller "owns" the parameters, so give each one an extra
  99. * reference
  100. */
  101. acpi_ps_update_parameter_list(info, REF_INCREMENT);
  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, info->obj_desc));
  109. info->pass_number = 1;
  110. status = acpi_ps_execute_pass(info);
  111. if (ACPI_FAILURE(status)) {
  112. goto cleanup;
  113. }
  114. /*
  115. * 2) Execute the method. Performs second pass parse simultaneously
  116. */
  117. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  118. "**** Begin Method Execution **** Entry=%p obj=%p\n",
  119. info->node, info->obj_desc));
  120. info->pass_number = 3;
  121. status = acpi_ps_execute_pass(info);
  122. cleanup:
  123. if (info->obj_desc->method.owner_id) {
  124. acpi_ut_release_owner_id(&info->obj_desc->method.owner_id);
  125. }
  126. /* Take away the extra reference that we gave the parameters above */
  127. acpi_ps_update_parameter_list(info, REF_DECREMENT);
  128. /* Exit now if error above */
  129. if (ACPI_FAILURE(status)) {
  130. return_ACPI_STATUS(status);
  131. }
  132. /*
  133. * If the method has returned an object, signal this to the caller with
  134. * a control exception code
  135. */
  136. if (info->return_object) {
  137. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  138. "Method returned obj_desc=%p\n",
  139. info->return_object));
  140. ACPI_DUMP_STACK_ENTRY(info->return_object);
  141. status = AE_CTRL_RETURN_VALUE;
  142. }
  143. return_ACPI_STATUS(status);
  144. }
  145. /*******************************************************************************
  146. *
  147. * FUNCTION: acpi_ps_update_parameter_list
  148. *
  149. * PARAMETERS: Info - See struct acpi_parameter_info
  150. * (Used: parameter_type and Parameters)
  151. * Action - Add or Remove reference
  152. *
  153. * RETURN: Status
  154. *
  155. * DESCRIPTION: Update reference count on all method parameter objects
  156. *
  157. ******************************************************************************/
  158. static void
  159. acpi_ps_update_parameter_list(struct acpi_parameter_info *info, u16 action)
  160. {
  161. acpi_native_uint i;
  162. if ((info->parameter_type == ACPI_PARAM_ARGS) && (info->parameters)) {
  163. /* Update reference count for each parameter */
  164. for (i = 0; info->parameters[i]; i++) {
  165. /* Ignore errors, just do them all */
  166. (void)acpi_ut_update_object_reference(info->
  167. parameters[i],
  168. action);
  169. }
  170. }
  171. }
  172. /*******************************************************************************
  173. *
  174. * FUNCTION: acpi_ps_execute_pass
  175. *
  176. * PARAMETERS: Info - See struct acpi_parameter_info
  177. * (Used: pass_number, Node, and obj_desc)
  178. *
  179. * RETURN: Status
  180. *
  181. * DESCRIPTION: Single AML pass: Parse or Execute a control method
  182. *
  183. ******************************************************************************/
  184. static acpi_status acpi_ps_execute_pass(struct acpi_parameter_info *info)
  185. {
  186. acpi_status status;
  187. union acpi_parse_object *op;
  188. struct acpi_walk_state *walk_state;
  189. ACPI_FUNCTION_TRACE("ps_execute_pass");
  190. /* Create and init a Root Node */
  191. op = acpi_ps_create_scope_op();
  192. if (!op) {
  193. return_ACPI_STATUS(AE_NO_MEMORY);
  194. }
  195. /* Create and initialize a new walk state */
  196. walk_state =
  197. acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
  198. NULL, NULL);
  199. if (!walk_state) {
  200. status = AE_NO_MEMORY;
  201. goto cleanup;
  202. }
  203. status = acpi_ds_init_aml_walk(walk_state, op, info->node,
  204. info->obj_desc->method.aml_start,
  205. info->obj_desc->method.aml_length,
  206. info->pass_number == 1 ? NULL : info,
  207. info->pass_number);
  208. if (ACPI_FAILURE(status)) {
  209. acpi_ds_delete_walk_state(walk_state);
  210. goto cleanup;
  211. }
  212. /* Parse the AML */
  213. status = acpi_ps_parse_aml(walk_state);
  214. /* Walk state was deleted by parse_aml */
  215. cleanup:
  216. acpi_ps_delete_parse_tree(op);
  217. return_ACPI_STATUS(status);
  218. }