]> err.no Git - linux-2.6/blobdiff - drivers/acpi/dispatcher/dsobject.c
Pull bugzilla-8385 into release branch
[linux-2.6] / drivers / acpi / dispatcher / dsobject.c
index 8b21f0f9e5177f3d82f9ea72b38ff772c75f972f..a474ca2334d536e3cd411adf8799b8897c647f28 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -81,7 +81,7 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
        union acpi_operand_object *obj_desc;
        acpi_status status;
 
-       ACPI_FUNCTION_TRACE("ds_build_internal_object");
+       ACPI_FUNCTION_TRACE(ds_build_internal_object);
 
        *obj_desc_ptr = NULL;
        if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
@@ -103,6 +103,7 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
                                                                         common.
                                                                         node)));
                        if (ACPI_FAILURE(status)) {
+
                                /* Check if we are resolving a named reference within a package */
 
                                if ((status == AE_NOT_FOUND)
@@ -186,7 +187,7 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
        union acpi_parse_object *byte_list;
        u32 byte_list_length = 0;
 
-       ACPI_FUNCTION_TRACE("ds_build_internal_buffer_obj");
+       ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
 
        /*
         * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
@@ -195,6 +196,7 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
         */
        obj_desc = *obj_desc_ptr;
        if (!obj_desc) {
+
                /* Create a new buffer object */
 
                obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
@@ -243,7 +245,7 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
                                  "Buffer defined with zero length in AML, creating\n"));
        } else {
                obj_desc->buffer.pointer =
-                   ACPI_MEM_CALLOCATE(obj_desc->buffer.length);
+                   ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
                if (!obj_desc->buffer.pointer) {
                        acpi_ut_delete_object_desc(obj_desc);
                        return_ACPI_STATUS(AE_NO_MEMORY);
@@ -258,7 +260,7 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
        }
 
        obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
-       op->common.node = (struct acpi_namespace_node *)obj_desc;
+       op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
        return_ACPI_STATUS(AE_OK);
 }
 
@@ -268,7 +270,8 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
  *
  * PARAMETERS:  walk_state      - Current walk state
  *              Op              - Parser object to be translated
- *              package_length  - Number of elements in the package
+ *              element_count   - Number of elements in the package - this is
+ *                                the num_elements argument to Package()
  *              obj_desc_ptr    - Where the ACPI internal object is returned
  *
  * RETURN:      Status
@@ -276,22 +279,33 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
  * DESCRIPTION: Translate a parser Op package object to the equivalent
  *              namespace object
  *
+ * NOTE: The number of elements in the package will be always be the num_elements
+ * count, regardless of the number of elements in the package list. If
+ * num_elements is smaller, only that many package list elements are used.
+ * if num_elements is larger, the Package object is padded out with
+ * objects of type Uninitialized (as per ACPI spec.)
+ *
+ * Even though the ASL compilers do not allow num_elements to be smaller
+ * than the Package list length (for the fixed length package opcode), some
+ * BIOS code modifies the AML on the fly to adjust the num_elements, and
+ * this code compensates for that. This also provides compatibility with
+ * other AML interpreters.
+ *
  ******************************************************************************/
 
 acpi_status
 acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                                   union acpi_parse_object *op,
-                                  u32 package_length,
+                                  u32 element_count,
                                   union acpi_operand_object **obj_desc_ptr)
 {
        union acpi_parse_object *arg;
        union acpi_parse_object *parent;
        union acpi_operand_object *obj_desc = NULL;
-       u32 package_list_length;
        acpi_status status = AE_OK;
        acpi_native_uint i;
 
-       ACPI_FUNCTION_TRACE("ds_build_internal_package_obj");
+       ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
 
        /* Find the parent of a possibly nested package */
 
@@ -316,46 +330,34 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                obj_desc->package.node = parent->common.node;
        }
 
-       obj_desc->package.count = package_length;
-
-       /* Count the number of items in the package list */
-
-       arg = op->common.value.arg;
-       arg = arg->common.next;
-       for (package_list_length = 0; arg; package_list_length++) {
-               arg = arg->common.next;
-       }
-
        /*
-        * The package length (number of elements) will be the greater
-        * of the specified length and the length of the initializer list
+        * Allocate the element array (array of pointers to the individual
+        * objects) based on the num_elements parameter. Add an extra pointer slot
+        * so that the list is always null terminated.
         */
