initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / events / evevent.c
blob558ec7b33756acadd97d22f2bfbdcf64edefb31c
1 /******************************************************************************
3 * Module Name: evevent - Fixed Event handling and dispatch
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2004, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/acevents.h>
47 #define _COMPONENT ACPI_EVENTS
48 ACPI_MODULE_NAME ("evevent")
51 /*******************************************************************************
53 * FUNCTION: acpi_ev_initialize_events
55 * PARAMETERS: None
57 * RETURN: Status
59 * DESCRIPTION: Initialize global data structures for events.
61 ******************************************************************************/
63 acpi_status
64 acpi_ev_initialize_events (
65 void)
67 acpi_status status;
70 ACPI_FUNCTION_TRACE ("ev_initialize_events");
73 /* Make sure we have ACPI tables */
75 if (!acpi_gbl_DSDT) {
76 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No ACPI tables present!\n"));
77 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
81 * Initialize the Fixed and General Purpose Events. This is
82 * done prior to enabling SCIs to prevent interrupts from
83 * occurring before handers are installed.
85 status = acpi_ev_fixed_event_initialize ();
86 if (ACPI_FAILURE (status)) {
87 ACPI_REPORT_ERROR ((
88 "Unable to initialize fixed events, %s\n",
89 acpi_format_exception (status)));
90 return_ACPI_STATUS (status);
93 status = acpi_ev_gpe_initialize ();
94 if (ACPI_FAILURE (status)) {
95 ACPI_REPORT_ERROR ((
96 "Unable to initialize general purpose events, %s\n",
97 acpi_format_exception (status)));
98 return_ACPI_STATUS (status);
101 return_ACPI_STATUS (status);
105 /*******************************************************************************
107 * FUNCTION: acpi_ev_install_xrupt_handlers
109 * PARAMETERS: None
111 * RETURN: Status
113 * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
115 ******************************************************************************/
117 acpi_status
118 acpi_ev_install_xrupt_handlers (
119 void)
121 acpi_status status;
124 ACPI_FUNCTION_TRACE ("ev_install_xrupt_handlers");
127 /* Install the SCI handler */
129 status = acpi_ev_install_sci_handler ();
130 if (ACPI_FAILURE (status)) {
131 ACPI_REPORT_ERROR ((
132 "Unable to install System Control Interrupt Handler, %s\n",
133 acpi_format_exception (status)));
134 return_ACPI_STATUS (status);
137 /* Install the handler for the Global Lock */
139 status = acpi_ev_init_global_lock_handler ();
140 if (ACPI_FAILURE (status)) {
141 ACPI_REPORT_ERROR ((
142 "Unable to initialize Global Lock handler, %s\n",
143 acpi_format_exception (status)));
144 return_ACPI_STATUS (status);
147 acpi_gbl_events_initialized = TRUE;
148 return_ACPI_STATUS (status);
152 /*******************************************************************************
154 * FUNCTION: acpi_ev_fixed_event_initialize
156 * PARAMETERS: None
158 * RETURN: Status
160 * DESCRIPTION: Install the fixed event handlers and enable the fixed events.
162 ******************************************************************************/
164 acpi_status
165 acpi_ev_fixed_event_initialize (
166 void)
168 acpi_native_uint i;
169 acpi_status status;
173 * Initialize the structure that keeps track of fixed event handlers
174 * and enable the fixed events.
176 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
177 acpi_gbl_fixed_event_handlers[i].handler = NULL;
178 acpi_gbl_fixed_event_handlers[i].context = NULL;
180 /* Enable the fixed event */
182 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
183 status = acpi_set_register (acpi_gbl_fixed_event_info[i].enable_register_id,
184 0, ACPI_MTX_LOCK);
185 if (ACPI_FAILURE (status)) {
186 return (status);
191 return (AE_OK);
195 /*******************************************************************************
197 * FUNCTION: acpi_ev_fixed_event_detect
199 * PARAMETERS: None
201 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
203 * DESCRIPTION: Checks the PM status register for fixed events
205 ******************************************************************************/
208 acpi_ev_fixed_event_detect (
209 void)
211 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
212 u32 fixed_status;
213 u32 fixed_enable;
214 acpi_native_uint i;
217 ACPI_FUNCTION_NAME ("ev_fixed_event_detect");
221 * Read the fixed feature status and enable registers, as all the cases
222 * depend on their values. Ignore errors here.
224 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS, &fixed_status);
225 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE, &fixed_enable);
227 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
228 "Fixed Event Block: Enable %08X Status %08X\n",
229 fixed_enable, fixed_status));
232 * Check for all possible Fixed Events and dispatch those that are active
234 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
235 /* Both the status and enable bits must be on for this event */
237 if ((fixed_status & acpi_gbl_fixed_event_info[i].status_bit_mask) &&
238 (fixed_enable & acpi_gbl_fixed_event_info[i].enable_bit_mask)) {
239 /* Found an active (signalled) event */
241 int_status |= acpi_ev_fixed_event_dispatch ((u32) i);
245 return (int_status);
249 /*******************************************************************************
251 * FUNCTION: acpi_ev_fixed_event_dispatch
253 * PARAMETERS: Event - Event type
255 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
257 * DESCRIPTION: Clears the status bit for the requested event, calls the
258 * handler that previously registered for the event.
260 ******************************************************************************/
263 acpi_ev_fixed_event_dispatch (
264 u32 event)
268 ACPI_FUNCTION_ENTRY ();
271 /* Clear the status bit */
273 (void) acpi_set_register (acpi_gbl_fixed_event_info[event].status_register_id,
274 1, ACPI_MTX_DO_NOT_LOCK);
277 * Make sure we've got a handler. If not, report an error.
278 * The event is disabled to prevent further interrupts.
280 if (NULL == acpi_gbl_fixed_event_handlers[event].handler) {
281 (void) acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id,
282 0, ACPI_MTX_DO_NOT_LOCK);
284 ACPI_REPORT_ERROR (
285 ("No installed handler for fixed event [%08X]\n",
286 event));
288 return (ACPI_INTERRUPT_NOT_HANDLED);
291 /* Invoke the Fixed Event handler */
293 return ((acpi_gbl_fixed_event_handlers[event].handler)(
294 acpi_gbl_fixed_event_handlers[event].context));