1 /****************************************************************************** 2 * 3 * Module Name: evmisc - Miscellaneous event manager support functions 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2012, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 #include <contrib/dev/acpica/include/acpi.h> 45 #include <contrib/dev/acpica/include/accommon.h> 46 #include <contrib/dev/acpica/include/acevents.h> 47 #include <contrib/dev/acpica/include/acnamesp.h> 48 49 #define _COMPONENT ACPI_EVENTS 50 ACPI_MODULE_NAME ("evmisc") 51 52 53 /* Local prototypes */ 54 55 static void ACPI_SYSTEM_XFACE 56 AcpiEvNotifyDispatch ( 57 void *Context); 58 59 60 /******************************************************************************* 61 * 62 * FUNCTION: AcpiEvIsNotifyObject 63 * 64 * PARAMETERS: Node - Node to check 65 * 66 * RETURN: TRUE if notifies allowed on this object 67 * 68 * DESCRIPTION: Check type of node for a object that supports notifies. 69 * 70 * TBD: This could be replaced by a flag bit in the node. 71 * 72 ******************************************************************************/ 73 74 BOOLEAN 75 AcpiEvIsNotifyObject ( 76 ACPI_NAMESPACE_NODE *Node) 77 { 78 switch (Node->Type) 79 { 80 case ACPI_TYPE_DEVICE: 81 case ACPI_TYPE_PROCESSOR: 82 case ACPI_TYPE_THERMAL: 83 /* 84 * These are the ONLY objects that can receive ACPI notifications 85 */ 86 return (TRUE); 87 88 default: 89 return (FALSE); 90 } 91 } 92 93 94 /******************************************************************************* 95 * 96 * FUNCTION: AcpiEvQueueNotifyRequest 97 * 98 * PARAMETERS: Node - NS node for the notified object 99 * NotifyValue - Value from the Notify() request 100 * 101 * RETURN: Status 102 * 103 * DESCRIPTION: Dispatch a device notification event to a previously 104 * installed handler. 105 * 106 ******************************************************************************/ 107 108 ACPI_STATUS 109 AcpiEvQueueNotifyRequest ( 110 ACPI_NAMESPACE_NODE *Node, 111 UINT32 NotifyValue) 112 { 113 ACPI_OPERAND_OBJECT *ObjDesc; 114 ACPI_OPERAND_OBJECT *HandlerListHead = NULL; 115 ACPI_GENERIC_STATE *Info; 116 UINT8 HandlerListId = 0; 117 ACPI_STATUS Status = AE_OK; 118 119 120 ACPI_FUNCTION_NAME (EvQueueNotifyRequest); 121 122 123 /* Are Notifies allowed on this object? */ 124 125 if (!AcpiEvIsNotifyObject (Node)) 126 { 127 return (AE_TYPE); 128 } 129 130 /* Get the correct notify list type (System or Device) */ 131 132 if (NotifyValue <= ACPI_MAX_SYS_NOTIFY) 133 { 134 HandlerListId = ACPI_SYSTEM_HANDLER_LIST; 135 } 136 else 137 { 138 HandlerListId = ACPI_DEVICE_HANDLER_LIST; 139 } 140 141 /* Get the notify object attached to the namespace Node */ 142 143 ObjDesc = AcpiNsGetAttachedObject (Node); 144 if (ObjDesc) 145 { 146 /* We have an attached object, Get the correct handler list */ 147 148 HandlerListHead = ObjDesc->CommonNotify.NotifyList[HandlerListId]; 149 } 150 151 /* 152 * If there is no notify handler (Global or Local) 153 * for this object, just ignore the notify 154 */ 155 if (!AcpiGbl_GlobalNotify[HandlerListId].Handler && !HandlerListHead) 156 { 157 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 158 "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n", 159 AcpiUtGetNodeName (Node), NotifyValue, Node)); 160 161 return (AE_OK); 162 } 163 164 /* Setup notify info and schedule the notify dispatcher */ 165 166 Info = AcpiUtCreateGenericState (); 167 if (!Info) 168 { 169 return (AE_NO_MEMORY); 170 } 171 172 Info->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY; 173 174 Info->Notify.Node = Node; 175 Info->Notify.Value = (UINT16) NotifyValue; 176 Info->Notify.HandlerListId = HandlerListId; 177 Info->Notify.HandlerListHead = HandlerListHead; 178 Info->Notify.Global = &AcpiGbl_GlobalNotify[HandlerListId]; 179 180 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 181 "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n", 182 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type), 183 NotifyValue, AcpiUtGetNotifyName (NotifyValue), Node)); 184 185 Status = AcpiOsExecute (OSL_NOTIFY_HANDLER, AcpiEvNotifyDispatch, 186 Info); 187 if (ACPI_FAILURE (Status)) 188 { 189 AcpiUtDeleteGenericState (Info); 190 } 191 192 return (Status); 193 } 194 195 196 /******************************************************************************* 197 * 198 * FUNCTION: AcpiEvNotifyDispatch 199 * 200 * PARAMETERS: Context - To be passed to the notify handler 201 * 202 * RETURN: None. 203 * 204 * DESCRIPTION: Dispatch a device notification event to a previously 205 * installed handler. 206 * 207 ******************************************************************************/ 208 209 static void ACPI_SYSTEM_XFACE 210 AcpiEvNotifyDispatch ( 211 void *Context) 212 { 213 ACPI_GENERIC_STATE *Info = (ACPI_GENERIC_STATE *) Context; 214 ACPI_OPERAND_OBJECT *HandlerObj; 215 216 217 ACPI_FUNCTION_ENTRY (); 218 219 220 /* Invoke a global notify handler if installed */ 221 222 if (Info->Notify.Global->Handler) 223 { 224 Info->Notify.Global->Handler (Info->Notify.Node, 225 Info->Notify.Value, 226 Info->Notify.Global->Context); 227 } 228 229 /* Now invoke the local notify handler(s) if any are installed */ 230 231 HandlerObj = Info->Notify.HandlerListHead; 232 while (HandlerObj) 233 { 234 HandlerObj->Notify.Handler (Info->Notify.Node, 235 Info->Notify.Value, 236 HandlerObj->Notify.Context); 237 238 HandlerObj = HandlerObj->Notify.Next[Info->Notify.HandlerListId]; 239 } 240 241 /* All done with the info object */ 242 243 AcpiUtDeleteGenericState (Info); 244 } 245 246 247 #if (!ACPI_REDUCED_HARDWARE) 248 /****************************************************************************** 249 * 250 * FUNCTION: AcpiEvTerminate 251 * 252 * PARAMETERS: none 253 * 254 * RETURN: none 255 * 256 * DESCRIPTION: Disable events and free memory allocated for table storage. 257 * 258 ******************************************************************************/ 259 260 void 261 AcpiEvTerminate ( 262 void) 263 { 264 UINT32 i; 265 ACPI_STATUS Status; 266 267 268 ACPI_FUNCTION_TRACE (EvTerminate); 269 270 271 if (AcpiGbl_EventsInitialized) 272 { 273 /* 274 * Disable all event-related functionality. In all cases, on error, 275 * print a message but obviously we don't abort. 276 */ 277 278 /* Disable all fixed events */ 279 280 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) 281 { 282 Status = AcpiDisableEvent (i, 0); 283 if (ACPI_FAILURE (Status)) 284 { 285 ACPI_ERROR ((AE_INFO, 286 "Could not disable fixed event %u", (UINT32) i)); 287 } 288 } 289 290 /* Disable all GPEs in all GPE blocks */ 291 292 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL); 293 294 /* Remove SCI handler */ 295 296 Status = AcpiEvRemoveSciHandler (); 297 if (ACPI_FAILURE(Status)) 298 { 299 ACPI_ERROR ((AE_INFO, 300 "Could not remove SCI handler")); 301 } 302 303 Status = AcpiEvRemoveGlobalLockHandler (); 304 if (ACPI_FAILURE(Status)) 305 { 306 ACPI_ERROR ((AE_INFO, 307 "Could not remove Global Lock handler")); 308 } 309 } 310 311 /* Deallocate all handler objects installed within GPE info structs */ 312 313 Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers, NULL); 314 315 /* Return to original mode if necessary */ 316 317 if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY) 318 { 319 Status = AcpiDisable (); 320 if (ACPI_FAILURE (Status)) 321 { 322 ACPI_WARNING ((AE_INFO, "AcpiDisable failed")); 323 } 324 } 325 return_VOID; 326 } 327 328 #endif /* !ACPI_REDUCED_HARDWARE */ 329