evmisc.c revision 107325
190792Sgshapiro/****************************************************************************** 2261363Sgshapiro * 390792Sgshapiro * Module Name: evmisc - Miscellaneous event manager support functions 490792Sgshapiro * $Revision: 59 $ 590792Sgshapiro * 690792Sgshapiro *****************************************************************************/ 790792Sgshapiro 890792Sgshapiro/****************************************************************************** 9266692Sgshapiro * 1090792Sgshapiro * 1. Copyright Notice 1190792Sgshapiro * 1290792Sgshapiro * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. 1390792Sgshapiro * All rights reserved. 1490792Sgshapiro * 1590792Sgshapiro * 2. License 1690792Sgshapiro * 1790792Sgshapiro * 2.1. This is your license from Intel Corp. under its intellectual property 1890792Sgshapiro * rights. You may have additional license terms from the party that provided 1990792Sgshapiro * you this software, covering your right to use that party's intellectual 2090792Sgshapiro * property rights. 2190792Sgshapiro * 2290792Sgshapiro * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2390792Sgshapiro * copy of the source code appearing in this file ("Covered Code") an 2490792Sgshapiro * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2590792Sgshapiro * base code distributed originally by Intel ("Original Intel Code") to copy, 2690792Sgshapiro * make derivatives, distribute, use and display any portion of the Covered 27249729Sgshapiro * Code in any form, with the right to sublicense such rights; and 28249729Sgshapiro * 2990792Sgshapiro * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3090792Sgshapiro * license (with the right to sublicense), under only those claims of Intel 3190792Sgshapiro * patents that are infringed by the Original Intel Code, to make, use, sell, 32249729Sgshapiro * offer to sell, and import the Covered Code and derivative works thereof 3390792Sgshapiro * solely to the minimum extent necessary to exercise the above copyright 34249729Sgshapiro * license, and in no event shall the patent license extend to any additions 3590792Sgshapiro * to or modifications of the Original Intel Code. No other license or right 36249729Sgshapiro * is granted directly or by implication, estoppel or otherwise; 3790792Sgshapiro * 3890792Sgshapiro * The above copyright and patent license is granted only if the following 3990792Sgshapiro * conditions are met: 4090792Sgshapiro * 4190792Sgshapiro * 3. Conditions 4290792Sgshapiro * 4390792Sgshapiro * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4490792Sgshapiro * Redistribution of source code of any substantial portion of the Covered 4590792Sgshapiro * Code or modification with rights to further distribute source must include 4690792Sgshapiro * the above Copyright Notice, the above License, this list of Conditions, 4790792Sgshapiro * and the following Disclaimer and Export Compliance provision. In addition, 4890792Sgshapiro * Licensee must cause all Covered Code to which Licensee contributes to 4990792Sgshapiro * contain a file documenting the changes Licensee made to create that Covered 5090792Sgshapiro * Code and the date of any change. Licensee must include in that file the 5190792Sgshapiro * documentation of any changes made by any predecessor Licensee. Licensee 5290792Sgshapiro * must include a prominent statement that the modification is derived, 5390792Sgshapiro * directly or indirectly, from Original Intel Code. 5490792Sgshapiro * 5590792Sgshapiro * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5690792Sgshapiro * Redistribution of source code of any substantial portion of the Covered 5790792Sgshapiro * Code or modification without rights to further distribute source must 5890792Sgshapiro * include the following Disclaimer and Export Compliance provision in the 5990792Sgshapiro * documentation and/or other materials provided with distribution. In 6090792Sgshapiro * addition, Licensee may not authorize further sublicense of source of any 6190792Sgshapiro * portion of the Covered Code, and must include terms to the effect that the 6290792Sgshapiro * license from Licensee to its licensee is limited to the intellectual 6390792Sgshapiro * property embodied in the software Licensee provides to its licensee, and 6490792Sgshapiro * not to intellectual property embodied in modifications its licensee may 6590792Sgshapiro * make. 6690792Sgshapiro * 6790792Sgshapiro * 3.3. Redistribution of Executable. Redistribution in executable form of any 6890792Sgshapiro * substantial portion of the Covered Code or modification must reproduce the 6990792Sgshapiro * above Copyright Notice, and the following Disclaimer and Export Compliance 7090792Sgshapiro * provision in the documentation and/or other materials provided with the 7190792Sgshapiro * distribution. 7290792Sgshapiro * 7390792Sgshapiro * 3.4. Intel retains all right, title, and interest in and to the Original 7490792Sgshapiro * Intel Code. 7590792Sgshapiro * 7690792Sgshapiro * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7790792Sgshapiro * Intel shall be used in advertising or otherwise to promote the sale, use or 7890792Sgshapiro * other dealings in products derived from or relating to the Covered Code 7990792Sgshapiro * without prior written authorization from Intel. 8090792Sgshapiro * 8190792Sgshapiro * 4. Disclaimer and Export Compliance 8290792Sgshapiro * 8390792Sgshapiro * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8490792Sgshapiro * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8590792Sgshapiro * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8690792Sgshapiro * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8790792Sgshapiro * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8890792Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8990792Sgshapiro * PARTICULAR PURPOSE. 9090792Sgshapiro * 9190792Sgshapiro * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9290792Sgshapiro * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9390792Sgshapiro * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9490792Sgshapiro * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9590792Sgshapiro * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9690792Sgshapiro * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9790792Sgshapiro * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9890792Sgshapiro * LIMITED REMEDY. 9990792Sgshapiro * 10090792Sgshapiro * 4.3. Licensee shall not export, either directly or indirectly, any of this 10190792Sgshapiro * software or system incorporating such software without first obtaining any 10290792Sgshapiro * required license or other approval from the U. S. Department of Commerce or 10390792Sgshapiro * any other agency or department of the United States Government. In the 10490792Sgshapiro * event Licensee exports any such software from the United States or 10590792Sgshapiro * re-exports any such software from a foreign destination, Licensee shall 10690792Sgshapiro * ensure that the distribution and export/re-export of the software is in 10790792Sgshapiro * compliance with all laws, regulations, orders, or other restrictions of the 10890792Sgshapiro * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10990792Sgshapiro * any of its subsidiaries will export/re-export any technical data, process, 11090792Sgshapiro * software, or service, directly or indirectly, to any country for which the 11190792Sgshapiro * United States government or any agency thereof requires an export license, 11290792Sgshapiro * other governmental approval, or letter of assurance, without first obtaining 11390792Sgshapiro * such license, approval or letter. 11490792Sgshapiro * 11590792Sgshapiro *****************************************************************************/ 11690792Sgshapiro 11790792Sgshapiro#include "acpi.h" 11890792Sgshapiro#include "acevents.h" 11990792Sgshapiro#include "acnamesp.h" 12090792Sgshapiro#include "acinterp.h" 12190792Sgshapiro 12290792Sgshapiro#define _COMPONENT ACPI_EVENTS 12390792Sgshapiro ACPI_MODULE_NAME ("evmisc") 12490792Sgshapiro 12590792Sgshapiro 12690792Sgshapiro/******************************************************************************* 12790792Sgshapiro * 12890792Sgshapiro * FUNCTION: AcpiEvIsNotifyObject 12990792Sgshapiro * 13090792Sgshapiro * PARAMETERS: Node - Node to check 13190792Sgshapiro * 13290792Sgshapiro * RETURN: TRUE if notifies allowed on this object 13390792Sgshapiro * 13490792Sgshapiro * DESCRIPTION: Check type of node for a object that supports notifies. 13590792Sgshapiro * 13690792Sgshapiro * TBD: This could be replaced by a flag bit in the node. 13790792Sgshapiro * 13890792Sgshapiro ******************************************************************************/ 13990792Sgshapiro 14090792SgshapiroBOOLEAN 14190792SgshapiroAcpiEvIsNotifyObject ( 14290792Sgshapiro ACPI_NAMESPACE_NODE *Node) 14390792Sgshapiro{ 14490792Sgshapiro switch (Node->Type) 14590792Sgshapiro { 14690792Sgshapiro case ACPI_TYPE_DEVICE: 14790792Sgshapiro case ACPI_TYPE_PROCESSOR: 148132943Sgshapiro case ACPI_TYPE_POWER: 149132943Sgshapiro case ACPI_TYPE_THERMAL: 150141858Sgshapiro /* 151132943Sgshapiro * These are the ONLY objects that can receive ACPI notifications 15294334Sgshapiro */ 153132943Sgshapiro return (TRUE); 154132943Sgshapiro 155132943Sgshapiro default: 15694334Sgshapiro return (FALSE); 15794334Sgshapiro } 15894334Sgshapiro} 15994334Sgshapiro 16094334Sgshapiro 16194334Sgshapiro/******************************************************************************* 162132943Sgshapiro * 163132943Sgshapiro * FUNCTION: AcpiEvGetGpeRegisterIndex 164132943Sgshapiro * 165132943Sgshapiro * PARAMETERS: GpeNumber - Raw GPE number 166132943Sgshapiro * 167132943Sgshapiro * RETURN: None. 16894334Sgshapiro * 169132943Sgshapiro * DESCRIPTION: Returns the register index (index into the GPE register info 170132943Sgshapiro * table) associated with this GPE. 171132943Sgshapiro * 172132943Sgshapiro ******************************************************************************/ 173132943Sgshapiro 174132943SgshapiroUINT32 175132943SgshapiroAcpiEvGetGpeRegisterIndex ( 176132943Sgshapiro UINT32 GpeNumber) 177132943Sgshapiro{ 178132943Sgshapiro 179132943Sgshapiro if (GpeNumber > AcpiGbl_GpeNumberMax) 180132943Sgshapiro { 181132943Sgshapiro return (ACPI_GPE_INVALID); 182132943Sgshapiro } 183132943Sgshapiro 184132943Sgshapiro return (ACPI_DIV_8 (AcpiGbl_GpeNumberToIndex[GpeNumber].NumberIndex)); 185132943Sgshapiro} 186132943Sgshapiro 187132943Sgshapiro 188132943Sgshapiro/******************************************************************************* 18990792Sgshapiro * 190 * FUNCTION: AcpiEvGetGpeNumberIndex 191 * 192 * PARAMETERS: GpeNumber - Raw GPE number 193 * 194 * RETURN: None. 195 * 196 * DESCRIPTION: Returns the number index (index into the GPE number info table) 197 * associated with this GPE. 198 * 199 ******************************************************************************/ 200 201UINT32 202AcpiEvGetGpeNumberIndex ( 203 UINT32 GpeNumber) 204{ 205 206 if (GpeNumber > AcpiGbl_GpeNumberMax) 207 { 208 return (ACPI_GPE_INVALID); 209 } 210 211 return (AcpiGbl_GpeNumberToIndex[GpeNumber].NumberIndex); 212} 213 214 215/******************************************************************************* 216 * 217 * FUNCTION: AcpiEvQueueNotifyRequest 218 * 219 * PARAMETERS: 220 * 221 * RETURN: None. 222 * 223 * DESCRIPTION: Dispatch a device notification event to a previously 224 * installed handler. 225 * 226 ******************************************************************************/ 227 228ACPI_STATUS 229AcpiEvQueueNotifyRequest ( 230 ACPI_NAMESPACE_NODE *Node, 231 UINT32 NotifyValue) 232{ 233 ACPI_OPERAND_OBJECT *ObjDesc; 234 ACPI_OPERAND_OBJECT *HandlerObj = NULL; 235 ACPI_GENERIC_STATE *NotifyInfo; 236 ACPI_STATUS Status = AE_OK; 237 238 239 ACPI_FUNCTION_NAME ("EvQueueNotifyRequest"); 240 241 242 /* 243 * For value 1 (Ejection Request), some device method may need to be run. 244 * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need to be run. 245 * For value 0x80 (Status Change) on the power button or sleep button, 246 * initiate soft-off or sleep operation? 247 */ 248 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 249 "Dispatching Notify(%X) on node %p\n", NotifyValue, Node)); 250 251 switch (NotifyValue) 252 { 253 case 0: 254 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Re-enumerate Devices\n")); 255 break; 256 257 case 1: 258 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Ejection Request\n")); 259 break; 260 261 case 2: 262 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Device Wake\n")); 263 break; 264 265 case 0x80: 266 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Status Change\n")); 267 break; 268 269 default: 270 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Unknown Notify Value: %X \n", NotifyValue)); 271 break; 272 } 273 274 /* 275 * Get the notify object attached to the NS Node 276 */ 277 ObjDesc = AcpiNsGetAttachedObject (Node); 278 if (ObjDesc) 279 { 280 /* We have the notify object, Get the right handler */ 281 282 switch (Node->Type) 283 { 284 case ACPI_TYPE_DEVICE: 285 case ACPI_TYPE_THERMAL: 286 case ACPI_TYPE_PROCESSOR: 287 case ACPI_TYPE_POWER: 288 289 if (NotifyValue <= ACPI_MAX_SYS_NOTIFY) 290 { 291 HandlerObj = ObjDesc->CommonNotify.SysHandler; 292 } 293 else 294 { 295 HandlerObj = ObjDesc->CommonNotify.DrvHandler; 296 } 297 break; 298 299 default: 300 /* All other types are not supported */ 301 return (AE_TYPE); 302 } 303 } 304 305 /* If there is any handler to run, schedule the dispatcher */ 306 307 if ((AcpiGbl_SysNotify.Handler && (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) || 308 (AcpiGbl_DrvNotify.Handler && (NotifyValue > ACPI_MAX_SYS_NOTIFY)) || 309 HandlerObj) 310 { 311 NotifyInfo = AcpiUtCreateGenericState (); 312 if (!NotifyInfo) 313 { 314 return (AE_NO_MEMORY); 315 } 316 317 NotifyInfo->Common.DataType = ACPI_DESC_TYPE_STATE_NOTIFY; 318 NotifyInfo->Notify.Node = Node; 319 NotifyInfo->Notify.Value = (UINT16) NotifyValue; 320 NotifyInfo->Notify.HandlerObj = HandlerObj; 321 322 Status = AcpiOsQueueForExecution (OSD_PRIORITY_HIGH, 323 AcpiEvNotifyDispatch, NotifyInfo); 324 if (ACPI_FAILURE (Status)) 325 { 326 AcpiUtDeleteGenericState (NotifyInfo); 327 } 328 } 329 330 if (!HandlerObj) 331 { 332 /* There is no per-device notify handler for this device */ 333 334 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 335 "No notify handler for [%4.4s] node %p\n", Node->Name.Ascii, Node)); 336 } 337 338 return (Status); 339} 340 341 342/******************************************************************************* 343 * 344 * FUNCTION: AcpiEvNotifyDispatch 345 * 346 * PARAMETERS: 347 * 348 * RETURN: None. 349 * 350 * DESCRIPTION: Dispatch a device notification event to a previously 351 * installed handler. 352 * 353 ******************************************************************************/ 354 355void ACPI_SYSTEM_XFACE 356AcpiEvNotifyDispatch ( 357 void *Context) 358{ 359 ACPI_GENERIC_STATE *NotifyInfo = (ACPI_GENERIC_STATE *) Context; 360 ACPI_NOTIFY_HANDLER GlobalHandler = NULL; 361 void *GlobalContext = NULL; 362 ACPI_OPERAND_OBJECT *HandlerObj; 363 364 365 ACPI_FUNCTION_ENTRY (); 366 367 368 /* 369 * We will invoke a global notify handler if installed. 370 * This is done _before_ we invoke the per-device handler attached to the device. 371 */ 372 if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY) 373 { 374 /* Global system notification handler */ 375 376 if (AcpiGbl_SysNotify.Handler) 377 { 378 GlobalHandler = AcpiGbl_SysNotify.Handler; 379 GlobalContext = AcpiGbl_SysNotify.Context; 380 } 381 } 382 else 383 { 384 /* Global driver notification handler */ 385 386 if (AcpiGbl_DrvNotify.Handler) 387 { 388 GlobalHandler = AcpiGbl_DrvNotify.Handler; 389 GlobalContext = AcpiGbl_DrvNotify.Context; 390 } 391 } 392 393 /* Invoke the system handler first, if present */ 394 395 if (GlobalHandler) 396 { 397 GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value, GlobalContext); 398 } 399 400 /* Now invoke the per-device handler, if present */ 401 402 HandlerObj = NotifyInfo->Notify.HandlerObj; 403 if (HandlerObj) 404 { 405 HandlerObj->NotifyHandler.Handler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value, 406 HandlerObj->NotifyHandler.Context); 407 } 408 409 /* All done with the info object */ 410 411 AcpiUtDeleteGenericState (NotifyInfo); 412} 413 414 415/******************************************************************************* 416 * 417 * FUNCTION: AcpiEvGlobalLockThread 418 * 419 * RETURN: None 420 * 421 * DESCRIPTION: Invoked by SCI interrupt handler upon acquisition of the 422 * Global Lock. Simply signal all threads that are waiting 423 * for the lock. 424 * 425 ******************************************************************************/ 426 427static void ACPI_SYSTEM_XFACE 428AcpiEvGlobalLockThread ( 429 void *Context) 430{ 431 ACPI_STATUS Status; 432 433 434 /* Signal threads that are waiting for the lock */ 435 436 if (AcpiGbl_GlobalLockThreadCount) 437 { 438 /* Send sufficient units to the semaphore */ 439 440 Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 441 AcpiGbl_GlobalLockThreadCount); 442 if (ACPI_FAILURE (Status)) 443 { 444 ACPI_REPORT_ERROR (("Could not signal Global Lock semaphore\n")); 445 } 446 } 447} 448 449 450/******************************************************************************* 451 * 452 * FUNCTION: AcpiEvGlobalLockHandler 453 * 454 * RETURN: Status 455 * 456 * DESCRIPTION: Invoked directly from the SCI handler when a global lock 457 * release interrupt occurs. Grab the global lock and queue 458 * the global lock thread for execution 459 * 460 ******************************************************************************/ 461 462static UINT32 463AcpiEvGlobalLockHandler ( 464 void *Context) 465{ 466 BOOLEAN Acquired = FALSE; 467 ACPI_STATUS Status; 468 469 470 /* 471 * Attempt to get the lock 472 * If we don't get it now, it will be marked pending and we will 473 * take another interrupt when it becomes free. 474 */ 475 ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Acquired); 476 if (Acquired) 477 { 478 /* Got the lock, now wake all threads waiting for it */ 479 480 AcpiGbl_GlobalLockAcquired = TRUE; 481 482 /* Run the Global Lock thread which will signal all waiting threads */ 483 484 Status = AcpiOsQueueForExecution (OSD_PRIORITY_HIGH, 485 AcpiEvGlobalLockThread, Context); 486 if (ACPI_FAILURE (Status)) 487 { 488 ACPI_REPORT_ERROR (("Could not queue Global Lock thread, %s\n", 489 AcpiFormatException (Status))); 490 491 return (ACPI_INTERRUPT_NOT_HANDLED); 492 } 493 } 494 495 return (ACPI_INTERRUPT_HANDLED); 496} 497 498 499/******************************************************************************* 500 * 501 * FUNCTION: AcpiEvInitGlobalLockHandler 502 * 503 * RETURN: Status 504 * 505 * DESCRIPTION: Install a handler for the global lock release event 506 * 507 ******************************************************************************/ 508 509ACPI_STATUS 510AcpiEvInitGlobalLockHandler (void) 511{ 512 ACPI_STATUS Status; 513 514 515 ACPI_FUNCTION_TRACE ("EvInitGlobalLockHandler"); 516 517 518 AcpiGbl_GlobalLockPresent = TRUE; 519 Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL, 520 AcpiEvGlobalLockHandler, NULL); 521 522 /* 523 * If the global lock does not exist on this platform, the attempt 524 * to enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick) 525 * Map to AE_OK, but mark global lock as not present. 526 * Any attempt to actually use the global lock will be flagged 527 * with an error. 528 */ 529 if (Status == AE_NO_HARDWARE_RESPONSE) 530 { 531 AcpiGbl_GlobalLockPresent = FALSE; 532 Status = AE_OK; 533 } 534 535 return_ACPI_STATUS (Status); 536} 537 538 539/****************************************************************************** 540 * 541 * FUNCTION: AcpiEvAcquireGlobalLock 542 * 543 * RETURN: Status 544 * 545 * DESCRIPTION: Attempt to gain ownership of the Global Lock. 546 * 547 *****************************************************************************/ 548 549ACPI_STATUS 550AcpiEvAcquireGlobalLock ( 551 UINT16 Timeout) 552{ 553 ACPI_STATUS Status = AE_OK; 554 BOOLEAN Acquired = FALSE; 555 556 557 ACPI_FUNCTION_TRACE ("EvAcquireGlobalLock"); 558 559 560#ifndef ACPI_APPLICATION 561 /* Make sure that we actually have a global lock */ 562 563 if (!AcpiGbl_GlobalLockPresent) 564 { 565 return_ACPI_STATUS (AE_NO_GLOBAL_LOCK); 566 } 567#endif 568 569 /* One more thread wants the global lock */ 570 571 AcpiGbl_GlobalLockThreadCount++; 572 573 /* If we (OS side vs. BIOS side) have the hardware lock already, we are done */ 574 575 if (AcpiGbl_GlobalLockAcquired) 576 { 577 return_ACPI_STATUS (AE_OK); 578 } 579 580 /* We must acquire the actual hardware lock */ 581 582 ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Acquired); 583 if (Acquired) 584 { 585 /* We got the lock */ 586 587 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired the HW Global Lock\n")); 588 589 AcpiGbl_GlobalLockAcquired = TRUE; 590 return_ACPI_STATUS (AE_OK); 591 } 592 593 /* 594 * Did not get the lock. The pending bit was set above, and we must now 595 * wait until we get the global lock released interrupt. 596 */ 597 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for the HW Global Lock\n")); 598 599 /* 600 * Acquire the global lock semaphore first. 601 * Since this wait will block, we must release the interpreter 602 */ 603 Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore, 604 Timeout); 605 return_ACPI_STATUS (Status); 606} 607 608 609/******************************************************************************* 610 * 611 * FUNCTION: AcpiEvReleaseGlobalLock 612 * 613 * DESCRIPTION: Releases ownership of the Global Lock. 614 * 615 ******************************************************************************/ 616 617ACPI_STATUS 618AcpiEvReleaseGlobalLock (void) 619{ 620 BOOLEAN Pending = FALSE; 621 ACPI_STATUS Status = AE_OK; 622 623 624 ACPI_FUNCTION_TRACE ("EvReleaseGlobalLock"); 625 626 627 if (!AcpiGbl_GlobalLockThreadCount) 628 { 629 ACPI_REPORT_WARNING(("Cannot release HW Global Lock, it has not been acquired\n")); 630 return_ACPI_STATUS (AE_NOT_ACQUIRED); 631 } 632 633 /* One fewer thread has the global lock */ 634 635 AcpiGbl_GlobalLockThreadCount--; 636 if (AcpiGbl_GlobalLockThreadCount) 637 { 638 /* There are still some threads holding the lock, cannot release */ 639 640 return_ACPI_STATUS (AE_OK); 641 } 642 643 /* 644 * No more threads holding lock, we can do the actual hardware 645 * release 646 */ 647 ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Pending); 648 AcpiGbl_GlobalLockAcquired = FALSE; 649 650 /* 651 * If the pending bit was set, we must write GBL_RLS to the control 652 * register 653 */ 654 if (Pending) 655 { 656 Status = AcpiSetRegister (ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1, ACPI_MTX_LOCK); 657 } 658 659 return_ACPI_STATUS (Status); 660} 661 662 663/****************************************************************************** 664 * 665 * FUNCTION: AcpiEvTerminate 666 * 667 * PARAMETERS: none 668 * 669 * RETURN: none 670 * 671 * DESCRIPTION: Disable events and free memory allocated for table storage. 672 * 673 ******************************************************************************/ 674 675void 676AcpiEvTerminate (void) 677{ 678 NATIVE_UINT_MAX32 i; 679 ACPI_STATUS Status; 680 681 682 ACPI_FUNCTION_TRACE ("EvTerminate"); 683 684 685 if (AcpiGbl_EventsInitialized) 686 { 687 /* 688 * Disable all event-related functionality. 689 * In all cases, on error, print a message but obviously we don't abort. 690 */ 691 692 /* 693 * Disable all fixed events 694 */ 695 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) 696 { 697 Status = AcpiDisableEvent(i, ACPI_EVENT_FIXED, 0); 698 if (ACPI_FAILURE (Status)) 699 { 700 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable fixed event %d\n", i)); 701 } 702 } 703 704 /* 705 * Disable all GPEs 706 */ 707 for (i = 0; i < AcpiGbl_GpeNumberMax; i++) 708 { 709 if (AcpiEvGetGpeNumberIndex(i) != ACPI_GPE_INVALID) 710 { 711 Status = AcpiHwDisableGpe(i); 712 if (ACPI_FAILURE (Status)) 713 { 714 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable GPE %d\n", i)); 715 } 716 } 717 } 718 719 /* 720 * Remove SCI handler 721 */ 722 Status = AcpiEvRemoveSciHandler(); 723 if (ACPI_FAILURE(Status)) 724 { 725 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not remove SCI handler\n")); 726 } 727 } 728 729 /* 730 * Return to original mode if necessary 731 */ 732 if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY) 733 { 734 Status = AcpiDisable (); 735 if (ACPI_FAILURE (Status)) 736 { 737 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "AcpiDisable failed\n")); 738 } 739 } 740 741 /* 742 * Free global tables, etc. 743 */ 744 if (AcpiGbl_GpeRegisterInfo) 745 { 746 ACPI_MEM_FREE (AcpiGbl_GpeRegisterInfo); 747 AcpiGbl_GpeRegisterInfo = NULL; 748 } 749 750 if (AcpiGbl_GpeNumberInfo) 751 { 752 ACPI_MEM_FREE (AcpiGbl_GpeNumberInfo); 753 AcpiGbl_GpeNumberInfo = NULL; 754 } 755 756 if (AcpiGbl_GpeNumberToIndex) 757 { 758 ACPI_MEM_FREE (AcpiGbl_GpeNumberToIndex); 759 AcpiGbl_GpeNumberToIndex = NULL; 760 } 761 762 return_VOID; 763} 764 765