dswscope.c 6.6 KB

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