xref: /minix3/minix/drivers/power/acpi/events/evgpeinit.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: evgpeinit - System GPE initialization and update
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  *****************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acevents.h"
47433d6423SLionel Sambuc #include "acnamesp.h"
48433d6423SLionel Sambuc 
49433d6423SLionel Sambuc #define _COMPONENT          ACPI_EVENTS
50433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("evgpeinit")
51433d6423SLionel Sambuc 
52*29492bb7SDavid van Moolenbroek #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53*29492bb7SDavid van Moolenbroek 
54*29492bb7SDavid van Moolenbroek /*
55*29492bb7SDavid van Moolenbroek  * Note: History of _PRW support in ACPICA
56*29492bb7SDavid van Moolenbroek  *
57*29492bb7SDavid van Moolenbroek  * Originally (2000 - 2010), the GPE initialization code performed a walk of
58*29492bb7SDavid van Moolenbroek  * the entire namespace to execute the _PRW methods and detect all GPEs
59*29492bb7SDavid van Moolenbroek  * capable of waking the system.
60*29492bb7SDavid van Moolenbroek  *
61*29492bb7SDavid van Moolenbroek  * As of 10/2010, the _PRW method execution has been removed since it is
62*29492bb7SDavid van Moolenbroek  * actually unnecessary. The host OS must in fact execute all _PRW methods
63*29492bb7SDavid van Moolenbroek  * in order to identify the device/power-resource dependencies. We now put
64*29492bb7SDavid van Moolenbroek  * the onus on the host OS to identify the wake GPEs as part of this process
65*29492bb7SDavid van Moolenbroek  * and to inform ACPICA of these GPEs via the AcpiSetupGpeForWake interface. This
66*29492bb7SDavid van Moolenbroek  * not only reduces the complexity of the ACPICA initialization code, but in
67*29492bb7SDavid van Moolenbroek  * some cases (on systems with very large namespaces) it should reduce the
68*29492bb7SDavid van Moolenbroek  * kernel boot time as well.
69*29492bb7SDavid van Moolenbroek  */
70433d6423SLionel Sambuc 
71433d6423SLionel Sambuc /*******************************************************************************
72433d6423SLionel Sambuc  *
73433d6423SLionel Sambuc  * FUNCTION:    AcpiEvGpeInitialize
74433d6423SLionel Sambuc  *
75433d6423SLionel Sambuc  * PARAMETERS:  None
76433d6423SLionel Sambuc  *
77433d6423SLionel Sambuc  * RETURN:      Status
78433d6423SLionel Sambuc  *
79433d6423SLionel Sambuc  * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
80433d6423SLionel Sambuc  *
81433d6423SLionel Sambuc  ******************************************************************************/
82433d6423SLionel Sambuc 
83433d6423SLionel Sambuc ACPI_STATUS
AcpiEvGpeInitialize(void)84433d6423SLionel Sambuc AcpiEvGpeInitialize (
85433d6423SLionel Sambuc     void)
86433d6423SLionel Sambuc {
87433d6423SLionel Sambuc     UINT32                  RegisterCount0 = 0;
88433d6423SLionel Sambuc     UINT32                  RegisterCount1 = 0;
89433d6423SLionel Sambuc     UINT32                  GpeNumberMax = 0;
90433d6423SLionel Sambuc     ACPI_STATUS             Status;
91433d6423SLionel Sambuc 
92433d6423SLionel Sambuc 
93433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (EvGpeInitialize);
94433d6423SLionel Sambuc 
95433d6423SLionel Sambuc 
96*29492bb7SDavid van Moolenbroek     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
97*29492bb7SDavid van Moolenbroek         "Initializing General Purpose Events (GPEs):\n"));
98*29492bb7SDavid van Moolenbroek 
99433d6423SLionel Sambuc     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
100433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
101433d6423SLionel Sambuc     {
102433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
103433d6423SLionel Sambuc     }
104433d6423SLionel Sambuc 
105433d6423SLionel Sambuc     /*
106433d6423SLionel Sambuc      * Initialize the GPE Block(s) defined in the FADT
107433d6423SLionel Sambuc      *
108433d6423SLionel Sambuc      * Why the GPE register block lengths are divided by 2:  From the ACPI
109433d6423SLionel Sambuc      * Spec, section "General-Purpose Event Registers", we have:
110433d6423SLionel Sambuc      *
111433d6423SLionel Sambuc      * "Each register block contains two registers of equal length
112433d6423SLionel Sambuc      *  GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
113433d6423SLionel Sambuc      *  GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
114433d6423SLionel Sambuc      *  The length of the GPE1_STS and GPE1_EN registers is equal to
115433d6423SLionel Sambuc      *  half the GPE1_LEN. If a generic register block is not supported
116433d6423SLionel Sambuc      *  then its respective block pointer and block length values in the
117433d6423SLionel Sambuc      *  FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
118433d6423SLionel Sambuc      *  to be the same size."
119433d6423SLionel Sambuc      */
120433d6423SLionel Sambuc 
121433d6423SLionel Sambuc     /*
122433d6423SLionel Sambuc      * Determine the maximum GPE number for this machine.
123433d6423SLionel Sambuc      *
124433d6423SLionel Sambuc      * Note: both GPE0 and GPE1 are optional, and either can exist without
125433d6423SLionel Sambuc      * the other.
126433d6423SLionel Sambuc      *
127433d6423SLionel Sambuc      * If EITHER the register length OR the block address are zero, then that
128433d6423SLionel Sambuc      * particular block is not supported.
129433d6423SLionel Sambuc      */
130433d6423SLionel Sambuc     if (AcpiGbl_FADT.Gpe0BlockLength &&
131433d6423SLionel Sambuc         AcpiGbl_FADT.XGpe0Block.Address)
132433d6423SLionel Sambuc     {
133433d6423SLionel Sambuc         /* GPE block 0 exists (has both length and address > 0) */
134433d6423SLionel Sambuc 
135433d6423SLionel Sambuc         RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
136433d6423SLionel Sambuc         GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
137433d6423SLionel Sambuc 
138433d6423SLionel Sambuc         /* Install GPE Block 0 */
139433d6423SLionel Sambuc 
140433d6423SLionel Sambuc         Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
141*29492bb7SDavid van Moolenbroek                     AcpiGbl_FADT.XGpe0Block.Address,
142*29492bb7SDavid van Moolenbroek                     AcpiGbl_FADT.XGpe0Block.SpaceId,
143*29492bb7SDavid van Moolenbroek                     RegisterCount0, 0,
144433d6423SLionel Sambuc                     AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
145433d6423SLionel Sambuc 
146433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
147433d6423SLionel Sambuc         {
148433d6423SLionel Sambuc             ACPI_EXCEPTION ((AE_INFO, Status,
149433d6423SLionel Sambuc                 "Could not create GPE Block 0"));
150433d6423SLionel Sambuc         }
151433d6423SLionel Sambuc     }
152433d6423SLionel Sambuc 
153433d6423SLionel Sambuc     if (AcpiGbl_FADT.Gpe1BlockLength &&
154433d6423SLionel Sambuc         AcpiGbl_FADT.XGpe1Block.Address)
155433d6423SLionel Sambuc     {
156433d6423SLionel Sambuc         /* GPE block 1 exists (has both length and address > 0) */
157433d6423SLionel Sambuc 
158433d6423SLionel Sambuc         RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
159433d6423SLionel Sambuc 
160433d6423SLionel Sambuc         /* Check for GPE0/GPE1 overlap (if both banks exist) */
161433d6423SLionel Sambuc 
162433d6423SLionel Sambuc         if ((RegisterCount0) &&
163433d6423SLionel Sambuc             (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
164433d6423SLionel Sambuc         {
165433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO,
166433d6423SLionel Sambuc                 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
167433d6423SLionel Sambuc                 "(GPE %u to %u) - Ignoring GPE1",
168433d6423SLionel Sambuc                 GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
169433d6423SLionel Sambuc                 AcpiGbl_FADT.Gpe1Base +
170433d6423SLionel Sambuc                 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
171433d6423SLionel Sambuc 
172433d6423SLionel Sambuc             /* Ignore GPE1 block by setting the register count to zero */
173433d6423SLionel Sambuc 
174433d6423SLionel Sambuc             RegisterCount1 = 0;
175433d6423SLionel Sambuc         }
176433d6423SLionel Sambuc         else
177433d6423SLionel Sambuc         {
178433d6423SLionel Sambuc             /* Install GPE Block 1 */
179433d6423SLionel Sambuc 
180433d6423SLionel Sambuc             Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
181*29492bb7SDavid van Moolenbroek                         AcpiGbl_FADT.XGpe1Block.Address,
182*29492bb7SDavid van Moolenbroek                         AcpiGbl_FADT.XGpe1Block.SpaceId,
183*29492bb7SDavid van Moolenbroek                         RegisterCount1,
184433d6423SLionel Sambuc                         AcpiGbl_FADT.Gpe1Base,
185433d6423SLionel Sambuc                         AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
186433d6423SLionel Sambuc 
187433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
188433d6423SLionel Sambuc             {
189433d6423SLionel Sambuc                 ACPI_EXCEPTION ((AE_INFO, Status,
190433d6423SLionel Sambuc                     "Could not create GPE Block 1"));
191433d6423SLionel Sambuc             }
192433d6423SLionel Sambuc 
193433d6423SLionel Sambuc             /*
194433d6423SLionel Sambuc              * GPE0 and GPE1 do not have to be contiguous in the GPE number
195433d6423SLionel Sambuc              * space. However, GPE0 always starts at GPE number zero.
196433d6423SLionel Sambuc              */
197433d6423SLionel Sambuc             GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
198433d6423SLionel Sambuc                             ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
199433d6423SLionel Sambuc         }
200433d6423SLionel Sambuc     }
201433d6423SLionel Sambuc 
202433d6423SLionel Sambuc     /* Exit if there are no GPE registers */
203433d6423SLionel Sambuc 
204433d6423SLionel Sambuc     if ((RegisterCount0 + RegisterCount1) == 0)
205433d6423SLionel Sambuc     {
206433d6423SLionel Sambuc         /* GPEs are not required by ACPI, this is OK */
207433d6423SLionel Sambuc 
208433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
209433d6423SLionel Sambuc             "There are no GPE blocks defined in the FADT\n"));
210433d6423SLionel Sambuc         Status = AE_OK;
211433d6423SLionel Sambuc         goto Cleanup;
212433d6423SLionel Sambuc     }
213433d6423SLionel Sambuc 
214433d6423SLionel Sambuc 
215433d6423SLionel Sambuc Cleanup:
216433d6423SLionel Sambuc     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
217433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
218433d6423SLionel Sambuc }
219433d6423SLionel Sambuc 
220433d6423SLionel Sambuc 
221433d6423SLionel Sambuc /*******************************************************************************
222433d6423SLionel Sambuc  *
223433d6423SLionel Sambuc  * FUNCTION:    AcpiEvUpdateGpes
224433d6423SLionel Sambuc  *
225433d6423SLionel Sambuc  * PARAMETERS:  TableOwnerId        - ID of the newly-loaded ACPI table
226433d6423SLionel Sambuc  *
227433d6423SLionel Sambuc  * RETURN:      None
228433d6423SLionel Sambuc  *
229433d6423SLionel Sambuc  * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
230433d6423SLionel Sambuc  *              result of a Load() or LoadTable() operation. If new GPE
231*29492bb7SDavid van Moolenbroek  *              methods have been installed, register the new methods.
232433d6423SLionel Sambuc  *
233433d6423SLionel Sambuc  ******************************************************************************/
234433d6423SLionel Sambuc 
235433d6423SLionel Sambuc void
AcpiEvUpdateGpes(ACPI_OWNER_ID TableOwnerId)236433d6423SLionel Sambuc AcpiEvUpdateGpes (
237433d6423SLionel Sambuc     ACPI_OWNER_ID           TableOwnerId)
238433d6423SLionel Sambuc {
239433d6423SLionel Sambuc     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
240433d6423SLionel Sambuc     ACPI_GPE_BLOCK_INFO     *GpeBlock;
241433d6423SLionel Sambuc     ACPI_GPE_WALK_INFO      WalkInfo;
242433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
243433d6423SLionel Sambuc 
244433d6423SLionel Sambuc 
245433d6423SLionel Sambuc     /*
246*29492bb7SDavid van Moolenbroek      * Find any _Lxx/_Exx GPE methods that have just been loaded.
247433d6423SLionel Sambuc      *
248*29492bb7SDavid van Moolenbroek      * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
249*29492bb7SDavid van Moolenbroek      * enabled.
250433d6423SLionel Sambuc      *
251433d6423SLionel Sambuc      * Examine the namespace underneath each GpeDevice within the
252433d6423SLionel Sambuc      * GpeBlock lists.
253433d6423SLionel Sambuc      */
254433d6423SLionel Sambuc     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
255433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
256433d6423SLionel Sambuc     {
257433d6423SLionel Sambuc         return;
258433d6423SLionel Sambuc     }
259433d6423SLionel Sambuc 
260433d6423SLionel Sambuc     WalkInfo.Count = 0;
261*29492bb7SDavid van Moolenbroek     WalkInfo.OwnerId = TableOwnerId;
262*29492bb7SDavid van Moolenbroek     WalkInfo.ExecuteByOwnerId = TRUE;
263433d6423SLionel Sambuc 
264433d6423SLionel Sambuc     /* Walk the interrupt level descriptor list */
265433d6423SLionel Sambuc 
266433d6423SLionel Sambuc     GpeXruptInfo = AcpiGbl_GpeXruptListHead;
267433d6423SLionel Sambuc     while (GpeXruptInfo)
268433d6423SLionel Sambuc     {
269433d6423SLionel Sambuc         /* Walk all Gpe Blocks attached to this interrupt level */
270433d6423SLionel Sambuc 
271433d6423SLionel Sambuc         GpeBlock = GpeXruptInfo->GpeBlockListHead;
272433d6423SLionel Sambuc         while (GpeBlock)
273433d6423SLionel Sambuc         {
274433d6423SLionel Sambuc             WalkInfo.GpeBlock = GpeBlock;
275433d6423SLionel Sambuc             WalkInfo.GpeDevice = GpeBlock->Node;
276433d6423SLionel Sambuc 
277433d6423SLionel Sambuc             Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD,
278433d6423SLionel Sambuc                         WalkInfo.GpeDevice, ACPI_UINT32_MAX,
279433d6423SLionel Sambuc                         ACPI_NS_WALK_NO_UNLOCK, AcpiEvMatchGpeMethod,
280433d6423SLionel Sambuc                         NULL, &WalkInfo, NULL);
281433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
282433d6423SLionel Sambuc             {
283433d6423SLionel Sambuc                 ACPI_EXCEPTION ((AE_INFO, Status,
284433d6423SLionel Sambuc                     "While decoding _Lxx/_Exx methods"));
285433d6423SLionel Sambuc             }
286433d6423SLionel Sambuc 
287433d6423SLionel Sambuc             GpeBlock = GpeBlock->Next;
288433d6423SLionel Sambuc         }
289433d6423SLionel Sambuc 
290433d6423SLionel Sambuc         GpeXruptInfo = GpeXruptInfo->Next;
291433d6423SLionel Sambuc     }
292433d6423SLionel Sambuc 
293*29492bb7SDavid van Moolenbroek     if (WalkInfo.Count)
294433d6423SLionel Sambuc     {
295*29492bb7SDavid van Moolenbroek         ACPI_INFO ((AE_INFO, "Enabled %u new GPEs", WalkInfo.Count));
296433d6423SLionel Sambuc     }
297433d6423SLionel Sambuc 
298433d6423SLionel Sambuc     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
299433d6423SLionel Sambuc     return;
300433d6423SLionel Sambuc }
301433d6423SLionel Sambuc 
302433d6423SLionel Sambuc 
303433d6423SLionel Sambuc /*******************************************************************************
304433d6423SLionel Sambuc  *
305433d6423SLionel Sambuc  * FUNCTION:    AcpiEvMatchGpeMethod
306433d6423SLionel Sambuc  *
307433d6423SLionel Sambuc  * PARAMETERS:  Callback from WalkNamespace
308433d6423SLionel Sambuc  *
309433d6423SLionel Sambuc  * RETURN:      Status
310433d6423SLionel Sambuc  *
311433d6423SLionel Sambuc  * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
312433d6423SLionel Sambuc  *              control method under the _GPE portion of the namespace.
313433d6423SLionel Sambuc  *              Extract the name and GPE type from the object, saving this
314433d6423SLionel Sambuc  *              information for quick lookup during GPE dispatch. Allows a
315433d6423SLionel Sambuc  *              per-OwnerId evaluation if ExecuteByOwnerId is TRUE in the
316433d6423SLionel Sambuc  *              WalkInfo parameter block.
317433d6423SLionel Sambuc  *
318433d6423SLionel Sambuc  *              The name of each GPE control method is of the form:
319433d6423SLionel Sambuc  *              "_Lxx" or "_Exx", where:
320433d6423SLionel Sambuc  *                  L      - means that the GPE is level triggered
321433d6423SLionel Sambuc  *                  E      - means that the GPE is edge triggered
322433d6423SLionel Sambuc  *                  xx     - is the GPE number [in HEX]
323433d6423SLionel Sambuc  *
324433d6423SLionel Sambuc  * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods
325433d6423SLionel Sambuc  * with that owner.
326433d6423SLionel Sambuc  *
327433d6423SLionel Sambuc  ******************************************************************************/
328433d6423SLionel Sambuc 
329433d6423SLionel Sambuc ACPI_STATUS
AcpiEvMatchGpeMethod(ACPI_HANDLE ObjHandle,UINT32 Level,void * Context,void ** ReturnValue)330433d6423SLionel Sambuc AcpiEvMatchGpeMethod (
331433d6423SLionel Sambuc     ACPI_HANDLE             ObjHandle,
332433d6423SLionel Sambuc     UINT32                  Level,
333433d6423SLionel Sambuc     void                    *Context,
334433d6423SLionel Sambuc     void                    **ReturnValue)
335433d6423SLionel Sambuc {
336433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
337433d6423SLionel Sambuc     ACPI_GPE_WALK_INFO      *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context);
338433d6423SLionel Sambuc     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
339433d6423SLionel Sambuc     UINT32                  GpeNumber;
340433d6423SLionel Sambuc     char                    Name[ACPI_NAME_SIZE + 1];
341433d6423SLionel Sambuc     UINT8                   Type;
342433d6423SLionel Sambuc 
343433d6423SLionel Sambuc 
344433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
345433d6423SLionel Sambuc 
346433d6423SLionel Sambuc 
347433d6423SLionel Sambuc     /* Check if requested OwnerId matches this OwnerId */
348433d6423SLionel Sambuc 
349433d6423SLionel Sambuc     if ((WalkInfo->ExecuteByOwnerId) &&
350433d6423SLionel Sambuc         (MethodNode->OwnerId != WalkInfo->OwnerId))
351433d6423SLionel Sambuc     {
352433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
353433d6423SLionel Sambuc     }
354433d6423SLionel Sambuc 
355433d6423SLionel Sambuc     /*
356433d6423SLionel Sambuc      * Match and decode the _Lxx and _Exx GPE method names
357433d6423SLionel Sambuc      *
358433d6423SLionel Sambuc      * 1) Extract the method name and null terminate it
359433d6423SLionel Sambuc      */
360433d6423SLionel Sambuc     ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
361433d6423SLionel Sambuc     Name[ACPI_NAME_SIZE] = 0;
362433d6423SLionel Sambuc 
363433d6423SLionel Sambuc     /* 2) Name must begin with an underscore */
364433d6423SLionel Sambuc 
365433d6423SLionel Sambuc     if (Name[0] != '_')
366433d6423SLionel Sambuc     {
367433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK); /* Ignore this method */
368433d6423SLionel Sambuc     }
369433d6423SLionel Sambuc 
370433d6423SLionel Sambuc     /*
371433d6423SLionel Sambuc      * 3) Edge/Level determination is based on the 2nd character
372433d6423SLionel Sambuc      *    of the method name
373433d6423SLionel Sambuc      */
374433d6423SLionel Sambuc     switch (Name[1])
375433d6423SLionel Sambuc     {
376433d6423SLionel Sambuc     case 'L':
377*29492bb7SDavid van Moolenbroek 
378433d6423SLionel Sambuc         Type = ACPI_GPE_LEVEL_TRIGGERED;
379433d6423SLionel Sambuc         break;
380433d6423SLionel Sambuc 
381433d6423SLionel Sambuc     case 'E':
382*29492bb7SDavid van Moolenbroek 
383433d6423SLionel Sambuc         Type = ACPI_GPE_EDGE_TRIGGERED;
384433d6423SLionel Sambuc         break;
385433d6423SLionel Sambuc 
386433d6423SLionel Sambuc     default:
387*29492bb7SDavid van Moolenbroek 
388433d6423SLionel Sambuc         /* Unknown method type, just ignore it */
389433d6423SLionel Sambuc 
390433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
391433d6423SLionel Sambuc             "Ignoring unknown GPE method type: %s "
392433d6423SLionel Sambuc             "(name not of form _Lxx or _Exx)", Name));
393433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
394433d6423SLionel Sambuc     }
395433d6423SLionel Sambuc 
396433d6423SLionel Sambuc     /* 4) The last two characters of the name are the hex GPE Number */
397433d6423SLionel Sambuc 
398433d6423SLionel Sambuc     GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
399433d6423SLionel Sambuc     if (GpeNumber == ACPI_UINT32_MAX)
400433d6423SLionel Sambuc     {
401433d6423SLionel Sambuc         /* Conversion failed; invalid method, just ignore it */
402433d6423SLionel Sambuc 
403433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
404433d6423SLionel Sambuc             "Could not extract GPE number from name: %s "
405433d6423SLionel Sambuc             "(name is not of form _Lxx or _Exx)", Name));
406433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
407433d6423SLionel Sambuc     }
408433d6423SLionel Sambuc 
409433d6423SLionel Sambuc     /* Ensure that we have a valid GPE number for this GPE block */
410433d6423SLionel Sambuc 
411433d6423SLionel Sambuc     GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, WalkInfo->GpeBlock);
412433d6423SLionel Sambuc     if (!GpeEventInfo)
413433d6423SLionel Sambuc     {
414433d6423SLionel Sambuc         /*
415433d6423SLionel Sambuc          * This GpeNumber is not valid for this GPE block, just ignore it.
416433d6423SLionel Sambuc          * However, it may be valid for a different GPE block, since GPE0
417433d6423SLionel Sambuc          * and GPE1 methods both appear under \_GPE.
418433d6423SLionel Sambuc          */
419433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
420433d6423SLionel Sambuc     }
421433d6423SLionel Sambuc 
422433d6423SLionel Sambuc     if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
423433d6423SLionel Sambuc             ACPI_GPE_DISPATCH_HANDLER)
424433d6423SLionel Sambuc     {
425433d6423SLionel Sambuc         /* If there is already a handler, ignore this GPE method */
426433d6423SLionel Sambuc 
427433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
428433d6423SLionel Sambuc     }
429433d6423SLionel Sambuc 
430433d6423SLionel Sambuc     if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
431433d6423SLionel Sambuc             ACPI_GPE_DISPATCH_METHOD)
432433d6423SLionel Sambuc     {
433433d6423SLionel Sambuc         /*
434433d6423SLionel Sambuc          * If there is already a method, ignore this method. But check
435433d6423SLionel Sambuc          * for a type mismatch (if both the _Lxx AND _Exx exist)
436433d6423SLionel Sambuc          */
437433d6423SLionel Sambuc         if (Type != (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
438433d6423SLionel Sambuc         {
439433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO,
440433d6423SLionel Sambuc                 "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
441433d6423SLionel Sambuc                 GpeNumber, GpeNumber, GpeNumber));
442433d6423SLionel Sambuc         }
443433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
444433d6423SLionel Sambuc     }
445433d6423SLionel Sambuc 
446*29492bb7SDavid van Moolenbroek     /* Disable the GPE in case it's been enabled already. */
447*29492bb7SDavid van Moolenbroek 
448*29492bb7SDavid van Moolenbroek     (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
449*29492bb7SDavid van Moolenbroek 
450433d6423SLionel Sambuc     /*
451433d6423SLionel Sambuc      * Add the GPE information from above to the GpeEventInfo block for
452433d6423SLionel Sambuc      * use during dispatch of this GPE.
453433d6423SLionel Sambuc      */
454*29492bb7SDavid van Moolenbroek     GpeEventInfo->Flags &= ~(ACPI_GPE_DISPATCH_MASK);
455433d6423SLionel Sambuc     GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD);
456433d6423SLionel Sambuc     GpeEventInfo->Dispatch.MethodNode = MethodNode;
457433d6423SLionel Sambuc 
458433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
459433d6423SLionel Sambuc         "Registered GPE method %s as GPE number 0x%.2X\n",
460433d6423SLionel Sambuc         Name, GpeNumber));
461433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
462433d6423SLionel Sambuc }
463433d6423SLionel Sambuc 
464*29492bb7SDavid van Moolenbroek #endif /* !ACPI_REDUCED_HARDWARE */
465