Deleted Added
full compact
evgpe.c (129684) evgpe.c (131440)
1/******************************************************************************
2 *
3 * Module Name: evgpe - General Purpose Event handling and dispatch
1/******************************************************************************
2 *
3 * Module Name: evgpe - General Purpose Event handling and dispatch
4 * $Revision: 40 $
4 * $Revision: 42 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#include "acpi.h"
118#include "acevents.h"
119#include "acnamesp.h"
120
121#define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evgpe")
123
124
125/*******************************************************************************
126 *
127 * FUNCTION: AcpiEvSetGpeType
128 *
129 * PARAMETERS: GpeEventInfo - GPE to set
130 * Type - New type
131 *
132 * RETURN: Status
133 *
134 * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run)
135 *
136 ******************************************************************************/
137
138ACPI_STATUS
139AcpiEvSetGpeType (
140 ACPI_GPE_EVENT_INFO *GpeEventInfo,
141 UINT8 Type)
142{
143 ACPI_STATUS Status;
144
145
146 ACPI_FUNCTION_TRACE ("EvSetGpeType");
147
148
149 /* Validate type and update register enable masks */
150
151 switch (Type)
152 {
153 case ACPI_GPE_TYPE_WAKE:
154 case ACPI_GPE_TYPE_RUNTIME:
155 case ACPI_GPE_TYPE_WAKE_RUN:
156 break;
157
158 default:
159 return_ACPI_STATUS (AE_BAD_PARAMETER);
160 }
161
162 /* Disable the GPE if currently enabled */
163
164 Status = AcpiEvDisableGpe (GpeEventInfo);
165
166 /* Type was validated above */
167
168 GpeEventInfo->Flags &= ~ACPI_GPE_TYPE_MASK; /* Clear type bits */
169 GpeEventInfo->Flags |= Type; /* Insert type */
170 return_ACPI_STATUS (Status);
171}
172
173
174/*******************************************************************************
175 *
176 * FUNCTION: AcpiEvUpdateGpeEnableMasks
177 *
178 * PARAMETERS: GpeEventInfo - GPE to update
179 *
180 * RETURN: Status
181 *
182 * DESCRIPTION: Updates GPE register enable masks based on the GPE type
183 *
184 ******************************************************************************/
185
186ACPI_STATUS
187AcpiEvUpdateGpeEnableMasks (
188 ACPI_GPE_EVENT_INFO *GpeEventInfo,
189 UINT8 Type)
190{
191 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
192 UINT8 RegisterBit;
193
194
195 ACPI_FUNCTION_TRACE ("EvUpdateGpeEnableMasks");
196
197
198 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
199 if (!GpeRegisterInfo)
200 {
201 return_ACPI_STATUS (AE_NOT_EXIST);
202 }
203 RegisterBit = GpeEventInfo->RegisterBit;
204
205 /* 1) Disable case. Simply clear all enable bits */
206
207 if (Type == ACPI_GPE_DISABLE)
208 {
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#include "acpi.h"
118#include "acevents.h"
119#include "acnamesp.h"
120
121#define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evgpe")
123
124
125/*******************************************************************************
126 *
127 * FUNCTION: AcpiEvSetGpeType
128 *
129 * PARAMETERS: GpeEventInfo - GPE to set
130 * Type - New type
131 *
132 * RETURN: Status
133 *
134 * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run)
135 *
136 ******************************************************************************/
137
138ACPI_STATUS
139AcpiEvSetGpeType (
140 ACPI_GPE_EVENT_INFO *GpeEventInfo,
141 UINT8 Type)
142{
143 ACPI_STATUS Status;
144
145
146 ACPI_FUNCTION_TRACE ("EvSetGpeType");
147
148
149 /* Validate type and update register enable masks */
150
151 switch (Type)
152 {
153 case ACPI_GPE_TYPE_WAKE:
154 case ACPI_GPE_TYPE_RUNTIME:
155 case ACPI_GPE_TYPE_WAKE_RUN:
156 break;
157
158 default:
159 return_ACPI_STATUS (AE_BAD_PARAMETER);
160 }
161
162 /* Disable the GPE if currently enabled */
163
164 Status = AcpiEvDisableGpe (GpeEventInfo);
165
166 /* Type was validated above */
167
168 GpeEventInfo->Flags &= ~ACPI_GPE_TYPE_MASK; /* Clear type bits */
169 GpeEventInfo->Flags |= Type; /* Insert type */
170 return_ACPI_STATUS (Status);
171}
172
173
174/*******************************************************************************
175 *
176 * FUNCTION: AcpiEvUpdateGpeEnableMasks
177 *
178 * PARAMETERS: GpeEventInfo - GPE to update
179 *
180 * RETURN: Status
181 *
182 * DESCRIPTION: Updates GPE register enable masks based on the GPE type
183 *
184 ******************************************************************************/
185
186ACPI_STATUS
187AcpiEvUpdateGpeEnableMasks (
188 ACPI_GPE_EVENT_INFO *GpeEventInfo,
189 UINT8 Type)
190{
191 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
192 UINT8 RegisterBit;
193
194
195 ACPI_FUNCTION_TRACE ("EvUpdateGpeEnableMasks");
196
197
198 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
199 if (!GpeRegisterInfo)
200 {
201 return_ACPI_STATUS (AE_NOT_EXIST);
202 }
203 RegisterBit = GpeEventInfo->RegisterBit;
204
205 /* 1) Disable case. Simply clear all enable bits */
206
207 if (Type == ACPI_GPE_DISABLE)
208 {
209 GpeRegisterInfo->EnableForWake &= ~RegisterBit;
210 GpeRegisterInfo->EnableForRun &= ~RegisterBit;
209 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, RegisterBit);
210 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
211 return_ACPI_STATUS (AE_OK);
212 }
213
211 return_ACPI_STATUS (AE_OK);
212 }
213
214 /* 2) Enable case. Set the appropriate enable bits */
214 /* 2) Enable case. Set/Clear the appropriate enable bits */
215
216 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
217 {
218 case ACPI_GPE_TYPE_WAKE:
215
216 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
217 {
218 case ACPI_GPE_TYPE_WAKE:
219 GpeRegisterInfo->EnableForWake |= RegisterBit;
220 GpeRegisterInfo->EnableForRun &= ~RegisterBit;
219 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, RegisterBit);
220 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
221 break;
222
223 case ACPI_GPE_TYPE_RUNTIME:
221 break;
222
223 case ACPI_GPE_TYPE_RUNTIME:
224 GpeRegisterInfo->EnableForWake &= ~RegisterBit;
225 GpeRegisterInfo->EnableForRun |= RegisterBit;
224 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, RegisterBit);
225 ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
226 break;
227
228 case ACPI_GPE_TYPE_WAKE_RUN:
226 break;
227
228 case ACPI_GPE_TYPE_WAKE_RUN:
229 GpeRegisterInfo->EnableForWake |= RegisterBit;
230 GpeRegisterInfo->EnableForRun |= RegisterBit;
229 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, RegisterBit);
230 ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
231 break;
232
233 default:
234 return_ACPI_STATUS (AE_BAD_PARAMETER);
235 }
236
237 return_ACPI_STATUS (AE_OK);
238}
239
240
241/*******************************************************************************
242 *
243 * FUNCTION: AcpiEvEnableGpe
244 *
245 * PARAMETERS: GpeEventInfo - GPE to enable
246 *
247 * RETURN: Status
248 *
249 * DESCRIPTION: Enable a GPE based on the GPE type
250 *
251 ******************************************************************************/
252
253ACPI_STATUS
254AcpiEvEnableGpe (
255 ACPI_GPE_EVENT_INFO *GpeEventInfo,
256 BOOLEAN WriteToHardware)
257{
258 ACPI_STATUS Status;
259
260
261 ACPI_FUNCTION_TRACE ("EvEnableGpe");
262
263
264 /* Make sure HW enable masks are updated */
265
266 Status = AcpiEvUpdateGpeEnableMasks (GpeEventInfo, ACPI_GPE_ENABLE);
267 if (ACPI_FAILURE (Status))
268 {
269 return_ACPI_STATUS (Status);
270 }
271
272 /* Mark wake-enabled or HW enable, or both */
273
274 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
275 {
276 case ACPI_GPE_TYPE_WAKE:
231 break;
232
233 default:
234 return_ACPI_STATUS (AE_BAD_PARAMETER);
235 }
236
237 return_ACPI_STATUS (AE_OK);
238}
239
240
241/*******************************************************************************
242 *
243 * FUNCTION: AcpiEvEnableGpe
244 *
245 * PARAMETERS: GpeEventInfo - GPE to enable
246 *
247 * RETURN: Status
248 *
249 * DESCRIPTION: Enable a GPE based on the GPE type
250 *
251 ******************************************************************************/
252
253ACPI_STATUS
254AcpiEvEnableGpe (
255 ACPI_GPE_EVENT_INFO *GpeEventInfo,
256 BOOLEAN WriteToHardware)
257{
258 ACPI_STATUS Status;
259
260
261 ACPI_FUNCTION_TRACE ("EvEnableGpe");
262
263
264 /* Make sure HW enable masks are updated */
265
266 Status = AcpiEvUpdateGpeEnableMasks (GpeEventInfo, ACPI_GPE_ENABLE);
267 if (ACPI_FAILURE (Status))
268 {
269 return_ACPI_STATUS (Status);
270 }
271
272 /* Mark wake-enabled or HW enable, or both */
273
274 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
275 {
276 case ACPI_GPE_TYPE_WAKE:
277 GpeEventInfo->Flags |= ACPI_GPE_WAKE_ENABLED;
277
278 ACPI_SET_BIT (GpeEventInfo->Flags, ACPI_GPE_WAKE_ENABLED);
278 break;
279
280 case ACPI_GPE_TYPE_WAKE_RUN:
279 break;
280
281 case ACPI_GPE_TYPE_WAKE_RUN:
281 GpeEventInfo->Flags |= ACPI_GPE_WAKE_ENABLED;
282
282
283 ACPI_SET_BIT (GpeEventInfo->Flags, ACPI_GPE_WAKE_ENABLED);
284
283 /*lint -fallthrough */
284
285 case ACPI_GPE_TYPE_RUNTIME:
286
285 /*lint -fallthrough */
286
287 case ACPI_GPE_TYPE_RUNTIME:
288
287 GpeEventInfo->Flags |= ACPI_GPE_RUN_ENABLED;
289 ACPI_SET_BIT (GpeEventInfo->Flags, ACPI_GPE_RUN_ENABLED);
288
289 if (WriteToHardware)
290 {
291 /* Clear the GPE (of stale events), then enable it */
292
293 Status = AcpiHwClearGpe (GpeEventInfo);
294 if (ACPI_FAILURE (Status))
295 {
296 return_ACPI_STATUS (Status);
297 }
298
299 /* Enable the requested runtime GPE */
300
301 Status = AcpiHwWriteGpeEnableReg (GpeEventInfo);
302 }
303 break;
304
305 default:
306 return_ACPI_STATUS (AE_BAD_PARAMETER);
307 }
308
309 return_ACPI_STATUS (AE_OK);
310}
311
312
313/*******************************************************************************
314 *
315 * FUNCTION: AcpiEvDisableGpe
316 *
317 * PARAMETERS: GpeEventInfo - GPE to disable
318 *
319 * RETURN: Status
320 *
321 * DESCRIPTION: Disable a GPE based on the GPE type
322 *
323 ******************************************************************************/
324
325ACPI_STATUS
326AcpiEvDisableGpe (
327 ACPI_GPE_EVENT_INFO *GpeEventInfo)
328{
329 ACPI_STATUS Status;
330
331
332 ACPI_FUNCTION_TRACE ("EvDisableGpe");
333
334
335 if (!(GpeEventInfo->Flags & ACPI_GPE_ENABLE_MASK))
336 {
337 return_ACPI_STATUS (AE_OK);
338 }
339
340 /* Make sure HW enable masks are updated */
341
342 Status = AcpiEvUpdateGpeEnableMasks (GpeEventInfo, ACPI_GPE_DISABLE);
343 if (ACPI_FAILURE (Status))
344 {
345 return_ACPI_STATUS (Status);
346 }
347
348 /* Mark wake-disabled or HW disable, or both */
349
350 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
351 {
352 case ACPI_GPE_TYPE_WAKE:
290
291 if (WriteToHardware)
292 {
293 /* Clear the GPE (of stale events), then enable it */
294
295 Status = AcpiHwClearGpe (GpeEventInfo);
296 if (ACPI_FAILURE (Status))
297 {
298 return_ACPI_STATUS (Status);
299 }
300
301 /* Enable the requested runtime GPE */
302
303 Status = AcpiHwWriteGpeEnableReg (GpeEventInfo);
304 }
305 break;
306
307 default:
308 return_ACPI_STATUS (AE_BAD_PARAMETER);
309 }
310
311 return_ACPI_STATUS (AE_OK);
312}
313
314
315/*******************************************************************************
316 *
317 * FUNCTION: AcpiEvDisableGpe
318 *
319 * PARAMETERS: GpeEventInfo - GPE to disable
320 *
321 * RETURN: Status
322 *
323 * DESCRIPTION: Disable a GPE based on the GPE type
324 *
325 ******************************************************************************/
326
327ACPI_STATUS
328AcpiEvDisableGpe (
329 ACPI_GPE_EVENT_INFO *GpeEventInfo)
330{
331 ACPI_STATUS Status;
332
333
334 ACPI_FUNCTION_TRACE ("EvDisableGpe");
335
336
337 if (!(GpeEventInfo->Flags & ACPI_GPE_ENABLE_MASK))
338 {
339 return_ACPI_STATUS (AE_OK);
340 }
341
342 /* Make sure HW enable masks are updated */
343
344 Status = AcpiEvUpdateGpeEnableMasks (GpeEventInfo, ACPI_GPE_DISABLE);
345 if (ACPI_FAILURE (Status))
346 {
347 return_ACPI_STATUS (Status);
348 }
349
350 /* Mark wake-disabled or HW disable, or both */
351
352 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
353 {
354 case ACPI_GPE_TYPE_WAKE:
353 GpeEventInfo->Flags &= ~ACPI_GPE_WAKE_ENABLED;
355 ACPI_CLEAR_BIT (GpeEventInfo->Flags, ACPI_GPE_WAKE_ENABLED);
354 break;
355
356 case ACPI_GPE_TYPE_WAKE_RUN:
356 break;
357
358 case ACPI_GPE_TYPE_WAKE_RUN:
357 GpeEventInfo->Flags &= ~ACPI_GPE_WAKE_ENABLED;
359 ACPI_CLEAR_BIT (GpeEventInfo->Flags, ACPI_GPE_WAKE_ENABLED);
358
359 /*lint -fallthrough */
360
361 case ACPI_GPE_TYPE_RUNTIME:
362
363 /* Disable the requested runtime GPE */
364
360
361 /*lint -fallthrough */
362
363 case ACPI_GPE_TYPE_RUNTIME:
364
365 /* Disable the requested runtime GPE */
366
365 GpeEventInfo->Flags &= ~ACPI_GPE_RUN_ENABLED;
367 ACPI_CLEAR_BIT (GpeEventInfo->Flags, ACPI_GPE_RUN_ENABLED);
366 Status = AcpiHwWriteGpeEnableReg (GpeEventInfo);
367 break;
368
369 default:
370 return_ACPI_STATUS (AE_BAD_PARAMETER);
371 }
372
373 return_ACPI_STATUS (AE_OK);
374}
375
376
377/*******************************************************************************
378 *
379 * FUNCTION: AcpiEvGetGpeEventInfo
380 *
381 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
382 * GpeNumber - Raw GPE number
383 *
384 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE
385 *
386 * DESCRIPTION: Returns the EventInfo struct associated with this GPE.
387 * Validates the GpeBlock and the GpeNumber
388 *
389 * Should be called only when the GPE lists are semaphore locked
390 * and not subject to change.
391 *
392 ******************************************************************************/
393
394ACPI_GPE_EVENT_INFO *
395AcpiEvGetGpeEventInfo (
396 ACPI_HANDLE GpeDevice,
397 UINT32 GpeNumber)
398{
399 ACPI_OPERAND_OBJECT *ObjDesc;
400 ACPI_GPE_BLOCK_INFO *GpeBlock;
401 ACPI_NATIVE_UINT i;
402
403
404 ACPI_FUNCTION_ENTRY ();
405
406
407 /* A NULL GpeBlock means use the FADT-defined GPE block(s) */
408
409 if (!GpeDevice)
410 {
411 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
412
413 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++)
414 {
415 GpeBlock = AcpiGbl_GpeFadtBlocks[i];
416 if (GpeBlock)
417 {
418 if ((GpeNumber >= GpeBlock->BlockBaseNumber) &&
419 (GpeNumber < GpeBlock->BlockBaseNumber + (GpeBlock->RegisterCount * 8)))
420 {
421 return (&GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber]);
422 }
423 }
424 }
425
426 /* The GpeNumber was not in the range of either FADT GPE block */
427
428 return (NULL);
429 }
430
431 /* A Non-NULL GpeDevice means this is a GPE Block Device */
432
433 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) GpeDevice);
434 if (!ObjDesc ||
435 !ObjDesc->Device.GpeBlock)
436 {
437 return (NULL);
438 }
439
440 GpeBlock = ObjDesc->Device.GpeBlock;
441
442 if ((GpeNumber >= GpeBlock->BlockBaseNumber) &&
443 (GpeNumber < GpeBlock->BlockBaseNumber + (GpeBlock->RegisterCount * 8)))
444 {
445 return (&GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber]);
446 }
447
448 return (NULL);
449}
450
451
452/*******************************************************************************
453 *
454 * FUNCTION: AcpiEvGpeDetect
455 *
456 * PARAMETERS: GpeXruptList - Interrupt block for this interrupt.
457 * Can have multiple GPE blocks attached.
458 *
459 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
460 *
461 * DESCRIPTION: Detect if any GP events have occurred. This function is
462 * executed at interrupt level.
463 *
464 ******************************************************************************/
465
466UINT32
467AcpiEvGpeDetect (
468 ACPI_GPE_XRUPT_INFO *GpeXruptList)
469{
470 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
471 UINT8 EnabledStatusByte;
472 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
473 UINT32 StatusReg;
474 UINT32 EnableReg;
475 ACPI_STATUS Status;
476 ACPI_GPE_BLOCK_INFO *GpeBlock;
477 ACPI_NATIVE_UINT i;
478 ACPI_NATIVE_UINT j;
479
480
481 ACPI_FUNCTION_NAME ("EvGpeDetect");
482
483 /* Check for the case where there are no GPEs */
484
485 if (!GpeXruptList)
486 {
487 return (IntStatus);
488 }
489
490 /* Examine all GPE blocks attached to this interrupt level */
491
492 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_ISR);
493 GpeBlock = GpeXruptList->GpeBlockListHead;
494 while (GpeBlock)
495 {
496 /*
497 * Read all of the 8-bit GPE status and enable registers
498 * in this GPE block, saving all of them.
499 * Find all currently active GP events.
500 */
501 for (i = 0; i < GpeBlock->RegisterCount; i++)
502 {
503 /* Get the next status/enable pair */
504
505 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
506
507 /* Read the Status Register */
508
509 Status = AcpiHwLowLevelRead (ACPI_GPE_REGISTER_WIDTH, &StatusReg,
510 &GpeRegisterInfo->StatusAddress);
511 if (ACPI_FAILURE (Status))
512 {
513 goto UnlockAndExit;
514 }
515
516 /* Read the Enable Register */
517
518 Status = AcpiHwLowLevelRead (ACPI_GPE_REGISTER_WIDTH, &EnableReg,
519 &GpeRegisterInfo->EnableAddress);
520 if (ACPI_FAILURE (Status))
521 {
522 goto UnlockAndExit;
523 }
524
525 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
526 "GPE pair: Status %8.8X%8.8X = %02X, Enable %8.8X%8.8X = %02X\n",
527 ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (
528 GpeRegisterInfo->StatusAddress.Address)),
529 StatusReg,
530 ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (
531 GpeRegisterInfo->EnableAddress.Address)),
532 EnableReg));
533
534 /* First check if there is anything active at all in this register */
535
536 EnabledStatusByte = (UINT8) (StatusReg & EnableReg);
537 if (!EnabledStatusByte)
538 {
539 /* No active GPEs in this register, move on */
540
541 continue;
542 }
543
544 /* Now look at the individual GPEs in this byte register */
545
546 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
547 {
548 /* Examine one GPE bit */
549
550 if (EnabledStatusByte & AcpiGbl_DecodeTo8bit[j])
551 {
552 /*
553 * Found an active GPE. Dispatch the event to a handler
554 * or method.
555 */
556 IntStatus |= AcpiEvGpeDispatch (
557 &GpeBlock->EventInfo[(i * ACPI_GPE_REGISTER_WIDTH) + j],
558 (UINT32) j + GpeRegisterInfo->BaseGpeNumber);
559 }
560 }
561 }
562
563 GpeBlock = GpeBlock->Next;
564 }
565
566UnlockAndExit:
567
568 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_ISR);
569 return (IntStatus);
570}
571
572
573/*******************************************************************************
574 *
575 * FUNCTION: AcpiEvAsynchExecuteGpeMethod
576 *
577 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
578 *
579 * RETURN: None
580 *
581 * DESCRIPTION: Perform the actual execution of a GPE control method. This
582 * function is called from an invocation of AcpiOsQueueForExecution
583 * (and therefore does NOT execute at interrupt level) so that
584 * the control method itself is not executed in the context of
585 * an interrupt handler.
586 *
587 ******************************************************************************/
588
589static void ACPI_SYSTEM_XFACE
590AcpiEvAsynchExecuteGpeMethod (
591 void *Context)
592{
593 ACPI_GPE_EVENT_INFO *GpeEventInfo = (void *) Context;
594 UINT32 GpeNumber = 0;
595 ACPI_STATUS Status;
596 ACPI_GPE_EVENT_INFO LocalGpeEventInfo;
597 ACPI_PARAMETER_INFO Info;
598
599
600 ACPI_FUNCTION_TRACE ("EvAsynchExecuteGpeMethod");
601
602
603 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
604 if (ACPI_FAILURE (Status))
605 {
606 return_VOID;
607 }
608
609 /* Must revalidate the GpeNumber/GpeBlock */
610
611 if (!AcpiEvValidGpeEvent (GpeEventInfo))
612 {
613 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
614 return_VOID;
615 }
616
617 /* Set the GPE flags for return to enabled state */
618
619 (void) AcpiEvEnableGpe (GpeEventInfo, FALSE);
620
621 /*
622 * Take a snapshot of the GPE info for this level - we copy the
623 * info to prevent a race condition with RemoveHandler/RemoveBlock.
624 */
625 ACPI_MEMCPY (&LocalGpeEventInfo, GpeEventInfo, sizeof (ACPI_GPE_EVENT_INFO));
626
627 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
628 if (ACPI_FAILURE (Status))
629 {
630 return_VOID;
631 }
632
633 /*
634 * Must check for control method type dispatch one more
635 * time to avoid race with EvGpeInstallHandler
636 */
637 if ((LocalGpeEventInfo.Flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD)
638 {
639 /*
640 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
641 * control method that corresponds to this GPE
642 */
643 Info.Node = LocalGpeEventInfo.Dispatch.MethodNode;
644 Info.Parameters = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT *, GpeEventInfo);
645 Info.ParameterType = ACPI_PARAM_GPE;
646
647 Status = AcpiNsEvaluateByHandle (&Info);
648 if (ACPI_FAILURE (Status))
649 {
650 ACPI_REPORT_ERROR ((
651 "%s while evaluating method [%4.4s] for GPE[%2X]\n",
652 AcpiFormatException (Status),
653 AcpiUtGetNodeName (LocalGpeEventInfo.Dispatch.MethodNode),
654 GpeNumber));
655 }
656 }
657
658 if ((LocalGpeEventInfo.Flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED)
659 {
660 /*
661 * GPE is level-triggered, we clear the GPE status bit after
662 * handling the event.
663 */
664 Status = AcpiHwClearGpe (&LocalGpeEventInfo);
665 if (ACPI_FAILURE (Status))
666 {
667 return_VOID;
668 }
669 }
670
671 /* Enable this GPE */
672
673 (void) AcpiHwWriteGpeEnableReg (&LocalGpeEventInfo);
674 return_VOID;
675}
676
677
678/*******************************************************************************
679 *
680 * FUNCTION: AcpiEvGpeDispatch
681 *
682 * PARAMETERS: GpeEventInfo - info for this GPE
683 * GpeNumber - Number relative to the parent GPE block
684 *
685 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
686 *
687 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
688 * or method (e.g. _Lxx/_Exx) handler.
689 *
690 * This function executes at interrupt level.
691 *
692 ******************************************************************************/
693
694UINT32
695AcpiEvGpeDispatch (
696 ACPI_GPE_EVENT_INFO *GpeEventInfo,
697 UINT32 GpeNumber)
698{
699 ACPI_STATUS Status;
700
701
702 ACPI_FUNCTION_TRACE ("EvGpeDispatch");
703
704
705 /*
706 * If edge-triggered, clear the GPE status bit now. Note that
707 * level-triggered events are cleared after the GPE is serviced.
708 */
709 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_EDGE_TRIGGERED)
710 {
711 Status = AcpiHwClearGpe (GpeEventInfo);
712 if (ACPI_FAILURE (Status))
713 {
714 ACPI_REPORT_ERROR (("AcpiEvGpeDispatch: Unable to clear GPE[%2X]\n",
715 GpeNumber));
716 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
717 }
718 }
719
720 /* Save current system state */
721
722 if (AcpiGbl_SystemAwakeAndRunning)
723 {
368 Status = AcpiHwWriteGpeEnableReg (GpeEventInfo);
369 break;
370
371 default:
372 return_ACPI_STATUS (AE_BAD_PARAMETER);
373 }
374
375 return_ACPI_STATUS (AE_OK);
376}
377
378
379/*******************************************************************************
380 *
381 * FUNCTION: AcpiEvGetGpeEventInfo
382 *
383 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
384 * GpeNumber - Raw GPE number
385 *
386 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE
387 *
388 * DESCRIPTION: Returns the EventInfo struct associated with this GPE.
389 * Validates the GpeBlock and the GpeNumber
390 *
391 * Should be called only when the GPE lists are semaphore locked
392 * and not subject to change.
393 *
394 ******************************************************************************/
395
396ACPI_GPE_EVENT_INFO *
397AcpiEvGetGpeEventInfo (
398 ACPI_HANDLE GpeDevice,
399 UINT32 GpeNumber)
400{
401 ACPI_OPERAND_OBJECT *ObjDesc;
402 ACPI_GPE_BLOCK_INFO *GpeBlock;
403 ACPI_NATIVE_UINT i;
404
405
406 ACPI_FUNCTION_ENTRY ();
407
408
409 /* A NULL GpeBlock means use the FADT-defined GPE block(s) */
410
411 if (!GpeDevice)
412 {
413 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
414
415 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++)
416 {
417 GpeBlock = AcpiGbl_GpeFadtBlocks[i];
418 if (GpeBlock)
419 {
420 if ((GpeNumber >= GpeBlock->BlockBaseNumber) &&
421 (GpeNumber < GpeBlock->BlockBaseNumber + (GpeBlock->RegisterCount * 8)))
422 {
423 return (&GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber]);
424 }
425 }
426 }
427
428 /* The GpeNumber was not in the range of either FADT GPE block */
429
430 return (NULL);
431 }
432
433 /* A Non-NULL GpeDevice means this is a GPE Block Device */
434
435 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) GpeDevice);
436 if (!ObjDesc ||
437 !ObjDesc->Device.GpeBlock)
438 {
439 return (NULL);
440 }
441
442 GpeBlock = ObjDesc->Device.GpeBlock;
443
444 if ((GpeNumber >= GpeBlock->BlockBaseNumber) &&
445 (GpeNumber < GpeBlock->BlockBaseNumber + (GpeBlock->RegisterCount * 8)))
446 {
447 return (&GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber]);
448 }
449
450 return (NULL);
451}
452
453
454/*******************************************************************************
455 *
456 * FUNCTION: AcpiEvGpeDetect
457 *
458 * PARAMETERS: GpeXruptList - Interrupt block for this interrupt.
459 * Can have multiple GPE blocks attached.
460 *
461 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
462 *
463 * DESCRIPTION: Detect if any GP events have occurred. This function is
464 * executed at interrupt level.
465 *
466 ******************************************************************************/
467
468UINT32
469AcpiEvGpeDetect (
470 ACPI_GPE_XRUPT_INFO *GpeXruptList)
471{
472 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
473 UINT8 EnabledStatusByte;
474 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
475 UINT32 StatusReg;
476 UINT32 EnableReg;
477 ACPI_STATUS Status;
478 ACPI_GPE_BLOCK_INFO *GpeBlock;
479 ACPI_NATIVE_UINT i;
480 ACPI_NATIVE_UINT j;
481
482
483 ACPI_FUNCTION_NAME ("EvGpeDetect");
484
485 /* Check for the case where there are no GPEs */
486
487 if (!GpeXruptList)
488 {
489 return (IntStatus);
490 }
491
492 /* Examine all GPE blocks attached to this interrupt level */
493
494 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_ISR);
495 GpeBlock = GpeXruptList->GpeBlockListHead;
496 while (GpeBlock)
497 {
498 /*
499 * Read all of the 8-bit GPE status and enable registers
500 * in this GPE block, saving all of them.
501 * Find all currently active GP events.
502 */
503 for (i = 0; i < GpeBlock->RegisterCount; i++)
504 {
505 /* Get the next status/enable pair */
506
507 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
508
509 /* Read the Status Register */
510
511 Status = AcpiHwLowLevelRead (ACPI_GPE_REGISTER_WIDTH, &StatusReg,
512 &GpeRegisterInfo->StatusAddress);
513 if (ACPI_FAILURE (Status))
514 {
515 goto UnlockAndExit;
516 }
517
518 /* Read the Enable Register */
519
520 Status = AcpiHwLowLevelRead (ACPI_GPE_REGISTER_WIDTH, &EnableReg,
521 &GpeRegisterInfo->EnableAddress);
522 if (ACPI_FAILURE (Status))
523 {
524 goto UnlockAndExit;
525 }
526
527 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
528 "GPE pair: Status %8.8X%8.8X = %02X, Enable %8.8X%8.8X = %02X\n",
529 ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (
530 GpeRegisterInfo->StatusAddress.Address)),
531 StatusReg,
532 ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (
533 GpeRegisterInfo->EnableAddress.Address)),
534 EnableReg));
535
536 /* First check if there is anything active at all in this register */
537
538 EnabledStatusByte = (UINT8) (StatusReg & EnableReg);
539 if (!EnabledStatusByte)
540 {
541 /* No active GPEs in this register, move on */
542
543 continue;
544 }
545
546 /* Now look at the individual GPEs in this byte register */
547
548 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
549 {
550 /* Examine one GPE bit */
551
552 if (EnabledStatusByte & AcpiGbl_DecodeTo8bit[j])
553 {
554 /*
555 * Found an active GPE. Dispatch the event to a handler
556 * or method.
557 */
558 IntStatus |= AcpiEvGpeDispatch (
559 &GpeBlock->EventInfo[(i * ACPI_GPE_REGISTER_WIDTH) + j],
560 (UINT32) j + GpeRegisterInfo->BaseGpeNumber);
561 }
562 }
563 }
564
565 GpeBlock = GpeBlock->Next;
566 }
567
568UnlockAndExit:
569
570 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_ISR);
571 return (IntStatus);
572}
573
574
575/*******************************************************************************
576 *
577 * FUNCTION: AcpiEvAsynchExecuteGpeMethod
578 *
579 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
580 *
581 * RETURN: None
582 *
583 * DESCRIPTION: Perform the actual execution of a GPE control method. This
584 * function is called from an invocation of AcpiOsQueueForExecution
585 * (and therefore does NOT execute at interrupt level) so that
586 * the control method itself is not executed in the context of
587 * an interrupt handler.
588 *
589 ******************************************************************************/
590
591static void ACPI_SYSTEM_XFACE
592AcpiEvAsynchExecuteGpeMethod (
593 void *Context)
594{
595 ACPI_GPE_EVENT_INFO *GpeEventInfo = (void *) Context;
596 UINT32 GpeNumber = 0;
597 ACPI_STATUS Status;
598 ACPI_GPE_EVENT_INFO LocalGpeEventInfo;
599 ACPI_PARAMETER_INFO Info;
600
601
602 ACPI_FUNCTION_TRACE ("EvAsynchExecuteGpeMethod");
603
604
605 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
606 if (ACPI_FAILURE (Status))
607 {
608 return_VOID;
609 }
610
611 /* Must revalidate the GpeNumber/GpeBlock */
612
613 if (!AcpiEvValidGpeEvent (GpeEventInfo))
614 {
615 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
616 return_VOID;
617 }
618
619 /* Set the GPE flags for return to enabled state */
620
621 (void) AcpiEvEnableGpe (GpeEventInfo, FALSE);
622
623 /*
624 * Take a snapshot of the GPE info for this level - we copy the
625 * info to prevent a race condition with RemoveHandler/RemoveBlock.
626 */
627 ACPI_MEMCPY (&LocalGpeEventInfo, GpeEventInfo, sizeof (ACPI_GPE_EVENT_INFO));
628
629 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
630 if (ACPI_FAILURE (Status))
631 {
632 return_VOID;
633 }
634
635 /*
636 * Must check for control method type dispatch one more
637 * time to avoid race with EvGpeInstallHandler
638 */
639 if ((LocalGpeEventInfo.Flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD)
640 {
641 /*
642 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
643 * control method that corresponds to this GPE
644 */
645 Info.Node = LocalGpeEventInfo.Dispatch.MethodNode;
646 Info.Parameters = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT *, GpeEventInfo);
647 Info.ParameterType = ACPI_PARAM_GPE;
648
649 Status = AcpiNsEvaluateByHandle (&Info);
650 if (ACPI_FAILURE (Status))
651 {
652 ACPI_REPORT_ERROR ((
653 "%s while evaluating method [%4.4s] for GPE[%2X]\n",
654 AcpiFormatException (Status),
655 AcpiUtGetNodeName (LocalGpeEventInfo.Dispatch.MethodNode),
656 GpeNumber));
657 }
658 }
659
660 if ((LocalGpeEventInfo.Flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED)
661 {
662 /*
663 * GPE is level-triggered, we clear the GPE status bit after
664 * handling the event.
665 */
666 Status = AcpiHwClearGpe (&LocalGpeEventInfo);
667 if (ACPI_FAILURE (Status))
668 {
669 return_VOID;
670 }
671 }
672
673 /* Enable this GPE */
674
675 (void) AcpiHwWriteGpeEnableReg (&LocalGpeEventInfo);
676 return_VOID;
677}
678
679
680/*******************************************************************************
681 *
682 * FUNCTION: AcpiEvGpeDispatch
683 *
684 * PARAMETERS: GpeEventInfo - info for this GPE
685 * GpeNumber - Number relative to the parent GPE block
686 *
687 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
688 *
689 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
690 * or method (e.g. _Lxx/_Exx) handler.
691 *
692 * This function executes at interrupt level.
693 *
694 ******************************************************************************/
695
696UINT32
697AcpiEvGpeDispatch (
698 ACPI_GPE_EVENT_INFO *GpeEventInfo,
699 UINT32 GpeNumber)
700{
701 ACPI_STATUS Status;
702
703
704 ACPI_FUNCTION_TRACE ("EvGpeDispatch");
705
706
707 /*
708 * If edge-triggered, clear the GPE status bit now. Note that
709 * level-triggered events are cleared after the GPE is serviced.
710 */
711 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_EDGE_TRIGGERED)
712 {
713 Status = AcpiHwClearGpe (GpeEventInfo);
714 if (ACPI_FAILURE (Status))
715 {
716 ACPI_REPORT_ERROR (("AcpiEvGpeDispatch: Unable to clear GPE[%2X]\n",
717 GpeNumber));
718 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
719 }
720 }
721
722 /* Save current system state */
723
724 if (AcpiGbl_SystemAwakeAndRunning)
725 {
724 GpeEventInfo->Flags |= ACPI_GPE_SYSTEM_RUNNING;
726 ACPI_SET_BIT (GpeEventInfo->Flags, ACPI_GPE_SYSTEM_RUNNING);
725 }
726 else
727 {
727 }
728 else
729 {
728 GpeEventInfo->Flags &= ~ACPI_GPE_SYSTEM_RUNNING;
730 ACPI_CLEAR_BIT (GpeEventInfo->Flags, ACPI_GPE_SYSTEM_RUNNING);
729 }
730
731 /*
732 * Dispatch the GPE to either an installed handler, or the control
733 * method associated with this GPE (_Lxx or _Exx).
734 * If a handler exists, we invoke it and do not attempt to run the method.
735 * If there is neither a handler nor a method, we disable the level to
736 * prevent further events from coming in here.
737 */
738 switch (GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK)
739 {
740 case ACPI_GPE_DISPATCH_HANDLER:
741
731 }
732
733 /*
734 * Dispatch the GPE to either an installed handler, or the control
735 * method associated with this GPE (_Lxx or _Exx).
736 * If a handler exists, we invoke it and do not attempt to run the method.
737 * If there is neither a handler nor a method, we disable the level to
738 * prevent further events from coming in here.
739 */
740 switch (GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK)
741 {
742 case ACPI_GPE_DISPATCH_HANDLER:
743
742 /* Invoke the installed handler (at interrupt level) */
743
744 GpeEventInfo->Dispatch.Handler->Address ((void *)
744 /*
745 * Invoke the installed handler (at interrupt level)
746 * Ignore return status for now. TBD: leave GPE disabled on error?
747 */
748 (void) GpeEventInfo->Dispatch.Handler->Address (
745 GpeEventInfo->Dispatch.Handler->Context);
746
747 /* It is now safe to clear level-triggered events. */
748
749 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED)
750 {
751 Status = AcpiHwClearGpe (GpeEventInfo);
752 if (ACPI_FAILURE (Status))
753 {
754 ACPI_REPORT_ERROR ((
755 "AcpiEvGpeDispatch: Unable to clear GPE[%2X]\n",
756 GpeNumber));
757 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
758 }
759 }
760 break;
761
762 case ACPI_GPE_DISPATCH_METHOD:
763
764 /*
765 * Disable GPE, so it doesn't keep firing before the method has a
766 * chance to run.
767 */
768 Status = AcpiEvDisableGpe (GpeEventInfo);
769 if (ACPI_FAILURE (Status))
770 {
771 ACPI_REPORT_ERROR ((
772 "AcpiEvGpeDispatch: Unable to disable GPE[%2X]\n",
773 GpeNumber));
774 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
775 }
776
777 /*
778 * Execute the method associated with the GPE
779 * NOTE: Level-triggered GPEs are cleared after the method completes.
780 */
781 if (ACPI_FAILURE (AcpiOsQueueForExecution (OSD_PRIORITY_GPE,
782 AcpiEvAsynchExecuteGpeMethod,
783 GpeEventInfo)))
784 {
785 ACPI_REPORT_ERROR ((
786 "AcpiEvGpeDispatch: Unable to queue handler for GPE[%2X], event is disabled\n",
787 GpeNumber));
788 }
789 break;
790
791 default:
792
793 /* No handler or method to run! */
794
795 ACPI_REPORT_ERROR ((
796 "AcpiEvGpeDispatch: No handler or method for GPE[%2X], disabling event\n",
797 GpeNumber));
798
799 /*
800 * Disable the GPE. The GPE will remain disabled until the ACPI
801 * Core Subsystem is restarted, or a handler is installed.
802 */
803 Status = AcpiEvDisableGpe (GpeEventInfo);
804 if (ACPI_FAILURE (Status))
805 {
806 ACPI_REPORT_ERROR ((
807 "AcpiEvGpeDispatch: Unable to disable GPE[%2X]\n",
808 GpeNumber));
809 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
810 }
811 break;
812 }
813
814 return_VALUE (ACPI_INTERRUPT_HANDLED);
815}
816
817
818#ifdef ACPI_GPE_NOTIFY_CHECK
819
820/*******************************************************************************
821 * NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED
822 *
823 * FUNCTION: AcpiEvCheckForWakeOnlyGpe
824 *
825 * PARAMETERS: GpeEventInfo - info for this GPE
826 *
827 * RETURN: Status
828 *
829 * DESCRIPTION: Determine if a a GPE is "wake-only".
830 *
831 * Called from Notify() code in interpreter when a "DeviceWake"
832 * Notify comes in.
833 *
834 ******************************************************************************/
835
836ACPI_STATUS
837AcpiEvCheckForWakeOnlyGpe (
838 ACPI_GPE_EVENT_INFO *GpeEventInfo)
839{
840 ACPI_STATUS Status;
841
842
843 ACPI_FUNCTION_TRACE ("EvCheckForWakeOnlyGpe");
844
845
846 if ((GpeEventInfo) && /* Only >0 for _Lxx/_Exx */
847 ((GpeEventInfo->Flags & ACPI_GPE_SYSTEM_MASK) == ACPI_GPE_SYSTEM_RUNNING)) /* System state at GPE time */
848 {
849 /* This must be a wake-only GPE, disable it */
850
851 Status = AcpiEvDisableGpe (GpeEventInfo);
852
853 /* Set GPE to wake-only. Do not change wake disabled/enabled status */
854
855 AcpiEvSetGpeType (GpeEventInfo, ACPI_GPE_TYPE_WAKE);
856
857 ACPI_REPORT_INFO (("GPE %p was updated from wake/run to wake-only\n",
858 GpeEventInfo));
859
860 /* This was a wake-only GPE */
861
862 return_ACPI_STATUS (AE_WAKE_ONLY_GPE);
863 }
864
865 return_ACPI_STATUS (AE_OK);
866}
867#endif
868
869
749 GpeEventInfo->Dispatch.Handler->Context);
750
751 /* It is now safe to clear level-triggered events. */
752
753 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED)
754 {
755 Status = AcpiHwClearGpe (GpeEventInfo);
756 if (ACPI_FAILURE (Status))
757 {
758 ACPI_REPORT_ERROR ((
759 "AcpiEvGpeDispatch: Unable to clear GPE[%2X]\n",
760 GpeNumber));
761 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
762 }
763 }
764 break;
765
766 case ACPI_GPE_DISPATCH_METHOD:
767
768 /*
769 * Disable GPE, so it doesn't keep firing before the method has a
770 * chance to run.
771 */
772 Status = AcpiEvDisableGpe (GpeEventInfo);
773 if (ACPI_FAILURE (Status))
774 {
775 ACPI_REPORT_ERROR ((
776 "AcpiEvGpeDispatch: Unable to disable GPE[%2X]\n",
777 GpeNumber));
778 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
779 }
780
781 /*
782 * Execute the method associated with the GPE
783 * NOTE: Level-triggered GPEs are cleared after the method completes.
784 */
785 if (ACPI_FAILURE (AcpiOsQueueForExecution (OSD_PRIORITY_GPE,
786 AcpiEvAsynchExecuteGpeMethod,
787 GpeEventInfo)))
788 {
789 ACPI_REPORT_ERROR ((
790 "AcpiEvGpeDispatch: Unable to queue handler for GPE[%2X], event is disabled\n",
791 GpeNumber));
792 }
793 break;
794
795 default:
796
797 /* No handler or method to run! */
798
799 ACPI_REPORT_ERROR ((
800 "AcpiEvGpeDispatch: No handler or method for GPE[%2X], disabling event\n",
801 GpeNumber));
802
803 /*
804 * Disable the GPE. The GPE will remain disabled until the ACPI
805 * Core Subsystem is restarted, or a handler is installed.
806 */
807 Status = AcpiEvDisableGpe (GpeEventInfo);
808 if (ACPI_FAILURE (Status))
809 {
810 ACPI_REPORT_ERROR ((
811 "AcpiEvGpeDispatch: Unable to disable GPE[%2X]\n",
812 GpeNumber));
813 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
814 }
815 break;
816 }
817
818 return_VALUE (ACPI_INTERRUPT_HANDLED);
819}
820
821
822#ifdef ACPI_GPE_NOTIFY_CHECK
823
824/*******************************************************************************
825 * NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED
826 *
827 * FUNCTION: AcpiEvCheckForWakeOnlyGpe
828 *
829 * PARAMETERS: GpeEventInfo - info for this GPE
830 *
831 * RETURN: Status
832 *
833 * DESCRIPTION: Determine if a a GPE is "wake-only".
834 *
835 * Called from Notify() code in interpreter when a "DeviceWake"
836 * Notify comes in.
837 *
838 ******************************************************************************/
839
840ACPI_STATUS
841AcpiEvCheckForWakeOnlyGpe (
842 ACPI_GPE_EVENT_INFO *GpeEventInfo)
843{
844 ACPI_STATUS Status;
845
846
847 ACPI_FUNCTION_TRACE ("EvCheckForWakeOnlyGpe");
848
849
850 if ((GpeEventInfo) && /* Only >0 for _Lxx/_Exx */
851 ((GpeEventInfo->Flags & ACPI_GPE_SYSTEM_MASK) == ACPI_GPE_SYSTEM_RUNNING)) /* System state at GPE time */
852 {
853 /* This must be a wake-only GPE, disable it */
854
855 Status = AcpiEvDisableGpe (GpeEventInfo);
856
857 /* Set GPE to wake-only. Do not change wake disabled/enabled status */
858
859 AcpiEvSetGpeType (GpeEventInfo, ACPI_GPE_TYPE_WAKE);
860
861 ACPI_REPORT_INFO (("GPE %p was updated from wake/run to wake-only\n",
862 GpeEventInfo));
863
864 /* This was a wake-only GPE */
865
866 return_ACPI_STATUS (AE_WAKE_ONLY_GPE);
867 }
868
869 return_ACPI_STATUS (AE_OK);
870}
871#endif
872
873