exsystem.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /******************************************************************************
  2. *
  3. * Module Name: exsystem - Interface to OS services
  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. #include <acpi/acinterp.h>
  44. #include <acpi/acevents.h>
  45. #define _COMPONENT ACPI_EXECUTER
  46. ACPI_MODULE_NAME("exsystem")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ex_system_wait_semaphore
  50. *
  51. * PARAMETERS: Semaphore - Semaphore to wait on
  52. * Timeout - Max time to wait
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Implements a semaphore wait with a check to see if the
  57. * semaphore is available immediately. If it is not, the
  58. * interpreter is released.
  59. *
  60. ******************************************************************************/
  61. acpi_status acpi_ex_system_wait_semaphore(acpi_handle semaphore, u16 timeout)
  62. {
  63. acpi_status status;
  64. acpi_status status2;
  65. ACPI_FUNCTION_TRACE("ex_system_wait_semaphore");
  66. status = acpi_os_wait_semaphore(semaphore, 1, 0);
  67. if (ACPI_SUCCESS(status)) {
  68. return_ACPI_STATUS(status);
  69. }
  70. if (status == AE_TIME) {
  71. /* We must wait, so unlock the interpreter */
  72. acpi_ex_exit_interpreter();
  73. status = acpi_os_wait_semaphore(semaphore, 1, timeout);
  74. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  75. "*** Thread awake after blocking, %s\n",
  76. acpi_format_exception(status)));
  77. /* Reacquire the interpreter */
  78. status2 = acpi_ex_enter_interpreter();
  79. if (ACPI_FAILURE(status2)) {
  80. /* Report fatal error, could not acquire interpreter */
  81. return_ACPI_STATUS(status2);
  82. }
  83. }
  84. return_ACPI_STATUS(status);
  85. }
  86. /*******************************************************************************
  87. *
  88. * FUNCTION: acpi_ex_system_do_stall
  89. *
  90. * PARAMETERS: how_long - The amount of time to stall,
  91. * in microseconds
  92. *
  93. * RETURN: Status
  94. *
  95. * DESCRIPTION: Suspend running thread for specified amount of time.
  96. * Note: ACPI specification requires that Stall() does not
  97. * relinquish the processor, and delays longer than 100 usec
  98. * should use Sleep() instead. We allow stalls up to 255 usec
  99. * for compatibility with other interpreters and existing BIOSs.
  100. *
  101. ******************************************************************************/
  102. acpi_status acpi_ex_system_do_stall(u32 how_long)
  103. {
  104. acpi_status status = AE_OK;
  105. ACPI_FUNCTION_ENTRY();
  106. if (how_long > 255) { /* 255 microseconds */
  107. /*
  108. * Longer than 255 usec, this is an error
  109. *
  110. * (ACPI specifies 100 usec as max, but this gives some slack in
  111. * order to support existing BIOSs)
  112. */
  113. ACPI_REPORT_ERROR(("Stall: Time parameter is too large (%d)\n",
  114. how_long));
  115. status = AE_AML_OPERAND_VALUE;
  116. } else {
  117. acpi_os_stall(how_long);
  118. }
  119. return (status);
  120. }
  121. /*******************************************************************************
  122. *
  123. * FUNCTION: acpi_ex_system_do_suspend
  124. *
  125. * PARAMETERS: how_long - The amount of time to suspend,
  126. * in milliseconds
  127. *
  128. * RETURN: None
  129. *
  130. * DESCRIPTION: Suspend running thread for specified amount of time.
  131. *
  132. ******************************************************************************/
  133. acpi_status acpi_ex_system_do_suspend(acpi_integer how_long)
  134. {
  135. acpi_status status;
  136. ACPI_FUNCTION_ENTRY();
  137. /* Since this thread will sleep, we must release the interpreter */
  138. acpi_ex_exit_interpreter();
  139. acpi_os_sleep(how_long);
  140. /* And now we must get the interpreter again */
  141. status = acpi_ex_enter_interpreter();
  142. return (status);
  143. }
  144. /*******************************************************************************
  145. *
  146. * FUNCTION: acpi_ex_system_acquire_mutex
  147. *
  148. * PARAMETERS: time_desc - The 'time to delay' object descriptor
  149. * obj_desc - The object descriptor for this op
  150. *
  151. * RETURN: Status
  152. *
  153. * DESCRIPTION: Provides an access point to perform synchronization operations
  154. * within the AML. This function will cause a lock to be generated
  155. * for the Mutex pointed to by obj_desc.
  156. *
  157. ******************************************************************************/
  158. acpi_status
  159. acpi_ex_system_acquire_mutex(union acpi_operand_object * time_desc,
  160. union acpi_operand_object * obj_desc)
  161. {
  162. acpi_status status = AE_OK;
  163. ACPI_FUNCTION_TRACE_PTR("ex_system_acquire_mutex", obj_desc);
  164. if (!obj_desc) {
  165. return_ACPI_STATUS(AE_BAD_PARAMETER);
  166. }
  167. /* Support for the _GL_ Mutex object -- go get the global lock */
  168. if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
  169. status =
  170. acpi_ev_acquire_global_lock((u16) time_desc->integer.value);
  171. return_ACPI_STATUS(status);
  172. }
  173. status = acpi_ex_system_wait_semaphore(obj_desc->mutex.semaphore,
  174. (u16) time_desc->integer.value);
  175. return_ACPI_STATUS(status);
  176. }
  177. /*******************************************************************************
  178. *
  179. * FUNCTION: acpi_ex_system_release_mutex
  180. *
  181. * PARAMETERS: obj_desc - The object descriptor for this op
  182. *
  183. * RETURN: Status
  184. *
  185. * DESCRIPTION: Provides an access point to perform synchronization operations
  186. * within the AML. This operation is a request to release a
  187. * previously acquired Mutex. If the Mutex variable is set then
  188. * it will be decremented.
  189. *
  190. ******************************************************************************/
  191. acpi_status acpi_ex_system_release_mutex(union acpi_operand_object *obj_desc)
  192. {
  193. acpi_status status = AE_OK;
  194. ACPI_FUNCTION_TRACE("ex_system_release_mutex");
  195. if (!obj_desc) {
  196. return_ACPI_STATUS(AE_BAD_PARAMETER);
  197. }
  198. /* Support for the _GL_ Mutex object -- release the global lock */
  199. if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
  200. status = acpi_ev_release_global_lock();
  201. return_ACPI_STATUS(status);
  202. }
  203. status = acpi_os_signal_semaphore(obj_desc->mutex.semaphore, 1);
  204. return_ACPI_STATUS(status);
  205. }
  206. /*******************************************************************************
  207. *
  208. * FUNCTION: acpi_ex_system_signal_event
  209. *
  210. * PARAMETERS: obj_desc - The object descriptor for this op
  211. *
  212. * RETURN: Status
  213. *
  214. * DESCRIPTION: Provides an access point to perform synchronization operations
  215. * within the AML.
  216. *
  217. ******************************************************************************/
  218. acpi_status acpi_ex_system_signal_event(union acpi_operand_object *obj_desc)
  219. {
  220. acpi_status status = AE_OK;
  221. ACPI_FUNCTION_TRACE("ex_system_signal_event");
  222. if (obj_desc) {
  223. status = acpi_os_signal_semaphore(obj_desc->event.semaphore, 1);
  224. }
  225. return_ACPI_STATUS(status);
  226. }
  227. /*******************************************************************************
  228. *
  229. * FUNCTION: acpi_ex_system_wait_event
  230. *
  231. * PARAMETERS: time_desc - The 'time to delay' object descriptor
  232. * obj_desc - The object descriptor for this op
  233. *
  234. * RETURN: Status
  235. *
  236. * DESCRIPTION: Provides an access point to perform synchronization operations
  237. * within the AML. This operation is a request to wait for an
  238. * event.
  239. *
  240. ******************************************************************************/
  241. acpi_status
  242. acpi_ex_system_wait_event(union acpi_operand_object *time_desc,
  243. union acpi_operand_object *obj_desc)
  244. {
  245. acpi_status status = AE_OK;
  246. ACPI_FUNCTION_TRACE("ex_system_wait_event");
  247. if (obj_desc) {
  248. status =
  249. acpi_ex_system_wait_semaphore(obj_desc->event.semaphore,
  250. (u16) time_desc->integer.
  251. value);
  252. }
  253. return_ACPI_STATUS(status);
  254. }
  255. /*******************************************************************************
  256. *
  257. * FUNCTION: acpi_ex_system_reset_event
  258. *
  259. * PARAMETERS: obj_desc - The object descriptor for this op
  260. *
  261. * RETURN: Status
  262. *
  263. * DESCRIPTION: Reset an event to a known state.
  264. *
  265. ******************************************************************************/
  266. acpi_status acpi_ex_system_reset_event(union acpi_operand_object *obj_desc)
  267. {
  268. acpi_status status = AE_OK;
  269. void *temp_semaphore;
  270. ACPI_FUNCTION_ENTRY();
  271. /*
  272. * We are going to simply delete the existing semaphore and
  273. * create a new one!
  274. */
  275. status =
  276. acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore);
  277. if (ACPI_SUCCESS(status)) {
  278. (void)acpi_os_delete_semaphore(obj_desc->event.semaphore);
  279. obj_desc->event.semaphore = temp_semaphore;
  280. }
  281. return (status);
  282. }