]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/evmisc.c
ACPICA: Lint fixes for acpi_write, no functional changes
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / evmisc.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: evmisc - Miscellaneous event manager support functions
4 *
5 *****************************************************************************/
6
7/*
77848130 8 * Copyright (C) 2000 - 2012, 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 50ACPI_MODULE_NAME("evmisc")
1da177e4 51
44f6c012 52/* Local prototypes */
4be44fcd 53static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context);
44f6c012 54
1da177e4
LT
55/*******************************************************************************
56 *
57 * FUNCTION: acpi_ev_is_notify_object
58 *
59 * PARAMETERS: Node - Node to check
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 69u8 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 *
89 * PARAMETERS: Node - NS node for the notified object
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 99acpi_status
4be44fcd
LB
100acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
101 u32 notify_value)
1da177e4 102{
4be44fcd
LB
103 union acpi_operand_object *obj_desc;
104 union acpi_operand_object *handler_obj = NULL;
105 union acpi_generic_state *notify_info;
106 acpi_status status = AE_OK;
1da177e4 107
b229cf92 108 ACPI_FUNCTION_NAME(ev_queue_notify_request);
1da177e4
LT
109
110 /*
ea143604
BM
111 * For value 0x03 (Ejection Request), may need to run a device method.
112 * For value 0x02 (Device Wake), if _PRW exists, may need to run
113 * the _PS0 method.
1da177e4 114 * For value 0x80 (Status Change) on the power button or sleep button,
ea143604
BM
115 * initiate soft-off or sleep operation.
116 *
117 * For all cases, simply dispatch the notify to the handler.
1da177e4 118 */
4be44fcd 119 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
ea143604
BM
120 "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n",
121 acpi_ut_get_node_name(node),
122 acpi_ut_get_type_name(node->type), notify_value,
123 acpi_ut_get_notify_name(notify_value), node));
1da177e4
LT
124
125 /* Get the notify object attached to the NS Node */
126
4be44fcd 127 obj_desc = acpi_ns_get_attached_object(node);
1da177e4 128 if (obj_desc) {
52fc0b02 129
ea143604 130 /* We have the notify object, Get the correct handler */
1da177e4
LT
131
132 switch (node->type) {
514d18d7 133
ea143604 134 /* Notify is allowed only on these types */
514d18d7 135
1da177e4
LT
136 case ACPI_TYPE_DEVICE:
137 case ACPI_TYPE_THERMAL:
138 case ACPI_TYPE_PROCESSOR:
1da177e4
LT
139
140 if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
4be44fcd
LB
141 handler_obj =
142 obj_desc->common_notify.system_notify;
143 } else {
144 handler_obj =
145 obj_desc->common_notify.device_notify;
1da177e4
LT
146 }
147 break;
148
149 default:
9f15fc66 150
1da177e4 151 /* All other types are not supported */
9f15fc66 152
1da177e4
LT
153 return (AE_TYPE);
154 }
155 }
156
514d18d7 157 /*
ea143604 158 * If there is a handler to run, schedule the dispatcher.
514d18d7
ZR
159 * Check for:
160 * 1) Global system notify handler
161 * 2) Global device notify handler
162 * 3) Per-device notify handler
163 */
d4913dc6
BM
164 if ((acpi_gbl_system_notify.handler &&
165 (notify_value <= ACPI_MAX_SYS_NOTIFY)) ||
166 (acpi_gbl_device_notify.handler &&
167 (notify_value > ACPI_MAX_SYS_NOTIFY)) || handler_obj) {
4be44fcd 168 notify_info = acpi_ut_create_generic_state();
1da177e4
LT
169 if (!notify_info) {
170 return (AE_NO_MEMORY);
171 }
172
514d18d7
ZR
173 if (!handler_obj) {
174 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
d4913dc6
BM
175 "Executing system notify handler for Notify (%4.4s, %X) "
176 "node %p\n",
514d18d7
ZR
177 acpi_ut_get_node_name(node),
178 notify_value, node));
179 }
180
61686124
BM
181 notify_info->common.descriptor_type =
182 ACPI_DESC_TYPE_STATE_NOTIFY;
4be44fcd
LB
183 notify_info->notify.node = node;
184 notify_info->notify.value = (u16) notify_value;
1da177e4
LT
185 notify_info->notify.handler_obj = handler_obj;
186
40d07080
LB
187 status =
188 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch,
189 notify_info);
190 if (ACPI_FAILURE(status)) {
191 acpi_ut_delete_generic_state(notify_info);
192 }
514d18d7 193 } else {
9f15fc66
BM
194 /* There is no notify handler (per-device or system) for this device */
195
4be44fcd 196 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
514d18d7 197 "No notify handler for Notify (%4.4s, %X) node %p\n",
4be44fcd
LB
198 acpi_ut_get_node_name(node), notify_value,
199 node));
1da177e4
LT
200 }
201
202 return (status);
203}
204
1da177e4
LT
205/*******************************************************************************
206 *
207 * FUNCTION: acpi_ev_notify_dispatch
208 *
44f6c012 209 * PARAMETERS: Context - To be passed to the notify handler
1da177e4
LT
210 *
211 * RETURN: None.
212 *
213 * DESCRIPTION: Dispatch a device notification event to a previously
214 * installed handler.
215 *
216 ******************************************************************************/
217
4be44fcd 218static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
1da177e4 219{
4be44fcd
LB
220 union acpi_generic_state *notify_info =
221 (union acpi_generic_state *)context;
222 acpi_notify_handler global_handler = NULL;
223 void *global_context = NULL;
224 union acpi_operand_object *handler_obj;
1da177e4 225
4be44fcd 226 ACPI_FUNCTION_ENTRY();
1da177e4
LT
227
228 /*
9f15fc66
BM
229 * We will invoke a global notify handler if installed. This is done
230 * _before_ we invoke the per-device handler attached to the device.
1da177e4
LT
231 */
232 if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) {
52fc0b02 233
1da177e4
LT
234 /* Global system notification handler */
235
236 if (acpi_gbl_system_notify.handler) {
237 global_handler = acpi_gbl_system_notify.handler;
238 global_context = acpi_gbl_system_notify.context;
239 }
4be44fcd 240 } else {
1da177e4
LT
241 /* Global driver notification handler */
242
243 if (acpi_gbl_device_notify.handler) {
244 global_handler = acpi_gbl_device_notify.handler;
245 global_context = acpi_gbl_device_notify.context;
246 }
247 }
248
249 /* Invoke the system handler first, if present */
250
251 if (global_handler) {
4be44fcd
LB
252 global_handler(notify_info->notify.node,
253 notify_info->notify.value, global_context);
1da177e4
LT
254 }
255
256 /* Now invoke the per-device handler, if present */
257
258 handler_obj = notify_info->notify.handler_obj;
259 if (handler_obj) {
3f0be671
RW
260 struct acpi_object_notify_handler *notifier;
261
262 notifier = &handler_obj->notify;
263 while (notifier) {
264 notifier->handler(notify_info->notify.node,
265 notify_info->notify.value,
266 notifier->context);
267 notifier = notifier->next;
268 }
1da177e4
LT
269 }
270
271 /* All done with the info object */
272
4be44fcd 273 acpi_ut_delete_generic_state(notify_info);
1da177e4
LT
274}
275
33620c54 276#if (!ACPI_REDUCED_HARDWARE)
1da177e4
LT
277/******************************************************************************
278 *
279 * FUNCTION: acpi_ev_terminate
280 *
281 * PARAMETERS: none
282 *
283 * RETURN: none
284 *
285 * DESCRIPTION: Disable events and free memory allocated for table storage.
286 *
287 ******************************************************************************/
288
4be44fcd 289void acpi_ev_terminate(void)
1da177e4 290{
67a119f9 291 u32 i;
4be44fcd 292 acpi_status status;
1da177e4 293
b229cf92 294 ACPI_FUNCTION_TRACE(ev_terminate);
1da177e4
LT
295
296 if (acpi_gbl_events_initialized) {
297 /*
9f15fc66
BM
298 * Disable all event-related functionality. In all cases, on error,
299 * print a message but obviously we don't abort.
1da177e4
LT
300 */
301
302 /* Disable all fixed events */
303
304 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
67a119f9 305 status = acpi_disable_event(i, 0);
4be44fcd 306 if (ACPI_FAILURE(status)) {
b8e4d893 307 ACPI_ERROR((AE_INFO,
f6a22b0b 308 "Could not disable fixed event %u",
b8e4d893 309 (u32) i));
1da177e4
LT
310 }
311 }
312
313 /* Disable all GPEs in all GPE blocks */
314
e97d6bf1 315 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
1da177e4
LT
316
317 /* Remove SCI handler */
318
4be44fcd 319 status = acpi_ev_remove_sci_handler();
1da177e4 320 if (ACPI_FAILURE(status)) {
b8e4d893 321 ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
1da177e4 322 }
8876016b
BM
323
324 status = acpi_ev_remove_global_lock_handler();
325 if (ACPI_FAILURE(status)) {
326 ACPI_ERROR((AE_INFO,
327 "Could not remove Global Lock handler"));
328 }
1da177e4
LT
329 }
330
331 /* Deallocate all handler objects installed within GPE info structs */
332
e97d6bf1 333 status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL);
1da177e4
LT
334
335 /* Return to original mode if necessary */
336
337 if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) {
4be44fcd
LB
338 status = acpi_disable();
339 if (ACPI_FAILURE(status)) {
b229cf92 340 ACPI_WARNING((AE_INFO, "AcpiDisable failed"));
1da177e4
LT
341 }
342 }
343 return_VOID;
344}
33620c54
BM
345
346#endif /* !ACPI_REDUCED_HARDWARE */