1 /******************************************************************************
3 * Module Name: evevent - Fixed Event handling and dispatch
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
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 <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acevents.h>
48 #define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME ("evevent")
51 /* Local prototypes */
54 AcpiEvFixedEventInitialize (
58 AcpiEvFixedEventDispatch (
62 /*******************************************************************************
64 * FUNCTION: AcpiEvInitializeEvents
70 * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
72 ******************************************************************************/
75 AcpiEvInitializeEvents (
81 ACPI_FUNCTION_TRACE (EvInitializeEvents);
85 * Initialize the Fixed and General Purpose Events. This is done prior to
86 * enabling SCIs to prevent interrupts from occurring before the handlers
89 Status = AcpiEvFixedEventInitialize ();
90 if (ACPI_FAILURE (Status))
92 ACPI_EXCEPTION ((AE_INFO, Status,
93 "Unable to initialize fixed events"));
94 return_ACPI_STATUS (Status);
97 Status = AcpiEvGpeInitialize ();
98 if (ACPI_FAILURE (Status))
100 ACPI_EXCEPTION ((AE_INFO, Status,
101 "Unable to initialize general purpose events"));
102 return_ACPI_STATUS (Status);
105 return_ACPI_STATUS (Status);
109 /*******************************************************************************
111 * FUNCTION: AcpiEvInstallXruptHandlers
117 * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
119 ******************************************************************************/
122 AcpiEvInstallXruptHandlers (
128 ACPI_FUNCTION_TRACE (EvInstallXruptHandlers);
131 /* Install the SCI handler */
133 Status = AcpiEvInstallSciHandler ();
134 if (ACPI_FAILURE (Status))
136 ACPI_EXCEPTION ((AE_INFO, Status,
137 "Unable to install System Control Interrupt handler"));
138 return_ACPI_STATUS (Status);
141 /* Install the handler for the Global Lock */
143 Status = AcpiEvInitGlobalLockHandler ();
144 if (ACPI_FAILURE (Status))
146 ACPI_EXCEPTION ((AE_INFO, Status,
147 "Unable to initialize Global Lock handler"));
148 return_ACPI_STATUS (Status);
151 AcpiGbl_EventsInitialized = TRUE;
152 return_ACPI_STATUS (Status);
156 /*******************************************************************************
158 * FUNCTION: AcpiEvFixedEventInitialize
164 * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
166 ******************************************************************************/
169 AcpiEvFixedEventInitialize (
177 * Initialize the structure that keeps track of fixed event handlers and
178 * enable the fixed events.
180 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
182 AcpiGbl_FixedEventHandlers[i].Handler = NULL;
183 AcpiGbl_FixedEventHandlers[i].Context = NULL;
185 /* Disable the fixed event */
187 if (AcpiGbl_FixedEventInfo[i].EnableRegisterId != 0xFF)
189 Status = AcpiWriteBitRegister (
190 AcpiGbl_FixedEventInfo[i].EnableRegisterId,
192 if (ACPI_FAILURE (Status))
203 /*******************************************************************************
205 * FUNCTION: AcpiEvFixedEventDetect
209 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
211 * DESCRIPTION: Checks the PM status register for active fixed events
213 ******************************************************************************/
216 AcpiEvFixedEventDetect (
219 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
225 ACPI_FUNCTION_NAME (EvFixedEventDetect);
229 * Read the fixed feature status and enable registers, as all the cases
230 * depend on their values. Ignore errors here.
232 (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_STATUS, &FixedStatus);
233 (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_ENABLE, &FixedEnable);
235 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
236 "Fixed Event Block: Enable %08X Status %08X\n",
237 FixedEnable, FixedStatus));
240 * Check for all possible Fixed Events and dispatch those that are active
242 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
244 /* Both the status and enable bits must be on for this event */
246 if ((FixedStatus & AcpiGbl_FixedEventInfo[i].StatusBitMask) &&
247 (FixedEnable & AcpiGbl_FixedEventInfo[i].EnableBitMask))
250 * Found an active (signalled) event. Invoke global event
251 * handler if present.
253 AcpiFixedEventCount[i]++;
254 if (AcpiGbl_GlobalEventHandler)
256 AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_FIXED, NULL,
257 i, AcpiGbl_GlobalEventHandlerContext);
260 IntStatus |= AcpiEvFixedEventDispatch (i);
268 /*******************************************************************************
270 * FUNCTION: AcpiEvFixedEventDispatch
272 * PARAMETERS: Event - Event type
274 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
276 * DESCRIPTION: Clears the status bit for the requested event, calls the
277 * handler that previously registered for the event.
279 ******************************************************************************/
282 AcpiEvFixedEventDispatch (
286 ACPI_FUNCTION_ENTRY ();
289 /* Clear the status bit */
291 (void) AcpiWriteBitRegister (
292 AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
296 * Make sure we've got a handler. If not, report an error. The event is
297 * disabled to prevent further interrupts.
299 if (NULL == AcpiGbl_FixedEventHandlers[Event].Handler)
301 (void) AcpiWriteBitRegister (
302 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
305 ACPI_ERROR ((AE_INFO,
306 "No installed handler for fixed event [0x%08X]",
309 return (ACPI_INTERRUPT_NOT_HANDLED);
312 /* Invoke the Fixed Event handler */
314 return ((AcpiGbl_FixedEventHandlers[Event].Handler)(
315 AcpiGbl_FixedEventHandlers[Event].Context));