evxface.c revision 1.6 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: evxface - External interfaces for ACPI events
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.4 jruoho /*
8 1.6 christos * Copyright (C) 2000 - 2014, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.4 jruoho * Redistribution and use in source and binary forms, with or without
12 1.4 jruoho * modification, are permitted provided that the following conditions
13 1.4 jruoho * are met:
14 1.4 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.4 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.4 jruoho * without modification.
17 1.4 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.4 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.4 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.4 jruoho * including a substantially similar Disclaimer requirement for further
21 1.4 jruoho * binary redistribution.
22 1.4 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.4 jruoho * of any contributors may be used to endorse or promote products derived
24 1.4 jruoho * from this software without specific prior written permission.
25 1.4 jruoho *
26 1.4 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.4 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.4 jruoho * Software Foundation.
29 1.4 jruoho *
30 1.4 jruoho * NO WARRANTY
31 1.4 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.4 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.4 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.4 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.4 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.4 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.4 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.4 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.4 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.4 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.4 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.4 jruoho */
43 1.1 jruoho
44 1.1 jruoho #define __EVXFACE_C__
45 1.5 christos #define EXPORT_ACPI_INTERFACES
46 1.1 jruoho
47 1.1 jruoho #include "acpi.h"
48 1.1 jruoho #include "accommon.h"
49 1.1 jruoho #include "acnamesp.h"
50 1.1 jruoho #include "acevents.h"
51 1.1 jruoho #include "acinterp.h"
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_EVENTS
54 1.1 jruoho ACPI_MODULE_NAME ("evxface")
55 1.1 jruoho
56 1.1 jruoho
57 1.1 jruoho /*******************************************************************************
58 1.1 jruoho *
59 1.5 christos * FUNCTION: AcpiInstallNotifyHandler
60 1.5 christos *
61 1.5 christos * PARAMETERS: Device - The device for which notifies will be handled
62 1.5 christos * HandlerType - The type of handler:
63 1.5 christos * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
64 1.5 christos * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
65 1.5 christos * ACPI_ALL_NOTIFY: Both System and Device
66 1.5 christos * Handler - Address of the handler
67 1.5 christos * Context - Value passed to the handler on each GPE
68 1.5 christos *
69 1.5 christos * RETURN: Status
70 1.5 christos *
71 1.5 christos * DESCRIPTION: Install a handler for notifications on an ACPI Device,
72 1.5 christos * ThermalZone, or Processor object.
73 1.5 christos *
74 1.5 christos * NOTES: The Root namespace object may have only one handler for each
75 1.5 christos * type of notify (System/Device). Device/Thermal/Processor objects
76 1.5 christos * may have one device notify handler, and multiple system notify
77 1.5 christos * handlers.
78 1.5 christos *
79 1.5 christos ******************************************************************************/
80 1.5 christos
81 1.5 christos ACPI_STATUS
82 1.5 christos AcpiInstallNotifyHandler (
83 1.5 christos ACPI_HANDLE Device,
84 1.5 christos UINT32 HandlerType,
85 1.5 christos ACPI_NOTIFY_HANDLER Handler,
86 1.5 christos void *Context)
87 1.5 christos {
88 1.5 christos ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
89 1.5 christos ACPI_OPERAND_OBJECT *ObjDesc;
90 1.5 christos ACPI_OPERAND_OBJECT *HandlerObj;
91 1.5 christos ACPI_STATUS Status;
92 1.5 christos UINT32 i;
93 1.5 christos
94 1.5 christos
95 1.5 christos ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler);
96 1.5 christos
97 1.5 christos
98 1.5 christos /* Parameter validation */
99 1.5 christos
100 1.5 christos if ((!Device) || (!Handler) || (!HandlerType) ||
101 1.5 christos (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
102 1.5 christos {
103 1.5 christos return_ACPI_STATUS (AE_BAD_PARAMETER);
104 1.5 christos }
105 1.5 christos
106 1.5 christos Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
107 1.5 christos if (ACPI_FAILURE (Status))
108 1.5 christos {
109 1.5 christos return_ACPI_STATUS (Status);
110 1.5 christos }
111 1.5 christos
112 1.5 christos /*
113 1.5 christos * Root Object:
114 1.5 christos * Registering a notify handler on the root object indicates that the
115 1.5 christos * caller wishes to receive notifications for all objects. Note that
116 1.5 christos * only one global handler can be registered per notify type.
117 1.5 christos * Ensure that a handler is not already installed.
118 1.5 christos */
119 1.5 christos if (Device == ACPI_ROOT_OBJECT)
120 1.5 christos {
121 1.5 christos for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
122 1.5 christos {
123 1.5 christos if (HandlerType & (i+1))
124 1.5 christos {
125 1.5 christos if (AcpiGbl_GlobalNotify[i].Handler)
126 1.5 christos {
127 1.5 christos Status = AE_ALREADY_EXISTS;
128 1.5 christos goto UnlockAndExit;
129 1.5 christos }
130 1.5 christos
131 1.5 christos AcpiGbl_GlobalNotify[i].Handler = Handler;
132 1.5 christos AcpiGbl_GlobalNotify[i].Context = Context;
133 1.5 christos }
134 1.5 christos }
135 1.5 christos
136 1.5 christos goto UnlockAndExit; /* Global notify handler installed, all done */
137 1.5 christos }
138 1.5 christos
139 1.5 christos /*
140 1.5 christos * All Other Objects:
141 1.5 christos * Caller will only receive notifications specific to the target
142 1.5 christos * object. Note that only certain object types are allowed to
143 1.5 christos * receive notifications.
144 1.5 christos */
145 1.5 christos
146 1.5 christos /* Are Notifies allowed on this object? */
147 1.5 christos
148 1.5 christos if (!AcpiEvIsNotifyObject (Node))
149 1.5 christos {
150 1.5 christos Status = AE_TYPE;
151 1.5 christos goto UnlockAndExit;
152 1.5 christos }
153 1.5 christos
154 1.5 christos /* Check for an existing internal object, might not exist */
155 1.5 christos
156 1.5 christos ObjDesc = AcpiNsGetAttachedObject (Node);
157 1.5 christos if (!ObjDesc)
158 1.5 christos {
159 1.5 christos /* Create a new object */
160 1.5 christos
161 1.5 christos ObjDesc = AcpiUtCreateInternalObject (Node->Type);
162 1.5 christos if (!ObjDesc)
163 1.5 christos {
164 1.5 christos Status = AE_NO_MEMORY;
165 1.5 christos goto UnlockAndExit;
166 1.5 christos }
167 1.5 christos
168 1.5 christos /* Attach new object to the Node, remove local reference */
169 1.5 christos
170 1.5 christos Status = AcpiNsAttachObject (Device, ObjDesc, Node->Type);
171 1.5 christos AcpiUtRemoveReference (ObjDesc);
172 1.5 christos if (ACPI_FAILURE (Status))
173 1.5 christos {
174 1.5 christos goto UnlockAndExit;
175 1.5 christos }
176 1.5 christos }
177 1.5 christos
178 1.5 christos /* Ensure that the handler is not already installed in the lists */
179 1.5 christos
180 1.5 christos for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
181 1.5 christos {
182 1.5 christos if (HandlerType & (i+1))
183 1.5 christos {
184 1.5 christos HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
185 1.5 christos while (HandlerObj)
186 1.5 christos {
187 1.5 christos if (HandlerObj->Notify.Handler == Handler)
188 1.5 christos {
189 1.5 christos Status = AE_ALREADY_EXISTS;
190 1.5 christos goto UnlockAndExit;
191 1.5 christos }
192 1.5 christos
193 1.5 christos HandlerObj = HandlerObj->Notify.Next[i];
194 1.5 christos }
195 1.5 christos }
196 1.5 christos }
197 1.5 christos
198 1.5 christos /* Create and populate a new notify handler object */
199 1.5 christos
200 1.5 christos HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY);
201 1.5 christos if (!HandlerObj)
202 1.5 christos {
203 1.5 christos Status = AE_NO_MEMORY;
204 1.5 christos goto UnlockAndExit;
205 1.5 christos }
206 1.5 christos
207 1.5 christos HandlerObj->Notify.Node = Node;
208 1.5 christos HandlerObj->Notify.HandlerType = HandlerType;
209 1.5 christos HandlerObj->Notify.Handler = Handler;
210 1.5 christos HandlerObj->Notify.Context = Context;
211 1.5 christos
212 1.5 christos /* Install the handler at the list head(s) */
213 1.5 christos
214 1.5 christos for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
215 1.5 christos {
216 1.5 christos if (HandlerType & (i+1))
217 1.5 christos {
218 1.5 christos HandlerObj->Notify.Next[i] =
219 1.5 christos ObjDesc->CommonNotify.NotifyList[i];
220 1.5 christos
221 1.5 christos ObjDesc->CommonNotify.NotifyList[i] = HandlerObj;
222 1.5 christos }
223 1.5 christos }
224 1.5 christos
225 1.5 christos /* Add an extra reference if handler was installed in both lists */
226 1.5 christos
227 1.5 christos if (HandlerType == ACPI_ALL_NOTIFY)
228 1.5 christos {
229 1.5 christos AcpiUtAddReference (HandlerObj);
230 1.5 christos }
231 1.5 christos
232 1.5 christos
233 1.5 christos UnlockAndExit:
234 1.5 christos (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
235 1.5 christos return_ACPI_STATUS (Status);
236 1.5 christos }
237 1.5 christos
238 1.5 christos ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler)
239 1.5 christos
240 1.5 christos
241 1.5 christos /*******************************************************************************
242 1.5 christos *
243 1.5 christos * FUNCTION: AcpiRemoveNotifyHandler
244 1.5 christos *
245 1.5 christos * PARAMETERS: Device - The device for which the handler is installed
246 1.5 christos * HandlerType - The type of handler:
247 1.5 christos * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
248 1.5 christos * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
249 1.5 christos * ACPI_ALL_NOTIFY: Both System and Device
250 1.5 christos * Handler - Address of the handler
251 1.5 christos *
252 1.5 christos * RETURN: Status
253 1.5 christos *
254 1.5 christos * DESCRIPTION: Remove a handler for notifies on an ACPI device
255 1.5 christos *
256 1.5 christos ******************************************************************************/
257 1.5 christos
258 1.5 christos ACPI_STATUS
259 1.5 christos AcpiRemoveNotifyHandler (
260 1.5 christos ACPI_HANDLE Device,
261 1.5 christos UINT32 HandlerType,
262 1.5 christos ACPI_NOTIFY_HANDLER Handler)
263 1.5 christos {
264 1.5 christos ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
265 1.5 christos ACPI_OPERAND_OBJECT *ObjDesc;
266 1.5 christos ACPI_OPERAND_OBJECT *HandlerObj;
267 1.5 christos ACPI_OPERAND_OBJECT *PreviousHandlerObj;
268 1.6 christos ACPI_STATUS Status = AE_OK;
269 1.5 christos UINT32 i;
270 1.5 christos
271 1.5 christos
272 1.5 christos ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler);
273 1.5 christos
274 1.5 christos
275 1.5 christos /* Parameter validation */
276 1.5 christos
277 1.5 christos if ((!Device) || (!Handler) || (!HandlerType) ||
278 1.5 christos (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
279 1.5 christos {
280 1.5 christos return_ACPI_STATUS (AE_BAD_PARAMETER);
281 1.5 christos }
282 1.5 christos
283 1.5 christos /* Root Object. Global handlers are removed here */
284 1.5 christos
285 1.5 christos if (Device == ACPI_ROOT_OBJECT)
286 1.5 christos {
287 1.5 christos for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
288 1.5 christos {
289 1.5 christos if (HandlerType & (i+1))
290 1.5 christos {
291 1.6 christos Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
292 1.6 christos if (ACPI_FAILURE (Status))
293 1.6 christos {
294 1.6 christos return_ACPI_STATUS (Status);
295 1.6 christos }
296 1.6 christos
297 1.5 christos if (!AcpiGbl_GlobalNotify[i].Handler ||
298 1.5 christos (AcpiGbl_GlobalNotify[i].Handler != Handler))
299 1.5 christos {
300 1.5 christos Status = AE_NOT_EXIST;
301 1.5 christos goto UnlockAndExit;
302 1.5 christos }
303 1.5 christos
304 1.5 christos ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
305 1.5 christos "Removing global notify handler\n"));
306 1.5 christos
307 1.5 christos AcpiGbl_GlobalNotify[i].Handler = NULL;
308 1.5 christos AcpiGbl_GlobalNotify[i].Context = NULL;
309 1.6 christos
310 1.6 christos (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
311 1.6 christos
312 1.6 christos /* Make sure all deferred notify tasks are completed */
313 1.6 christos
314 1.6 christos AcpiOsWaitEventsComplete ();
315 1.5 christos }
316 1.5 christos }
317 1.5 christos
318 1.6 christos return_ACPI_STATUS (AE_OK);
319 1.5 christos }
320 1.5 christos
321 1.5 christos /* All other objects: Are Notifies allowed on this object? */
322 1.5 christos
323 1.5 christos if (!AcpiEvIsNotifyObject (Node))
324 1.5 christos {
325 1.6 christos return_ACPI_STATUS (AE_TYPE);
326 1.5 christos }
327 1.5 christos
328 1.5 christos /* Must have an existing internal object */
329 1.5 christos
330 1.5 christos ObjDesc = AcpiNsGetAttachedObject (Node);
331 1.5 christos if (!ObjDesc)
332 1.5 christos {
333 1.6 christos return_ACPI_STATUS (AE_NOT_EXIST);
334 1.5 christos }
335 1.5 christos
336 1.5 christos /* Internal object exists. Find the handler and remove it */
337 1.5 christos
338 1.5 christos for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
339 1.5 christos {
340 1.5 christos if (HandlerType & (i+1))
341 1.5 christos {
342 1.6 christos Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
343 1.6 christos if (ACPI_FAILURE (Status))
344 1.6 christos {
345 1.6 christos return_ACPI_STATUS (Status);
346 1.6 christos }
347 1.6 christos
348 1.5 christos HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
349 1.5 christos PreviousHandlerObj = NULL;
350 1.5 christos
351 1.5 christos /* Attempt to find the handler in the handler list */
352 1.5 christos
353 1.5 christos while (HandlerObj &&
354 1.5 christos (HandlerObj->Notify.Handler != Handler))
355 1.5 christos {
356 1.5 christos PreviousHandlerObj = HandlerObj;
357 1.5 christos HandlerObj = HandlerObj->Notify.Next[i];
358 1.5 christos }
359 1.5 christos
360 1.5 christos if (!HandlerObj)
361 1.5 christos {
362 1.5 christos Status = AE_NOT_EXIST;
363 1.5 christos goto UnlockAndExit;
364 1.5 christos }
365 1.5 christos
366 1.5 christos /* Remove the handler object from the list */
367 1.5 christos
368 1.5 christos if (PreviousHandlerObj) /* Handler is not at the list head */
369 1.5 christos {
370 1.5 christos PreviousHandlerObj->Notify.Next[i] =
371 1.5 christos HandlerObj->Notify.Next[i];
372 1.5 christos }
373 1.5 christos else /* Handler is at the list head */
374 1.5 christos {
375 1.5 christos ObjDesc->CommonNotify.NotifyList[i] =
376 1.5 christos HandlerObj->Notify.Next[i];
377 1.5 christos }
378 1.5 christos
379 1.6 christos (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
380 1.6 christos
381 1.6 christos /* Make sure all deferred notify tasks are completed */
382 1.6 christos
383 1.6 christos AcpiOsWaitEventsComplete ();
384 1.5 christos AcpiUtRemoveReference (HandlerObj);
385 1.5 christos }
386 1.5 christos }
387 1.5 christos
388 1.6 christos return_ACPI_STATUS (Status);
389 1.6 christos
390 1.5 christos
391 1.5 christos UnlockAndExit:
392 1.5 christos (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
393 1.5 christos return_ACPI_STATUS (Status);
394 1.5 christos }
395 1.5 christos
396 1.5 christos ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler)
397 1.5 christos
398 1.5 christos
399 1.5 christos /*******************************************************************************
400 1.5 christos *
401 1.1 jruoho * FUNCTION: AcpiInstallExceptionHandler
402 1.1 jruoho *
403 1.1 jruoho * PARAMETERS: Handler - Pointer to the handler function for the
404 1.1 jruoho * event
405 1.1 jruoho *
406 1.1 jruoho * RETURN: Status
407 1.1 jruoho *
408 1.1 jruoho * DESCRIPTION: Saves the pointer to the handler function
409 1.1 jruoho *
410 1.1 jruoho ******************************************************************************/
411 1.1 jruoho
412 1.1 jruoho ACPI_STATUS
413 1.1 jruoho AcpiInstallExceptionHandler (
414 1.1 jruoho ACPI_EXCEPTION_HANDLER Handler)
415 1.1 jruoho {
416 1.1 jruoho ACPI_STATUS Status;
417 1.1 jruoho
418 1.1 jruoho
419 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler);
420 1.1 jruoho
421 1.1 jruoho
422 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
423 1.1 jruoho if (ACPI_FAILURE (Status))
424 1.1 jruoho {
425 1.1 jruoho return_ACPI_STATUS (Status);
426 1.1 jruoho }
427 1.1 jruoho
428 1.5 christos /* Don't allow two handlers. */
429 1.5 christos
430 1.5 christos if (AcpiGbl_ExceptionHandler)
431 1.5 christos {
432 1.5 christos Status = AE_ALREADY_EXISTS;
433 1.5 christos goto Cleanup;
434 1.5 christos }
435 1.5 christos
436 1.5 christos /* Install the handler */
437 1.5 christos
438 1.5 christos AcpiGbl_ExceptionHandler = Handler;
439 1.5 christos
440 1.5 christos Cleanup:
441 1.5 christos (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
442 1.5 christos return_ACPI_STATUS (Status);
443 1.5 christos }
444 1.5 christos
445 1.5 christos ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler)
446 1.5 christos
447 1.5 christos
448 1.5 christos #if (!ACPI_REDUCED_HARDWARE)
449 1.5 christos /*******************************************************************************
450 1.5 christos *
451 1.5 christos * FUNCTION: AcpiInstallSciHandler
452 1.5 christos *
453 1.5 christos * PARAMETERS: Address - Address of the handler
454 1.5 christos * Context - Value passed to the handler on each SCI
455 1.5 christos *
456 1.5 christos * RETURN: Status
457 1.5 christos *
458 1.5 christos * DESCRIPTION: Install a handler for a System Control Interrupt.
459 1.5 christos *
460 1.5 christos ******************************************************************************/
461 1.5 christos
462 1.5 christos ACPI_STATUS
463 1.5 christos AcpiInstallSciHandler (
464 1.5 christos ACPI_SCI_HANDLER Address,
465 1.5 christos void *Context)
466 1.5 christos {
467 1.5 christos ACPI_SCI_HANDLER_INFO *NewSciHandler;
468 1.5 christos ACPI_SCI_HANDLER_INFO *SciHandler;
469 1.5 christos ACPI_CPU_FLAGS Flags;
470 1.5 christos ACPI_STATUS Status;
471 1.5 christos
472 1.5 christos
473 1.5 christos ACPI_FUNCTION_TRACE (AcpiInstallSciHandler);
474 1.5 christos
475 1.5 christos
476 1.5 christos if (!Address)
477 1.5 christos {
478 1.5 christos return_ACPI_STATUS (AE_BAD_PARAMETER);
479 1.5 christos }
480 1.5 christos
481 1.5 christos /* Allocate and init a handler object */
482 1.5 christos
483 1.5 christos NewSciHandler = ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO));
484 1.5 christos if (!NewSciHandler)
485 1.5 christos {
486 1.5 christos return_ACPI_STATUS (AE_NO_MEMORY);
487 1.5 christos }
488 1.5 christos
489 1.5 christos NewSciHandler->Address = Address;
490 1.5 christos NewSciHandler->Context = Context;
491 1.5 christos
492 1.5 christos Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
493 1.5 christos if (ACPI_FAILURE (Status))
494 1.5 christos {
495 1.5 christos goto Exit;
496 1.5 christos }
497 1.5 christos
498 1.5 christos /* Lock list during installation */
499 1.5 christos
500 1.5 christos Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
501 1.5 christos SciHandler = AcpiGbl_SciHandlerList;
502 1.5 christos
503 1.5 christos /* Ensure handler does not already exist */
504 1.5 christos
505 1.5 christos while (SciHandler)
506 1.5 christos {
507 1.5 christos if (Address == SciHandler->Address)
508 1.5 christos {
509 1.5 christos Status = AE_ALREADY_EXISTS;
510 1.5 christos goto UnlockAndExit;
511 1.5 christos }
512 1.5 christos
513 1.5 christos SciHandler = SciHandler->Next;
514 1.5 christos }
515 1.5 christos
516 1.5 christos /* Install the new handler into the global list (at head) */
517 1.5 christos
518 1.5 christos NewSciHandler->Next = AcpiGbl_SciHandlerList;
519 1.5 christos AcpiGbl_SciHandlerList = NewSciHandler;
520 1.5 christos
521 1.5 christos
522 1.5 christos UnlockAndExit:
523 1.5 christos
524 1.5 christos AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
525 1.5 christos (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
526 1.5 christos
527 1.5 christos Exit:
528 1.5 christos if (ACPI_FAILURE (Status))
529 1.5 christos {
530 1.5 christos ACPI_FREE (NewSciHandler);
531 1.5 christos }
532 1.5 christos return_ACPI_STATUS (Status);
533 1.5 christos }
534 1.5 christos
535 1.6 christos ACPI_EXPORT_SYMBOL (AcpiInstallSciHandler)
536 1.6 christos
537 1.5 christos
538 1.5 christos /*******************************************************************************
539 1.5 christos *
540 1.5 christos * FUNCTION: AcpiRemoveSciHandler
541 1.5 christos *
542 1.5 christos * PARAMETERS: Address - Address of the handler
543 1.5 christos *
544 1.5 christos * RETURN: Status
545 1.5 christos *
546 1.5 christos * DESCRIPTION: Remove a handler for a System Control Interrupt.
547 1.5 christos *
548 1.5 christos ******************************************************************************/
549 1.5 christos
550 1.5 christos ACPI_STATUS
551 1.5 christos AcpiRemoveSciHandler (
552 1.5 christos ACPI_SCI_HANDLER Address)
553 1.5 christos {
554 1.5 christos ACPI_SCI_HANDLER_INFO *PrevSciHandler;
555 1.5 christos ACPI_SCI_HANDLER_INFO *NextSciHandler;
556 1.5 christos ACPI_CPU_FLAGS Flags;
557 1.5 christos ACPI_STATUS Status;
558 1.5 christos
559 1.5 christos
560 1.5 christos ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler);
561 1.5 christos
562 1.5 christos
563 1.5 christos if (!Address)
564 1.5 christos {
565 1.5 christos return_ACPI_STATUS (AE_BAD_PARAMETER);
566 1.5 christos }
567 1.5 christos
568 1.5 christos Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
569 1.5 christos if (ACPI_FAILURE (Status))
570 1.5 christos {
571 1.5 christos return_ACPI_STATUS (Status);
572 1.5 christos }
573 1.5 christos
574 1.5 christos /* Remove the SCI handler with lock */
575 1.5 christos
576 1.5 christos Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
577 1.5 christos
578 1.5 christos PrevSciHandler = NULL;
579 1.5 christos NextSciHandler = AcpiGbl_SciHandlerList;
580 1.5 christos while (NextSciHandler)
581 1.5 christos {
582 1.5 christos if (NextSciHandler->Address == Address)
583 1.5 christos {
584 1.5 christos /* Unlink and free the SCI handler info block */
585 1.5 christos
586 1.5 christos if (PrevSciHandler)
587 1.5 christos {
588 1.5 christos PrevSciHandler->Next = NextSciHandler->Next;
589 1.5 christos }
590 1.5 christos else
591 1.5 christos {
592 1.5 christos AcpiGbl_SciHandlerList = NextSciHandler->Next;
593 1.5 christos }
594 1.5 christos
595 1.5 christos AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
596 1.5 christos ACPI_FREE (NextSciHandler);
597 1.5 christos goto UnlockAndExit;
598 1.5 christos }
599 1.1 jruoho
600 1.5 christos PrevSciHandler = NextSciHandler;
601 1.5 christos NextSciHandler = NextSciHandler->Next;
602 1.1 jruoho }
603 1.1 jruoho
604 1.5 christos AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
605 1.5 christos Status = AE_NOT_EXIST;
606 1.1 jruoho
607 1.1 jruoho
608 1.5 christos UnlockAndExit:
609 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
610 1.1 jruoho return_ACPI_STATUS (Status);
611 1.1 jruoho }
612 1.1 jruoho
613 1.6 christos ACPI_EXPORT_SYMBOL (AcpiRemoveSciHandler)
614 1.6 christos
615 1.1 jruoho
616 1.1 jruoho /*******************************************************************************
617 1.1 jruoho *
618 1.4 jruoho * FUNCTION: AcpiInstallGlobalEventHandler
619 1.4 jruoho *
620 1.4 jruoho * PARAMETERS: Handler - Pointer to the global event handler function
621 1.4 jruoho * Context - Value passed to the handler on each event
622 1.4 jruoho *
623 1.4 jruoho * RETURN: Status
624 1.4 jruoho *
625 1.4 jruoho * DESCRIPTION: Saves the pointer to the handler function. The global handler
626 1.4 jruoho * is invoked upon each incoming GPE and Fixed Event. It is
627 1.4 jruoho * invoked at interrupt level at the time of the event dispatch.
628 1.4 jruoho * Can be used to update event counters, etc.
629 1.4 jruoho *
630 1.4 jruoho ******************************************************************************/
631 1.4 jruoho
632 1.4 jruoho ACPI_STATUS
633 1.4 jruoho AcpiInstallGlobalEventHandler (
634 1.4 jruoho ACPI_GBL_EVENT_HANDLER Handler,
635 1.4 jruoho void *Context)
636 1.4 jruoho {
637 1.4 jruoho ACPI_STATUS Status;
638 1.4 jruoho
639 1.4 jruoho
640 1.4 jruoho ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler);
641 1.4 jruoho
642 1.4 jruoho
643 1.4 jruoho /* Parameter validation */
644 1.4 jruoho
645 1.4 jruoho if (!Handler)
646 1.4 jruoho {
647 1.4 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
648 1.4 jruoho }
649 1.4 jruoho
650 1.4 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
651 1.4 jruoho if (ACPI_FAILURE (Status))
652 1.4 jruoho {
653 1.4 jruoho return_ACPI_STATUS (Status);
654 1.4 jruoho }
655 1.4 jruoho
656 1.4 jruoho /* Don't allow two handlers. */
657 1.4 jruoho
658 1.4 jruoho if (AcpiGbl_GlobalEventHandler)
659 1.4 jruoho {
660 1.4 jruoho Status = AE_ALREADY_EXISTS;
661 1.4 jruoho goto Cleanup;
662 1.4 jruoho }
663 1.4 jruoho
664 1.4 jruoho AcpiGbl_GlobalEventHandler = Handler;
665 1.4 jruoho AcpiGbl_GlobalEventHandlerContext = Context;
666 1.4 jruoho
667 1.4 jruoho
668 1.4 jruoho Cleanup:
669 1.4 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
670 1.4 jruoho return_ACPI_STATUS (Status);
671 1.4 jruoho }
672 1.4 jruoho
673 1.4 jruoho ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler)
674 1.4 jruoho
675 1.4 jruoho
676 1.4 jruoho /*******************************************************************************
677 1.4 jruoho *
678 1.1 jruoho * FUNCTION: AcpiInstallFixedEventHandler
679 1.1 jruoho *
680 1.1 jruoho * PARAMETERS: Event - Event type to enable.
681 1.1 jruoho * Handler - Pointer to the handler function for the
682 1.1 jruoho * event
683 1.1 jruoho * Context - Value passed to the handler on each GPE
684 1.1 jruoho *
685 1.1 jruoho * RETURN: Status
686 1.1 jruoho *
687 1.1 jruoho * DESCRIPTION: Saves the pointer to the handler function and then enables the
688 1.1 jruoho * event.
689 1.1 jruoho *
690 1.1 jruoho ******************************************************************************/
691 1.1 jruoho
692 1.1 jruoho ACPI_STATUS
693 1.1 jruoho AcpiInstallFixedEventHandler (
694 1.1 jruoho UINT32 Event,
695 1.1 jruoho ACPI_EVENT_HANDLER Handler,
696 1.1 jruoho void *Context)
697 1.1 jruoho {
698 1.1 jruoho ACPI_STATUS Status;
699 1.1 jruoho
700 1.1 jruoho
701 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler);
702 1.1 jruoho
703 1.1 jruoho
704 1.1 jruoho /* Parameter validation */
705 1.1 jruoho
706 1.1 jruoho if (Event > ACPI_EVENT_MAX)
707 1.1 jruoho {
708 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
709 1.1 jruoho }
710 1.1 jruoho
711 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
712 1.1 jruoho if (ACPI_FAILURE (Status))
713 1.1 jruoho {
714 1.1 jruoho return_ACPI_STATUS (Status);
715 1.1 jruoho }
716 1.1 jruoho
717 1.5 christos /* Do not allow multiple handlers */
718 1.1 jruoho
719 1.5 christos if (AcpiGbl_FixedEventHandlers[Event].Handler)
720 1.1 jruoho {
721 1.1 jruoho Status = AE_ALREADY_EXISTS;
722 1.1 jruoho goto Cleanup;
723 1.1 jruoho }
724 1.1 jruoho
725 1.1 jruoho /* Install the handler before enabling the event */
726 1.1 jruoho
727 1.1 jruoho AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
728 1.1 jruoho AcpiGbl_FixedEventHandlers[Event].Context = Context;
729 1.1 jruoho
730 1.1 jruoho Status = AcpiEnableEvent (Event, 0);
731 1.1 jruoho if (ACPI_FAILURE (Status))
732 1.1 jruoho {
733 1.5 christos ACPI_WARNING ((AE_INFO,
734 1.5 christos "Could not enable fixed event - %s (%u)",
735 1.5 christos AcpiUtGetEventName (Event), Event));
736 1.1 jruoho
737 1.1 jruoho /* Remove the handler */
738 1.1 jruoho
739 1.1 jruoho AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
740 1.1 jruoho AcpiGbl_FixedEventHandlers[Event].Context = NULL;
741 1.1 jruoho }
742 1.1 jruoho else
743 1.1 jruoho {
744 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
745 1.5 christos "Enabled fixed event %s (%X), Handler=%p\n",
746 1.5 christos AcpiUtGetEventName (Event), Event, Handler));
747 1.1 jruoho }
748 1.1 jruoho
749 1.1 jruoho
750 1.1 jruoho Cleanup:
751 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
752 1.1 jruoho return_ACPI_STATUS (Status);
753 1.1 jruoho }
754 1.1 jruoho
755 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler)
756 1.1 jruoho
757 1.1 jruoho
758 1.1 jruoho /*******************************************************************************
759 1.1 jruoho *
760 1.1 jruoho * FUNCTION: AcpiRemoveFixedEventHandler
761 1.1 jruoho *
762 1.1 jruoho * PARAMETERS: Event - Event type to disable.
763 1.1 jruoho * Handler - Address of the handler
764 1.1 jruoho *
765 1.1 jruoho * RETURN: Status
766 1.1 jruoho *
767 1.1 jruoho * DESCRIPTION: Disables the event and unregisters the event handler.
768 1.1 jruoho *
769 1.1 jruoho ******************************************************************************/
770 1.1 jruoho
771 1.1 jruoho ACPI_STATUS
772 1.1 jruoho AcpiRemoveFixedEventHandler (
773 1.1 jruoho UINT32 Event,
774 1.1 jruoho ACPI_EVENT_HANDLER Handler)
775 1.1 jruoho {
776 1.1 jruoho ACPI_STATUS Status = AE_OK;
777 1.1 jruoho
778 1.1 jruoho
779 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler);
780 1.1 jruoho
781 1.1 jruoho
782 1.1 jruoho /* Parameter validation */
783 1.1 jruoho
784 1.1 jruoho if (Event > ACPI_EVENT_MAX)
785 1.1 jruoho {
786 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
787 1.1 jruoho }
788 1.1 jruoho
789 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
790 1.1 jruoho if (ACPI_FAILURE (Status))
791 1.1 jruoho {
792 1.1 jruoho return_ACPI_STATUS (Status);
793 1.1 jruoho }
794 1.1 jruoho
795 1.1 jruoho /* Disable the event before removing the handler */
796 1.1 jruoho
797 1.1 jruoho Status = AcpiDisableEvent (Event, 0);
798 1.1 jruoho
799 1.1 jruoho /* Always Remove the handler */
800 1.1 jruoho
801 1.1 jruoho AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
802 1.1 jruoho AcpiGbl_FixedEventHandlers[Event].Context = NULL;
803 1.1 jruoho
804 1.1 jruoho if (ACPI_FAILURE (Status))
805 1.1 jruoho {
806 1.1 jruoho ACPI_WARNING ((AE_INFO,
807 1.5 christos "Could not disable fixed event - %s (%u)",
808 1.5 christos AcpiUtGetEventName (Event), Event));
809 1.1 jruoho }
810 1.1 jruoho else
811 1.1 jruoho {
812 1.5 christos ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
813 1.5 christos "Disabled fixed event - %s (%X)\n",
814 1.5 christos AcpiUtGetEventName (Event), Event));
815 1.1 jruoho }
816 1.1 jruoho
817 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
818 1.1 jruoho return_ACPI_STATUS (Status);
819 1.1 jruoho }
820 1.1 jruoho
821 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler)
822 1.1 jruoho
823 1.1 jruoho
824 1.1 jruoho /*******************************************************************************
825 1.1 jruoho *
826 1.1 jruoho * FUNCTION: AcpiInstallGpeHandler
827 1.1 jruoho *
828 1.1 jruoho * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
829 1.1 jruoho * defined GPEs)
830 1.1 jruoho * GpeNumber - The GPE number within the GPE block
831 1.1 jruoho * Type - Whether this GPE should be treated as an
832 1.1 jruoho * edge- or level-triggered interrupt.
833 1.1 jruoho * Address - Address of the handler
834 1.1 jruoho * Context - Value passed to the handler on each GPE
835 1.1 jruoho *
836 1.1 jruoho * RETURN: Status
837 1.1 jruoho *
838 1.1 jruoho * DESCRIPTION: Install a handler for a General Purpose Event.
839 1.1 jruoho *
840 1.1 jruoho ******************************************************************************/
841 1.1 jruoho
842 1.1 jruoho ACPI_STATUS
843 1.1 jruoho AcpiInstallGpeHandler (
844 1.1 jruoho ACPI_HANDLE GpeDevice,
845 1.1 jruoho UINT32 GpeNumber,
846 1.1 jruoho UINT32 Type,
847 1.4 jruoho ACPI_GPE_HANDLER Address,
848 1.1 jruoho void *Context)
849 1.1 jruoho {
850 1.1 jruoho ACPI_GPE_EVENT_INFO *GpeEventInfo;
851 1.4 jruoho ACPI_GPE_HANDLER_INFO *Handler;
852 1.1 jruoho ACPI_STATUS Status;
853 1.1 jruoho ACPI_CPU_FLAGS Flags;
854 1.1 jruoho
855 1.1 jruoho
856 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);
857 1.1 jruoho
858 1.1 jruoho
859 1.1 jruoho /* Parameter validation */
860 1.1 jruoho
861 1.1 jruoho if ((!Address) || (Type & ~ACPI_GPE_XRUPT_TYPE_MASK))
862 1.1 jruoho {
863 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
864 1.1 jruoho }
865 1.1 jruoho
866 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
867 1.1 jruoho if (ACPI_FAILURE (Status))
868 1.1 jruoho {
869 1.1 jruoho return_ACPI_STATUS (Status);
870 1.1 jruoho }
871 1.1 jruoho
872 1.4 jruoho /* Allocate and init handler object (before lock) */
873 1.4 jruoho
874 1.4 jruoho Handler = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO));
875 1.4 jruoho if (!Handler)
876 1.4 jruoho {
877 1.4 jruoho Status = AE_NO_MEMORY;
878 1.4 jruoho goto UnlockAndExit;
879 1.4 jruoho }
880 1.4 jruoho
881 1.4 jruoho Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
882 1.4 jruoho
883 1.1 jruoho /* Ensure that we have a valid GPE number */
884 1.1 jruoho
885 1.1 jruoho GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
886 1.1 jruoho if (!GpeEventInfo)
887 1.1 jruoho {
888 1.1 jruoho Status = AE_BAD_PARAMETER;
889 1.4 jruoho goto FreeAndExit;
890 1.1 jruoho }
891 1.1 jruoho
892 1.1 jruoho /* Make sure that there isn't a handler there already */
893 1.1 jruoho
894 1.1 jruoho if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
895 1.1 jruoho ACPI_GPE_DISPATCH_HANDLER)
896 1.1 jruoho {
897 1.1 jruoho Status = AE_ALREADY_EXISTS;
898 1.4 jruoho goto FreeAndExit;
899 1.1 jruoho }
900 1.1 jruoho
901 1.4 jruoho Handler->Address = Address;
902 1.4 jruoho Handler->Context = Context;
903 1.4 jruoho Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;
904 1.4 jruoho Handler->OriginalFlags = (UINT8) (GpeEventInfo->Flags &
905 1.4 jruoho (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK));
906 1.1 jruoho
907 1.4 jruoho /*
908 1.4 jruoho * If the GPE is associated with a method, it may have been enabled
909 1.4 jruoho * automatically during initialization, in which case it has to be
910 1.4 jruoho * disabled now to avoid spurious execution of the handler.
911 1.4 jruoho */
912 1.4 jruoho if (((Handler->OriginalFlags & ACPI_GPE_DISPATCH_METHOD) ||
913 1.4 jruoho (Handler->OriginalFlags & ACPI_GPE_DISPATCH_NOTIFY)) &&
914 1.4 jruoho GpeEventInfo->RuntimeCount)
915 1.1 jruoho {
916 1.4 jruoho Handler->OriginallyEnabled = TRUE;
917 1.4 jruoho (void) AcpiEvRemoveGpeReference (GpeEventInfo);
918 1.1 jruoho
919 1.4 jruoho /* Sanity check of original type against new type */
920 1.1 jruoho
921 1.4 jruoho if (Type != (UINT32) (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
922 1.4 jruoho {
923 1.4 jruoho ACPI_WARNING ((AE_INFO, "GPE type mismatch (level/edge)"));
924 1.4 jruoho }
925 1.1 jruoho }
926 1.1 jruoho
927 1.1 jruoho /* Install the handler */
928 1.1 jruoho
929 1.1 jruoho GpeEventInfo->Dispatch.Handler = Handler;
930 1.1 jruoho
931 1.4 jruoho /* Setup up dispatch flags to indicate handler (vs. method/notify) */
932 1.1 jruoho
933 1.1 jruoho GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
934 1.1 jruoho GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_HANDLER);
935 1.1 jruoho
936 1.1 jruoho AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
937 1.1 jruoho
938 1.1 jruoho
939 1.1 jruoho UnlockAndExit:
940 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
941 1.1 jruoho return_ACPI_STATUS (Status);
942 1.4 jruoho
943 1.4 jruoho FreeAndExit:
944 1.4 jruoho AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
945 1.4 jruoho ACPI_FREE (Handler);
946 1.4 jruoho goto UnlockAndExit;
947 1.1 jruoho }
948 1.1 jruoho
949 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)
950 1.1 jruoho
951 1.1 jruoho
952 1.1 jruoho /*******************************************************************************
953 1.1 jruoho *
954 1.1 jruoho * FUNCTION: AcpiRemoveGpeHandler
955 1.1 jruoho *
956 1.1 jruoho * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
957 1.1 jruoho * defined GPEs)
958 1.1 jruoho * GpeNumber - The event to remove a handler
959 1.1 jruoho * Address - Address of the handler
960 1.1 jruoho *
961 1.1 jruoho * RETURN: Status
962 1.1 jruoho *
963 1.1 jruoho * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
964 1.1 jruoho *
965 1.1 jruoho ******************************************************************************/
966 1.1 jruoho
967 1.1 jruoho ACPI_STATUS
968 1.1 jruoho AcpiRemoveGpeHandler (
969 1.1 jruoho ACPI_HANDLE GpeDevice,
970 1.1 jruoho UINT32 GpeNumber,
971 1.4 jruoho ACPI_GPE_HANDLER Address)
972 1.1 jruoho {
973 1.1 jruoho ACPI_GPE_EVENT_INFO *GpeEventInfo;
974 1.4 jruoho ACPI_GPE_HANDLER_INFO *Handler;
975 1.1 jruoho ACPI_STATUS Status;
976 1.1 jruoho ACPI_CPU_FLAGS Flags;
977 1.1 jruoho
978 1.1 jruoho
979 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler);
980 1.1 jruoho
981 1.1 jruoho
982 1.1 jruoho /* Parameter validation */
983 1.1 jruoho
984 1.1 jruoho if (!Address)
985 1.1 jruoho {
986 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
987 1.1 jruoho }
988 1.1 jruoho
989 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
990 1.1 jruoho if (ACPI_FAILURE (Status))
991 1.1 jruoho {
992 1.1 jruoho return_ACPI_STATUS (Status);
993 1.1 jruoho }
994 1.1 jruoho
995 1.4 jruoho Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
996 1.4 jruoho
997 1.1 jruoho /* Ensure that we have a valid GPE number */
998 1.1 jruoho
999 1.1 jruoho GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
1000 1.1 jruoho if (!GpeEventInfo)
1001 1.1 jruoho {
1002 1.1 jruoho Status = AE_BAD_PARAMETER;
1003 1.1 jruoho goto UnlockAndExit;
1004 1.1 jruoho }
1005 1.1 jruoho
1006 1.1 jruoho /* Make sure that a handler is indeed installed */
1007 1.1 jruoho
1008 1.1 jruoho if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) !=
1009 1.1 jruoho ACPI_GPE_DISPATCH_HANDLER)
1010 1.1 jruoho {
1011 1.1 jruoho Status = AE_NOT_EXIST;
1012 1.1 jruoho goto UnlockAndExit;
1013 1.1 jruoho }
1014 1.1 jruoho
1015 1.1 jruoho /* Make sure that the installed handler is the same */
1016 1.1 jruoho
1017 1.1 jruoho if (GpeEventInfo->Dispatch.Handler->Address != Address)
1018 1.1 jruoho {
1019 1.1 jruoho Status = AE_BAD_PARAMETER;
1020 1.1 jruoho goto UnlockAndExit;
1021 1.1 jruoho }
1022 1.1 jruoho
1023 1.1 jruoho /* Remove the handler */
1024 1.1 jruoho
1025 1.1 jruoho Handler = GpeEventInfo->Dispatch.Handler;
1026 1.1 jruoho
1027 1.1 jruoho /* Restore Method node (if any), set dispatch flags */
1028 1.1 jruoho
1029 1.1 jruoho GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;
1030 1.4 jruoho GpeEventInfo->Flags &=
1031 1.4 jruoho ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
1032 1.4 jruoho GpeEventInfo->Flags |= Handler->OriginalFlags;
1033 1.4 jruoho
1034 1.4 jruoho /*
1035 1.4 jruoho * If the GPE was previously associated with a method and it was
1036 1.4 jruoho * enabled, it should be enabled at this point to restore the
1037 1.4 jruoho * post-initialization configuration.
1038 1.4 jruoho */
1039 1.6 christos if (((Handler->OriginalFlags & ACPI_GPE_DISPATCH_METHOD) ||
1040 1.6 christos (Handler->OriginalFlags & ACPI_GPE_DISPATCH_NOTIFY)) &&
1041 1.4 jruoho Handler->OriginallyEnabled)
1042 1.1 jruoho {
1043 1.4 jruoho (void) AcpiEvAddGpeReference (GpeEventInfo);
1044 1.1 jruoho }
1045 1.1 jruoho
1046 1.6 christos AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
1047 1.6 christos (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1048 1.6 christos
1049 1.6 christos /* Make sure all deferred GPE tasks are completed */
1050 1.6 christos
1051 1.6 christos AcpiOsWaitEventsComplete ();
1052 1.6 christos
1053 1.1 jruoho /* Now we can free the handler object */
1054 1.1 jruoho
1055 1.1 jruoho ACPI_FREE (Handler);
1056 1.6 christos return_ACPI_STATUS (Status);
1057 1.1 jruoho
1058 1.1 jruoho UnlockAndExit:
1059 1.4 jruoho AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
1060 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1061 1.1 jruoho return_ACPI_STATUS (Status);
1062 1.1 jruoho }
1063 1.1 jruoho
1064 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler)
1065 1.1 jruoho
1066 1.1 jruoho
1067 1.1 jruoho /*******************************************************************************
1068 1.1 jruoho *
1069 1.1 jruoho * FUNCTION: AcpiAcquireGlobalLock
1070 1.1 jruoho *
1071 1.1 jruoho * PARAMETERS: Timeout - How long the caller is willing to wait
1072 1.1 jruoho * Handle - Where the handle to the lock is returned
1073 1.1 jruoho * (if acquired)
1074 1.1 jruoho *
1075 1.1 jruoho * RETURN: Status
1076 1.1 jruoho *
1077 1.1 jruoho * DESCRIPTION: Acquire the ACPI Global Lock
1078 1.1 jruoho *
1079 1.1 jruoho * Note: Allows callers with the same thread ID to acquire the global lock
1080 1.1 jruoho * multiple times. In other words, externally, the behavior of the global lock
1081 1.1 jruoho * is identical to an AML mutex. On the first acquire, a new handle is
1082 1.1 jruoho * returned. On any subsequent calls to acquire by the same thread, the same
1083 1.1 jruoho * handle is returned.
1084 1.1 jruoho *
1085 1.1 jruoho ******************************************************************************/
1086 1.1 jruoho
1087 1.1 jruoho ACPI_STATUS
1088 1.1 jruoho AcpiAcquireGlobalLock (
1089 1.1 jruoho UINT16 Timeout,
1090 1.1 jruoho UINT32 *Handle)
1091 1.1 jruoho {
1092 1.1 jruoho ACPI_STATUS Status;
1093 1.1 jruoho
1094 1.1 jruoho
1095 1.1 jruoho if (!Handle)
1096 1.1 jruoho {
1097 1.1 jruoho return (AE_BAD_PARAMETER);
1098 1.1 jruoho }
1099 1.1 jruoho
1100 1.1 jruoho /* Must lock interpreter to prevent race conditions */
1101 1.1 jruoho
1102 1.1 jruoho AcpiExEnterInterpreter ();
1103 1.1 jruoho
1104 1.1 jruoho Status = AcpiExAcquireMutexObject (Timeout,
1105 1.1 jruoho AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
1106 1.1 jruoho
1107 1.1 jruoho if (ACPI_SUCCESS (Status))
1108 1.1 jruoho {
1109 1.1 jruoho /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
1110 1.1 jruoho
1111 1.1 jruoho *Handle = AcpiGbl_GlobalLockHandle;
1112 1.1 jruoho }
1113 1.1 jruoho
1114 1.1 jruoho AcpiExExitInterpreter ();
1115 1.1 jruoho return (Status);
1116 1.1 jruoho }
1117 1.1 jruoho
1118 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock)
1119 1.1 jruoho
1120 1.1 jruoho
1121 1.1 jruoho /*******************************************************************************
1122 1.1 jruoho *
1123 1.1 jruoho * FUNCTION: AcpiReleaseGlobalLock
1124 1.1 jruoho *
1125 1.1 jruoho * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
1126 1.1 jruoho *
1127 1.1 jruoho * RETURN: Status
1128 1.1 jruoho *
1129 1.1 jruoho * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1130 1.1 jruoho *
1131 1.1 jruoho ******************************************************************************/
1132 1.1 jruoho
1133 1.1 jruoho ACPI_STATUS
1134 1.1 jruoho AcpiReleaseGlobalLock (
1135 1.1 jruoho UINT32 Handle)
1136 1.1 jruoho {
1137 1.1 jruoho ACPI_STATUS Status;
1138 1.1 jruoho
1139 1.1 jruoho
1140 1.1 jruoho if (!Handle || (Handle != AcpiGbl_GlobalLockHandle))
1141 1.1 jruoho {
1142 1.1 jruoho return (AE_NOT_ACQUIRED);
1143 1.1 jruoho }
1144 1.1 jruoho
1145 1.1 jruoho Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
1146 1.1 jruoho return (Status);
1147 1.1 jruoho }
1148 1.1 jruoho
1149 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock)
1150 1.1 jruoho
1151 1.5 christos #endif /* !ACPI_REDUCED_HARDWARE */
1152