xref: /titanic_41/usr/src/uts/intel/io/acpica/events/evmisc.c (revision e802abbda8c322f24d47835734f4a793ef15ddc8)
1 /******************************************************************************
2  *
3  * Module Name: evmisc - Miscellaneous event manager support functions
4  *              $Revision: 1.109 $
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 #include "acpi.h"
118 #include "acevents.h"
119 #include "acnamesp.h"
120 #include "acinterp.h"
121 
122 #define _COMPONENT          ACPI_EVENTS
123         ACPI_MODULE_NAME    ("evmisc")
124 
125 
126 /* Pointer to FACS needed for the Global Lock */
127 
128 static ACPI_TABLE_FACS      *Facs = NULL;
129 
130 /* Local prototypes */
131 
132 static void ACPI_SYSTEM_XFACE
133 AcpiEvNotifyDispatch (
134     void                    *Context);
135 
136 static UINT32
137 AcpiEvGlobalLockHandler (
138     void                    *Context);
139 
140 static ACPI_STATUS
141 AcpiEvRemoveGlobalLockHandler (
142     void);
143 
144 
145 /*******************************************************************************
146  *
147  * FUNCTION:    AcpiEvIsNotifyObject
148  *
149  * PARAMETERS:  Node            - Node to check
150  *
151  * RETURN:      TRUE if notifies allowed on this object
152  *
153  * DESCRIPTION: Check type of node for a object that supports notifies.
154  *
155  *              TBD: This could be replaced by a flag bit in the node.
156  *
157  ******************************************************************************/
158 
159 BOOLEAN
160 AcpiEvIsNotifyObject (
161     ACPI_NAMESPACE_NODE     *Node)
162 {
163     switch (Node->Type)
164     {
165     case ACPI_TYPE_DEVICE:
166     case ACPI_TYPE_PROCESSOR:
167     case ACPI_TYPE_THERMAL:
168         /*
169          * These are the ONLY objects that can receive ACPI notifications
170          */
171         return (TRUE);
172 
173     default:
174         return (FALSE);
175     }
176 }
177 
178 
179 /*******************************************************************************
180  *
181  * FUNCTION:    AcpiEvQueueNotifyRequest
182  *
183  * PARAMETERS:  Node            - NS node for the notified object
184  *              NotifyValue     - Value from the Notify() request
185  *
186  * RETURN:      Status
187  *
188  * DESCRIPTION: Dispatch a device notification event to a previously
189  *              installed handler.
190  *
191  ******************************************************************************/
192 
193 ACPI_STATUS
194 AcpiEvQueueNotifyRequest (
195     ACPI_NAMESPACE_NODE     *Node,
196     UINT32                  NotifyValue)
197 {
198     ACPI_OPERAND_OBJECT     *ObjDesc;
199     ACPI_OPERAND_OBJECT     *HandlerObj = NULL;
200     ACPI_GENERIC_STATE      *NotifyInfo;
201     ACPI_STATUS             Status = AE_OK;
202 
203 
204     ACPI_FUNCTION_NAME (EvQueueNotifyRequest);
205 
206 
207     /*
208      * For value 3 (Ejection Request), some device method may need to be run.
209      * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need
210      *   to be run.
211      * For value 0x80 (Status Change) on the power button or sleep button,
212      *   initiate soft-off or sleep operation?
213      */
214     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
215         "Dispatching Notify on [%4.4s] Node %p Value 0x%2.2X (%s)\n",
216         AcpiUtGetNodeName (Node), Node, NotifyValue,
217         AcpiUtGetNotifyName (NotifyValue)));
218 
219     /* Get the notify object attached to the NS Node */
220 
221     ObjDesc = AcpiNsGetAttachedObject (Node);
222     if (ObjDesc)
223     {
224         /* We have the notify object, Get the right handler */
225 
226         switch (Node->Type)
227         {
228         /* Notify allowed only on these types */
229 
230         case ACPI_TYPE_DEVICE:
231         case ACPI_TYPE_THERMAL:
232         case ACPI_TYPE_PROCESSOR:
233 
234             if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
235             {
236                 HandlerObj = ObjDesc->CommonNotify.SystemNotify;
237             }
238             else
239             {
240                 HandlerObj = ObjDesc->CommonNotify.DeviceNotify;
241             }
242             break;
243 
244         default:
245             /* All other types are not supported */
246             return (AE_TYPE);
247         }
248     }
249 
250     /*
251      * If there is any handler to run, schedule the dispatcher.
252      * Check for:
253      * 1) Global system notify handler
254      * 2) Global device notify handler
255      * 3) Per-device notify handler
256      */
257     if ((AcpiGbl_SystemNotify.Handler && (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) ||
258         (AcpiGbl_DeviceNotify.Handler && (NotifyValue > ACPI_MAX_SYS_NOTIFY))  ||
259         HandlerObj)
260     {
261         NotifyInfo = AcpiUtCreateGenericState ();
262         if (!NotifyInfo)
263         {
264             return (AE_NO_MEMORY);
265         }
266 
267         if (!HandlerObj)
268         {
269             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
270                 "Executing system notify handler for Notify (%4.4s, %X) node %p\n",
271                 AcpiUtGetNodeName (Node), NotifyValue, Node));
272         }
273 
274         NotifyInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY;
275         NotifyInfo->Notify.Node = Node;
276         NotifyInfo->Notify.Value = (UINT16) NotifyValue;
277         NotifyInfo->Notify.HandlerObj = HandlerObj;
278 
279         Status = AcpiOsExecute (
280                     OSL_NOTIFY_HANDLER, AcpiEvNotifyDispatch, NotifyInfo);
281         if (ACPI_FAILURE (Status))
282         {
283             AcpiUtDeleteGenericState (NotifyInfo);
284         }
285     }
286     else
287     {
288         /*
289          * There is no notify handler (per-device or system) for this device.
290          */
291         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
292             "No notify handler for Notify (%4.4s, %X) node %p\n",
293             AcpiUtGetNodeName (Node), NotifyValue, Node));
294     }
295 
296     return (Status);
297 }
298 
299 
300 /*******************************************************************************
301  *
302  * FUNCTION:    AcpiEvNotifyDispatch
303  *
304  * PARAMETERS:  Context         - To be passed to the notify handler
305  *
306  * RETURN:      None.
307  *
308  * DESCRIPTION: Dispatch a device notification event to a previously
309  *              installed handler.
310  *
311  ******************************************************************************/
312 
313 static void ACPI_SYSTEM_XFACE
314 AcpiEvNotifyDispatch (
315     void                    *Context)
316 {
317     ACPI_GENERIC_STATE      *NotifyInfo = (ACPI_GENERIC_STATE *) Context;
318     ACPI_NOTIFY_HANDLER     GlobalHandler = NULL;
319     void                    *GlobalContext = NULL;
320     ACPI_OPERAND_OBJECT     *HandlerObj;
321 
322 
323     ACPI_FUNCTION_ENTRY ();
324 
325 
326     /*
327      * We will invoke a global notify handler if installed.
328      * This is done _before_ we invoke the per-device handler attached
329      * to the device.
330      */
331     if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY)
332     {
333         /* Global system notification handler */
334 
335         if (AcpiGbl_SystemNotify.Handler)
336         {
337             GlobalHandler = AcpiGbl_SystemNotify.Handler;
338             GlobalContext = AcpiGbl_SystemNotify.Context;
339         }
340     }
341     else
342     {
343         /* Global driver notification handler */
344 
345         if (AcpiGbl_DeviceNotify.Handler)
346         {
347             GlobalHandler = AcpiGbl_DeviceNotify.Handler;
348             GlobalContext = AcpiGbl_DeviceNotify.Context;
349         }
350     }
351 
352     /* Invoke the system handler first, if present */
353 
354     if (GlobalHandler)
355     {
356         GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value,
357             GlobalContext);
358     }
359 
360     /* Now invoke the per-device handler, if present */
361 
362     HandlerObj = NotifyInfo->Notify.HandlerObj;
363     if (HandlerObj)
364     {
365         HandlerObj->Notify.Handler (NotifyInfo->Notify.Node,
366             NotifyInfo->Notify.Value,
367             HandlerObj->Notify.Context);
368     }
369 
370     /* All done with the info object */
371 
372     AcpiUtDeleteGenericState (NotifyInfo);
373 }
374 
375 
376 /*******************************************************************************
377  *
378  * FUNCTION:    AcpiEvGlobalLockHandler
379  *
380  * PARAMETERS:  Context         - From thread interface, not used
381  *
382  * RETURN:      ACPI_INTERRUPT_HANDLED
383  *
384  * DESCRIPTION: Invoked directly from the SCI handler when a global lock
385  *              release interrupt occurs. Attempt to acquire the global lock,
386  *              if successful, signal the thread waiting for the lock.
387  *
388  * NOTE: Assumes that the semaphore can be signaled from interrupt level. If
389  * this is not possible for some reason, a separate thread will have to be
390  * scheduled to do this.
391  *
392  ******************************************************************************/
393 
394 static UINT32
395 AcpiEvGlobalLockHandler (
396     void                    *Context)
397 {
398     BOOLEAN                 Acquired = FALSE;
399     ACPI_STATUS             Status;
400 
401 
402     /*
403      * Attempt to get the lock.
404      *
405      * If we don't get it now, it will be marked pending and we will
406      * take another interrupt when it becomes free.
407      */
408     ACPI_ACQUIRE_GLOBAL_LOCK (Facs, Acquired);
409     if (Acquired)
410     {
411         /* Got the lock, now wake the thread waiting for it */
412 
413         AcpiGbl_GlobalLockAcquired = TRUE;
414 
415         /* Send a unit to the semaphore */
416 
417         Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
418         if (ACPI_FAILURE (Status))
419         {
420             ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
421         }
422     }
423 
424     return (ACPI_INTERRUPT_HANDLED);
425 }
426 
427 
428 /*******************************************************************************
429  *
430  * FUNCTION:    AcpiEvInitGlobalLockHandler
431  *
432  * PARAMETERS:  None
433  *
434  * RETURN:      Status
435  *
436  * DESCRIPTION: Install a handler for the global lock release event
437  *
438  ******************************************************************************/
439 
440 ACPI_STATUS
441 AcpiEvInitGlobalLockHandler (
442     void)
443 {
444     ACPI_STATUS             Status;
445 
446 
447     ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
448 
449 
450     Status = AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS,
451                 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &Facs));
452     if (ACPI_FAILURE (Status))
453     {
454         return_ACPI_STATUS (Status);
455     }
456 
457     AcpiGbl_GlobalLockPresent = TRUE;
458     Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
459                 AcpiEvGlobalLockHandler, NULL);
460 
461     /*
462      * If the global lock does not exist on this platform, the attempt
463      * to enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick)
464      * Map to AE_OK, but mark global lock as not present.
465      * Any attempt to actually use the global lock will be flagged
466      * with an error.
467      */
468     if (Status == AE_NO_HARDWARE_RESPONSE)
469     {
470         ACPI_ERROR ((AE_INFO,
471             "No response from Global Lock hardware, disabling lock"));
472 
473         AcpiGbl_GlobalLockPresent = FALSE;
474         Status = AE_OK;
475     }
476 
477     return_ACPI_STATUS (Status);
478 }
479 
480 
481 /*******************************************************************************
482  *
483  * FUNCTION:    AcpiEvRemoveGlobalLockHandler
484  *
485  * PARAMETERS:  None
486  *
487  * RETURN:      Status
488  *
489  * DESCRIPTION: Remove the handler for the Global Lock
490  *
491  ******************************************************************************/
492 
493 static ACPI_STATUS
494 AcpiEvRemoveGlobalLockHandler (
495     void)
496 {
497     ACPI_STATUS             Status;
498 
499 
500     ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
501 
502     AcpiGbl_GlobalLockPresent = FALSE;
503     Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL,
504                 AcpiEvGlobalLockHandler);
505 
506     return_ACPI_STATUS (Status);
507 }
508 
509 
510 /******************************************************************************
511  *
512  * FUNCTION:    AcpiEvAcquireGlobalLock
513  *
514  * PARAMETERS:  Timeout         - Max time to wait for the lock, in millisec.
515  *
516  * RETURN:      Status
517  *
518  * DESCRIPTION: Attempt to gain ownership of the Global Lock.
519  *
520  * MUTEX:       Interpreter must be locked
521  *
522  * Note: The original implementation allowed multiple threads to "acquire" the
523  * Global Lock, and the OS would hold the lock until the last thread had
524  * released it. However, this could potentially starve the BIOS out of the
525  * lock, especially in the case where there is a tight handshake between the
526  * Embedded Controller driver and the BIOS. Therefore, this implementation
527  * allows only one thread to acquire the HW Global Lock at a time, and makes
528  * the global lock appear as a standard mutex on the OS side.
529  *
530  *****************************************************************************/
531 
532 ACPI_STATUS
533 AcpiEvAcquireGlobalLock (
534     UINT16                  Timeout)
535 {
536     ACPI_STATUS             Status = AE_OK;
537     BOOLEAN                 Acquired = FALSE;
538 
539 
540     ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
541 
542 
543     /*
544      * Only one thread can acquire the GL at a time, the GlobalLockMutex
545      * enforces this. This interface releases the interpreter if we must wait.
546      */
547     Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
548                 Timeout);
549     if (ACPI_FAILURE (Status))
550     {
551         return_ACPI_STATUS (Status);
552     }
553 
554     /*
555      * Update the global lock handle and check for wraparound. The handle is
556      * only used for the external global lock interfaces, but it is updated
557      * here to properly handle the case where a single thread may acquire the
558      * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
559      * handle is therefore updated on the first acquire from a given thread
560      * regardless of where the acquisition request originated.
561      */
562     AcpiGbl_GlobalLockHandle++;
563     if (AcpiGbl_GlobalLockHandle == 0)
564     {
565         AcpiGbl_GlobalLockHandle = 1;
566     }
567 
568     /*
569      * Make sure that a global lock actually exists. If not, just treat
570      * the lock as a standard mutex.
571      */
572     if (!AcpiGbl_GlobalLockPresent)
573     {
574         AcpiGbl_GlobalLockAcquired = TRUE;
575         return_ACPI_STATUS (AE_OK);
576     }
577 
578     /* Attempt to acquire the actual hardware lock */
579 
580     ACPI_ACQUIRE_GLOBAL_LOCK (Facs, Acquired);
581     if (Acquired)
582     {
583        /* We got the lock */
584 
585         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired hardware Global Lock\n"));
586 
587         AcpiGbl_GlobalLockAcquired = TRUE;
588         return_ACPI_STATUS (AE_OK);
589     }
590 
591     /*
592      * Did not get the lock. The pending bit was set above, and we must now
593      * wait until we get the global lock released interrupt.
594      */
595     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for hardware Global Lock\n"));
596 
597     /*
598      * Wait for handshake with the global lock interrupt handler.
599      * This interface releases the interpreter if we must wait.
600      */
601     Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore,
602                 ACPI_WAIT_FOREVER);
603 
604     return_ACPI_STATUS (Status);
605 }
606 
607 
608 /*******************************************************************************
609  *
610  * FUNCTION:    AcpiEvReleaseGlobalLock
611  *
612  * PARAMETERS:  None
613  *
614  * RETURN:      Status
615  *
616  * DESCRIPTION: Releases ownership of the Global Lock.
617  *
618  ******************************************************************************/
619 
620 ACPI_STATUS
621 AcpiEvReleaseGlobalLock (
622     void)
623 {
624     BOOLEAN                 Pending = FALSE;
625     ACPI_STATUS             Status = AE_OK;
626 
627 
628     ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
629 
630 
631     /* Lock must be already acquired */
632 
633     if (!AcpiGbl_GlobalLockAcquired)
634     {
635         ACPI_WARNING ((AE_INFO,
636             "Cannot release the ACPI Global Lock, it has not been acquired"));
637         return_ACPI_STATUS (AE_NOT_ACQUIRED);
638     }
639 
640     if (AcpiGbl_GlobalLockPresent)
641     {
642         /* Allow any thread to release the lock */
643 
644         ACPI_RELEASE_GLOBAL_LOCK (Facs, Pending);
645 
646         /*
647          * If the pending bit was set, we must write GBL_RLS to the control
648          * register
649          */
650         if (Pending)
651         {
652             Status = AcpiSetRegister (
653                         ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1);
654         }
655 
656         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
657     }
658 
659     AcpiGbl_GlobalLockAcquired = FALSE;
660 
661     /* Release the local GL mutex */
662 
663     AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
664     return_ACPI_STATUS (Status);
665 }
666 
667 
668 /******************************************************************************
669  *
670  * FUNCTION:    AcpiEvTerminate
671  *
672  * PARAMETERS:  none
673  *
674  * RETURN:      none
675  *
676  * DESCRIPTION: Disable events and free memory allocated for table storage.
677  *
678  ******************************************************************************/
679 
680 void
681 AcpiEvTerminate (
682     void)
683 {
684     UINT32                  i;
685     ACPI_STATUS             Status;
686 
687 
688     ACPI_FUNCTION_TRACE (EvTerminate);
689 
690 
691     if (AcpiGbl_EventsInitialized)
692     {
693         /*
694          * Disable all event-related functionality.
695          * In all cases, on error, print a message but obviously we don't abort.
696          */
697 
698         /* Disable all fixed events */
699 
700         for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
701         {
702             Status = AcpiDisableEvent (i, 0);
703             if (ACPI_FAILURE (Status))
704             {
705                 ACPI_ERROR ((AE_INFO,
706                     "Could not disable fixed event %d", (UINT32) i));
707             }
708         }
709 
710         /* Disable all GPEs in all GPE blocks */
711 
712         Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock);
713 
714         /* Remove SCI handler */
715 
716         Status = AcpiEvRemoveSciHandler ();
717         if (ACPI_FAILURE(Status))
718         {
719             ACPI_ERROR ((AE_INFO,
720                 "Could not remove SCI handler"));
721         }
722 
723         Status = AcpiEvRemoveGlobalLockHandler ();
724         if (ACPI_FAILURE(Status))
725         {
726             ACPI_ERROR ((AE_INFO,
727                 "Could not remove Global Lock handler"));
728         }
729     }
730 
731     /* Deallocate all handler objects installed within GPE info structs */
732 
733     Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers);
734 
735     /* Return to original mode if necessary */
736 
737     if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY)
738     {
739         Status = AcpiDisable ();
740         if (ACPI_FAILURE (Status))
741         {
742             ACPI_WARNING ((AE_INFO, "AcpiDisable failed"));
743         }
744     }
745     return_VOID;
746 }
747 
748