167754Smsmith/****************************************************************************** 267754Smsmith * 399146Siwasaki * Module Name: evmisc - Miscellaneous event manager support functions 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7316303Sjkim/****************************************************************************** 8316303Sjkim * 9316303Sjkim * 1. Copyright Notice 10316303Sjkim * 11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 1270243Smsmith * All rights reserved. 1367754Smsmith * 14316303Sjkim * 2. License 15316303Sjkim * 16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17316303Sjkim * rights. You may have additional license terms from the party that provided 18316303Sjkim * you this software, covering your right to use that party's intellectual 19316303Sjkim * property rights. 20316303Sjkim * 21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 26316303Sjkim * Code in any form, with the right to sublicense such rights; and 27316303Sjkim * 28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29316303Sjkim * license (with the right to sublicense), under only those claims of Intel 30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 33316303Sjkim * license, and in no event shall the patent license extend to any additions 34316303Sjkim * to or modifications of the Original Intel Code. No other license or right 35316303Sjkim * is granted directly or by implication, estoppel or otherwise; 36316303Sjkim * 37316303Sjkim * The above copyright and patent license is granted only if the following 38316303Sjkim * conditions are met: 39316303Sjkim * 40316303Sjkim * 3. Conditions 41316303Sjkim * 42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43316303Sjkim * Redistribution of source code of any substantial portion of the Covered 44316303Sjkim * Code or modification with rights to further distribute source must include 45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 49316303Sjkim * Code and the date of any change. Licensee must include in that file the 50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51316303Sjkim * must include a prominent statement that the modification is derived, 52316303Sjkim * directly or indirectly, from Original Intel Code. 53316303Sjkim * 54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55316303Sjkim * Redistribution of source code of any substantial portion of the Covered 56316303Sjkim * Code or modification without rights to further distribute source must 57316303Sjkim * include the following Disclaimer and Export Compliance provision in the 58316303Sjkim * documentation and/or other materials provided with distribution. In 59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 61316303Sjkim * license from Licensee to its licensee is limited to the intellectual 62316303Sjkim * property embodied in the software Licensee provides to its licensee, and 63316303Sjkim * not to intellectual property embodied in modifications its licensee may 64316303Sjkim * make. 65316303Sjkim * 66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69316303Sjkim * provision in the documentation and/or other materials provided with the 70316303Sjkim * distribution. 71316303Sjkim * 72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73316303Sjkim * Intel Code. 74316303Sjkim * 75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77316303Sjkim * other dealings in products derived from or relating to the Covered Code 78316303Sjkim * without prior written authorization from Intel. 79316303Sjkim * 80316303Sjkim * 4. Disclaimer and Export Compliance 81316303Sjkim * 82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88316303Sjkim * PARTICULAR PURPOSE. 89316303Sjkim * 90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97316303Sjkim * LIMITED REMEDY. 98316303Sjkim * 99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100316303Sjkim * software or system incorporating such software without first obtaining any 101316303Sjkim * required license or other approval from the U. S. Department of Commerce or 102316303Sjkim * any other agency or department of the United States Government. In the 103316303Sjkim * event Licensee exports any such software from the United States or 104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 105316303Sjkim * ensure that the distribution and export/re-export of the software is in 106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109316303Sjkim * software, or service, directly or indirectly, to any country for which the 110316303Sjkim * United States government or any agency thereof requires an export license, 111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 112316303Sjkim * such license, approval or letter. 113316303Sjkim * 114316303Sjkim ***************************************************************************** 115316303Sjkim * 116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 117316303Sjkim * following license: 118316303Sjkim * 119217365Sjkim * Redistribution and use in source and binary forms, with or without 120217365Sjkim * modification, are permitted provided that the following conditions 121217365Sjkim * are met: 122217365Sjkim * 1. Redistributions of source code must retain the above copyright 123217365Sjkim * notice, this list of conditions, and the following disclaimer, 124217365Sjkim * without modification. 125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 127217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 128217365Sjkim * including a substantially similar Disclaimer requirement for further 129217365Sjkim * binary redistribution. 130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 131217365Sjkim * of any contributors may be used to endorse or promote products derived 132217365Sjkim * from this software without specific prior written permission. 13367754Smsmith * 134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145316303Sjkim * 146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 148217365Sjkim * Software Foundation. 14967754Smsmith * 150316303Sjkim *****************************************************************************/ 15167754Smsmith 152193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 153193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 154193341Sjkim#include <contrib/dev/acpica/include/acevents.h> 155193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 15667754Smsmith 15777424Smsmith#define _COMPONENT ACPI_EVENTS 15891116Smsmith ACPI_MODULE_NAME ("evmisc") 15967754Smsmith 16067754Smsmith 161151937Sjkim/* Local prototypes */ 162151937Sjkim 163151937Sjkimstatic void ACPI_SYSTEM_XFACE 164151937SjkimAcpiEvNotifyDispatch ( 165151937Sjkim void *Context); 166151937Sjkim 167151937Sjkim 16877424Smsmith/******************************************************************************* 16967754Smsmith * 17099146Siwasaki * FUNCTION: AcpiEvIsNotifyObject 17199146Siwasaki * 17299146Siwasaki * PARAMETERS: Node - Node to check 17399146Siwasaki * 17499146Siwasaki * RETURN: TRUE if notifies allowed on this object 17599146Siwasaki * 17699146Siwasaki * DESCRIPTION: Check type of node for a object that supports notifies. 17799146Siwasaki * 17899146Siwasaki * TBD: This could be replaced by a flag bit in the node. 17999146Siwasaki * 18099146Siwasaki ******************************************************************************/ 18199146Siwasaki 18299146SiwasakiBOOLEAN 18399146SiwasakiAcpiEvIsNotifyObject ( 18499146Siwasaki ACPI_NAMESPACE_NODE *Node) 18599146Siwasaki{ 186298714Sjkim 18799146Siwasaki switch (Node->Type) 18899146Siwasaki { 18999146Siwasaki case ACPI_TYPE_DEVICE: 19099146Siwasaki case ACPI_TYPE_PROCESSOR: 19199146Siwasaki case ACPI_TYPE_THERMAL: 19299146Siwasaki /* 19399146Siwasaki * These are the ONLY objects that can receive ACPI notifications 19499146Siwasaki */ 19599146Siwasaki return (TRUE); 19699146Siwasaki 19799146Siwasaki default: 198250838Sjkim 19999146Siwasaki return (FALSE); 20099146Siwasaki } 20199146Siwasaki} 20299146Siwasaki 20399146Siwasaki 20499146Siwasaki/******************************************************************************* 20599146Siwasaki * 20677424Smsmith * FUNCTION: AcpiEvQueueNotifyRequest 20767754Smsmith * 208138287Smarks * PARAMETERS: Node - NS node for the notified object 209138287Smarks * NotifyValue - Value from the Notify() request 21067754Smsmith * 211138287Smarks * RETURN: Status 21267754Smsmith * 21367754Smsmith * DESCRIPTION: Dispatch a device notification event to a previously 21467754Smsmith * installed handler. 21567754Smsmith * 21677424Smsmith ******************************************************************************/ 21767754Smsmith 21877424SmsmithACPI_STATUS 21977424SmsmithAcpiEvQueueNotifyRequest ( 22077424Smsmith ACPI_NAMESPACE_NODE *Node, 22167754Smsmith UINT32 NotifyValue) 22267754Smsmith{ 22367754Smsmith ACPI_OPERAND_OBJECT *ObjDesc; 224234623Sjkim ACPI_OPERAND_OBJECT *HandlerListHead = NULL; 225234623Sjkim ACPI_GENERIC_STATE *Info; 226234623Sjkim UINT8 HandlerListId = 0; 22777424Smsmith ACPI_STATUS Status = AE_OK; 22867754Smsmith 22967754Smsmith 230167802Sjkim ACPI_FUNCTION_NAME (EvQueueNotifyRequest); 23177424Smsmith 23277424Smsmith 233234623Sjkim /* Are Notifies allowed on this object? */ 23467754Smsmith 235234623Sjkim if (!AcpiEvIsNotifyObject (Node)) 23667754Smsmith { 237234623Sjkim return (AE_TYPE); 238234623Sjkim } 23977424Smsmith 240234623Sjkim /* Get the correct notify list type (System or Device) */ 241193267Sjkim 242234623Sjkim if (NotifyValue <= ACPI_MAX_SYS_NOTIFY) 243234623Sjkim { 244234623Sjkim HandlerListId = ACPI_SYSTEM_HANDLER_LIST; 245234623Sjkim } 246234623Sjkim else 247234623Sjkim { 248234623Sjkim HandlerListId = ACPI_DEVICE_HANDLER_LIST; 249234623Sjkim } 25091116Smsmith 251234623Sjkim /* Get the notify object attached to the namespace Node */ 25277424Smsmith 253234623Sjkim ObjDesc = AcpiNsGetAttachedObject (Node); 254234623Sjkim if (ObjDesc) 255234623Sjkim { 256234623Sjkim /* We have an attached object, Get the correct handler list */ 257193267Sjkim 258234623Sjkim HandlerListHead = ObjDesc->CommonNotify.NotifyList[HandlerListId]; 25967754Smsmith } 26067754Smsmith 261193267Sjkim /* 262234623Sjkim * If there is no notify handler (Global or Local) 263234623Sjkim * for this object, just ignore the notify 264193267Sjkim */ 265234623Sjkim if (!AcpiGbl_GlobalNotify[HandlerListId].Handler && !HandlerListHead) 26667754Smsmith { 267234623Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 268234623Sjkim "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n", 269234623Sjkim AcpiUtGetNodeName (Node), NotifyValue, Node)); 27067754Smsmith 271234623Sjkim return (AE_OK); 272234623Sjkim } 273193267Sjkim 274234623Sjkim /* Setup notify info and schedule the notify dispatcher */ 27567754Smsmith 276234623Sjkim Info = AcpiUtCreateGenericState (); 277234623Sjkim if (!Info) 278234623Sjkim { 279234623Sjkim return (AE_NO_MEMORY); 28077424Smsmith } 281234623Sjkim 282234623Sjkim Info->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY; 283234623Sjkim 284234623Sjkim Info->Notify.Node = Node; 285234623Sjkim Info->Notify.Value = (UINT16) NotifyValue; 286234623Sjkim Info->Notify.HandlerListId = HandlerListId; 287234623Sjkim Info->Notify.HandlerListHead = HandlerListHead; 288234623Sjkim Info->Notify.Global = &AcpiGbl_GlobalNotify[HandlerListId]; 289234623Sjkim 290234623Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 291234623Sjkim "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n", 292234623Sjkim AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type), 293272444Sjkim NotifyValue, AcpiUtGetNotifyName (NotifyValue, ACPI_TYPE_ANY), Node)); 294234623Sjkim 295298714Sjkim Status = AcpiOsExecute (OSL_NOTIFY_HANDLER, 296298714Sjkim AcpiEvNotifyDispatch, Info); 297234623Sjkim if (ACPI_FAILURE (Status)) 298193267Sjkim { 299234623Sjkim AcpiUtDeleteGenericState (Info); 30067754Smsmith } 30167754Smsmith 30277424Smsmith return (Status); 30377424Smsmith} 30467754Smsmith 30567754Smsmith 30677424Smsmith/******************************************************************************* 30777424Smsmith * 30877424Smsmith * FUNCTION: AcpiEvNotifyDispatch 30977424Smsmith * 310151937Sjkim * PARAMETERS: Context - To be passed to the notify handler 31177424Smsmith * 31277424Smsmith * RETURN: None. 31377424Smsmith * 31477424Smsmith * DESCRIPTION: Dispatch a device notification event to a previously 31577424Smsmith * installed handler. 31677424Smsmith * 31777424Smsmith ******************************************************************************/ 31877424Smsmith 319151937Sjkimstatic void ACPI_SYSTEM_XFACE 32077424SmsmithAcpiEvNotifyDispatch ( 32177424Smsmith void *Context) 32277424Smsmith{ 323234623Sjkim ACPI_GENERIC_STATE *Info = (ACPI_GENERIC_STATE *) Context; 32477424Smsmith ACPI_OPERAND_OBJECT *HandlerObj; 32577424Smsmith 32677424Smsmith 32791116Smsmith ACPI_FUNCTION_ENTRY (); 32883174Smsmith 32983174Smsmith 330234623Sjkim /* Invoke a global notify handler if installed */ 33177424Smsmith 332234623Sjkim if (Info->Notify.Global->Handler) 33367754Smsmith { 334234623Sjkim Info->Notify.Global->Handler (Info->Notify.Node, 335234623Sjkim Info->Notify.Value, 336234623Sjkim Info->Notify.Global->Context); 33767754Smsmith } 33867754Smsmith 339234623Sjkim /* Now invoke the local notify handler(s) if any are installed */ 34077424Smsmith 341234623Sjkim HandlerObj = Info->Notify.HandlerListHead; 342234623Sjkim while (HandlerObj) 34367754Smsmith { 344234623Sjkim HandlerObj->Notify.Handler (Info->Notify.Node, 345234623Sjkim Info->Notify.Value, 346234623Sjkim HandlerObj->Notify.Context); 34767754Smsmith 348234623Sjkim HandlerObj = HandlerObj->Notify.Next[Info->Notify.HandlerListId]; 34967754Smsmith } 35067754Smsmith 35177424Smsmith /* All done with the info object */ 35267754Smsmith 353234623Sjkim AcpiUtDeleteGenericState (Info); 35467754Smsmith} 35567754Smsmith 35667754Smsmith 357231844Sjkim#if (!ACPI_REDUCED_HARDWARE) 35877424Smsmith/****************************************************************************** 35967754Smsmith * 36091116Smsmith * FUNCTION: AcpiEvTerminate 36191116Smsmith * 36291116Smsmith * PARAMETERS: none 36391116Smsmith * 36491116Smsmith * RETURN: none 36591116Smsmith * 366104470Siwasaki * DESCRIPTION: Disable events and free memory allocated for table storage. 36791116Smsmith * 36891116Smsmith ******************************************************************************/ 36991116Smsmith 37091116Smsmithvoid 371151937SjkimAcpiEvTerminate ( 372151937Sjkim void) 37391116Smsmith{ 374193267Sjkim UINT32 i; 375102550Siwasaki ACPI_STATUS Status; 37691116Smsmith 377102550Siwasaki 378167802Sjkim ACPI_FUNCTION_TRACE (EvTerminate); 37991116Smsmith 38091116Smsmith 381104470Siwasaki if (AcpiGbl_EventsInitialized) 382102550Siwasaki { 383104470Siwasaki /* 384193267Sjkim * Disable all event-related functionality. In all cases, on error, 385193267Sjkim * print a message but obviously we don't abort. 386104470Siwasaki */ 387104470Siwasaki 388117521Snjl /* Disable all fixed events */ 389117521Snjl 390104470Siwasaki for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) 391102550Siwasaki { 392193267Sjkim Status = AcpiDisableEvent (i, 0); 393104470Siwasaki if (ACPI_FAILURE (Status)) 394104470Siwasaki { 395167802Sjkim ACPI_ERROR ((AE_INFO, 396204773Sjkim "Could not disable fixed event %u", (UINT32) i)); 397104470Siwasaki } 398102550Siwasaki } 399102550Siwasaki 400117521Snjl /* Disable all GPEs in all GPE blocks */ 401114237Snjl 402193267Sjkim Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL); 403114237Snjl 404167802Sjkim Status = AcpiEvRemoveGlobalLockHandler (); 405167802Sjkim if (ACPI_FAILURE(Status)) 406167802Sjkim { 407167802Sjkim ACPI_ERROR ((AE_INFO, 408167802Sjkim "Could not remove Global Lock handler")); 409167802Sjkim } 410250838Sjkim 411250838Sjkim AcpiGbl_EventsInitialized = FALSE; 412102550Siwasaki } 413102550Siwasaki 414254745Sjkim /* Remove SCI handlers */ 415254745Sjkim 416254745Sjkim Status = AcpiEvRemoveAllSciHandlers (); 417254745Sjkim if (ACPI_FAILURE(Status)) 418254745Sjkim { 419254745Sjkim ACPI_ERROR ((AE_INFO, 420254745Sjkim "Could not remove SCI handler")); 421254745Sjkim } 422254745Sjkim 423129684Snjl /* Deallocate all handler objects installed within GPE info structs */ 424129684Snjl 425193267Sjkim Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers, NULL); 426129684Snjl 427117521Snjl /* Return to original mode if necessary */ 428117521Snjl 429102550Siwasaki if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY) 430102550Siwasaki { 431102550Siwasaki Status = AcpiDisable (); 432102550Siwasaki if (ACPI_FAILURE (Status)) 433102550Siwasaki { 434167802Sjkim ACPI_WARNING ((AE_INFO, "AcpiDisable failed")); 435102550Siwasaki } 436102550Siwasaki } 43767754Smsmith return_VOID; 43867754Smsmith} 439231844Sjkim 440231844Sjkim#endif /* !ACPI_REDUCED_HARDWARE */ 441