1 /******************************************************************************
3 * Module Name: evevent - Fixed Event handling and dispatch
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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")
50 /* Local prototypes */
53 acpi_ev_fixed_event_initialize (
57 acpi_ev_fixed_event_dispatch (
61 /*******************************************************************************
63 * FUNCTION: acpi_ev_initialize_events
69 * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
71 ******************************************************************************/
74 acpi_ev_initialize_events (
80 ACPI_FUNCTION_TRACE ("ev_initialize_events");
83 /* Make sure we have ACPI tables */
86 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No ACPI tables present!\n"));
87 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
91 * Initialize the Fixed and General Purpose Events. This is done prior to
92 * enabling SCIs to prevent interrupts from occurring before the handlers are
95 status = acpi_ev_fixed_event_initialize ();
96 if (ACPI_FAILURE (status)) {
98 "Unable to initialize fixed events, %s\n",
99 acpi_format_exception (status)));
100 return_ACPI_STATUS (status);
103 status = acpi_ev_gpe_initialize ();
104 if (ACPI_FAILURE (status)) {
106 "Unable to initialize general purpose events, %s\n",
107 acpi_format_exception (status)));
108 return_ACPI_STATUS (status);
111 return_ACPI_STATUS (status);
115 /*******************************************************************************
117 * FUNCTION: acpi_ev_install_xrupt_handlers
123 * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
125 ******************************************************************************/
128 acpi_ev_install_xrupt_handlers (
134 ACPI_FUNCTION_TRACE ("ev_install_xrupt_handlers");
137 /* Install the SCI handler */
139 status = acpi_ev_install_sci_handler ();
140 if (ACPI_FAILURE (status)) {
142 "Unable to install System Control Interrupt Handler, %s\n",
143 acpi_format_exception (status)));
144 return_ACPI_STATUS (status);
147 /* Install the handler for the Global Lock */
149 status = acpi_ev_init_global_lock_handler ();
150 if (ACPI_FAILURE (status)) {
152 "Unable to initialize Global Lock handler, %s\n",
153 acpi_format_exception (status)));
154 return_ACPI_STATUS (status);
157 acpi_gbl_events_initialized = TRUE;
158 return_ACPI_STATUS (status);
162 /*******************************************************************************
164 * FUNCTION: acpi_ev_fixed_event_initialize
170 * DESCRIPTION: Install the fixed event handlers and enable the fixed events.
172 ******************************************************************************/
175 acpi_ev_fixed_event_initialize (
183 * Initialize the structure that keeps track of fixed event handlers
184 * and enable the fixed events.
186 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
187 acpi_gbl_fixed_event_handlers[i].handler = NULL;
188 acpi_gbl_fixed_event_handlers[i].context = NULL;
190 /* Enable the fixed event */
192 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
193 status = acpi_set_register (
194 acpi_gbl_fixed_event_info[i].enable_register_id,
196 if (ACPI_FAILURE (status)) {
206 /*******************************************************************************
208 * FUNCTION: acpi_ev_fixed_event_detect
212 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
214 * DESCRIPTION: Checks the PM status register for active fixed events
216 ******************************************************************************/
219 acpi_ev_fixed_event_detect (
222 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
228 ACPI_FUNCTION_NAME ("ev_fixed_event_detect");
232 * Read the fixed feature status and enable registers, as all the cases
233 * depend on their values. Ignore errors here.
235 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
237 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE,
240 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
241 "Fixed Event Block: Enable %08X Status %08X\n",
242 fixed_enable, fixed_status));
245 * Check for all possible Fixed Events and dispatch those that are active
247 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
248 /* Both the status and enable bits must be on for this event */
250 if ((fixed_status & acpi_gbl_fixed_event_info[i].status_bit_mask) &&
251 (fixed_enable & acpi_gbl_fixed_event_info[i].enable_bit_mask)) {
252 /* Found an active (signalled) event */
254 int_status |= acpi_ev_fixed_event_dispatch ((u32) i);
262 /*******************************************************************************
264 * FUNCTION: acpi_ev_fixed_event_dispatch
266 * PARAMETERS: Event - Event type
268 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
270 * DESCRIPTION: Clears the status bit for the requested event, calls the
271 * handler that previously registered for the event.
273 ******************************************************************************/
276 acpi_ev_fixed_event_dispatch (
281 ACPI_FUNCTION_ENTRY ();
284 /* Clear the status bit */
286 (void) acpi_set_register (acpi_gbl_fixed_event_info[event].status_register_id,
287 1, ACPI_MTX_DO_NOT_LOCK);
290 * Make sure we've got a handler. If not, report an error.
291 * The event is disabled to prevent further interrupts.
293 if (NULL == acpi_gbl_fixed_event_handlers[event].handler) {
294 (void) acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id,
295 0, ACPI_MTX_DO_NOT_LOCK);
298 ("No installed handler for fixed event [%08X]\n",
301 return (ACPI_INTERRUPT_NOT_HANDLED);
304 /* Invoke the Fixed Event handler */
306 return ((acpi_gbl_fixed_event_handlers[event].handler)(
307 acpi_gbl_fixed_event_handlers[event].context));