Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / acpi / events / evrgnini.c
index 4983a33..baed8c1 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2005, R. Byron Moore
+ * Copyright (C) 2000 - 2006, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * POSSIBILITY OF SUCH DAMAGES.
  */
 
-
 #include <acpi/acpi.h>
 #include <acpi/acevents.h>
 #include <acpi/acnamesp.h>
 
 #define _COMPONENT          ACPI_EVENTS
-        ACPI_MODULE_NAME    ("evrgnini")
-
+ACPI_MODULE_NAME("evrgnini")
 
 /*******************************************************************************
  *
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Do any prep work for region handling, a nop for now
+ * DESCRIPTION: Setup a system_memory operation region
  *
  ******************************************************************************/
-
 acpi_status
-acpi_ev_system_memory_region_setup (
-       acpi_handle                     handle,
-       u32                             function,
-       void                            *handler_context,
-       void                            **region_context)
+acpi_ev_system_memory_region_setup(acpi_handle handle,
+                                  u32 function,
+                                  void *handler_context, void **region_context)
 {
-       union acpi_operand_object       *region_desc = (union acpi_operand_object *) handle;
-       struct acpi_mem_space_context   *local_region_context;
-
-
-       ACPI_FUNCTION_TRACE ("ev_system_memory_region_setup");
+       union acpi_operand_object *region_desc =
+           (union acpi_operand_object *)handle;
+       struct acpi_mem_space_context *local_region_context;
 
+       ACPI_FUNCTION_TRACE("ev_system_memory_region_setup");
 
        if (function == ACPI_REGION_DEACTIVATE) {
                if (*region_context) {
-                       ACPI_MEM_FREE (*region_context);
+                       ACPI_MEM_FREE(*region_context);
                        *region_context = NULL;
                }
-               return_ACPI_STATUS (AE_OK);
+               return_ACPI_STATUS(AE_OK);
        }
 
        /* Create a new context */
 
-       local_region_context = ACPI_MEM_CALLOCATE (sizeof (struct acpi_mem_space_context));
+       local_region_context =
+           ACPI_MEM_CALLOCATE(sizeof(struct acpi_mem_space_context));
        if (!(local_region_context)) {
-               return_ACPI_STATUS (AE_NO_MEMORY);
+               return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
        /* Save the region length and address for use in the handler */
@@ -100,10 +95,9 @@ acpi_ev_system_memory_region_setup (
        local_region_context->address = region_desc->region.address;
 
        *region_context = local_region_context;
-       return_ACPI_STATUS (AE_OK);
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_io_space_region_setup
@@ -115,67 +109,59 @@ acpi_ev_system_memory_region_setup (
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Do any prep work for region handling
+ * DESCRIPTION: Setup a IO operation region
  *
  ******************************************************************************/
 
 acpi_status
-acpi_ev_io_space_region_setup (
-       acpi_handle                     handle,
-       u32                             function,
-       void                            *handler_context,
-       void                            **region_context)
+acpi_ev_io_space_region_setup(acpi_handle handle,
+                             u32 function,
+                             void *handler_context, void **region_context)
 {
-       ACPI_FUNCTION_TRACE ("ev_io_space_region_setup");
-
+       ACPI_FUNCTION_TRACE("ev_io_space_region_setup");
 
        if (function == ACPI_REGION_DEACTIVATE) {
                *region_context = NULL;
-       }
-       else {
+       } else {
                *region_context = handler_context;
        }
 
-       return_ACPI_STATUS (AE_OK);
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_pci_config_region_setup
  *
- * PARAMETERS:  Handle             - Region we are interested in
+ * PARAMETERS:  Handle              - Region we are interested in
  *              Function            - Start or stop
  *              handler_context     - Address space handler context
  *              region_context      - Region specific context
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Do any prep work for region handling
+ * DESCRIPTION: Setup a PCI_Config operation region
  *
  * MUTEX:       Assumes namespace is not locked
  *
  ******************************************************************************/
 
 acpi_status
-acpi_ev_pci_config_region_setup (
-       acpi_handle                     handle,
-       u32                             function,
-       void                            *handler_context,
-       void                            **region_context)
+acpi_ev_pci_config_region_setup(acpi_handle handle,
+                               u32 function,
+                               void *handler_context, void **region_context)
 {
-       acpi_status                     status = AE_OK;
-       acpi_integer                    pci_value;
-       struct acpi_pci_id              *pci_id = *region_context;
-       union acpi_operand_object       *handler_obj;
-       struct acpi_namespace_node      *parent_node;
-       struct acpi_namespace_node      *pci_root_node;
-       union acpi_operand_object       *region_obj = (union acpi_operand_object   *) handle;
-       struct acpi_device_id           object_hID;
-
-
-       ACPI_FUNCTION_TRACE ("ev_pci_config_region_setup");
-
+       acpi_status status = AE_OK;
+       acpi_integer pci_value;
+       struct acpi_pci_id *pci_id = *region_context;
+       union acpi_operand_object *handler_obj;
+       struct acpi_namespace_node *parent_node;
+       struct acpi_namespace_node *pci_root_node;
+       union acpi_operand_object *region_obj =
+           (union acpi_operand_object *)handle;
+       struct acpi_device_id object_hID;
+
+       ACPI_FUNCTION_TRACE("ev_pci_config_region_setup");
 
        handler_obj = region_obj->region.handler;
        if (!handler_obj) {
@@ -183,20 +169,21 @@ acpi_ev_pci_config_region_setup (
                 * No installed handler. This shouldn't happen because the dispatch
                 * routine checks before we get here, but we check again just in case.
                 */
-               ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-                       "Attempting to init a region %p, with no handler\n", region_obj));
-               return_ACPI_STATUS (AE_NOT_EXIST);
+               ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
+                                 "Attempting to init a region %p, with no handler\n",
+                                 region_obj));
+               return_ACPI_STATUS(AE_NOT_EXIST);
        }
 
        *region_context = NULL;
        if (function == ACPI_REGION_DEACTIVATE) {
                if (pci_id) {
-                       ACPI_MEM_FREE (pci_id);
+                       ACPI_MEM_FREE(pci_id);
                }
-               return_ACPI_STATUS (status);
+               return_ACPI_STATUS(status);
        }
 
-       parent_node = acpi_ns_get_parent_node (region_obj->region.node);
+       parent_node = acpi_ns_get_parent_node(region_obj->region.node);
 
        /*
         * Get the _SEG and _BBN values from the device upon which the handler
@@ -216,18 +203,28 @@ acpi_ev_pci_config_region_setup (
 
                pci_root_node = parent_node;
                while (pci_root_node != acpi_gbl_root_node) {
-                       status = acpi_ut_execute_HID (pci_root_node, &object_hID);
-                       if (ACPI_SUCCESS (status)) {
-                               /* Got a valid _HID, check if this is a PCI root */
-
-                               if (!(ACPI_STRNCMP (object_hID.value, PCI_ROOT_HID_STRING,
-                                                  sizeof (PCI_ROOT_HID_STRING)))) {
+                       status =
+                           acpi_ut_execute_HID(pci_root_node, &object_hID);
+                       if (ACPI_SUCCESS(status)) {
+                               /*
+                                * Got a valid _HID string, check if this is a PCI root.
+                                * New for ACPI 3.0: check for a PCI Express root also.
+                                */
+                               if (!
+                                   (ACPI_STRNCMP
+                                    (object_hID.value, PCI_ROOT_HID_STRING,
+                                     sizeof(PCI_ROOT_HID_STRING))
+                                    ||
+                                    !(ACPI_STRNCMP
+                                      (object_hID.value,
+                                       PCI_EXPRESS_ROOT_HID_STRING,
+                                       sizeof(PCI_EXPRESS_ROOT_HID_STRING)))))
+                               {
                                        /* Install a handler for this PCI root bridge */
 
-                                       status = acpi_install_address_space_handler ((acpi_handle) pci_root_node,
-                                                          ACPI_ADR_SPACE_PCI_CONFIG,
-                                                          ACPI_DEFAULT_HANDLER, NULL, NULL);
-                                       if (ACPI_FAILURE (status)) {
+                                       status =
+                                           acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
+                                       if (ACPI_FAILURE(status)) {
                                                if (status == AE_SAME_HANDLER) {
                                                        /*
                                                         * It is OK if the handler is already installed on the root
@@ -235,23 +232,23 @@ acpi_ev_pci_config_region_setup (
                                                         * new PCI_Config operation region, however.
                                                         */
                                                        status = AE_OK;
-                                               }
-                                               else {
-                                                       ACPI_REPORT_ERROR ((
-                                                               "Could not install pci_config handler for Root Bridge %4.4s, %s\n",
-                                                               acpi_ut_get_node_name (pci_root_node), acpi_format_exception (status)));
+                                               } else {
+                                                       ACPI_EXCEPTION((AE_INFO,
+                                                                       status,
+                                                                       "Could not install pci_config handler for Root Bridge %4.4s",
+                                                                       acpi_ut_get_node_name
+                                                                       (pci_root_node)));
                                                }
                                        }
                                        break;
                                }
                        }
 
-                       pci_root_node = acpi_ns_get_parent_node (pci_root_node);
+                       pci_root_node = acpi_ns_get_parent_node(pci_root_node);
                }
 
                /* PCI root bridge not found, use namespace root node */
-       }
-       else {
+       } else {
                pci_root_node = handler_obj->address_space.node;
        }
 
@@ -260,14 +257,14 @@ acpi_ev_pci_config_region_setup (
         * (install_address_space_handler could have initialized it)
         */
        if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
-               return_ACPI_STATUS (AE_OK);
+               return_ACPI_STATUS(AE_OK);
        }
 
        /* Region is still not initialized. Create a new context */
 
-       pci_id = ACPI_MEM_CALLOCATE (sizeof (struct acpi_pci_id));
+       pci_id = ACPI_MEM_CALLOCATE(sizeof(struct acpi_pci_id));
        if (!pci_id) {
-               return_ACPI_STATUS (AE_NO_MEMORY);
+               return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
        /*
@@ -279,40 +276,45 @@ acpi_ev_pci_config_region_setup (
         * Get the PCI device and function numbers from the _ADR object
         * contained in the parent's scope.
         */
-       status = acpi_ut_evaluate_numeric_object (METHOD_NAME__ADR, parent_node, &pci_value);
+       status =
+           acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, parent_node,
+                                           &pci_value);
 
        /*
         * The default is zero, and since the allocation above zeroed
         * the data, just do nothing on failure.
         */
-       if (ACPI_SUCCESS (status)) {
-               pci_id->device  = ACPI_HIWORD (ACPI_LODWORD (pci_value));
-               pci_id->function = ACPI_LOWORD (ACPI_LODWORD (pci_value));
+       if (ACPI_SUCCESS(status)) {
+               pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value));
+               pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value));
        }
 
        /* The PCI segment number comes from the _SEG method */
 
