utstate.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*******************************************************************************
  2. *
  3. * Module Name: utstate - state object support procedures
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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_push_generic_state
  49. *
  50. * PARAMETERS: list_head - Head of the state stack
  51. * state - State object to push
  52. *
  53. * RETURN: None
  54. *
  55. * DESCRIPTION: Push a state object onto a state stack
  56. *
  57. ******************************************************************************/
  58. void
  59. acpi_ut_push_generic_state(union acpi_generic_state **list_head,
  60. union acpi_generic_state *state)
  61. {
  62. ACPI_FUNCTION_ENTRY();
  63. /* Push the state object onto the front of the list (stack) */
  64. state->common.next = *list_head;
  65. *list_head = state;
  66. return;
  67. }
  68. /*******************************************************************************
  69. *
  70. * FUNCTION: acpi_ut_pop_generic_state
  71. *
  72. * PARAMETERS: list_head - Head of the state stack
  73. *
  74. * RETURN: The popped state object
  75. *
  76. * DESCRIPTION: Pop a state object from a state stack
  77. *
  78. ******************************************************************************/
  79. union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
  80. **list_head)
  81. {
  82. union acpi_generic_state *state;
  83. ACPI_FUNCTION_ENTRY();
  84. /* Remove the state object at the head of the list (stack) */
  85. state = *list_head;
  86. if (state) {
  87. /* Update the list head */
  88. *list_head = state->common.next;
  89. }
  90. return (state);
  91. }
  92. /*******************************************************************************
  93. *
  94. * FUNCTION: acpi_ut_create_generic_state
  95. *
  96. * PARAMETERS: None
  97. *
  98. * RETURN: The new state object. NULL on failure.
  99. *
  100. * DESCRIPTION: Create a generic state object. Attempt to obtain one from
  101. * the global state cache; If none available, create a new one.
  102. *
  103. ******************************************************************************/
  104. union acpi_generic_state *acpi_ut_create_generic_state(void)
  105. {
  106. union acpi_generic_state *state;
  107. ACPI_FUNCTION_ENTRY();
  108. state = acpi_os_acquire_object(acpi_gbl_state_cache);
  109. if (state) {
  110. /* Initialize */
  111. state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
  112. }
  113. return (state);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_ut_create_thread_state
  118. *
  119. * PARAMETERS: None
  120. *
  121. * RETURN: New Thread State. NULL on failure
  122. *
  123. * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
  124. * to track per-thread info during method execution
  125. *
  126. ******************************************************************************/
  127. struct acpi_thread_state *acpi_ut_create_thread_state(void)
  128. {
  129. union acpi_generic_state *state;
  130. ACPI_FUNCTION_ENTRY();
  131. /* Create the generic state object */
  132. state = acpi_ut_create_generic_state();
  133. if (!state) {
  134. return (NULL);
  135. }
  136. /* Init fields specific to the update struct */
  137. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
  138. state->thread.thread_id = acpi_os_get_thread_id();
  139. /* Check for invalid thread ID - zero is very bad, it will break things */
  140. if (!state->thread.thread_id) {
  141. ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
  142. state->thread.thread_id = (acpi_thread_id) 1;
  143. }
  144. return ((struct acpi_thread_state *)state);
  145. }
  146. /*******************************************************************************
  147. *
  148. * FUNCTION: acpi_ut_create_update_state
  149. *
  150. * PARAMETERS: object - Initial Object to be installed in the state
  151. * action - Update action to be performed
  152. *
  153. * RETURN: New state object, null on failure
  154. *
  155. * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
  156. * to update reference counts and delete complex objects such
  157. * as packages.
  158. *
  159. ******************************************************************************/
  160. union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
  161. *object, u16 action)
  162. {
  163. union acpi_generic_state *state;
  164. ACPI_FUNCTION_ENTRY();
  165. /* Create the generic state object */
  166. state = acpi_ut_create_generic_state();
  167. if (!state) {
  168. return (NULL);
  169. }
  170. /* Init fields specific to the update struct */
  171. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
  172. state->update.object = object;
  173. state->update.value = action;
  174. return (state);
  175. }
  176. /*******************************************************************************
  177. *
  178. * FUNCTION: acpi_ut_create_pkg_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 a "Package State"
  186. *
  187. ******************************************************************************/
  188. union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
  189. void *external_object,
  190. u16 index)
  191. {
  192. union acpi_generic_state *state;
  193. ACPI_FUNCTION_ENTRY();
  194. /* Create the generic state object */
  195. state = acpi_ut_create_generic_state();
  196. if (!state) {
  197. return (NULL);
  198. }
  199. /* Init fields specific to the update struct */
  200. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
  201. state->pkg.source_object = (union acpi_operand_object *)internal_object;
  202. state->pkg.dest_object = external_object;
  203. state->pkg.index = index;
  204. state->pkg.num_packages = 1;
  205. return (state);
  206. }
  207. /*******************************************************************************
  208. *
  209. * FUNCTION: acpi_ut_create_control_state
  210. *
  211. * PARAMETERS: None
  212. *
  213. * RETURN: New state object, null on failure
  214. *
  215. * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
  216. * to support nested IF/WHILE constructs in the AML.
  217. *
  218. ******************************************************************************/
  219. union acpi_generic_state *acpi_ut_create_control_state(void)
  220. {
  221. union acpi_generic_state *state;
  222. ACPI_FUNCTION_ENTRY();
  223. /* Create the generic state object */
  224. state = acpi_ut_create_generic_state();
  225. if (!state) {
  226. return (NULL);
  227. }
  228. /* Init fields specific to the control struct */
  229. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
  230. state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
  231. return (state);
  232. }
  233. /*******************************************************************************
  234. *
  235. * FUNCTION: acpi_ut_delete_generic_state
  236. *
  237. * PARAMETERS: state - The state object to be deleted
  238. *
  239. * RETURN: None
  240. *
  241. * DESCRIPTION: Release a state object to the state cache. NULL state objects
  242. * are ignored.
  243. *
  244. ******************************************************************************/
  245. void acpi_ut_delete_generic_state(union acpi_generic_state *state)
  246. {
  247. ACPI_FUNCTION_ENTRY();
  248. /* Ignore null state */
  249. if (state) {
  250. (void)acpi_os_release_object(acpi_gbl_state_cache, state);
  251. }
  252. return;
  253. }