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