-       if (package_list_length > package_length) {
-               obj_desc->package.count = package_list_length;
-       }
-
-       /*
-        * Allocate the pointer array (array of pointers to the
-        * individual objects). Add an extra pointer slot so
-        * that the list is always null terminated.
-        */
-       obj_desc->package.elements = ACPI_MEM_CALLOCATE(((acpi_size) obj_desc->
-                                                        package.count +
-                                                        1) * sizeof(void *));
+       obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
+                                                          element_count +
+                                                          1) * sizeof(void *));
 
        if (!obj_desc->package.elements) {
                acpi_ut_delete_object_desc(obj_desc);
                return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
+       obj_desc->package.count = element_count;
+
        /*
-        * Initialize all elements of the package
+        * Initialize the elements of the package, up to the num_elements count.
+        * Package is automatically padded with uninitialized (NULL) elements
+        * if num_elements is greater than the package list length. Likewise,
+        * Package is truncated if num_elements is less than the list length.
         */
        arg = op->common.value.arg;
        arg = arg->common.next;
-       for (i = 0; arg; i++) {
+       for (i = 0; arg && (i < element_count); i++) {
                if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
-                       /* Object (package or buffer) is already built */
+
+                       /* This package element is already built, just get it */
 
                        obj_desc->package.elements[i] =
                            ACPI_CAST_PTR(union acpi_operand_object,
@@ -369,8 +371,14 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                arg = arg->common.next;
        }
 
+       if (!arg) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                                 "Package List length larger than NumElements count (%X), truncated\n",
+                                 element_count));
+       }
+
        obj_desc->package.flags |= AOPOBJ_DATA_VALID;
-       op->common.node = (struct acpi_namespace_node *)obj_desc;
+       op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
        return_ACPI_STATUS(status);
 }
 
@@ -396,7 +404,7 @@ acpi_ds_create_node(struct acpi_walk_state *walk_state,
        acpi_status status;
        union acpi_operand_object *obj_desc;
 
-       ACPI_FUNCTION_TRACE_PTR("ds_create_node", op);
+       ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
 
        /*
         * Because of the execution pass through the non-control-method
@@ -408,6 +416,7 @@ acpi_ds_create_node(struct acpi_walk_state *walk_state,
        }
 
        if (!op->common.value.arg) {
+
                /* No arguments, there is nothing to do */
 
                return_ACPI_STATUS(AE_OK);
@@ -464,11 +473,12 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
        union acpi_operand_object *obj_desc;
        acpi_status status = AE_OK;
 
-       ACPI_FUNCTION_TRACE("ds_init_object_from_op");
+       ACPI_FUNCTION_TRACE(ds_init_object_from_op);
 
        obj_desc = *ret_obj_desc;
        op_info = acpi_ps_get_opcode_info(opcode);
        if (op_info->class == AML_CLASS_UNKNOWN) {
+
                /* Unknown opcode */
 
                return_ACPI_STATUS(AE_TYPE);
@@ -482,8 +492,9 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                /*
                 * Defer evaluation of Buffer term_arg operand
                 */
-               obj_desc->buffer.node = (struct acpi_namespace_node *)
-                   walk_state->operands[0];
+               obj_desc->buffer.node =
+                   ACPI_CAST_PTR(struct acpi_namespace_node,
+                                 walk_state->operands[0]);
                obj_desc->buffer.aml_start = op->named.data;
                obj_desc->buffer.aml_length = op->named.length;
                break;
@@ -493,8 +504,9 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                /*
                 * Defer evaluation of Package term_arg operand
                 */
-               obj_desc->package.node = (struct acpi_namespace_node *)
-                   walk_state->operands[0];
+               obj_desc->package.node =
+                   ACPI_CAST_PTR(struct acpi_namespace_node,
+                                 walk_state->operands[0]);
                obj_desc->package.aml_start = op->named.data;
                obj_desc->package.aml_length = op->named.length;
                break;
@@ -626,6 +638,7 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                default:        /* Other literals, etc.. */
 
                        if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
+
                                /* Node was saved in Op */
 
                                obj_desc->reference.node = op->common.node;