dswscope.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /******************************************************************************
  2. *
  3. * Module Name: dswscope - Scope stack manipulation
  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/acdispat.h>
  44. #define _COMPONENT ACPI_DISPATCHER
  45. ACPI_MODULE_NAME ("dswscope")
  46. /****************************************************************************
  47. *
  48. * FUNCTION: acpi_ds_scope_stack_clear
  49. *
  50. * PARAMETERS: walk_state - Current state
  51. *
  52. * RETURN: None
  53. *
  54. * DESCRIPTION: Pop (and free) everything on the scope stack except the
  55. * root scope object (which remains at the stack top.)
  56. *
  57. ***************************************************************************/
  58. void
  59. acpi_ds_scope_stack_clear (
  60. struct acpi_walk_state *walk_state)
  61. {
  62. union acpi_generic_state *scope_info;
  63. ACPI_FUNCTION_NAME ("ds_scope_stack_clear");
  64. while (walk_state->scope_info) {
  65. /* Pop a scope off the stack */
  66. scope_info = walk_state->scope_info;
  67. walk_state->scope_info = scope_info->scope.next;
  68. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  69. "Popped object type (%s)\n",
  70. acpi_ut_get_type_name (scope_info->common.value)));
  71. acpi_ut_delete_generic_state (scope_info);
  72. }
  73. }
  74. /****************************************************************************
  75. *
  76. * FUNCTION: acpi_ds_scope_stack_push
  77. *
  78. * PARAMETERS: Node - Name to be made current
  79. * Type - Type of frame being pushed
  80. * walk_state - Current state
  81. *
  82. * RETURN: Status
  83. *
  84. * DESCRIPTION: Push the current scope on the scope stack, and make the
  85. * passed Node current.
  86. *
  87. ***************************************************************************/
  88. acpi_status
  89. acpi_ds_scope_stack_push (
  90. struct acpi_namespace_node *node,
  91. acpi_object_type type,
  92. struct acpi_walk_state *walk_state)
  93. {
  94. union acpi_generic_state *scope_info;
  95. union acpi_generic_state *old_scope_info;
  96. ACPI_FUNCTION_TRACE ("ds_scope_stack_push");
  97. if (!node) {
  98. /* Invalid scope */
  99. ACPI_REPORT_ERROR (("ds_scope_stack_push: null scope passed\n"));
  100. return_ACPI_STATUS (AE_BAD_PARAMETER);
  101. }
  102. /* Make sure object type is valid */
  103. if (!acpi_ut_valid_object_type (type)) {
  104. ACPI_REPORT_WARNING ((
  105. "ds_scope_stack_push: Invalid object type: 0x%X\n", type));
  106. }
  107. /* Allocate a new scope object */
  108. scope_info = acpi_ut_create_generic_state ();
  109. if (!scope_info) {
  110. return_ACPI_STATUS (AE_NO_MEMORY);
  111. }
  112. /* Init new scope object */
  113. scope_info->common.data_type = ACPI_DESC_TYPE_STATE_WSCOPE;
  114. scope_info->scope.node = node;
  115. scope_info->common.value = (u16) type;
  116. walk_state->scope_depth++;
  117. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  118. "[%.2d] Pushed scope ", (u32) walk_state->scope_depth));
  119. old_scope_info = walk_state->scope_info;
  120. if (old_scope_info) {
  121. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
  122. "[%4.4s] (%s)",
  123. acpi_ut_get_node_name (old_scope_info->scope.node),
  124. acpi_ut_get_type_name (old_scope_info->common.value)));
  125. }
  126. else {
  127. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
  128. "[\\___] (%s)", "ROOT"));
  129. }
  130. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
  131. ", New scope -> [%4.4s] (%s)\n",
  132. acpi_ut_get_node_name (scope_info->scope.node),
  133. acpi_ut_get_type_name (scope_info->common.value)));
  134. /* Push new scope object onto stack */
  135. acpi_ut_push_generic_state (&walk_state->scope_info, scope_info);
  136. return_ACPI_STATUS (AE_OK);
  137. }
  138. /****************************************************************************
  139. *
  140. * FUNCTION: acpi_ds_scope_stack_pop
  141. *
  142. * PARAMETERS: walk_state - Current state
  143. *
  144. * RETURN: Status
  145. *
  146. * DESCRIPTION: Pop the scope stack once.
  147. *
  148. ***************************************************************************/
  149. acpi_status
  150. acpi_ds_scope_stack_pop (
  151. struct acpi_walk_state *walk_state)
  152. {
  153. union acpi_generic_state *scope_info;
  154. union acpi_generic_state *new_scope_info;
  155. ACPI_FUNCTION_TRACE ("ds_scope_stack_pop");
  156. /*
  157. * Pop scope info object off the stack.
  158. */
  159. scope_info = acpi_ut_pop_generic_state (&walk_state->scope_info);
  160. if (!scope_info) {
  161. return_ACPI_STATUS (AE_STACK_UNDERFLOW);
  162. }
  163. walk_state->scope_depth--;
  164. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  165. "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
  166. (u32) walk_state->scope_depth,
  167. acpi_ut_get_node_name (scope_info->scope.node),
  168. acpi_ut_get_type_name (scope_info->common.value)));
  169. new_scope_info = walk_state->scope_info;
  170. if (new_scope_info) {
  171. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
  172. "[%4.4s] (%s)\n",
  173. acpi_ut_get_node_name (new_scope_info->scope.node),
  174. acpi_ut_get_type_name (new_scope_info->common.value)));
  175. }
  176. else {
  177. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
  178. "[\\___] (ROOT)\n"));
  179. }
  180. acpi_ut_delete_generic_state (scope_info);
  181. return_ACPI_STATUS (AE_OK);
  182. }