]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/acpi/dispatcher/dsobject.c
Merge branch 'bugzilla-10503' into test
[linux-2.6-omap-h63xx.git] / drivers / acpi / dispatcher / dsobject.c
index 954ac8ce958a63c55a6740a4dcc1bbab5e4071bc..4f08e599d07e2a62eb257fefa2b6ba812b132578 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2007, R. Byron Moore
+ * Copyright (C) 2000 - 2008, Intel Corp.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -157,7 +157,9 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
                         * will remain as named references. This behavior is not described
                         * in the ACPI spec, but it appears to be an oversight.
                         */
-                       obj_desc = (union acpi_operand_object *)op->common.node;
+                       obj_desc =
+                           ACPI_CAST_PTR(union acpi_operand_object,
+                                         op->common.node);
 
                        status =
                            acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
@@ -172,7 +174,19 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
                        switch (op->common.node->type) {
                                /*
                                 * For these types, we need the actual node, not the subobject.
-                                * However, the subobject got an extra reference count above.
+                                * However, the subobject did not get an extra reference count above.
+                                *
+                                * TBD: should ex_resolve_node_to_value be changed to fix this?
+                                */
+                       case ACPI_TYPE_DEVICE:
+                       case ACPI_TYPE_THERMAL:
+
+                               acpi_ut_add_reference(op->common.node->object);
+
+                               /*lint -fallthrough */
+                               /*
+                                * For these types, we need the actual node, not the subobject.
+                                * The subobject got an extra reference count in ex_resolve_node_to_value.
                                 */
                        case ACPI_TYPE_MUTEX:
                        case ACPI_TYPE_METHOD:
@@ -180,25 +194,15 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
                        case ACPI_TYPE_PROCESSOR:
                        case ACPI_TYPE_EVENT:
                        case ACPI_TYPE_REGION:
-                       case ACPI_TYPE_DEVICE:
-                       case ACPI_TYPE_THERMAL:
 
-                               obj_desc =
-                                   (union acpi_operand_object *)op->common.
-                                   node;
+                               /* We will create a reference object for these types below */
                                break;
 
                        default:
-                               break;
-                       }
-
-                       /*
-                        * If above resolved to an operand object, we are done. Otherwise,
-                        * we have a NS node, we must create the package entry as a named
-                        * reference.
-                        */
-                       if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) !=
-                           ACPI_DESC_TYPE_NAMED) {
+                               /*
+                                * All other types - the node was resolved to an actual
+                                * object, we are done.
+                                */
                                goto exit;
                        }
                }
@@ -223,7 +227,7 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
 
       exit:
        *obj_desc_ptr = obj_desc;
-       return_ACPI_STATUS(AE_OK);
+       return_ACPI_STATUS(status);
 }
 
 /*******************************************************************************
@@ -369,7 +373,9 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
        union acpi_parse_object *parent;
        union acpi_operand_object *obj_desc = NULL;
        acpi_status status = AE_OK;
-       acpi_native_uint i;
+       unsigned i;
+       u16 index;
+       u16 reference_count;
 
        ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
 
@@ -447,13 +453,60 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                                                               package.
                                                               elements[i]);
                }
+
+               if (*obj_desc_ptr) {
+
+                       /* Existing package, get existing reference count */
+
+                       reference_count =
+                           (*obj_desc_ptr)->common.reference_count;
+                       if (reference_count > 1) {
+
+                               /* Make new element ref count match original ref count */
+
+                               for (index = 0; index < (reference_count - 1);
+                                    index++) {
+                                       acpi_ut_add_reference((obj_desc->
+                                                              package.
+                                                              elements[i]));
+                               }
+                       }
+               }
+
                arg = arg->common.next;
        }
 
