]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/acpi/acpica/evxfevnt.c
d6a6d4a765926dff17da0b255bc3a9d4a49e7ae9
[linux-beck.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_clear_and_enable_gpe
214  *
215  * PARAMETERS:  gpe_event_info  - GPE to enable
216  *
217  * RETURN:      Status
218  *
219  * DESCRIPTION: Clear the given GPE from stale events and enable it.
220  *
221  ******************************************************************************/
222 static acpi_status
223 acpi_clear_and_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
224 {
225         acpi_status status;
226
227         /*
228          * We will only allow a GPE to be enabled if it has either an
229          * associated method (_Lxx/_Exx) or a handler. Otherwise, the
230          * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
231          * first time it fires.
232          */
233         if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
234                 return_ACPI_STATUS(AE_NO_HANDLER);
235         }
236
237         /* Clear the GPE (of stale events) */
238         status = acpi_hw_clear_gpe(gpe_event_info);
239         if (ACPI_FAILURE(status)) {
240                 return_ACPI_STATUS(status);
241         }
242
243         /* Enable the requested GPE */
244         status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
245
246         return_ACPI_STATUS(status);
247 }
248
249 /*******************************************************************************
250  *
251  * FUNCTION:    acpi_set_gpe
252  *
253  * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
254  *              gpe_number      - GPE level within the GPE block
255  *              action          - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
256  *
257  * RETURN:      Status
258  *
259  * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
260  *              the reference count mechanism used in the acpi_enable_gpe and
261  *              acpi_disable_gpe interfaces -- and should be used with care.
262  *
263  * Note: Typically used to disable a runtime GPE for short period of time,
264  * then re-enable it, without disturbing the existing reference counts. This
265  * is useful, for example, in the Embedded Controller (EC) driver.
266  *
267  ******************************************************************************/
268 acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
269 {
270         struct acpi_gpe_event_info *gpe_event_info;
271         acpi_status status;
272         acpi_cpu_flags flags;
273
274         ACPI_FUNCTION_TRACE(acpi_set_gpe);
275
276         flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
277
278         /* Ensure that we have a valid GPE number */
279
280         gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
281         if (!gpe_event_info) {
282                 status = AE_BAD_PARAMETER;
283                 goto unlock_and_exit;
284         }
285
286         /* Perform the action */
287
288         switch (action) {
289         case ACPI_GPE_ENABLE:
290                 status = acpi_clear_and_enable_gpe(gpe_event_info);
291                 break;
292
293         case ACPI_GPE_DISABLE:
294                 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
295                 break;
296
297         default:
298                 status = AE_BAD_PARAMETER;
299                 break;
300         }
301
302       unlock_and_exit:
303         acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
304         return_ACPI_STATUS(status);
305 }
306
307 ACPI_EXPORT_SYMBOL(acpi_set_gpe)
308
309 /*******************************************************************************
310  *
311  * FUNCTION:    acpi_gpe_wakeup
312  *
313  * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
314  *              gpe_number      - GPE level within the GPE block
315  *              Action          - Enable or Disable
316  *
317  * RETURN:      Status
318  *
319  * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
320  *
321  ******************************************************************************/
322 acpi_status acpi_gpe_wakeup(acpi_handle gpe_device, u32 gpe_number, u8 action)
323 {
324         acpi_status status = AE_OK;
325         struct acpi_gpe_event_info *gpe_event_info;
326         struct acpi_gpe_register_info *gpe_register_info;
327         acpi_cpu_flags flags;
328         u32 register_bit;
329
330         ACPI_FUNCTION_TRACE(acpi_gpe_wakeup);
331
332         flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
333
334         /* Ensure that we have a valid GPE number */
335
336         gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
337         if (!gpe_event_info) {
338                 status = AE_BAD_PARAMETER;
339                 goto unlock_and_exit;
340         }
341
342         gpe_register_info = gpe_event_info->register_info;
343         if (!gpe_register_info) {
344                 status = AE_NOT_EXIST;
345                 goto unlock_and_exit;
346         }
347
348         register_bit =
349             acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
350
351         /* Perform the action */
352
353         switch (action) {
354         case ACPI_GPE_ENABLE:
355                 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
356                 break;
357
358         case ACPI_GPE_DISABLE:
359                 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
360                                register_bit);
361                 break;
362
363         default:
364                 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
365                 status = AE_BAD_PARAMETER;
366                 break;
367         }
368
369 unlock_and_exit:
370         acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
371         return_ACPI_STATUS(status);
372 }
373
374 ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
375
376 /*******************************************************************************
377  *
378  * FUNCTION:    acpi_enable_gpe
379  *
380  * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
381  *              gpe_number      - GPE level within the GPE block
382  *              gpe_type        - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
383  *                                or both
384  *
385  * RETURN:      Status
386  *
387  * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
388  *              hardware-enabled (for runtime GPEs), or the GPE register mask
389  *              is updated (for wake GPEs).
390  *
391  ******************************************************************************/
392 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
393 {
394         acpi_status status = AE_OK;
395         struct acpi_gpe_event_info *gpe_event_info;
396         acpi_cpu_flags flags;
397
398         ACPI_FUNCTION_TRACE(acpi_enable_gpe);
399
400         /* Parameter validation */
401
402         if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
403                 return_ACPI_STATUS(AE_BAD_PARAMETER);
404         }
405
406         flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
407
408         /* Ensure that we have a valid GPE number */
409
410         gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
411         if (!gpe_event_info) {
412                 status = AE_BAD_PARAMETER;
413                 goto unlock_and_exit;
414         }
415
416         if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
417                 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
418                         status = AE_LIMIT;      /* Too many references */
419                         goto unlock_and_exit;
420                 }
421
422                 gpe_event_info->runtime_count++;
423                 if (gpe_event_info->runtime_count == 1) {
424                         status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
425                         if (ACPI_SUCCESS(status)) {
426                                 status = acpi_clear_and_enable_gpe(gpe_event_info);
427                         }
428
429                         if (ACPI_FAILURE(status)) {
430                                 gpe_event_info->runtime_count--;
431                                 goto unlock_and_exit;
432                         }
433                 }
434         }
435
436         if (gpe_type & ACPI_GPE_TYPE_WAKE) {
437                 /* The GPE must have the ability to wake the system */
438
439                 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
440                         status = AE_TYPE;
441                         goto unlock_and_exit;
442                 }
443
444                 if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
445                         status = AE_LIMIT;      /* Too many references */
446                         goto unlock_and_exit;
447                 }
448
449                 /*
450                  * Update the enable mask on the first wakeup reference. Wake GPEs
451                  * are only hardware-enabled just before sleeping.
452                  */
453                 gpe_event_info->wakeup_count++;
454                 if (gpe_event_info->wakeup_count == 1) {
455                         status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
456                 }
457         }
458
459 unlock_and_exit:
460         acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
461         return_ACPI_STATUS(status);
462 }
463 ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
464
465 /*******************************************************************************
466  *
467  * FUNCTION:    acpi_disable_gpe
468  *
469  * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
470  *              gpe_number      - GPE level within the GPE block
471  *              gpe_type        - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
472  *                                or both
473  *
474  * RETURN:      Status
475  *
476  * DESCRIPTION: Remove a reference to a GPE. When the last reference is
477  *              removed, only then is the GPE disabled (for runtime GPEs), or
478  *              the GPE mask bit disabled (for wake GPEs)
479  *
480  ******************************************************************************/
481 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
482 {
483         acpi_status status = AE_OK;
484         struct acpi_gpe_event_info *gpe_event_info;
485         acpi_cpu_flags flags;
486
487         ACPI_FUNCTION_TRACE(acpi_disable_gpe);
488
489         /* Parameter validation */
490
491         if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
492                 return_ACPI_STATUS(AE_BAD_PARAMETER);
493         }
494
495         flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
496
497         /* Ensure that we have a valid GPE number */
498
499         gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
500         if (!gpe_event_info) {
501                 status = AE_BAD_PARAMETER;
502                 goto unlock_and_exit;
503         }
504
505         /* Hardware-disable a runtime GPE on removal of the last reference */
506
507         if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
508                 if (!gpe_event_info->runtime_count) {
509                         status = AE_LIMIT;      /* There are no references to remove */
510                         goto unlock_and_exit;
511                 }
512
513                 gpe_event_info->runtime_count--;
514                 if (!gpe_event_info->runtime_count) {
515                         status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
516                         if (ACPI_SUCCESS(status)) {
517                                 status = acpi_hw_low_set_gpe(gpe_event_info,
518                                                              ACPI_GPE_DISABLE);
519                         }
520
521                         if (ACPI_FAILURE(status)) {
522                                 gpe_event_info->runtime_count++;
523                                 goto unlock_and_exit;
524                         }
525                 }
526         }
527
528         /*
529          * Update masks for wake GPE on removal of the last reference.
530          * No need to hardware-disable wake GPEs here, they are not currently
531          * enabled.
532          */
533         if (gpe_type & ACPI_GPE_TYPE_WAKE) {
534                 if (!gpe_event_info->wakeup_count) {
535                         status = AE_LIMIT;      /* There are no references to remove */
536                         goto unlock_and_exit;
537                 }
538
539                 gpe_event_info->wakeup_count--;
540                 if (!gpe_event_info->wakeup_count) {
541                         status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
542                 }
543         }
544
545 unlock_and_exit:
546         acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
547         return_ACPI_STATUS(status);
548 }
549 ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
550
551 /*******************************************************************************
552  *
553  * FUNCTION:    acpi_disable_event
554  *
555  * PARAMETERS:  Event           - The fixed eventto be enabled
556  *              Flags           - Reserved
557  *
558  * RETURN:      Status
559  *
560  * DESCRIPTION: Disable an ACPI event (fixed)
561  *
562  ******************************************************************************/
563 acpi_status acpi_disable_event(u32 event, u32 flags)
564 {
565         acpi_status status = AE_OK;
566         u32 value;
567
568         ACPI_FUNCTION_TRACE(acpi_disable_event);
569
570         /* Decode the Fixed Event */
571
572         if (event > ACPI_EVENT_MAX) {
573                 return_ACPI_STATUS(AE_BAD_PARAMETER);
574         }
575
576         /*
577          * Disable the requested fixed event (by writing a zero to the enable
578          * register bit)
579          */
580         status =
581             acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
582                                     enable_register_id, ACPI_DISABLE_EVENT);
583         if (ACPI_FAILURE(status)) {
584                 return_ACPI_STATUS(status);
585         }
586
587         status =
588             acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
589                                    enable_register_id, &value);
590         if (ACPI_FAILURE(status)) {
591                 return_ACPI_STATUS(status);
592         }
593
594         if (value != 0) {
595                 ACPI_ERROR((AE_INFO,
596                             "Could not disable %s events",
597                             acpi_ut_get_event_name(event)));
598                 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
599         }
600
601         return_ACPI_STATUS(status);
602 }
603
604 ACPI_EXPORT_SYMBOL(acpi_disable_event)
605
606 /*******************************************************************************
607  *
608  * FUNCTION:    acpi_clear_event
609  *
610  * PARAMETERS:  Event           - The fixed event to be cleared
611  *
612  * RETURN:      Status
613  *
614  * DESCRIPTION: Clear an ACPI event (fixed)
615  *
616  ******************************************************************************/
617 acpi_status acpi_clear_event(u32 event)
618 {
619         acpi_status status = AE_OK;
620
621         ACPI_FUNCTION_TRACE(acpi_clear_event);
622
623         /* Decode the Fixed Event */
624
625         if (event > ACPI_EVENT_MAX) {
626                 return_ACPI_STATUS(AE_BAD_PARAMETER);
627         }
628
629         /*
630          * Clear the requested fixed event (By writing a one to the status
631          * register bit)
632          */
633         status =
634             acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
635                                     status_register_id, ACPI_CLEAR_STATUS);
636
637         return_ACPI_STATUS(status);
638 }
639
640 ACPI_EXPORT_SYMBOL(acpi_clear_event)
641
642 /*******************************************************************************
643  *
644  * FUNCTION:    acpi_clear_gpe
645  *
646  * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
647  *              gpe_number      - GPE level within the GPE block
648  *
649  * RETURN:      Status
650  *
651  * DESCRIPTION: Clear an ACPI event (general purpose)
652  *
653  ******************************************************************************/
654 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
655 {
656         acpi_status status = AE_OK;
657         struct acpi_gpe_event_info *gpe_event_info;
658         acpi_cpu_flags flags;
659
660         ACPI_FUNCTION_TRACE(acpi_clear_gpe);
661
662         flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
663
664         /* Ensure that we have a valid GPE number */
665
666         gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
667         if (!gpe_event_info) {
668                 status = AE_BAD_PARAMETER;
669                 goto unlock_and_exit;
670         }
671
672         status = acpi_hw_clear_gpe(gpe_event_info);
673
674       unlock_and_exit:
675         acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
676         return_ACPI_STATUS(status);
677 }
678
679 ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
680 /*******************************************************************************
681  *
682  * FUNCTION:    acpi_get_event_status
683  *
684  * PARAMETERS:  Event           - The fixed event
685  *              event_status    - Where the current status of the event will
686  *                                be returned
687  *
688  * RETURN:      Status
689  *
690  * DESCRIPTION: Obtains and returns the current status of the event
691  *
692  ******************************************************************************/
693 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
694 {
695         acpi_status status = AE_OK;
696         u32 value;
697
698         ACPI_FUNCTION_TRACE(acpi_get_event_status);
699
700         if (!event_status) {
701                 return_ACPI_STATUS(AE_BAD_PARAMETER);
702         }
703
704         /* Decode the Fixed Event */
705
706         if (event > ACPI_EVENT_MAX) {
707                 return_ACPI_STATUS(AE_BAD_PARAMETER);
708         }
709
710         /* Get the status of the requested fixed event */
711
712         status =
713             acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
714                               enable_register_id, &value);
715         if (ACPI_FAILURE(status))
716                 return_ACPI_STATUS(status);
717
718         *event_status = value;
719
720         status =
721             acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
722                               status_register_id, &value);
723         if (ACPI_FAILURE(status))
724                 return_ACPI_STATUS(status);
725
726         if (value)
727                 *event_status |= ACPI_EVENT_FLAG_SET;
728
729         if (acpi_gbl_fixed_event_handlers[event].handler)
730                 *event_status |= ACPI_EVENT_FLAG_HANDLE;
731
732         return_ACPI_STATUS(status);
733 }
734
735 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
736
737 /*******************************************************************************
738  *
739  * FUNCTION:    acpi_get_gpe_status
740  *
741  * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
742  *              gpe_number      - GPE level within the GPE block
743  *              event_status    - Where the current status of the event will
744  *                                be returned
745  *
746  * RETURN:      Status
747  *
748  * DESCRIPTION: Get status of an event (general purpose)
749  *
750  ******************************************************************************/
751 acpi_status
752 acpi_get_gpe_status(acpi_handle gpe_device,
753                     u32 gpe_number, acpi_event_status *event_status)
754 {
755         acpi_status status = AE_OK;
756         struct acpi_gpe_event_info *gpe_event_info;
757         acpi_cpu_flags flags;
758
759         ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
760
761         flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
762
763         /* Ensure that we have a valid GPE number */
764
765         gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
766         if (!gpe_event_info) {
767                 status = AE_BAD_PARAMETER;
768                 goto unlock_and_exit;
769         }
770
771         /* Obtain status on the requested GPE number */
772
773         status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
774
775         if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
776                 *event_status |= ACPI_EVENT_FLAG_HANDLE;
777
778       unlock_and_exit:
779         acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
780         return_ACPI_STATUS(status);
781 }
782
783 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
784 /*******************************************************************************
785  *
786  * FUNCTION:    acpi_install_gpe_block
787  *
788  * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
789  *              gpe_block_address   - Address and space_iD
790  *              register_count      - Number of GPE register pairs in the block
791  *              interrupt_number    - H/W interrupt for the block
792  *
793  * RETURN:      Status
794  *
795  * DESCRIPTION: Create and Install a block of GPE registers
796  *
797  ******************************************************************************/
798 acpi_status
799 acpi_install_gpe_block(acpi_handle gpe_device,
800                        struct acpi_generic_address *gpe_block_address,
801                        u32 register_count, u32 interrupt_number)
802 {
803         acpi_status status;
804         union acpi_operand_object *obj_desc;
805         struct acpi_namespace_node *node;
806         struct acpi_gpe_block_info *gpe_block;
807
808         ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
809
810         if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
811                 return_ACPI_STATUS(AE_BAD_PARAMETER);
812         }
813
814         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
815         if (ACPI_FAILURE(status)) {
816                 return (status);
817         }
818
819         node = acpi_ns_validate_handle(gpe_device);
820         if (!node) {
821                 status = AE_BAD_PARAMETER;
822                 goto unlock_and_exit;
823         }
824
825         /*
826          * For user-installed GPE Block Devices, the gpe_block_base_number
827          * is always zero
828          */
829         status =
830             acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
831                                      interrupt_number, &gpe_block);
832         if (ACPI_FAILURE(status)) {
833                 goto unlock_and_exit;
834         }
835
836         /* Install block in the device_object attached to the node */
837
838         obj_desc = acpi_ns_get_attached_object(node);
839         if (!obj_desc) {
840
841                 /*
842                  * No object, create a new one (Device nodes do not always have
843                  * an attached object)
844                  */
845                 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
846                 if (!obj_desc) {
847                         status = AE_NO_MEMORY;
848                         goto unlock_and_exit;
849                 }
850
851                 status =
852                     acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
853
854                 /* Remove local reference to the object */
855
856                 acpi_ut_remove_reference(obj_desc);
857
858                 if (ACPI_FAILURE(status)) {
859                         goto unlock_and_exit;
860                 }
861         }
862
863         /* Now install the GPE block in the device_object */
864
865         obj_desc->device.gpe_block = gpe_block;
866
867         /* Run the _PRW methods and enable the runtime GPEs in the new block */
868
869         status = acpi_ev_initialize_gpe_block(node, gpe_block);
870
871       unlock_and_exit:
872         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
873         return_ACPI_STATUS(status);
874 }
875
876 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
877
878 /*******************************************************************************
879  *
880  * FUNCTION:    acpi_remove_gpe_block
881  *
882  * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
883  *
884  * RETURN:      Status
885  *
886  * DESCRIPTION: Remove a previously installed block of GPE registers
887  *
888  ******************************************************************************/
889 acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
890 {
891         union acpi_operand_object *obj_desc;
892         acpi_status status;
893         struct acpi_namespace_node *node;
894
895         ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
896
897         if (!gpe_device) {
898                 return_ACPI_STATUS(AE_BAD_PARAMETER);
899         }
900
901         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
902         if (ACPI_FAILURE(status)) {
903                 return (status);
904         }
905
906         node = acpi_ns_validate_handle(gpe_device);
907         if (!node) {
908                 status = AE_BAD_PARAMETER;
909                 goto unlock_and_exit;
910         }
911
912         /* Get the device_object attached to the node */
913
914         obj_desc = acpi_ns_get_attached_object(node);
915         if (!obj_desc || !obj_desc->device.gpe_block) {
916                 return_ACPI_STATUS(AE_NULL_OBJECT);
917         }
918
919         /* Delete the GPE block (but not the device_object) */
920
921         status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
922         if (ACPI_SUCCESS(status)) {
923                 obj_desc->device.gpe_block = NULL;
924         }
925
926       unlock_and_exit:
927         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
928         return_ACPI_STATUS(status);
929 }
930
931 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
932
933 /*******************************************************************************
934  *
935  * FUNCTION:    acpi_get_gpe_device
936  *
937  * PARAMETERS:  Index               - System GPE index (0-current_gpe_count)
938  *              gpe_device          - Where the parent GPE Device is returned
939  *
940  * RETURN:      Status
941  *
942  * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
943  *              gpe device indicates that the gpe number is contained in one of
944  *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
945  *
946  ******************************************************************************/
947 acpi_status
948 acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
949 {
950         struct acpi_gpe_device_info info;
951         acpi_status status;
952
953         ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
954
955         if (!gpe_device) {
956                 return_ACPI_STATUS(AE_BAD_PARAMETER);
957         }
958
959         if (index >= acpi_current_gpe_count) {
960                 return_ACPI_STATUS(AE_NOT_EXIST);
961         }
962
963         /* Setup and walk the GPE list */
964
965         info.index = index;
966         info.status = AE_NOT_EXIST;
967         info.gpe_device = NULL;
968         info.next_block_base_index = 0;
969
970         status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
971         if (ACPI_FAILURE(status)) {
972                 return_ACPI_STATUS(status);
973         }
974
975         *gpe_device = info.gpe_device;
976         return_ACPI_STATUS(info.status);
977 }
978
979 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
980
981 /*******************************************************************************
982  *
983  * FUNCTION:    acpi_ev_get_gpe_device
984  *
985  * PARAMETERS:  GPE_WALK_CALLBACK
986  *
987  * RETURN:      Status
988  *
989  * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
990  *              block device. NULL if the GPE is one of the FADT-defined GPEs.
991  *
992  ******************************************************************************/
993 static acpi_status
994 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
995                        struct acpi_gpe_block_info *gpe_block, void *context)
996 {
997         struct acpi_gpe_device_info *info = context;
998
999         /* Increment Index by the number of GPEs in this block */
1000
1001         info->next_block_base_index += gpe_block->gpe_count;
1002
1003         if (info->index < info->next_block_base_index) {
1004                 /*
1005                  * The GPE index is within this block, get the node. Leave the node
1006                  * NULL for the FADT-defined GPEs
1007                  */
1008                 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
1009                         info->gpe_device = gpe_block->node;
1010                 }
1011
1012                 info->status = AE_OK;
1013                 return (AE_CTRL_END);
1014         }
1015
1016         return (AE_OK);
1017 }
1018
1019 /******************************************************************************
1020  *
1021  * FUNCTION:    acpi_disable_all_gpes
1022  *
1023  * PARAMETERS:  None
1024  *
1025  * RETURN:      Status
1026  *
1027  * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
1028  *
1029  ******************************************************************************/
1030
1031 acpi_status acpi_disable_all_gpes(void)
1032 {
1033         acpi_status status;
1034
1035         ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
1036
1037         status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1038         if (ACPI_FAILURE(status)) {
1039                 return_ACPI_STATUS(status);
1040         }
1041
1042         status = acpi_hw_disable_all_gpes();
1043         (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1044
1045         return_ACPI_STATUS(status);
1046 }
1047
1048 /******************************************************************************
1049  *
1050  * FUNCTION:    acpi_enable_all_runtime_gpes
1051  *
1052  * PARAMETERS:  None
1053  *
1054  * RETURN:      Status
1055  *
1056  * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
1057  *
1058  ******************************************************************************/
1059
1060 acpi_status acpi_enable_all_runtime_gpes(void)
1061 {
1062         acpi_status status;
1063
1064         ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
1065
1066         status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1067         if (ACPI_FAILURE(status)) {
1068                 return_ACPI_STATUS(status);
1069         }
1070
1071         status = acpi_hw_enable_all_runtime_gpes();
1072         (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1073
1074         return_ACPI_STATUS(status);
1075 }