psxface.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. * The caller "owns" the parameters, so give each one an extra
  90. * reference
  91. */
  92. acpi_ps_update_parameter_list(info, REF_INCREMENT);
  93. /*
  94. * 1) Perform the first pass parse of the method to enter any
  95. * named objects that it creates into the namespace
  96. */
  97. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  98. "**** Begin Method Parse **** Entry=%p obj=%p\n",
  99. info->node, info->obj_desc));
  100. info->pass_number = 1;
  101. status = acpi_ps_execute_pass(info);
  102. if (ACPI_FAILURE(status)) {
  103. goto cleanup;
  104. }
  105. /*
  106. * 2) Execute the method. Performs second pass parse simultaneously
  107. */
  108. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  109. "**** Begin Method Execution **** Entry=%p obj=%p\n",
  110. info->node, info->obj_desc));
  111. info->pass_number = 3;
  112. status = acpi_ps_execute_pass(info);
  113. cleanup:
  114. /* Take away the extra reference that we gave the parameters above */
  115. acpi_ps_update_parameter_list(info, REF_DECREMENT);
  116. /* Exit now if error above */
  117. if (ACPI_FAILURE(status)) {
  118. return_ACPI_STATUS(status);
  119. }
  120. /*
  121. * If the method has returned an object, signal this to the caller with
  122. * a control exception code
  123. */
  124. if (info->return_object) {
  125. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  126. "Method returned obj_desc=%p\n",
  127. info->return_object));
  128. ACPI_DUMP_STACK_ENTRY(info->return_object);
  129. status = AE_CTRL_RETURN_VALUE;
  130. }
  131. return_ACPI_STATUS(status);
  132. }
  133. /*******************************************************************************
  134. *
  135. * FUNCTION: acpi_ps_update_parameter_list
  136. *
  137. * PARAMETERS: Info - See struct acpi_parameter_info
  138. * (Used: parameter_type and Parameters)
  139. * Action - Add or Remove reference
  140. *
  141. * RETURN: Status
  142. *
  143. * DESCRIPTION: Update reference count on all method parameter objects
  144. *
  145. ******************************************************************************/
  146. static void
  147. acpi_ps_update_parameter_list(struct acpi_parameter_info *info, u16 action)
  148. {
  149. acpi_native_uint i;
  150. if ((info->parameter_type == ACPI_PARAM_ARGS) && (info->parameters)) {
  151. /* Update reference count for each parameter */
  152. for (i = 0; info->parameters[i]; i++) {
  153. /* Ignore errors, just do them all */
  154. (void)acpi_ut_update_object_reference(info->
  155. parameters[i],
  156. action);
  157. }
  158. }
  159. }
  160. /*******************************************************************************
  161. *
  162. * FUNCTION: acpi_ps_execute_pass
  163. *
  164. * PARAMETERS: Info - See struct acpi_parameter_info
  165. * (Used: pass_number, Node, and obj_desc)
  166. *
  167. * RETURN: Status
  168. *
  169. * DESCRIPTION: Single AML pass: Parse or Execute a control method
  170. *
  171. ******************************************************************************/
  172. static acpi_status acpi_ps_execute_pass(struct acpi_parameter_info *info)
  173. {
  174. acpi_status status;
  175. union acpi_parse_object *op;
  176. struct acpi_walk_state *walk_state;
  177. ACPI_FUNCTION_TRACE("ps_execute_pass");
  178. /* Create and init a Root Node */
  179. op = acpi_ps_create_scope_op();
  180. if (!op) {
  181. return_ACPI_STATUS(AE_NO_MEMORY);
  182. }
  183. /* Create and initialize a new walk state */
  184. walk_state =
  185. acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
  186. NULL, NULL);
  187. if (!walk_state) {
  188. status = AE_NO_MEMORY;
  189. goto cleanup;
  190. }
  191. status = acpi_ds_init_aml_walk(walk_state, op, info->node,
  192. info->obj_desc->method.aml_start,
  193. info->obj_desc->method.aml_length,
  194. info->pass_number == 1 ? NULL : info,
  195. info->pass_number);
  196. if (ACPI_FAILURE(status)) {
  197. acpi_ds_delete_walk_state(walk_state);
  198. goto cleanup;
  199. }
  200. /* Parse the AML */
  201. status = acpi_ps_parse_aml(walk_state);
  202. /* Walk state was deleted by parse_aml */
  203. cleanup:
  204. acpi_ps_delete_parse_tree(op);
  205. return_ACPI_STATUS(status);
  206. }