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