evmisc.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /******************************************************************************
  2. *
  3. * Module Name: evmisc - Miscellaneous event manager support functions
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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_list_head = NULL;
  96. union acpi_generic_state *info;
  97. u8 handler_list_id = 0;
  98. acpi_status status = AE_OK;
  99. ACPI_FUNCTION_NAME(ev_queue_notify_request);
  100. /* Are Notifies allowed on this object? */
  101. if (!acpi_ev_is_notify_object(node)) {
  102. return (AE_TYPE);
  103. }
  104. /* Get the correct notify list type (System or Device) */
  105. if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
  106. handler_list_id = ACPI_SYSTEM_HANDLER_LIST;
  107. } else {
  108. handler_list_id = ACPI_DEVICE_HANDLER_LIST;
  109. }
  110. /* Get the notify object attached to the namespace Node */
  111. obj_desc = acpi_ns_get_attached_object(node);
  112. if (obj_desc) {
  113. /* We have an attached object, Get the correct handler list */
  114. handler_list_head =
  115. obj_desc->common_notify.notify_list[handler_list_id];
  116. }
  117. /*
  118. * If there is no notify handler (Global or Local)
  119. * for this object, just ignore the notify
  120. */
  121. if (!acpi_gbl_global_notify[handler_list_id].handler
  122. && !handler_list_head) {
  123. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  124. "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n",
  125. acpi_ut_get_node_name(node), notify_value,
  126. node));
  127. return (AE_OK);
  128. }
  129. /* Setup notify info and schedule the notify dispatcher */
  130. info = acpi_ut_create_generic_state();
  131. if (!info) {
  132. return (AE_NO_MEMORY);
  133. }
  134. info->common.descriptor_type = ACPI_DESC_TYPE_STATE_NOTIFY;
  135. info->notify.node = node;
  136. info->notify.value = (u16)notify_value;
  137. info->notify.handler_list_id = handler_list_id;
  138. info->notify.handler_list_head = handler_list_head;
  139. info->notify.global = &acpi_gbl_global_notify[handler_list_id];
  140. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  141. "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n",
  142. acpi_ut_get_node_name(node),
  143. acpi_ut_get_type_name(node->type), notify_value,
  144. acpi_ut_get_notify_name(notify_value, ACPI_TYPE_ANY),
  145. node));
  146. status = acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch,
  147. info);
  148. if (ACPI_FAILURE(status)) {
  149. acpi_ut_delete_generic_state(info);
  150. }
  151. return (status);
  152. }
  153. /*******************************************************************************
  154. *
  155. * FUNCTION: acpi_ev_notify_dispatch
  156. *
  157. * PARAMETERS: context - To be passed to the notify handler
  158. *
  159. * RETURN: None.
  160. *
  161. * DESCRIPTION: Dispatch a device notification event to a previously
  162. * installed handler.
  163. *
  164. ******************************************************************************/
  165. static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
  166. {
  167. union acpi_generic_state *info = (union acpi_generic_state *)context;
  168. union acpi_operand_object *handler_obj;
  169. ACPI_FUNCTION_ENTRY();
  170. /* Invoke a global notify handler if installed */
  171. if (info->notify.global->handler) {
  172. info->notify.global->handler(info->notify.node,
  173. info->notify.value,
  174. info->notify.global->context);
  175. }
  176. /* Now invoke the local notify handler(s) if any are installed */
  177. handler_obj = info->notify.handler_list_head;
  178. while (handler_obj) {
  179. handler_obj->notify.handler(info->notify.node,
  180. info->notify.value,
  181. handler_obj->notify.context);
  182. handler_obj =
  183. handler_obj->notify.next[info->notify.handler_list_id];
  184. }
  185. /* All done with the info object */
  186. acpi_ut_delete_generic_state(info);
  187. }
  188. #if (!ACPI_REDUCED_HARDWARE)
  189. /******************************************************************************
  190. *
  191. * FUNCTION: acpi_ev_terminate
  192. *
  193. * PARAMETERS: none
  194. *
  195. * RETURN: none
  196. *
  197. * DESCRIPTION: Disable events and free memory allocated for table storage.
  198. *
  199. ******************************************************************************/
  200. void acpi_ev_terminate(void)
  201. {
  202. u32 i;
  203. acpi_status status;
  204. ACPI_FUNCTION_TRACE(ev_terminate);
  205. if (acpi_gbl_events_initialized) {
  206. /*
  207. * Disable all event-related functionality. In all cases, on error,
  208. * print a message but obviously we don't abort.
  209. */
  210. /* Disable all fixed events */
  211. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
  212. status = acpi_disable_event(i, 0);
  213. if (ACPI_FAILURE(status)) {
  214. ACPI_ERROR((AE_INFO,
  215. "Could not disable fixed event %u",
  216. (u32) i));
  217. }
  218. }
  219. /* Disable all GPEs in all GPE blocks */
  220. status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
  221. status = acpi_ev_remove_global_lock_handler();
  222. if (ACPI_FAILURE(status)) {
  223. ACPI_ERROR((AE_INFO,
  224. "Could not remove Global Lock handler"));
  225. }
  226. acpi_gbl_events_initialized = FALSE;
  227. }
  228. /* Remove SCI handlers */
  229. status = acpi_ev_remove_all_sci_handlers();
  230. if (ACPI_FAILURE(status)) {
  231. ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
  232. }
  233. /* Deallocate all handler objects installed within GPE info structs */
  234. status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL);
  235. /* Return to original mode if necessary */
  236. if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) {
  237. status = acpi_disable();
  238. if (ACPI_FAILURE(status)) {
  239. ACPI_WARNING((AE_INFO, "AcpiDisable failed"));
  240. }
  241. }
  242. return_VOID;
  243. }
  244. #endif /* !ACPI_REDUCED_HARDWARE */