xref: /freebsd/sys/contrib/dev/acpica/components/events/evsci.c (revision ddd5b8e9b4d8957fce018c520657cdfa4ecffad3)
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 <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acevents.h>
48 
49 
50 #define _COMPONENT          ACPI_EVENTS
51         ACPI_MODULE_NAME    ("evsci")
52 
53 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
54 
55 /* Local prototypes */
56 
57 static UINT32 ACPI_SYSTEM_XFACE
58 AcpiEvSciXruptHandler (
59     void                    *Context);
60 
61 
62 /*******************************************************************************
63  *
64  * FUNCTION:    AcpiEvSciXruptHandler
65  *
66  * PARAMETERS:  Context   - Calling Context
67  *
68  * RETURN:      Status code indicates whether interrupt was handled.
69  *
70  * DESCRIPTION: Interrupt handler that will figure out what function or
71  *              control method to call to deal with a SCI.
72  *
73  ******************************************************************************/
74 
75 static UINT32 ACPI_SYSTEM_XFACE
76 AcpiEvSciXruptHandler (
77     void                    *Context)
78 {
79     ACPI_GPE_XRUPT_INFO     *GpeXruptList = Context;
80     UINT32                  InterruptHandled = ACPI_INTERRUPT_NOT_HANDLED;
81 
82 
83     ACPI_FUNCTION_TRACE (EvSciXruptHandler);
84 
85 
86     /*
87      * We are guaranteed by the ACPI CA initialization/shutdown code that
88      * if this interrupt handler is installed, ACPI is enabled.
89      */
90 
91     /*
92      * Fixed Events:
93      * Check for and dispatch any Fixed Events that have occurred
94      */
95     InterruptHandled |= AcpiEvFixedEventDetect ();
96 
97     /*
98      * General Purpose Events:
99      * Check for and dispatch any GPEs that have occurred
100      */
101     InterruptHandled |= AcpiEvGpeDetect (GpeXruptList);
102 
103     AcpiSciCount++;
104     return_UINT32 (InterruptHandled);
105 }
106 
107 
108 /*******************************************************************************
109  *
110  * FUNCTION:    AcpiEvGpeXruptHandler
111  *
112  * PARAMETERS:  Context   - Calling Context
113  *
114  * RETURN:      Status code indicates whether interrupt was handled.
115  *
116  * DESCRIPTION: Handler for GPE Block Device interrupts
117  *
118  ******************************************************************************/
119 
120 UINT32 ACPI_SYSTEM_XFACE
121 AcpiEvGpeXruptHandler (
122     void                    *Context)
123 {
124     ACPI_GPE_XRUPT_INFO     *GpeXruptList = Context;
125     UINT32                  InterruptHandled = ACPI_INTERRUPT_NOT_HANDLED;
126 
127 
128     ACPI_FUNCTION_TRACE (EvGpeXruptHandler);
129 
130 
131     /*
132      * We are guaranteed by the ACPI CA initialization/shutdown code that
133      * if this interrupt handler is installed, ACPI is enabled.
134      */
135 
136     /* GPEs: Check for and dispatch any GPEs that have occurred */
137 
138     InterruptHandled |= AcpiEvGpeDetect (GpeXruptList);
139 
140     return_UINT32 (InterruptHandled);
141 }
142 
143 
144 /******************************************************************************
145  *
146  * FUNCTION:    AcpiEvInstallSciHandler
147  *
148  * PARAMETERS:  none
149  *
150  * RETURN:      Status
151  *
152  * DESCRIPTION: Installs SCI handler.
153  *
154  ******************************************************************************/
155 
156 UINT32
157 AcpiEvInstallSciHandler (
158     void)
159 {
160     UINT32                  Status = AE_OK;
161 
162 
163     ACPI_FUNCTION_TRACE (EvInstallSciHandler);
164 
165 
166     Status = AcpiOsInstallInterruptHandler ((UINT32) AcpiGbl_FADT.SciInterrupt,
167                 AcpiEvSciXruptHandler, AcpiGbl_GpeXruptListHead);
168     return_ACPI_STATUS (Status);
169 }
170 
171 
172 /******************************************************************************
173  *
174  * FUNCTION:    AcpiEvRemoveSciHandler
175  *
176  * PARAMETERS:  none
177  *
178  * RETURN:      E_OK if handler uninstalled OK, E_ERROR if handler was not
179  *              installed to begin with
180  *
181  * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
182  *              taken.
183  *
184  * Note:  It doesn't seem important to disable all events or set the event
185  *        enable registers to their original values. The OS should disable
186  *        the SCI interrupt level when the handler is removed, so no more
187  *        events will come in.
188  *
189  ******************************************************************************/
190 
191 ACPI_STATUS
192 AcpiEvRemoveSciHandler (
193     void)
194 {
195     ACPI_STATUS             Status;
196 
197 
198     ACPI_FUNCTION_TRACE (EvRemoveSciHandler);
199 
200 
201     /* Just let the OS remove the handler and disable the level */
202 
203     Status = AcpiOsRemoveInterruptHandler ((UINT32) AcpiGbl_FADT.SciInterrupt,
204                 AcpiEvSciXruptHandler);
205 
206     return_ACPI_STATUS (Status);
207 }
208 
209 #endif /* !ACPI_REDUCED_HARDWARE */
210