1 /******************************************************************************
3 * Module Name: evevent - Fixed Event handling and dispatch
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, 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.
48 #define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME ("evevent")
51 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53 /* Local prototypes */
56 AcpiEvFixedEventInitialize (
60 AcpiEvFixedEventDispatch (
64 /*******************************************************************************
66 * FUNCTION: AcpiEvInitializeEvents
72 * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
74 ******************************************************************************/
77 AcpiEvInitializeEvents (
83 ACPI_FUNCTION_TRACE (EvInitializeEvents
);
86 /* If Hardware Reduced flag is set, there are no fixed events */
88 if (AcpiGbl_ReducedHardware
)
90 return_ACPI_STATUS (AE_OK
);
94 * Initialize the Fixed and General Purpose Events. This is done prior to
95 * enabling SCIs to prevent interrupts from occurring before the handlers
98 Status
= AcpiEvFixedEventInitialize ();
99 if (ACPI_FAILURE (Status
))
101 ACPI_EXCEPTION ((AE_INFO
, Status
,
102 "Unable to initialize fixed events"));
103 return_ACPI_STATUS (Status
);
106 Status
= AcpiEvGpeInitialize ();
107 if (ACPI_FAILURE (Status
))
109 ACPI_EXCEPTION ((AE_INFO
, Status
,
110 "Unable to initialize general purpose events"));
111 return_ACPI_STATUS (Status
);
114 return_ACPI_STATUS (Status
);
118 /*******************************************************************************
120 * FUNCTION: AcpiEvInstallXruptHandlers
126 * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
128 ******************************************************************************/
131 AcpiEvInstallXruptHandlers (
137 ACPI_FUNCTION_TRACE (EvInstallXruptHandlers
);
140 /* If Hardware Reduced flag is set, there is no ACPI h/w */
142 if (AcpiGbl_ReducedHardware
)
144 return_ACPI_STATUS (AE_OK
);
147 /* Install the SCI handler */
149 Status
= AcpiEvInstallSciHandler ();
150 if (ACPI_FAILURE (Status
))
152 ACPI_EXCEPTION ((AE_INFO
, Status
,
153 "Unable to install System Control Interrupt handler"));
154 return_ACPI_STATUS (Status
);
157 /* Install the handler for the Global Lock */
159 Status
= AcpiEvInitGlobalLockHandler ();
160 if (ACPI_FAILURE (Status
))
162 ACPI_EXCEPTION ((AE_INFO
, Status
,
163 "Unable to initialize Global Lock handler"));
164 return_ACPI_STATUS (Status
);
167 AcpiGbl_EventsInitialized
= TRUE
;
168 return_ACPI_STATUS (Status
);
172 /*******************************************************************************
174 * FUNCTION: AcpiEvFixedEventInitialize
180 * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
182 ******************************************************************************/
185 AcpiEvFixedEventInitialize (
193 * Initialize the structure that keeps track of fixed event handlers and
194 * enable the fixed events.
196 for (i
= 0; i
< ACPI_NUM_FIXED_EVENTS
; i
++)
198 AcpiGbl_FixedEventHandlers
[i
].Handler
= NULL
;
199 AcpiGbl_FixedEventHandlers
[i
].Context
= NULL
;
201 /* Disable the fixed event */
203 if (AcpiGbl_FixedEventInfo
[i
].EnableRegisterId
!= 0xFF)
205 Status
= AcpiWriteBitRegister (
206 AcpiGbl_FixedEventInfo
[i
].EnableRegisterId
,
208 if (ACPI_FAILURE (Status
))
219 /*******************************************************************************
221 * FUNCTION: AcpiEvFixedEventDetect
225 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
227 * DESCRIPTION: Checks the PM status register for active fixed events
229 ******************************************************************************/
232 AcpiEvFixedEventDetect (
235 UINT32 IntStatus
= ACPI_INTERRUPT_NOT_HANDLED
;
242 ACPI_FUNCTION_NAME (EvFixedEventDetect
);
246 * Read the fixed feature status and enable registers, as all the cases
247 * depend on their values. Ignore errors here.
249 Status
= AcpiHwRegisterRead (ACPI_REGISTER_PM1_STATUS
, &FixedStatus
);
250 Status
|= AcpiHwRegisterRead (ACPI_REGISTER_PM1_ENABLE
, &FixedEnable
);
251 if (ACPI_FAILURE (Status
))
256 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS
,
257 "Fixed Event Block: Enable %08X Status %08X\n",
258 FixedEnable
, FixedStatus
));
261 * Check for all possible Fixed Events and dispatch those that are active
263 for (i
= 0; i
< ACPI_NUM_FIXED_EVENTS
; i
++)
265 /* Both the status and enable bits must be on for this event */
267 if ((FixedStatus
& AcpiGbl_FixedEventInfo
[i
].StatusBitMask
) &&
268 (FixedEnable
& AcpiGbl_FixedEventInfo
[i
].EnableBitMask
))
271 * Found an active (signalled) event. Invoke global event
272 * handler if present.
274 AcpiFixedEventCount
[i
]++;
275 if (AcpiGbl_GlobalEventHandler
)
277 AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_FIXED
, NULL
,
278 i
, AcpiGbl_GlobalEventHandlerContext
);
281 IntStatus
|= AcpiEvFixedEventDispatch (i
);
289 /*******************************************************************************
291 * FUNCTION: AcpiEvFixedEventDispatch
293 * PARAMETERS: Event - Event type
295 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
297 * DESCRIPTION: Clears the status bit for the requested event, calls the
298 * handler that previously registered for the event.
299 * NOTE: If there is no handler for the event, the event is
300 * disabled to prevent further interrupts.
302 ******************************************************************************/
305 AcpiEvFixedEventDispatch (
309 ACPI_FUNCTION_ENTRY ();
312 /* Clear the status bit */
314 (void) AcpiWriteBitRegister (
315 AcpiGbl_FixedEventInfo
[Event
].StatusRegisterId
,
319 * Make sure that a handler exists. If not, report an error
320 * and disable the event to prevent further interrupts.
322 if (!AcpiGbl_FixedEventHandlers
[Event
].Handler
)
324 (void) AcpiWriteBitRegister (
325 AcpiGbl_FixedEventInfo
[Event
].EnableRegisterId
,
328 ACPI_ERROR ((AE_INFO
,
329 "No installed handler for fixed event - %s (%u), disabling",
330 AcpiUtGetEventName (Event
), Event
));
332 return (ACPI_INTERRUPT_NOT_HANDLED
);
335 /* Invoke the Fixed Event handler */
337 return ((AcpiGbl_FixedEventHandlers
[Event
].Handler
)(
338 AcpiGbl_FixedEventHandlers
[Event
].Context
));
341 #endif /* !ACPI_REDUCED_HARDWARE */