/drivers/acpi/dispatcher/dswscope.c

https://bitbucket.org/evzijst/gittest · C · 229 lines · 94 code · 48 blank · 87 comment · 9 complexity · 0c3e8a871ce52c11c67f9e5d03969519 MD5 · raw file

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