psxface.c 7.0 KB

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