evmisc.c revision 123315
1146392Smarius/****************************************************************************** 2146392Smarius * 3146392Smarius * Module Name: evmisc - Miscellaneous event manager support functions 4146392Smarius * $Revision: 69 $ 5146392Smarius * 6146392Smarius *****************************************************************************/ 7146392Smarius 8146392Smarius/****************************************************************************** 9146392Smarius * 10146392Smarius * 1. Copyright Notice 11146392Smarius * 12146392Smarius * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp. 13146392Smarius * All rights reserved. 14146392Smarius * 15146392Smarius * 2. License 16146392Smarius * 17146392Smarius * 2.1. This is your license from Intel Corp. under its intellectual property 18146392Smarius * rights. You may have additional license terms from the party that provided 19146392Smarius * you this software, covering your right to use that party's intellectual 20146392Smarius * property rights. 21146392Smarius * 22146392Smarius * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23146392Smarius * copy of the source code appearing in this file ("Covered Code") an 24146392Smarius * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25146392Smarius * base code distributed originally by Intel ("Original Intel Code") to copy, 26146392Smarius * make derivatives, distribute, use and display any portion of the Covered 27146392Smarius * Code in any form, with the right to sublicense such rights; and 28146392Smarius * 29146392Smarius * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30146392Smarius * license (with the right to sublicense), under only those claims of Intel 31146392Smarius * patents that are infringed by the Original Intel Code, to make, use, sell, 32146392Smarius * offer to sell, and import the Covered Code and derivative works thereof 33146392Smarius * solely to the minimum extent necessary to exercise the above copyright 34146392Smarius * license, and in no event shall the patent license extend to any additions 35146392Smarius * to or modifications of the Original Intel Code. No other license or right 36146392Smarius * is granted directly or by implication, estoppel or otherwise; 37146392Smarius * 38146392Smarius * The above copyright and patent license is granted only if the following 39146392Smarius * conditions are met: 40146392Smarius * 41146392Smarius * 3. Conditions 42146392Smarius * 43146392Smarius * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44146392Smarius * Redistribution of source code of any substantial portion of the Covered 45146392Smarius * Code or modification with rights to further distribute source must include 46146392Smarius * the above Copyright Notice, the above License, this list of Conditions, 47146392Smarius * and the following Disclaimer and Export Compliance provision. In addition, 48146392Smarius * Licensee must cause all Covered Code to which Licensee contributes to 49146392Smarius * contain a file documenting the changes Licensee made to create that Covered 50146392Smarius * Code and the date of any change. Licensee must include in that file the 51146392Smarius * documentation of any changes made by any predecessor Licensee. Licensee 52146392Smarius * must include a prominent statement that the modification is derived, 53146392Smarius * directly or indirectly, from Original Intel Code. 54146392Smarius * 55146392Smarius * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56146392Smarius * Redistribution of source code of any substantial portion of the Covered 57146392Smarius * Code or modification without rights to further distribute source must 58146392Smarius * include the following Disclaimer and Export Compliance provision in the 59146392Smarius * documentation and/or other materials provided with distribution. In 60146392Smarius * addition, Licensee may not authorize further sublicense of source of any 61146392Smarius * portion of the Covered Code, and must include terms to the effect that the 62146392Smarius * license from Licensee to its licensee is limited to the intellectual 63146392Smarius * property embodied in the software Licensee provides to its licensee, and 64146392Smarius * not to intellectual property embodied in modifications its licensee may 65146392Smarius * make. 66146392Smarius * 67146392Smarius * 3.3. Redistribution of Executable. Redistribution in executable form of any 68146392Smarius * substantial portion of the Covered Code or modification must reproduce the 69146392Smarius * above Copyright Notice, and the following Disclaimer and Export Compliance 70146392Smarius * provision in the documentation and/or other materials provided with the 71146392Smarius * distribution. 72146392Smarius * 73146392Smarius * 3.4. Intel retains all right, title, and interest in and to the Original 74146392Smarius * Intel Code. 75146392Smarius * 76146392Smarius * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77152684Smarius * Intel shall be used in advertising or otherwise to promote the sale, use or 78146392Smarius * other dealings in products derived from or relating to the Covered Code 79146392Smarius * without prior written authorization from Intel. 80146392Smarius * 81146392Smarius * 4. Disclaimer and Export Compliance 82146392Smarius * 83146392Smarius * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84146392Smarius * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85146392Smarius * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86146392Smarius * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87146392Smarius * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88146392Smarius * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89146392Smarius * PARTICULAR PURPOSE. 90146392Smarius * 91152684Smarius * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92146392Smarius * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93146392Smarius * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94146392Smarius * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95146392Smarius * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96146392Smarius * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97146392Smarius * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98146392Smarius * LIMITED REMEDY. 99146392Smarius * 100146392Smarius * 4.3. Licensee shall not export, either directly or indirectly, any of this 101146392Smarius * software or system incorporating such software without first obtaining any 102146392Smarius * required license or other approval from the U. S. Department of Commerce or 103146392Smarius * any other agency or department of the United States Government. In the 104146392Smarius * event Licensee exports any such software from the United States or 105146392Smarius * re-exports any such software from a foreign destination, Licensee shall 106146392Smarius * ensure that the distribution and export/re-export of the software is in 107146392Smarius * compliance with all laws, regulations, orders, or other restrictions of the 108152684Smarius * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109146392Smarius * any of its subsidiaries will export/re-export any technical data, process, 110152684Smarius * software, or service, directly or indirectly, to any country for which the 111152684Smarius * United States government or any agency thereof requires an export license, 112146392Smarius * other governmental approval, or letter of assurance, without first obtaining 113152684Smarius * such license, approval or letter. 114146392Smarius * 115146392Smarius *****************************************************************************/ 116166147Smarius 117146392Smarius#include "acpi.h" 118146392Smarius#include "acevents.h" 119154870Smarius#include "acnamesp.h" 120154870Smarius#include "acinterp.h" 121154870Smarius 122146392Smarius#define _COMPONENT ACPI_EVENTS 123146392Smarius ACPI_MODULE_NAME ("evmisc") 124146392Smarius 125146392Smarius 126155067Smarius/******************************************************************************* 127146392Smarius * 128146392Smarius * FUNCTION: AcpiEvIsNotifyObject 129146392Smarius * 130146392Smarius * PARAMETERS: Node - Node to check 131146392Smarius * 132146392Smarius * RETURN: TRUE if notifies allowed on this object 133146392Smarius * 134146392Smarius * DESCRIPTION: Check type of node for a object that supports notifies. 135146392Smarius * 136152684Smarius * TBD: This could be replaced by a flag bit in the node. 137152684Smarius * 138152684Smarius ******************************************************************************/ 139152684Smarius 140152684SmariusBOOLEAN 141152684SmariusAcpiEvIsNotifyObject ( 142146392Smarius ACPI_NAMESPACE_NODE *Node) 143146392Smarius{ 144146392Smarius switch (Node->Type) 145146392Smarius { 146146392Smarius case ACPI_TYPE_DEVICE: 147146392Smarius case ACPI_TYPE_PROCESSOR: 148146392Smarius case ACPI_TYPE_POWER: 149146392Smarius case ACPI_TYPE_THERMAL: 150146392Smarius /* 151146392Smarius * These are the ONLY objects that can receive ACPI notifications 152146392Smarius */ 153182062Smarius return (TRUE); 154182062Smarius 155146392Smarius default: 156146392Smarius return (FALSE); 157146392Smarius } 158146392Smarius} 159146392Smarius 160146392Smarius 161146392Smarius/******************************************************************************* 162146392Smarius * 163146392Smarius * FUNCTION: AcpiEvQueueNotifyRequest 164166147Smarius * 165166147Smarius * PARAMETERS: 166146392Smarius * 167166147Smarius * RETURN: None. 168146392Smarius * 169146392Smarius * DESCRIPTION: Dispatch a device notification event to a previously 170146392Smarius * installed handler. 171146392Smarius * 172146392Smarius ******************************************************************************/ 173146392Smarius 174146392SmariusACPI_STATUS 175146392SmariusAcpiEvQueueNotifyRequest ( 176146392Smarius ACPI_NAMESPACE_NODE *Node, 177146392Smarius UINT32 NotifyValue) 178152684Smarius{ 179146392Smarius ACPI_OPERAND_OBJECT *ObjDesc; 180146392Smarius ACPI_OPERAND_OBJECT *HandlerObj = NULL; 181146392Smarius ACPI_GENERIC_STATE *NotifyInfo; 182146392Smarius ACPI_STATUS Status = AE_OK; 183146392Smarius 184146392Smarius 185146392Smarius ACPI_FUNCTION_NAME ("EvQueueNotifyRequest"); 186146392Smarius 187146392Smarius 188146392Smarius /* 189146392Smarius * For value 1 (Ejection Request), some device method may need to be run. 190146392Smarius * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need to be run. 191146392Smarius * For value 0x80 (Status Change) on the power button or sleep button, 192146392Smarius * initiate soft-off or sleep operation? 193146392Smarius */ 194146392Smarius ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 195146392Smarius "Dispatching Notify(%X) on node %p\n", NotifyValue, Node)); 196146392Smarius 197146392Smarius switch (NotifyValue) 198146392Smarius { 199146392Smarius case 0: 200146392Smarius ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Re-enumerate Devices\n")); 201146392Smarius break; 202146392Smarius 203146392Smarius case 1: 204146392Smarius ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Ejection Request\n")); 205146392Smarius break; 206146392Smarius 207146392Smarius case 2: 208146392Smarius ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Device Wake\n")); 209146392Smarius break; 210146392Smarius 211146392Smarius case 0x80: 212146392Smarius ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Status Change\n")); 213146392Smarius break; 214146392Smarius 215146392Smarius default: 216146392Smarius ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Unknown Notify Value: %X \n", NotifyValue)); 217146392Smarius break; 218146392Smarius } 219146392Smarius 220146392Smarius /* 221146392Smarius * Get the notify object attached to the NS Node 222146392Smarius */ 223146392Smarius ObjDesc = AcpiNsGetAttachedObject (Node); 224146392Smarius if (ObjDesc) 225146392Smarius { 226146392Smarius /* We have the notify object, Get the right handler */ 227146392Smarius 228146392Smarius switch (Node->Type) 229146392Smarius { 230146392Smarius case ACPI_TYPE_DEVICE: 231146392Smarius case ACPI_TYPE_THERMAL: 232146392Smarius case ACPI_TYPE_PROCESSOR: 233166147Smarius case ACPI_TYPE_POWER: 234166147Smarius 235146392Smarius if (NotifyValue <= ACPI_MAX_SYS_NOTIFY) 236146392Smarius { 237146392Smarius HandlerObj = ObjDesc->CommonNotify.SystemNotify; 238146392Smarius } 239146392Smarius else 240146392Smarius { 241146392Smarius HandlerObj = ObjDesc->CommonNotify.DeviceNotify; 242146392Smarius } 243146392Smarius break; 244146392Smarius 245146392Smarius default: 246146392Smarius /* All other types are not supported */ 247146392Smarius return (AE_TYPE); 248146392Smarius } 249146392Smarius } 250146392Smarius 251146392Smarius /* If there is any handler to run, schedule the dispatcher */ 252146392Smarius 253146392Smarius if ((AcpiGbl_SystemNotify.Handler && (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) || 254146392Smarius (AcpiGbl_DeviceNotify.Handler && (NotifyValue > ACPI_MAX_SYS_NOTIFY)) || 255146392Smarius HandlerObj) 256146392Smarius { 257146392Smarius NotifyInfo = AcpiUtCreateGenericState (); 258146392Smarius if (!NotifyInfo) 259146392Smarius { 260146392Smarius return (AE_NO_MEMORY); 261146392Smarius } 262146392Smarius 263152684Smarius NotifyInfo->Common.DataType = ACPI_DESC_TYPE_STATE_NOTIFY; 264146392Smarius NotifyInfo->Notify.Node = Node; 265146392Smarius NotifyInfo->Notify.Value = (UINT16) NotifyValue; 266152684Smarius NotifyInfo->Notify.HandlerObj = HandlerObj; 267152684Smarius 268152684Smarius Status = AcpiOsQueueForExecution (OSD_PRIORITY_HIGH, 269146392Smarius AcpiEvNotifyDispatch, NotifyInfo); 270146392Smarius if (ACPI_FAILURE (Status)) 271146392Smarius { 272146392Smarius AcpiUtDeleteGenericState (NotifyInfo); 273146392Smarius } 274152684Smarius } 275146392Smarius 276146392Smarius if (!HandlerObj) 277146392Smarius { 278146392Smarius /* There is no per-device notify handler for this device */ 279146392Smarius 280146392Smarius ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 281152684Smarius "No notify handler for [%4.4s] node %p\n", 282146392Smarius AcpiUtGetNodeName (Node), Node)); 283146392Smarius } 284146392Smarius 285146392Smarius return (Status); 286146392Smarius} 287146392Smarius 288146392Smarius 289146392Smarius/******************************************************************************* 290146392Smarius * 291152684Smarius * FUNCTION: AcpiEvNotifyDispatch 292146392Smarius * 293146392Smarius * PARAMETERS: 294146392Smarius * 295146392Smarius * RETURN: None. 296146392Smarius * 297146392Smarius * DESCRIPTION: Dispatch a device notification event to a previously 298146392Smarius * installed handler. 299152684Smarius * 300152684Smarius ******************************************************************************/ 301146392Smarius 302152684Smariusvoid ACPI_SYSTEM_XFACE 303146392SmariusAcpiEvNotifyDispatch ( 304146392Smarius void *Context) 305146392Smarius{ 306146392Smarius ACPI_GENERIC_STATE *NotifyInfo = (ACPI_GENERIC_STATE *) Context; 307152684Smarius ACPI_NOTIFY_HANDLER GlobalHandler = NULL; 308152684Smarius void *GlobalContext = NULL; 309152684Smarius ACPI_OPERAND_OBJECT *HandlerObj; 310146392Smarius 311146392Smarius 312146392Smarius ACPI_FUNCTION_ENTRY (); 313146392Smarius 314146392Smarius 315146392Smarius /* 316146392Smarius * We will invoke a global notify handler if installed. 317146392Smarius * This is done _before_ we invoke the per-device handler attached to the device. 318146392Smarius */ 319152684Smarius if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY) 320152684Smarius { 321146392Smarius /* Global system notification handler */ 322152684Smarius 323146392Smarius if (AcpiGbl_SystemNotify.Handler) 324146392Smarius { 325146392Smarius GlobalHandler = AcpiGbl_SystemNotify.Handler; 326146392Smarius GlobalContext = AcpiGbl_SystemNotify.Context; 327146392Smarius } 328146392Smarius } 329146392Smarius else 330146392Smarius { 331146392Smarius /* Global driver notification handler */ 332152684Smarius 333152684Smarius if (AcpiGbl_DeviceNotify.Handler) 334146392Smarius { 335146392Smarius GlobalHandler = AcpiGbl_DeviceNotify.Handler; 336146392Smarius GlobalContext = AcpiGbl_DeviceNotify.Context; 337146392Smarius } 338146392Smarius } 339146392Smarius 340146392Smarius /* Invoke the system handler first, if present */ 341146392Smarius 342146392Smarius if (GlobalHandler) 343146392Smarius { 344146392Smarius GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value, GlobalContext); 345146392Smarius } 346146392Smarius 347146392Smarius /* Now invoke the per-device handler, if present */ 348146392Smarius 349146392Smarius HandlerObj = NotifyInfo->Notify.HandlerObj; 350146392Smarius if (HandlerObj) 351146392Smarius { 352146392Smarius HandlerObj->Notify.Handler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value, 353146392Smarius HandlerObj->Notify.Context); 354146392Smarius } 355146392Smarius 356146392Smarius /* All done with the info object */ 357146392Smarius 358152684Smarius AcpiUtDeleteGenericState (NotifyInfo); 359152684Smarius} 360152684Smarius 361152684Smarius 362146392Smarius/******************************************************************************* 363146392Smarius * 364146392Smarius * FUNCTION: AcpiEvGlobalLockThread 365146392Smarius * 366146392Smarius * RETURN: None 367146392Smarius * 368146392Smarius * DESCRIPTION: Invoked by SCI interrupt handler upon acquisition of the 369152684Smarius * Global Lock. Simply signal all threads that are waiting 370146392Smarius * for the lock. 371146392Smarius * 372146392Smarius ******************************************************************************/ 373146392Smarius 374146392Smariusstatic void ACPI_SYSTEM_XFACE 375146392SmariusAcpiEvGlobalLockThread ( 376146392Smarius void *Context) 377146392Smarius{ 378146392Smarius ACPI_STATUS Status; 379152684Smarius 380146392Smarius 381146392Smarius /* Signal threads that are waiting for the lock */ 382146392Smarius 383146392Smarius if (AcpiGbl_GlobalLockThreadCount) 384146392Smarius { 385146392Smarius /* Send sufficient units to the semaphore */ 386146392Smarius 387152684Smarius Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 388146392Smarius AcpiGbl_GlobalLockThreadCount); 389152684Smarius if (ACPI_FAILURE (Status)) 390152684Smarius { 391152684Smarius ACPI_REPORT_ERROR (("Could not signal Global Lock semaphore\n")); 392152684Smarius } 393152684Smarius } 394146392Smarius} 395146392Smarius 396146392Smarius 397146392Smarius/******************************************************************************* 398146392Smarius * 399146392Smarius * FUNCTION: AcpiEvGlobalLockHandler 400146392Smarius * 401146392Smarius * RETURN: Status 402146392Smarius * 403146392Smarius * DESCRIPTION: Invoked directly from the SCI handler when a global lock 404146392Smarius * release interrupt occurs. Grab the global lock and queue 405152684Smarius * the global lock thread for execution 406152684Smarius * 407146392Smarius ******************************************************************************/ 408152684Smarius 409146392Smariusstatic UINT32 410152684SmariusAcpiEvGlobalLockHandler ( 411152684Smarius void *Context) 412146392Smarius{ 413146392Smarius BOOLEAN Acquired = FALSE; 414152684Smarius ACPI_STATUS Status; 415152684Smarius 416146392Smarius 417152684Smarius /* 418146392Smarius * Attempt to get the lock 419152684Smarius * If we don't get it now, it will be marked pending and we will 420152684Smarius * take another interrupt when it becomes free. 421152684Smarius */ 422152684Smarius ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Acquired); 423152684Smarius if (Acquired) 424146392Smarius { 425 /* Got the lock, now wake all threads waiting for it */ 426 427 AcpiGbl_GlobalLockAcquired = TRUE; 428 429 /* Run the Global Lock thread which will signal all waiting threads */ 430 431 Status = AcpiOsQueueForExecution (OSD_PRIORITY_HIGH, 432 AcpiEvGlobalLockThread, Context); 433 if (ACPI_FAILURE (Status)) 434 { 435 ACPI_REPORT_ERROR (("Could not queue Global Lock thread, %s\n", 436 AcpiFormatException (Status))); 437 438 return (ACPI_INTERRUPT_NOT_HANDLED); 439 } 440 } 441 442 return (ACPI_INTERRUPT_HANDLED); 443} 444 445 446/******************************************************************************* 447 * 448 * FUNCTION: AcpiEvInitGlobalLockHandler 449 * 450 * RETURN: Status 451 * 452 * DESCRIPTION: Install a handler for the global lock release event 453 * 454 ******************************************************************************/ 455 456ACPI_STATUS 457AcpiEvInitGlobalLockHandler (void) 458{ 459 ACPI_STATUS Status; 460 461 462 ACPI_FUNCTION_TRACE ("EvInitGlobalLockHandler"); 463 464 465 AcpiGbl_GlobalLockPresent = TRUE; 466 Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL, 467 AcpiEvGlobalLockHandler, NULL); 468 469 /* 470 * If the global lock does not exist on this platform, the attempt 471 * to enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick) 472 * Map to AE_OK, but mark global lock as not present. 473 * Any attempt to actually use the global lock will be flagged 474 * with an error. 475 */ 476 if (Status == AE_NO_HARDWARE_RESPONSE) 477 { 478 AcpiGbl_GlobalLockPresent = FALSE; 479 Status = AE_OK; 480 } 481 482 return_ACPI_STATUS (Status); 483} 484 485 486/****************************************************************************** 487 * 488 * FUNCTION: AcpiEvAcquireGlobalLock 489 * 490 * RETURN: Status 491 * 492 * DESCRIPTION: Attempt to gain ownership of the Global Lock. 493 * 494 *****************************************************************************/ 495 496ACPI_STATUS 497AcpiEvAcquireGlobalLock ( 498 UINT16 Timeout) 499{ 500 ACPI_STATUS Status = AE_OK; 501 BOOLEAN Acquired = FALSE; 502 503 504 ACPI_FUNCTION_TRACE ("EvAcquireGlobalLock"); 505 506 507#ifndef ACPI_APPLICATION 508 /* Make sure that we actually have a global lock */ 509 510 if (!AcpiGbl_GlobalLockPresent) 511 { 512 return_ACPI_STATUS (AE_NO_GLOBAL_LOCK); 513 } 514#endif 515 516 /* One more thread wants the global lock */ 517 518 AcpiGbl_GlobalLockThreadCount++; 519 520 /* If we (OS side vs. BIOS side) have the hardware lock already, we are done */ 521 522 if (AcpiGbl_GlobalLockAcquired) 523 { 524 return_ACPI_STATUS (AE_OK); 525 } 526 527 /* We must acquire the actual hardware lock */ 528 529 ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Acquired); 530 if (Acquired) 531 { 532 /* We got the lock */ 533 534 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired the HW Global Lock\n")); 535 536 AcpiGbl_GlobalLockAcquired = TRUE; 537 return_ACPI_STATUS (AE_OK); 538 } 539 540 /* 541 * Did not get the lock. The pending bit was set above, and we must now 542 * wait until we get the global lock released interrupt. 543 */ 544 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for the HW Global Lock\n")); 545 546 /* 547 * Acquire the global lock semaphore first. 548 * Since this wait will block, we must release the interpreter 549 */ 550 Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore, 551 Timeout); 552 return_ACPI_STATUS (Status); 553} 554 555 556/******************************************************************************* 557 * 558 * FUNCTION: AcpiEvReleaseGlobalLock 559 * 560 * DESCRIPTION: Releases ownership of the Global Lock. 561 * 562 ******************************************************************************/ 563 564ACPI_STATUS 565AcpiEvReleaseGlobalLock (void) 566{ 567 BOOLEAN Pending = FALSE; 568 ACPI_STATUS Status = AE_OK; 569 570 571 ACPI_FUNCTION_TRACE ("EvReleaseGlobalLock"); 572 573 574 if (!AcpiGbl_GlobalLockThreadCount) 575 { 576 ACPI_REPORT_WARNING(("Cannot release HW Global Lock, it has not been acquired\n")); 577 return_ACPI_STATUS (AE_NOT_ACQUIRED); 578 } 579 580 /* One fewer thread has the global lock */ 581 582 AcpiGbl_GlobalLockThreadCount--; 583 if (AcpiGbl_GlobalLockThreadCount) 584 { 585 /* There are still some threads holding the lock, cannot release */ 586 587 return_ACPI_STATUS (AE_OK); 588 } 589 590 /* 591 * No more threads holding lock, we can do the actual hardware 592 * release 593 */ 594 ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Pending); 595 AcpiGbl_GlobalLockAcquired = FALSE; 596 597 /* 598 * If the pending bit was set, we must write GBL_RLS to the control 599 * register 600 */ 601 if (Pending) 602 { 603 Status = AcpiSetRegister (ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1, ACPI_MTX_LOCK); 604 } 605 606 return_ACPI_STATUS (Status); 607} 608 609 610/****************************************************************************** 611 * 612 * FUNCTION: AcpiEvTerminate 613 * 614 * PARAMETERS: none 615 * 616 * RETURN: none 617 * 618 * DESCRIPTION: Disable events and free memory allocated for table storage. 619 * 620 ******************************************************************************/ 621 622void 623AcpiEvTerminate (void) 624{ 625 ACPI_NATIVE_UINT i; 626 ACPI_STATUS Status; 627 628 629 ACPI_FUNCTION_TRACE ("EvTerminate"); 630 631 632 if (AcpiGbl_EventsInitialized) 633 { 634 /* 635 * Disable all event-related functionality. 636 * In all cases, on error, print a message but obviously we don't abort. 637 */ 638 639 /* Disable all fixed events */ 640 641 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) 642 { 643 Status = AcpiDisableEvent ((UINT32) i, 0); 644 if (ACPI_FAILURE (Status)) 645 { 646 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable fixed event %d\n", (UINT32) i)); 647 } 648 } 649 650 /* Disable all GPEs in all GPE blocks */ 651 652 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock); 653 654 /* Remove SCI handler */ 655 656 Status = AcpiEvRemoveSciHandler (); 657 if (ACPI_FAILURE(Status)) 658 { 659 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not remove SCI handler\n")); 660 } 661 } 662 663 /* Return to original mode if necessary */ 664 665 if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY) 666 { 667 Status = AcpiDisable (); 668 if (ACPI_FAILURE (Status)) 669 { 670 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "AcpiDisable failed\n")); 671 } 672 } 673 return_VOID; 674} 675 676