]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/acpi/events/evxfevnt.c
ACPI: ACPICA 20060217
[mirror_ubuntu-hirsute-kernel.git] / drivers / acpi / events / evxfevnt.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4 *
5 *****************************************************************************/
6
7/*
4a90c7e8 8 * Copyright (C) 2000 - 2006, R. Byron Moore
1da177e4
LT
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 <linux/module.h>
45
46#include <acpi/acpi.h>
47#include <acpi/acevents.h>
48#include <acpi/acnamesp.h>
49
50#define _COMPONENT ACPI_EVENTS
4be44fcd 51ACPI_MODULE_NAME("evxfevnt")
1da177e4
LT
52
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_enable
56 *
57 * PARAMETERS: None
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Transfers the system into ACPI mode.
62 *
63 ******************************************************************************/
4be44fcd 64acpi_status acpi_enable(void)
1da177e4 65{
4be44fcd 66 acpi_status status = AE_OK;
1da177e4 67
4be44fcd 68 ACPI_FUNCTION_TRACE("acpi_enable");
1da177e4 69
4be44fcd 70 /* Make sure we have the FADT */
1da177e4
LT
71
72 if (!acpi_gbl_FADT) {
b8e4d893 73 ACPI_WARNING((AE_INFO, "No FADT information present!"));
4be44fcd 74 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
1da177e4
LT
75 }
76
77 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
4be44fcd
LB
78 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
79 "System is already in ACPI mode\n"));
80 } else {
1da177e4
LT
81 /* Transition to ACPI mode */
82
4be44fcd
LB
83 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
84 if (ACPI_FAILURE(status)) {
b8e4d893
BM
85 ACPI_ERROR((AE_INFO,
86 "Could not transition to ACPI mode"));
4be44fcd 87 return_ACPI_STATUS(status);
1da177e4
LT
88 }
89
4be44fcd
LB
90 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
91 "Transition to ACPI mode successful\n"));
1da177e4
LT
92 }
93
4be44fcd 94 return_ACPI_STATUS(status);
1da177e4
LT
95}
96
1da177e4
LT
97/*******************************************************************************
98 *
99 * FUNCTION: acpi_disable
100 *
101 * PARAMETERS: None
102 *
103 * RETURN: Status
104 *
44f6c012 105 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
1da177e4
LT
106 *
107 ******************************************************************************/
108
4be44fcd 109acpi_status acpi_disable(void)
1da177e4 110{
4be44fcd 111 acpi_status status = AE_OK;
1da177e4 112
4be44fcd 113 ACPI_FUNCTION_TRACE("acpi_disable");
1da177e4
LT
114
115 if (!acpi_gbl_FADT) {
b8e4d893 116 ACPI_WARNING((AE_INFO, "No FADT information present!"));
4be44fcd 117 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
1da177e4
LT
118 }
119
120 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
4be44fcd
LB
121 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
122 "System is already in legacy (non-ACPI) mode\n"));
123 } else {
1da177e4
LT
124 /* Transition to LEGACY mode */
125
4be44fcd 126 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
1da177e4 127
4be44fcd 128 if (ACPI_FAILURE(status)) {
b8e4d893
BM
129 ACPI_ERROR((AE_INFO,
130 "Could not exit ACPI mode to legacy mode"));
4be44fcd 131 return_ACPI_STATUS(status);
1da177e4
LT
132 }
133
4be44fcd 134 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
1da177e4
LT
135 }
136
4be44fcd 137 return_ACPI_STATUS(status);
1da177e4
LT
138}
139
1da177e4
LT
140/*******************************************************************************
141 *
142 * FUNCTION: acpi_enable_event
143 *
144 * PARAMETERS: Event - The fixed eventto be enabled
145 * Flags - Reserved
146 *
147 * RETURN: Status
148 *
149 * DESCRIPTION: Enable an ACPI event (fixed)
150 *
151 ******************************************************************************/
152
4be44fcd 153acpi_status acpi_enable_event(u32 event, u32 flags)
1da177e4 154{
4be44fcd
LB
155 acpi_status status = AE_OK;
156 u32 value;
1da177e4 157
4be44fcd 158 ACPI_FUNCTION_TRACE("acpi_enable_event");
1da177e4
LT
159
160 /* Decode the Fixed Event */
161
162 if (event > ACPI_EVENT_MAX) {
4be44fcd 163 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
164 }
165
166 /*
167 * Enable the requested fixed event (by writing a one to the
168 * enable register bit)
169 */
4be44fcd
LB
170 status =
171 acpi_set_register(acpi_gbl_fixed_event_info[event].
172 enable_register_id, 1, ACPI_MTX_LOCK);
173 if (ACPI_FAILURE(status)) {
174 return_ACPI_STATUS(status);
1da177e4
LT
175 }
176
177 /* Make sure that the hardware responded */
178
4be44fcd
LB
179 status =
180 acpi_get_register(acpi_gbl_fixed_event_info[event].
181 enable_register_id, &value, ACPI_MTX_LOCK);
182 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status);
1da177e4
LT
184 }
185
186 if (value != 1) {
b8e4d893
BM
187 ACPI_ERROR((AE_INFO,
188 "Could not enable %s event",
189 acpi_ut_get_event_name(event)));
4be44fcd 190 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
191 }
192
4be44fcd 193 return_ACPI_STATUS(status);
1da177e4 194}
1da177e4 195
4be44fcd 196EXPORT_SYMBOL(acpi_enable_event);
1da177e4
LT
197
198/*******************************************************************************
199 *
200 * FUNCTION: acpi_set_gpe_type
201 *
202 * PARAMETERS: gpe_device - Parent GPE Device
203 * gpe_number - GPE level within the GPE block
204 * Type - New GPE type
205 *
206 * RETURN: Status
207 *
44f6c012 208 * DESCRIPTION: Set the type of an individual GPE
1da177e4
LT
209 *
210 ******************************************************************************/
211
4be44fcd 212acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
1da177e4 213{
4be44fcd
LB
214 acpi_status status = AE_OK;
215 struct acpi_gpe_event_info *gpe_event_info;
1da177e4 216
4be44fcd 217 ACPI_FUNCTION_TRACE("acpi_set_gpe_type");
1da177e4
LT
218
219 /* Ensure that we have a valid GPE number */
220
4be44fcd 221 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
1da177e4
LT
222 if (!gpe_event_info) {
223 status = AE_BAD_PARAMETER;
224 goto unlock_and_exit;
225 }
226
227 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
4be44fcd 228 return_ACPI_STATUS(AE_OK);
1da177e4
LT
229 }
230
231 /* Set the new type (will disable GPE if currently enabled) */
232
4be44fcd 233 status = acpi_ev_set_gpe_type(gpe_event_info, type);
1da177e4 234
4be44fcd
LB
235 unlock_and_exit:
236 return_ACPI_STATUS(status);
1da177e4 237}
1da177e4 238
4be44fcd 239EXPORT_SYMBOL(acpi_set_gpe_type);
1da177e4
LT
240
241/*******************************************************************************
242 *
243 * FUNCTION: acpi_enable_gpe
244 *
245 * PARAMETERS: gpe_device - Parent GPE Device
246 * gpe_number - GPE level within the GPE block
247 * Flags - Just enable, or also wake enable?
248 * Called from ISR or not
249 *
250 * RETURN: Status
251 *
252 * DESCRIPTION: Enable an ACPI event (general purpose)
253 *
254 ******************************************************************************/
255
4be44fcd 256acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
1da177e4 257{
4be44fcd
LB
258 acpi_status status = AE_OK;
259 struct acpi_gpe_event_info *gpe_event_info;
1da177e4 260
4be44fcd 261 ACPI_FUNCTION_TRACE("acpi_enable_gpe");
1da177e4
LT
262
263 /* Use semaphore lock if not executing at interrupt level */
264
265 if (flags & ACPI_NOT_ISR) {
4be44fcd
LB
266 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
267 if (ACPI_FAILURE(status)) {
268 return_ACPI_STATUS(status);
1da177e4
LT
269 }
270 }
271
272 /* Ensure that we have a valid GPE number */
273
4be44fcd 274 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
1da177e4
LT
275 if (!gpe_event_info) {
276 status = AE_BAD_PARAMETER;
277 goto unlock_and_exit;
278 }
279
280 /* Perform the enable */
281
4be44fcd 282 status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
1da177e4 283
4be44fcd 284 unlock_and_exit:
1da177e4 285 if (flags & ACPI_NOT_ISR) {
4be44fcd 286 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1da177e4 287 }
4be44fcd 288 return_ACPI_STATUS(status);
1da177e4 289}
1da177e4 290
4be44fcd 291EXPORT_SYMBOL(acpi_enable_gpe);
1da177e4
LT
292
293/*******************************************************************************
294 *
295 * FUNCTION: acpi_disable_gpe
296 *
297 * PARAMETERS: gpe_device - Parent GPE Device
298 * gpe_number - GPE level within the GPE block
299 * Flags - Just disable, or also wake disable?
300 * Called from ISR or not
301 *
302 * RETURN: Status
303 *
304 * DESCRIPTION: Disable an ACPI event (general purpose)
305 *
306 ******************************************************************************/
307
4be44fcd 308acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
1da177e4 309{
4be44fcd
LB
310 acpi_status status = AE_OK;
311 struct acpi_gpe_event_info *gpe_event_info;
1da177e4 312
4be44fcd 313 ACPI_FUNCTION_TRACE("acpi_disable_gpe");
1da177e4
LT
314
315 /* Use semaphore lock if not executing at interrupt level */
316
317 if (flags & ACPI_NOT_ISR) {
4be44fcd
LB
318 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
319 if (ACPI_FAILURE(status)) {
320 return_ACPI_STATUS(status);
1da177e4
LT
321 }
322 }
323
324 /* Ensure that we have a valid GPE number */
325
4be44fcd 326 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
1da177e4
LT
327 if (!gpe_event_info) {
328 status = AE_BAD_PARAMETER;
329 goto unlock_and_exit;
330 }
331
4be44fcd 332 status = acpi_ev_disable_gpe(gpe_event_info);
1da177e4 333
4be44fcd 334 unlock_and_exit:
1da177e4 335 if (flags & ACPI_NOT_ISR) {
4be44fcd 336 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1da177e4 337 }
4be44fcd 338 return_ACPI_STATUS(status);
1da177e4
LT
339}
340
1da177e4
LT
341/*******************************************************************************
342 *
343 * FUNCTION: acpi_disable_event
344 *
345 * PARAMETERS: Event - The fixed eventto be enabled
346 * Flags - Reserved
347 *
348 * RETURN: Status
349 *
350 * DESCRIPTION: Disable an ACPI event (fixed)
351 *
352 ******************************************************************************/
353
4be44fcd 354acpi_status acpi_disable_event(u32 event, u32 flags)
1da177e4 355{
4be44fcd
LB
356 acpi_status status = AE_OK;
357 u32 value;
1da177e4 358
4be44fcd 359 ACPI_FUNCTION_TRACE("acpi_disable_event");
1da177e4
LT
360
361 /* Decode the Fixed Event */
362
363 if (event > ACPI_EVENT_MAX) {
4be44fcd 364 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
365 }
366
367 /*
368 * Disable the requested fixed event (by writing a zero to the
369 * enable register bit)
370 */
4be44fcd
LB
371 status =
372 acpi_set_register(acpi_gbl_fixed_event_info[event].
373 enable_register_id, 0, ACPI_MTX_LOCK);
374 if (ACPI_FAILURE(status)) {
375 return_ACPI_STATUS(status);
1da177e4
LT
376 }
377
4be44fcd
LB
378 status =
379 acpi_get_register(acpi_gbl_fixed_event_info[event].
380 enable_register_id, &value, ACPI_MTX_LOCK);
381 if (ACPI_FAILURE(status)) {
382 return_ACPI_STATUS(status);
1da177e4
LT
383 }
384
385 if (value != 0) {
b8e4d893
BM
386 ACPI_ERROR((AE_INFO,
387 "Could not disable %s events",
388 acpi_ut_get_event_name(event)));
4be44fcd 389 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
390 }
391
4be44fcd 392 return_ACPI_STATUS(status);
1da177e4 393}
1da177e4 394
4be44fcd 395EXPORT_SYMBOL(acpi_disable_event);
1da177e4
LT
396
397/*******************************************************************************
398 *
399 * FUNCTION: acpi_clear_event
400 *
401 * PARAMETERS: Event - The fixed event to be cleared
402 *
403 * RETURN: Status
404 *
405 * DESCRIPTION: Clear an ACPI event (fixed)
406 *
407 ******************************************************************************/
408
4be44fcd 409acpi_status acpi_clear_event(u32 event)
1da177e4 410{
4be44fcd 411 acpi_status status = AE_OK;
1da177e4 412
4be44fcd 413 ACPI_FUNCTION_TRACE("acpi_clear_event");
1da177e4
LT
414
415 /* Decode the Fixed Event */
416
417 if (event > ACPI_EVENT_MAX) {
4be44fcd 418 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
419 }
420
421 /*
422 * Clear the requested fixed event (By writing a one to the
423 * status register bit)
424 */
4be44fcd
LB
425 status =
426 acpi_set_register(acpi_gbl_fixed_event_info[event].
427 status_register_id, 1, ACPI_MTX_LOCK);
1da177e4 428
4be44fcd 429 return_ACPI_STATUS(status);
1da177e4 430}
1da177e4 431
4be44fcd 432EXPORT_SYMBOL(acpi_clear_event);
1da177e4
LT
433
434/*******************************************************************************
435 *
436 * FUNCTION: acpi_clear_gpe
437 *
438 * PARAMETERS: gpe_device - Parent GPE Device
439 * gpe_number - GPE level within the GPE block
440 * Flags - Called from an ISR or not
441 *
442 * RETURN: Status
443 *
444 * DESCRIPTION: Clear an ACPI event (general purpose)
445 *
446 ******************************************************************************/
447
4be44fcd 448acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
1da177e4 449{
4be44fcd
LB
450 acpi_status status = AE_OK;
451 struct acpi_gpe_event_info *gpe_event_info;
1da177e4 452
4be44fcd 453 ACPI_FUNCTION_TRACE("acpi_clear_gpe");
1da177e4
LT
454
455 /* Use semaphore lock if not executing at interrupt level */
456
457 if (flags & ACPI_NOT_ISR) {
4be44fcd
LB
458 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
459 if (ACPI_FAILURE(status)) {
460 return_ACPI_STATUS(status);
1da177e4
LT
461 }
462 }
463
464 /* Ensure that we have a valid GPE number */
465
4be44fcd 466 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
1da177e4
LT
467 if (!gpe_event_info) {
468 status = AE_BAD_PARAMETER;
469 goto unlock_and_exit;
470 }
471
4be44fcd 472 status = acpi_hw_clear_gpe(gpe_event_info);
1da177e4 473
4be44fcd 474 unlock_and_exit:
1da177e4 475 if (flags & ACPI_NOT_ISR) {
4be44fcd 476 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1da177e4 477 }
4be44fcd 478 return_ACPI_STATUS(status);
1da177e4
LT
479}
480
1da177e4 481#ifdef ACPI_FUTURE_USAGE
1da177e4
LT
482/*******************************************************************************
483 *
484 * FUNCTION: acpi_get_event_status
485 *
486 * PARAMETERS: Event - The fixed event
44f6c012 487 * event_status - Where the current status of the event will
1da177e4
LT
488 * be returned
489 *
490 * RETURN: Status
491 *
492 * DESCRIPTION: Obtains and returns the current status of the event
493 *
494 ******************************************************************************/
495
4be44fcd 496acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
1da177e4 497{
4be44fcd 498 acpi_status status = AE_OK;
1da177e4 499
4be44fcd 500 ACPI_FUNCTION_TRACE("acpi_get_event_status");
1da177e4
LT
501
502 if (!event_status) {
4be44fcd 503 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
504 }
505
506 /* Decode the Fixed Event */
507
508 if (event > ACPI_EVENT_MAX) {
4be44fcd 509 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
510 }
511
512 /* Get the status of the requested fixed event */
513
4be44fcd
LB
514 status =
515 acpi_get_register(acpi_gbl_fixed_event_info[event].
516 status_register_id, event_status, ACPI_MTX_LOCK);
1da177e4 517
4be44fcd 518 return_ACPI_STATUS(status);
1da177e4
LT
519}
520
1da177e4
LT
521/*******************************************************************************
522 *
523 * FUNCTION: acpi_get_gpe_status
524 *
525 * PARAMETERS: gpe_device - Parent GPE Device
526 * gpe_number - GPE level within the GPE block
527 * Flags - Called from an ISR or not
44f6c012 528 * event_status - Where the current status of the event will
1da177e4
LT
529 * be returned
530 *
531 * RETURN: Status
532 *
533 * DESCRIPTION: Get status of an event (general purpose)
534 *
535 ******************************************************************************/
536
537acpi_status
4be44fcd
LB
538acpi_get_gpe_status(acpi_handle gpe_device,
539 u32 gpe_number, u32 flags, acpi_event_status * event_status)
1da177e4 540{
4be44fcd
LB
541 acpi_status status = AE_OK;
542 struct acpi_gpe_event_info *gpe_event_info;
1da177e4 543
4be44fcd 544 ACPI_FUNCTION_TRACE("acpi_get_gpe_status");
1da177e4
LT
545
546 /* Use semaphore lock if not executing at interrupt level */
547
548 if (flags & ACPI_NOT_ISR) {
4be44fcd
LB
549 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
550 if (ACPI_FAILURE(status)) {
551 return_ACPI_STATUS(status);
1da177e4
LT
552 }
553 }
554
555 /* Ensure that we have a valid GPE number */
556
4be44fcd 557 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
1da177e4
LT
558 if (!gpe_event_info) {
559 status = AE_BAD_PARAMETER;
560 goto unlock_and_exit;
561 }
562
563 /* Obtain status on the requested GPE number */
564
4be44fcd 565 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
1da177e4 566
4be44fcd 567 unlock_and_exit:
1da177e4 568 if (flags & ACPI_NOT_ISR) {
4be44fcd 569 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1da177e4 570 }
4be44fcd 571 return_ACPI_STATUS(status);
1da177e4 572}
4be44fcd 573#endif /* ACPI_FUTURE_USAGE */
1da177e4
LT
574
575/*******************************************************************************
576 *
577 * FUNCTION: acpi_install_gpe_block
578 *
579 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
580 * gpe_block_address - Address and space_iD
581 * register_count - Number of GPE register pairs in the block
6f42ccf2 582 * interrupt_number - H/W interrupt for the block
1da177e4
LT
583 *
584 * RETURN: Status
585 *
586 * DESCRIPTION: Create and Install a block of GPE registers
587 *
588 ******************************************************************************/
589
590acpi_status
4be44fcd
LB
591acpi_install_gpe_block(acpi_handle gpe_device,
592 struct acpi_generic_address *gpe_block_address,
593 u32 register_count, u32 interrupt_number)
1da177e4 594{
4be44fcd
LB
595 acpi_status status;
596 union acpi_operand_object *obj_desc;
597 struct acpi_namespace_node *node;
598 struct acpi_gpe_block_info *gpe_block;
1da177e4 599
4be44fcd 600 ACPI_FUNCTION_TRACE("acpi_install_gpe_block");
1da177e4 601
4be44fcd
LB
602 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
603 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
604 }
605
4be44fcd
LB
606 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
607 if (ACPI_FAILURE(status)) {
1da177e4
LT
608 return (status);
609 }
610
4be44fcd 611 node = acpi_ns_map_handle_to_node(gpe_device);
1da177e4
LT
612 if (!node) {
613 status = AE_BAD_PARAMETER;
614 goto unlock_and_exit;
615 }
616
617 /*
618 * For user-installed GPE Block Devices, the gpe_block_base_number
619 * is always zero
620 */
4be44fcd
LB
621 status =
622 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
623 interrupt_number, &gpe_block);
624 if (ACPI_FAILURE(status)) {
1da177e4
LT
625 goto unlock_and_exit;
626 }
627
96db255c
BM
628 /* Run the _PRW methods and enable the GPEs */
629
630 status = acpi_ev_initialize_gpe_block(node, gpe_block);
631 if (ACPI_FAILURE(status)) {
632 goto unlock_and_exit;
633 }
634
1da177e4
LT
635 /* Get the device_object attached to the node */
636
4be44fcd 637 obj_desc = acpi_ns_get_attached_object(node);
1da177e4 638 if (!obj_desc) {
52fc0b02 639
1da177e4
LT
640 /* No object, create a new one */
641
4be44fcd 642 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
1da177e4
LT
643 if (!obj_desc) {
644 status = AE_NO_MEMORY;
645 goto unlock_and_exit;
646 }
647
4be44fcd
LB
648 status =
649 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
1da177e4
LT
650
651 /* Remove local reference to the object */
652
4be44fcd 653 acpi_ut_remove_reference(obj_desc);
1da177e4 654
4be44fcd 655 if (ACPI_FAILURE(status)) {
1da177e4
LT
656 goto unlock_and_exit;
657 }
658 }
659
660 /* Install the GPE block in the device_object */
661
662 obj_desc->device.gpe_block = gpe_block;
663
4be44fcd
LB
664 unlock_and_exit:
665 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
666 return_ACPI_STATUS(status);
1da177e4 667}
1da177e4 668
4be44fcd 669EXPORT_SYMBOL(acpi_install_gpe_block);
1da177e4
LT
670
671/*******************************************************************************
672 *
673 * FUNCTION: acpi_remove_gpe_block
674 *
675 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
676 *
677 * RETURN: Status
678 *
679 * DESCRIPTION: Remove a previously installed block of GPE registers
680 *
681 ******************************************************************************/
682
4be44fcd 683acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
1da177e4 684{
4be44fcd
LB
685 union acpi_operand_object *obj_desc;
686 acpi_status status;
687 struct acpi_namespace_node *node;
1da177e4 688
4be44fcd 689 ACPI_FUNCTION_TRACE("acpi_remove_gpe_block");
1da177e4
LT
690
691 if (!gpe_device) {
4be44fcd 692 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
693 }
694
4be44fcd
LB
695 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
696 if (ACPI_FAILURE(status)) {
1da177e4
LT
697 return (status);
698 }
699
4be44fcd 700 node = acpi_ns_map_handle_to_node(gpe_device);
1da177e4
LT
701 if (!node) {
702 status = AE_BAD_PARAMETER;
703 goto unlock_and_exit;
704 }
705
706 /* Get the device_object attached to the node */
707
4be44fcd
LB
708 obj_desc = acpi_ns_get_attached_object(node);
709 if (!obj_desc || !obj_desc->device.gpe_block) {
710 return_ACPI_STATUS(AE_NULL_OBJECT);
1da177e4
LT
711 }
712
713 /* Delete the GPE block (but not the device_object) */
714
4be44fcd
LB
715 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
716 if (ACPI_SUCCESS(status)) {
1da177e4
LT
717 obj_desc->device.gpe_block = NULL;
718 }
719
4be44fcd
LB
720 unlock_and_exit:
721 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
722 return_ACPI_STATUS(status);
1da177e4 723}
44f6c012 724
1da177e4 725EXPORT_SYMBOL(acpi_remove_gpe_block);