Linux 4.19.133
[linux/fpc-iii.git] / drivers / acpi / acpica / evevent.c
blobb3d07cc14d75d7dddc9149207c75b88a5954f01b
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: evevent - Fixed Event handling and dispatch
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
11 #include "accommon.h"
12 #include "acevents.h"
14 #define _COMPONENT ACPI_EVENTS
15 ACPI_MODULE_NAME("evevent")
16 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
17 /* Local prototypes */
18 static acpi_status acpi_ev_fixed_event_initialize(void);
20 static u32 acpi_ev_fixed_event_dispatch(u32 event);
22 /*******************************************************************************
24 * FUNCTION: acpi_ev_initialize_events
26 * PARAMETERS: None
28 * RETURN: Status
30 * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
32 ******************************************************************************/
34 acpi_status acpi_ev_initialize_events(void)
36 acpi_status status;
38 ACPI_FUNCTION_TRACE(ev_initialize_events);
40 /* If Hardware Reduced flag is set, there are no fixed events */
42 if (acpi_gbl_reduced_hardware) {
43 return_ACPI_STATUS(AE_OK);
47 * Initialize the Fixed and General Purpose Events. This is done prior to
48 * enabling SCIs to prevent interrupts from occurring before the handlers
49 * are installed.
51 status = acpi_ev_fixed_event_initialize();
52 if (ACPI_FAILURE(status)) {
53 ACPI_EXCEPTION((AE_INFO, status,
54 "Unable to initialize fixed events"));
55 return_ACPI_STATUS(status);
58 status = acpi_ev_gpe_initialize();
59 if (ACPI_FAILURE(status)) {
60 ACPI_EXCEPTION((AE_INFO, status,
61 "Unable to initialize general purpose events"));
62 return_ACPI_STATUS(status);
65 return_ACPI_STATUS(status);
68 /*******************************************************************************
70 * FUNCTION: acpi_ev_install_xrupt_handlers
72 * PARAMETERS: None
74 * RETURN: Status
76 * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
78 ******************************************************************************/
80 acpi_status acpi_ev_install_xrupt_handlers(void)
82 acpi_status status;
84 ACPI_FUNCTION_TRACE(ev_install_xrupt_handlers);
86 /* If Hardware Reduced flag is set, there is no ACPI h/w */
88 if (acpi_gbl_reduced_hardware) {
89 return_ACPI_STATUS(AE_OK);
92 /* Install the SCI handler */
94 status = acpi_ev_install_sci_handler();
95 if (ACPI_FAILURE(status)) {
96 ACPI_EXCEPTION((AE_INFO, status,
97 "Unable to install System Control Interrupt handler"));
98 return_ACPI_STATUS(status);
101 /* Install the handler for the Global Lock */
103 status = acpi_ev_init_global_lock_handler();
104 if (ACPI_FAILURE(status)) {
105 ACPI_EXCEPTION((AE_INFO, status,
106 "Unable to initialize Global Lock handler"));
107 return_ACPI_STATUS(status);
110 acpi_gbl_events_initialized = TRUE;
111 return_ACPI_STATUS(status);
114 /*******************************************************************************
116 * FUNCTION: acpi_ev_fixed_event_initialize
118 * PARAMETERS: None
120 * RETURN: Status
122 * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
124 ******************************************************************************/
126 static acpi_status acpi_ev_fixed_event_initialize(void)
128 u32 i;
129 acpi_status status;
132 * Initialize the structure that keeps track of fixed event handlers and
133 * enable the fixed events.
135 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
136 acpi_gbl_fixed_event_handlers[i].handler = NULL;
137 acpi_gbl_fixed_event_handlers[i].context = NULL;
139 /* Disable the fixed event */
141 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
142 status =
143 acpi_write_bit_register(acpi_gbl_fixed_event_info
144 [i].enable_register_id,
145 ACPI_DISABLE_EVENT);
146 if (ACPI_FAILURE(status)) {
147 return (status);
152 return (AE_OK);
155 /*******************************************************************************
157 * FUNCTION: acpi_ev_fixed_event_detect
159 * PARAMETERS: None
161 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
163 * DESCRIPTION: Checks the PM status register for active fixed events
165 ******************************************************************************/
167 u32 acpi_ev_fixed_event_detect(void)
169 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
170 u32 fixed_status;
171 u32 fixed_enable;
172 u32 i;
173 acpi_status status;
175 ACPI_FUNCTION_NAME(ev_fixed_event_detect);
178 * Read the fixed feature status and enable registers, as all the cases
179 * depend on their values. Ignore errors here.
181 status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, &fixed_status);
182 status |=
183 acpi_hw_register_read(ACPI_REGISTER_PM1_ENABLE, &fixed_enable);
184 if (ACPI_FAILURE(status)) {
185 return (int_status);
188 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
189 "Fixed Event Block: Enable %08X Status %08X\n",
190 fixed_enable, fixed_status));
193 * Check for all possible Fixed Events and dispatch those that are active
195 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
197 /* Both the status and enable bits must be on for this event */
199 if ((fixed_status & acpi_gbl_fixed_event_info[i].
200 status_bit_mask)
201 && (fixed_enable & acpi_gbl_fixed_event_info[i].
202 enable_bit_mask)) {
204 * Found an active (signalled) event. Invoke global event
205 * handler if present.
207 acpi_fixed_event_count[i]++;
208 if (acpi_gbl_global_event_handler) {
209 acpi_gbl_global_event_handler
210 (ACPI_EVENT_TYPE_FIXED, NULL, i,
211 acpi_gbl_global_event_handler_context);
214 int_status |= acpi_ev_fixed_event_dispatch(i);
218 return (int_status);
221 /*******************************************************************************
223 * FUNCTION: acpi_ev_fixed_event_dispatch
225 * PARAMETERS: event - Event type
227 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
229 * DESCRIPTION: Clears the status bit for the requested event, calls the
230 * handler that previously registered for the event.
231 * NOTE: If there is no handler for the event, the event is
232 * disabled to prevent further interrupts.
234 ******************************************************************************/
236 static u32 acpi_ev_fixed_event_dispatch(u32 event)
239 ACPI_FUNCTION_ENTRY();
241 /* Clear the status bit */
243 (void)acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
244 status_register_id, ACPI_CLEAR_STATUS);
247 * Make sure that a handler exists. If not, report an error
248 * and disable the event to prevent further interrupts.
250 if (!acpi_gbl_fixed_event_handlers[event].handler) {
251 (void)acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
252 enable_register_id,
253 ACPI_DISABLE_EVENT);
255 ACPI_ERROR((AE_INFO,
256 "No installed handler for fixed event - %s (%u), disabling",
257 acpi_ut_get_event_name(event), event));
259 return (ACPI_INTERRUPT_NOT_HANDLED);
262 /* Invoke the Fixed Event handler */
264 return ((acpi_gbl_fixed_event_handlers[event].
265 handler) (acpi_gbl_fixed_event_handlers[event].context));
268 #endif /* !ACPI_REDUCED_HARDWARE */