xref: /minix3/minix/drivers/power/acpi/events/evevent.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: evevent - Fixed Event handling and dispatch
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  *****************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acevents.h"
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc #define _COMPONENT          ACPI_EVENTS
49433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("evevent")
50433d6423SLionel Sambuc 
51*29492bb7SDavid van Moolenbroek #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
52*29492bb7SDavid van Moolenbroek 
53433d6423SLionel Sambuc /* Local prototypes */
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc static ACPI_STATUS
56433d6423SLionel Sambuc AcpiEvFixedEventInitialize (
57433d6423SLionel Sambuc     void);
58433d6423SLionel Sambuc 
59433d6423SLionel Sambuc static UINT32
60433d6423SLionel Sambuc AcpiEvFixedEventDispatch (
61433d6423SLionel Sambuc     UINT32                  Event);
62433d6423SLionel Sambuc 
63433d6423SLionel Sambuc 
64433d6423SLionel Sambuc /*******************************************************************************
65433d6423SLionel Sambuc  *
66433d6423SLionel Sambuc  * FUNCTION:    AcpiEvInitializeEvents
67433d6423SLionel Sambuc  *
68433d6423SLionel Sambuc  * PARAMETERS:  None
69433d6423SLionel Sambuc  *
70433d6423SLionel Sambuc  * RETURN:      Status
71433d6423SLionel Sambuc  *
72433d6423SLionel Sambuc  * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
73433d6423SLionel Sambuc  *
74433d6423SLionel Sambuc  ******************************************************************************/
75433d6423SLionel Sambuc 
76433d6423SLionel Sambuc ACPI_STATUS
AcpiEvInitializeEvents(void)77433d6423SLionel Sambuc AcpiEvInitializeEvents (
78433d6423SLionel Sambuc     void)
79433d6423SLionel Sambuc {
80433d6423SLionel Sambuc     ACPI_STATUS             Status;
81433d6423SLionel Sambuc 
82433d6423SLionel Sambuc 
83433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (EvInitializeEvents);
84433d6423SLionel Sambuc 
85433d6423SLionel Sambuc 
86*29492bb7SDavid van Moolenbroek     /* If Hardware Reduced flag is set, there are no fixed events */
87*29492bb7SDavid van Moolenbroek 
88*29492bb7SDavid van Moolenbroek     if (AcpiGbl_ReducedHardware)
89*29492bb7SDavid van Moolenbroek     {
90*29492bb7SDavid van Moolenbroek         return_ACPI_STATUS (AE_OK);
91*29492bb7SDavid van Moolenbroek     }
92*29492bb7SDavid van Moolenbroek 
93433d6423SLionel Sambuc     /*
94433d6423SLionel Sambuc      * Initialize the Fixed and General Purpose Events. This is done prior to
95433d6423SLionel Sambuc      * enabling SCIs to prevent interrupts from occurring before the handlers
96433d6423SLionel Sambuc      * are installed.
97433d6423SLionel Sambuc      */
98433d6423SLionel Sambuc     Status = AcpiEvFixedEventInitialize ();
99433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
100433d6423SLionel Sambuc     {
101433d6423SLionel Sambuc         ACPI_EXCEPTION ((AE_INFO, Status,
102433d6423SLionel Sambuc             "Unable to initialize fixed events"));
103433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
104433d6423SLionel Sambuc     }
105433d6423SLionel Sambuc 
106433d6423SLionel Sambuc     Status = AcpiEvGpeInitialize ();
107433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
108433d6423SLionel Sambuc     {
109433d6423SLionel Sambuc         ACPI_EXCEPTION ((AE_INFO, Status,
110433d6423SLionel Sambuc             "Unable to initialize general purpose events"));
111433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
112433d6423SLionel Sambuc     }
113433d6423SLionel Sambuc 
114433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
115433d6423SLionel Sambuc }
116433d6423SLionel Sambuc 
117433d6423SLionel Sambuc 
118433d6423SLionel Sambuc /*******************************************************************************
119433d6423SLionel Sambuc  *
120433d6423SLionel Sambuc  * FUNCTION:    AcpiEvInstallXruptHandlers
121433d6423SLionel Sambuc  *
122433d6423SLionel Sambuc  * PARAMETERS:  None
123433d6423SLionel Sambuc  *
124433d6423SLionel Sambuc  * RETURN:      Status
125433d6423SLionel Sambuc  *
126433d6423SLionel Sambuc  * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
127433d6423SLionel Sambuc  *
128433d6423SLionel Sambuc  ******************************************************************************/
129433d6423SLionel Sambuc 
130433d6423SLionel Sambuc ACPI_STATUS
AcpiEvInstallXruptHandlers(void)131433d6423SLionel Sambuc AcpiEvInstallXruptHandlers (
132433d6423SLionel Sambuc     void)
133433d6423SLionel Sambuc {
134433d6423SLionel Sambuc     ACPI_STATUS             Status;
135433d6423SLionel Sambuc 
136433d6423SLionel Sambuc 
137433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (EvInstallXruptHandlers);
138433d6423SLionel Sambuc 
139433d6423SLionel Sambuc 
140*29492bb7SDavid van Moolenbroek     /* If Hardware Reduced flag is set, there is no ACPI h/w */
141*29492bb7SDavid van Moolenbroek 
142*29492bb7SDavid van Moolenbroek     if (AcpiGbl_ReducedHardware)
143*29492bb7SDavid van Moolenbroek     {
144*29492bb7SDavid van Moolenbroek         return_ACPI_STATUS (AE_OK);
145*29492bb7SDavid van Moolenbroek     }
146*29492bb7SDavid van Moolenbroek 
147433d6423SLionel Sambuc     /* Install the SCI handler */
148433d6423SLionel Sambuc 
149433d6423SLionel Sambuc     Status = AcpiEvInstallSciHandler ();
150433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
151433d6423SLionel Sambuc     {
152433d6423SLionel Sambuc         ACPI_EXCEPTION ((AE_INFO, Status,
153433d6423SLionel Sambuc             "Unable to install System Control Interrupt handler"));
154433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
155433d6423SLionel Sambuc     }
156433d6423SLionel Sambuc 
157433d6423SLionel Sambuc     /* Install the handler for the Global Lock */
158433d6423SLionel Sambuc 
159433d6423SLionel Sambuc     Status = AcpiEvInitGlobalLockHandler ();
160433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
161433d6423SLionel Sambuc     {
162433d6423SLionel Sambuc         ACPI_EXCEPTION ((AE_INFO, Status,
163433d6423SLionel Sambuc             "Unable to initialize Global Lock handler"));
164433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
165433d6423SLionel Sambuc     }
166433d6423SLionel Sambuc 
167433d6423SLionel Sambuc     AcpiGbl_EventsInitialized = TRUE;
168433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
169433d6423SLionel Sambuc }
170433d6423SLionel Sambuc 
171433d6423SLionel Sambuc 
172433d6423SLionel Sambuc /*******************************************************************************
173433d6423SLionel Sambuc  *
174433d6423SLionel Sambuc  * FUNCTION:    AcpiEvFixedEventInitialize
175433d6423SLionel Sambuc  *
176433d6423SLionel Sambuc  * PARAMETERS:  None
177433d6423SLionel Sambuc  *
178433d6423SLionel Sambuc  * RETURN:      Status
179433d6423SLionel Sambuc  *
180433d6423SLionel Sambuc  * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
181433d6423SLionel Sambuc  *
182433d6423SLionel Sambuc  ******************************************************************************/
183433d6423SLionel Sambuc 
184433d6423SLionel Sambuc static ACPI_STATUS
AcpiEvFixedEventInitialize(void)185433d6423SLionel Sambuc AcpiEvFixedEventInitialize (
186433d6423SLionel Sambuc     void)
187433d6423SLionel Sambuc {
188433d6423SLionel Sambuc     UINT32                  i;
189433d6423SLionel Sambuc     ACPI_STATUS             Status;
190433d6423SLionel Sambuc 
191433d6423SLionel Sambuc 
192433d6423SLionel Sambuc     /*
193433d6423SLionel Sambuc      * Initialize the structure that keeps track of fixed event handlers and
194433d6423SLionel Sambuc      * enable the fixed events.
195433d6423SLionel Sambuc      */
196433d6423SLionel Sambuc     for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
197433d6423SLionel Sambuc     {
198433d6423SLionel Sambuc         AcpiGbl_FixedEventHandlers[i].Handler = NULL;
199433d6423SLionel Sambuc         AcpiGbl_FixedEventHandlers[i].Context = NULL;
200433d6423SLionel Sambuc 
201433d6423SLionel Sambuc         /* Disable the fixed event */
202433d6423SLionel Sambuc 
203433d6423SLionel Sambuc         if (AcpiGbl_FixedEventInfo[i].EnableRegisterId != 0xFF)
204433d6423SLionel Sambuc         {
205433d6423SLionel Sambuc             Status = AcpiWriteBitRegister (
206433d6423SLionel Sambuc                         AcpiGbl_FixedEventInfo[i].EnableRegisterId,
207433d6423SLionel Sambuc                         ACPI_DISABLE_EVENT);
208433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
209433d6423SLionel Sambuc             {
210433d6423SLionel Sambuc                 return (Status);
211433d6423SLionel Sambuc             }
212433d6423SLionel Sambuc         }
213433d6423SLionel Sambuc     }
214433d6423SLionel Sambuc 
215433d6423SLionel Sambuc     return (AE_OK);
216433d6423SLionel Sambuc }
217433d6423SLionel Sambuc 
218433d6423SLionel Sambuc 
219433d6423SLionel Sambuc /*******************************************************************************
220433d6423SLionel Sambuc  *
221433d6423SLionel Sambuc  * FUNCTION:    AcpiEvFixedEventDetect
222433d6423SLionel Sambuc  *
223433d6423SLionel Sambuc  * PARAMETERS:  None
224433d6423SLionel Sambuc  *
225433d6423SLionel Sambuc  * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
226433d6423SLionel Sambuc  *
227433d6423SLionel Sambuc  * DESCRIPTION: Checks the PM status register for active fixed events
228433d6423SLionel Sambuc  *
229433d6423SLionel Sambuc  ******************************************************************************/
230433d6423SLionel Sambuc 
231433d6423SLionel Sambuc UINT32
AcpiEvFixedEventDetect(void)232433d6423SLionel Sambuc AcpiEvFixedEventDetect (
233433d6423SLionel Sambuc     void)
234433d6423SLionel Sambuc {
235433d6423SLionel Sambuc     UINT32                  IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
236433d6423SLionel Sambuc     UINT32                  FixedStatus;
237433d6423SLionel Sambuc     UINT32                  FixedEnable;
238433d6423SLionel Sambuc     UINT32                  i;
239433d6423SLionel Sambuc 
240433d6423SLionel Sambuc 
241433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (EvFixedEventDetect);
242433d6423SLionel Sambuc 
243433d6423SLionel Sambuc 
244433d6423SLionel Sambuc     /*
245433d6423SLionel Sambuc      * Read the fixed feature status and enable registers, as all the cases
246433d6423SLionel Sambuc      * depend on their values. Ignore errors here.
247433d6423SLionel Sambuc      */
248433d6423SLionel Sambuc     (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_STATUS, &FixedStatus);
249433d6423SLionel Sambuc     (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_ENABLE, &FixedEnable);
250433d6423SLionel Sambuc 
251433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
252433d6423SLionel Sambuc         "Fixed Event Block: Enable %08X Status %08X\n",
253433d6423SLionel Sambuc         FixedEnable, FixedStatus));
254433d6423SLionel Sambuc 
255433d6423SLionel Sambuc     /*
256433d6423SLionel Sambuc      * Check for all possible Fixed Events and dispatch those that are active
257433d6423SLionel Sambuc      */
258433d6423SLionel Sambuc     for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
259433d6423SLionel Sambuc     {
260433d6423SLionel Sambuc         /* Both the status and enable bits must be on for this event */
261433d6423SLionel Sambuc 
262433d6423SLionel Sambuc         if ((FixedStatus & AcpiGbl_FixedEventInfo[i].StatusBitMask) &&
263433d6423SLionel Sambuc             (FixedEnable & AcpiGbl_FixedEventInfo[i].EnableBitMask))
264433d6423SLionel Sambuc         {
265*29492bb7SDavid van Moolenbroek             /*
266*29492bb7SDavid van Moolenbroek              * Found an active (signalled) event. Invoke global event
267*29492bb7SDavid van Moolenbroek              * handler if present.
268*29492bb7SDavid van Moolenbroek              */
269433d6423SLionel Sambuc             AcpiFixedEventCount[i]++;
270*29492bb7SDavid van Moolenbroek             if (AcpiGbl_GlobalEventHandler)
271*29492bb7SDavid van Moolenbroek             {
272*29492bb7SDavid van Moolenbroek                 AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_FIXED, NULL,
273*29492bb7SDavid van Moolenbroek                      i, AcpiGbl_GlobalEventHandlerContext);
274*29492bb7SDavid van Moolenbroek             }
275*29492bb7SDavid van Moolenbroek 
276433d6423SLionel Sambuc             IntStatus |= AcpiEvFixedEventDispatch (i);
277433d6423SLionel Sambuc         }
278433d6423SLionel Sambuc     }
279433d6423SLionel Sambuc 
280433d6423SLionel Sambuc     return (IntStatus);
281433d6423SLionel Sambuc }
282433d6423SLionel Sambuc 
283433d6423SLionel Sambuc 
284433d6423SLionel Sambuc /*******************************************************************************
285433d6423SLionel Sambuc  *
286433d6423SLionel Sambuc  * FUNCTION:    AcpiEvFixedEventDispatch
287433d6423SLionel Sambuc  *
288433d6423SLionel Sambuc  * PARAMETERS:  Event               - Event type
289433d6423SLionel Sambuc  *
290433d6423SLionel Sambuc  * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
291433d6423SLionel Sambuc  *
292433d6423SLionel Sambuc  * DESCRIPTION: Clears the status bit for the requested event, calls the
293433d6423SLionel Sambuc  *              handler that previously registered for the event.
294*29492bb7SDavid van Moolenbroek  *              NOTE: If there is no handler for the event, the event is
295*29492bb7SDavid van Moolenbroek  *              disabled to prevent further interrupts.
296433d6423SLionel Sambuc  *
297433d6423SLionel Sambuc  ******************************************************************************/
298433d6423SLionel Sambuc 
299433d6423SLionel Sambuc static UINT32
AcpiEvFixedEventDispatch(UINT32 Event)300433d6423SLionel Sambuc AcpiEvFixedEventDispatch (
301433d6423SLionel Sambuc     UINT32                  Event)
302433d6423SLionel Sambuc {
303433d6423SLionel Sambuc 
304433d6423SLionel Sambuc     ACPI_FUNCTION_ENTRY ();
305433d6423SLionel Sambuc 
306433d6423SLionel Sambuc 
307433d6423SLionel Sambuc     /* Clear the status bit */
308433d6423SLionel Sambuc 
309433d6423SLionel Sambuc     (void) AcpiWriteBitRegister (
310433d6423SLionel Sambuc             AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
311433d6423SLionel Sambuc             ACPI_CLEAR_STATUS);
312433d6423SLionel Sambuc 
313433d6423SLionel Sambuc     /*
314*29492bb7SDavid van Moolenbroek      * Make sure that a handler exists. If not, report an error
315*29492bb7SDavid van Moolenbroek      * and disable the event to prevent further interrupts.
316433d6423SLionel Sambuc      */
317*29492bb7SDavid van Moolenbroek     if (!AcpiGbl_FixedEventHandlers[Event].Handler)
318433d6423SLionel Sambuc     {
319433d6423SLionel Sambuc         (void) AcpiWriteBitRegister (
320433d6423SLionel Sambuc                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
321433d6423SLionel Sambuc                 ACPI_DISABLE_EVENT);
322433d6423SLionel Sambuc 
323433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
324*29492bb7SDavid van Moolenbroek             "No installed handler for fixed event - %s (%u), disabling",
325*29492bb7SDavid van Moolenbroek             AcpiUtGetEventName (Event), Event));
326433d6423SLionel Sambuc 
327433d6423SLionel Sambuc         return (ACPI_INTERRUPT_NOT_HANDLED);
328433d6423SLionel Sambuc     }
329433d6423SLionel Sambuc 
330433d6423SLionel Sambuc     /* Invoke the Fixed Event handler */
331433d6423SLionel Sambuc 
332433d6423SLionel Sambuc     return ((AcpiGbl_FixedEventHandlers[Event].Handler)(
333433d6423SLionel Sambuc                 AcpiGbl_FixedEventHandlers[Event].Context));
334433d6423SLionel Sambuc }
335433d6423SLionel Sambuc 
336*29492bb7SDavid van Moolenbroek #endif /* !ACPI_REDUCED_HARDWARE */
337