-       if (!arg) {
+       /* Check for match between num_elements and actual length of package_list */
+
+       if (arg) {
+               /*
+                * num_elements was exhausted, but there are remaining elements in the
+                * package_list.
+                *
+                * Note: technically, this is an error, from ACPI spec: "It is an error
+                * for NumElements to be less than the number of elements in the
+                * PackageList". However, for now, we just print an error message and
+                * no exception is returned.
+                */
+               while (arg) {
+
+                       /* Find out how many elements there really are */
+
+                       i++;
+                       arg = arg->common.next;
+               }
+
+               ACPI_WARNING((AE_INFO,
+                           "Package List length (%X) larger than NumElements count (%X), truncated\n",
+                           i, element_count));
+       } else if (i < element_count) {
+               /*
+                * Arg list (elements) was exhausted, but we did not reach num_elements count.
+                * Note: this is not an error, the package is padded out with NULLs.
+                */
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                 "Package List length larger than NumElements count (%X), truncated\n",
-                                 element_count));
+                                 "Package List length (%X) smaller than NumElements count (%X), padded with null elements\n",
+                                 i, element_count));
        }
 
        obj_desc->package.flags |= AOPOBJ_DATA_VALID;
@@ -678,52 +731,70 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                switch (op_info->type) {
                case AML_TYPE_LOCAL_VARIABLE:
 
-                       /* Split the opcode into a base opcode + offset */
+                       /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
 
-                       obj_desc->reference.opcode = AML_LOCAL_OP;
-                       obj_desc->reference.offset = opcode - AML_LOCAL_OP;
+                       obj_desc->reference.value = opcode - AML_LOCAL_OP;
+                       obj_desc->reference.class = ACPI_REFCLASS_LOCAL;
 
 #ifndef ACPI_NO_METHOD_EXECUTION
-                       status = acpi_ds_method_data_get_node(AML_LOCAL_OP,
-                                                             obj_desc->
-                                                             reference.offset,
-                                                             walk_state,
-                                                             (struct
-                                                              acpi_namespace_node
-                                                              **)&obj_desc->
-                                                             reference.object);
+                       status =
+                           acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL,
+                                                        obj_desc->reference.
+                                                        value, walk_state,
+                                                        ACPI_CAST_INDIRECT_PTR
+                                                        (struct
+                                                         acpi_namespace_node,
+                                                         &obj_desc->reference.
+                                                         object));
 #endif
                        break;
 
                case AML_TYPE_METHOD_ARGUMENT:
 
-                       /* Split the opcode into a base opcode + offset */
+                       /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
 
-                       obj_desc->reference.opcode = AML_ARG_OP;
-                       obj_desc->reference.offset = opcode - AML_ARG_OP;
+                       obj_desc->reference.value = opcode - AML_ARG_OP;
+                       obj_desc->reference.class = ACPI_REFCLASS_ARG;
 
 #ifndef ACPI_NO_METHOD_EXECUTION
-                       status = acpi_ds_method_data_get_node(AML_ARG_OP,
+                       status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG,
                                                              obj_desc->
-                                                             reference.offset,
+                                                             reference.value,
                                                              walk_state,
+                                                             ACPI_CAST_INDIRECT_PTR
                                                              (struct
-                                                              acpi_namespace_node
-                                                              **)&obj_desc->
-                                                             reference.object);
+                                                              acpi_namespace_node,
+                                                              &obj_desc->
+                                                              reference.
+                                                              object));
 #endif
                        break;
 
-               default:        /* Other literals, etc.. */
+               default:        /* Object name or Debug object */
 
-                       if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
+                       switch (op->common.aml_opcode) {
+                       case AML_INT_NAMEPATH_OP:
 
                                /* Node was saved in Op */
 
                                obj_desc->reference.node = op->common.node;
-                       }
+                               obj_desc->reference.object =
+                                   op->common.node->object;
+                               obj_desc->reference.class = ACPI_REFCLASS_NAME;
+                               break;
+
+                       case AML_DEBUG_OP:
 
-                       obj_desc->reference.opcode = opcode;
+                               obj_desc->reference.class = ACPI_REFCLASS_DEBUG;
+                               break;
+
+                       default:
+
+                               ACPI_ERROR((AE_INFO,
+                                           "Unimplemented reference type for AML opcode: %4.4X",
+                                           opcode));
+                               return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
+                       }
                        break;
                }
                break;