psscope.c 8.2 KB

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