^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: evsci - System Control Interrupt configuration and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * legacy to ACPI mode state transition functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "acevents.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define _COMPONENT ACPI_EVENTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) ACPI_MODULE_NAME("evsci")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * FUNCTION: acpi_ev_sci_dispatch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * PARAMETERS: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * RETURN: Status code indicates whether interrupt was handled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u32 acpi_ev_sci_dispatch(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct acpi_sci_handler_info *sci_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ACPI_FUNCTION_NAME(ev_sci_dispatch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* Are there any host-installed SCI handlers? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (!acpi_gbl_sci_handler_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return (int_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* Invoke all host-installed SCI handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) sci_handler = acpi_gbl_sci_handler_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) while (sci_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* Invoke the installed handler (at interrupt level) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int_status |= sci_handler->address(sci_handler->context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) sci_handler = sci_handler->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return (int_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * FUNCTION: acpi_ev_sci_xrupt_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * PARAMETERS: context - Calling Context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * RETURN: Status code indicates whether interrupt was handled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * DESCRIPTION: Interrupt handler that will figure out what function or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * control method to call to deal with a SCI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ACPI_FUNCTION_TRACE(ev_sci_xrupt_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * We are guaranteed by the ACPICA initialization/shutdown code that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * if this interrupt handler is installed, ACPI is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * Fixed Events:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * Check for and dispatch any Fixed Events that have occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) interrupt_handled |= acpi_ev_fixed_event_detect();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * General Purpose Events:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * Check for and dispatch any GPEs that have occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* Invoke all host-installed SCI handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) interrupt_handled |= acpi_ev_sci_dispatch();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) acpi_sci_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return_UINT32(interrupt_handled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * FUNCTION: acpi_ev_gpe_xrupt_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * PARAMETERS: context - Calling Context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * RETURN: Status code indicates whether interrupt was handled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * DESCRIPTION: Handler for GPE Block Device interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_xrupt_handler(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct acpi_gpe_xrupt_info *gpe_xrupt_list = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ACPI_FUNCTION_TRACE(ev_gpe_xrupt_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * We are guaranteed by the ACPICA initialization/shutdown code that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * if this interrupt handler is installed, ACPI is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* GPEs: Check for and dispatch any GPEs that have occurred */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return_UINT32(interrupt_handled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * FUNCTION: acpi_ev_install_sci_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * PARAMETERS: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * DESCRIPTION: Installs SCI handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) u32 acpi_ev_install_sci_handler(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u32 status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ACPI_FUNCTION_TRACE(ev_install_sci_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) acpi_ev_sci_xrupt_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) acpi_gbl_gpe_xrupt_list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * FUNCTION: acpi_ev_remove_all_sci_handlers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * PARAMETERS: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * RETURN: AE_OK if handler uninstalled, AE_ERROR if handler was not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * installed to begin with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * taken. Remove all host-installed SCI handlers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * Note: It doesn't seem important to disable all events or set the event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * enable registers to their original values. The OS should disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * the SCI interrupt level when the handler is removed, so no more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * events will come in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) acpi_status acpi_ev_remove_all_sci_handlers(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct acpi_sci_handler_info *sci_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ACPI_FUNCTION_TRACE(ev_remove_all_sci_handlers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* Just let the OS remove the handler and disable the level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) acpi_ev_sci_xrupt_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!acpi_gbl_sci_handler_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Free all host-installed SCI handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) while (acpi_gbl_sci_handler_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) sci_handler = acpi_gbl_sci_handler_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) acpi_gbl_sci_handler_list = sci_handler->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ACPI_FREE(sci_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #endif /* !ACPI_REDUCED_HARDWARE */