evmisc.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /******************************************************************************
  2. *
  3. * Module Name: evmisc - Miscellaneous event manager support functions
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, 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. #include "acevents.h"
  45. #include "acnamesp.h"
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evmisc")
  48. /* Local prototypes */
  49. static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context);
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_ev_is_notify_object
  53. *
  54. * PARAMETERS: Node - Node to check
  55. *
  56. * RETURN: TRUE if notifies allowed on this object
  57. *
  58. * DESCRIPTION: Check type of node for a object that supports notifies.
  59. *
  60. * TBD: This could be replaced by a flag bit in the node.
  61. *
  62. ******************************************************************************/
  63. u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node)
  64. {
  65. switch (node->type) {
  66. case ACPI_TYPE_DEVICE:
  67. case ACPI_TYPE_PROCESSOR:
  68. case ACPI_TYPE_THERMAL:
  69. /*
  70. * These are the ONLY objects that can receive ACPI notifications
  71. */
  72. return (TRUE);
  73. default:
  74. return (FALSE);
  75. }
  76. }
  77. /*******************************************************************************
  78. *
  79. * FUNCTION: acpi_ev_queue_notify_request
  80. *
  81. * PARAMETERS: Node - NS node for the notified object
  82. * notify_value - Value from the Notify() request
  83. *
  84. * RETURN: Status
  85. *
  86. * DESCRIPTION: Dispatch a device notification event to a previously
  87. * installed handler.
  88. *
  89. ******************************************************************************/
  90. acpi_status
  91. acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
  92. u32 notify_value)
  93. {
  94. union acpi_operand_object *obj_desc;
  95. union acpi_operand_object *handler_obj = NULL;
  96. union acpi_generic_state *notify_info;
  97. acpi_status status = AE_OK;
  98. ACPI_FUNCTION_NAME(ev_queue_notify_request);
  99. /*
  100. * For value 3 (Ejection Request), some device method may need to be run.
  101. * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need
  102. * to be run.
  103. * For value 0x80 (Status Change) on the power button or sleep button,
  104. * initiate soft-off or sleep operation?
  105. */
  106. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  107. "Dispatching Notify on [%4.4s] Node %p Value 0x%2.2X (%s)\n",
  108. acpi_ut_get_node_name(node), node, notify_value,
  109. acpi_ut_get_notify_name(notify_value)));
  110. /* Get the notify object attached to the NS Node */
  111. obj_desc = acpi_ns_get_attached_object(node);
  112. if (obj_desc) {
  113. /* We have the notify object, Get the right handler */
  114. switch (node->type) {
  115. /* Notify allowed only on these types */
  116. case ACPI_TYPE_DEVICE:
  117. case ACPI_TYPE_THERMAL:
  118. case ACPI_TYPE_PROCESSOR:
  119. if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
  120. handler_obj =
  121. obj_desc->common_notify.system_notify;
  122. } else {
  123. handler_obj =
  124. obj_desc->common_notify.device_notify;
  125. }
  126. break;
  127. default:
  128. /* All other types are not supported */
  129. return (AE_TYPE);
  130. }
  131. }
  132. /*
  133. * If there is any handler to run, schedule the dispatcher.
  134. * Check for:
  135. * 1) Global system notify handler
  136. * 2) Global device notify handler
  137. * 3) Per-device notify handler
  138. */
  139. if ((acpi_gbl_system_notify.handler &&
  140. (notify_value <= ACPI_MAX_SYS_NOTIFY)) ||
  141. (acpi_gbl_device_notify.handler &&
  142. (notify_value > ACPI_MAX_SYS_NOTIFY)) || handler_obj) {
  143. notify_info = acpi_ut_create_generic_state();
  144. if (!notify_info) {
  145. return (AE_NO_MEMORY);
  146. }
  147. if (!handler_obj) {
  148. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  149. "Executing system notify handler for Notify (%4.4s, %X) "
  150. "node %p\n",
  151. acpi_ut_get_node_name(node),
  152. notify_value, node));
  153. }
  154. notify_info->common.descriptor_type =
  155. ACPI_DESC_TYPE_STATE_NOTIFY;
  156. notify_info->notify.node = node;
  157. notify_info->notify.value = (u16) notify_value;
  158. notify_info->notify.handler_obj = handler_obj;
  159. status =
  160. acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch,
  161. notify_info);
  162. if (ACPI_FAILURE(status)) {
  163. acpi_ut_delete_generic_state(notify_info);
  164. }
  165. } else {
  166. /* There is no notify handler (per-device or system) for this device */
  167. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  168. "No notify handler for Notify (%4.4s, %X) node %p\n",
  169. acpi_ut_get_node_name(node), notify_value,
  170. node));
  171. }
  172. return (status);
  173. }
  174. /*******************************************************************************
  175. *
  176. * FUNCTION: acpi_ev_notify_dispatch
  177. *
  178. * PARAMETERS: Context - To be passed to the notify handler
  179. *
  180. * RETURN: None.
  181. *
  182. * DESCRIPTION: Dispatch a device notification event to a previously
  183. * installed handler.
  184. *
  185. ******************************************************************************/
  186. static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
  187. {
  188. union acpi_generic_state *notify_info =
  189. (union acpi_generic_state *)context;
  190. acpi_notify_handler global_handler = NULL;
  191. void *global_context = NULL;
  192. union acpi_operand_object *handler_obj;
  193. ACPI_FUNCTION_ENTRY();
  194. /*
  195. * We will invoke a global notify handler if installed. This is done
  196. * _before_ we invoke the per-device handler attached to the device.
  197. */
  198. if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) {
  199. /* Global system notification handler */
  200. if (acpi_gbl_system_notify.handler) {
  201. global_handler = acpi_gbl_system_notify.handler;
  202. global_context = acpi_gbl_system_notify.context;
  203. }
  204. } else {
  205. /* Global driver notification handler */
  206. if (acpi_gbl_device_notify.handler) {
  207. global_handler = acpi_gbl_device_notify.handler;
  208. global_context = acpi_gbl_device_notify.context;
  209. }
  210. }
  211. /* Invoke the system handler first, if present */
  212. if (global_handler) {
  213. global_handler(notify_info->notify.node,
  214. notify_info->notify.value, global_context);
  215. }
  216. /* Now invoke the per-device handler, if present */
  217. handler_obj = notify_info->notify.handler_obj;
  218. if (handler_obj) {
  219. struct acpi_object_notify_handler *notifier;
  220. notifier = &handler_obj->notify;
  221. while (notifier) {
  222. notifier->handler(notify_info->notify.node,
  223. notify_info->notify.value,
  224. notifier->context);
  225. notifier = notifier->next;
  226. }
  227. }
  228. /* All done with the info object */
  229. acpi_ut_delete_generic_state(notify_info);
  230. }
  231. /******************************************************************************
  232. *
  233. * FUNCTION: acpi_ev_terminate
  234. *
  235. * PARAMETERS: none
  236. *
  237. * RETURN: none
  238. *
  239. * DESCRIPTION: Disable events and free memory allocated for table storage.
  240. *
  241. ******************************************************************************/
  242. void acpi_ev_terminate(void)
  243. {
  244. u32 i;
  245. acpi_status status;
  246. ACPI_FUNCTION_TRACE(ev_terminate);
  247. if (acpi_gbl_events_initialized) {
  248. /*
  249. * Disable all event-related functionality. In all cases, on error,
  250. * print a message but obviously we don't abort.
  251. */
  252. /* Disable all fixed events */
  253. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
  254. status = acpi_disable_event(i, 0);
  255. if (ACPI_FAILURE(status)) {
  256. ACPI_ERROR((AE_INFO,
  257. "Could not disable fixed event %u",
  258. (u32) i));
  259. }
  260. }
  261. /* Disable all GPEs in all GPE blocks */
  262. status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
  263. /* Remove SCI handler */
  264. status = acpi_ev_remove_sci_handler();
  265. if (ACPI_FAILURE(status)) {
  266. ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
  267. }
  268. status = acpi_ev_remove_global_lock_handler();
  269. if (ACPI_FAILURE(status)) {
  270. ACPI_ERROR((AE_INFO,
  271. "Could not remove Global Lock handler"));
  272. }
  273. }
  274. /* Deallocate all handler objects installed within GPE info structs */
  275. status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL);
  276. /* Return to original mode if necessary */
  277. if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) {
  278. status = acpi_disable();
  279. if (ACPI_FAILURE(status)) {
  280. ACPI_WARNING((AE_INFO, "AcpiDisable failed"));
  281. }
  282. }
  283. return_VOID;
  284. }