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