utstate.c 10 KB

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