]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: evmisc - Miscellaneous event manager support functions | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
c8100dc4 | 8 | * Copyright (C) 2000 - 2016, 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 | 70 | { |
1fad8738 | 71 | |
1da177e4 LT |
72 | switch (node->type) { |
73 | case ACPI_TYPE_DEVICE: | |
74 | case ACPI_TYPE_PROCESSOR: | |
1da177e4 LT |
75 | case ACPI_TYPE_THERMAL: |
76 | /* | |
77 | * These are the ONLY objects that can receive ACPI notifications | |
78 | */ | |
79 | return (TRUE); | |
80 | ||
81 | default: | |
1d1ea1b7 | 82 | |
1da177e4 LT |
83 | return (FALSE); |
84 | } | |
85 | } | |
86 | ||
1da177e4 LT |
87 | /******************************************************************************* |
88 | * | |
89 | * FUNCTION: acpi_ev_queue_notify_request | |
90 | * | |
ba494bee | 91 | * PARAMETERS: node - NS node for the notified object |
1da177e4 LT |
92 | * notify_value - Value from the Notify() request |
93 | * | |
94 | * RETURN: Status | |
95 | * | |
96 | * DESCRIPTION: Dispatch a device notification event to a previously | |
97 | * installed handler. | |
98 | * | |
99 | ******************************************************************************/ | |
100 | ||
1da177e4 | 101 | acpi_status |
4be44fcd LB |
102 | acpi_ev_queue_notify_request(struct acpi_namespace_node * node, |
103 | u32 notify_value) | |
1da177e4 | 104 | { |
4be44fcd | 105 | union acpi_operand_object *obj_desc; |
86ed4bc8 BM |
106 | union acpi_operand_object *handler_list_head = NULL; |
107 | union acpi_generic_state *info; | |
108 | u8 handler_list_id = 0; | |
4be44fcd | 109 | acpi_status status = AE_OK; |
1da177e4 | 110 | |
b229cf92 | 111 | ACPI_FUNCTION_NAME(ev_queue_notify_request); |
1da177e4 | 112 | |
86ed4bc8 | 113 | /* Are Notifies allowed on this object? */ |
52fc0b02 | 114 | |
86ed4bc8 BM |
115 | if (!acpi_ev_is_notify_object(node)) { |
116 | return (AE_TYPE); | |
117 | } | |
514d18d7 | 118 | |
86ed4bc8 | 119 | /* Get the correct notify list type (System or Device) */ |
514d18d7 | 120 | |
86ed4bc8 BM |
121 | if (notify_value <= ACPI_MAX_SYS_NOTIFY) { |
122 | handler_list_id = ACPI_SYSTEM_HANDLER_LIST; | |
123 | } else { | |
124 | handler_list_id = ACPI_DEVICE_HANDLER_LIST; | |
125 | } | |
1da177e4 | 126 | |
86ed4bc8 | 127 | /* Get the notify object attached to the namespace Node */ |
1da177e4 | 128 | |
86ed4bc8 BM |
129 | obj_desc = acpi_ns_get_attached_object(node); |
130 | if (obj_desc) { | |
9f15fc66 | 131 | |
86ed4bc8 | 132 | /* We have an attached object, Get the correct handler list */ |
9f15fc66 | 133 | |
86ed4bc8 BM |
134 | handler_list_head = |
135 | obj_desc->common_notify.notify_list[handler_list_id]; | |
1da177e4 LT |
136 | } |
137 | ||
514d18d7 | 138 | /* |
86ed4bc8 BM |
139 | * If there is no notify handler (Global or Local) |
140 | * for this object, just ignore the notify | |
514d18d7 | 141 | */ |
86ed4bc8 BM |
142 | if (!acpi_gbl_global_notify[handler_list_id].handler |
143 | && !handler_list_head) { | |
4be44fcd | 144 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
86ed4bc8 | 145 | "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n", |
4be44fcd LB |
146 | acpi_ut_get_node_name(node), notify_value, |
147 | node)); | |
86ed4bc8 BM |
148 | |
149 | return (AE_OK); | |
150 | } | |
151 | ||
152 | /* Setup notify info and schedule the notify dispatcher */ | |
153 | ||
154 | info = acpi_ut_create_generic_state(); | |
155 | if (!info) { | |
156 | return (AE_NO_MEMORY); | |
157 | } | |
158 | ||
159 | info->common.descriptor_type = ACPI_DESC_TYPE_STATE_NOTIFY; | |
160 | ||
161 | info->notify.node = node; | |
162 | info->notify.value = (u16)notify_value; | |
163 | info->notify.handler_list_id = handler_list_id; | |
164 | info->notify.handler_list_head = handler_list_head; | |
165 | info->notify.global = &acpi_gbl_global_notify[handler_list_id]; | |
166 | ||
167 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
168 | "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n", | |
169 | acpi_ut_get_node_name(node), | |
170 | acpi_ut_get_type_name(node->type), notify_value, | |
06a63e33 BM |
171 | acpi_ut_get_notify_name(notify_value, ACPI_TYPE_ANY), |
172 | node)); | |
86ed4bc8 | 173 | |
1fad8738 BM |
174 | status = acpi_os_execute(OSL_NOTIFY_HANDLER, |
175 | acpi_ev_notify_dispatch, info); | |
86ed4bc8 BM |
176 | if (ACPI_FAILURE(status)) { |
177 | acpi_ut_delete_generic_state(info); | |
1da177e4 LT |
178 | } |
179 | ||
180 | return (status); | |
181 | } | |
182 | ||
1da177e4 LT |
183 | /******************************************************************************* |
184 | * | |
185 | * FUNCTION: acpi_ev_notify_dispatch | |
186 | * | |
ba494bee | 187 | * PARAMETERS: context - To be passed to the notify handler |
1da177e4 LT |
188 | * |
189 | * RETURN: None. | |
190 | * | |
191 | * DESCRIPTION: Dispatch a device notification event to a previously | |
192 | * installed handler. | |
193 | * | |
194 | ******************************************************************************/ | |
195 | ||
4be44fcd | 196 | static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context) |
1da177e4 | 197 | { |
86ed4bc8 | 198 | union acpi_generic_state *info = (union acpi_generic_state *)context; |
4be44fcd | 199 | union acpi_operand_object *handler_obj; |
1da177e4 | 200 | |
4be44fcd | 201 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 202 | |
86ed4bc8 | 203 | /* Invoke a global notify handler if installed */ |
1da177e4 | 204 | |
86ed4bc8 BM |
205 | if (info->notify.global->handler) { |
206 | info->notify.global->handler(info->notify.node, | |
207 | info->notify.value, | |
208 | info->notify.global->context); | |
1da177e4 LT |
209 | } |
210 | ||
86ed4bc8 | 211 | /* Now invoke the local notify handler(s) if any are installed */ |
1da177e4 | 212 | |
86ed4bc8 BM |
213 | handler_obj = info->notify.handler_list_head; |
214 | while (handler_obj) { | |
215 | handler_obj->notify.handler(info->notify.node, | |
216 | info->notify.value, | |
217 | handler_obj->notify.context); | |
3f0be671 | 218 | |
86ed4bc8 BM |
219 | handler_obj = |
220 | handler_obj->notify.next[info->notify.handler_list_id]; | |
1da177e4 LT |
221 | } |
222 | ||
223 | /* All done with the info object */ | |
224 | ||
86ed4bc8 | 225 | acpi_ut_delete_generic_state(info); |
1da177e4 LT |
226 | } |
227 | ||
33620c54 | 228 | #if (!ACPI_REDUCED_HARDWARE) |
1da177e4 LT |
229 | /****************************************************************************** |
230 | * | |
231 | * FUNCTION: acpi_ev_terminate | |
232 | * | |
233 | * PARAMETERS: none | |
234 | * | |
235 | * RETURN: none | |
236 | * | |
237 | * DESCRIPTION: Disable events and free memory allocated for table storage. | |
238 | * | |
239 | ******************************************************************************/ | |
240 | ||
4be44fcd | 241 | void acpi_ev_terminate(void) |
1da177e4 | 242 | { |
67a119f9 | 243 | u32 i; |
4be44fcd | 244 | acpi_status status; |
1da177e4 | 245 | |
b229cf92 | 246 | ACPI_FUNCTION_TRACE(ev_terminate); |
1da177e4 LT |
247 | |
248 | if (acpi_gbl_events_initialized) { | |
249 | /* | |
9f15fc66 BM |
250 | * Disable all event-related functionality. In all cases, on error, |
251 | * print a message but obviously we don't abort. | |
1da177e4 LT |
252 | */ |
253 | ||
254 | /* Disable all fixed events */ | |
255 | ||
256 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { | |
67a119f9 | 257 | status = acpi_disable_event(i, 0); |
4be44fcd | 258 | if (ACPI_FAILURE(status)) { |
b8e4d893 | 259 | ACPI_ERROR((AE_INFO, |
f6a22b0b | 260 | "Could not disable fixed event %u", |
b8e4d893 | 261 | (u32) i)); |
1da177e4 LT |
262 | } |
263 | } | |
264 | ||
265 | /* Disable all GPEs in all GPE blocks */ | |
266 | ||
e97d6bf1 | 267 | status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL); |
1da177e4 | 268 | |
8876016b BM |
269 | status = acpi_ev_remove_global_lock_handler(); |
270 | if (ACPI_FAILURE(status)) { | |
271 | ACPI_ERROR((AE_INFO, | |
272 | "Could not remove Global Lock handler")); | |
273 | } | |
64f3af5f TN |
274 | |
275 | acpi_gbl_events_initialized = FALSE; | |
1da177e4 LT |
276 | } |
277 | ||
a2fd4b4b LZ |
278 | /* Remove SCI handlers */ |
279 | ||
280 | status = acpi_ev_remove_all_sci_handlers(); | |
281 | if (ACPI_FAILURE(status)) { | |
282 | ACPI_ERROR((AE_INFO, "Could not remove SCI handler")); | |
283 | } | |
284 | ||
1da177e4 LT |
285 | /* Deallocate all handler objects installed within GPE info structs */ |
286 | ||
e97d6bf1 | 287 | status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL); |
1da177e4 LT |
288 | |
289 | /* Return to original mode if necessary */ | |
290 | ||
291 | if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) { | |
4be44fcd LB |
292 | status = acpi_disable(); |
293 | if (ACPI_FAILURE(status)) { | |
b229cf92 | 294 | ACPI_WARNING((AE_INFO, "AcpiDisable failed")); |
1da177e4 LT |
295 | } |
296 | } | |
297 | return_VOID; | |
298 | } | |
33620c54 BM |
299 | |
300 | #endif /* !ACPI_REDUCED_HARDWARE */ |