psscope.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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)
  81. ((parser_state->aml >= parser_state->scope->parse_scope.arg_end ||
  82. !parser_state->scope->parse_scope.arg_count)));
  83. }
  84. /*******************************************************************************
  85. *
  86. * FUNCTION: acpi_ps_init_scope
  87. *
  88. * PARAMETERS: parser_state - Current parser state object
  89. * Root - the Root Node of this new scope
  90. *
  91. * RETURN: Status
  92. *
  93. * DESCRIPTION: Allocate and init a new scope object
  94. *
  95. ******************************************************************************/
  96. acpi_status
  97. acpi_ps_init_scope (
  98. struct acpi_parse_state *parser_state,
  99. union acpi_parse_object *root_op)
  100. {
  101. union acpi_generic_state *scope;
  102. ACPI_FUNCTION_TRACE_PTR ("ps_init_scope", root_op);
  103. scope = acpi_ut_create_generic_state ();
  104. if (!scope) {
  105. return_ACPI_STATUS (AE_NO_MEMORY);
  106. }
  107. scope->common.data_type = ACPI_DESC_TYPE_STATE_RPSCOPE;
  108. scope->parse_scope.op = root_op;
  109. scope->parse_scope.arg_count = ACPI_VAR_ARGS;
  110. scope->parse_scope.arg_end = parser_state->aml_end;
  111. scope->parse_scope.pkg_end = parser_state->aml_end;
  112. parser_state->scope = scope;
  113. parser_state->start_op = root_op;
  114. return_ACPI_STATUS (AE_OK);
  115. }
  116. /*******************************************************************************
  117. *
  118. * FUNCTION: acpi_ps_push_scope
  119. *
  120. * PARAMETERS: parser_state - Current parser state object
  121. * Op - Current op to be pushed
  122. * remaining_args - List of args remaining
  123. * arg_count - Fixed or variable number of args
  124. *
  125. * RETURN: Status
  126. *
  127. * DESCRIPTION: Push current op to begin parsing its argument
  128. *
  129. ******************************************************************************/
  130. acpi_status
  131. acpi_ps_push_scope (
  132. struct acpi_parse_state *parser_state,
  133. union acpi_parse_object *op,
  134. u32 remaining_args,
  135. u32 arg_count)
  136. {
  137. union acpi_generic_state *scope;
  138. ACPI_FUNCTION_TRACE_PTR ("ps_push_scope", op);
  139. scope = acpi_ut_create_generic_state ();
  140. if (!scope) {
  141. return_ACPI_STATUS (AE_NO_MEMORY);
  142. }
  143. scope->common.data_type = ACPI_DESC_TYPE_STATE_PSCOPE;
  144. scope->parse_scope.op = op;
  145. scope->parse_scope.arg_list = remaining_args;
  146. scope->parse_scope.arg_count = arg_count;
  147. scope->parse_scope.pkg_end = parser_state->pkg_end;
  148. /* Push onto scope stack */
  149. acpi_ut_push_generic_state (&parser_state->scope, scope);
  150. if (arg_count == ACPI_VAR_ARGS) {
  151. /* Multiple arguments */
  152. scope->parse_scope.arg_end = parser_state->pkg_end;
  153. }
  154. else {
  155. /* Single argument */
  156. scope->parse_scope.arg_end = ACPI_TO_POINTER (ACPI_MAX_PTR);
  157. }
  158. return_ACPI_STATUS (AE_OK);
  159. }
  160. /*******************************************************************************
  161. *
  162. * FUNCTION: acpi_ps_pop_scope
  163. *
  164. * PARAMETERS: parser_state - Current parser state object
  165. * Op - Where the popped op is returned
  166. * arg_list - Where the popped "next argument" is
  167. * returned
  168. * arg_count - Count of objects in arg_list
  169. *
  170. * RETURN: Status
  171. *
  172. * DESCRIPTION: Return to parsing a previous op
  173. *
  174. ******************************************************************************/
  175. void
  176. acpi_ps_pop_scope (
  177. struct acpi_parse_state *parser_state,
  178. union acpi_parse_object **op,
  179. u32 *arg_list,
  180. u32 *arg_count)
  181. {
  182. union acpi_generic_state *scope = parser_state->scope;
  183. ACPI_FUNCTION_TRACE ("ps_pop_scope");
  184. /* Only pop the scope if there is in fact a next scope */
  185. if (scope->common.next) {
  186. scope = acpi_ut_pop_generic_state (&parser_state->scope);
  187. /* return to parsing previous op */
  188. *op = scope->parse_scope.op;
  189. *arg_list = scope->parse_scope.arg_list;
  190. *arg_count = scope->parse_scope.arg_count;
  191. parser_state->pkg_end = scope->parse_scope.pkg_end;
  192. /* All done with this scope state structure */
  193. acpi_ut_delete_generic_state (scope);
  194. }
  195. else {
  196. /* empty parse stack, prepare to fetch next opcode */
  197. *op = NULL;
  198. *arg_list = 0;
  199. *arg_count = 0;
  200. }
  201. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  202. "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: None
  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. }