utstate.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*******************************************************************************
  2. *
  3. * Module Name: utstate - state object support procedures
  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. #define _COMPONENT ACPI_UTILITIES
  44. ACPI_MODULE_NAME("utstate")
  45. /*******************************************************************************
  46. *
  47. * FUNCTION: acpi_ut_create_pkg_state_and_push
  48. *
  49. * PARAMETERS: Object - Object to be added to the new state
  50. * Action - Increment/Decrement
  51. * state_list - List the state will be added to
  52. *
  53. * RETURN: Status
  54. *
  55. * DESCRIPTION: Create a new state and push it
  56. *
  57. ******************************************************************************/
  58. acpi_status
  59. acpi_ut_create_pkg_state_and_push(void *internal_object,
  60. void *external_object,
  61. u16 index,
  62. union acpi_generic_state ** state_list)
  63. {
  64. union acpi_generic_state *state;
  65. ACPI_FUNCTION_ENTRY();
  66. state =
  67. acpi_ut_create_pkg_state(internal_object, external_object, index);
  68. if (!state) {
  69. return (AE_NO_MEMORY);
  70. }
  71. acpi_ut_push_generic_state(state_list, state);
  72. return (AE_OK);
  73. }
  74. /*******************************************************************************
  75. *
  76. * FUNCTION: acpi_ut_push_generic_state
  77. *
  78. * PARAMETERS: list_head - Head of the state stack
  79. * State - State object to push
  80. *
  81. * RETURN: None
  82. *
  83. * DESCRIPTION: Push a state object onto a state stack
  84. *
  85. ******************************************************************************/
  86. void
  87. acpi_ut_push_generic_state(union acpi_generic_state **list_head,
  88. union acpi_generic_state *state)
  89. {
  90. ACPI_FUNCTION_TRACE("ut_push_generic_state");
  91. /* Push the state object onto the front of the list (stack) */
  92. state->common.next = *list_head;
  93. *list_head = state;
  94. return_VOID;
  95. }
  96. /*******************************************************************************
  97. *
  98. * FUNCTION: acpi_ut_pop_generic_state
  99. *
  100. * PARAMETERS: list_head - Head of the state stack
  101. *
  102. * RETURN: The popped state object
  103. *
  104. * DESCRIPTION: Pop a state object from a state stack
  105. *
  106. ******************************************************************************/
  107. union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
  108. **list_head)
  109. {
  110. union acpi_generic_state *state;
  111. ACPI_FUNCTION_TRACE("ut_pop_generic_state");
  112. /* Remove the state object at the head of the list (stack) */
  113. state = *list_head;
  114. if (state) {
  115. /* Update the list head */
  116. *list_head = state->common.next;
  117. }
  118. return_PTR(state);
  119. }
  120. /*******************************************************************************
  121. *
  122. * FUNCTION: acpi_ut_create_generic_state
  123. *
  124. * PARAMETERS: None
  125. *
  126. * RETURN: The new state object. NULL on failure.
  127. *
  128. * DESCRIPTION: Create a generic state object. Attempt to obtain one from
  129. * the global state cache; If none available, create a new one.
  130. *
  131. ******************************************************************************/
  132. union acpi_generic_state *acpi_ut_create_generic_state(void)
  133. {
  134. union acpi_generic_state *state;
  135. ACPI_FUNCTION_ENTRY();
  136. state = acpi_os_acquire_object(acpi_gbl_state_cache);
  137. if (state) {
  138. /* Initialize */
  139. memset(state, 0, sizeof(union acpi_generic_state));
  140. state->common.data_type = ACPI_DESC_TYPE_STATE;
  141. }
  142. return (state);
  143. }
  144. /*******************************************************************************
  145. *
  146. * FUNCTION: acpi_ut_create_thread_state
  147. *
  148. * PARAMETERS: None
  149. *
  150. * RETURN: New Thread State. NULL on failure
  151. *
  152. * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
  153. * to track per-thread info during method execution
  154. *
  155. ******************************************************************************/
  156. struct acpi_thread_state *acpi_ut_create_thread_state(void)
  157. {
  158. union acpi_generic_state *state;
  159. ACPI_FUNCTION_TRACE("ut_create_thread_state");
  160. /* Create the generic state object */
  161. state = acpi_ut_create_generic_state();
  162. if (!state) {
  163. return_PTR(NULL);
  164. }
  165. /* Init fields specific to the update struct */
  166. state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD;
  167. state->thread.thread_id = acpi_os_get_thread_id();
  168. return_PTR((struct acpi_thread_state *)state);
  169. }
  170. /*******************************************************************************
  171. *
  172. * FUNCTION: acpi_ut_create_update_state
  173. *
  174. * PARAMETERS: Object - Initial Object to be installed in the state
  175. * Action - Update action to be performed
  176. *
  177. * RETURN: New state object, null on failure
  178. *
  179. * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
  180. * to update reference counts and delete complex objects such
  181. * as packages.
  182. *
  183. ******************************************************************************/
  184. union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
  185. *object, u16 action)
  186. {
  187. union acpi_generic_state *state;
  188. ACPI_FUNCTION_TRACE_PTR("ut_create_update_state", object);
  189. /* Create the generic state object */
  190. state = acpi_ut_create_generic_state();
  191. if (!state) {
  192. return_PTR(NULL);
  193. }
  194. /* Init fields specific to the update struct */
  195. state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE;
  196. state->update.object = object;
  197. state->update.value = action;
  198. return_PTR(state);
  199. }
  200. /*******************************************************************************
  201. *
  202. * FUNCTION: acpi_ut_create_pkg_state
  203. *
  204. * PARAMETERS: Object - Initial Object to be installed in the state
  205. * Action - Update action to be performed
  206. *
  207. * RETURN: New state object, null on failure
  208. *
  209. * DESCRIPTION: Create a "Package State"
  210. *
  211. ******************************************************************************/
  212. union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
  213. void *external_object,
  214. u16 index)
  215. {
  216. union acpi_generic_state *state;
  217. ACPI_FUNCTION_TRACE_PTR("ut_create_pkg_state", internal_object);
  218. /* Create the generic state object */
  219. state = acpi_ut_create_generic_state();
  220. if (!state) {
  221. return_PTR(NULL);
  222. }
  223. /* Init fields specific to the update struct */
  224. state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE;
  225. state->pkg.source_object = (union acpi_operand_object *)internal_object;
  226. state->pkg.dest_object = external_object;
  227. state->pkg.index = index;
  228. state->pkg.num_packages = 1;
  229. return_PTR(state);
  230. }
  231. /*******************************************************************************
  232. *
  233. * FUNCTION: acpi_ut_create_control_state
  234. *
  235. * PARAMETERS: None
  236. *
  237. * RETURN: New state object, null on failure
  238. *
  239. * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
  240. * to support nested IF/WHILE constructs in the AML.
  241. *
  242. ******************************************************************************/
  243. union acpi_generic_state *acpi_ut_create_control_state(void)
  244. {
  245. union acpi_generic_state *state;
  246. ACPI_FUNCTION_TRACE("ut_create_control_state");
  247. /* Create the generic state object */
  248. state = acpi_ut_create_generic_state();
  249. if (!state) {
  250. return_PTR(NULL);
  251. }
  252. /* Init fields specific to the control struct */
  253. state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL;
  254. state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
  255. return_PTR(state);
  256. }
  257. /*******************************************************************************
  258. *
  259. * FUNCTION: acpi_ut_delete_generic_state
  260. *
  261. * PARAMETERS: State - The state object to be deleted
  262. *
  263. * RETURN: None
  264. *
  265. * DESCRIPTION: Put a state object back into the global state cache. The object
  266. * is not actually freed at this time.
  267. *
  268. ******************************************************************************/
  269. void acpi_ut_delete_generic_state(union acpi_generic_state *state)
  270. {
  271. ACPI_FUNCTION_TRACE("ut_delete_generic_state");
  272. (void)acpi_os_release_object(acpi_gbl_state_cache, state);
  273. return_VOID;
  274. }