psscope.c 8.1 KB

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