1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: evsci - System Control Interrupt configuration and
4433d6423SLionel Sambuc * legacy to ACPI mode state transition functions
5433d6423SLionel Sambuc *
6433d6423SLionel Sambuc ******************************************************************************/
7433d6423SLionel Sambuc
8*29492bb7SDavid van Moolenbroek /*
9*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
10433d6423SLionel Sambuc * All rights reserved.
11433d6423SLionel Sambuc *
12*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
13*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
14*29492bb7SDavid van Moolenbroek * are met:
15*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
16*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
17*29492bb7SDavid van Moolenbroek * without modification.
18*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
20*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
21*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
22*29492bb7SDavid van Moolenbroek * binary redistribution.
23*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
24*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
25*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
26433d6423SLionel Sambuc *
27*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
28*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
29*29492bb7SDavid van Moolenbroek * Software Foundation.
30433d6423SLionel Sambuc *
31*29492bb7SDavid van Moolenbroek * NO WARRANTY
32*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
43*29492bb7SDavid van Moolenbroek */
44433d6423SLionel Sambuc
45433d6423SLionel Sambuc #include "acpi.h"
46433d6423SLionel Sambuc #include "accommon.h"
47433d6423SLionel Sambuc #include "acevents.h"
48433d6423SLionel Sambuc
49433d6423SLionel Sambuc
50433d6423SLionel Sambuc #define _COMPONENT ACPI_EVENTS
51433d6423SLionel Sambuc ACPI_MODULE_NAME ("evsci")
52433d6423SLionel Sambuc
53*29492bb7SDavid van Moolenbroek #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
54*29492bb7SDavid van Moolenbroek
55433d6423SLionel Sambuc /* Local prototypes */
56433d6423SLionel Sambuc
57433d6423SLionel Sambuc static UINT32 ACPI_SYSTEM_XFACE
58433d6423SLionel Sambuc AcpiEvSciXruptHandler (
59433d6423SLionel Sambuc void *Context);
60433d6423SLionel Sambuc
61433d6423SLionel Sambuc
62433d6423SLionel Sambuc /*******************************************************************************
63433d6423SLionel Sambuc *
64*29492bb7SDavid van Moolenbroek * FUNCTION: AcpiEvSciDispatch
65*29492bb7SDavid van Moolenbroek *
66*29492bb7SDavid van Moolenbroek * PARAMETERS: None
67*29492bb7SDavid van Moolenbroek *
68*29492bb7SDavid van Moolenbroek * RETURN: Status code indicates whether interrupt was handled.
69*29492bb7SDavid van Moolenbroek *
70*29492bb7SDavid van Moolenbroek * DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers.
71*29492bb7SDavid van Moolenbroek *
72*29492bb7SDavid van Moolenbroek ******************************************************************************/
73*29492bb7SDavid van Moolenbroek
74*29492bb7SDavid van Moolenbroek UINT32
AcpiEvSciDispatch(void)75*29492bb7SDavid van Moolenbroek AcpiEvSciDispatch (
76*29492bb7SDavid van Moolenbroek void)
77*29492bb7SDavid van Moolenbroek {
78*29492bb7SDavid van Moolenbroek ACPI_SCI_HANDLER_INFO *SciHandler;
79*29492bb7SDavid van Moolenbroek ACPI_CPU_FLAGS Flags;
80*29492bb7SDavid van Moolenbroek UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
81*29492bb7SDavid van Moolenbroek
82*29492bb7SDavid van Moolenbroek
83*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_NAME (EvSciDispatch);
84*29492bb7SDavid van Moolenbroek
85*29492bb7SDavid van Moolenbroek
86*29492bb7SDavid van Moolenbroek /* Are there any host-installed SCI handlers? */
87*29492bb7SDavid van Moolenbroek
88*29492bb7SDavid van Moolenbroek if (!AcpiGbl_SciHandlerList)
89*29492bb7SDavid van Moolenbroek {
90*29492bb7SDavid van Moolenbroek return (IntStatus);
91*29492bb7SDavid van Moolenbroek }
92*29492bb7SDavid van Moolenbroek
93*29492bb7SDavid van Moolenbroek Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
94*29492bb7SDavid van Moolenbroek
95*29492bb7SDavid van Moolenbroek /* Invoke all host-installed SCI handlers */
96*29492bb7SDavid van Moolenbroek
97*29492bb7SDavid van Moolenbroek SciHandler = AcpiGbl_SciHandlerList;
98*29492bb7SDavid van Moolenbroek while (SciHandler)
99*29492bb7SDavid van Moolenbroek {
100*29492bb7SDavid van Moolenbroek /* Invoke the installed handler (at interrupt level) */
101*29492bb7SDavid van Moolenbroek
102*29492bb7SDavid van Moolenbroek IntStatus |= SciHandler->Address (
103*29492bb7SDavid van Moolenbroek SciHandler->Context);
104*29492bb7SDavid van Moolenbroek
105*29492bb7SDavid van Moolenbroek SciHandler = SciHandler->Next;
106*29492bb7SDavid van Moolenbroek }
107*29492bb7SDavid van Moolenbroek
108*29492bb7SDavid van Moolenbroek AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
109*29492bb7SDavid van Moolenbroek return (IntStatus);
110*29492bb7SDavid van Moolenbroek }
111*29492bb7SDavid van Moolenbroek
112*29492bb7SDavid van Moolenbroek
113*29492bb7SDavid van Moolenbroek /*******************************************************************************
114*29492bb7SDavid van Moolenbroek *
115433d6423SLionel Sambuc * FUNCTION: AcpiEvSciXruptHandler
116433d6423SLionel Sambuc *
117433d6423SLionel Sambuc * PARAMETERS: Context - Calling Context
118433d6423SLionel Sambuc *
119433d6423SLionel Sambuc * RETURN: Status code indicates whether interrupt was handled.
120433d6423SLionel Sambuc *
121433d6423SLionel Sambuc * DESCRIPTION: Interrupt handler that will figure out what function or
122433d6423SLionel Sambuc * control method to call to deal with a SCI.
123433d6423SLionel Sambuc *
124433d6423SLionel Sambuc ******************************************************************************/
125433d6423SLionel Sambuc
126433d6423SLionel Sambuc static UINT32 ACPI_SYSTEM_XFACE
AcpiEvSciXruptHandler(void * Context)127433d6423SLionel Sambuc AcpiEvSciXruptHandler (
128433d6423SLionel Sambuc void *Context)
129433d6423SLionel Sambuc {
130433d6423SLionel Sambuc ACPI_GPE_XRUPT_INFO *GpeXruptList = Context;
131433d6423SLionel Sambuc UINT32 InterruptHandled = ACPI_INTERRUPT_NOT_HANDLED;
132433d6423SLionel Sambuc
133433d6423SLionel Sambuc
134433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (EvSciXruptHandler);
135433d6423SLionel Sambuc
136433d6423SLionel Sambuc
137433d6423SLionel Sambuc /*
138433d6423SLionel Sambuc * We are guaranteed by the ACPICA initialization/shutdown code that
139433d6423SLionel Sambuc * if this interrupt handler is installed, ACPI is enabled.
140433d6423SLionel Sambuc */
141433d6423SLionel Sambuc
142433d6423SLionel Sambuc /*
143433d6423SLionel Sambuc * Fixed Events:
144433d6423SLionel Sambuc * Check for and dispatch any Fixed Events that have occurred
145433d6423SLionel Sambuc */
146433d6423SLionel Sambuc InterruptHandled |= AcpiEvFixedEventDetect ();
147433d6423SLionel Sambuc
148433d6423SLionel Sambuc /*
149433d6423SLionel Sambuc * General Purpose Events:
150433d6423SLionel Sambuc * Check for and dispatch any GPEs that have occurred
151433d6423SLionel Sambuc */
152433d6423SLionel Sambuc InterruptHandled |= AcpiEvGpeDetect (GpeXruptList);
153433d6423SLionel Sambuc
154*29492bb7SDavid van Moolenbroek /* Invoke all host-installed SCI handlers */
155*29492bb7SDavid van Moolenbroek
156*29492bb7SDavid van Moolenbroek InterruptHandled |= AcpiEvSciDispatch ();
157*29492bb7SDavid van Moolenbroek
158433d6423SLionel Sambuc AcpiSciCount++;
159433d6423SLionel Sambuc return_UINT32 (InterruptHandled);
160433d6423SLionel Sambuc }
161433d6423SLionel Sambuc
162433d6423SLionel Sambuc
163433d6423SLionel Sambuc /*******************************************************************************
164433d6423SLionel Sambuc *
165433d6423SLionel Sambuc * FUNCTION: AcpiEvGpeXruptHandler
166433d6423SLionel Sambuc *
167433d6423SLionel Sambuc * PARAMETERS: Context - Calling Context
168433d6423SLionel Sambuc *
169433d6423SLionel Sambuc * RETURN: Status code indicates whether interrupt was handled.
170433d6423SLionel Sambuc *
171433d6423SLionel Sambuc * DESCRIPTION: Handler for GPE Block Device interrupts
172433d6423SLionel Sambuc *
173433d6423SLionel Sambuc ******************************************************************************/
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc UINT32 ACPI_SYSTEM_XFACE
AcpiEvGpeXruptHandler(void * Context)176433d6423SLionel Sambuc AcpiEvGpeXruptHandler (
177433d6423SLionel Sambuc void *Context)
178433d6423SLionel Sambuc {
179433d6423SLionel Sambuc ACPI_GPE_XRUPT_INFO *GpeXruptList = Context;
180433d6423SLionel Sambuc UINT32 InterruptHandled = ACPI_INTERRUPT_NOT_HANDLED;
181433d6423SLionel Sambuc
182433d6423SLionel Sambuc
183433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (EvGpeXruptHandler);
184433d6423SLionel Sambuc
185433d6423SLionel Sambuc
186433d6423SLionel Sambuc /*
187433d6423SLionel Sambuc * We are guaranteed by the ACPICA initialization/shutdown code that
188433d6423SLionel Sambuc * if this interrupt handler is installed, ACPI is enabled.
189433d6423SLionel Sambuc */
190433d6423SLionel Sambuc
191433d6423SLionel Sambuc /* GPEs: Check for and dispatch any GPEs that have occurred */
192433d6423SLionel Sambuc
193433d6423SLionel Sambuc InterruptHandled |= AcpiEvGpeDetect (GpeXruptList);
194433d6423SLionel Sambuc return_UINT32 (InterruptHandled);
195433d6423SLionel Sambuc }
196433d6423SLionel Sambuc
197433d6423SLionel Sambuc
198433d6423SLionel Sambuc /******************************************************************************
199433d6423SLionel Sambuc *
200433d6423SLionel Sambuc * FUNCTION: AcpiEvInstallSciHandler
201433d6423SLionel Sambuc *
202433d6423SLionel Sambuc * PARAMETERS: none
203433d6423SLionel Sambuc *
204433d6423SLionel Sambuc * RETURN: Status
205433d6423SLionel Sambuc *
206433d6423SLionel Sambuc * DESCRIPTION: Installs SCI handler.
207433d6423SLionel Sambuc *
208433d6423SLionel Sambuc ******************************************************************************/
209433d6423SLionel Sambuc
210433d6423SLionel Sambuc UINT32
AcpiEvInstallSciHandler(void)211433d6423SLionel Sambuc AcpiEvInstallSciHandler (
212433d6423SLionel Sambuc void)
213433d6423SLionel Sambuc {
214433d6423SLionel Sambuc UINT32 Status = AE_OK;
215433d6423SLionel Sambuc
216433d6423SLionel Sambuc
217433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (EvInstallSciHandler);
218433d6423SLionel Sambuc
219433d6423SLionel Sambuc
220433d6423SLionel Sambuc Status = AcpiOsInstallInterruptHandler ((UINT32) AcpiGbl_FADT.SciInterrupt,
221433d6423SLionel Sambuc AcpiEvSciXruptHandler, AcpiGbl_GpeXruptListHead);
222433d6423SLionel Sambuc return_ACPI_STATUS (Status);
223433d6423SLionel Sambuc }
224433d6423SLionel Sambuc
225433d6423SLionel Sambuc
226433d6423SLionel Sambuc /******************************************************************************
227433d6423SLionel Sambuc *
228*29492bb7SDavid van Moolenbroek * FUNCTION: AcpiEvRemoveAllSciHandlers
229433d6423SLionel Sambuc *
230433d6423SLionel Sambuc * PARAMETERS: none
231433d6423SLionel Sambuc *
232*29492bb7SDavid van Moolenbroek * RETURN: AE_OK if handler uninstalled, AE_ERROR if handler was not
233433d6423SLionel Sambuc * installed to begin with
234433d6423SLionel Sambuc *
235433d6423SLionel Sambuc * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
236*29492bb7SDavid van Moolenbroek * taken. Remove all host-installed SCI handlers.
237433d6423SLionel Sambuc *
238433d6423SLionel Sambuc * Note: It doesn't seem important to disable all events or set the event
239433d6423SLionel Sambuc * enable registers to their original values. The OS should disable
240433d6423SLionel Sambuc * the SCI interrupt level when the handler is removed, so no more
241433d6423SLionel Sambuc * events will come in.
242433d6423SLionel Sambuc *
243433d6423SLionel Sambuc ******************************************************************************/
244433d6423SLionel Sambuc
245433d6423SLionel Sambuc ACPI_STATUS
AcpiEvRemoveAllSciHandlers(void)246*29492bb7SDavid van Moolenbroek AcpiEvRemoveAllSciHandlers (
247433d6423SLionel Sambuc void)
248433d6423SLionel Sambuc {
249*29492bb7SDavid van Moolenbroek ACPI_SCI_HANDLER_INFO *SciHandler;
250*29492bb7SDavid van Moolenbroek ACPI_CPU_FLAGS Flags;
251433d6423SLionel Sambuc ACPI_STATUS Status;
252433d6423SLionel Sambuc
253433d6423SLionel Sambuc
254*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_TRACE (EvRemoveAllSciHandlers);
255433d6423SLionel Sambuc
256433d6423SLionel Sambuc
257433d6423SLionel Sambuc /* Just let the OS remove the handler and disable the level */
258433d6423SLionel Sambuc
259433d6423SLionel Sambuc Status = AcpiOsRemoveInterruptHandler ((UINT32) AcpiGbl_FADT.SciInterrupt,
260433d6423SLionel Sambuc AcpiEvSciXruptHandler);
261433d6423SLionel Sambuc
262*29492bb7SDavid van Moolenbroek if (!AcpiGbl_SciHandlerList)
263*29492bb7SDavid van Moolenbroek {
264*29492bb7SDavid van Moolenbroek return (Status);
265*29492bb7SDavid van Moolenbroek }
266*29492bb7SDavid van Moolenbroek
267*29492bb7SDavid van Moolenbroek Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
268*29492bb7SDavid van Moolenbroek
269*29492bb7SDavid van Moolenbroek /* Free all host-installed SCI handlers */
270*29492bb7SDavid van Moolenbroek
271*29492bb7SDavid van Moolenbroek while (AcpiGbl_SciHandlerList)
272*29492bb7SDavid van Moolenbroek {
273*29492bb7SDavid van Moolenbroek SciHandler = AcpiGbl_SciHandlerList;
274*29492bb7SDavid van Moolenbroek AcpiGbl_SciHandlerList = SciHandler->Next;
275*29492bb7SDavid van Moolenbroek ACPI_FREE (SciHandler);
276*29492bb7SDavid van Moolenbroek }
277*29492bb7SDavid van Moolenbroek
278*29492bb7SDavid van Moolenbroek AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
279433d6423SLionel Sambuc return_ACPI_STATUS (Status);
280433d6423SLionel Sambuc }
281433d6423SLionel Sambuc
282*29492bb7SDavid van Moolenbroek #endif /* !ACPI_REDUCED_HARDWARE */
283