evmisc.c revision 172314
1280849Scy/****************************************************************************** 2258945Sroberto * 3280849Scy * Module Name: evmisc - Miscellaneous event manager support functions 4280849Scy * $Revision: 1.103 $ 5258945Sroberto * 6258945Sroberto *****************************************************************************/ 7258945Sroberto 8280849Scy/****************************************************************************** 9258945Sroberto * 10258945Sroberto * 1. Copyright Notice 11258945Sroberto * 12258945Sroberto * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp. 13258945Sroberto * All rights reserved. 14258945Sroberto * 15258945Sroberto * 2. License 16258945Sroberto * 17258945Sroberto * 2.1. This is your license from Intel Corp. under its intellectual property 18280849Scy * rights. You may have additional license terms from the party that provided 19280849Scy * you this software, covering your right to use that party's intellectual 20258945Sroberto * property rights. 21280849Scy * 22280849Scy * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23280849Scy * copy of the source code appearing in this file ("Covered Code") an 24280849Scy * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25280849Scy * base code distributed originally by Intel ("Original Intel Code") to copy, 26280849Scy * make derivatives, distribute, use and display any portion of the Covered 27280849Scy * Code in any form, with the right to sublicense such rights; and 28280849Scy * 29280849Scy * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30280849Scy * license (with the right to sublicense), under only those claims of Intel 31280849Scy * patents that are infringed by the Original Intel Code, to make, use, sell, 32280849Scy * offer to sell, and import the Covered Code and derivative works thereof 33280849Scy * solely to the minimum extent necessary to exercise the above copyright 34280849Scy * license, and in no event shall the patent license extend to any additions 35280849Scy * to or modifications of the Original Intel Code. No other license or right 36280849Scy * is granted directly or by implication, estoppel or otherwise; 37258945Sroberto * 38280849Scy * The above copyright and patent license is granted only if the following 39258945Sroberto * conditions are met: 40258945Sroberto * 41258945Sroberto * 3. Conditions 42258945Sroberto * 43258945Sroberto * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44258945Sroberto * Redistribution of source code of any substantial portion of the Covered 45258945Sroberto * Code or modification with rights to further distribute source must include 46258945Sroberto * the above Copyright Notice, the above License, this list of Conditions, 47258945Sroberto * and the following Disclaimer and Export Compliance provision. In addition, 48258945Sroberto * Licensee must cause all Covered Code to which Licensee contributes to 49280849Scy * contain a file documenting the changes Licensee made to create that Covered 50258945Sroberto * Code and the date of any change. Licensee must include in that file the 51258945Sroberto * documentation of any changes made by any predecessor Licensee. Licensee 52258945Sroberto * must include a prominent statement that the modification is derived, 53258945Sroberto * directly or indirectly, from Original Intel Code. 54258945Sroberto * 55258945Sroberto * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56280849Scy * Redistribution of source code of any substantial portion of the Covered 57258945Sroberto * Code or modification without rights to further distribute source must 58258945Sroberto * include the following Disclaimer and Export Compliance provision in the 59258945Sroberto * documentation and/or other materials provided with distribution. In 60258945Sroberto * addition, Licensee may not authorize further sublicense of source of any 61258945Sroberto * portion of the Covered Code, and must include terms to the effect that the 62258945Sroberto * license from Licensee to its licensee is limited to the intellectual 63280849Scy * property embodied in the software Licensee provides to its licensee, and 64280849Scy * not to intellectual property embodied in modifications its licensee may 65258945Sroberto * make. 66258945Sroberto * 67258945Sroberto * 3.3. Redistribution of Executable. Redistribution in executable form of any 68258945Sroberto * substantial portion of the Covered Code or modification must reproduce the 69258945Sroberto * above Copyright Notice, and the following Disclaimer and Export Compliance 70258945Sroberto * provision in the documentation and/or other materials provided with the 71258945Sroberto * distribution. 72258945Sroberto * 73258945Sroberto * 3.4. Intel retains all right, title, and interest in and to the Original 74258945Sroberto * Intel Code. 75258945Sroberto * 76280849Scy * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77258945Sroberto * Intel shall be used in advertising or otherwise to promote the sale, use or 78280849Scy * other dealings in products derived from or relating to the Covered Code 79280849Scy * without prior written authorization from Intel. 80280849Scy * 81280849Scy * 4. Disclaimer and Export Compliance 82258945Sroberto * 83280849Scy * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84258945Sroberto * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85258945Sroberto * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86258945Sroberto * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87258945Sroberto * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88258945Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89280849Scy * PARTICULAR PURPOSE. 90258945Sroberto * 91280849Scy * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92258945Sroberto * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93280849Scy * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94280849Scy * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95280849Scy * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96280849Scy * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97258945Sroberto * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98280849Scy * LIMITED REMEDY. 99258945Sroberto * 100280849Scy * 4.3. Licensee shall not export, either directly or indirectly, any of this 101258945Sroberto * software or system incorporating such software without first obtaining any 102280849Scy * required license or other approval from the U. S. Department of Commerce or 103258945Sroberto * any other agency or department of the United States Government. In the 104280849Scy * event Licensee exports any such software from the United States or 105258945Sroberto * re-exports any such software from a foreign destination, Licensee shall 106280849Scy * ensure that the distribution and export/re-export of the software is in 107280849Scy * compliance with all laws, regulations, orders, or other restrictions of the 108258945Sroberto * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109280849Scy * any of its subsidiaries will export/re-export any technical data, process, 110280849Scy * software, or service, directly or indirectly, to any country for which the 111258945Sroberto * United States government or any agency thereof requires an export license, 112280849Scy * other governmental approval, or letter of assurance, without first obtaining 113258945Sroberto * such license, approval or letter. 114258945Sroberto * 115258945Sroberto *****************************************************************************/ 116258945Sroberto 117258945Sroberto#include <contrib/dev/acpica/acpi.h> 118280849Scy#include <contrib/dev/acpica/acevents.h> 119280849Scy#include <contrib/dev/acpica/acnamesp.h> 120258945Sroberto#include <contrib/dev/acpica/acinterp.h> 121258945Sroberto 122258945Sroberto#define _COMPONENT ACPI_EVENTS 123280849Scy ACPI_MODULE_NAME ("evmisc") 124280849Scy 125280849Scy 126280849Scy/* Names for Notify() values, used for debug output */ 127280849Scy 128280849Scy#ifdef ACPI_DEBUG_OUTPUT 129280849Scystatic const char *AcpiNotifyValueNames[] = 130280849Scy{ 131258945Sroberto "Bus Check", 132258945Sroberto "Device Check", 133258945Sroberto "Device Wake", 134258945Sroberto "Eject Request", 135258945Sroberto "Device Check Light", 136258945Sroberto "Frequency Mismatch", 137258945Sroberto "Bus Mode Mismatch", 138258945Sroberto "Power Fault" 139258945Sroberto}; 140258945Sroberto#endif 141258945Sroberto 142258945Sroberto/* Pointer to FACS needed for the Global Lock */ 143258945Sroberto 144258945Srobertostatic ACPI_TABLE_FACS *Facs = NULL; 145258945Sroberto 146258945Sroberto/* Local prototypes */ 147258945Sroberto 148258945Srobertostatic void ACPI_SYSTEM_XFACE 149258945SrobertoAcpiEvNotifyDispatch ( 150258945Sroberto void *Context); 151258945Sroberto 152280849Scystatic UINT32 153258945SrobertoAcpiEvGlobalLockHandler ( 154280849Scy void *Context); 155258945Sroberto 156258945Srobertostatic ACPI_STATUS 157258945SrobertoAcpiEvRemoveGlobalLockHandler ( 158280849Scy void); 159280849Scy 160258945Sroberto 161280849Scy/******************************************************************************* 162258945Sroberto * 163280849Scy * FUNCTION: AcpiEvIsNotifyObject 164280849Scy * 165280849Scy * PARAMETERS: Node - Node to check 166258945Sroberto * 167280849Scy * RETURN: TRUE if notifies allowed on this object 168258945Sroberto * 169258945Sroberto * DESCRIPTION: Check type of node for a object that supports notifies. 170258945Sroberto * 171258945Sroberto * TBD: This could be replaced by a flag bit in the node. 172280849Scy * 173258945Sroberto ******************************************************************************/ 174258945Sroberto 175258945SrobertoBOOLEAN 176258945SrobertoAcpiEvIsNotifyObject ( 177258945Sroberto ACPI_NAMESPACE_NODE *Node) 178258945Sroberto{ 179258945Sroberto switch (Node->Type) 180280849Scy { 181258945Sroberto case ACPI_TYPE_DEVICE: 182258945Sroberto case ACPI_TYPE_PROCESSOR: 183258945Sroberto case ACPI_TYPE_POWER: 184258945Sroberto case ACPI_TYPE_THERMAL: 185258945Sroberto /* 186258945Sroberto * These are the ONLY objects that can receive ACPI notifications 187258945Sroberto */ 188280849Scy return (TRUE); 189258945Sroberto 190258945Sroberto default: 191258945Sroberto return (FALSE); 192258945Sroberto } 193258945Sroberto} 194258945Sroberto 195258945Sroberto 196258945Sroberto/******************************************************************************* 197258945Sroberto * 198280849Scy * FUNCTION: AcpiEvQueueNotifyRequest 199280849Scy * 200280849Scy * PARAMETERS: Node - NS node for the notified object 201280849Scy * NotifyValue - Value from the Notify() request 202280849Scy * 203280849Scy * RETURN: Status 204280849Scy * 205280849Scy * DESCRIPTION: Dispatch a device notification event to a previously 206280849Scy * installed handler. 207280849Scy * 208280849Scy ******************************************************************************/ 209258945Sroberto 210258945SrobertoACPI_STATUS 211258945SrobertoAcpiEvQueueNotifyRequest ( 212258945Sroberto ACPI_NAMESPACE_NODE *Node, 213258945Sroberto UINT32 NotifyValue) 214258945Sroberto{ 215258945Sroberto ACPI_OPERAND_OBJECT *ObjDesc; 216258945Sroberto ACPI_OPERAND_OBJECT *HandlerObj = NULL; 217258945Sroberto ACPI_GENERIC_STATE *NotifyInfo; 218258945Sroberto ACPI_STATUS Status = AE_OK; 219258945Sroberto 220258945Sroberto 221258945Sroberto ACPI_FUNCTION_NAME (EvQueueNotifyRequest); 222258945Sroberto 223258945Sroberto 224258945Sroberto /* 225258945Sroberto * For value 3 (Ejection Request), some device method may need to be run. 226258945Sroberto * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need 227258945Sroberto * to be run. 228258945Sroberto * For value 0x80 (Status Change) on the power button or sleep button, 229258945Sroberto * initiate soft-off or sleep operation? 230258945Sroberto */ 231258945Sroberto ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 232258945Sroberto "Dispatching Notify(%X) on node %p\n", NotifyValue, Node)); 233258945Sroberto 234258945Sroberto if (NotifyValue <= 7) 235258945Sroberto { 236258945Sroberto ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: %s\n", 237258945Sroberto AcpiNotifyValueNames[NotifyValue])); 238258945Sroberto } 239258945Sroberto else 240258945Sroberto { 241258945Sroberto ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 242280849Scy "Notify value: 0x%2.2X **Device Specific**\n", 243258945Sroberto NotifyValue)); 244 } 245 246 /* Get the notify object attached to the NS Node */ 247 248 ObjDesc = AcpiNsGetAttachedObject (Node); 249 if (ObjDesc) 250 { 251 /* We have the notify object, Get the right handler */ 252 253 switch (Node->Type) 254 { 255 case ACPI_TYPE_DEVICE: 256 case ACPI_TYPE_THERMAL: 257 case ACPI_TYPE_PROCESSOR: 258 case ACPI_TYPE_POWER: 259 260 if (NotifyValue <= ACPI_MAX_SYS_NOTIFY) 261 { 262 HandlerObj = ObjDesc->CommonNotify.SystemNotify; 263 } 264 else 265 { 266 HandlerObj = ObjDesc->CommonNotify.DeviceNotify; 267 } 268 break; 269 270 default: 271 /* All other types are not supported */ 272 return (AE_TYPE); 273 } 274 } 275 276 /* If there is any handler to run, schedule the dispatcher */ 277 278 if ((AcpiGbl_SystemNotify.Handler && (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) || 279 (AcpiGbl_DeviceNotify.Handler && (NotifyValue > ACPI_MAX_SYS_NOTIFY)) || 280 HandlerObj) 281 { 282 NotifyInfo = AcpiUtCreateGenericState (); 283 if (!NotifyInfo) 284 { 285 return (AE_NO_MEMORY); 286 } 287 288 NotifyInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY; 289 NotifyInfo->Notify.Node = Node; 290 NotifyInfo->Notify.Value = (UINT16) NotifyValue; 291 NotifyInfo->Notify.HandlerObj = HandlerObj; 292 293 Status = AcpiOsExecute ( 294 OSL_NOTIFY_HANDLER, AcpiEvNotifyDispatch, NotifyInfo); 295 if (ACPI_FAILURE (Status)) 296 { 297 AcpiUtDeleteGenericState (NotifyInfo); 298 } 299 } 300 301 if (!HandlerObj) 302 { 303 /* 304 * There is no per-device notify handler for this device. 305 * This may or may not be a problem. 306 */ 307 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 308 "No notify handler for Notify(%4.4s, %X) node %p\n", 309 AcpiUtGetNodeName (Node), NotifyValue, Node)); 310 } 311 312 return (Status); 313} 314 315 316/******************************************************************************* 317 * 318 * FUNCTION: AcpiEvNotifyDispatch 319 * 320 * PARAMETERS: Context - To be passed to the notify handler 321 * 322 * RETURN: None. 323 * 324 * DESCRIPTION: Dispatch a device notification event to a previously 325 * installed handler. 326 * 327 ******************************************************************************/ 328 329static void ACPI_SYSTEM_XFACE 330AcpiEvNotifyDispatch ( 331 void *Context) 332{ 333 ACPI_GENERIC_STATE *NotifyInfo = (ACPI_GENERIC_STATE *) Context; 334 ACPI_NOTIFY_HANDLER GlobalHandler = NULL; 335 void *GlobalContext = NULL; 336 ACPI_OPERAND_OBJECT *HandlerObj; 337 338 339 ACPI_FUNCTION_ENTRY (); 340 341 342 /* 343 * We will invoke a global notify handler if installed. 344 * This is done _before_ we invoke the per-device handler attached 345 * to the device. 346 */ 347 if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY) 348 { 349 /* Global system notification handler */ 350 351 if (AcpiGbl_SystemNotify.Handler) 352 { 353 GlobalHandler = AcpiGbl_SystemNotify.Handler; 354 GlobalContext = AcpiGbl_SystemNotify.Context; 355 } 356 } 357 else 358 { 359 /* Global driver notification handler */ 360 361 if (AcpiGbl_DeviceNotify.Handler) 362 { 363 GlobalHandler = AcpiGbl_DeviceNotify.Handler; 364 GlobalContext = AcpiGbl_DeviceNotify.Context; 365 } 366 } 367 368 /* Invoke the system handler first, if present */ 369 370 if (GlobalHandler) 371 { 372 GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value, 373 GlobalContext); 374 } 375 376 /* Now invoke the per-device handler, if present */ 377 378 HandlerObj = NotifyInfo->Notify.HandlerObj; 379 if (HandlerObj) 380 { 381 HandlerObj->Notify.Handler (NotifyInfo->Notify.Node, 382 NotifyInfo->Notify.Value, 383 HandlerObj->Notify.Context); 384 } 385 386 /* All done with the info object */ 387 388 AcpiUtDeleteGenericState (NotifyInfo); 389} 390 391 392/******************************************************************************* 393 * 394 * FUNCTION: AcpiEvGlobalLockHandler 395 * 396 * PARAMETERS: Context - From thread interface, not used 397 * 398 * RETURN: ACPI_INTERRUPT_HANDLED 399 * 400 * DESCRIPTION: Invoked directly from the SCI handler when a global lock 401 * release interrupt occurs. Attempt to acquire the global lock, 402 * if successful, signal the thread waiting for the lock. 403 * 404 * NOTE: Assumes that the semaphore can be signaled from interrupt level. If 405 * this is not possible for some reason, a separate thread will have to be 406 * scheduled to do this. 407 * 408 ******************************************************************************/ 409 410static UINT32 411AcpiEvGlobalLockHandler ( 412 void *Context) 413{ 414 BOOLEAN Acquired = FALSE; 415 ACPI_STATUS Status; 416 417 418 /* 419 * Attempt to get the lock. 420 * 421 * If we don't get it now, it will be marked pending and we will 422 * take another interrupt when it becomes free. 423 */ 424 ACPI_ACQUIRE_GLOBAL_LOCK (Facs, Acquired); 425 if (Acquired) 426 { 427 /* Got the lock, now wake the thread waiting for it */ 428 429 AcpiGbl_GlobalLockAcquired = TRUE; 430 431 /* Send a unit to the semaphore */ 432 433 Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1); 434 if (ACPI_FAILURE (Status)) 435 { 436 ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore")); 437 } 438 } 439 440 return (ACPI_INTERRUPT_HANDLED); 441} 442 443 444/******************************************************************************* 445 * 446 * FUNCTION: AcpiEvInitGlobalLockHandler 447 * 448 * PARAMETERS: None 449 * 450 * RETURN: Status 451 * 452 * DESCRIPTION: Install a handler for the global lock release event 453 * 454 ******************************************************************************/ 455 456ACPI_STATUS 457AcpiEvInitGlobalLockHandler ( 458 void) 459{ 460 ACPI_STATUS Status; 461 462 463 ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler); 464 465 466 Status = AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS, 467 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &Facs)); 468 if (ACPI_FAILURE (Status)) 469 { 470 return_ACPI_STATUS (Status); 471 } 472 473 AcpiGbl_GlobalLockPresent = TRUE; 474 Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL, 475 AcpiEvGlobalLockHandler, NULL); 476 477 /* 478 * If the global lock does not exist on this platform, the attempt 479 * to enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick) 480 * Map to AE_OK, but mark global lock as not present. 481 * Any attempt to actually use the global lock will be flagged 482 * with an error. 483 */ 484 if (Status == AE_NO_HARDWARE_RESPONSE) 485 { 486 ACPI_ERROR ((AE_INFO, 487 "No response from Global Lock hardware, disabling lock")); 488 489 AcpiGbl_GlobalLockPresent = FALSE; 490 Status = AE_OK; 491 } 492 493 return_ACPI_STATUS (Status); 494} 495 496 497/******************************************************************************* 498 * 499 * FUNCTION: AcpiEvRemoveGlobalLockHandler 500 * 501 * PARAMETERS: None 502 * 503 * RETURN: Status 504 * 505 * DESCRIPTION: Remove the handler for the Global Lock 506 * 507 ******************************************************************************/ 508 509static ACPI_STATUS 510AcpiEvRemoveGlobalLockHandler ( 511 void) 512{ 513 ACPI_STATUS Status; 514 515 516 ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler); 517 518 AcpiGbl_GlobalLockPresent = FALSE; 519 Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL, 520 AcpiEvGlobalLockHandler); 521 522 return_ACPI_STATUS (Status); 523} 524 525 526/****************************************************************************** 527 * 528 * FUNCTION: AcpiEvAcquireGlobalLock 529 * 530 * PARAMETERS: Timeout - Max time to wait for the lock, in millisec. 531 * 532 * RETURN: Status 533 * 534 * DESCRIPTION: Attempt to gain ownership of the Global Lock. 535 * 536 * MUTEX: Interpreter must be locked 537 * 538 * Note: The original implementation allowed multiple threads to "acquire" the 539 * Global Lock, and the OS would hold the lock until the last thread had 540 * released it. However, this could potentially starve the BIOS out of the 541 * lock, especially in the case where there is a tight handshake between the 542 * Embedded Controller driver and the BIOS. Therefore, this implementation 543 * allows only one thread to acquire the HW Global Lock at a time, and makes 544 * the global lock appear as a standard mutex on the OS side. 545 * 546 *****************************************************************************/ 547 548ACPI_STATUS 549AcpiEvAcquireGlobalLock ( 550 UINT16 Timeout) 551{ 552 ACPI_STATUS Status = AE_OK; 553 BOOLEAN Acquired = FALSE; 554 555 556 ACPI_FUNCTION_TRACE (EvAcquireGlobalLock); 557 558 559 /* 560 * Only one thread can acquire the GL at a time, the GlobalLockMutex 561 * enforces this. This interface releases the interpreter if we must wait. 562 */ 563 Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex, 564 Timeout); 565 if (ACPI_FAILURE (Status)) 566 { 567 return_ACPI_STATUS (Status); 568 } 569 570 /* 571 * Update the global lock handle and check for wraparound. The handle is 572 * only used for the external global lock interfaces, but it is updated 573 * here to properly handle the case where a single thread may acquire the 574 * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The 575 * handle is therefore updated on the first acquire from a given thread 576 * regardless of where the acquisition request originated. 577 */ 578 AcpiGbl_GlobalLockHandle++; 579 if (AcpiGbl_GlobalLockHandle == 0) 580 { 581 AcpiGbl_GlobalLockHandle = 1; 582 } 583 584 /* 585 * Make sure that a global lock actually exists. If not, just treat 586 * the lock as a standard mutex. 587 */ 588 if (!AcpiGbl_GlobalLockPresent) 589 { 590 AcpiGbl_GlobalLockAcquired = TRUE; 591 return_ACPI_STATUS (AE_OK); 592 } 593 594 /* Attempt to acquire the actual hardware lock */ 595 596 ACPI_ACQUIRE_GLOBAL_LOCK (Facs, Acquired); 597 if (Acquired) 598 { 599 /* We got the lock */ 600 601 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired hardware Global Lock\n")); 602 603 AcpiGbl_GlobalLockAcquired = TRUE; 604 return_ACPI_STATUS (AE_OK); 605 } 606 607 /* 608 * Did not get the lock. The pending bit was set above, and we must now 609 * wait until we get the global lock released interrupt. 610 */ 611 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for hardware Global Lock\n")); 612 613 /* 614 * Wait for handshake with the global lock interrupt handler. 615 * This interface releases the interpreter if we must wait. 616 */ 617 Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore, 618 ACPI_WAIT_FOREVER); 619 620 return_ACPI_STATUS (Status); 621} 622 623 624/******************************************************************************* 625 * 626 * FUNCTION: AcpiEvReleaseGlobalLock 627 * 628 * PARAMETERS: None 629 * 630 * RETURN: Status 631 * 632 * DESCRIPTION: Releases ownership of the Global Lock. 633 * 634 ******************************************************************************/ 635 636ACPI_STATUS 637AcpiEvReleaseGlobalLock ( 638 void) 639{ 640 BOOLEAN Pending = FALSE; 641 ACPI_STATUS Status = AE_OK; 642 643 644 ACPI_FUNCTION_TRACE (EvReleaseGlobalLock); 645 646 647 /* Lock must be already acquired */ 648 649 if (!AcpiGbl_GlobalLockAcquired) 650 { 651 ACPI_WARNING ((AE_INFO, 652 "Cannot release the ACPI Global Lock, it has not been acquired")); 653 return_ACPI_STATUS (AE_NOT_ACQUIRED); 654 } 655 656 if (AcpiGbl_GlobalLockPresent) 657 { 658 /* Allow any thread to release the lock */ 659 660 ACPI_RELEASE_GLOBAL_LOCK (Facs, Pending); 661 662 /* 663 * If the pending bit was set, we must write GBL_RLS to the control 664 * register 665 */ 666 if (Pending) 667 { 668 Status = AcpiSetRegister ( 669 ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1); 670 } 671 672 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n")); 673 } 674 675 AcpiGbl_GlobalLockAcquired = FALSE; 676 677 /* Release the local GL mutex */ 678 679 AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex); 680 return_ACPI_STATUS (Status); 681} 682 683 684/****************************************************************************** 685 * 686 * FUNCTION: AcpiEvTerminate 687 * 688 * PARAMETERS: none 689 * 690 * RETURN: none 691 * 692 * DESCRIPTION: Disable events and free memory allocated for table storage. 693 * 694 ******************************************************************************/ 695 696void 697AcpiEvTerminate ( 698 void) 699{ 700 ACPI_NATIVE_UINT i; 701 ACPI_STATUS Status; 702 703 704 ACPI_FUNCTION_TRACE (EvTerminate); 705 706 707 if (AcpiGbl_EventsInitialized) 708 { 709 /* 710 * Disable all event-related functionality. 711 * In all cases, on error, print a message but obviously we don't abort. 712 */ 713 714 /* Disable all fixed events */ 715 716 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) 717 { 718 Status = AcpiDisableEvent ((UINT32) i, 0); 719 if (ACPI_FAILURE (Status)) 720 { 721 ACPI_ERROR ((AE_INFO, 722 "Could not disable fixed event %d", (UINT32) i)); 723 } 724 } 725 726 /* Disable all GPEs in all GPE blocks */ 727 728 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock); 729 730 /* Remove SCI handler */ 731 732 Status = AcpiEvRemoveSciHandler (); 733 if (ACPI_FAILURE(Status)) 734 { 735 ACPI_ERROR ((AE_INFO, 736 "Could not remove SCI handler")); 737 } 738 739 Status = AcpiEvRemoveGlobalLockHandler (); 740 if (ACPI_FAILURE(Status)) 741 { 742 ACPI_ERROR ((AE_INFO, 743 "Could not remove Global Lock handler")); 744 } 745 } 746 747 /* Deallocate all handler objects installed within GPE info structs */ 748 749 Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers); 750 751 /* Return to original mode if necessary */ 752 753 if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY) 754 { 755 Status = AcpiDisable (); 756 if (ACPI_FAILURE (Status)) 757 { 758 ACPI_WARNING ((AE_INFO, "AcpiDisable failed")); 759 } 760 } 761 return_VOID; 762} 763 764