]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/acpi/acpica/evxfevnt.c
bd06fad83e7a39fe43c9e07f82f1c200332bfb18
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / evxfevnt.c
1 /******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2010, Intel Corp.
9 * 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
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acevents.h"
47 #include "acnamesp.h"
48 #include "actables.h"
49
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME("evxfevnt")
52
53 /* Local prototypes */
54 static acpi_status
55 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
56 struct acpi_gpe_block_info *gpe_block, void *context);
57
58 /*******************************************************************************
59 *
60 * FUNCTION: acpi_enable
61 *
62 * PARAMETERS: None
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Transfers the system into ACPI mode.
67 *
68 ******************************************************************************/
69
70 acpi_status acpi_enable(void)
71 {
72 acpi_status status;
73
74 ACPI_FUNCTION_TRACE(acpi_enable);
75
76 /* ACPI tables must be present */
77
78 if (!acpi_tb_tables_loaded()) {
79 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
80 }
81
82 /* Check current mode */
83
84 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
85 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
86 "System is already in ACPI mode\n"));
87 return_ACPI_STATUS(AE_OK);
88 }
89
90 /* Transition to ACPI mode */
91
92 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
93 if (ACPI_FAILURE(status)) {
94 ACPI_ERROR((AE_INFO,
95 "Could not transition to ACPI mode"));
96 return_ACPI_STATUS(status);
97 }
98
99 /* Sanity check that transition succeeded */
100
101 if (acpi_hw_get_mode() != ACPI_SYS_MODE_ACPI) {
102 ACPI_ERROR((AE_INFO,
103 "Hardware did not enter ACPI mode"));
104 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
105 }
106
107 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
108 "Transition to ACPI mode successful\n"));
109
110 return_ACPI_STATUS(AE_OK);
111 }
112
113 ACPI_EXPORT_SYMBOL(acpi_enable)
114
115 /*******************************************************************************
116 *
117 * FUNCTION: acpi_disable
118 *
119 * PARAMETERS: None
120 *
121 * RETURN: Status
122 *
123 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
124 *
125 ******************************************************************************/
126 acpi_status acpi_disable(void)
127 {
128 acpi_status status = AE_OK;
129
130 ACPI_FUNCTION_TRACE(acpi_disable);
131
132 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
133 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
134 "System is already in legacy (non-ACPI) mode\n"));
135 } else {
136 /* Transition to LEGACY mode */
137
138 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
139
140 if (ACPI_FAILURE(status)) {
141 ACPI_ERROR((AE_INFO,
142 "Could not exit ACPI mode to legacy mode"));
143 return_ACPI_STATUS(status);
144 }
145
146 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
147 }
148
149 return_ACPI_STATUS(status);
150 }
151
152 ACPI_EXPORT_SYMBOL(acpi_disable)
153
154 /*******************************************************************************
155 *
156 * FUNCTION: acpi_enable_event
157 *
158 * PARAMETERS: Event - The fixed eventto be enabled
159 * Flags - Reserved
160 *
161 * RETURN: Status
162 *
163 * DESCRIPTION: Enable an ACPI event (fixed)
164 *
165 ******************************************************************************/
166 acpi_status acpi_enable_event(u32 event, u32 flags)
167 {
168 acpi_status status = AE_OK;
169 u32 value;
170
171 ACPI_FUNCTION_TRACE(acpi_enable_event);
172
173 /* Decode the Fixed Event */
174
175 if (event > ACPI_EVENT_MAX) {
176 return_ACPI_STATUS(AE_BAD_PARAMETER);
177 }
178
179 /*
180 * Enable the requested fixed event (by writing a one to the enable
181 * register bit)
182 */
183 status =
184 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
185 enable_register_id, ACPI_ENABLE_EVENT);
186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
188 }
189
190 /* Make sure that the hardware responded */
191
192 status =
193 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
194 enable_register_id, &value);
195 if (ACPI_FAILURE(status)) {
196 return_ACPI_STATUS(status);
197 }
198
199 if (value != 1) {
200 ACPI_ERROR((AE_INFO,
201 "Could not enable %s event",
202 acpi_ut_get_event_name(event)));
203 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
204 }
205
206 return_ACPI_STATUS(status);
207 }
208
209 ACPI_EXPORT_SYMBOL(acpi_enable_event)
210
211 /*******************************************************************************
212 *
213 * FUNCTION: acpi_gpe_wakeup
214 *
215 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
216 * gpe_number - GPE level within the GPE block
217 * Action - Enable or Disable
218 *
219 * RETURN: Status
220 *
221 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
222 *
223 ******************************************************************************/
224 acpi_status acpi_gpe_wakeup(acpi_handle gpe_device, u32 gpe_number, u8 action)
225 {
226 acpi_status status = AE_OK;
227 struct acpi_gpe_event_info *gpe_event_info;
228 struct acpi_gpe_register_info *gpe_register_info;
229 acpi_cpu_flags flags;
230 u32 register_bit;
231
232 ACPI_FUNCTION_TRACE(acpi_gpe_wakeup);
233
234 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
235
236 /* Ensure that we have a valid GPE number */
237
238 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
239 if (!gpe_event_info) {
240 status = AE_BAD_PARAMETER;
241 goto unlock_and_exit;
242 }
243
244 gpe_register_info = gpe_event_info->register_info;
245 if (!gpe_register_info) {
246 status = AE_NOT_EXIST;
247 goto unlock_and_exit;
248 }
249
250 register_bit =
251 acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
252
253 /* Perform the action */
254
255 switch (action) {
256 case ACPI_GPE_ENABLE:
257 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
258 (u8)register_bit);
259 break;
260
261 case ACPI_GPE_DISABLE:
262 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
263 (u8)register_bit);
264 break;
265
266 default:
267 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
268 status = AE_BAD_PARAMETER;
269 break;
270 }
271
272 unlock_and_exit:
273 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
274 return_ACPI_STATUS(status);
275 }
276
277 ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
278
279 /*******************************************************************************
280 *
281 * FUNCTION: acpi_enable_gpe
282 *
283 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
284 * gpe_number - GPE level within the GPE block
285 *
286 * RETURN: Status
287 *
288 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
289 * hardware-enabled.
290 *
291 ******************************************************************************/
292 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
293 {
294 acpi_status status = AE_OK;
295 struct acpi_gpe_event_info *gpe_event_info;
296 acpi_cpu_flags flags;
297
298 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
299
300 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
301
302 /* Ensure that we have a valid GPE number */
303
304 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
305 if (!gpe_event_info) {
306 status = AE_BAD_PARAMETER;
307 goto unlock_and_exit;
308 }
309
310 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
311 status = AE_LIMIT; /* Too many references */
312 goto unlock_and_exit;
313 }
314
315 gpe_event_info->runtime_count++;
316 if (gpe_event_info->runtime_count == 1) {
317 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
318 if (ACPI_SUCCESS(status)) {
319 status = acpi_ev_enable_gpe(gpe_event_info);
320 }
321 if (ACPI_FAILURE(status)) {
322 gpe_event_info->runtime_count--;
323 }
324 }
325
326 unlock_and_exit:
327 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
328 return_ACPI_STATUS(status);
329 }
330 ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
331
332 /*******************************************************************************
333 *
334 * FUNCTION: acpi_disable_gpe
335 *
336 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
337 * gpe_number - GPE level within the GPE block
338 *
339 * RETURN: Status
340 *
341 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
342 * removed, only then is the GPE disabled (for runtime GPEs), or
343 * the GPE mask bit disabled (for wake GPEs)
344 *
345 ******************************************************************************/
346 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
347 {
348 acpi_status status = AE_OK;
349 struct acpi_gpe_event_info *gpe_event_info;
350 acpi_cpu_flags flags;
351
352 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
353
354 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
355
356 /* Ensure that we have a valid GPE number */
357
358 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
359 if (!gpe_event_info) {
360 status = AE_BAD_PARAMETER;
361 goto unlock_and_exit;
362 }
363
364 /* Hardware-disable a runtime GPE on removal of the last reference */
365
366 if (!gpe_event_info->runtime_count) {
367 status = AE_LIMIT; /* There are no references to remove */
368 goto unlock_and_exit;
369 }
370
371 gpe_event_info->runtime_count--;
372 if (!gpe_event_info->runtime_count) {
373 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
374 if (ACPI_SUCCESS(status)) {
375 status =
376 acpi_hw_low_set_gpe(gpe_event_info,
377 ACPI_GPE_DISABLE);
378 }
379 if (ACPI_FAILURE(status)) {
380 gpe_event_info->runtime_count++;
381 }
382 }
383
384 unlock_and_exit:
385 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
386 return_ACPI_STATUS(status);
387 }
388 ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
389
390 /*******************************************************************************
391 *
392 * FUNCTION: acpi_gpe_can_wake
393 *
394 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
395 * gpe_number - GPE level within the GPE block
396 *
397 * RETURN: Status
398 *
399 * DESCRIPTION: Set the ACPI_GPE_CAN_WAKE flag for the given GPE. If the GPE
400 * has a corresponding method and is currently enabled, disable it
401 * (GPEs with corresponding methods are enabled unconditionally
402 * during initialization, but GPEs that can wake up are expected
403 * to be initially disabled).
404 *
405 ******************************************************************************/
406 acpi_status acpi_gpe_can_wake(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 u8 disable = 0;
412
413 ACPI_FUNCTION_TRACE(acpi_gpe_can_wake);
414
415 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
416
417 /* Ensure that we have a valid GPE number */
418
419 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
420 if (!gpe_event_info) {
421 status = AE_BAD_PARAMETER;
422 goto unlock_and_exit;
423 }
424
425 if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
426 goto unlock_and_exit;
427 }
428
429 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
430 disable = (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)
431 && gpe_event_info->runtime_count;
432
433 unlock_and_exit:
434 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
435
436 if (disable)
437 status = acpi_disable_gpe(gpe_device, gpe_number);
438
439 return_ACPI_STATUS(status);
440 }
441 ACPI_EXPORT_SYMBOL(acpi_gpe_can_wake)
442
443 /*******************************************************************************
444 *
445 * FUNCTION: acpi_disable_event
446 *
447 * PARAMETERS: Event - The fixed eventto be enabled
448 * Flags - Reserved
449 *
450 * RETURN: Status
451 *
452 * DESCRIPTION: Disable an ACPI event (fixed)
453 *
454 ******************************************************************************/
455 acpi_status acpi_disable_event(u32 event, u32 flags)
456 {
457 acpi_status status = AE_OK;
458 u32 value;
459
460 ACPI_FUNCTION_TRACE(acpi_disable_event);
461
462 /* Decode the Fixed Event */
463
464 if (event > ACPI_EVENT_MAX) {
465 return_ACPI_STATUS(AE_BAD_PARAMETER);
466 }
467
468 /*
469 * Disable the requested fixed event (by writing a zero to the enable
470 * register bit)
471 */
472 status =
473 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
474 enable_register_id, ACPI_DISABLE_EVENT);
475 if (ACPI_FAILURE(status)) {
476 return_ACPI_STATUS(status);
477 }
478
479 status =
480 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
481 enable_register_id, &value);
482 if (ACPI_FAILURE(status)) {
483 return_ACPI_STATUS(status);
484 }
485
486 if (value != 0) {
487 ACPI_ERROR((AE_INFO,
488 "Could not disable %s events",
489 acpi_ut_get_event_name(event)));
490 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
491 }
492
493 return_ACPI_STATUS(status);
494 }
495
496 ACPI_EXPORT_SYMBOL(acpi_disable_event)
497
498 /*******************************************************************************
499 *
500 * FUNCTION: acpi_clear_event
501 *
502 * PARAMETERS: Event - The fixed event to be cleared
503 *
504 * RETURN: Status
505 *
506 * DESCRIPTION: Clear an ACPI event (fixed)
507 *
508 ******************************************************************************/
509 acpi_status acpi_clear_event(u32 event)
510 {
511 acpi_status status = AE_OK;
512
513 ACPI_FUNCTION_TRACE(acpi_clear_event);
514
515 /* Decode the Fixed Event */
516
517 if (event > ACPI_EVENT_MAX) {
518 return_ACPI_STATUS(AE_BAD_PARAMETER);
519 }
520
521 /*
522 * Clear the requested fixed event (By writing a one to the status
523 * register bit)
524 */
525 status =
526 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
527 status_register_id, ACPI_CLEAR_STATUS);
528
529 return_ACPI_STATUS(status);
530 }
531
532 ACPI_EXPORT_SYMBOL(acpi_clear_event)
533
534 /*******************************************************************************
535 *
536 * FUNCTION: acpi_clear_gpe
537 *
538 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
539 * gpe_number - GPE level within the GPE block
540 *
541 * RETURN: Status
542 *
543 * DESCRIPTION: Clear an ACPI event (general purpose)
544 *
545 ******************************************************************************/
546 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
547 {
548 acpi_status status = AE_OK;
549 struct acpi_gpe_event_info *gpe_event_info;
550 acpi_cpu_flags flags;
551
552 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
553
554 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
555
556 /* Ensure that we have a valid GPE number */
557
558 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
559 if (!gpe_event_info) {
560 status = AE_BAD_PARAMETER;
561 goto unlock_and_exit;
562 }
563
564 status = acpi_hw_clear_gpe(gpe_event_info);
565
566 unlock_and_exit:
567 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
568 return_ACPI_STATUS(status);
569 }
570
571 ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
572 /*******************************************************************************
573 *
574 * FUNCTION: acpi_get_event_status
575 *
576 * PARAMETERS: Event - The fixed event
577 * event_status - Where the current status of the event will
578 * be returned
579 *
580 * RETURN: Status
581 *
582 * DESCRIPTION: Obtains and returns the current status of the event
583 *
584 ******************************************************************************/
585 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
586 {
587 acpi_status status = AE_OK;
588 u32 value;
589
590 ACPI_FUNCTION_TRACE(acpi_get_event_status);
591
592 if (!event_status) {
593 return_ACPI_STATUS(AE_BAD_PARAMETER);
594 }
595
596 /* Decode the Fixed Event */
597
598 if (event > ACPI_EVENT_MAX) {
599 return_ACPI_STATUS(AE_BAD_PARAMETER);
600 }
601
602 /* Get the status of the requested fixed event */
603
604 status =
605 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
606 enable_register_id, &value);
607 if (ACPI_FAILURE(status))
608 return_ACPI_STATUS(status);
609
610 *event_status = value;
611
612 status =
613 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
614 status_register_id, &value);
615 if (ACPI_FAILURE(status))
616 return_ACPI_STATUS(status);
617
618 if (value)
619 *event_status |= ACPI_EVENT_FLAG_SET;
620
621 if (acpi_gbl_fixed_event_handlers[event].handler)
622 *event_status |= ACPI_EVENT_FLAG_HANDLE;
623
624 return_ACPI_STATUS(status);
625 }
626
627 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
628
629 /*******************************************************************************
630 *
631 * FUNCTION: acpi_get_gpe_status
632 *
633 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
634 * gpe_number - GPE level within the GPE block
635 * event_status - Where the current status of the event will
636 * be returned
637 *
638 * RETURN: Status
639 *
640 * DESCRIPTION: Get status of an event (general purpose)
641 *
642 ******************************************************************************/
643 acpi_status
644 acpi_get_gpe_status(acpi_handle gpe_device,
645 u32 gpe_number, acpi_event_status *event_status)
646 {
647 acpi_status status = AE_OK;
648 struct acpi_gpe_event_info *gpe_event_info;
649 acpi_cpu_flags flags;
650
651 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
652
653 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
654
655 /* Ensure that we have a valid GPE number */
656
657 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
658 if (!gpe_event_info) {
659 status = AE_BAD_PARAMETER;
660 goto unlock_and_exit;
661 }
662
663 /* Obtain status on the requested GPE number */
664
665 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
666
667 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
668 *event_status |= ACPI_EVENT_FLAG_HANDLE;
669
670 unlock_and_exit:
671 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
672 return_ACPI_STATUS(status);
673 }
674
675 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
676 /*******************************************************************************
677 *
678 * FUNCTION: acpi_install_gpe_block
679 *
680 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
681 * gpe_block_address - Address and space_iD
682 * register_count - Number of GPE register pairs in the block
683 * interrupt_number - H/W interrupt for the block
684 *
685 * RETURN: Status
686 *
687 * DESCRIPTION: Create and Install a block of GPE registers
688 *
689 ******************************************************************************/
690 acpi_status
691 acpi_install_gpe_block(acpi_handle gpe_device,
692 struct acpi_generic_address *gpe_block_address,
693 u32 register_count, u32 interrupt_number)
694 {
695 acpi_status status;
696 union acpi_operand_object *obj_desc;
697 struct acpi_namespace_node *node;
698 struct acpi_gpe_block_info *gpe_block;
699
700 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
701
702 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
703 return_ACPI_STATUS(AE_BAD_PARAMETER);
704 }
705
706 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
707 if (ACPI_FAILURE(status)) {
708 return (status);
709 }
710
711 node = acpi_ns_validate_handle(gpe_device);
712 if (!node) {
713 status = AE_BAD_PARAMETER;
714 goto unlock_and_exit;
715 }
716
717 /*
718 * For user-installed GPE Block Devices, the gpe_block_base_number
719 * is always zero
720 */
721 status =
722 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
723 interrupt_number, &gpe_block);
724 if (ACPI_FAILURE(status)) {
725 goto unlock_and_exit;
726 }
727
728 /* Install block in the device_object attached to the node */
729
730 obj_desc = acpi_ns_get_attached_object(node);
731 if (!obj_desc) {
732
733 /*
734 * No object, create a new one (Device nodes do not always have
735 * an attached object)
736 */
737 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
738 if (!obj_desc) {
739 status = AE_NO_MEMORY;
740 goto unlock_and_exit;
741 }
742
743 status =
744 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
745
746 /* Remove local reference to the object */
747
748 acpi_ut_remove_reference(obj_desc);
749
750 if (ACPI_FAILURE(status)) {
751 goto unlock_and_exit;
752 }
753 }
754
755 /* Now install the GPE block in the device_object */
756
757 obj_desc->device.gpe_block = gpe_block;
758
759 /* Enable the runtime GPEs in the new block */
760
761 status = acpi_ev_initialize_gpe_block(node, gpe_block);
762
763 unlock_and_exit:
764 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
765 return_ACPI_STATUS(status);
766 }
767
768 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
769
770 /*******************************************************************************
771 *
772 * FUNCTION: acpi_remove_gpe_block
773 *
774 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
775 *
776 * RETURN: Status
777 *
778 * DESCRIPTION: Remove a previously installed block of GPE registers
779 *
780 ******************************************************************************/
781 acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
782 {
783 union acpi_operand_object *obj_desc;
784 acpi_status status;
785 struct acpi_namespace_node *node;
786
787 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
788
789 if (!gpe_device) {
790 return_ACPI_STATUS(AE_BAD_PARAMETER);
791 }
792
793 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
794 if (ACPI_FAILURE(status)) {
795 return (status);
796 }
797
798 node = acpi_ns_validate_handle(gpe_device);
799 if (!node) {
800 status = AE_BAD_PARAMETER;
801 goto unlock_and_exit;
802 }
803
804 /* Get the device_object attached to the node */
805
806 obj_desc = acpi_ns_get_attached_object(node);
807 if (!obj_desc || !obj_desc->device.gpe_block) {
808 return_ACPI_STATUS(AE_NULL_OBJECT);
809 }
810
811 /* Delete the GPE block (but not the device_object) */
812
813 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
814 if (ACPI_SUCCESS(status)) {
815 obj_desc->device.gpe_block = NULL;
816 }
817
818 unlock_and_exit:
819 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
820 return_ACPI_STATUS(status);
821 }
822
823 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
824
825 /*******************************************************************************
826 *
827 * FUNCTION: acpi_get_gpe_device
828 *
829 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
830 * gpe_device - Where the parent GPE Device is returned
831 *
832 * RETURN: Status
833 *
834 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
835 * gpe device indicates that the gpe number is contained in one of
836 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
837 *
838 ******************************************************************************/
839 acpi_status
840 acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
841 {
842 struct acpi_gpe_device_info info;
843 acpi_status status;
844
845 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
846
847 if (!gpe_device) {
848 return_ACPI_STATUS(AE_BAD_PARAMETER);
849 }
850
851 if (index >= acpi_current_gpe_count) {
852 return_ACPI_STATUS(AE_NOT_EXIST);
853 }
854
855 /* Setup and walk the GPE list */
856
857 info.index = index;
858 info.status = AE_NOT_EXIST;
859 info.gpe_device = NULL;
860 info.next_block_base_index = 0;
861
862 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
863 if (ACPI_FAILURE(status)) {
864 return_ACPI_STATUS(status);
865 }
866
867 *gpe_device = info.gpe_device;
868 return_ACPI_STATUS(info.status);
869 }
870
871 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
872
873 /*******************************************************************************
874 *
875 * FUNCTION: acpi_ev_get_gpe_device
876 *
877 * PARAMETERS: GPE_WALK_CALLBACK
878 *
879 * RETURN: Status
880 *
881 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
882 * block device. NULL if the GPE is one of the FADT-defined GPEs.
883 *
884 ******************************************************************************/
885 static acpi_status
886 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
887 struct acpi_gpe_block_info *gpe_block, void *context)
888 {
889 struct acpi_gpe_device_info *info = context;
890
891 /* Increment Index by the number of GPEs in this block */
892
893 info->next_block_base_index += gpe_block->gpe_count;
894
895 if (info->index < info->next_block_base_index) {
896 /*
897 * The GPE index is within this block, get the node. Leave the node
898 * NULL for the FADT-defined GPEs
899 */
900 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
901 info->gpe_device = gpe_block->node;
902 }
903
904 info->status = AE_OK;
905 return (AE_CTRL_END);
906 }
907
908 return (AE_OK);
909 }
910
911 /******************************************************************************
912 *
913 * FUNCTION: acpi_disable_all_gpes
914 *
915 * PARAMETERS: None
916 *
917 * RETURN: Status
918 *
919 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
920 *
921 ******************************************************************************/
922
923 acpi_status acpi_disable_all_gpes(void)
924 {
925 acpi_status status;
926
927 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
928
929 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
930 if (ACPI_FAILURE(status)) {
931 return_ACPI_STATUS(status);
932 }
933
934 status = acpi_hw_disable_all_gpes();
935 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
936
937 return_ACPI_STATUS(status);
938 }
939
940 /******************************************************************************
941 *
942 * FUNCTION: acpi_enable_all_runtime_gpes
943 *
944 * PARAMETERS: None
945 *
946 * RETURN: Status
947 *
948 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
949 *
950 ******************************************************************************/
951
952 acpi_status acpi_enable_all_runtime_gpes(void)
953 {
954 acpi_status status;
955
956 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
957
958 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
959 if (ACPI_FAILURE(status)) {
960 return_ACPI_STATUS(status);
961 }
962
963 status = acpi_hw_enable_all_runtime_gpes();
964 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
965
966 return_ACPI_STATUS(status);
967 }