exsystem.c 8.9 KB

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