blob: 6affbdb4b88c930567f8c3a852b8c051fbbb0dbf [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 Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, 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 */
Lin Ming3cfd53d2010-12-13 13:36:02 +080054/******************************************************************************
55 *
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}
175ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
176
Lin Mingbba63a22010-12-13 13:39:17 +0800177
Lin Ming3cfd53d2010-12-13 13:36:02 +0800178/*******************************************************************************
179 *
Lin Ming3a378982010-12-13 13:36:15 +0800180 * FUNCTION: acpi_setup_gpe_for_wake
Lin Ming3cfd53d2010-12-13 13:36:02 +0800181 *
Lin Mingbba63a22010-12-13 13:39:17 +0800182 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
183 * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
184 * gpe_number - GPE level within the GPE block
Lin Ming3cfd53d2010-12-13 13:36:02 +0800185 *
186 * RETURN: Status
187 *
Lin Mingbba63a22010-12-13 13:39:17 +0800188 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
189 * interface is intended to be used as the host executes the
190 * _PRW methods (Power Resources for Wake) in the system tables.
191 * Each _PRW appears under a Device Object (The wake_device), and
192 * contains the info for the wake GPE associated with the
193 * wake_device.
Lin Ming3cfd53d2010-12-13 13:36:02 +0800194 *
195 ******************************************************************************/
Lin Mingbba63a22010-12-13 13:39:17 +0800196acpi_status
197acpi_setup_gpe_for_wake(acpi_handle wake_device,
198 acpi_handle gpe_device, u32 gpe_number)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800199{
Bob Moore5816b342012-06-29 10:04:17 +0800200 acpi_status status;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800201 struct acpi_gpe_event_info *gpe_event_info;
Lin Mingbba63a22010-12-13 13:39:17 +0800202 struct acpi_namespace_node *device_node;
Bob Moore5816b342012-06-29 10:04:17 +0800203 struct acpi_gpe_notify_info *notify;
204 struct acpi_gpe_notify_info *new_notify;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800205 acpi_cpu_flags flags;
206
Lin Ming3a378982010-12-13 13:36:15 +0800207 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800208
Lin Mingbba63a22010-12-13 13:39:17 +0800209 /* Parameter Validation */
210
211 if (!wake_device) {
212 /*
213 * By forcing wake_device to be valid, we automatically enable the
214 * implicit notify feature on all hosts.
215 */
216 return_ACPI_STATUS(AE_BAD_PARAMETER);
217 }
218
Bob Moore5816b342012-06-29 10:04:17 +0800219 /* Handle root object case */
220
221 if (wake_device == ACPI_ROOT_OBJECT) {
222 device_node = acpi_gbl_root_node;
223 } else {
224 device_node = ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
225 }
226
227 /* Validate WakeDevice is of type Device */
228
229 if (device_node->type != ACPI_TYPE_DEVICE) {
230 return_ACPI_STATUS (AE_BAD_PARAMETER);
231 }
232
233 /*
234 * Allocate a new notify object up front, in case it is needed.
235 * Memory allocation while holding a spinlock is a big no-no
236 * on some hosts.
237 */
238 new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info));
239 if (!new_notify) {
240 return_ACPI_STATUS(AE_NO_MEMORY);
241 }
242
Lin Ming3cfd53d2010-12-13 13:36:02 +0800243 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
244
245 /* Ensure that we have a valid GPE number */
246
247 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100248 if (!gpe_event_info) {
Bob Moore5816b342012-06-29 10:04:17 +0800249 status = AE_BAD_PARAMETER;
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100250 goto unlock_and_exit;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800251 }
252
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100253 /*
254 * If there is no method or handler for this GPE, then the
Bob Moore5816b342012-06-29 10:04:17 +0800255 * wake_device will be notified whenever this GPE fires. This is
256 * known as an "implicit notify". Note: The GPE is assumed to be
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100257 * level-triggered (for windows compatibility).
258 */
Bob Moore5816b342012-06-29 10:04:17 +0800259 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
260 ACPI_GPE_DISPATCH_NONE) {
261 /*
262 * This is the first device for implicit notify on this GPE.
263 * Just set the flags here, and enter the NOTIFY block below.
264 */
265 gpe_event_info->flags =
266 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100267 }
268
Bob Moore5816b342012-06-29 10:04:17 +0800269 /*
270 * If we already have an implicit notify on this GPE, add
271 * this device to the notify list.
272 */
273 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
274 ACPI_GPE_DISPATCH_NOTIFY) {
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100275
Bob Moore5816b342012-06-29 10:04:17 +0800276 /* Ensure that the device is not already in the list */
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100277
Bob Moore5816b342012-06-29 10:04:17 +0800278 notify = gpe_event_info->dispatch.notify_list;
279 while (notify) {
280 if (notify->device_node == device_node) {
281 status = AE_ALREADY_EXISTS;
282 goto unlock_and_exit;
283 }
284 notify = notify->next;
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100285 }
286
Bob Moore5816b342012-06-29 10:04:17 +0800287 /* Add this device to the notify list for this GPE */
288
289 new_notify->device_node = device_node;
290 new_notify->next = gpe_event_info->dispatch.notify_list;
291 gpe_event_info->dispatch.notify_list = new_notify;
292 new_notify = NULL;
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100293 }
294
Bob Moore5816b342012-06-29 10:04:17 +0800295 /* Mark the GPE as a possible wake event */
296
Rafael J. Wysocki2d559512011-02-12 01:39:15 +0100297 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
298 status = AE_OK;
299
Bob Moore5816b342012-06-29 10:04:17 +0800300unlock_and_exit:
Lin Ming3cfd53d2010-12-13 13:36:02 +0800301 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Bob Moore5816b342012-06-29 10:04:17 +0800302
303 /* Delete the notify object if it was not used above */
304
305 if (new_notify) {
306 ACPI_FREE(new_notify);
307 }
Lin Ming3cfd53d2010-12-13 13:36:02 +0800308 return_ACPI_STATUS(status);
309}
Lin Ming3a378982010-12-13 13:36:15 +0800310ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800311
312/*******************************************************************************
313 *
Lin Ming3a378982010-12-13 13:36:15 +0800314 * FUNCTION: acpi_set_gpe_wake_mask
Lin Ming3cfd53d2010-12-13 13:36:02 +0800315 *
316 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
317 * gpe_number - GPE level within the GPE block
Bob Mooreba494be2012-07-12 09:40:10 +0800318 * action - Enable or Disable
Lin Ming3cfd53d2010-12-13 13:36:02 +0800319 *
320 * RETURN: Status
321 *
Lin Mingda503372010-12-13 13:39:37 +0800322 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
323 * already be marked as a WAKE GPE.
Lin Ming3cfd53d2010-12-13 13:36:02 +0800324 *
325 ******************************************************************************/
326
Lin Ming3a378982010-12-13 13:36:15 +0800327acpi_status acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800328{
329 acpi_status status = AE_OK;
330 struct acpi_gpe_event_info *gpe_event_info;
331 struct acpi_gpe_register_info *gpe_register_info;
332 acpi_cpu_flags flags;
333 u32 register_bit;
334
Lin Ming3a378982010-12-13 13:36:15 +0800335 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800336
337 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
338
Lin Mingda503372010-12-13 13:39:37 +0800339 /*
340 * Ensure that we have a valid GPE number and that this GPE is in
341 * fact a wake GPE
342 */
Lin Ming3cfd53d2010-12-13 13:36:02 +0800343 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Lin Ming3a378982010-12-13 13:36:15 +0800344 if (!gpe_event_info) {
Lin Ming3cfd53d2010-12-13 13:36:02 +0800345 status = AE_BAD_PARAMETER;
346 goto unlock_and_exit;
347 }
348
Lin Ming3a378982010-12-13 13:36:15 +0800349 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
350 status = AE_TYPE;
351 goto unlock_and_exit;
352 }
353
Lin Ming3cfd53d2010-12-13 13:36:02 +0800354 gpe_register_info = gpe_event_info->register_info;
355 if (!gpe_register_info) {
356 status = AE_NOT_EXIST;
357 goto unlock_and_exit;
358 }
359
360 register_bit =
361 acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
362
363 /* Perform the action */
364
365 switch (action) {
366 case ACPI_GPE_ENABLE:
367 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
368 (u8)register_bit);
369 break;
370
371 case ACPI_GPE_DISABLE:
372 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
373 (u8)register_bit);
374 break;
375
376 default:
377 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
378 status = AE_BAD_PARAMETER;
379 break;
380 }
381
382unlock_and_exit:
383 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
384 return_ACPI_STATUS(status);
385}
386
Lin Ming3a378982010-12-13 13:36:15 +0800387ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800388
389/*******************************************************************************
390 *
391 * FUNCTION: acpi_clear_gpe
392 *
393 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
394 * gpe_number - GPE level within the GPE block
395 *
396 * RETURN: Status
397 *
398 * DESCRIPTION: Clear an ACPI event (general purpose)
399 *
400 ******************************************************************************/
401acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
402{
403 acpi_status status = AE_OK;
404 struct acpi_gpe_event_info *gpe_event_info;
405 acpi_cpu_flags flags;
406
407 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
408
409 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
410
411 /* Ensure that we have a valid GPE number */
412
413 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
414 if (!gpe_event_info) {
415 status = AE_BAD_PARAMETER;
416 goto unlock_and_exit;
417 }
418
419 status = acpi_hw_clear_gpe(gpe_event_info);
420
421 unlock_and_exit:
422 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
423 return_ACPI_STATUS(status);
424}
425
426ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
427
428/*******************************************************************************
429 *
430 * FUNCTION: acpi_get_gpe_status
431 *
432 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
433 * gpe_number - GPE level within the GPE block
434 * event_status - Where the current status of the event will
435 * be returned
436 *
437 * RETURN: Status
438 *
Lin Mingda503372010-12-13 13:39:37 +0800439 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800440 *
441 ******************************************************************************/
442acpi_status
443acpi_get_gpe_status(acpi_handle gpe_device,
444 u32 gpe_number, acpi_event_status *event_status)
445{
446 acpi_status status = AE_OK;
447 struct acpi_gpe_event_info *gpe_event_info;
448 acpi_cpu_flags flags;
449
450 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
451
452 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
453
454 /* Ensure that we have a valid GPE number */
455
456 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
457 if (!gpe_event_info) {
458 status = AE_BAD_PARAMETER;
459 goto unlock_and_exit;
460 }
461
462 /* Obtain status on the requested GPE number */
463
464 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
465
466 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
467 *event_status |= ACPI_EVENT_FLAG_HANDLE;
468
469 unlock_and_exit:
470 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
471 return_ACPI_STATUS(status);
472}
473
474ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
475
476/******************************************************************************
477 *
478 * FUNCTION: acpi_disable_all_gpes
479 *
480 * PARAMETERS: None
481 *
482 * RETURN: Status
483 *
484 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
485 *
486 ******************************************************************************/
487
488acpi_status acpi_disable_all_gpes(void)
489{
490 acpi_status status;
491
492 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
493
494 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
495 if (ACPI_FAILURE(status)) {
496 return_ACPI_STATUS(status);
497 }
498
499 status = acpi_hw_disable_all_gpes();
500 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
501
502 return_ACPI_STATUS(status);
503}
504
Lin Ming3a378982010-12-13 13:36:15 +0800505ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
506
Lin Ming3cfd53d2010-12-13 13:36:02 +0800507/******************************************************************************
508 *
509 * FUNCTION: acpi_enable_all_runtime_gpes
510 *
511 * PARAMETERS: None
512 *
513 * RETURN: Status
514 *
515 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
516 *
517 ******************************************************************************/
518
519acpi_status acpi_enable_all_runtime_gpes(void)
520{
521 acpi_status status;
522
523 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
524
525 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
526 if (ACPI_FAILURE(status)) {
527 return_ACPI_STATUS(status);
528 }
529
530 status = acpi_hw_enable_all_runtime_gpes();
531 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
532
533 return_ACPI_STATUS(status);
534}
535
Lin Ming3a378982010-12-13 13:36:15 +0800536ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
537
Lin Ming3cfd53d2010-12-13 13:36:02 +0800538/*******************************************************************************
539 *
540 * FUNCTION: acpi_install_gpe_block
541 *
542 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
Bob Mooreba494be2012-07-12 09:40:10 +0800543 * gpe_block_address - Address and space_ID
Lin Ming3cfd53d2010-12-13 13:36:02 +0800544 * register_count - Number of GPE register pairs in the block
545 * interrupt_number - H/W interrupt for the block
546 *
547 * RETURN: Status
548 *
Lin Mingda503372010-12-13 13:39:37 +0800549 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
550 * enabled here.
Lin Ming3cfd53d2010-12-13 13:36:02 +0800551 *
552 ******************************************************************************/
553acpi_status
554acpi_install_gpe_block(acpi_handle gpe_device,
555 struct acpi_generic_address *gpe_block_address,
556 u32 register_count, u32 interrupt_number)
557{
Lin Ming3a378982010-12-13 13:36:15 +0800558 acpi_status status;
Lin Ming3cfd53d2010-12-13 13:36:02 +0800559 union acpi_operand_object *obj_desc;
560 struct acpi_namespace_node *node;
561 struct acpi_gpe_block_info *gpe_block;
562
563 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
564
565 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
566 return_ACPI_STATUS(AE_BAD_PARAMETER);
567 }
568
569 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
570 if (ACPI_FAILURE(status)) {
571 return (status);
572 }
573
574 node = acpi_ns_validate_handle(gpe_device);
575 if (!node) {
576 status = AE_BAD_PARAMETER;
577 goto unlock_and_exit;
578 }
579
580 /*
581 * For user-installed GPE Block Devices, the gpe_block_base_number
582 * is always zero
583 */
584 status =
585 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
586 interrupt_number, &gpe_block);
587 if (ACPI_FAILURE(status)) {
588 goto unlock_and_exit;
589 }
590
591 /* Install block in the device_object attached to the node */
592
593 obj_desc = acpi_ns_get_attached_object(node);
594 if (!obj_desc) {
595
596 /*
597 * No object, create a new one (Device nodes do not always have
598 * an attached object)
599 */
600 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
601 if (!obj_desc) {
602 status = AE_NO_MEMORY;
603 goto unlock_and_exit;
604 }
605
606 status =
607 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
608
609 /* Remove local reference to the object */
610
611 acpi_ut_remove_reference(obj_desc);
612
613 if (ACPI_FAILURE(status)) {
614 goto unlock_and_exit;
615 }
616 }
617
618 /* Now install the GPE block in the device_object */
619
620 obj_desc->device.gpe_block = gpe_block;
621
622 unlock_and_exit:
623 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
624 return_ACPI_STATUS(status);
625}
626
627ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
628
629/*******************************************************************************
630 *
631 * FUNCTION: acpi_remove_gpe_block
632 *
633 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
634 *
635 * RETURN: Status
636 *
637 * DESCRIPTION: Remove a previously installed block of GPE registers
638 *
639 ******************************************************************************/
640acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
641{
642 union acpi_operand_object *obj_desc;
643 acpi_status status;
644 struct acpi_namespace_node *node;
645
646 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
647
648 if (!gpe_device) {
649 return_ACPI_STATUS(AE_BAD_PARAMETER);
650 }
651
652 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
653 if (ACPI_FAILURE(status)) {
654 return (status);
655 }
656
657 node = acpi_ns_validate_handle(gpe_device);
658 if (!node) {
659 status = AE_BAD_PARAMETER;
660 goto unlock_and_exit;
661 }
662
663 /* Get the device_object attached to the node */
664
665 obj_desc = acpi_ns_get_attached_object(node);
666 if (!obj_desc || !obj_desc->device.gpe_block) {
667 return_ACPI_STATUS(AE_NULL_OBJECT);
668 }
669
670 /* Delete the GPE block (but not the device_object) */
671
672 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
673 if (ACPI_SUCCESS(status)) {
674 obj_desc->device.gpe_block = NULL;
675 }
676
677 unlock_and_exit:
678 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
679 return_ACPI_STATUS(status);
680}
681
682ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
683
684/*******************************************************************************
685 *
686 * FUNCTION: acpi_get_gpe_device
687 *
Bob Mooreba494be2012-07-12 09:40:10 +0800688 * PARAMETERS: index - System GPE index (0-current_gpe_count)
Lin Ming3cfd53d2010-12-13 13:36:02 +0800689 * gpe_device - Where the parent GPE Device is returned
690 *
691 * RETURN: Status
692 *
693 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
694 * gpe device indicates that the gpe number is contained in one of
695 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
696 *
697 ******************************************************************************/
698acpi_status
699acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
700{
701 struct acpi_gpe_device_info info;
702 acpi_status status;
703
704 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
705
706 if (!gpe_device) {
707 return_ACPI_STATUS(AE_BAD_PARAMETER);
708 }
709
710 if (index >= acpi_current_gpe_count) {
711 return_ACPI_STATUS(AE_NOT_EXIST);
712 }
713
714 /* Setup and walk the GPE list */
715
716 info.index = index;
717 info.status = AE_NOT_EXIST;
718 info.gpe_device = NULL;
719 info.next_block_base_index = 0;
720
721 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
722 if (ACPI_FAILURE(status)) {
723 return_ACPI_STATUS(status);
724 }
725
Lin Ming3a378982010-12-13 13:36:15 +0800726 *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
Lin Ming3cfd53d2010-12-13 13:36:02 +0800727 return_ACPI_STATUS(info.status);
728}
729
730ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
Bob Moore33620c52012-02-14 18:14:27 +0800731#endif /* !ACPI_REDUCED_HARDWARE */