utstate.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*******************************************************************************
  2. *
  3. * Module Name: utstate - state object support procedures
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, 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. #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.descriptor_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.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
  167. state->thread.thread_id = acpi_os_get_thread_id();
  168. /* Check for invalid thread ID - zero is very bad, it will break things */
  169. if (!state->thread.thread_id) {
  170. ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
  171. state->thread.thread_id = (acpi_thread_id) 1;
  172. }
  173. return_PTR((struct acpi_thread_state *)state);
  174. }
  175. /*******************************************************************************
  176. *
  177. * FUNCTION: acpi_ut_create_update_state
  178. *
  179. * PARAMETERS: Object - Initial Object to be installed in the state
  180. * Action - Update action to be performed
  181. *
  182. * RETURN: New state object, null on failure
  183. *
  184. * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
  185. * to update reference counts and delete complex objects such
  186. * as packages.
  187. *
  188. ******************************************************************************/
  189. union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
  190. *object, u16 action)
  191. {
  192. union acpi_generic_state *state;
  193. ACPI_FUNCTION_TRACE_PTR(ut_create_update_state, object);
  194. /* Create the generic state object */
  195. state = acpi_ut_create_generic_state();
  196. if (!state) {
  197. return_PTR(NULL);
  198. }
  199. /* Init fields specific to the update struct */
  200. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
  201. state->update.object = object;
  202. state->update.value = action;
  203. return_PTR(state);
  204. }
  205. /*******************************************************************************
  206. *
  207. * FUNCTION: acpi_ut_create_pkg_state
  208. *
  209. * PARAMETERS: Object - Initial Object to be installed in the state
  210. * Action - Update action to be performed
  211. *
  212. * RETURN: New state object, null on failure
  213. *
  214. * DESCRIPTION: Create a "Package State"
  215. *
  216. ******************************************************************************/
  217. union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
  218. void *external_object,
  219. u16 index)
  220. {
  221. union acpi_generic_state *state;
  222. ACPI_FUNCTION_TRACE_PTR(ut_create_pkg_state, internal_object);
  223. /* Create the generic state object */
  224. state = acpi_ut_create_generic_state();
  225. if (!state) {
  226. return_PTR(NULL);
  227. }
  228. /* Init fields specific to the update struct */
  229. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
  230. state->pkg.source_object = (union acpi_operand_object *)internal_object;
  231. state->pkg.dest_object = external_object;
  232. state->pkg.index = index;
  233. state->pkg.num_packages = 1;
  234. return_PTR(state);
  235. }
  236. /*******************************************************************************
  237. *
  238. * FUNCTION: acpi_ut_create_control_state
  239. *
  240. * PARAMETERS: None
  241. *
  242. * RETURN: New state object, null on failure
  243. *
  244. * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
  245. * to support nested IF/WHILE constructs in the AML.
  246. *
  247. ******************************************************************************/
  248. union acpi_generic_state *acpi_ut_create_control_state(void)
  249. {
  250. union acpi_generic_state *state;
  251. ACPI_FUNCTION_TRACE(ut_create_control_state);
  252. /* Create the generic state object */
  253. state = acpi_ut_create_generic_state();
  254. if (!state) {
  255. return_PTR(NULL);
  256. }
  257. /* Init fields specific to the control struct */
  258. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
  259. state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
  260. return_PTR(state);
  261. }
  262. /*******************************************************************************
  263. *
  264. * FUNCTION: acpi_ut_delete_generic_state
  265. *
  266. * PARAMETERS: State - The state object to be deleted
  267. *
  268. * RETURN: None
  269. *
  270. * DESCRIPTION: Release a state object to the state cache. NULL state objects
  271. * are ignored.
  272. *
  273. ******************************************************************************/
  274. void acpi_ut_delete_generic_state(union acpi_generic_state *state)
  275. {
  276. ACPI_FUNCTION_TRACE(ut_delete_generic_state);
  277. /* Ignore null state */
  278. if (state) {
  279. (void)acpi_os_release_object(acpi_gbl_state_cache, state);
  280. }
  281. return_VOID;
  282. }