Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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: evxface - External interfaces for ACPI events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 2000 - 2020, Intel Corp.
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #define EXPORT_ACPI_INTERFACES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include "acnamesp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include "acevents.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include "acinterp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #define _COMPONENT          ACPI_EVENTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) ACPI_MODULE_NAME("evxface")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #if (!ACPI_REDUCED_HARDWARE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) acpi_ev_install_gpe_handler(acpi_handle gpe_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 			    u32 gpe_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 			    u32 type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 			    u8 is_raw_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 			    acpi_gpe_handler address, void *context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  * FUNCTION:    acpi_install_notify_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  * PARAMETERS:  device          - The device for which notifies will be handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  *              handler_type    - The type of handler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *                                  ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  *                                  ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *                                  ACPI_ALL_NOTIFY:    Both System and Device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  *              handler         - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  *              context         - Value passed to the handler on each GPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  * DESCRIPTION: Install a handler for notifications on an ACPI Device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  *              thermal_zone, or Processor object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  * NOTES:       The Root namespace object may have only one handler for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)  *              type of notify (System/Device). Device/Thermal/Processor objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  *              may have one device notify handler, and multiple system notify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  *              handlers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) acpi_install_notify_handler(acpi_handle device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 			    u32 handler_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 			    acpi_notify_handler handler, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	struct acpi_namespace_node *node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	    ACPI_CAST_PTR(struct acpi_namespace_node, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	union acpi_operand_object *obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	union acpi_operand_object *handler_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	ACPI_FUNCTION_TRACE(acpi_install_notify_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	/* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	if ((!device) || (!handler) || (!handler_type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	    (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 		return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	 * Root Object:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	 * Registering a notify handler on the root object indicates that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	 * caller wishes to receive notifications for all objects. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	 * only one global handler can be registered per notify type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	 * Ensure that a handler is not already installed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	if (device == ACPI_ROOT_OBJECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 		for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 			if (handler_type & (i + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 				if (acpi_gbl_global_notify[i].handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 					status = AE_ALREADY_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 					goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 				acpi_gbl_global_notify[i].handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 				acpi_gbl_global_notify[i].context = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 		goto unlock_and_exit;	/* Global notify handler installed, all done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	 * All Other Objects:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	 * Caller will only receive notifications specific to the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	 * object. Note that only certain object types are allowed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	 * receive notifications.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	/* Are Notifies allowed on this object? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	if (!acpi_ev_is_notify_object(node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		status = AE_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 		goto unlock_and_exit;
^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) 	/* Check for an existing internal object, might not exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	obj_desc = acpi_ns_get_attached_object(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	if (!obj_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 		/* Create a new object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		obj_desc = acpi_ut_create_internal_object(node->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		if (!obj_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 			status = AE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 			goto unlock_and_exit;
^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) 		/* Attach new object to the Node, remove local reference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 		status = acpi_ns_attach_object(device, obj_desc, node->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		acpi_ut_remove_reference(obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 			goto unlock_and_exit;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	/* Ensure that the handler is not already installed in the lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 		if (handler_type & (i + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 			handler_obj = obj_desc->common_notify.notify_list[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 			while (handler_obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 				if (handler_obj->notify.handler == handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 					status = AE_ALREADY_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 					goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 				handler_obj = handler_obj->notify.next[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	/* Create and populate a new notify handler object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	handler_obj = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	if (!handler_obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		status = AE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 		goto unlock_and_exit;
^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) 	handler_obj->notify.node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	handler_obj->notify.handler_type = handler_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	handler_obj->notify.handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	handler_obj->notify.context = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	/* Install the handler at the list head(s) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		if (handler_type & (i + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 			handler_obj->notify.next[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 			    obj_desc->common_notify.notify_list[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 			obj_desc->common_notify.notify_list[i] = handler_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		}
^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) 	/* Add an extra reference if handler was installed in both lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	if (handler_type == ACPI_ALL_NOTIFY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		acpi_ut_add_reference(handler_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) unlock_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) ACPI_EXPORT_SYMBOL(acpi_install_notify_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  * FUNCTION:    acpi_remove_notify_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)  * PARAMETERS:  device          - The device for which the handler is installed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)  *              handler_type    - The type of handler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200)  *                                  ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201)  *                                  ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202)  *                                  ACPI_ALL_NOTIFY:    Both System and Device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203)  *              handler         - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207)  * DESCRIPTION: Remove a handler for notifies on an ACPI device
^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_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) acpi_remove_notify_handler(acpi_handle device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 			   u32 handler_type, acpi_notify_handler handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	struct acpi_namespace_node *node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	    ACPI_CAST_PTR(struct acpi_namespace_node, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	union acpi_operand_object *obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	union acpi_operand_object *handler_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	union acpi_operand_object *previous_handler_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	ACPI_FUNCTION_TRACE(acpi_remove_notify_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	/* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	if ((!device) || (!handler) || (!handler_type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	    (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	/* Root Object. Global handlers are removed here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	if (device == ACPI_ROOT_OBJECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			if (handler_type & (i + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 				status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 				    acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 				if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 					return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 				if (!acpi_gbl_global_notify[i].handler ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 				    (acpi_gbl_global_notify[i].handler !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 				     handler)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 					status = AE_NOT_EXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 					goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 				ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 						  "Removing global notify handler\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 				acpi_gbl_global_notify[i].handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 				acpi_gbl_global_notify[i].context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 				(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 				/* Make sure all deferred notify tasks are completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 				acpi_os_wait_events_complete();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	/* All other objects: Are Notifies allowed on this object? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	if (!acpi_ev_is_notify_object(node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		return_ACPI_STATUS(AE_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	/* Must have an existing internal object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	obj_desc = acpi_ns_get_attached_object(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	if (!obj_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		return_ACPI_STATUS(AE_NOT_EXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	/* Internal object exists. Find the handler and remove it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		if (handler_type & (i + 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 			status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 			if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 				return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			handler_obj = obj_desc->common_notify.notify_list[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 			previous_handler_obj = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 			/* Attempt to find the handler in the handler list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 			while (handler_obj &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 			       (handler_obj->notify.handler != handler)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 				previous_handler_obj = handler_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 				handler_obj = handler_obj->notify.next[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			if (!handler_obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 				status = AE_NOT_EXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 				goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			/* Remove the handler object from the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 			if (previous_handler_obj) {	/* Handler is not at the list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 				previous_handler_obj->notify.next[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 				    handler_obj->notify.next[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			} else {	/* Handler is at the list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 				obj_desc->common_notify.notify_list[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 				    handler_obj->notify.next[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 			/* Make sure all deferred notify tasks are completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 			acpi_os_wait_events_complete();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			acpi_ut_remove_reference(handler_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) unlock_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335)  * FUNCTION:    acpi_install_exception_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337)  * PARAMETERS:  handler         - Pointer to the handler function for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338)  *                                event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342)  * DESCRIPTION: Saves the pointer to the handler function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) #ifdef ACPI_FUTURE_USAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	ACPI_FUNCTION_TRACE(acpi_install_exception_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	/* Don't allow two handlers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	if (acpi_gbl_exception_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		status = AE_ALREADY_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	/* Install the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	acpi_gbl_exception_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) #if (!ACPI_REDUCED_HARDWARE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)  * FUNCTION:    acpi_install_sci_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381)  * PARAMETERS:  address             - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382)  *              context             - Value passed to the handler on each SCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386)  * DESCRIPTION: Install a handler for a System Control Interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) acpi_status acpi_install_sci_handler(acpi_sci_handler address, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	struct acpi_sci_handler_info *new_sci_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	struct acpi_sci_handler_info *sci_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	ACPI_FUNCTION_TRACE(acpi_install_sci_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	if (!address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	/* Allocate and init a handler object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	new_sci_handler = ACPI_ALLOCATE(sizeof(struct acpi_sci_handler_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (!new_sci_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	new_sci_handler->address = address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	new_sci_handler->context = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	/* Lock list during installation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	sci_handler = acpi_gbl_sci_handler_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	/* Ensure handler does not already exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	while (sci_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		if (address == sci_handler->address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 			status = AE_ALREADY_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 			goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		sci_handler = sci_handler->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	/* Install the new handler into the global list (at head) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	new_sci_handler->next = acpi_gbl_sci_handler_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	acpi_gbl_sci_handler_list = new_sci_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) unlock_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		ACPI_FREE(new_sci_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) ACPI_EXPORT_SYMBOL(acpi_install_sci_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454)  * FUNCTION:    acpi_remove_sci_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456)  * PARAMETERS:  address             - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460)  * DESCRIPTION: Remove a handler for a System Control Interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) acpi_status acpi_remove_sci_handler(acpi_sci_handler address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	struct acpi_sci_handler_info *prev_sci_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	struct acpi_sci_handler_info *next_sci_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	ACPI_FUNCTION_TRACE(acpi_remove_sci_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	if (!address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	/* Remove the SCI handler with lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	prev_sci_handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	next_sci_handler = acpi_gbl_sci_handler_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	while (next_sci_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		if (next_sci_handler->address == address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			/* Unlink and free the SCI handler info block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			if (prev_sci_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 				prev_sci_handler->next = next_sci_handler->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 				acpi_gbl_sci_handler_list =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 				    next_sci_handler->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			ACPI_FREE(next_sci_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		prev_sci_handler = next_sci_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		next_sci_handler = next_sci_handler->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	status = AE_NOT_EXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) unlock_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) ACPI_EXPORT_SYMBOL(acpi_remove_sci_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)  * FUNCTION:    acpi_install_global_event_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522)  * PARAMETERS:  handler         - Pointer to the global event handler function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523)  *              context         - Value passed to the handler on each event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527)  * DESCRIPTION: Saves the pointer to the handler function. The global handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528)  *              is invoked upon each incoming GPE and Fixed Event. It is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529)  *              invoked at interrupt level at the time of the event dispatch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530)  *              Can be used to update event counters, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) acpi_install_global_event_handler(acpi_gbl_event_handler handler, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	ACPI_FUNCTION_TRACE(acpi_install_global_event_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	/* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	if (!handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	/* Don't allow two handlers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	if (acpi_gbl_global_event_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		status = AE_ALREADY_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	acpi_gbl_global_event_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	acpi_gbl_global_event_handler_context = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570)  * FUNCTION:    acpi_install_fixed_event_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572)  * PARAMETERS:  event           - Event type to enable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573)  *              handler         - Pointer to the handler function for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574)  *                                event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575)  *              context         - Value passed to the handler on each GPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579)  * DESCRIPTION: Saves the pointer to the handler function and then enables the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580)  *              event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) acpi_install_fixed_event_handler(u32 event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 				 acpi_event_handler handler, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	/* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	if (event > ACPI_EVENT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	/* Do not allow multiple handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	if (acpi_gbl_fixed_event_handlers[event].handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		status = AE_ALREADY_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	/* Install the handler before enabling the event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	acpi_gbl_fixed_event_handlers[event].handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	acpi_gbl_fixed_event_handlers[event].context = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	status = acpi_clear_event(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		status = acpi_enable_event(event, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		ACPI_WARNING((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 			      "Could not enable fixed event - %s (%u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 			      acpi_ut_get_event_name(event), event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		/* Remove the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		acpi_gbl_fixed_event_handlers[event].handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		acpi_gbl_fixed_event_handlers[event].context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 				  "Enabled fixed event %s (%X), Handler=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 				  acpi_ut_get_event_name(event), event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 				  handler));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642)  * FUNCTION:    acpi_remove_fixed_event_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644)  * PARAMETERS:  event           - Event type to disable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645)  *              handler         - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649)  * DESCRIPTION: Disables the event and unregisters the event handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	/* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	if (event > ACPI_EVENT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	/* Disable the event before removing the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	status = acpi_disable_event(event, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	/* Always Remove the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	acpi_gbl_fixed_event_handlers[event].handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	acpi_gbl_fixed_event_handlers[event].context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		ACPI_WARNING((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			      "Could not disable fixed event - %s (%u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			      acpi_ut_get_event_name(event), event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 				  "Disabled fixed event - %s (%X)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 				  acpi_ut_get_event_name(event), event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697)  * FUNCTION:    acpi_ev_install_gpe_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699)  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700)  *                                defined GPEs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701)  *              gpe_number      - The GPE number within the GPE block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702)  *              type            - Whether this GPE should be treated as an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703)  *                                edge- or level-triggered interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)  *              is_raw_handler  - Whether this GPE should be handled using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)  *                                the special GPE handler mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)  *              address         - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)  *              context         - Value passed to the handler on each GPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711)  * DESCRIPTION: Internal function to install a handler for a General Purpose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712)  *              Event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) acpi_ev_install_gpe_handler(acpi_handle gpe_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			    u32 gpe_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 			    u32 type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			    u8 is_raw_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			    acpi_gpe_handler address, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	struct acpi_gpe_event_info *gpe_event_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	struct acpi_gpe_handler_info *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	ACPI_FUNCTION_TRACE(ev_install_gpe_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	/* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	/* Allocate and init handler object (before lock) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	if (!handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		status = AE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	/* Ensure that we have a valid GPE number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	if (!gpe_event_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		status = AE_BAD_PARAMETER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		goto free_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	/* Make sure that there isn't a handler there already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	     ACPI_GPE_DISPATCH_HANDLER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	    (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	     ACPI_GPE_DISPATCH_RAW_HANDLER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		status = AE_ALREADY_EXISTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		goto free_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	handler->address = address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	handler->context = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	handler->method_node = gpe_event_info->dispatch.method_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	handler->original_flags = (u8)(gpe_event_info->flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 				       (ACPI_GPE_XRUPT_TYPE_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 					ACPI_GPE_DISPATCH_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	 * If the GPE is associated with a method, it may have been enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	 * automatically during initialization, in which case it has to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	 * disabled now to avoid spurious execution of the handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	if (((ACPI_GPE_DISPATCH_TYPE(handler->original_flags) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	      ACPI_GPE_DISPATCH_METHOD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	     (ACPI_GPE_DISPATCH_TYPE(handler->original_flags) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	      ACPI_GPE_DISPATCH_NOTIFY)) && gpe_event_info->runtime_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		handler->originally_enabled = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		(void)acpi_ev_remove_gpe_reference(gpe_event_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		/* Sanity check of original type against new type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		if (type !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		    (u32)(gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 			ACPI_WARNING((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 				      "GPE type mismatch (level/edge)"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	/* Install the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	gpe_event_info->dispatch.handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	/* Setup up dispatch flags to indicate handler (vs. method/notify) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	gpe_event_info->flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	    ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	gpe_event_info->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	    (u8)(type |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		 (is_raw_handler ? ACPI_GPE_DISPATCH_RAW_HANDLER :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		  ACPI_GPE_DISPATCH_HANDLER));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) unlock_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) free_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	ACPI_FREE(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823)  * FUNCTION:    acpi_install_gpe_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  *                                defined GPEs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  *              gpe_number      - The GPE number within the GPE block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828)  *              type            - Whether this GPE should be treated as an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829)  *                                edge- or level-triggered interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830)  *              address         - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831)  *              context         - Value passed to the handler on each GPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835)  * DESCRIPTION: Install a handler for a General Purpose Event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) acpi_install_gpe_handler(acpi_handle gpe_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			 u32 gpe_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 			 u32 type, acpi_gpe_handler address, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	ACPI_FUNCTION_TRACE(acpi_install_gpe_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	status = acpi_ev_install_gpe_handler(gpe_device, gpe_number, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 					     FALSE, address, context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858)  * FUNCTION:    acpi_install_gpe_raw_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860)  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861)  *                                defined GPEs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862)  *              gpe_number      - The GPE number within the GPE block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863)  *              type            - Whether this GPE should be treated as an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864)  *                                edge- or level-triggered interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865)  *              address         - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866)  *              context         - Value passed to the handler on each GPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870)  * DESCRIPTION: Install a handler for a General Purpose Event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) acpi_install_gpe_raw_handler(acpi_handle gpe_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 			     u32 gpe_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 			     u32 type, acpi_gpe_handler address, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	ACPI_FUNCTION_TRACE(acpi_install_gpe_raw_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	status = acpi_ev_install_gpe_handler(gpe_device, gpe_number, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 					     TRUE, address, context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) ACPI_EXPORT_SYMBOL(acpi_install_gpe_raw_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892)  * FUNCTION:    acpi_remove_gpe_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894)  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895)  *                                defined GPEs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896)  *              gpe_number      - The event to remove a handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897)  *              address         - Address of the handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901)  * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) acpi_remove_gpe_handler(acpi_handle gpe_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 			u32 gpe_number, acpi_gpe_handler address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	struct acpi_gpe_event_info *gpe_event_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	struct acpi_gpe_handler_info *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	/* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	if (!address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	/* Ensure that we have a valid GPE number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	if (!gpe_event_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		status = AE_BAD_PARAMETER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	/* Make sure that a handler is indeed installed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	     ACPI_GPE_DISPATCH_HANDLER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	    (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	     ACPI_GPE_DISPATCH_RAW_HANDLER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		status = AE_NOT_EXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	/* Make sure that the installed handler is the same */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	if (gpe_event_info->dispatch.handler->address != address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		status = AE_BAD_PARAMETER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	/* Remove the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	handler = gpe_event_info->dispatch.handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	gpe_event_info->dispatch.handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	/* Restore Method node (if any), set dispatch flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	gpe_event_info->dispatch.method_node = handler->method_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	gpe_event_info->flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	    ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	gpe_event_info->flags |= handler->original_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	 * If the GPE was previously associated with a method and it was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	 * enabled, it should be enabled at this point to restore the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	 * post-initialization configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	if (((ACPI_GPE_DISPATCH_TYPE(handler->original_flags) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	      ACPI_GPE_DISPATCH_METHOD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	     (ACPI_GPE_DISPATCH_TYPE(handler->original_flags) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	      ACPI_GPE_DISPATCH_NOTIFY)) && handler->originally_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		(void)acpi_ev_add_gpe_reference(gpe_event_info, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		if (ACPI_GPE_IS_POLLING_NEEDED(gpe_event_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			/* Poll edge triggered GPEs to handle existing events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			(void)acpi_ev_detect_gpe(gpe_device, gpe_event_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 						 gpe_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	/* Make sure all deferred GPE tasks are completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	acpi_os_wait_events_complete();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	/* Now we can free the handler object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	ACPI_FREE(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) unlock_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)  * FUNCTION:    acpi_acquire_global_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)  * PARAMETERS:  timeout         - How long the caller is willing to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)  *              handle          - Where the handle to the lock is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  *                                (if acquired)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)  * DESCRIPTION: Acquire the ACPI Global Lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)  * Note: Allows callers with the same thread ID to acquire the global lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)  * multiple times. In other words, externally, the behavior of the global lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)  * is identical to an AML mutex. On the first acquire, a new handle is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)  * returned. On any subsequent calls to acquire by the same thread, the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)  * handle is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) acpi_status acpi_acquire_global_lock(u16 timeout, u32 *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	if (!handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		return (AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	/* Must lock interpreter to prevent race conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	acpi_ex_enter_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	status = acpi_ex_acquire_mutex_object(timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 					      acpi_gbl_global_lock_mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 					      acpi_os_get_thread_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		/* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		*handle = acpi_gbl_global_lock_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	acpi_ex_exit_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)  * FUNCTION:    acpi_release_global_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)  * PARAMETERS:  handle      - Returned from acpi_acquire_global_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)  * RETURN:      Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)  * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) acpi_status acpi_release_global_lock(u32 handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	if (!handle || (handle != acpi_gbl_global_lock_handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		return (AE_NOT_ACQUIRED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) ACPI_EXPORT_SYMBOL(acpi_release_global_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) #endif				/* !ACPI_REDUCED_HARDWARE */