Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: evmisc - Miscellaneous event manager support functions | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
25f044e6 | 8 | * Copyright (C) 2000 - 2013, Intel Corp. |
1da177e4 LT |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
44 | #include <acpi/acpi.h> | |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acevents.h" | |
47 | #include "acnamesp.h" | |
1da177e4 LT |
48 | |
49 | #define _COMPONENT ACPI_EVENTS | |
4be44fcd | 50 | ACPI_MODULE_NAME("evmisc") |
1da177e4 | 51 | |
44f6c012 | 52 | /* Local prototypes */ |
4be44fcd | 53 | static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context); |
44f6c012 | 54 | |
1da177e4 LT |
55 | /******************************************************************************* |
56 | * | |
57 | * FUNCTION: acpi_ev_is_notify_object | |
58 | * | |
ba494bee | 59 | * PARAMETERS: node - Node to check |
1da177e4 LT |
60 | * |
61 | * RETURN: TRUE if notifies allowed on this object | |
62 | * | |
63 | * DESCRIPTION: Check type of node for a object that supports notifies. | |
64 | * | |
65 | * TBD: This could be replaced by a flag bit in the node. | |
66 | * | |
67 | ******************************************************************************/ | |
68 | ||
4be44fcd | 69 | u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node) |
1da177e4 LT |
70 | { |
71 | switch (node->type) { | |
72 | case ACPI_TYPE_DEVICE: | |
73 | case ACPI_TYPE_PROCESSOR: | |
1da177e4 LT |
74 | case ACPI_TYPE_THERMAL: |
75 | /* | |
76 | * These are the ONLY objects that can receive ACPI notifications | |
77 | */ | |
78 | return (TRUE); | |
79 | ||
80 | default: | |
81 | return (FALSE); | |
82 | } | |
83 | } | |
84 | ||
1da177e4 LT |
85 | /******************************************************************************* |
86 | * | |
87 | * FUNCTION: acpi_ev_queue_notify_request | |
88 | * | |
ba494bee | 89 | * PARAMETERS: node - NS node for the notified object |
1da177e4 LT |
90 | * notify_value - Value from the Notify() request |
91 | * | |
92 | * RETURN: Status | |
93 | * | |
94 | * DESCRIPTION: Dispatch a device notification event to a previously | |
95 | * installed handler. | |
96 | * | |
97 | ******************************************************************************/ | |
98 | ||
1da177e4 | 99 | acpi_status |
4be44fcd LB |
100 | acpi_ev_queue_notify_request(struct acpi_namespace_node * node, |
101 | u32 notify_value) | |
1da177e4 | 102 | { |
4be44fcd | 103 | union acpi_operand_object *obj_desc; |
86ed4bc8 BM |
104 | union acpi_operand_object *handler_list_head = NULL; |
105 | union acpi_generic_state *info; | |
106 | u8 handler_list_id = 0; | |
4be44fcd | 107 | acpi_status status = AE_OK; |
1da177e4 | 108 | |
b229cf92 | 109 | ACPI_FUNCTION_NAME(ev_queue_notify_request); |
1da177e4 | 110 | |
86ed4bc8 | 111 | /* Are Notifies allowed on this object? */ |
52fc0b02 | 112 | |
86ed4bc8 BM |
113 | if (!acpi_ev_is_notify_object(node)) { |
114 | return (AE_TYPE); | |
115 | } | |
514d18d7 | 116 | |
86ed4bc8 | 117 | /* Get the correct notify list type (System or Device) */ |
514d18d7 | 118 | |
86ed4bc8 BM |
119 | if (notify_value <= ACPI_MAX_SYS_NOTIFY) { |
120 | handler_list_id = ACPI_SYSTEM_HANDLER_LIST; | |
121 | } else { | |
122 | handler_list_id = ACPI_DEVICE_HANDLER_LIST; | |
123 | } | |
1da177e4 | 124 | |
86ed4bc8 | 125 | /* Get the notify object attached to the namespace Node */ |
1da177e4 | 126 | |
86ed4bc8 BM |
127 | obj_desc = acpi_ns_get_attached_object(node); |
128 | if (obj_desc) { | |
9f15fc66 | 129 | |
86ed4bc8 | 130 | /* We have an attached object, Get the correct handler list */ |
9f15fc66 | 131 | |
86ed4bc8 BM |
132 | handler_list_head = |
133 | obj_desc->common_notify.notify_list[handler_list_id]; | |
1da177e4 LT |
134 | } |
135 | ||
514d18d7 | 136 | /* |
86ed4bc8 BM |
137 | * If there is no notify handler (Global or Local) |
138 | * for this object, just ignore the notify | |
514d18d7 | 139 | */ |
86ed4bc8 BM |
140 | if (!acpi_gbl_global_notify[handler_list_id].handler |
141 | && !handler_list_head) { | |
4be44fcd | 142 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
86ed4bc8 | 143 | "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n", |
4be44fcd LB |
144 | acpi_ut_get_node_name(node), notify_value, |
145 | node)); | |
86ed4bc8 BM |
146 | |
147 | return (AE_OK); | |
148 | } | |
149 | ||
150 | /* Setup notify info and schedule the notify dispatcher */ | |
151 | ||
152 | info = acpi_ut_create_generic_state(); | |
153 | if (!info) { | |
154 | return (AE_NO_MEMORY); | |
155 | } | |
156 | ||
157 | info->common.descriptor_type = ACPI_DESC_TYPE_STATE_NOTIFY; | |
158 | ||
159 | info->notify.node = node; | |
160 | info->notify.value = (u16)notify_value; | |
161 | info->notify.handler_list_id = handler_list_id; | |
162 | info->notify.handler_list_head = handler_list_head; | |
163 | info->notify.global = &acpi_gbl_global_notify[handler_list_id]; | |
164 | ||
165 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
166 | "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n", | |
167 | acpi_ut_get_node_name(node), | |
168 | acpi_ut_get_type_name(node->type), notify_value, | |
169 | acpi_ut_get_notify_name(notify_value), node)); | |
170 | ||
171 | status = acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch, | |
172 | info); | |
173 | if (ACPI_FAILURE(status)) { | |
174 | acpi_ut_delete_generic_state(info); | |
1da177e4 LT |
175 | } |
176 | ||
177 | return (status); | |
178 | } | |
179 | ||
1da177e4 LT |
180 | /******************************************************************************* |
181 | * | |
182 | * FUNCTION: acpi_ev_notify_dispatch | |
183 | * | |
ba494bee | 184 | * PARAMETERS: context - To be passed to the notify handler |
1da177e4 LT |
185 | * |
186 | * RETURN: None. | |
187 | * | |
188 | * DESCRIPTION: Dispatch a device notification event to a previously | |
189 | * installed handler. | |
190 | * | |
191 | ******************************************************************************/ | |
192 | ||
4be44fcd | 193 | static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context) |
1da177e4 | 194 | { |
86ed4bc8 | 195 | union acpi_generic_state *info = (union acpi_generic_state *)context; |
4be44fcd | 196 | union acpi_operand_object *handler_obj; |
1da177e4 | 197 | |
4be44fcd | 198 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 199 | |
86ed4bc8 | 200 | /* Invoke a global notify handler if installed */ |
1da177e4 | 201 | |
86ed4bc8 BM |
202 | if (info->notify.global->handler) { |
203 | info->notify.global->handler(info->notify.node, | |
204 | info->notify.value, | |
205 | info->notify.global->context); | |
1da177e4 LT |
206 | } |
207 | ||
86ed4bc8 | 208 | /* Now invoke the local notify handler(s) if any are installed */ |
1da177e4 | 209 | |
86ed4bc8 BM |
210 | handler_obj = info->notify.handler_list_head; |
211 | while (handler_obj) { | |
212 | handler_obj->notify.handler(info->notify.node, | |
213 | info->notify.value, | |
214 | handler_obj->notify.context); | |
3f0be671 | 215 | |
86ed4bc8 BM |
216 | handler_obj = |
217 | handler_obj->notify.next[info->notify.handler_list_id]; | |
1da177e4 LT |
218 | } |
219 | ||
220 | /* All done with the info object */ | |
221 | ||
86ed4bc8 | 222 | acpi_ut_delete_generic_state(info); |
1da177e4 LT |
223 | } |
224 | ||
33620c54 | 225 | #if (!ACPI_REDUCED_HARDWARE) |
1da177e4 LT |
226 | /****************************************************************************** |
227 | * | |
228 | * FUNCTION: acpi_ev_terminate | |
229 | * | |
230 | * PARAMETERS: none | |
231 | * | |
232 | * RETURN: none | |
233 | * | |
234 | * DESCRIPTION: Disable events and free memory allocated for table storage. | |
235 | * | |
236 | ******************************************************************************/ | |
237 | ||
4be44fcd | 238 | void acpi_ev_terminate(void) |
1da177e4 | 239 | { |
67a119f9 | 240 | u32 i; |
4be44fcd | 241 | acpi_status status; |
1da177e4 | 242 | |
b229cf92 | 243 | ACPI_FUNCTION_TRACE(ev_terminate); |
1da177e4 LT |
244 | |
245 | if (acpi_gbl_events_initialized) { | |
246 | /* | |
9f15fc66 BM |
247 | * Disable all event-related functionality. In all cases, on error, |
248 | * print a message but obviously we don't abort. | |
1da177e4 LT |
249 | */ |
250 | ||
251 | /* Disable all fixed events */ | |
252 | ||
253 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { | |
67a119f9 | 254 | status = acpi_disable_event(i, 0); |
4be44fcd | 255 | if (ACPI_FAILURE(status)) { |
b8e4d893 | 256 | ACPI_ERROR((AE_INFO, |
f6a22b0b | 257 | "Could not disable fixed event %u", |
b8e4d893 | 258 | (u32) i)); |
1da177e4 LT |
259 | } |
260 | } | |
261 | ||
262 | /* Disable all GPEs in all GPE blocks */ | |
263 | ||
e97d6bf1 | 264 | status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL); |
1da177e4 LT |
265 | |
266 | /* Remove SCI handler */ | |
267 | ||
4be44fcd | 268 | status = acpi_ev_remove_sci_handler(); |
1da177e4 | 269 | if (ACPI_FAILURE(status)) { |
b8e4d893 | 270 | ACPI_ERROR((AE_INFO, "Could not remove SCI handler")); |
1da177e4 | 271 | } |
8876016b BM |
272 | |
273 | status = acpi_ev_remove_global_lock_handler(); | |
274 | if (ACPI_FAILURE(status)) { | |
275 | ACPI_ERROR((AE_INFO, | |
276 | "Could not remove Global Lock handler")); | |
277 | } | |
1da177e4 LT |
278 | } |
279 | ||
280 | /* Deallocate all handler objects installed within GPE info structs */ | |
281 | ||
e97d6bf1 | 282 | status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL); |
1da177e4 LT |
283 | |
284 | /* Return to original mode if necessary */ | |
285 | ||
286 | if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) { | |
4be44fcd LB |
287 | status = acpi_disable(); |
288 | if (ACPI_FAILURE(status)) { | |
b229cf92 | 289 | ACPI_WARNING((AE_INFO, "AcpiDisable failed")); |
1da177e4 LT |
290 | } |
291 | } | |
292 | return_VOID; | |
293 | } | |
33620c54 BM |
294 | |
295 | #endif /* !ACPI_REDUCED_HARDWARE */ |