1
1

psscope.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /******************************************************************************
  2. *
  3. * Module Name: psscope - Parser scope stack management routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2019, 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.h"
  43. #include "accommon.h"
  44. #include "acparser.h"
  45. #define _COMPONENT ACPI_PARSER
  46. ACPI_MODULE_NAME ("psscope")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: AcpiPsGetParentScope
  50. *
  51. * PARAMETERS: ParserState - 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. ACPI_PARSE_OBJECT *
  59. AcpiPsGetParentScope (
  60. ACPI_PARSE_STATE *ParserState)
  61. {
  62. return (ParserState->Scope->ParseScope.Op);
  63. }
  64. /*******************************************************************************
  65. *
  66. * FUNCTION: AcpiPsHasCompletedScope
  67. *
  68. * PARAMETERS: ParserState - Current parser state object
  69. *
  70. * RETURN: Boolean, TRUE = scope completed.
  71. *
  72. * DESCRIPTION: Is parsing of current argument complete? Determined by
  73. * 1) AML pointer is at or beyond the end of the scope
  74. * 2) The scope argument count has reached zero.
  75. *
  76. ******************************************************************************/
  77. BOOLEAN
  78. AcpiPsHasCompletedScope (
  79. ACPI_PARSE_STATE *ParserState)
  80. {
  81. return ((BOOLEAN)
  82. ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||
  83. !ParserState->Scope->ParseScope.ArgCount)));
  84. }
  85. /*******************************************************************************
  86. *
  87. * FUNCTION: AcpiPsInitScope
  88. *
  89. * PARAMETERS: ParserState - Current parser state object
  90. * Root - the Root Node of this new scope
  91. *
  92. * RETURN: Status
  93. *
  94. * DESCRIPTION: Allocate and init a new scope object
  95. *
  96. ******************************************************************************/
  97. ACPI_STATUS
  98. AcpiPsInitScope (
  99. ACPI_PARSE_STATE *ParserState,
  100. ACPI_PARSE_OBJECT *RootOp)
  101. {
  102. ACPI_GENERIC_STATE *Scope;
  103. ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);
  104. Scope = AcpiUtCreateGenericState ();
  105. if (!Scope)
  106. {
  107. return_ACPI_STATUS (AE_NO_MEMORY);
  108. }
  109. Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE;
  110. Scope->ParseScope.Op = RootOp;
  111. Scope->ParseScope.ArgCount = ACPI_VAR_ARGS;
  112. Scope->ParseScope.ArgEnd = ParserState->AmlEnd;
  113. Scope->ParseScope.PkgEnd = ParserState->AmlEnd;
  114. ParserState->Scope = Scope;
  115. ParserState->StartOp = RootOp;
  116. return_ACPI_STATUS (AE_OK);
  117. }
  118. /*******************************************************************************
  119. *
  120. * FUNCTION: AcpiPsPushScope
  121. *
  122. * PARAMETERS: ParserState - Current parser state object
  123. * Op - Current op to be pushed
  124. * RemainingArgs - List of args remaining
  125. * ArgCount - Fixed or variable number of args
  126. *
  127. * RETURN: Status
  128. *
  129. * DESCRIPTION: Push current op to begin parsing its argument
  130. *
  131. ******************************************************************************/
  132. ACPI_STATUS
  133. AcpiPsPushScope (
  134. ACPI_PARSE_STATE *ParserState,
  135. ACPI_PARSE_OBJECT *Op,
  136. UINT32 RemainingArgs,
  137. UINT32 ArgCount)
  138. {
  139. ACPI_GENERIC_STATE *Scope;
  140. ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);
  141. Scope = AcpiUtCreateGenericState ();
  142. if (!Scope)
  143. {
  144. return_ACPI_STATUS (AE_NO_MEMORY);
  145. }
  146. Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE;
  147. Scope->ParseScope.Op = Op;
  148. Scope->ParseScope.ArgList = RemainingArgs;
  149. Scope->ParseScope.ArgCount = ArgCount;
  150. Scope->ParseScope.PkgEnd = ParserState->PkgEnd;
  151. /* Push onto scope stack */
  152. AcpiUtPushGenericState (&ParserState->Scope, Scope);
  153. if (ArgCount == ACPI_VAR_ARGS)
  154. {
  155. /* Multiple arguments */
  156. Scope->ParseScope.ArgEnd = ParserState->PkgEnd;
  157. }
  158. else
  159. {
  160. /* Single argument */
  161. Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);
  162. }
  163. return_ACPI_STATUS (AE_OK);
  164. }
  165. /*******************************************************************************
  166. *
  167. * FUNCTION: AcpiPsPopScope
  168. *
  169. * PARAMETERS: ParserState - Current parser state object
  170. * Op - Where the popped op is returned
  171. * ArgList - Where the popped "next argument" is
  172. * returned
  173. * ArgCount - Count of objects in ArgList
  174. *
  175. * RETURN: Status
  176. *
  177. * DESCRIPTION: Return to parsing a previous op
  178. *
  179. ******************************************************************************/
  180. void
  181. AcpiPsPopScope (
  182. ACPI_PARSE_STATE *ParserState,
  183. ACPI_PARSE_OBJECT **Op,
  184. UINT32 *ArgList,
  185. UINT32 *ArgCount)
  186. {
  187. ACPI_GENERIC_STATE *Scope = ParserState->Scope;
  188. ACPI_FUNCTION_TRACE (PsPopScope);
  189. /* Only pop the scope if there is in fact a next scope */
  190. if (Scope->Common.Next)
  191. {
  192. Scope = AcpiUtPopGenericState (&ParserState->Scope);
  193. /* Return to parsing previous op */
  194. *Op = Scope->ParseScope.Op;
  195. *ArgList = Scope->ParseScope.ArgList;
  196. *ArgCount = Scope->ParseScope.ArgCount;
  197. ParserState->PkgEnd = Scope->ParseScope.PkgEnd;
  198. /* All done with this scope state structure */
  199. AcpiUtDeleteGenericState (Scope);
  200. }
  201. else
  202. {
  203. /* Empty parse stack, prepare to fetch next opcode */
  204. *Op = NULL;
  205. *ArgList = 0;
  206. *ArgCount = 0;
  207. }
  208. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  209. "Popped Op %p Args %X\n", *Op, *ArgCount));
  210. return_VOID;
  211. }
  212. /*******************************************************************************
  213. *
  214. * FUNCTION: AcpiPsCleanupScope
  215. *
  216. * PARAMETERS: ParserState - Current parser state object
  217. *
  218. * RETURN: None
  219. *
  220. * DESCRIPTION: Destroy available list, remaining stack levels, and return
  221. * root scope
  222. *
  223. ******************************************************************************/
  224. void
  225. AcpiPsCleanupScope (
  226. ACPI_PARSE_STATE *ParserState)
  227. {
  228. ACPI_GENERIC_STATE *Scope;
  229. ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);
  230. if (!ParserState)
  231. {
  232. return_VOID;
  233. }
  234. /* Delete anything on the scope stack */
  235. while (ParserState->Scope)
  236. {
  237. Scope = AcpiUtPopGenericState (&ParserState->Scope);
  238. AcpiUtDeleteGenericState (Scope);
  239. }
  240. return_VOID;
  241. }