dswscope.c 6.6 KB

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