blob: 7662f1a42ff6bb19513e0f9272f90c921f64ec90 [file] [log] [blame]
Lin Ming3cfd53d2010-12-13 13:36:02 +08001/******************************************************************************
2 *
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
4 *
5 *****************************************************************************/
6
7/*
Bob Moore25f044e2013-01-25 05:38:56 +00008 * Copyright (C) 2000 - 2013, Intel Corp.
Lin Ming3cfd53d2010-12-13 13:36:02 +08009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Paul Gortmaker214f2c92011-10-26 16:22:14 -040044#include <linux/export.h>
Lin Ming3cfd53d2010-12-13 13:36:02 +080045#include <acpi/acpi.h>
46#include "accommon.h"
47#include "acevents.h"
48#include "acnamesp.h"
49
50#define _COMPONENT ACPI_EVENTS
51ACPI_MODULE_NAME("evxfgpe")
52
Bob Moore33620c52012-02-14 18:14:27 +080053#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
Lv Zheng75c80442012-12-19 05:36:49 +000054/*******************************************************************************
Lin Ming3cfd53d2010-12-13 13:36:02 +080055 *
Lin Ming3a378982010-12-13 13:36:15 +080056 * FUNCTION: acpi_update_all_gpes
Lin Ming3cfd53d2010-12-13 13:36:02 +080057 *
58 * PARAMETERS: None
59 *
Lin Mingda503372010-12-13 13:39:37 +080060 * RETURN: Status
Lin Ming3cfd53d2010-12-13 13:36:02 +080061 *
Lin Mingda503372010-12-13 13:39:37 +080062 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
63 * associated _Lxx or _Exx methods and are not pointed to by any
64 * device _PRW methods (this indicates that these GPEs are
65 * generally intended for system or device wakeup. Such GPEs
66 * have to be enabled directly when the devices whose _PRW
67 * methods point to them are set up for wakeup signaling.)
68 *
69 * NOTE: Should be called after any GPEs are added to the system. Primarily,
70 * after the system _PRW methods have been run, but also after a GPE Block
71 * Device has been added or if any new GPE methods have been added via a
72 * dynamic table load.
Lin Ming3cfd53d2010-12-13 13:36:02 +080073 *
74 ******************************************************************************/
75
Lin Ming3a378982010-12-13 13:36:15 +080076acpi_status acpi_update_all_gpes(void)
Lin Ming3cfd53d2010-12-13 13:36:02 +080077{
78 acpi_status status;
79
Lin Ming3a378982010-12-13 13:36:15 +080080 ACPI_FUNCTION_TRACE(acpi_update_all_gpes);
Lin Ming3cfd53d2010-12-13 13:36:02 +080081
82 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
83 if (ACPI_FAILURE(status)) {
84 return_ACPI_STATUS(status);
Lin Ming3a378982010-12-13 13:36:15 +080085 }
86
87 if (acpi_gbl_all_gpes_initialized) {
88 goto unlock_and_exit;
Lin Ming3cfd53d2010-12-13 13:36:02 +080089 }
90
91 status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block, NULL);
92 if (ACPI_SUCCESS(status)) {
Lin Ming3a378982010-12-13 13:36:15 +080093 acpi_gbl_all_gpes_initialized = TRUE;
Lin Ming3cfd53d2010-12-13 13:36:02 +080094 }
95
Lin Ming3a378982010-12-13 13:36:15 +080096unlock_and_exit:
Lin Ming3cfd53d2010-12-13 13:36:02 +080097 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
98
99 return_ACPI_STATUS(status);
100}
101
Lin Ming3a378982010-12-13 13:36:15 +0800102ACPI_EXPORT_SYMBOL(acpi_update_all_gpes)
103
Lin Ming3cfd53d2010-12-13 13:36:02 +0800104/*******************************************************************************
105 *
106 * FUNCTION: acpi_enable_gpe
107 *
108 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
109 * gpe_number - GPE level within the GPE block
110 *
111 * RETURN: Status
112 *
113 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
114 * hardware-enabled.
115 *
116 ******************************************************************************/
117
118acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
119{
120 acpi_status status = AE_BAD_PARAMETER;
121 struct acpi_gpe_event_info *gpe_event_info;
122 acpi_cpu_flags flags;
123
124 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
125
126 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
127
128 /* Ensure that we have a valid GPE number */
129
130 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
131 if (gpe_event_info) {
Lin Ming3a378982010-12-13 13:36:15 +0800132 status = acpi_ev_add_gpe_reference(gpe_event_info);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800133 }
134
135 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
136 return_ACPI_STATUS(status);
137}
138ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
139
140/*******************************************************************************
141 *
142 * FUNCTION: acpi_disable_gpe
143 *
144 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
145 * gpe_number - GPE level within the GPE block
146 *
147 * RETURN: Status
148 *
149 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
150 * removed, only then is the GPE disabled (for runtime GPEs), or
151 * the GPE mask bit disabled (for wake GPEs)
152 *
153 ******************************************************************************/
154
155acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
156{
157 acpi_status status = AE_BAD_PARAMETER;
158 struct acpi_gpe_event_info *gpe_event_info;
159 acpi_cpu_flags flags;
160
161 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
162
163 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
164
165 /* Ensure that we have a valid GPE number */
166
167 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
168 if (gpe_event_info) {
Lin Ming3a378982010-12-13 13:36:15 +0800169 status = acpi_ev_remove_gpe_reference(gpe_event_info) ;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800170 }
171
172 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
173 return_ACPI_STATUS(status);
174}
Lv Zheng3e8214e2012-12-19 05:37:15 +0000175
Lin Ming3cfd53d2010-12-13 13:36:02 +0800176ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
177
Lin Mingbba63a22010-12-13 13:39:17 +0800178
Lin Ming3cfd53d2010-12-13 13:36:02 +0800179/*******************************************************************************
180 *
Lin Ming3a378982010-12-13 13:36:15 +0800181 * FUNCTION: acpi_setup_gpe_for_wake
Lin Ming3cfd53d2010-12-13 13:36:02 +0800182 *
Lin Mingbba63a22010-12-13 13:39:17 +0800183 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
184 * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
185 * gpe_number - GPE level within the GPE block
Lin Ming3cfd53d2010-12-13 13:36:02 +0800186 *
187 * RETURN: Status
188 *
Lin Mingbba63a22010-12-13 13:39:17 +0800189 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
190 * interface is intended to be used as the host executes the
191 * _PRW methods (Power Resources for Wake) in the system tables.
192 * Each _PRW appears under a Device Object (The wake_device), and
193 * contains the info for the wake GPE associated with the
194 * wake_device.
Lin Ming3cfd53d2010-12-13 13:36:02 +0800195 *
196 ******************************************************************************/
Lin Mingbba63a22010-12-13 13:39:17 +0800197acpi_status
198acpi_setup_gpe_for_wake(acpi_handle wake_device,
199 acpi_handle gpe_device, u32 gpe_number)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800200{
Bob Moore5816b342012-06-29 10:04:17 +0800201 acpi_status status;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800202 struct acpi_gpe_event_info *gpe_event_info;
Lin Mingbba63a22010-12-13 13:39:17 +0800203 struct acpi_namespace_node *device_node;
Bob Moore5816b342012-06-29 10:04:17 +0800204 struct acpi_gpe_notify_info *notify;
205 struct acpi_gpe_notify_info *new_notify;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800206 acpi_cpu_flags flags;
207
Lin Ming3a378982010-12-13 13:36:15 +0800208 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800209
Lin Mingbba63a22010-12-13 13:39:17 +0800210 /* Parameter Validation */
211
212 if (!wake_device) {
213 /*
214 * By forcing wake_device to be valid, we automatically enable the
215 * implicit notify feature on all hosts.
216 */
217 return_ACPI_STATUS(AE_BAD_PARAMETER);
218 }
219
Bob Moore5816b342012-06-29 10:04:17 +0800220 /* Handle root object case */
221
222 if (wake_device == ACPI_ROOT_OBJECT) {
223 device_node = acpi_gbl_root_node;
224 } else {
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000225 device_node =
226 ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
Bob Moore5816b342012-06-29 10:04:17 +0800227 }
228
Lv Zheng75c80442012-12-19 05:36:49 +0000229 /* Validate wake_device is of type Device */
Bob Moore5816b342012-06-29 10:04:17 +0800230
231 if (device_node->type != ACPI_TYPE_DEVICE) {
232 return_ACPI_STATUS (AE_BAD_PARAMETER);
233 }
234
235 /*
236 * Allocate a new notify object up front, in case it is needed.
237 * Memory allocation while holding a spinlock is a big no-no
238 * on some hosts.
239 */
240 new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info));
241 if (!new_notify) {
242 return_ACPI_STATUS(AE_NO_MEMORY);
243 }
244
Lin Ming3cfd53d2010-12-13 13:36:02 +0800245 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
246
247 /* Ensure that we have a valid GPE number */
248
249 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100250 if (!gpe_event_info) {
Bob Moore5816b342012-06-29 10:04:17 +0800251 status = AE_BAD_PARAMETER;
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100252 goto unlock_and_exit;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800253 }
254
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100255 /*
256 * If there is no method or handler for this GPE, then the
Bob Moore5816b342012-06-29 10:04:17 +0800257 * wake_device will be notified whenever this GPE fires. This is
258 * known as an "implicit notify". Note: The GPE is assumed to be
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100259 * level-triggered (for windows compatibility).
260 */
Bob Moore5816b342012-06-29 10:04:17 +0800261 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
262 ACPI_GPE_DISPATCH_NONE) {
263 /*
264 * This is the first device for implicit notify on this GPE.
265 * Just set the flags here, and enter the NOTIFY block below.
266 */
267 gpe_event_info->flags =
268 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100269 }
270
Bob Moore5816b342012-06-29 10:04:17 +0800271 /*
272 * If we already have an implicit notify on this GPE, add
273 * this device to the notify list.
274 */
275 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
276 ACPI_GPE_DISPATCH_NOTIFY) {
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100277
Bob Moore5816b342012-06-29 10:04:17 +0800278 /* Ensure that the device is not already in the list */
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100279
Bob Moore5816b342012-06-29 10:04:17 +0800280 notify = gpe_event_info->dispatch.notify_list;
281 while (notify) {
282 if (notify->device_node == device_node) {
283 status = AE_ALREADY_EXISTS;
284 goto unlock_and_exit;
285 }
286 notify = notify->next;
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100287 }
288
Bob Moore5816b342012-06-29 10:04:17 +0800289 /* Add this device to the notify list for this GPE */
290
291 new_notify->device_node = device_node;
292 new_notify->next = gpe_event_info->dispatch.notify_list;
293 gpe_event_info->dispatch.notify_list = new_notify;
294 new_notify = NULL;
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100295 }
296
Bob Moore5816b342012-06-29 10:04:17 +0800297 /* Mark the GPE as a possible wake event */
298
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100299 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
300 status = AE_OK;
301
Bob Moore5816b342012-06-29 10:04:17 +0800302unlock_and_exit:
Lin Ming3cfd53d2010-12-13 13:36:02 +0800303 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Bob Moore5816b342012-06-29 10:04:17 +0800304
305 /* Delete the notify object if it was not used above */
306
307 if (new_notify) {
308 ACPI_FREE(new_notify);
309 }
Lin Ming3cfd53d2010-12-13 13:36:02 +0800310 return_ACPI_STATUS(status);
311}
Lin Ming3a378982010-12-13 13:36:15 +0800312ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800313
314/*******************************************************************************
315 *
Lin Ming3a378982010-12-13 13:36:15 +0800316 * FUNCTION: acpi_set_gpe_wake_mask
Lin Ming3cfd53d2010-12-13 13:36:02 +0800317 *
318 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
319 * gpe_number - GPE level within the GPE block
Bob Mooreba494be2012-07-12 09:40:10 +0800320 * action - Enable or Disable
Lin Ming3cfd53d2010-12-13 13:36:02 +0800321 *
322 * RETURN: Status
323 *
Lin Mingda503372010-12-13 13:39:37 +0800324 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
325 * already be marked as a WAKE GPE.
Lin Ming3cfd53d2010-12-13 13:36:02 +0800326 *
327 ******************************************************************************/
328
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000329acpi_status
330acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800331{
332 acpi_status status = AE_OK;
333 struct acpi_gpe_event_info *gpe_event_info;
334 struct acpi_gpe_register_info *gpe_register_info;
335 acpi_cpu_flags flags;
336 u32 register_bit;
337
Lin Ming3a378982010-12-13 13:36:15 +0800338 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800339
340 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
341
Lin Mingda503372010-12-13 13:39:37 +0800342 /*
343 * Ensure that we have a valid GPE number and that this GPE is in
344 * fact a wake GPE
345 */
Lin Ming3cfd53d2010-12-13 13:36:02 +0800346 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Lin Ming3a378982010-12-13 13:36:15 +0800347 if (!gpe_event_info) {
Lin Ming3cfd53d2010-12-13 13:36:02 +0800348 status = AE_BAD_PARAMETER;
349 goto unlock_and_exit;
350 }
351
Lin Ming3a378982010-12-13 13:36:15 +0800352 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
353 status = AE_TYPE;
354 goto unlock_and_exit;
355 }
356
Lin Ming3cfd53d2010-12-13 13:36:02 +0800357 gpe_register_info = gpe_event_info->register_info;
358 if (!gpe_register_info) {
359 status = AE_NOT_EXIST;
360 goto unlock_and_exit;
361 }
362
Feng Tang1d94e1e2012-08-17 11:10:02 +0800363 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800364
365 /* Perform the action */
366
367 switch (action) {
368 case ACPI_GPE_ENABLE:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000369
Lin Ming3cfd53d2010-12-13 13:36:02 +0800370 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
371 (u8)register_bit);
372 break;
373
374 case ACPI_GPE_DISABLE:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000375
Lin Ming3cfd53d2010-12-13 13:36:02 +0800376 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
377 (u8)register_bit);
378 break;
379
380 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000381
Lin Ming3cfd53d2010-12-13 13:36:02 +0800382 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
383 status = AE_BAD_PARAMETER;
384 break;
385 }
386
387unlock_and_exit:
388 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
389 return_ACPI_STATUS(status);
390}
391
Lin Ming3a378982010-12-13 13:36:15 +0800392ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800393
394/*******************************************************************************
395 *
396 * FUNCTION: acpi_clear_gpe
397 *
398 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
399 * gpe_number - GPE level within the GPE block
400 *
401 * RETURN: Status
402 *
403 * DESCRIPTION: Clear an ACPI event (general purpose)
404 *
405 ******************************************************************************/
406acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
407{
408 acpi_status status = AE_OK;
409 struct acpi_gpe_event_info *gpe_event_info;
410 acpi_cpu_flags flags;
411
412 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
413
414 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
415
416 /* Ensure that we have a valid GPE number */
417
418 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
419 if (!gpe_event_info) {
420 status = AE_BAD_PARAMETER;
421 goto unlock_and_exit;
422 }
423
424 status = acpi_hw_clear_gpe(gpe_event_info);
425
426 unlock_and_exit:
427 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
428 return_ACPI_STATUS(status);
429}
430
431ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
432
433/*******************************************************************************
434 *
435 * FUNCTION: acpi_get_gpe_status
436 *
437 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
438 * gpe_number - GPE level within the GPE block
Lv Zheng75c80442012-12-19 05:36:49 +0000439 * event_status - Where the current status of the event
440 * will be returned
Lin Ming3cfd53d2010-12-13 13:36:02 +0800441 *
442 * RETURN: Status
443 *
Lin Mingda503372010-12-13 13:39:37 +0800444 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800445 *
446 ******************************************************************************/
447acpi_status
448acpi_get_gpe_status(acpi_handle gpe_device,
449 u32 gpe_number, acpi_event_status *event_status)
450{
451 acpi_status status = AE_OK;
452 struct acpi_gpe_event_info *gpe_event_info;
453 acpi_cpu_flags flags;
454
455 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
456
457 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
458
459 /* Ensure that we have a valid GPE number */
460
461 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
462 if (!gpe_event_info) {
463 status = AE_BAD_PARAMETER;
464 goto unlock_and_exit;
465 }
466
467 /* Obtain status on the requested GPE number */
468
469 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
470
471 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
472 *event_status |= ACPI_EVENT_FLAG_HANDLE;
473
474 unlock_and_exit:
475 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
476 return_ACPI_STATUS(status);
477}
478
479ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
480
481/******************************************************************************
482 *
483 * FUNCTION: acpi_disable_all_gpes
484 *
485 * PARAMETERS: None
486 *
487 * RETURN: Status
488 *
489 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
490 *
491 ******************************************************************************/
492
493acpi_status acpi_disable_all_gpes(void)
494{
495 acpi_status status;
496
497 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
498
499 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
500 if (ACPI_FAILURE(status)) {
501 return_ACPI_STATUS(status);
502 }
503
504 status = acpi_hw_disable_all_gpes();
505 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
506
507 return_ACPI_STATUS(status);
508}
509
Lin Ming3a378982010-12-13 13:36:15 +0800510ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
511
Lin Ming3cfd53d2010-12-13 13:36:02 +0800512/******************************************************************************
513 *
514 * FUNCTION: acpi_enable_all_runtime_gpes
515 *
516 * PARAMETERS: None
517 *
518 * RETURN: Status
519 *
520 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
521 *
522 ******************************************************************************/
523
524acpi_status acpi_enable_all_runtime_gpes(void)
525{
526 acpi_status status;
527
528 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
529
530 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
531 if (ACPI_FAILURE(status)) {
532 return_ACPI_STATUS(status);
533 }
534
535 status = acpi_hw_enable_all_runtime_gpes();
536 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
537
538 return_ACPI_STATUS(status);
539}
540
Lin Ming3a378982010-12-13 13:36:15 +0800541ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
542
Lin Ming3cfd53d2010-12-13 13:36:02 +0800543/*******************************************************************************
544 *
545 * FUNCTION: acpi_install_gpe_block
546 *
547 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
Bob Mooreba494be2012-07-12 09:40:10 +0800548 * gpe_block_address - Address and space_ID
Lin Ming3cfd53d2010-12-13 13:36:02 +0800549 * register_count - Number of GPE register pairs in the block
550 * interrupt_number - H/W interrupt for the block
551 *
552 * RETURN: Status
553 *
Lin Mingda503372010-12-13 13:39:37 +0800554 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
555 * enabled here.
Lin Ming3cfd53d2010-12-13 13:36:02 +0800556 *
557 ******************************************************************************/
558acpi_status
559acpi_install_gpe_block(acpi_handle gpe_device,
560 struct acpi_generic_address *gpe_block_address,
561 u32 register_count, u32 interrupt_number)
562{
Lin Ming3a378982010-12-13 13:36:15 +0800563 acpi_status status;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800564 union acpi_operand_object *obj_desc;
565 struct acpi_namespace_node *node;
566 struct acpi_gpe_block_info *gpe_block;
567
568 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
569
570 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
571 return_ACPI_STATUS(AE_BAD_PARAMETER);
572 }
573
574 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
575 if (ACPI_FAILURE(status)) {
Bob Moore68aafc32012-10-31 02:26:01 +0000576 return_ACPI_STATUS(status);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800577 }
578
579 node = acpi_ns_validate_handle(gpe_device);
580 if (!node) {
581 status = AE_BAD_PARAMETER;
582 goto unlock_and_exit;
583 }
584
585 /*
586 * For user-installed GPE Block Devices, the gpe_block_base_number
587 * is always zero
588 */
589 status =
590 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
591 interrupt_number, &gpe_block);
592 if (ACPI_FAILURE(status)) {
593 goto unlock_and_exit;
594 }
595
596 /* Install block in the device_object attached to the node */
597
598 obj_desc = acpi_ns_get_attached_object(node);
599 if (!obj_desc) {
600
601 /*
602 * No object, create a new one (Device nodes do not always have
603 * an attached object)
604 */
605 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
606 if (!obj_desc) {
607 status = AE_NO_MEMORY;
608 goto unlock_and_exit;
609 }
610
611 status =
612 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
613
614 /* Remove local reference to the object */
615
616 acpi_ut_remove_reference(obj_desc);
617
618 if (ACPI_FAILURE(status)) {
619 goto unlock_and_exit;
620 }
621 }
622
623 /* Now install the GPE block in the device_object */
624
625 obj_desc->device.gpe_block = gpe_block;
626
627 unlock_and_exit:
628 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
629 return_ACPI_STATUS(status);
630}
631
632ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
633
634/*******************************************************************************
635 *
636 * FUNCTION: acpi_remove_gpe_block
637 *
638 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
639 *
640 * RETURN: Status
641 *
642 * DESCRIPTION: Remove a previously installed block of GPE registers
643 *
644 ******************************************************************************/
645acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
646{
647 union acpi_operand_object *obj_desc;
648 acpi_status status;
649 struct acpi_namespace_node *node;
650
651 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
652
653 if (!gpe_device) {
654 return_ACPI_STATUS(AE_BAD_PARAMETER);
655 }
656
657 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
658 if (ACPI_FAILURE(status)) {
Bob Moore68aafc32012-10-31 02:26:01 +0000659 return_ACPI_STATUS(status);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800660 }
661
662 node = acpi_ns_validate_handle(gpe_device);
663 if (!node) {
664 status = AE_BAD_PARAMETER;
665 goto unlock_and_exit;
666 }
667
668 /* Get the device_object attached to the node */
669
670 obj_desc = acpi_ns_get_attached_object(node);
671 if (!obj_desc || !obj_desc->device.gpe_block) {
672 return_ACPI_STATUS(AE_NULL_OBJECT);
673 }
674
675 /* Delete the GPE block (but not the device_object) */
676
677 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
678 if (ACPI_SUCCESS(status)) {
679 obj_desc->device.gpe_block = NULL;
680 }
681
682 unlock_and_exit:
683 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
684 return_ACPI_STATUS(status);
685}
686
687ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
688
689/*******************************************************************************
690 *
691 * FUNCTION: acpi_get_gpe_device
692 *
Bob Mooreba494be2012-07-12 09:40:10 +0800693 * PARAMETERS: index - System GPE index (0-current_gpe_count)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800694 * gpe_device - Where the parent GPE Device is returned
695 *
696 * RETURN: Status
697 *
698 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
699 * gpe device indicates that the gpe number is contained in one of
700 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
701 *
702 ******************************************************************************/
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000703acpi_status acpi_get_gpe_device(u32 index, acpi_handle * gpe_device)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800704{
705 struct acpi_gpe_device_info info;
706 acpi_status status;
707
708 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
709
710 if (!gpe_device) {
711 return_ACPI_STATUS(AE_BAD_PARAMETER);
712 }
713
714 if (index >= acpi_current_gpe_count) {
715 return_ACPI_STATUS(AE_NOT_EXIST);
716 }
717
718 /* Setup and walk the GPE list */
719
720 info.index = index;
721 info.status = AE_NOT_EXIST;
722 info.gpe_device = NULL;
723 info.next_block_base_index = 0;
724
725 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
726 if (ACPI_FAILURE(status)) {
727 return_ACPI_STATUS(status);
728 }
729
Lin Ming3a378982010-12-13 13:36:15 +0800730 *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800731 return_ACPI_STATUS(info.status);
732}
733
734ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
Bob Moore33620c52012-02-14 18:14:27 +0800735#endif /* !ACPI_REDUCED_HARDWARE */