[SCSI] convert ch to use scsi_execute_req
[linux-2.6/suspend2-2.6.18.git] / drivers / acpi / events / evxfevnt.c
blobf337dc2cc56984db838a5b490194aa52082b5a71
1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
44 #include <linux/module.h>
46 #include <acpi/acpi.h>
47 #include <acpi/acevents.h>
48 #include <acpi/acnamesp.h>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME ("evxfevnt")
54 /*******************************************************************************
56 * FUNCTION: acpi_enable
58 * PARAMETERS: None
60 * RETURN: Status
62 * DESCRIPTION: Transfers the system into ACPI mode.
64 ******************************************************************************/
66 acpi_status
67 acpi_enable (
68 void)
70 acpi_status status = AE_OK;
73 ACPI_FUNCTION_TRACE ("acpi_enable");
76 /* Make sure we have the FADT*/
78 if (!acpi_gbl_FADT) {
79 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
80 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
83 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
84 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
86 else {
87 /* Transition to ACPI mode */
89 status = acpi_hw_set_mode (ACPI_SYS_MODE_ACPI);
90 if (ACPI_FAILURE (status)) {
91 ACPI_REPORT_ERROR (("Could not transition to ACPI mode.\n"));
92 return_ACPI_STATUS (status);
95 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
96 "Transition to ACPI mode successful\n"));
99 return_ACPI_STATUS (status);
103 /*******************************************************************************
105 * FUNCTION: acpi_disable
107 * PARAMETERS: None
109 * RETURN: Status
111 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
113 ******************************************************************************/
115 acpi_status
116 acpi_disable (
117 void)
119 acpi_status status = AE_OK;
122 ACPI_FUNCTION_TRACE ("acpi_disable");
125 if (!acpi_gbl_FADT) {
126 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
127 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
130 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
131 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
132 "System is already in legacy (non-ACPI) mode\n"));
134 else {
135 /* Transition to LEGACY mode */
137 status = acpi_hw_set_mode (ACPI_SYS_MODE_LEGACY);
139 if (ACPI_FAILURE (status)) {
140 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
141 "Could not exit ACPI mode to legacy mode"));
142 return_ACPI_STATUS (status);
145 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
148 return_ACPI_STATUS (status);
152 /*******************************************************************************
154 * FUNCTION: acpi_enable_event
156 * PARAMETERS: Event - The fixed eventto be enabled
157 * Flags - Reserved
159 * RETURN: Status
161 * DESCRIPTION: Enable an ACPI event (fixed)
163 ******************************************************************************/
165 acpi_status
166 acpi_enable_event (
167 u32 event,
168 u32 flags)
170 acpi_status status = AE_OK;
171 u32 value;
174 ACPI_FUNCTION_TRACE ("acpi_enable_event");
177 /* Decode the Fixed Event */
179 if (event > ACPI_EVENT_MAX) {
180 return_ACPI_STATUS (AE_BAD_PARAMETER);
184 * Enable the requested fixed event (by writing a one to the
185 * enable register bit)
187 status = acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id,
188 1, ACPI_MTX_LOCK);
189 if (ACPI_FAILURE (status)) {
190 return_ACPI_STATUS (status);
193 /* Make sure that the hardware responded */
195 status = acpi_get_register (acpi_gbl_fixed_event_info[event].enable_register_id,
196 &value, ACPI_MTX_LOCK);
197 if (ACPI_FAILURE (status)) {
198 return_ACPI_STATUS (status);
201 if (value != 1) {
202 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
203 "Could not enable %s event\n", acpi_ut_get_event_name (event)));
204 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
207 return_ACPI_STATUS (status);
209 EXPORT_SYMBOL(acpi_enable_event);
212 /*******************************************************************************
214 * FUNCTION: acpi_set_gpe_type
216 * PARAMETERS: gpe_device - Parent GPE Device
217 * gpe_number - GPE level within the GPE block
218 * Type - New GPE type
220 * RETURN: Status
222 * DESCRIPTION: Set the type of an individual GPE
224 ******************************************************************************/
226 acpi_status
227 acpi_set_gpe_type (
228 acpi_handle gpe_device,
229 u32 gpe_number,
230 u8 type)
232 acpi_status status = AE_OK;
233 struct acpi_gpe_event_info *gpe_event_info;
236 ACPI_FUNCTION_TRACE ("acpi_set_gpe_type");
239 /* Ensure that we have a valid GPE number */
241 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
242 if (!gpe_event_info) {
243 status = AE_BAD_PARAMETER;
244 goto unlock_and_exit;
247 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
248 return_ACPI_STATUS (AE_OK);
251 /* Set the new type (will disable GPE if currently enabled) */
253 status = acpi_ev_set_gpe_type (gpe_event_info, type);
255 unlock_and_exit:
256 return_ACPI_STATUS (status);
258 EXPORT_SYMBOL(acpi_set_gpe_type);
261 /*******************************************************************************
263 * FUNCTION: acpi_enable_gpe
265 * PARAMETERS: gpe_device - Parent GPE Device
266 * gpe_number - GPE level within the GPE block
267 * Flags - Just enable, or also wake enable?
268 * Called from ISR or not
270 * RETURN: Status
272 * DESCRIPTION: Enable an ACPI event (general purpose)
274 ******************************************************************************/
276 acpi_status
277 acpi_enable_gpe (
278 acpi_handle gpe_device,
279 u32 gpe_number,
280 u32 flags)
282 acpi_status status = AE_OK;
283 struct acpi_gpe_event_info *gpe_event_info;
286 ACPI_FUNCTION_TRACE ("acpi_enable_gpe");
289 /* Use semaphore lock if not executing at interrupt level */
291 if (flags & ACPI_NOT_ISR) {
292 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
293 if (ACPI_FAILURE (status)) {
294 return_ACPI_STATUS (status);
298 /* Ensure that we have a valid GPE number */
300 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
301 if (!gpe_event_info) {
302 status = AE_BAD_PARAMETER;
303 goto unlock_and_exit;
306 /* Perform the enable */
308 status = acpi_ev_enable_gpe (gpe_event_info, TRUE);
310 unlock_and_exit:
311 if (flags & ACPI_NOT_ISR) {
312 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
314 return_ACPI_STATUS (status);
316 EXPORT_SYMBOL(acpi_enable_gpe);
319 /*******************************************************************************
321 * FUNCTION: acpi_disable_gpe
323 * PARAMETERS: gpe_device - Parent GPE Device
324 * gpe_number - GPE level within the GPE block
325 * Flags - Just disable, or also wake disable?
326 * Called from ISR or not
328 * RETURN: Status
330 * DESCRIPTION: Disable an ACPI event (general purpose)
332 ******************************************************************************/
334 acpi_status
335 acpi_disable_gpe (
336 acpi_handle gpe_device,
337 u32 gpe_number,
338 u32 flags)
340 acpi_status status = AE_OK;
341 struct acpi_gpe_event_info *gpe_event_info;
344 ACPI_FUNCTION_TRACE ("acpi_disable_gpe");
347 /* Use semaphore lock if not executing at interrupt level */
349 if (flags & ACPI_NOT_ISR) {
350 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
351 if (ACPI_FAILURE (status)) {
352 return_ACPI_STATUS (status);
356 /* Ensure that we have a valid GPE number */
358 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
359 if (!gpe_event_info) {
360 status = AE_BAD_PARAMETER;
361 goto unlock_and_exit;
364 status = acpi_ev_disable_gpe (gpe_event_info);
366 unlock_and_exit:
367 if (flags & ACPI_NOT_ISR) {
368 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
370 return_ACPI_STATUS (status);
374 /*******************************************************************************
376 * FUNCTION: acpi_disable_event
378 * PARAMETERS: Event - The fixed eventto be enabled
379 * Flags - Reserved
381 * RETURN: Status
383 * DESCRIPTION: Disable an ACPI event (fixed)
385 ******************************************************************************/
387 acpi_status
388 acpi_disable_event (
389 u32 event,
390 u32 flags)
392 acpi_status status = AE_OK;
393 u32 value;
396 ACPI_FUNCTION_TRACE ("acpi_disable_event");
399 /* Decode the Fixed Event */
401 if (event > ACPI_EVENT_MAX) {
402 return_ACPI_STATUS (AE_BAD_PARAMETER);
406 * Disable the requested fixed event (by writing a zero to the
407 * enable register bit)
409 status = acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id,
410 0, ACPI_MTX_LOCK);
411 if (ACPI_FAILURE (status)) {
412 return_ACPI_STATUS (status);
415 status = acpi_get_register (acpi_gbl_fixed_event_info[event].enable_register_id,
416 &value, ACPI_MTX_LOCK);
417 if (ACPI_FAILURE (status)) {
418 return_ACPI_STATUS (status);
421 if (value != 0) {
422 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
423 "Could not disable %s events\n", acpi_ut_get_event_name (event)));
424 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
427 return_ACPI_STATUS (status);
429 EXPORT_SYMBOL(acpi_disable_event);
432 /*******************************************************************************
434 * FUNCTION: acpi_clear_event
436 * PARAMETERS: Event - The fixed event to be cleared
438 * RETURN: Status
440 * DESCRIPTION: Clear an ACPI event (fixed)
442 ******************************************************************************/
444 acpi_status
445 acpi_clear_event (
446 u32 event)
448 acpi_status status = AE_OK;
451 ACPI_FUNCTION_TRACE ("acpi_clear_event");
454 /* Decode the Fixed Event */
456 if (event > ACPI_EVENT_MAX) {
457 return_ACPI_STATUS (AE_BAD_PARAMETER);
461 * Clear the requested fixed event (By writing a one to the
462 * status register bit)
464 status = acpi_set_register (acpi_gbl_fixed_event_info[event].status_register_id,
465 1, ACPI_MTX_LOCK);
467 return_ACPI_STATUS (status);
469 EXPORT_SYMBOL(acpi_clear_event);
472 /*******************************************************************************
474 * FUNCTION: acpi_clear_gpe
476 * PARAMETERS: gpe_device - Parent GPE Device
477 * gpe_number - GPE level within the GPE block
478 * Flags - Called from an ISR or not
480 * RETURN: Status
482 * DESCRIPTION: Clear an ACPI event (general purpose)
484 ******************************************************************************/
486 acpi_status
487 acpi_clear_gpe (
488 acpi_handle gpe_device,
489 u32 gpe_number,
490 u32 flags)
492 acpi_status status = AE_OK;
493 struct acpi_gpe_event_info *gpe_event_info;
496 ACPI_FUNCTION_TRACE ("acpi_clear_gpe");
499 /* Use semaphore lock if not executing at interrupt level */
501 if (flags & ACPI_NOT_ISR) {
502 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
503 if (ACPI_FAILURE (status)) {
504 return_ACPI_STATUS (status);
508 /* Ensure that we have a valid GPE number */
510 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
511 if (!gpe_event_info) {
512 status = AE_BAD_PARAMETER;
513 goto unlock_and_exit;
516 status = acpi_hw_clear_gpe (gpe_event_info);
518 unlock_and_exit:
519 if (flags & ACPI_NOT_ISR) {
520 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
522 return_ACPI_STATUS (status);
526 #ifdef ACPI_FUTURE_USAGE
527 /*******************************************************************************
529 * FUNCTION: acpi_get_event_status
531 * PARAMETERS: Event - The fixed event
532 * event_status - Where the current status of the event will
533 * be returned
535 * RETURN: Status
537 * DESCRIPTION: Obtains and returns the current status of the event
539 ******************************************************************************/
541 acpi_status
542 acpi_get_event_status (
543 u32 event,
544 acpi_event_status *event_status)
546 acpi_status status = AE_OK;
549 ACPI_FUNCTION_TRACE ("acpi_get_event_status");
552 if (!event_status) {
553 return_ACPI_STATUS (AE_BAD_PARAMETER);
556 /* Decode the Fixed Event */
558 if (event > ACPI_EVENT_MAX) {
559 return_ACPI_STATUS (AE_BAD_PARAMETER);
562 /* Get the status of the requested fixed event */
564 status = acpi_get_register (acpi_gbl_fixed_event_info[event].status_register_id,
565 event_status, ACPI_MTX_LOCK);
567 return_ACPI_STATUS (status);
571 /*******************************************************************************
573 * FUNCTION: acpi_get_gpe_status
575 * PARAMETERS: gpe_device - Parent GPE Device
576 * gpe_number - GPE level within the GPE block
577 * Flags - Called from an ISR or not
578 * event_status - Where the current status of the event will
579 * be returned
581 * RETURN: Status
583 * DESCRIPTION: Get status of an event (general purpose)
585 ******************************************************************************/
587 acpi_status
588 acpi_get_gpe_status (
589 acpi_handle gpe_device,
590 u32 gpe_number,
591 u32 flags,
592 acpi_event_status *event_status)
594 acpi_status status = AE_OK;
595 struct acpi_gpe_event_info *gpe_event_info;
598 ACPI_FUNCTION_TRACE ("acpi_get_gpe_status");
601 /* Use semaphore lock if not executing at interrupt level */
603 if (flags & ACPI_NOT_ISR) {
604 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
605 if (ACPI_FAILURE (status)) {
606 return_ACPI_STATUS (status);
610 /* Ensure that we have a valid GPE number */
612 gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number);
613 if (!gpe_event_info) {
614 status = AE_BAD_PARAMETER;
615 goto unlock_and_exit;
618 /* Obtain status on the requested GPE number */
620 status = acpi_hw_get_gpe_status (gpe_event_info, event_status);
622 unlock_and_exit:
623 if (flags & ACPI_NOT_ISR) {
624 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
626 return_ACPI_STATUS (status);
628 #endif /* ACPI_FUTURE_USAGE */
631 /*******************************************************************************
633 * FUNCTION: acpi_install_gpe_block
635 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
636 * gpe_block_address - Address and space_iD
637 * register_count - Number of GPE register pairs in the block
638 * interrupt_level - H/W interrupt for the block
640 * RETURN: Status
642 * DESCRIPTION: Create and Install a block of GPE registers
644 ******************************************************************************/
646 acpi_status
647 acpi_install_gpe_block (
648 acpi_handle gpe_device,
649 struct acpi_generic_address *gpe_block_address,
650 u32 register_count,
651 u32 interrupt_level)
653 acpi_status status;
654 union acpi_operand_object *obj_desc;
655 struct acpi_namespace_node *node;
656 struct acpi_gpe_block_info *gpe_block;
659 ACPI_FUNCTION_TRACE ("acpi_install_gpe_block");
662 if ((!gpe_device) ||
663 (!gpe_block_address) ||
664 (!register_count)) {
665 return_ACPI_STATUS (AE_BAD_PARAMETER);
668 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
669 if (ACPI_FAILURE (status)) {
670 return (status);
673 node = acpi_ns_map_handle_to_node (gpe_device);
674 if (!node) {
675 status = AE_BAD_PARAMETER;
676 goto unlock_and_exit;
680 * For user-installed GPE Block Devices, the gpe_block_base_number
681 * is always zero
683 status = acpi_ev_create_gpe_block (node, gpe_block_address, register_count,
684 0, interrupt_level, &gpe_block);
685 if (ACPI_FAILURE (status)) {
686 goto unlock_and_exit;
689 /* Get the device_object attached to the node */
691 obj_desc = acpi_ns_get_attached_object (node);
692 if (!obj_desc) {
693 /* No object, create a new one */
695 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_DEVICE);
696 if (!obj_desc) {
697 status = AE_NO_MEMORY;
698 goto unlock_and_exit;
701 status = acpi_ns_attach_object (node, obj_desc, ACPI_TYPE_DEVICE);
703 /* Remove local reference to the object */
705 acpi_ut_remove_reference (obj_desc);
707 if (ACPI_FAILURE (status)) {
708 goto unlock_and_exit;
712 /* Install the GPE block in the device_object */
714 obj_desc->device.gpe_block = gpe_block;
717 unlock_and_exit:
718 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
719 return_ACPI_STATUS (status);
721 EXPORT_SYMBOL(acpi_install_gpe_block);
724 /*******************************************************************************
726 * FUNCTION: acpi_remove_gpe_block
728 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
730 * RETURN: Status
732 * DESCRIPTION: Remove a previously installed block of GPE registers
734 ******************************************************************************/
736 acpi_status
737 acpi_remove_gpe_block (
738 acpi_handle gpe_device)
740 union acpi_operand_object *obj_desc;
741 acpi_status status;
742 struct acpi_namespace_node *node;
745 ACPI_FUNCTION_TRACE ("acpi_remove_gpe_block");
748 if (!gpe_device) {
749 return_ACPI_STATUS (AE_BAD_PARAMETER);
752 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
753 if (ACPI_FAILURE (status)) {
754 return (status);
757 node = acpi_ns_map_handle_to_node (gpe_device);
758 if (!node) {
759 status = AE_BAD_PARAMETER;
760 goto unlock_and_exit;
763 /* Get the device_object attached to the node */
765 obj_desc = acpi_ns_get_attached_object (node);
766 if (!obj_desc ||
767 !obj_desc->device.gpe_block) {
768 return_ACPI_STATUS (AE_NULL_OBJECT);
771 /* Delete the GPE block (but not the device_object) */
773 status = acpi_ev_delete_gpe_block (obj_desc->device.gpe_block);
774 if (ACPI_SUCCESS (status)) {
775 obj_desc->device.gpe_block = NULL;
778 unlock_and_exit:
779 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
780 return_ACPI_STATUS (status);
783 EXPORT_SYMBOL(acpi_remove_gpe_block);