blob: 94d9ebddf5755031a34b654664b0be6471330662 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: evsci - System Control Interrupt configuration and
4 * legacy to ACPI mode state transition functions
5 *
6 ******************************************************************************/
7
8/*
Bob Moore25f044e2013-01-25 05:38:56 +00009 * Copyright (C) 2000 - 2013, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acevents.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("evsci")
Bob Moore33620c52012-02-14 18:14:27 +080051#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040053static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/*******************************************************************************
56 *
Lv Zhenga2fd4b42013-09-23 09:52:05 +080057 * 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
67u32 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
Bob Moorec53ae3a2013-09-23 09:52:45 +080090 int_status |= sci_handler->address(sci_handler->context);
Lv Zhenga2fd4b42013-09-23 09:52:05 +080091
92 sci_handler = sci_handler->next;
93 }
94
95 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
96 return (int_status);
97}
98
99/*******************************************************************************
100 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 * FUNCTION: acpi_ev_sci_xrupt_handler
102 *
Bob Mooreba494be2012-07-12 09:40:10 +0800103 * PARAMETERS: context - Calling Context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 *
105 * RETURN: Status code indicates whether interrupt was handled.
106 *
107 * DESCRIPTION: Interrupt handler that will figure out what function or
108 * control method to call to deal with a SCI.
109 *
110 ******************************************************************************/
111
Len Brown4be44fc2005-08-05 00:44:28 -0400112static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Len Brown4be44fc2005-08-05 00:44:28 -0400114 struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
115 u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Bob Mooreb229cf92006-04-21 17:15:00 -0400117 ACPI_FUNCTION_TRACE(ev_sci_xrupt_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 /*
120 * We are guaranteed by the ACPI CA initialization/shutdown code that
121 * if this interrupt handler is installed, ACPI is enabled.
122 */
123
124 /*
125 * Fixed Events:
126 * Check for and dispatch any Fixed Events that have occurred
127 */
Len Brown4be44fc2005-08-05 00:44:28 -0400128 interrupt_handled |= acpi_ev_fixed_event_detect();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 /*
131 * General Purpose Events:
132 * Check for and dispatch any GPEs that have occurred
133 */
Len Brown4be44fc2005-08-05 00:44:28 -0400134 interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800136 /* Invoke all host-installed SCI handlers */
137
138 interrupt_handled |= acpi_ev_sci_dispatch();
139
Bob Moorefd1af712013-03-08 09:22:23 +0000140 return_UINT32(interrupt_handled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/*******************************************************************************
144 *
145 * FUNCTION: acpi_ev_gpe_xrupt_handler
146 *
Bob Mooreba494be2012-07-12 09:40:10 +0800147 * PARAMETERS: context - Calling Context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 *
149 * RETURN: Status code indicates whether interrupt was handled.
150 *
151 * DESCRIPTION: Handler for GPE Block Device interrupts
152 *
153 ******************************************************************************/
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_xrupt_handler(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Len Brown4be44fc2005-08-05 00:44:28 -0400157 struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
158 u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Bob Mooreb229cf92006-04-21 17:15:00 -0400160 ACPI_FUNCTION_TRACE(ev_gpe_xrupt_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /*
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800163 * We are guaranteed by the ACPICA initialization/shutdown code that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 * if this interrupt handler is installed, ACPI is enabled.
165 */
166
Bob Moore9f15fc62008-11-12 16:01:56 +0800167 /* GPEs: Check for and dispatch any GPEs that have occurred */
168
Len Brown4be44fc2005-08-05 00:44:28 -0400169 interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
Bob Moorefd1af712013-03-08 09:22:23 +0000170 return_UINT32(interrupt_handled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/******************************************************************************
174 *
175 * FUNCTION: acpi_ev_install_sci_handler
176 *
177 * PARAMETERS: none
178 *
179 * RETURN: Status
180 *
181 * DESCRIPTION: Installs SCI handler.
182 *
183 ******************************************************************************/
184
Len Brown4be44fc2005-08-05 00:44:28 -0400185u32 acpi_ev_install_sci_handler(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
Len Brown4be44fc2005-08-05 00:44:28 -0400187 u32 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Bob Mooreb229cf92006-04-21 17:15:00 -0400189 ACPI_FUNCTION_TRACE(ev_install_sci_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Bob Mooref3d2e782007-02-02 19:48:18 +0300191 status =
192 acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
193 acpi_ev_sci_xrupt_handler,
194 acpi_gbl_gpe_xrupt_list_head);
Len Brown4be44fc2005-08-05 00:44:28 -0400195 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/******************************************************************************
199 *
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800200 * FUNCTION: acpi_ev_remove_all_sci_handlers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 *
202 * PARAMETERS: none
203 *
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800204 * RETURN: AE_OK if handler uninstalled, AE_ERROR if handler was not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 * installed to begin with
206 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800207 * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800208 * taken. Remove all host-installed SCI handlers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 *
210 * Note: It doesn't seem important to disable all events or set the event
Bob Moore9f15fc62008-11-12 16:01:56 +0800211 * enable registers to their original values. The OS should disable
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 * the SCI interrupt level when the handler is removed, so no more
213 * events will come in.
214 *
215 ******************************************************************************/
216
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800217acpi_status acpi_ev_remove_all_sci_handlers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800219 struct acpi_sci_handler_info *sci_handler;
220 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400221 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800223 ACPI_FUNCTION_TRACE(ev_remove_all_sci_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 /* Just let the OS remove the handler and disable the level */
226
Bob Mooref3d2e782007-02-02 19:48:18 +0300227 status =
228 acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
229 acpi_ev_sci_xrupt_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800231 if (!acpi_gbl_sci_handler_list) {
232 return (status);
233 }
234
235 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
236
237 /* Free all host-installed SCI handlers */
238
239 while (acpi_gbl_sci_handler_list) {
240 sci_handler = acpi_gbl_sci_handler_list;
241 acpi_gbl_sci_handler_list = sci_handler->next;
242 ACPI_FREE(sci_handler);
243 }
244
245 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400246 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
Bob Moore33620c52012-02-14 18:14:27 +0800248
249#endif /* !ACPI_REDUCED_HARDWARE */