psscope.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /******************************************************************************
  2. *
  3. * Module Name: psscope - Parser scope stack management routines
  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. #define _COMPONENT ACPI_PARSER
  45. ACPI_MODULE_NAME ("psscope")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_ps_get_parent_scope
  49. *
  50. * PARAMETERS: parser_state - Current parser state object
  51. *
  52. * RETURN: Pointer to an Op object
  53. *
  54. * DESCRIPTION: Get parent of current op being parsed
  55. *
  56. ******************************************************************************/
  57. union acpi_parse_object *
  58. acpi_ps_get_parent_scope (
  59. struct acpi_parse_state *parser_state)
  60. {
  61. return (parser_state->scope->parse_scope.op);
  62. }
  63. /*******************************************************************************
  64. *
  65. * FUNCTION: acpi_ps_has_completed_scope
  66. *
  67. * PARAMETERS: parser_state - Current parser state object
  68. *
  69. * RETURN: Boolean, TRUE = scope completed.
  70. *
  71. * DESCRIPTION: Is parsing of current argument complete? Determined by
  72. * 1) AML pointer is at or beyond the end of the scope
  73. * 2) The scope argument count has reached zero.
  74. *
  75. ******************************************************************************/
  76. u8
  77. acpi_ps_has_completed_scope (
  78. struct acpi_parse_state *parser_state)
  79. {
  80. return ((u8) ((parser_state->aml >= parser_state->scope->parse_scope.arg_end ||
  81. !parser_state->scope->parse_scope.arg_count)));
  82. }
  83. /*******************************************************************************
  84. *
  85. * FUNCTION: acpi_ps_init_scope
  86. *
  87. * PARAMETERS: parser_state - Current parser state object
  88. * Root - the Root Node of this new scope
  89. *
  90. * RETURN: Status
  91. *
  92. * DESCRIPTION: Allocate and init a new scope object
  93. *
  94. ******************************************************************************/
  95. acpi_status
  96. acpi_ps_init_scope (
  97. struct acpi_parse_state *parser_state,
  98. union acpi_parse_object *root_op)
  99. {
  100. union acpi_generic_state *scope;
  101. ACPI_FUNCTION_TRACE_PTR ("ps_init_scope", root_op);
  102. scope = acpi_ut_create_generic_state ();
  103. if (!scope) {
  104. return_ACPI_STATUS (AE_NO_MEMORY);
  105. }
  106. scope->common.data_type = ACPI_DESC_TYPE_STATE_RPSCOPE;
  107. scope->parse_scope.op = root_op;
  108. scope->parse_scope.arg_count = ACPI_VAR_ARGS;
  109. scope->parse_scope.arg_end = parser_state->aml_end;
  110. scope->parse_scope.pkg_end = parser_state->aml_end;
  111. parser_state->scope = scope;
  112. parser_state->start_op = root_op;
  113. return_ACPI_STATUS (AE_OK);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_ps_push_scope
  118. *
  119. * PARAMETERS: parser_state - Current parser state object
  120. * Op - Current op to be pushed
  121. * remaining_args - List of args remaining
  122. * arg_count - Fixed or variable number of args
  123. *
  124. * RETURN: Status
  125. *
  126. * DESCRIPTION: Push current op to begin parsing its argument
  127. *
  128. ******************************************************************************/
  129. acpi_status
  130. acpi_ps_push_scope (
  131. struct acpi_parse_state *parser_state,
  132. union acpi_parse_object *op,
  133. u32 remaining_args,
  134. u32 arg_count)
  135. {
  136. union acpi_generic_state *scope;
  137. ACPI_FUNCTION_TRACE_PTR ("ps_push_scope", op);
  138. scope = acpi_ut_create_generic_state ();
  139. if (!scope) {
  140. return_ACPI_STATUS (AE_NO_MEMORY);
  141. }
  142. scope->common.data_type = ACPI_DESC_TYPE_STATE_PSCOPE;
  143. scope->parse_scope.op = op;
  144. scope->parse_scope.arg_list = remaining_args;
  145. scope->parse_scope.arg_count = arg_count;
  146. scope->parse_scope.pkg_end = parser_state->pkg_end;
  147. /* Push onto scope stack */
  148. acpi_ut_push_generic_state (&parser_state->scope, scope);
  149. if (arg_count == ACPI_VAR_ARGS) {
  150. /* multiple arguments */
  151. scope->parse_scope.arg_end = parser_state->pkg_end;
  152. }
  153. else {
  154. /* single argument */
  155. scope->parse_scope.arg_end = ACPI_TO_POINTER (ACPI_MAX_PTR);
  156. }
  157. return_ACPI_STATUS (AE_OK);
  158. }
  159. /*******************************************************************************
  160. *
  161. * FUNCTION: acpi_ps_pop_scope
  162. *
  163. * PARAMETERS: parser_state - Current parser state object
  164. * Op - Where the popped op is returned
  165. * arg_list - Where the popped "next argument" is
  166. * returned
  167. * arg_count - Count of objects in arg_list
  168. *
  169. * RETURN: Status
  170. *
  171. * DESCRIPTION: Return to parsing a previous op
  172. *
  173. ******************************************************************************/
  174. void
  175. acpi_ps_pop_scope (
  176. struct acpi_parse_state *parser_state,
  177. union acpi_parse_object **op,
  178. u32 *arg_list,
  179. u32 *arg_count)
  180. {
  181. union acpi_generic_state *scope = parser_state->scope;
  182. ACPI_FUNCTION_TRACE ("ps_pop_scope");
  183. /*
  184. * Only pop the scope if there is in fact a next scope
  185. */
  186. if (scope->common.next) {
  187. scope = acpi_ut_pop_generic_state (&parser_state->scope);
  188. /* return to parsing previous op */
  189. *op = scope->parse_scope.op;
  190. *arg_list = scope->parse_scope.arg_list;
  191. *arg_count = scope->parse_scope.arg_count;
  192. parser_state->pkg_end = scope->parse_scope.pkg_end;
  193. /* All done with this scope state structure */
  194. acpi_ut_delete_generic_state (scope);
  195. }
  196. else {
  197. /* empty parse stack, prepare to fetch next opcode */
  198. *op = NULL;
  199. *arg_list = 0;
  200. *arg_count = 0;
  201. }
  202. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped Op %p Args %X\n", *op, *arg_count));
  203. return_VOID;
  204. }
  205. /*******************************************************************************
  206. *
  207. * FUNCTION: acpi_ps_cleanup_scope
  208. *
  209. * PARAMETERS: parser_state - Current parser state object
  210. *
  211. * RETURN: Status
  212. *
  213. * DESCRIPTION: Destroy available list, remaining stack levels, and return
  214. * root scope
  215. *
  216. ******************************************************************************/
  217. void
  218. acpi_ps_cleanup_scope (
  219. struct acpi_parse_state *parser_state)
  220. {
  221. union acpi_generic_state *scope;
  222. ACPI_FUNCTION_TRACE_PTR ("ps_cleanup_scope", parser_state);
  223. if (!parser_state) {
  224. return_VOID;
  225. }
  226. /* Delete anything on the scope stack */
  227. while (parser_state->scope) {
  228. scope = acpi_ut_pop_generic_state (&parser_state->scope);
  229. acpi_ut_delete_generic_state (scope);
  230. }
  231. return_VOID;
  232. }