utstate.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*******************************************************************************
  2. *
  3. * Module Name: utstate - state object support procedures
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, 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. #define _COMPONENT ACPI_UTILITIES
  45. ACPI_MODULE_NAME("utstate")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_ut_create_pkg_state_and_push
  49. *
  50. * PARAMETERS: Object - Object to be added to the new state
  51. * Action - Increment/Decrement
  52. * state_list - List the state will be added to
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Create a new state and push it
  57. *
  58. ******************************************************************************/
  59. acpi_status
  60. acpi_ut_create_pkg_state_and_push(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 =
  68. acpi_ut_create_pkg_state(internal_object, external_object, index);
  69. if (!state) {
  70. return (AE_NO_MEMORY);
  71. }
  72. acpi_ut_push_generic_state(state_list, state);
  73. return (AE_OK);
  74. }
  75. /*******************************************************************************
  76. *
  77. * FUNCTION: acpi_ut_push_generic_state
  78. *
  79. * PARAMETERS: list_head - Head of the state stack
  80. * State - State object to push
  81. *
  82. * RETURN: None
  83. *
  84. * DESCRIPTION: Push a state object onto a state stack
  85. *
  86. ******************************************************************************/
  87. void
  88. acpi_ut_push_generic_state(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 *acpi_ut_pop_generic_state(union acpi_generic_state
  109. **list_head)
  110. {
  111. union acpi_generic_state *state;
  112. ACPI_FUNCTION_TRACE(ut_pop_generic_state);
  113. /* Remove the state object at the head of the list (stack) */
  114. state = *list_head;
  115. if (state) {
  116. /* Update the list head */
  117. *list_head = state->common.next;
  118. }
  119. return_PTR(state);
  120. }
  121. /*******************************************************************************
  122. *
  123. * FUNCTION: acpi_ut_create_generic_state
  124. *
  125. * PARAMETERS: None
  126. *
  127. * RETURN: The new state object. NULL on failure.
  128. *
  129. * DESCRIPTION: Create a generic state object. Attempt to obtain one from
  130. * the global state cache; If none available, create a new one.
  131. *
  132. ******************************************************************************/
  133. union acpi_generic_state *acpi_ut_create_generic_state(void)
  134. {
  135. union acpi_generic_state *state;
  136. ACPI_FUNCTION_ENTRY();
  137. state = acpi_os_acquire_object(acpi_gbl_state_cache);
  138. if (state) {
  139. /* Initialize */
  140. memset(state, 0, sizeof(union acpi_generic_state));
  141. state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
  142. }
  143. return (state);
  144. }
  145. /*******************************************************************************
  146. *
  147. * FUNCTION: acpi_ut_create_thread_state
  148. *
  149. * PARAMETERS: None
  150. *
  151. * RETURN: New Thread State. NULL on failure
  152. *
  153. * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
  154. * to track per-thread info during method execution
  155. *
  156. ******************************************************************************/
  157. struct acpi_thread_state *acpi_ut_create_thread_state(void)
  158. {
  159. union acpi_generic_state *state;
  160. ACPI_FUNCTION_TRACE(ut_create_thread_state);
  161. /* Create the generic state object */
  162. state = acpi_ut_create_generic_state();
  163. if (!state) {
  164. return_PTR(NULL);
  165. }
  166. /* Init fields specific to the update struct */
  167. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
  168. state->thread.thread_id = acpi_os_get_thread_id();
  169. /* Check for invalid thread ID - zero is very bad, it will break things */
  170. if (!state->thread.thread_id) {
  171. ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
  172. state->thread.thread_id = (acpi_thread_id) 1;
  173. }
  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 *acpi_ut_create_update_state(union acpi_operand_object
  191. *object, u16 action)
  192. {
  193. union acpi_generic_state *state;
  194. ACPI_FUNCTION_TRACE_PTR(ut_create_update_state, object);
  195. /* Create the generic state object */
  196. state = acpi_ut_create_generic_state();
  197. if (!state) {
  198. return_PTR(NULL);
  199. }
  200. /* Init fields specific to the update struct */
  201. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
  202. state->update.object = object;
  203. state->update.value = action;
  204. return_PTR(state);
  205. }
  206. /*******************************************************************************
  207. *
  208. * FUNCTION: acpi_ut_create_pkg_state
  209. *
  210. * PARAMETERS: Object - Initial Object to be installed in the state
  211. * Action - Update action to be performed
  212. *
  213. * RETURN: New state object, null on failure
  214. *
  215. * DESCRIPTION: Create a "Package State"
  216. *
  217. ******************************************************************************/
  218. union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
  219. void *external_object,
  220. u16 index)
  221. {
  222. union acpi_generic_state *state;
  223. ACPI_FUNCTION_TRACE_PTR(ut_create_pkg_state, internal_object);
  224. /* Create the generic state object */
  225. state = acpi_ut_create_generic_state();
  226. if (!state) {
  227. return_PTR(NULL);
  228. }
  229. /* Init fields specific to the update struct */
  230. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
  231. state->pkg.source_object = (union acpi_operand_object *)internal_object;
  232. state->pkg.dest_object = external_object;
  233. state->pkg.index = index;
  234. state->pkg.num_packages = 1;
  235. return_PTR(state);
  236. }
  237. /*******************************************************************************
  238. *
  239. * FUNCTION: acpi_ut_create_control_state
  240. *
  241. * PARAMETERS: None
  242. *
  243. * RETURN: New state object, null on failure
  244. *
  245. * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
  246. * to support nested IF/WHILE constructs in the AML.
  247. *
  248. ******************************************************************************/
  249. union acpi_generic_state *acpi_ut_create_control_state(void)
  250. {
  251. union acpi_generic_state *state;
  252. ACPI_FUNCTION_TRACE(ut_create_control_state);
  253. /* Create the generic state object */
  254. state = acpi_ut_create_generic_state();
  255. if (!state) {
  256. return_PTR(NULL);
  257. }
  258. /* Init fields specific to the control struct */
  259. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
  260. state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
  261. return_PTR(state);
  262. }
  263. /*******************************************************************************
  264. *
  265. * FUNCTION: acpi_ut_delete_generic_state
  266. *
  267. * PARAMETERS: State - The state object to be deleted
  268. *
  269. * RETURN: None
  270. *
  271. * DESCRIPTION: Release a state object to the state cache. NULL state objects
  272. * are ignored.
  273. *
  274. ******************************************************************************/
  275. void acpi_ut_delete_generic_state(union acpi_generic_state *state)
  276. {
  277. ACPI_FUNCTION_TRACE(ut_delete_generic_state);
  278. /* Ignore null state */
  279. if (state) {
  280. (void)acpi_os_release_object(acpi_gbl_state_cache, state);
  281. }
  282. return_VOID;
  283. }