Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[linux-drm-fsl-dcu.git] / drivers / acpi / executer / exfldio.c
index 051053f7cccb40c58931508c7347802cce084dfd..65a48b6170ee3c9803771cad7a58c2caecc04b77 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
@@ -257,14 +257,13 @@ acpi_ex_access_region(union acpi_operand_object *obj_desc,
        }
 
        ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD,
-                             " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %8.8X%8.8X\n",
+                             " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %p\n",
                              acpi_ut_get_region_name(rgn_desc->region.
                                                      space_id),
                              rgn_desc->region.space_id,
                              obj_desc->common_field.access_byte_width,
                              obj_desc->common_field.base_byte_offset,
-                             field_datum_byte_offset,
-                             ACPI_FORMAT_UINT64(address)));
+                             field_datum_byte_offset, (void *)address));
 
        /* Invoke the appropriate address_space/op_region handler */
 
@@ -727,11 +726,23 @@ acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
                        return_ACPI_STATUS(status);
                }
 
-               /* Merge with previous datum if necessary */
-
-               merged_datum |= raw_datum <<
-                   (obj_desc->common_field.access_bit_width -
-                    obj_desc->common_field.start_field_bit_offset);
+               /*
+                * Merge with previous datum if necessary.
+                *
+                * Note: Before the shift, check if the shift value will be larger than
+                * the integer size. If so, there is no need to perform the operation.
+                * This avoids the differences in behavior between different compilers
+                * concerning shift values larger than the target data width.
+                */
+               if ((obj_desc->common_field.access_bit_width -
+                    obj_desc->common_field.start_field_bit_offset) <
+                   ACPI_INTEGER_BIT_SIZE) {
+                       merged_datum |=
+                           raw_datum << (obj_desc->common_field.
+                                         access_bit_width -
+                                         obj_desc->common_field.
+                                         start_field_bit_offset);
+               }
 
                if (i == datum_count) {
                        break;
@@ -808,13 +819,23 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
                return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
        }
 
-       /* Compute the number of datums (access width data items) */
+       /*
+        * Create the bitmasks used for bit insertion.
+        * Note: This if/else is used to bypass compiler differences with the
+        * shift operator
+        */
+       if (obj_desc->common_field.access_bit_width == ACPI_INTEGER_BIT_SIZE) {
+               width_mask = ACPI_INTEGER_MAX;
+       } else {
+               width_mask =
+                   ACPI_MASK_BITS_ABOVE(obj_desc->common_field.
+                                        access_bit_width);
+       }
 
-       width_mask =
-           ACPI_MASK_BITS_ABOVE(obj_desc->common_field.access_bit_width);
-       mask =
-           width_mask & ACPI_MASK_BITS_BELOW(obj_desc->common_field.
-                                             start_field_bit_offset);
+       mask = width_mask &
+           ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset);
+
+       /* Compute the number of datums (access width data items) */
 
        datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
                                       obj_desc->common_field.access_bit_width);
@@ -848,12 +869,29 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
                        return_ACPI_STATUS(status);
                }
 
-               /* Start new output datum by merging with previous input datum */
-
                field_offset += obj_desc->common_field.access_byte_width;
-               merged_datum = raw_datum >>
-                   (obj_desc->common_field.access_bit_width -
-                    obj_desc->common_field.start_field_bit_offset);
+
+               /*
+                * Start new output datum by merging with previous input datum
+                * if necessary.
+                *
+                * Note: Before the shift, check if the shift value will be larger than
+                * the integer size. If so, there is no need to perform the operation.
+                * This avoids the differences in behavior between different compilers
+                * concerning shift values larger than the target data width.
+                */
+               if ((obj_desc->common_field.access_bit_width -
+                    obj_desc->common_field.start_field_bit_offset) <
+                   ACPI_INTEGER_BIT_SIZE) {
+                       merged_datum =
+                           raw_datum >> (obj_desc->common_field.
+                                         access_bit_width -
+                                         obj_desc->common_field.
+                                         start_field_bit_offset);
+               } else {
+                       merged_datum = 0;
+               }
+
                mask = width_mask;
 
                if (i == datum_count) {