-       status = acpi_ut_evaluate_numeric_object (METHOD_NAME__SEG, pci_root_node, &pci_value);
-       if (ACPI_SUCCESS (status)) {
-               pci_id->segment = ACPI_LOWORD (pci_value);
+       status =
+           acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, pci_root_node,
+                                           &pci_value);
+       if (ACPI_SUCCESS(status)) {
+               pci_id->segment = ACPI_LOWORD(pci_value);
        }
 
        /* The PCI bus number comes from the _BBN method */
 
-       status = acpi_ut_evaluate_numeric_object (METHOD_NAME__BBN, pci_root_node, &pci_value);
-       if (ACPI_SUCCESS (status)) {
-               pci_id->bus = ACPI_LOWORD (pci_value);
+       status =
+           acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, pci_root_node,
+                                           &pci_value);
+       if (ACPI_SUCCESS(status)) {
+               pci_id->bus = ACPI_LOWORD(pci_value);
        }
 
        /* Complete this device's pci_id */
 
-       acpi_os_derive_pci_id (pci_root_node, region_obj->region.node, &pci_id);
+       acpi_os_derive_pci_id(pci_root_node, region_obj->region.node, &pci_id);
 
        *region_context = pci_id;
-       return_ACPI_STATUS (AE_OK);
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_pci_bar_region_setup
@@ -324,26 +326,22 @@ acpi_ev_pci_config_region_setup (
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Do any prep work for region handling
+ * DESCRIPTION: Setup a pci_bAR operation region
  *
  * MUTEX:       Assumes namespace is not locked
  *
  ******************************************************************************/
 
 acpi_status
-acpi_ev_pci_bar_region_setup (
-       acpi_handle                     handle,
-       u32                             function,
-       void                            *handler_context,
-       void                            **region_context)
+acpi_ev_pci_bar_region_setup(acpi_handle handle,
+                            u32 function,
+                            void *handler_context, void **region_context)
 {
-       ACPI_FUNCTION_TRACE ("ev_pci_bar_region_setup");
-
+       ACPI_FUNCTION_TRACE("ev_pci_bar_region_setup");
 
-       return_ACPI_STATUS (AE_OK);
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_cmos_region_setup
@@ -355,26 +353,22 @@ acpi_ev_pci_bar_region_setup (
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Do any prep work for region handling
+ * DESCRIPTION: Setup a CMOS operation region
  *
  * MUTEX:       Assumes namespace is not locked
  *
  ******************************************************************************/
 
 acpi_status
-acpi_ev_cmos_region_setup (
-       acpi_handle                     handle,
-       u32                             function,
-       void                            *handler_context,
-       void                            **region_context)
+acpi_ev_cmos_region_setup(acpi_handle handle,
+                         u32 function,
+                         void *handler_context, void **region_context)
 {
-       ACPI_FUNCTION_TRACE ("ev_cmos_region_setup");
-
+       ACPI_FUNCTION_TRACE("ev_cmos_region_setup");
 
-       return_ACPI_STATUS (AE_OK);
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_default_region_setup
@@ -386,31 +380,26 @@ acpi_ev_cmos_region_setup (
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Do any prep work for region handling
+ * DESCRIPTION: Default region initialization
  *
  ******************************************************************************/
 
 acpi_status
-acpi_ev_default_region_setup (
-       acpi_handle                     handle,
-       u32                             function,
-       void                            *handler_context,
-       void                            **region_context)
+acpi_ev_default_region_setup(acpi_handle handle,
+                            u32 function,
+                            void *handler_context, void **region_context)
 {
-       ACPI_FUNCTION_TRACE ("ev_default_region_setup");
-
+       ACPI_FUNCTION_TRACE("ev_default_region_setup");
 
        if (function == ACPI_REGION_DEACTIVATE) {
                *region_context = NULL;
-       }
-       else {
+       } else {
                *region_context = handler_context;
        }
 
-       return_ACPI_STATUS (AE_OK);
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_initialize_region
@@ -434,37 +423,34 @@ acpi_ev_default_region_setup (
  ******************************************************************************/
 
 acpi_status
-acpi_ev_initialize_region (
-       union acpi_operand_object       *region_obj,
-       u8                              acpi_ns_locked)
+acpi_ev_initialize_region(union acpi_operand_object *region_obj,
+                         u8 acpi_ns_locked)
 {
-       union acpi_operand_object       *handler_obj;
-       union acpi_operand_object       *obj_desc;
-       acpi_adr_space_type             space_id;
-       struct acpi_namespace_node      *node;
-       acpi_status                     status;
-       struct acpi_namespace_node      *method_node;
-       acpi_name                       *reg_name_ptr = (acpi_name *) METHOD_NAME__REG;
-       union acpi_operand_object       *region_obj2;
-
-
-       ACPI_FUNCTION_TRACE_U32 ("ev_initialize_region", acpi_ns_locked);
+       union acpi_operand_object *handler_obj;
+       union acpi_operand_object *obj_desc;
+       acpi_adr_space_type space_id;
+       struct acpi_namespace_node *node;
+       acpi_status status;
+       struct acpi_namespace_node *method_node;
+       acpi_name *reg_name_ptr = (acpi_name *) METHOD_NAME__REG;
+       union acpi_operand_object *region_obj2;
 
+       ACPI_FUNCTION_TRACE_U32("ev_initialize_region", acpi_ns_locked);
 
        if (!region_obj) {
-               return_ACPI_STATUS (AE_BAD_PARAMETER);
+               return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
        if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) {
-               return_ACPI_STATUS (AE_OK);
+               return_ACPI_STATUS(AE_OK);
        }
 
-       region_obj2 = acpi_ns_get_secondary_object (region_obj);
+       region_obj2 = acpi_ns_get_secondary_object(region_obj);
        if (!region_obj2) {
-               return_ACPI_STATUS (AE_NOT_EXIST);
+               return_ACPI_STATUS(AE_NOT_EXIST);
        }
 
-       node = acpi_ns_get_parent_node (region_obj->region.node);
+       node = acpi_ns_get_parent_node(region_obj->region.node);
        space_id = region_obj->region.space_id;
 
        /* Setup defaults */
@@ -476,9 +462,9 @@ acpi_ev_initialize_region (
 
        /* Find any "_REG" method associated with this region definition */
 
-       status = acpi_ns_search_node (*reg_name_ptr, node,
-                         ACPI_TYPE_METHOD, &method_node);
-       if (ACPI_SUCCESS (status)) {
+       status = acpi_ns_search_node(*reg_name_ptr, node,
+                                    ACPI_TYPE_METHOD, &method_node);
+       if (ACPI_SUCCESS(status)) {
                /*
                 * The _REG method is optional and there can be only one per region
                 * definition.  This will be executed when the handler is attached
@@ -495,7 +481,7 @@ acpi_ev_initialize_region (
                /* Check to see if a handler exists */
 
                handler_obj = NULL;
-               obj_desc = acpi_ns_get_attached_object (node);
+               obj_desc = acpi_ns_get_attached_object(node);
                if (obj_desc) {
                        /* Can only be a handler if the object exists */
 
@@ -523,37 +509,50 @@ acpi_ev_initialize_region (
                        while (handler_obj) {
                                /* Is this handler of the correct type? */
 
-                               if (handler_obj->address_space.space_id == space_id) {
+                               if (handler_obj->address_space.space_id ==
+                                   space_id) {
                                        /* Found correct handler */
 
-                                       ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-                                               "Found handler %p for region %p in obj %p\n",
-                                               handler_obj, region_obj, obj_desc));
+                                       ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
+                                                         "Found handler %p for region %p in obj %p\n",
+                                                         handler_obj,
+                                                         region_obj,
+                                                         obj_desc));
 
-                                       status = acpi_ev_attach_region (handler_obj, region_obj,
-                                                        acpi_ns_locked);
+                                       status =
+                                           acpi_ev_attach_region(handler_obj,
+                                                                 region_obj,
+                                                                 acpi_ns_locked);
 
                                        /*
                                         * Tell all users that this region is usable by running the _REG
                                         * method
                                         */
                                        if (acpi_ns_locked) {
-                                               status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
-                                               if (ACPI_FAILURE (status)) {
-                                                       return_ACPI_STATUS (status);
+                                               status =
+                                                   acpi_ut_release_mutex
+                                                   (ACPI_MTX_NAMESPACE);
+                                               if (ACPI_FAILURE(status)) {
+                                                       return_ACPI_STATUS
+                                                           (status);
                                                }
                                        }
 
-                                       status = acpi_ev_execute_reg_method (region_obj, 1);
+                                       status =
+                                           acpi_ev_execute_reg_method
+                                           (region_obj, 1);
 
                                        if (acpi_ns_locked) {
-                                               status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
-                                               if (ACPI_FAILURE (status)) {
-                                                       return_ACPI_STATUS (status);
+                                               status =
+                                                   acpi_ut_acquire_mutex
+                                                   (ACPI_MTX_NAMESPACE);
+                                               if (ACPI_FAILURE(status)) {
+                                                       return_ACPI_STATUS
+                                                           (status);
                                                }
                                        }
 
-                                       return_ACPI_STATUS (AE_OK);
+                                       return_ACPI_STATUS(AE_OK);
                                }
 
                                /* Try next handler in the list */
@@ -566,15 +565,15 @@ acpi_ev_initialize_region (
                 * This node does not have the handler we need;
                 * Pop up one level
                 */
-               node = acpi_ns_get_parent_node (node);
+               node = acpi_ns_get_parent_node(node);
        }
 
        /* If we get here, there is no handler for this region */
 
-       ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-               "No handler for region_type %s(%X) (region_obj %p)\n",
-               acpi_ut_get_region_name (space_id), space_id, region_obj));
+       ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
+                         "No handler for region_type %s(%X) (region_obj %p)\n",
+                         acpi_ut_get_region_name(space_id), space_id,
+                         region_obj));
 
-       return_ACPI_STATUS (AE_NOT_EXIST);
+       return_ACPI_STATUS(AE_NOT_EXIST);
 }
-