17c478bd9Sstevel@tonic-gate /******************************************************************************
27c478bd9Sstevel@tonic-gate  *
37c478bd9Sstevel@tonic-gate  * Module Name: evxface - External interfaces for ACPI events
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  *****************************************************************************/
67c478bd9Sstevel@tonic-gate 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
127c478bd9Sstevel@tonic-gate  * All rights reserved.
137c478bd9Sstevel@tonic-gate  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
11926f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross  * are met:
12226f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross  *    without modification.
12526f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross  *    binary redistribution.
13026f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross  *    from this software without specific prior written permission.
13326f3cdf0SGordon Ross  *
13426f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
1517c478bd9Sstevel@tonic-gate 
1527b1019a6SJerry Jelinek #define EXPORT_ACPI_INTERFACES
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #include "acpi.h"
155aa2aa9a6SDana Myers #include "accommon.h"
1567c478bd9Sstevel@tonic-gate #include "acnamesp.h"
1577c478bd9Sstevel@tonic-gate #include "acevents.h"
1587c478bd9Sstevel@tonic-gate #include "acinterp.h"
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #define _COMPONENT          ACPI_EVENTS
1617c478bd9Sstevel@tonic-gate         ACPI_MODULE_NAME    ("evxface")
1627c478bd9Sstevel@tonic-gate 
1637b1019a6SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE)
1647b1019a6SJerry Jelinek 
1657b1019a6SJerry Jelinek /* Local prototypes */
1667b1019a6SJerry Jelinek 
1677b1019a6SJerry Jelinek static ACPI_STATUS
1687b1019a6SJerry Jelinek AcpiEvInstallGpeHandler (
1697b1019a6SJerry Jelinek     ACPI_HANDLE             GpeDevice,
1707b1019a6SJerry Jelinek     UINT32                  GpeNumber,
1717b1019a6SJerry Jelinek     UINT32                  Type,
1727b1019a6SJerry Jelinek     BOOLEAN                 IsRawHandler,
1737b1019a6SJerry Jelinek     ACPI_GPE_HANDLER        Address,
1747b1019a6SJerry Jelinek     void                    *Context);
1757b1019a6SJerry Jelinek 
1767b1019a6SJerry Jelinek #endif
1777b1019a6SJerry Jelinek 
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*******************************************************************************
1807c478bd9Sstevel@tonic-gate  *
1817b1019a6SJerry Jelinek  * FUNCTION:    AcpiInstallNotifyHandler
1827c478bd9Sstevel@tonic-gate  *
1837b1019a6SJerry Jelinek  * PARAMETERS:  Device          - The device for which notifies will be handled
1847b1019a6SJerry Jelinek  *              HandlerType     - The type of handler:
1857b1019a6SJerry Jelinek  *                                  ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
1867b1019a6SJerry Jelinek  *                                  ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
1877b1019a6SJerry Jelinek  *                                  ACPI_ALL_NOTIFY:    Both System and Device
1887b1019a6SJerry Jelinek  *              Handler         - Address of the handler
1897b1019a6SJerry Jelinek  *              Context         - Value passed to the handler on each GPE
1907c478bd9Sstevel@tonic-gate  *
1917c478bd9Sstevel@tonic-gate  * RETURN:      Status
1927c478bd9Sstevel@tonic-gate  *
1937b1019a6SJerry Jelinek  * DESCRIPTION: Install a handler for notifications on an ACPI Device,
1947b1019a6SJerry Jelinek  *              ThermalZone, or Processor object.
1957b1019a6SJerry Jelinek  *
1967b1019a6SJerry Jelinek  * NOTES:       The Root namespace object may have only one handler for each
1977b1019a6SJerry Jelinek  *              type of notify (System/Device). Device/Thermal/Processor objects
1987b1019a6SJerry Jelinek  *              may have one device notify handler, and multiple system notify
1997b1019a6SJerry Jelinek  *              handlers.
2007c478bd9Sstevel@tonic-gate  *
2017c478bd9Sstevel@tonic-gate  ******************************************************************************/
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiInstallNotifyHandler(ACPI_HANDLE Device,UINT32 HandlerType,ACPI_NOTIFY_HANDLER Handler,void * Context)2047b1019a6SJerry Jelinek AcpiInstallNotifyHandler (
2057b1019a6SJerry Jelinek     ACPI_HANDLE             Device,
2067b1019a6SJerry Jelinek     UINT32                  HandlerType,
2077b1019a6SJerry Jelinek     ACPI_NOTIFY_HANDLER     Handler,
2087b1019a6SJerry Jelinek     void                    *Context)
2097c478bd9Sstevel@tonic-gate {
2107b1019a6SJerry Jelinek     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
2117b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *ObjDesc;
2127b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *HandlerObj;
2137c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
2147b1019a6SJerry Jelinek     UINT32                  i;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 
2177b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 
2207b1019a6SJerry Jelinek     /* Parameter validation */
2217b1019a6SJerry Jelinek 
2227b1019a6SJerry Jelinek     if ((!Device) || (!Handler) || (!HandlerType) ||
2237b1019a6SJerry Jelinek         (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
2247b1019a6SJerry Jelinek     {
2257b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_BAD_PARAMETER);
2267b1019a6SJerry Jelinek     }
2277b1019a6SJerry Jelinek 
2287b1019a6SJerry Jelinek     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
2297c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
2307c478bd9Sstevel@tonic-gate     {
2317c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
2327c478bd9Sstevel@tonic-gate     }
2337c478bd9Sstevel@tonic-gate 
2347b1019a6SJerry Jelinek     /*
2357b1019a6SJerry Jelinek      * Root Object:
2367b1019a6SJerry Jelinek      * Registering a notify handler on the root object indicates that the
2377b1019a6SJerry Jelinek      * caller wishes to receive notifications for all objects. Note that
2387b1019a6SJerry Jelinek      * only one global handler can be registered per notify type.
2397b1019a6SJerry Jelinek      * Ensure that a handler is not already installed.
2407b1019a6SJerry Jelinek      */
2417b1019a6SJerry Jelinek     if (Device == ACPI_ROOT_OBJECT)
2427b1019a6SJerry Jelinek     {
2437b1019a6SJerry Jelinek         for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
2447b1019a6SJerry Jelinek         {
2457b1019a6SJerry Jelinek             if (HandlerType & (i+1))
2467b1019a6SJerry Jelinek             {
2477b1019a6SJerry Jelinek                 if (AcpiGbl_GlobalNotify[i].Handler)
2487b1019a6SJerry Jelinek                 {
2497b1019a6SJerry Jelinek                     Status = AE_ALREADY_EXISTS;
2507b1019a6SJerry Jelinek                     goto UnlockAndExit;
2517b1019a6SJerry Jelinek                 }
2527b1019a6SJerry Jelinek 
2537b1019a6SJerry Jelinek                 AcpiGbl_GlobalNotify[i].Handler = Handler;
2547b1019a6SJerry Jelinek                 AcpiGbl_GlobalNotify[i].Context = Context;
2557b1019a6SJerry Jelinek             }
2567b1019a6SJerry Jelinek         }
2577c478bd9Sstevel@tonic-gate 
2587b1019a6SJerry Jelinek         goto UnlockAndExit; /* Global notify handler installed, all done */
2597b1019a6SJerry Jelinek     }
2607b1019a6SJerry Jelinek 
2617b1019a6SJerry Jelinek     /*
2627b1019a6SJerry Jelinek      * All Other Objects:
2637b1019a6SJerry Jelinek      * Caller will only receive notifications specific to the target
2647b1019a6SJerry Jelinek      * object. Note that only certain object types are allowed to
2657b1019a6SJerry Jelinek      * receive notifications.
2667b1019a6SJerry Jelinek      */
2677b1019a6SJerry Jelinek 
2687b1019a6SJerry Jelinek     /* Are Notifies allowed on this object? */
2697b1019a6SJerry Jelinek 
2707b1019a6SJerry Jelinek     if (!AcpiEvIsNotifyObject (Node))
2717c478bd9Sstevel@tonic-gate     {
2727b1019a6SJerry Jelinek         Status = AE_TYPE;
2737b1019a6SJerry Jelinek         goto UnlockAndExit;
2747c478bd9Sstevel@tonic-gate     }
2757c478bd9Sstevel@tonic-gate 
2767b1019a6SJerry Jelinek     /* Check for an existing internal object, might not exist */
2777c478bd9Sstevel@tonic-gate 
2787b1019a6SJerry Jelinek     ObjDesc = AcpiNsGetAttachedObject (Node);
2797b1019a6SJerry Jelinek     if (!ObjDesc)
2807b1019a6SJerry Jelinek     {
2817b1019a6SJerry Jelinek         /* Create a new object */
2827c478bd9Sstevel@tonic-gate 
2837b1019a6SJerry Jelinek         ObjDesc = AcpiUtCreateInternalObject (Node->Type);
2847b1019a6SJerry Jelinek         if (!ObjDesc)
2857b1019a6SJerry Jelinek         {
2867b1019a6SJerry Jelinek             Status = AE_NO_MEMORY;
2877b1019a6SJerry Jelinek             goto UnlockAndExit;
2887b1019a6SJerry Jelinek         }
2897b1019a6SJerry Jelinek 
2907b1019a6SJerry Jelinek         /* Attach new object to the Node, remove local reference */
2917b1019a6SJerry Jelinek 
2927b1019a6SJerry Jelinek         Status = AcpiNsAttachObject (Device, ObjDesc, Node->Type);
2937b1019a6SJerry Jelinek         AcpiUtRemoveReference (ObjDesc);
2947b1019a6SJerry Jelinek         if (ACPI_FAILURE (Status))
2957b1019a6SJerry Jelinek         {
2967b1019a6SJerry Jelinek             goto UnlockAndExit;
2977b1019a6SJerry Jelinek         }
2987b1019a6SJerry Jelinek     }
2997b1019a6SJerry Jelinek 
3007b1019a6SJerry Jelinek     /* Ensure that the handler is not already installed in the lists */
3017b1019a6SJerry Jelinek 
3027b1019a6SJerry Jelinek     for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
3037b1019a6SJerry Jelinek     {
3047b1019a6SJerry Jelinek         if (HandlerType & (i+1))
3057b1019a6SJerry Jelinek         {
3067b1019a6SJerry Jelinek             HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
3077b1019a6SJerry Jelinek             while (HandlerObj)
3087b1019a6SJerry Jelinek             {
3097b1019a6SJerry Jelinek                 if (HandlerObj->Notify.Handler == Handler)
3107b1019a6SJerry Jelinek                 {
3117b1019a6SJerry Jelinek                     Status = AE_ALREADY_EXISTS;
3127b1019a6SJerry Jelinek                     goto UnlockAndExit;
3137b1019a6SJerry Jelinek                 }
3147b1019a6SJerry Jelinek 
3157b1019a6SJerry Jelinek                 HandlerObj = HandlerObj->Notify.Next[i];
3167b1019a6SJerry Jelinek             }
3177b1019a6SJerry Jelinek         }
3187b1019a6SJerry Jelinek     }
3197b1019a6SJerry Jelinek 
3207b1019a6SJerry Jelinek     /* Create and populate a new notify handler object */
3217b1019a6SJerry Jelinek 
3227b1019a6SJerry Jelinek     HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY);
3237b1019a6SJerry Jelinek     if (!HandlerObj)
3247b1019a6SJerry Jelinek     {
3257b1019a6SJerry Jelinek         Status = AE_NO_MEMORY;
3267b1019a6SJerry Jelinek         goto UnlockAndExit;
3277b1019a6SJerry Jelinek     }
3287b1019a6SJerry Jelinek 
3297b1019a6SJerry Jelinek     HandlerObj->Notify.Node = Node;
3307b1019a6SJerry Jelinek     HandlerObj->Notify.HandlerType = HandlerType;
3317b1019a6SJerry Jelinek     HandlerObj->Notify.Handler = Handler;
3327b1019a6SJerry Jelinek     HandlerObj->Notify.Context = Context;
3337b1019a6SJerry Jelinek 
3347b1019a6SJerry Jelinek     /* Install the handler at the list head(s) */
3357b1019a6SJerry Jelinek 
3367b1019a6SJerry Jelinek     for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
3377b1019a6SJerry Jelinek     {
3387b1019a6SJerry Jelinek         if (HandlerType & (i+1))
3397b1019a6SJerry Jelinek         {
3407b1019a6SJerry Jelinek             HandlerObj->Notify.Next[i] =
3417b1019a6SJerry Jelinek                 ObjDesc->CommonNotify.NotifyList[i];
3427b1019a6SJerry Jelinek 
3437b1019a6SJerry Jelinek             ObjDesc->CommonNotify.NotifyList[i] = HandlerObj;
3447b1019a6SJerry Jelinek         }
3457b1019a6SJerry Jelinek     }
3467b1019a6SJerry Jelinek 
3477b1019a6SJerry Jelinek     /* Add an extra reference if handler was installed in both lists */
3487b1019a6SJerry Jelinek 
3497b1019a6SJerry Jelinek     if (HandlerType == ACPI_ALL_NOTIFY)
3507b1019a6SJerry Jelinek     {
3517b1019a6SJerry Jelinek         AcpiUtAddReference (HandlerObj);
3527b1019a6SJerry Jelinek     }
3537b1019a6SJerry Jelinek 
3547b1019a6SJerry Jelinek 
3557b1019a6SJerry Jelinek UnlockAndExit:
3567b1019a6SJerry Jelinek     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
3577c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiInstallNotifyHandler)3607b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler)
36127f7c583Smyers 
3627c478bd9Sstevel@tonic-gate 
36326f3cdf0SGordon Ross /*******************************************************************************
36426f3cdf0SGordon Ross  *
3657b1019a6SJerry Jelinek  * FUNCTION:    AcpiRemoveNotifyHandler
36626f3cdf0SGordon Ross  *
3677b1019a6SJerry Jelinek  * PARAMETERS:  Device          - The device for which the handler is installed
3687b1019a6SJerry Jelinek  *              HandlerType     - The type of handler:
3697b1019a6SJerry Jelinek  *                                  ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
3707b1019a6SJerry Jelinek  *                                  ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
3717b1019a6SJerry Jelinek  *                                  ACPI_ALL_NOTIFY:    Both System and Device
3727b1019a6SJerry Jelinek  *              Handler         - Address of the handler
37326f3cdf0SGordon Ross  *
37426f3cdf0SGordon Ross  * RETURN:      Status
37526f3cdf0SGordon Ross  *
3767b1019a6SJerry Jelinek  * DESCRIPTION: Remove a handler for notifies on an ACPI device
37726f3cdf0SGordon Ross  *
37826f3cdf0SGordon Ross  ******************************************************************************/
37926f3cdf0SGordon Ross 
38026f3cdf0SGordon Ross ACPI_STATUS
3817b1019a6SJerry Jelinek AcpiRemoveNotifyHandler (
3827b1019a6SJerry Jelinek     ACPI_HANDLE             Device,
3837b1019a6SJerry Jelinek     UINT32                  HandlerType,
3847b1019a6SJerry Jelinek     ACPI_NOTIFY_HANDLER     Handler)
38526f3cdf0SGordon Ross {
3867b1019a6SJerry Jelinek     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
3877b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *ObjDesc;
3887b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *HandlerObj;
3897b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *PreviousHandlerObj;
3907b1019a6SJerry Jelinek     ACPI_STATUS             Status = AE_OK;
3917b1019a6SJerry Jelinek     UINT32                  i;
39226f3cdf0SGordon Ross 
39326f3cdf0SGordon Ross 
3947b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler);
39526f3cdf0SGordon Ross 
39626f3cdf0SGordon Ross 
39726f3cdf0SGordon Ross     /* Parameter validation */
39826f3cdf0SGordon Ross 
3997b1019a6SJerry Jelinek     if ((!Device) || (!Handler) || (!HandlerType) ||
4007b1019a6SJerry Jelinek         (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
40126f3cdf0SGordon Ross     {
40226f3cdf0SGordon Ross         return_ACPI_STATUS (AE_BAD_PARAMETER);
40326f3cdf0SGordon Ross     }
40426f3cdf0SGordon Ross 
4057b1019a6SJerry Jelinek     /* Root Object. Global handlers are removed here */
4067b1019a6SJerry Jelinek 
4077b1019a6SJerry Jelinek     if (Device == ACPI_ROOT_OBJECT)
40826f3cdf0SGordon Ross     {
4097b1019a6SJerry Jelinek         for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
4107b1019a6SJerry Jelinek         {
4117b1019a6SJerry Jelinek             if (HandlerType & (i+1))
4127b1019a6SJerry Jelinek             {
4137b1019a6SJerry Jelinek                 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
4147b1019a6SJerry Jelinek                 if (ACPI_FAILURE (Status))
4157b1019a6SJerry Jelinek                 {
4167b1019a6SJerry Jelinek                     return_ACPI_STATUS (Status);
4177b1019a6SJerry Jelinek                 }
4187b1019a6SJerry Jelinek 
4197b1019a6SJerry Jelinek                 if (!AcpiGbl_GlobalNotify[i].Handler ||
4207b1019a6SJerry Jelinek                     (AcpiGbl_GlobalNotify[i].Handler != Handler))
4217b1019a6SJerry Jelinek                 {
4227b1019a6SJerry Jelinek                     Status = AE_NOT_EXIST;
4237b1019a6SJerry Jelinek                     goto UnlockAndExit;
4247b1019a6SJerry Jelinek                 }
4257b1019a6SJerry Jelinek 
4267b1019a6SJerry Jelinek                 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
4277b1019a6SJerry Jelinek                     "Removing global notify handler\n"));
4287b1019a6SJerry Jelinek 
4297b1019a6SJerry Jelinek                 AcpiGbl_GlobalNotify[i].Handler = NULL;
4307b1019a6SJerry Jelinek                 AcpiGbl_GlobalNotify[i].Context = NULL;
4317b1019a6SJerry Jelinek 
4327b1019a6SJerry Jelinek                 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
4337b1019a6SJerry Jelinek 
4347b1019a6SJerry Jelinek                 /* Make sure all deferred notify tasks are completed */
4357b1019a6SJerry Jelinek 
4367b1019a6SJerry Jelinek                 AcpiOsWaitEventsComplete ();
4377b1019a6SJerry Jelinek             }
4387b1019a6SJerry Jelinek         }
4397b1019a6SJerry Jelinek 
4407b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_OK);
44126f3cdf0SGordon Ross     }
44226f3cdf0SGordon Ross 
4437b1019a6SJerry Jelinek     /* All other objects: Are Notifies allowed on this object? */
44426f3cdf0SGordon Ross 
4457b1019a6SJerry Jelinek     if (!AcpiEvIsNotifyObject (Node))
44626f3cdf0SGordon Ross     {
4477b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_TYPE);
44826f3cdf0SGordon Ross     }
44926f3cdf0SGordon Ross 
4507b1019a6SJerry Jelinek     /* Must have an existing internal object */
45126f3cdf0SGordon Ross 
4527b1019a6SJerry Jelinek     ObjDesc = AcpiNsGetAttachedObject (Node);
4537b1019a6SJerry Jelinek     if (!ObjDesc)
4547b1019a6SJerry Jelinek     {
4557b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_NOT_EXIST);
4567b1019a6SJerry Jelinek     }
4577b1019a6SJerry Jelinek 
4587b1019a6SJerry Jelinek     /* Internal object exists. Find the handler and remove it */
4597b1019a6SJerry Jelinek 
4607b1019a6SJerry Jelinek     for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
4617b1019a6SJerry Jelinek     {
4627b1019a6SJerry Jelinek         if (HandlerType & (i+1))
4637b1019a6SJerry Jelinek         {
4647b1019a6SJerry Jelinek             Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
4657b1019a6SJerry Jelinek             if (ACPI_FAILURE (Status))
4667b1019a6SJerry Jelinek             {
4677b1019a6SJerry Jelinek                 return_ACPI_STATUS (Status);
4687b1019a6SJerry Jelinek             }
4697b1019a6SJerry Jelinek 
4707b1019a6SJerry Jelinek             HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
4717b1019a6SJerry Jelinek             PreviousHandlerObj = NULL;
4727b1019a6SJerry Jelinek 
4737b1019a6SJerry Jelinek             /* Attempt to find the handler in the handler list */
4747b1019a6SJerry Jelinek 
4757b1019a6SJerry Jelinek             while (HandlerObj &&
4767b1019a6SJerry Jelinek                   (HandlerObj->Notify.Handler != Handler))
4777b1019a6SJerry Jelinek             {
4787b1019a6SJerry Jelinek                 PreviousHandlerObj = HandlerObj;
4797b1019a6SJerry Jelinek                 HandlerObj = HandlerObj->Notify.Next[i];
4807b1019a6SJerry Jelinek             }
4817b1019a6SJerry Jelinek 
4827b1019a6SJerry Jelinek             if (!HandlerObj)
4837b1019a6SJerry Jelinek             {
4847b1019a6SJerry Jelinek                 Status = AE_NOT_EXIST;
4857b1019a6SJerry Jelinek                 goto UnlockAndExit;
4867b1019a6SJerry Jelinek             }
4877b1019a6SJerry Jelinek 
4887b1019a6SJerry Jelinek             /* Remove the handler object from the list */
4897b1019a6SJerry Jelinek 
4907b1019a6SJerry Jelinek             if (PreviousHandlerObj) /* Handler is not at the list head */
4917b1019a6SJerry Jelinek             {
4927b1019a6SJerry Jelinek                 PreviousHandlerObj->Notify.Next[i] =
4937b1019a6SJerry Jelinek                     HandlerObj->Notify.Next[i];
4947b1019a6SJerry Jelinek             }
4957b1019a6SJerry Jelinek             else /* Handler is at the list head */
4967b1019a6SJerry Jelinek             {
4977b1019a6SJerry Jelinek                 ObjDesc->CommonNotify.NotifyList[i] =
4987b1019a6SJerry Jelinek                     HandlerObj->Notify.Next[i];
4997b1019a6SJerry Jelinek             }
5007b1019a6SJerry Jelinek 
5017b1019a6SJerry Jelinek             (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
5027b1019a6SJerry Jelinek 
5037b1019a6SJerry Jelinek             /* Make sure all deferred notify tasks are completed */
5047b1019a6SJerry Jelinek 
5057b1019a6SJerry Jelinek             AcpiOsWaitEventsComplete ();
5067b1019a6SJerry Jelinek             AcpiUtRemoveReference (HandlerObj);
5077b1019a6SJerry Jelinek         }
5087b1019a6SJerry Jelinek     }
50926f3cdf0SGordon Ross 
5107b1019a6SJerry Jelinek     return_ACPI_STATUS (Status);
5117b1019a6SJerry Jelinek 
5127b1019a6SJerry Jelinek 
5137b1019a6SJerry Jelinek UnlockAndExit:
5147b1019a6SJerry Jelinek     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
51526f3cdf0SGordon Ross     return_ACPI_STATUS (Status);
51626f3cdf0SGordon Ross }
51726f3cdf0SGordon Ross 
ACPI_EXPORT_SYMBOL(AcpiRemoveNotifyHandler)5187b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler)
51926f3cdf0SGordon Ross 
52026f3cdf0SGordon Ross 
5217c478bd9Sstevel@tonic-gate /*******************************************************************************
5227c478bd9Sstevel@tonic-gate  *
5237b1019a6SJerry Jelinek  * FUNCTION:    AcpiInstallExceptionHandler
5247c478bd9Sstevel@tonic-gate  *
5257b1019a6SJerry Jelinek  * PARAMETERS:  Handler         - Pointer to the handler function for the
5267c478bd9Sstevel@tonic-gate  *                                event
5277c478bd9Sstevel@tonic-gate  *
5287c478bd9Sstevel@tonic-gate  * RETURN:      Status
5297c478bd9Sstevel@tonic-gate  *
5307b1019a6SJerry Jelinek  * DESCRIPTION: Saves the pointer to the handler function
5317c478bd9Sstevel@tonic-gate  *
5327c478bd9Sstevel@tonic-gate  ******************************************************************************/
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate ACPI_STATUS
5357b1019a6SJerry Jelinek AcpiInstallExceptionHandler (
5367b1019a6SJerry Jelinek     ACPI_EXCEPTION_HANDLER  Handler)
5377c478bd9Sstevel@tonic-gate {
5387c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 
5417b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler);
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
5457c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
5467c478bd9Sstevel@tonic-gate     {
5477c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
5487c478bd9Sstevel@tonic-gate     }
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate     /* Don't allow two handlers. */
5517c478bd9Sstevel@tonic-gate 
5527b1019a6SJerry Jelinek     if (AcpiGbl_ExceptionHandler)
5537c478bd9Sstevel@tonic-gate     {
5547c478bd9Sstevel@tonic-gate         Status = AE_ALREADY_EXISTS;
5557c478bd9Sstevel@tonic-gate         goto Cleanup;
5567c478bd9Sstevel@tonic-gate     }
5577c478bd9Sstevel@tonic-gate 
5587b1019a6SJerry Jelinek     /* Install the handler */
5597c478bd9Sstevel@tonic-gate 
5607b1019a6SJerry Jelinek     AcpiGbl_ExceptionHandler = Handler;
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate Cleanup:
5637c478bd9Sstevel@tonic-gate     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
5647c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiInstallExceptionHandler)5677b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler)
56827f7c583Smyers 
5697c478bd9Sstevel@tonic-gate 
5707b1019a6SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE)
5717c478bd9Sstevel@tonic-gate /*******************************************************************************
5727c478bd9Sstevel@tonic-gate  *
5737b1019a6SJerry Jelinek  * FUNCTION:    AcpiInstallSciHandler
5747c478bd9Sstevel@tonic-gate  *
5757b1019a6SJerry Jelinek  * PARAMETERS:  Address             - Address of the handler
5767b1019a6SJerry Jelinek  *              Context             - Value passed to the handler on each SCI
5777c478bd9Sstevel@tonic-gate  *
5787c478bd9Sstevel@tonic-gate  * RETURN:      Status
5797c478bd9Sstevel@tonic-gate  *
5807b1019a6SJerry Jelinek  * DESCRIPTION: Install a handler for a System Control Interrupt.
5817c478bd9Sstevel@tonic-gate  *
5827c478bd9Sstevel@tonic-gate  ******************************************************************************/
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate ACPI_STATUS
5857b1019a6SJerry Jelinek AcpiInstallSciHandler (
5867b1019a6SJerry Jelinek     ACPI_SCI_HANDLER        Address,
5877b1019a6SJerry Jelinek     void                    *Context)
5887c478bd9Sstevel@tonic-gate {
5897b1019a6SJerry Jelinek     ACPI_SCI_HANDLER_INFO   *NewSciHandler;
5907b1019a6SJerry Jelinek     ACPI_SCI_HANDLER_INFO   *SciHandler;
5917b1019a6SJerry Jelinek     ACPI_CPU_FLAGS          Flags;
5927b1019a6SJerry Jelinek     ACPI_STATUS             Status;
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 
5957b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiInstallSciHandler);
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 
5987b1019a6SJerry Jelinek     if (!Address)
5997c478bd9Sstevel@tonic-gate     {
6007c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_BAD_PARAMETER);
6017c478bd9Sstevel@tonic-gate     }
6027c478bd9Sstevel@tonic-gate 
6037b1019a6SJerry Jelinek     /* Allocate and init a handler object */
6047b1019a6SJerry Jelinek 
6057b1019a6SJerry Jelinek     NewSciHandler = ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO));
6067b1019a6SJerry Jelinek     if (!NewSciHandler)
6077b1019a6SJerry Jelinek     {
6087b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_NO_MEMORY);
6097b1019a6SJerry Jelinek     }
6107b1019a6SJerry Jelinek 
6117b1019a6SJerry Jelinek     NewSciHandler->Address = Address;
6127b1019a6SJerry Jelinek     NewSciHandler->Context = Context;
6137b1019a6SJerry Jelinek 
6147c478bd9Sstevel@tonic-gate     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
6157c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
6167c478bd9Sstevel@tonic-gate     {
6177b1019a6SJerry Jelinek         goto Exit;
6187c478bd9Sstevel@tonic-gate     }
6197c478bd9Sstevel@tonic-gate 
6207b1019a6SJerry Jelinek     /* Lock list during installation */
6217c478bd9Sstevel@tonic-gate 
6227b1019a6SJerry Jelinek     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
6237b1019a6SJerry Jelinek     SciHandler = AcpiGbl_SciHandlerList;
6247c478bd9Sstevel@tonic-gate 
6257b1019a6SJerry Jelinek     /* Ensure handler does not already exist */
6267c478bd9Sstevel@tonic-gate 
6277b1019a6SJerry Jelinek     while (SciHandler)
6287c478bd9Sstevel@tonic-gate     {
6297b1019a6SJerry Jelinek         if (Address == SciHandler->Address)
6307b1019a6SJerry Jelinek         {
6317b1019a6SJerry Jelinek             Status = AE_ALREADY_EXISTS;
6327b1019a6SJerry Jelinek             goto UnlockAndExit;
6337b1019a6SJerry Jelinek         }
6347b1019a6SJerry Jelinek 
6357b1019a6SJerry Jelinek         SciHandler = SciHandler->Next;
6367c478bd9Sstevel@tonic-gate     }
6377c478bd9Sstevel@tonic-gate 
6387b1019a6SJerry Jelinek     /* Install the new handler into the global list (at head) */
6397b1019a6SJerry Jelinek 
6407b1019a6SJerry Jelinek     NewSciHandler->Next = AcpiGbl_SciHandlerList;
6417b1019a6SJerry Jelinek     AcpiGbl_SciHandlerList = NewSciHandler;
6427b1019a6SJerry Jelinek 
6437b1019a6SJerry Jelinek 
6447b1019a6SJerry Jelinek UnlockAndExit:
6457b1019a6SJerry Jelinek 
6467b1019a6SJerry Jelinek     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
6477c478bd9Sstevel@tonic-gate     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
6487b1019a6SJerry Jelinek 
6497b1019a6SJerry Jelinek Exit:
6507b1019a6SJerry Jelinek     if (ACPI_FAILURE (Status))
6517b1019a6SJerry Jelinek     {
6527b1019a6SJerry Jelinek         ACPI_FREE (NewSciHandler);
6537b1019a6SJerry Jelinek     }
6547c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
6557c478bd9Sstevel@tonic-gate }
6567c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiInstallSciHandler)6577b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiInstallSciHandler)
65827f7c583Smyers 
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate /*******************************************************************************
6617c478bd9Sstevel@tonic-gate  *
6627b1019a6SJerry Jelinek  * FUNCTION:    AcpiRemoveSciHandler
6637c478bd9Sstevel@tonic-gate  *
6647b1019a6SJerry Jelinek  * PARAMETERS:  Address             - Address of the handler
6657c478bd9Sstevel@tonic-gate  *
6667c478bd9Sstevel@tonic-gate  * RETURN:      Status
6677c478bd9Sstevel@tonic-gate  *
6687b1019a6SJerry Jelinek  * DESCRIPTION: Remove a handler for a System Control Interrupt.
6697c478bd9Sstevel@tonic-gate  *
6707c478bd9Sstevel@tonic-gate  ******************************************************************************/
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate ACPI_STATUS
6737b1019a6SJerry Jelinek AcpiRemoveSciHandler (
6747b1019a6SJerry Jelinek     ACPI_SCI_HANDLER        Address)
6757c478bd9Sstevel@tonic-gate {
6767b1019a6SJerry Jelinek     ACPI_SCI_HANDLER_INFO   *PrevSciHandler;
6777b1019a6SJerry Jelinek     ACPI_SCI_HANDLER_INFO   *NextSciHandler;
6787b1019a6SJerry Jelinek     ACPI_CPU_FLAGS          Flags;
6797c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 
6827b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler);
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 
6857b1019a6SJerry Jelinek     if (!Address)
6867c478bd9Sstevel@tonic-gate     {
6877c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_BAD_PARAMETER);
6887c478bd9Sstevel@tonic-gate     }
6897c478bd9Sstevel@tonic-gate 
6907b1019a6SJerry Jelinek     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
6917c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
6927c478bd9Sstevel@tonic-gate     {
6937c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
6947c478bd9Sstevel@tonic-gate     }
6957c478bd9Sstevel@tonic-gate 
6967b1019a6SJerry Jelinek     /* Remove the SCI handler with lock */
6977c478bd9Sstevel@tonic-gate 
6987b1019a6SJerry Jelinek     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
6997c478bd9Sstevel@tonic-gate 
7007b1019a6SJerry Jelinek     PrevSciHandler = NULL;
7017b1019a6SJerry Jelinek     NextSciHandler = AcpiGbl_SciHandlerList;
7027b1019a6SJerry Jelinek     while (NextSciHandler)
7037c478bd9Sstevel@tonic-gate     {
7047b1019a6SJerry Jelinek         if (NextSciHandler->Address == Address)
7057c478bd9Sstevel@tonic-gate         {
7067b1019a6SJerry Jelinek             /* Unlink and free the SCI handler info block */
7077c478bd9Sstevel@tonic-gate 
7087b1019a6SJerry Jelinek             if (PrevSciHandler)
7097b1019a6SJerry Jelinek             {
7107b1019a6SJerry Jelinek                 PrevSciHandler->Next = NextSciHandler->Next;
7117b1019a6SJerry Jelinek             }
7127b1019a6SJerry Jelinek             else
7137b1019a6SJerry Jelinek             {
7147b1019a6SJerry Jelinek                 AcpiGbl_SciHandlerList = NextSciHandler->Next;
7157b1019a6SJerry Jelinek             }
7167c478bd9Sstevel@tonic-gate 
7177b1019a6SJerry Jelinek             AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
7187b1019a6SJerry Jelinek             ACPI_FREE (NextSciHandler);
7197c478bd9Sstevel@tonic-gate             goto UnlockAndExit;
7207c478bd9Sstevel@tonic-gate         }
7217c478bd9Sstevel@tonic-gate 
7227b1019a6SJerry Jelinek         PrevSciHandler = NextSciHandler;
7237b1019a6SJerry Jelinek         NextSciHandler = NextSciHandler->Next;
7247b1019a6SJerry Jelinek     }
7257c478bd9Sstevel@tonic-gate 
7267b1019a6SJerry Jelinek     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
7277b1019a6SJerry Jelinek     Status = AE_NOT_EXIST;
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate 
7307b1019a6SJerry Jelinek UnlockAndExit:
7317b1019a6SJerry Jelinek     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
7327b1019a6SJerry Jelinek     return_ACPI_STATUS (Status);
7337b1019a6SJerry Jelinek }
7347c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiRemoveSciHandler)7357b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiRemoveSciHandler)
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 
7387b1019a6SJerry Jelinek /*******************************************************************************
7397b1019a6SJerry Jelinek  *
7407b1019a6SJerry Jelinek  * FUNCTION:    AcpiInstallGlobalEventHandler
7417b1019a6SJerry Jelinek  *
7427b1019a6SJerry Jelinek  * PARAMETERS:  Handler         - Pointer to the global event handler function
7437b1019a6SJerry Jelinek  *              Context         - Value passed to the handler on each event
7447b1019a6SJerry Jelinek  *
7457b1019a6SJerry Jelinek  * RETURN:      Status
7467b1019a6SJerry Jelinek  *
7477b1019a6SJerry Jelinek  * DESCRIPTION: Saves the pointer to the handler function. The global handler
7487b1019a6SJerry Jelinek  *              is invoked upon each incoming GPE and Fixed Event. It is
7497b1019a6SJerry Jelinek  *              invoked at interrupt level at the time of the event dispatch.
7507b1019a6SJerry Jelinek  *              Can be used to update event counters, etc.
7517b1019a6SJerry Jelinek  *
7527b1019a6SJerry Jelinek  ******************************************************************************/
7537c478bd9Sstevel@tonic-gate 
7547b1019a6SJerry Jelinek ACPI_STATUS
7557b1019a6SJerry Jelinek AcpiInstallGlobalEventHandler (
7567b1019a6SJerry Jelinek     ACPI_GBL_EVENT_HANDLER  Handler,
7577b1019a6SJerry Jelinek     void                    *Context)
7587b1019a6SJerry Jelinek {
7597b1019a6SJerry Jelinek     ACPI_STATUS             Status;
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 
7627b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler);
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 
7657b1019a6SJerry Jelinek     /* Parameter validation */
7667c478bd9Sstevel@tonic-gate 
7677b1019a6SJerry Jelinek     if (!Handler)
7687b1019a6SJerry Jelinek     {
7697b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_BAD_PARAMETER);
7707b1019a6SJerry Jelinek     }
7717c478bd9Sstevel@tonic-gate 
7727b1019a6SJerry Jelinek     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
7737b1019a6SJerry Jelinek     if (ACPI_FAILURE (Status))
7747b1019a6SJerry Jelinek     {
7757b1019a6SJerry Jelinek         return_ACPI_STATUS (Status);
7767b1019a6SJerry Jelinek     }
7777c478bd9Sstevel@tonic-gate 
7787b1019a6SJerry Jelinek     /* Don't allow two handlers. */
7797b1019a6SJerry Jelinek 
7807b1019a6SJerry Jelinek     if (AcpiGbl_GlobalEventHandler)
7817b1019a6SJerry Jelinek     {
7827b1019a6SJerry Jelinek         Status = AE_ALREADY_EXISTS;
7837b1019a6SJerry Jelinek         goto Cleanup;
7847c478bd9Sstevel@tonic-gate     }
7857c478bd9Sstevel@tonic-gate 
7867b1019a6SJerry Jelinek     AcpiGbl_GlobalEventHandler = Handler;
7877b1019a6SJerry Jelinek     AcpiGbl_GlobalEventHandlerContext = Context;
7887c478bd9Sstevel@tonic-gate 
7897b1019a6SJerry Jelinek 
7907b1019a6SJerry Jelinek Cleanup:
7917b1019a6SJerry Jelinek     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
7927c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
7937c478bd9Sstevel@tonic-gate }
7947c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiInstallGlobalEventHandler)7957b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler)
79627f7c583Smyers 
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate /*******************************************************************************
7997c478bd9Sstevel@tonic-gate  *
8007b1019a6SJerry Jelinek  * FUNCTION:    AcpiInstallFixedEventHandler
8017c478bd9Sstevel@tonic-gate  *
8027b1019a6SJerry Jelinek  * PARAMETERS:  Event           - Event type to enable.
8037b1019a6SJerry Jelinek  *              Handler         - Pointer to the handler function for the
8047b1019a6SJerry Jelinek  *                                event
8057b1019a6SJerry Jelinek  *              Context         - Value passed to the handler on each GPE
8067c478bd9Sstevel@tonic-gate  *
8077c478bd9Sstevel@tonic-gate  * RETURN:      Status
8087c478bd9Sstevel@tonic-gate  *
8097b1019a6SJerry Jelinek  * DESCRIPTION: Saves the pointer to the handler function and then enables the
8107b1019a6SJerry Jelinek  *              event.
8117c478bd9Sstevel@tonic-gate  *
8127c478bd9Sstevel@tonic-gate  ******************************************************************************/
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate ACPI_STATUS
8157b1019a6SJerry Jelinek AcpiInstallFixedEventHandler (
8167b1019a6SJerry Jelinek     UINT32                  Event,
8177b1019a6SJerry Jelinek     ACPI_EVENT_HANDLER      Handler,
8187b1019a6SJerry Jelinek     void                    *Context)
8197c478bd9Sstevel@tonic-gate {
8207c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate 
8237b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler);
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate     /* Parameter validation */
8277c478bd9Sstevel@tonic-gate 
8287b1019a6SJerry Jelinek     if (Event > ACPI_EVENT_MAX)
8297c478bd9Sstevel@tonic-gate     {
8307c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_BAD_PARAMETER);
8317c478bd9Sstevel@tonic-gate     }
8327c478bd9Sstevel@tonic-gate 
8337b1019a6SJerry Jelinek     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
8347c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
8357c478bd9Sstevel@tonic-gate     {
8367c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
8377c478bd9Sstevel@tonic-gate     }
8387c478bd9Sstevel@tonic-gate 
8397b1019a6SJerry Jelinek     /* Do not allow multiple handlers */
8407c478bd9Sstevel@tonic-gate 
8417b1019a6SJerry Jelinek     if (AcpiGbl_FixedEventHandlers[Event].Handler)
8427c478bd9Sstevel@tonic-gate     {
8437b1019a6SJerry Jelinek         Status = AE_ALREADY_EXISTS;
8447b1019a6SJerry Jelinek         goto Cleanup;
8457c478bd9Sstevel@tonic-gate     }
8467c478bd9Sstevel@tonic-gate 
8477b1019a6SJerry Jelinek     /* Install the handler before enabling the event */
8487c478bd9Sstevel@tonic-gate 
8497b1019a6SJerry Jelinek     AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
8507b1019a6SJerry Jelinek     AcpiGbl_FixedEventHandlers[Event].Context = Context;
8517c478bd9Sstevel@tonic-gate 
8527b1019a6SJerry Jelinek     Status = AcpiEnableEvent (Event, 0);
8537b1019a6SJerry Jelinek     if (ACPI_FAILURE (Status))
8547b1019a6SJerry Jelinek     {
8557b1019a6SJerry Jelinek         ACPI_WARNING ((AE_INFO,
8567b1019a6SJerry Jelinek             "Could not enable fixed event - %s (%u)",
8577b1019a6SJerry Jelinek             AcpiUtGetEventName (Event), Event));
8587c478bd9Sstevel@tonic-gate 
8597b1019a6SJerry Jelinek         /* Remove the handler */
8607c478bd9Sstevel@tonic-gate 
8617b1019a6SJerry Jelinek         AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
8627b1019a6SJerry Jelinek         AcpiGbl_FixedEventHandlers[Event].Context = NULL;
8637c478bd9Sstevel@tonic-gate     }
8647c478bd9Sstevel@tonic-gate     else
8657c478bd9Sstevel@tonic-gate     {
8667b1019a6SJerry Jelinek         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
8677b1019a6SJerry Jelinek             "Enabled fixed event %s (%X), Handler=%p\n",
8687b1019a6SJerry Jelinek             AcpiUtGetEventName (Event), Event, Handler));
8697b1019a6SJerry Jelinek     }
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate 
8727b1019a6SJerry Jelinek Cleanup:
8737b1019a6SJerry Jelinek     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
8747b1019a6SJerry Jelinek     return_ACPI_STATUS (Status);
8757b1019a6SJerry Jelinek }
8767c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiInstallFixedEventHandler)8777b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler)
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate 
8807b1019a6SJerry Jelinek /*******************************************************************************
8817b1019a6SJerry Jelinek  *
8827b1019a6SJerry Jelinek  * FUNCTION:    AcpiRemoveFixedEventHandler
8837b1019a6SJerry Jelinek  *
8847b1019a6SJerry Jelinek  * PARAMETERS:  Event           - Event type to disable.
8857b1019a6SJerry Jelinek  *              Handler         - Address of the handler
8867b1019a6SJerry Jelinek  *
8877b1019a6SJerry Jelinek  * RETURN:      Status
8887b1019a6SJerry Jelinek  *
8897b1019a6SJerry Jelinek  * DESCRIPTION: Disables the event and unregisters the event handler.
8907b1019a6SJerry Jelinek  *
8917b1019a6SJerry Jelinek  ******************************************************************************/
89227f7c583Smyers 
8937b1019a6SJerry Jelinek ACPI_STATUS
8947b1019a6SJerry Jelinek AcpiRemoveFixedEventHandler (
8957b1019a6SJerry Jelinek     UINT32                  Event,
8967b1019a6SJerry Jelinek     ACPI_EVENT_HANDLER      Handler)
8977b1019a6SJerry Jelinek {
8987b1019a6SJerry Jelinek     ACPI_STATUS             Status = AE_OK;
8997c478bd9Sstevel@tonic-gate 
9007c478bd9Sstevel@tonic-gate 
9017b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler);
9027c478bd9Sstevel@tonic-gate 
90327f7c583Smyers 
9047b1019a6SJerry Jelinek     /* Parameter validation */
9057c478bd9Sstevel@tonic-gate 
9067b1019a6SJerry Jelinek     if (Event > ACPI_EVENT_MAX)
9077b1019a6SJerry Jelinek     {
9087b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_BAD_PARAMETER);
9097b1019a6SJerry Jelinek     }
9107c478bd9Sstevel@tonic-gate 
9117b1019a6SJerry Jelinek     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
9127b1019a6SJerry Jelinek     if (ACPI_FAILURE (Status))
9137b1019a6SJerry Jelinek     {
9147b1019a6SJerry Jelinek         return_ACPI_STATUS (Status);
9157c478bd9Sstevel@tonic-gate     }
9167c478bd9Sstevel@tonic-gate 
9177b1019a6SJerry Jelinek     /* Disable the event before removing the handler */
9187c478bd9Sstevel@tonic-gate 
9197b1019a6SJerry Jelinek     Status = AcpiDisableEvent (Event, 0);
9207b1019a6SJerry Jelinek 
9217b1019a6SJerry Jelinek     /* Always Remove the handler */
9227b1019a6SJerry Jelinek 
9237b1019a6SJerry Jelinek     AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
9247b1019a6SJerry Jelinek     AcpiGbl_FixedEventHandlers[Event].Context = NULL;
9257b1019a6SJerry Jelinek 
9267b1019a6SJerry Jelinek     if (ACPI_FAILURE (Status))
9277b1019a6SJerry Jelinek     {
9287b1019a6SJerry Jelinek         ACPI_WARNING ((AE_INFO,
9297b1019a6SJerry Jelinek             "Could not disable fixed event - %s (%u)",
9307b1019a6SJerry Jelinek             AcpiUtGetEventName (Event), Event));
9317b1019a6SJerry Jelinek     }
9327b1019a6SJerry Jelinek     else
9337b1019a6SJerry Jelinek     {
9347b1019a6SJerry Jelinek         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
9357b1019a6SJerry Jelinek             "Disabled fixed event - %s (%X)\n",
9367b1019a6SJerry Jelinek             AcpiUtGetEventName (Event), Event));
9377b1019a6SJerry Jelinek     }
9387b1019a6SJerry Jelinek 
9397b1019a6SJerry Jelinek     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
9407c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
9417c478bd9Sstevel@tonic-gate }
9427c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiRemoveFixedEventHandler)9437b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler)
94427f7c583Smyers 
9457c478bd9Sstevel@tonic-gate 
9467c478bd9Sstevel@tonic-gate /*******************************************************************************
9477c478bd9Sstevel@tonic-gate  *
9487b1019a6SJerry Jelinek  * FUNCTION:    AcpiEvInstallGpeHandler
9497c478bd9Sstevel@tonic-gate  *
9507c478bd9Sstevel@tonic-gate  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
9517c478bd9Sstevel@tonic-gate  *                                defined GPEs)
9527c478bd9Sstevel@tonic-gate  *              GpeNumber       - The GPE number within the GPE block
9537c478bd9Sstevel@tonic-gate  *              Type            - Whether this GPE should be treated as an
9547c478bd9Sstevel@tonic-gate  *                                edge- or level-triggered interrupt.
9557b1019a6SJerry Jelinek  *              IsRawHandler    - Whether this GPE should be handled using
9567b1019a6SJerry Jelinek  *                                the special GPE handler mode.
9577c478bd9Sstevel@tonic-gate  *              Address         - Address of the handler
9587c478bd9Sstevel@tonic-gate  *              Context         - Value passed to the handler on each GPE
9597c478bd9Sstevel@tonic-gate  *
9607c478bd9Sstevel@tonic-gate  * RETURN:      Status
9617c478bd9Sstevel@tonic-gate  *
9627b1019a6SJerry Jelinek  * DESCRIPTION: Internal function to install a handler for a General Purpose
9637b1019a6SJerry Jelinek  *              Event.
9647c478bd9Sstevel@tonic-gate  *
9657c478bd9Sstevel@tonic-gate  ******************************************************************************/
9667c478bd9Sstevel@tonic-gate 
9677b1019a6SJerry Jelinek static ACPI_STATUS
9687b1019a6SJerry Jelinek AcpiEvInstallGpeHandler (
9697c478bd9Sstevel@tonic-gate     ACPI_HANDLE             GpeDevice,
9707c478bd9Sstevel@tonic-gate     UINT32                  GpeNumber,
9717c478bd9Sstevel@tonic-gate     UINT32                  Type,
9727b1019a6SJerry Jelinek     BOOLEAN                 IsRawHandler,
97326f3cdf0SGordon Ross     ACPI_GPE_HANDLER        Address,
9747c478bd9Sstevel@tonic-gate     void                    *Context)
9757c478bd9Sstevel@tonic-gate {
9767c478bd9Sstevel@tonic-gate     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
97726f3cdf0SGordon Ross     ACPI_GPE_HANDLER_INFO   *Handler;
9787c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
97930082d0cSmyers     ACPI_CPU_FLAGS          Flags;
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 
9827b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (EvInstallGpeHandler);
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 
9857c478bd9Sstevel@tonic-gate     /* Parameter validation */
9867c478bd9Sstevel@tonic-gate 
98726f3cdf0SGordon Ross     if ((!Address) || (Type & ~ACPI_GPE_XRUPT_TYPE_MASK))
9887c478bd9Sstevel@tonic-gate     {
9897c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_BAD_PARAMETER);
9907c478bd9Sstevel@tonic-gate     }
9917c478bd9Sstevel@tonic-gate 
9927c478bd9Sstevel@tonic-gate     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
9937c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
9947c478bd9Sstevel@tonic-gate     {
9957c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
9967c478bd9Sstevel@tonic-gate     }
9977c478bd9Sstevel@tonic-gate 
99826f3cdf0SGordon Ross     /* Allocate and init handler object (before lock) */
99926f3cdf0SGordon Ross 
100026f3cdf0SGordon Ross     Handler = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO));
100126f3cdf0SGordon Ross     if (!Handler)
100226f3cdf0SGordon Ross     {
100326f3cdf0SGordon Ross         Status = AE_NO_MEMORY;
100426f3cdf0SGordon Ross         goto UnlockAndExit;
100526f3cdf0SGordon Ross     }
100626f3cdf0SGordon Ross 
100726f3cdf0SGordon Ross     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
100826f3cdf0SGordon Ross 
10097c478bd9Sstevel@tonic-gate     /* Ensure that we have a valid GPE number */
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
10127c478bd9Sstevel@tonic-gate     if (!GpeEventInfo)
10137c478bd9Sstevel@tonic-gate     {
10147c478bd9Sstevel@tonic-gate         Status = AE_BAD_PARAMETER;
101526f3cdf0SGordon Ross         goto FreeAndExit;
10167c478bd9Sstevel@tonic-gate     }
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate     /* Make sure that there isn't a handler there already */
10197c478bd9Sstevel@tonic-gate 
10207b1019a6SJerry Jelinek     if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
10217b1019a6SJerry Jelinek             ACPI_GPE_DISPATCH_HANDLER) ||
10227b1019a6SJerry Jelinek         (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
10237b1019a6SJerry Jelinek             ACPI_GPE_DISPATCH_RAW_HANDLER))
10247c478bd9Sstevel@tonic-gate     {
10257c478bd9Sstevel@tonic-gate         Status = AE_ALREADY_EXISTS;
102626f3cdf0SGordon Ross         goto FreeAndExit;
10277c478bd9Sstevel@tonic-gate     }
10287c478bd9Sstevel@tonic-gate 
102926f3cdf0SGordon Ross     Handler->Address = Address;
103026f3cdf0SGordon Ross     Handler->Context = Context;
103126f3cdf0SGordon Ross     Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;
103226f3cdf0SGordon Ross     Handler->OriginalFlags = (UINT8) (GpeEventInfo->Flags &
103326f3cdf0SGordon Ross         (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK));
10347c478bd9Sstevel@tonic-gate 
103526f3cdf0SGordon Ross     /*
103626f3cdf0SGordon Ross      * If the GPE is associated with a method, it may have been enabled
103726f3cdf0SGordon Ross      * automatically during initialization, in which case it has to be
103826f3cdf0SGordon Ross      * disabled now to avoid spurious execution of the handler.
103926f3cdf0SGordon Ross      */
10407b1019a6SJerry Jelinek     if (((ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
10417b1019a6SJerry Jelinek             ACPI_GPE_DISPATCH_METHOD) ||
10427b1019a6SJerry Jelinek          (ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
10437b1019a6SJerry Jelinek             ACPI_GPE_DISPATCH_NOTIFY)) &&
104426f3cdf0SGordon Ross         GpeEventInfo->RuntimeCount)
10457c478bd9Sstevel@tonic-gate     {
104626f3cdf0SGordon Ross         Handler->OriginallyEnabled = TRUE;
104726f3cdf0SGordon Ross         (void) AcpiEvRemoveGpeReference (GpeEventInfo);
10487c478bd9Sstevel@tonic-gate 
104926f3cdf0SGordon Ross         /* Sanity check of original type against new type */
10507c478bd9Sstevel@tonic-gate 
105126f3cdf0SGordon Ross         if (Type != (UINT32) (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
105226f3cdf0SGordon Ross         {
105326f3cdf0SGordon Ross             ACPI_WARNING ((AE_INFO, "GPE type mismatch (level/edge)"));
105426f3cdf0SGordon Ross         }
10557c478bd9Sstevel@tonic-gate     }
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate     /* Install the handler */
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate     GpeEventInfo->Dispatch.Handler = Handler;
10607c478bd9Sstevel@tonic-gate 
106126f3cdf0SGordon Ross     /* Setup up dispatch flags to indicate handler (vs. method/notify) */
10627c478bd9Sstevel@tonic-gate 
1063aa2aa9a6SDana Myers     GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
10647b1019a6SJerry Jelinek     GpeEventInfo->Flags |= (UINT8) (Type | (IsRawHandler ?
10657b1019a6SJerry Jelinek         ACPI_GPE_DISPATCH_RAW_HANDLER : ACPI_GPE_DISPATCH_HANDLER));
10667c478bd9Sstevel@tonic-gate 
1067450d6964Smyers     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate UnlockAndExit:
10717c478bd9Sstevel@tonic-gate     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
10727c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
107326f3cdf0SGordon Ross 
107426f3cdf0SGordon Ross FreeAndExit:
107526f3cdf0SGordon Ross     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
107626f3cdf0SGordon Ross     ACPI_FREE (Handler);
107726f3cdf0SGordon Ross     goto UnlockAndExit;
10787c478bd9Sstevel@tonic-gate }
10797c478bd9Sstevel@tonic-gate 
10807b1019a6SJerry Jelinek 
10817b1019a6SJerry Jelinek /*******************************************************************************
10827b1019a6SJerry Jelinek  *
10837b1019a6SJerry Jelinek  * FUNCTION:    AcpiInstallGpeHandler
10847b1019a6SJerry Jelinek  *
10857b1019a6SJerry Jelinek  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
10867b1019a6SJerry Jelinek  *                                defined GPEs)
10877b1019a6SJerry Jelinek  *              GpeNumber       - The GPE number within the GPE block
10887b1019a6SJerry Jelinek  *              Type            - Whether this GPE should be treated as an
10897b1019a6SJerry Jelinek  *                                edge- or level-triggered interrupt.
10907b1019a6SJerry Jelinek  *              Address         - Address of the handler
10917b1019a6SJerry Jelinek  *              Context         - Value passed to the handler on each GPE
10927b1019a6SJerry Jelinek  *
10937b1019a6SJerry Jelinek  * RETURN:      Status
10947b1019a6SJerry Jelinek  *
10957b1019a6SJerry Jelinek  * DESCRIPTION: Install a handler for a General Purpose Event.
10967b1019a6SJerry Jelinek  *
10977b1019a6SJerry Jelinek  ******************************************************************************/
10987b1019a6SJerry Jelinek 
10997b1019a6SJerry Jelinek ACPI_STATUS
AcpiInstallGpeHandler(ACPI_HANDLE GpeDevice,UINT32 GpeNumber,UINT32 Type,ACPI_GPE_HANDLER Address,void * Context)11007b1019a6SJerry Jelinek AcpiInstallGpeHandler (
11017b1019a6SJerry Jelinek     ACPI_HANDLE             GpeDevice,
11027b1019a6SJerry Jelinek     UINT32                  GpeNumber,
11037b1019a6SJerry Jelinek     UINT32                  Type,
11047b1019a6SJerry Jelinek     ACPI_GPE_HANDLER        Address,
11057b1019a6SJerry Jelinek     void                    *Context)
11067b1019a6SJerry Jelinek {
11077b1019a6SJerry Jelinek     ACPI_STATUS             Status;
11087b1019a6SJerry Jelinek 
11097b1019a6SJerry Jelinek 
11107b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);
11117b1019a6SJerry Jelinek 
11127b1019a6SJerry Jelinek 
11137b1019a6SJerry Jelinek     Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type,
11147b1019a6SJerry Jelinek         FALSE, Address, Context);
11157b1019a6SJerry Jelinek 
11167b1019a6SJerry Jelinek     return_ACPI_STATUS (Status);
11177b1019a6SJerry Jelinek }
11187b1019a6SJerry Jelinek 
ACPI_EXPORT_SYMBOL(AcpiInstallGpeHandler)111927f7c583Smyers ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)
112027f7c583Smyers 
11217c478bd9Sstevel@tonic-gate 
11227b1019a6SJerry Jelinek /*******************************************************************************
11237b1019a6SJerry Jelinek  *
11247b1019a6SJerry Jelinek  * FUNCTION:    AcpiInstallGpeRawHandler
11257b1019a6SJerry Jelinek  *
11267b1019a6SJerry Jelinek  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
11277b1019a6SJerry Jelinek  *                                defined GPEs)
11287b1019a6SJerry Jelinek  *              GpeNumber       - The GPE number within the GPE block
11297b1019a6SJerry Jelinek  *              Type            - Whether this GPE should be treated as an
11307b1019a6SJerry Jelinek  *                                edge- or level-triggered interrupt.
11317b1019a6SJerry Jelinek  *              Address         - Address of the handler
11327b1019a6SJerry Jelinek  *              Context         - Value passed to the handler on each GPE
11337b1019a6SJerry Jelinek  *
11347b1019a6SJerry Jelinek  * RETURN:      Status
11357b1019a6SJerry Jelinek  *
11367b1019a6SJerry Jelinek  * DESCRIPTION: Install a handler for a General Purpose Event.
11377b1019a6SJerry Jelinek  *
11387b1019a6SJerry Jelinek  ******************************************************************************/
11397b1019a6SJerry Jelinek 
11407b1019a6SJerry Jelinek ACPI_STATUS
11417b1019a6SJerry Jelinek AcpiInstallGpeRawHandler (
11427b1019a6SJerry Jelinek     ACPI_HANDLE             GpeDevice,
11437b1019a6SJerry Jelinek     UINT32                  GpeNumber,
11447b1019a6SJerry Jelinek     UINT32                  Type,
11457b1019a6SJerry Jelinek     ACPI_GPE_HANDLER        Address,
11467b1019a6SJerry Jelinek     void                    *Context)
11477b1019a6SJerry Jelinek {
11487b1019a6SJerry Jelinek     ACPI_STATUS             Status;
11497b1019a6SJerry Jelinek 
11507b1019a6SJerry Jelinek 
11517b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiInstallGpeRawHandler);
11527b1019a6SJerry Jelinek 
11537b1019a6SJerry Jelinek 
11547b1019a6SJerry Jelinek     Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type,
11557b1019a6SJerry Jelinek         TRUE, Address, Context);
11567b1019a6SJerry Jelinek 
11577b1019a6SJerry Jelinek     return_ACPI_STATUS (Status);
11587b1019a6SJerry Jelinek }
11597b1019a6SJerry Jelinek 
ACPI_EXPORT_SYMBOL(AcpiInstallGpeRawHandler)11607b1019a6SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiInstallGpeRawHandler)
11617b1019a6SJerry Jelinek 
11627b1019a6SJerry Jelinek 
11637c478bd9Sstevel@tonic-gate /*******************************************************************************
11647c478bd9Sstevel@tonic-gate  *
11657c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiRemoveGpeHandler
11667c478bd9Sstevel@tonic-gate  *
11677c478bd9Sstevel@tonic-gate  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
11687c478bd9Sstevel@tonic-gate  *                                defined GPEs)
11697c478bd9Sstevel@tonic-gate  *              GpeNumber       - The event to remove a handler
11707c478bd9Sstevel@tonic-gate  *              Address         - Address of the handler
11717c478bd9Sstevel@tonic-gate  *
11727c478bd9Sstevel@tonic-gate  * RETURN:      Status
11737c478bd9Sstevel@tonic-gate  *
11747c478bd9Sstevel@tonic-gate  * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
11757c478bd9Sstevel@tonic-gate  *
11767c478bd9Sstevel@tonic-gate  ******************************************************************************/
11777c478bd9Sstevel@tonic-gate 
11787c478bd9Sstevel@tonic-gate ACPI_STATUS
11797c478bd9Sstevel@tonic-gate AcpiRemoveGpeHandler (
11807c478bd9Sstevel@tonic-gate     ACPI_HANDLE             GpeDevice,
11817c478bd9Sstevel@tonic-gate     UINT32                  GpeNumber,
118226f3cdf0SGordon Ross     ACPI_GPE_HANDLER        Address)
11837c478bd9Sstevel@tonic-gate {
11847c478bd9Sstevel@tonic-gate     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
118526f3cdf0SGordon Ross     ACPI_GPE_HANDLER_INFO   *Handler;
11867c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
118730082d0cSmyers     ACPI_CPU_FLAGS          Flags;
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate 
119027f7c583Smyers     ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler);
11917c478bd9Sstevel@tonic-gate 
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate     /* Parameter validation */
11947c478bd9Sstevel@tonic-gate 
11957c478bd9Sstevel@tonic-gate     if (!Address)
11967c478bd9Sstevel@tonic-gate     {
11977c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (AE_BAD_PARAMETER);
11987c478bd9Sstevel@tonic-gate     }
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
12017c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
12027c478bd9Sstevel@tonic-gate     {
12037c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
12047c478bd9Sstevel@tonic-gate     }
12057c478bd9Sstevel@tonic-gate 
120626f3cdf0SGordon Ross     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
120726f3cdf0SGordon Ross 
12087c478bd9Sstevel@tonic-gate     /* Ensure that we have a valid GPE number */
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
12117c478bd9Sstevel@tonic-gate     if (!GpeEventInfo)
12127c478bd9Sstevel@tonic-gate     {
12137c478bd9Sstevel@tonic-gate         Status = AE_BAD_PARAMETER;
12147c478bd9Sstevel@tonic-gate         goto UnlockAndExit;
12157c478bd9Sstevel@tonic-gate     }
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate     /* Make sure that a handler is indeed installed */
12187c478bd9Sstevel@tonic-gate 
12197b1019a6SJerry Jelinek     if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
12207b1019a6SJerry Jelinek             ACPI_GPE_DISPATCH_HANDLER) &&
12217b1019a6SJerry Jelinek         (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
12227b1019a6SJerry Jelinek             ACPI_GPE_DISPATCH_RAW_HANDLER))
12237c478bd9Sstevel@tonic-gate     {
12247c478bd9Sstevel@tonic-gate         Status = AE_NOT_EXIST;
12257c478bd9Sstevel@tonic-gate         goto UnlockAndExit;
12267c478bd9Sstevel@tonic-gate     }
12277c478bd9Sstevel@tonic-gate 
12287c478bd9Sstevel@tonic-gate     /* Make sure that the installed handler is the same */
12297c478bd9Sstevel@tonic-gate 
12307c478bd9Sstevel@tonic-gate     if (GpeEventInfo->Dispatch.Handler->Address != Address)
12317c478bd9Sstevel@tonic-gate     {
12327c478bd9Sstevel@tonic-gate         Status = AE_BAD_PARAMETER;
12337c478bd9Sstevel@tonic-gate         goto UnlockAndExit;
12347c478bd9Sstevel@tonic-gate     }
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate     /* Remove the handler */
12377c478bd9Sstevel@tonic-gate 
12387c478bd9Sstevel@tonic-gate     Handler = GpeEventInfo->Dispatch.Handler;
12397b1019a6SJerry Jelinek     GpeEventInfo->Dispatch.Handler = NULL;
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate     /* Restore Method node (if any), set dispatch flags */
12427c478bd9Sstevel@tonic-gate 
12437c478bd9Sstevel@tonic-gate     GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;
124426f3cdf0SGordon Ross     GpeEventInfo->Flags &=
124526f3cdf0SGordon Ross         ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
124626f3cdf0SGordon Ross     GpeEventInfo->Flags |= Handler->OriginalFlags;
124726f3cdf0SGordon Ross 
124826f3cdf0SGordon Ross     /*
124926f3cdf0SGordon Ross      * If the GPE was previously associated with a method and it was
125026f3cdf0SGordon Ross      * enabled, it should be enabled at this point to restore the
125126f3cdf0SGordon Ross      * post-initialization configuration.
125226f3cdf0SGordon Ross      */
12537b1019a6SJerry Jelinek     if (((ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
12547b1019a6SJerry Jelinek             ACPI_GPE_DISPATCH_METHOD) ||
12557b1019a6SJerry Jelinek          (ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
12567b1019a6SJerry Jelinek             ACPI_GPE_DISPATCH_NOTIFY)) &&
125726f3cdf0SGordon Ross         Handler->OriginallyEnabled)
12587c478bd9Sstevel@tonic-gate     {
125926f3cdf0SGordon Ross         (void) AcpiEvAddGpeReference (GpeEventInfo);
1260*35786f68SRobert Mustacchi         if (ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
1261*35786f68SRobert Mustacchi         {
1262*35786f68SRobert Mustacchi             /* Poll edge triggered GPEs to handle existing events */
1263*35786f68SRobert Mustacchi 
1264*35786f68SRobert Mustacchi             AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
1265*35786f68SRobert Mustacchi             (void) AcpiEvDetectGpe (
1266*35786f68SRobert Mustacchi                 GpeDevice, GpeEventInfo, GpeNumber);
1267*35786f68SRobert Mustacchi             Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
1268*35786f68SRobert Mustacchi         }
12697c478bd9Sstevel@tonic-gate     }
12707c478bd9Sstevel@tonic-gate 
12717b1019a6SJerry Jelinek     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
12727b1019a6SJerry Jelinek     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
12737b1019a6SJerry Jelinek 
12747b1019a6SJerry Jelinek     /* Make sure all deferred GPE tasks are completed */
12757b1019a6SJerry Jelinek 
12767b1019a6SJerry Jelinek     AcpiOsWaitEventsComplete ();
12777b1019a6SJerry Jelinek 
12787c478bd9Sstevel@tonic-gate     /* Now we can free the handler object */
12797c478bd9Sstevel@tonic-gate 
128027f7c583Smyers     ACPI_FREE (Handler);
12817b1019a6SJerry Jelinek     return_ACPI_STATUS (Status);
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate UnlockAndExit:
128426f3cdf0SGordon Ross     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
12857c478bd9Sstevel@tonic-gate     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
12867c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
12877c478bd9Sstevel@tonic-gate }
12887c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiRemoveGpeHandler)128927f7c583Smyers ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler)
129027f7c583Smyers 
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate /*******************************************************************************
12937c478bd9Sstevel@tonic-gate  *
12947c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiAcquireGlobalLock
12957c478bd9Sstevel@tonic-gate  *
12967c478bd9Sstevel@tonic-gate  * PARAMETERS:  Timeout         - How long the caller is willing to wait
12977c478bd9Sstevel@tonic-gate  *              Handle          - Where the handle to the lock is returned
12987c478bd9Sstevel@tonic-gate  *                                (if acquired)
12997c478bd9Sstevel@tonic-gate  *
13007c478bd9Sstevel@tonic-gate  * RETURN:      Status
13017c478bd9Sstevel@tonic-gate  *
13027c478bd9Sstevel@tonic-gate  * DESCRIPTION: Acquire the ACPI Global Lock
13037c478bd9Sstevel@tonic-gate  *
1304db2bae30SDana Myers  * Note: Allows callers with the same thread ID to acquire the global lock
1305db2bae30SDana Myers  * multiple times. In other words, externally, the behavior of the global lock
1306db2bae30SDana Myers  * is identical to an AML mutex. On the first acquire, a new handle is
1307db2bae30SDana Myers  * returned. On any subsequent calls to acquire by the same thread, the same
1308db2bae30SDana Myers  * handle is returned.
1309db2bae30SDana Myers  *
13107c478bd9Sstevel@tonic-gate  ******************************************************************************/
13117c478bd9Sstevel@tonic-gate 
13127c478bd9Sstevel@tonic-gate ACPI_STATUS
13137c478bd9Sstevel@tonic-gate AcpiAcquireGlobalLock (
13147c478bd9Sstevel@tonic-gate     UINT16                  Timeout,
13157c478bd9Sstevel@tonic-gate     UINT32                  *Handle)
13167c478bd9Sstevel@tonic-gate {
13177c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
13187c478bd9Sstevel@tonic-gate 
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate     if (!Handle)
13217c478bd9Sstevel@tonic-gate     {
13227c478bd9Sstevel@tonic-gate         return (AE_BAD_PARAMETER);
13237c478bd9Sstevel@tonic-gate     }
13247c478bd9Sstevel@tonic-gate 
1325db2bae30SDana Myers     /* Must lock interpreter to prevent race conditions */
13267c478bd9Sstevel@tonic-gate 
1327db2bae30SDana Myers     AcpiExEnterInterpreter ();
1328db2bae30SDana Myers 
1329db2bae30SDana Myers     Status = AcpiExAcquireMutexObject (Timeout,
13307b1019a6SJerry Jelinek         AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
13317c478bd9Sstevel@tonic-gate 
13327c478bd9Sstevel@tonic-gate     if (ACPI_SUCCESS (Status))
13337c478bd9Sstevel@tonic-gate     {
1334db2bae30SDana Myers         /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
1335db2bae30SDana Myers 
13367c478bd9Sstevel@tonic-gate         *Handle = AcpiGbl_GlobalLockHandle;
13377c478bd9Sstevel@tonic-gate     }
13387c478bd9Sstevel@tonic-gate 
1339db2bae30SDana Myers     AcpiExExitInterpreter ();
13407c478bd9Sstevel@tonic-gate     return (Status);
13417c478bd9Sstevel@tonic-gate }
13427c478bd9Sstevel@tonic-gate 
ACPI_EXPORT_SYMBOL(AcpiAcquireGlobalLock)134327f7c583Smyers ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock)
134427f7c583Smyers 
13457c478bd9Sstevel@tonic-gate 
13467c478bd9Sstevel@tonic-gate /*******************************************************************************
13477c478bd9Sstevel@tonic-gate  *
13487c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiReleaseGlobalLock
13497c478bd9Sstevel@tonic-gate  *
13507c478bd9Sstevel@tonic-gate  * PARAMETERS:  Handle      - Returned from AcpiAcquireGlobalLock
13517c478bd9Sstevel@tonic-gate  *
13527c478bd9Sstevel@tonic-gate  * RETURN:      Status
13537c478bd9Sstevel@tonic-gate  *
13547c478bd9Sstevel@tonic-gate  * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
13557c478bd9Sstevel@tonic-gate  *
13567c478bd9Sstevel@tonic-gate  ******************************************************************************/
13577c478bd9Sstevel@tonic-gate 
13587c478bd9Sstevel@tonic-gate ACPI_STATUS
13597c478bd9Sstevel@tonic-gate AcpiReleaseGlobalLock (
13607c478bd9Sstevel@tonic-gate     UINT32                  Handle)
13617c478bd9Sstevel@tonic-gate {
13627c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate 
1365db2bae30SDana Myers     if (!Handle || (Handle != AcpiGbl_GlobalLockHandle))
13667c478bd9Sstevel@tonic-gate     {
13677c478bd9Sstevel@tonic-gate         return (AE_NOT_ACQUIRED);
13687c478bd9Sstevel@tonic-gate     }
13697c478bd9Sstevel@tonic-gate 
1370db2bae30SDana Myers     Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
13717c478bd9Sstevel@tonic-gate     return (Status);
13727c478bd9Sstevel@tonic-gate }
13737c478bd9Sstevel@tonic-gate 
137427f7c583Smyers ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock)
13757c478bd9Sstevel@tonic-gate 
13767b1019a6SJerry Jelinek #endif /* !ACPI_REDUCED_HARDWARE */
1377