/******************************************************************************1*2* Module Name: evmisc - Miscellaneous event manager support functions3*4*****************************************************************************/56/*7* Copyright (C) 2000 - 2011, Intel Corp.8* All rights reserved.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions, and the following disclaimer,15* without modification.16* 2. Redistributions in binary form must reproduce at minimum a disclaimer17* substantially similar to the "NO WARRANTY" disclaimer below18* ("Disclaimer") and any redistribution must be conditioned upon19* including a substantially similar Disclaimer requirement for further20* binary redistribution.21* 3. Neither the names of the above-listed copyright holders nor the names22* of any contributors may be used to endorse or promote products derived23* from this software without specific prior written permission.24*25* Alternatively, this software may be distributed under the terms of the26* GNU General Public License ("GPL") version 2 as published by the Free27* Software Foundation.28*29* NO WARRANTY30* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS31* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT32* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR33* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT34* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL35* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS36* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)37* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,38* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING39* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE40* POSSIBILITY OF SUCH DAMAGES.41*/4243#include <acpi/acpi.h>44#include "accommon.h"45#include "acevents.h"46#include "acnamesp.h"4748#define _COMPONENT ACPI_EVENTS49ACPI_MODULE_NAME("evmisc")5051/* Local prototypes */52static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context);5354/*******************************************************************************55*56* FUNCTION: acpi_ev_is_notify_object57*58* PARAMETERS: Node - Node to check59*60* RETURN: TRUE if notifies allowed on this object61*62* DESCRIPTION: Check type of node for a object that supports notifies.63*64* TBD: This could be replaced by a flag bit in the node.65*66******************************************************************************/6768u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node)69{70switch (node->type) {71case ACPI_TYPE_DEVICE:72case ACPI_TYPE_PROCESSOR:73case ACPI_TYPE_THERMAL:74/*75* These are the ONLY objects that can receive ACPI notifications76*/77return (TRUE);7879default:80return (FALSE);81}82}8384/*******************************************************************************85*86* FUNCTION: acpi_ev_queue_notify_request87*88* PARAMETERS: Node - NS node for the notified object89* notify_value - Value from the Notify() request90*91* RETURN: Status92*93* DESCRIPTION: Dispatch a device notification event to a previously94* installed handler.95*96******************************************************************************/9798acpi_status99acpi_ev_queue_notify_request(struct acpi_namespace_node * node,100u32 notify_value)101{102union acpi_operand_object *obj_desc;103union acpi_operand_object *handler_obj = NULL;104union acpi_generic_state *notify_info;105acpi_status status = AE_OK;106107ACPI_FUNCTION_NAME(ev_queue_notify_request);108109/*110* For value 3 (Ejection Request), some device method may need to be run.111* For value 2 (Device Wake) if _PRW exists, the _PS0 method may need112* to be run.113* For value 0x80 (Status Change) on the power button or sleep button,114* initiate soft-off or sleep operation?115*/116ACPI_DEBUG_PRINT((ACPI_DB_INFO,117"Dispatching Notify on [%4.4s] Node %p Value 0x%2.2X (%s)\n",118acpi_ut_get_node_name(node), node, notify_value,119acpi_ut_get_notify_name(notify_value)));120121/* Get the notify object attached to the NS Node */122123obj_desc = acpi_ns_get_attached_object(node);124if (obj_desc) {125126/* We have the notify object, Get the right handler */127128switch (node->type) {129130/* Notify allowed only on these types */131132case ACPI_TYPE_DEVICE:133case ACPI_TYPE_THERMAL:134case ACPI_TYPE_PROCESSOR:135136if (notify_value <= ACPI_MAX_SYS_NOTIFY) {137handler_obj =138obj_desc->common_notify.system_notify;139} else {140handler_obj =141obj_desc->common_notify.device_notify;142}143break;144145default:146147/* All other types are not supported */148149return (AE_TYPE);150}151}152153/*154* If there is any handler to run, schedule the dispatcher.155* Check for:156* 1) Global system notify handler157* 2) Global device notify handler158* 3) Per-device notify handler159*/160if ((acpi_gbl_system_notify.handler &&161(notify_value <= ACPI_MAX_SYS_NOTIFY)) ||162(acpi_gbl_device_notify.handler &&163(notify_value > ACPI_MAX_SYS_NOTIFY)) || handler_obj) {164notify_info = acpi_ut_create_generic_state();165if (!notify_info) {166return (AE_NO_MEMORY);167}168169if (!handler_obj) {170ACPI_DEBUG_PRINT((ACPI_DB_INFO,171"Executing system notify handler for Notify (%4.4s, %X) "172"node %p\n",173acpi_ut_get_node_name(node),174notify_value, node));175}176177notify_info->common.descriptor_type =178ACPI_DESC_TYPE_STATE_NOTIFY;179notify_info->notify.node = node;180notify_info->notify.value = (u16) notify_value;181notify_info->notify.handler_obj = handler_obj;182183status =184acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch,185notify_info);186if (ACPI_FAILURE(status)) {187acpi_ut_delete_generic_state(notify_info);188}189} else {190/* There is no notify handler (per-device or system) for this device */191192ACPI_DEBUG_PRINT((ACPI_DB_INFO,193"No notify handler for Notify (%4.4s, %X) node %p\n",194acpi_ut_get_node_name(node), notify_value,195node));196}197198return (status);199}200201/*******************************************************************************202*203* FUNCTION: acpi_ev_notify_dispatch204*205* PARAMETERS: Context - To be passed to the notify handler206*207* RETURN: None.208*209* DESCRIPTION: Dispatch a device notification event to a previously210* installed handler.211*212******************************************************************************/213214static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)215{216union acpi_generic_state *notify_info =217(union acpi_generic_state *)context;218acpi_notify_handler global_handler = NULL;219void *global_context = NULL;220union acpi_operand_object *handler_obj;221222ACPI_FUNCTION_ENTRY();223224/*225* We will invoke a global notify handler if installed. This is done226* _before_ we invoke the per-device handler attached to the device.227*/228if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) {229230/* Global system notification handler */231232if (acpi_gbl_system_notify.handler) {233global_handler = acpi_gbl_system_notify.handler;234global_context = acpi_gbl_system_notify.context;235}236} else {237/* Global driver notification handler */238239if (acpi_gbl_device_notify.handler) {240global_handler = acpi_gbl_device_notify.handler;241global_context = acpi_gbl_device_notify.context;242}243}244245/* Invoke the system handler first, if present */246247if (global_handler) {248global_handler(notify_info->notify.node,249notify_info->notify.value, global_context);250}251252/* Now invoke the per-device handler, if present */253254handler_obj = notify_info->notify.handler_obj;255if (handler_obj) {256struct acpi_object_notify_handler *notifier;257258notifier = &handler_obj->notify;259while (notifier) {260notifier->handler(notify_info->notify.node,261notify_info->notify.value,262notifier->context);263notifier = notifier->next;264}265}266267/* All done with the info object */268269acpi_ut_delete_generic_state(notify_info);270}271272/******************************************************************************273*274* FUNCTION: acpi_ev_terminate275*276* PARAMETERS: none277*278* RETURN: none279*280* DESCRIPTION: Disable events and free memory allocated for table storage.281*282******************************************************************************/283284void acpi_ev_terminate(void)285{286u32 i;287acpi_status status;288289ACPI_FUNCTION_TRACE(ev_terminate);290291if (acpi_gbl_events_initialized) {292/*293* Disable all event-related functionality. In all cases, on error,294* print a message but obviously we don't abort.295*/296297/* Disable all fixed events */298299for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {300status = acpi_disable_event(i, 0);301if (ACPI_FAILURE(status)) {302ACPI_ERROR((AE_INFO,303"Could not disable fixed event %u",304(u32) i));305}306}307308/* Disable all GPEs in all GPE blocks */309310status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);311312/* Remove SCI handler */313314status = acpi_ev_remove_sci_handler();315if (ACPI_FAILURE(status)) {316ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));317}318319status = acpi_ev_remove_global_lock_handler();320if (ACPI_FAILURE(status)) {321ACPI_ERROR((AE_INFO,322"Could not remove Global Lock handler"));323}324}325326/* Deallocate all handler objects installed within GPE info structs */327328status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL);329330/* Return to original mode if necessary */331332if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) {333status = acpi_disable();334if (ACPI_FAILURE(status)) {335ACPI_WARNING((AE_INFO, "AcpiDisable failed"));336}337}338return_VOID;339}340341342