ACPICA: Add support for host-installed SCI handlers.
[pandora-kernel.git] / drivers / acpi / acpica / evsci.c
1 /*******************************************************************************
2  *
3  * Module Name: evsci - System Control Interrupt configuration and
4  *                      legacy to ACPI mode state transition functions
5  *
6  ******************************************************************************/
7
8 /*
9  * Copyright (C) 2000 - 2013, Intel Corp.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions, and the following disclaimer,
17  *    without modification.
18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19  *    substantially similar to the "NO WARRANTY" disclaimer below
20  *    ("Disclaimer") and any redistribution must be conditioned upon
21  *    including a substantially similar Disclaimer requirement for further
22  *    binary redistribution.
23  * 3. Neither the names of the above-listed copyright holders nor the names
24  *    of any contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * Alternatively, this software may be distributed under the terms of the
28  * GNU General Public License ("GPL") version 2 as published by the Free
29  * Software Foundation.
30  *
31  * NO WARRANTY
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGES.
43  */
44
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acevents.h"
48
49 #define _COMPONENT          ACPI_EVENTS
50 ACPI_MODULE_NAME("evsci")
51 #if (!ACPI_REDUCED_HARDWARE)    /* Entire module */
52 /* Local prototypes */
53 static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context);
54
55 /*******************************************************************************
56  *
57  * FUNCTION:    acpi_ev_sci_dispatch
58  *
59  * PARAMETERS:  None
60  *
61  * RETURN:      Status code indicates whether interrupt was handled.
62  *
63  * DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers.
64  *
65  ******************************************************************************/
66
67 u32 acpi_ev_sci_dispatch(void)
68 {
69         struct acpi_sci_handler_info *sci_handler;
70         acpi_cpu_flags flags;
71         u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
72
73         ACPI_FUNCTION_NAME(ev_sci_dispatch);
74
75         /* Are there any host-installed SCI handlers? */
76
77         if (!acpi_gbl_sci_handler_list) {
78                 return (int_status);
79         }
80
81         flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
82
83         /* Invoke all host-installed SCI handlers */
84
85         sci_handler = acpi_gbl_sci_handler_list;
86         while (sci_handler) {
87
88                 /* Invoke the installed handler (at interrupt level) */
89
90                 int_status |= sci_handler->address((u32)acpi_gbl_FADT.
91                                                    sci_interrupt,
92                                                    sci_handler->context);
93
94                 sci_handler = sci_handler->next;
95         }
96
97         acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
98         return (int_status);
99 }
100
101 /*******************************************************************************
102  *
103  * FUNCTION:    acpi_ev_sci_xrupt_handler
104  *
105  * PARAMETERS:  context   - Calling Context
106  *
107  * RETURN:      Status code indicates whether interrupt was handled.
108  *
109  * DESCRIPTION: Interrupt handler that will figure out what function or
110  *              control method to call to deal with a SCI.
111  *
112  ******************************************************************************/
113
114 static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context)
115 {
116         struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
117         u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
118
119         ACPI_FUNCTION_TRACE(ev_sci_xrupt_handler);
120
121         /*
122          * We are guaranteed by the ACPI CA initialization/shutdown code that
123          * if this interrupt handler is installed, ACPI is enabled.
124          */
125
126         /*
127          * Fixed Events:
128          * Check for and dispatch any Fixed Events that have occurred
129          */
130         interrupt_handled |= acpi_ev_fixed_event_detect();
131
132         /*
133          * General Purpose Events:
134          * Check for and dispatch any GPEs that have occurred
135          */
136         interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
137
138         /* Invoke all host-installed SCI handlers */
139
140         interrupt_handled |= acpi_ev_sci_dispatch();
141
142         return_UINT32(interrupt_handled);
143 }
144
145 /*******************************************************************************
146  *
147  * FUNCTION:    acpi_ev_gpe_xrupt_handler
148  *
149  * PARAMETERS:  context   - Calling Context
150  *
151  * RETURN:      Status code indicates whether interrupt was handled.
152  *
153  * DESCRIPTION: Handler for GPE Block Device interrupts
154  *
155  ******************************************************************************/
156
157 u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_xrupt_handler(void *context)
158 {
159         struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
160         u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
161
162         ACPI_FUNCTION_TRACE(ev_gpe_xrupt_handler);
163
164         /*
165          * We are guaranteed by the ACPICA initialization/shutdown code that
166          * if this interrupt handler is installed, ACPI is enabled.
167          */
168
169         /* GPEs: Check for and dispatch any GPEs that have occurred */
170
171         interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
172         return_UINT32(interrupt_handled);
173 }
174
175 /******************************************************************************
176  *
177  * FUNCTION:    acpi_ev_install_sci_handler
178  *
179  * PARAMETERS:  none
180  *
181  * RETURN:      Status
182  *
183  * DESCRIPTION: Installs SCI handler.
184  *
185  ******************************************************************************/
186
187 u32 acpi_ev_install_sci_handler(void)
188 {
189         u32 status = AE_OK;
190
191         ACPI_FUNCTION_TRACE(ev_install_sci_handler);
192
193         status =
194             acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
195                                               acpi_ev_sci_xrupt_handler,
196                                               acpi_gbl_gpe_xrupt_list_head);
197         return_ACPI_STATUS(status);
198 }
199
200 /******************************************************************************
201  *
202  * FUNCTION:    acpi_ev_remove_all_sci_handlers
203  *
204  * PARAMETERS:  none
205  *
206  * RETURN:      AE_OK if handler uninstalled, AE_ERROR if handler was not
207  *              installed to begin with
208  *
209  * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
210  *              taken. Remove all host-installed SCI handlers.
211  *
212  * Note:  It doesn't seem important to disable all events or set the event
213  *        enable registers to their original values. The OS should disable
214  *        the SCI interrupt level when the handler is removed, so no more
215  *        events will come in.
216  *
217  ******************************************************************************/
218
219 acpi_status acpi_ev_remove_all_sci_handlers(void)
220 {
221         struct acpi_sci_handler_info *sci_handler;
222         acpi_cpu_flags flags;
223         acpi_status status;
224
225         ACPI_FUNCTION_TRACE(ev_remove_all_sci_handlers);
226
227         /* Just let the OS remove the handler and disable the level */
228
229         status =
230             acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
231                                              acpi_ev_sci_xrupt_handler);
232
233         if (!acpi_gbl_sci_handler_list) {
234                 return (status);
235         }
236
237         flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
238
239         /* Free all host-installed SCI handlers */
240
241         while (acpi_gbl_sci_handler_list) {
242                 sci_handler = acpi_gbl_sci_handler_list;
243                 acpi_gbl_sci_handler_list = sci_handler->next;
244                 ACPI_FREE(sci_handler);
245         }
246
247         acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
248         return_ACPI_STATUS(status);
249 }
250
251 #endif                          /* !ACPI_REDUCED_HARDWARE */