exsystem.c 11 KB

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