Pull ec into release branch
[powerpc.git] / drivers / acpi / resources / rsmisc.c
index 16ad3bf..faf6e10 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
@@ -81,12 +81,15 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
        u16 item_count = 0;
        u16 temp16 = 0;
 
-       ACPI_FUNCTION_TRACE("rs_get_resource");
+       ACPI_FUNCTION_TRACE(rs_convert_aml_to_resource);
 
        if (((acpi_native_uint) resource) & 0x3) {
-               acpi_os_printf
-                   ("**** GET: Misaligned resource pointer: %p Type %2.2X Len %X\n",
-                    resource, resource->type, resource->length);
+
+               /* Each internal resource struct is expected to be 32-bit aligned */
+
+               ACPI_WARNING((AE_INFO,
+                             "Misaligned resource pointer (get): %p Type %2.2X Len %X",
+                             resource, resource->type, resource->length));
        }
 
        /* Extract the resource Length field (does not include header length) */
@@ -104,8 +107,9 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
                 * Source is the external AML byte stream buffer,
                 * destination is the internal resource descriptor
                 */
-               source = ((u8 *) aml) + info->aml_offset;
-               destination = ((u8 *) resource) + info->resource_offset;
+               source = ACPI_ADD_PTR(void, aml, info->aml_offset);
+               destination =
+                   ACPI_ADD_PTR(void, resource, info->resource_offset);
 
                switch (info->opcode) {
                case ACPI_RSC_INITGET:
@@ -129,22 +133,22 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
                        /*
                         * Mask and shift the flag bit
                         */
-                       *((u8 *) destination) = (u8)
-                           ((*((u8 *) source) >> info->value) & 0x01);
+                       ACPI_SET8(destination) = (u8)
+                           ((ACPI_GET8(source) >> info->value) & 0x01);
                        break;
 
                case ACPI_RSC_2BITFLAG:
                        /*
                         * Mask and shift the flag bits
                         */
-                       *((u8 *) destination) = (u8)
-                           ((*((u8 *) source) >> info->value) & 0x03);
+                       ACPI_SET8(destination) = (u8)
+                           ((ACPI_GET8(source) >> info->value) & 0x03);
                        break;
 
                case ACPI_RSC_COUNT:
 
-                       item_count = *((u8 *) source);
-                       *((u8 *) destination) = (u8) item_count;
+                       item_count = ACPI_GET8(source);
+                       ACPI_SET8(destination) = (u8) item_count;
 
                        resource->length = resource->length +
                            (info->value * (item_count - 1));
@@ -153,7 +157,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
                case ACPI_RSC_COUNT16:
 
                        item_count = aml_resource_length;
-                       *((u16 *) destination) = item_count;
+                       ACPI_SET16(destination) = item_count;
 
                        resource->length = resource->length +
                            (info->value * (item_count - 1));
@@ -186,9 +190,8 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
 
                case ACPI_RSC_DATA8:
 
-                       target = ((char *)resource) + info->value;
-                       ACPI_MEMCPY(destination, source,
-                                   *(ACPI_CAST_PTR(u16, target)));
+                       target = ACPI_ADD_PTR(char, resource, info->value);
+                       ACPI_MEMCPY(destination, source, ACPI_GET16(target));
                        break;
 
                case ACPI_RSC_ADDRESS:
@@ -217,8 +220,8 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
                         * complicated case used by the Interrupt() macro
                         */
                        target =
-                           ((char *)resource) + info->aml_offset +
-                           (item_count * 4);
+                           ACPI_ADD_PTR(char, resource,
+                                        info->aml_offset + (item_count * 4));
 
                        resource->length +=
                            acpi_rs_get_resource_source(aml_resource_length,
@@ -230,15 +233,14 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
                         * 8-bit encoded bitmask (DMA macro)
                         */
                        item_count =
-                           acpi_rs_decode_bitmask(*((u8 *) source),
+                           acpi_rs_decode_bitmask(ACPI_GET8(source),
                                                   destination);
                        if (item_count) {
-                               resource->length +=
-                                   resource->length + (item_count - 1);
+                               resource->length += (item_count - 1);
                        }
 
-                       target = ((char *)resource) + info->value;
-                       *((u8 *) target) = (u8) item_count;
+                       target = ACPI_ADD_PTR(char, resource, info->value);
+                       ACPI_SET8(target) = (u8) item_count;
                        break;
 
                case ACPI_RSC_BITMASK16:
@@ -250,12 +252,11 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
                        item_count =
                            acpi_rs_decode_bitmask(temp16, destination);
                        if (item_count) {
-                               resource->length =
-                                   resource->length + (item_count - 1);
+                               resource->length += (item_count - 1);
                        }
 
-                       target = ((char *)resource) + info->value;
-                       *((u8 *) target) = (u8) item_count;
+                       target = ACPI_ADD_PTR(char, resource, info->value);
+                       ACPI_SET8(target) = (u8) item_count;
                        break;
 
                case ACPI_RSC_EXIT_NE:
@@ -270,21 +271,22 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
                                break;
 
                        case ACPI_RSC_COMPARE_VALUE:
-                               if (*((u8 *) source) != info->value) {
+                               if (ACPI_GET8(source) != info->value) {
                                        goto exit;
                                }
                                break;
 
                        default:
-                               acpi_os_printf
-                                   ("*** Invalid conversion sub-opcode\n");
+
+                               ACPI_ERROR((AE_INFO,
+                                           "Invalid conversion sub-opcode"));
                                return_ACPI_STATUS(AE_BAD_PARAMETER);
                        }
                        break;
 
                default:
 
-                       acpi_os_printf("*** Invalid conversion opcode\n");
+                       ACPI_ERROR((AE_INFO, "Invalid conversion opcode"));
                        return_ACPI_STATUS(AE_BAD_PARAMETER);
                }
 
@@ -294,9 +296,11 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
 
       exit:
        if (!flags_mode) {
-               /* Round the resource struct length up to the next 32-bit boundary */
 
-               resource->length = ACPI_ROUND_UP_to_32_bITS(resource->length);
+               /* Round the resource struct length up to the next boundary (32 or 64) */
+
+               resource->length =
+                   (u32) ACPI_ROUND_UP_TO_NATIVE_WORD(resource->length);
        }
        return_ACPI_STATUS(AE_OK);
 }
@@ -328,15 +332,7 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
        u16 temp16 = 0;
        u16 item_count = 0;
 
-       ACPI_FUNCTION_TRACE("rs_convert_resource_to_aml");
-
-       /* Validate the Resource pointer, must be 32-bit aligned */
-
-       if (((acpi_native_uint) resource) & 0x3) {
-               acpi_os_printf
-                   ("**** SET: Misaligned resource pointer: %p Type %2.2X Len %X\n",
-                    resource, resource->type, resource->length);
-       }
+       ACPI_FUNCTION_TRACE(rs_convert_resource_to_aml);
 
        /*
         * First table entry must be ACPI_RSC_INITxxx and must contain the
@@ -349,8 +345,8 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
                 * Source is the internal resource descriptor,
                 * destination is the external AML byte stream buffer
                 */
-               source = ((u8 *) resource) + info->resource_offset;
-               destination = ((u8 *) aml) + info->aml_offset;
+               source = ACPI_ADD_PTR(void, resource, info->resource_offset);
+               destination = ACPI_ADD_PTR(void, aml, info->aml_offset);
 
                switch (info->opcode) {
                case ACPI_RSC_INITSET:
@@ -368,37 +364,38 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
                        /*
                         * Clear the flag byte
                         */
-                       *((u8 *) destination) = 0;
+                       ACPI_SET8(destination) = 0;
                        break;
 
                case ACPI_RSC_1BITFLAG:
                        /*
                         * Mask and shift the flag bit
                         */
-                       *((u8 *) destination) |= (u8)
-                           ((*((u8 *) source) & 0x01) << info->value);
+                       ACPI_SET8(destination) |= (u8)
+                           ((ACPI_GET8(source) & 0x01) << info->value);
                        break;
 
                case ACPI_RSC_2BITFLAG:
                        /*
                         * Mask and shift the flag bits
                         */
-                       *((u8 *) destination) |= (u8)
-                           ((*((u8 *) source) & 0x03) << info->value);
+                       ACPI_SET8(destination) |= (u8)
+                           ((ACPI_GET8(source) & 0x03) << info->value);
                        break;
 
                case ACPI_RSC_COUNT:
 
-                       item_count = *((u8 *) source);
-                       *((u8 *) destination) = (u8) item_count;
+                       item_count = ACPI_GET8(source);
+                       ACPI_SET8(destination) = (u8) item_count;
 
-                       aml_length = (u16) (aml_length +
-                                           (info->value * (item_count - 1)));
+                       aml_length =
+                           (u16) (aml_length +
+                                  (info->value * (item_count - 1)));
                        break;
 
                case ACPI_RSC_COUNT16:
 
-                       item_count = *((u16 *) source);
+                       item_count = ACPI_GET16(source);
                        aml_length = (u16) (aml_length + item_count);
                        acpi_rs_set_resource_length(aml_length, aml);
                        break;
@@ -453,20 +450,21 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
                        /*
                         * 8-bit encoded bitmask (DMA macro)
                         */
-                       *((u8 *) destination) = (u8)
+                       ACPI_SET8(destination) = (u8)
                            acpi_rs_encode_bitmask(source,
-                                                  *(((u8 *) resource) +
-                                                    info->value));
+                                                  *ACPI_ADD_PTR(u8, resource,
+                                                                info->value));
                        break;
 
                case ACPI_RSC_BITMASK16:
                        /*
                         * 16-bit encoded bitmask (IRQ macro)
                         */
-                       temp16 =
-                           acpi_rs_encode_bitmask(source,
-                                                  *(((u8 *) resource) +
-                                                    info->value));
+                       temp16 = acpi_rs_encode_bitmask(source,
+                                                       *ACPI_ADD_PTR(u8,
+                                                                     resource,
+                                                                     info->
+                                                                     value));
                        ACPI_MOVE_16_TO_16(destination, &temp16);
                        break;
 
@@ -485,24 +483,25 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
                         */
                        switch (COMPARE_OPCODE(info)) {
                        case ACPI_RSC_COMPARE_VALUE:
-                               if (*
-                                   ((u8 *) (((u8 *) resource) +
-                                            COMPARE_TARGET(info))) !=
+
+                               if (*ACPI_ADD_PTR(u8, resource,
+                                                 COMPARE_TARGET(info)) !=
                                    COMPARE_VALUE(info)) {
                                        goto exit;
                                }
                                break;
 
                        default:
-                               acpi_os_printf
-                                   ("*** Invalid conversion sub-opcode\n");
+
+                               ACPI_ERROR((AE_INFO,
+                                           "Invalid conversion sub-opcode"));
                                return_ACPI_STATUS(AE_BAD_PARAMETER);
                        }
                        break;
 
                default:
 
-                       acpi_os_printf("*** Invalid conversion opcode\n");
+                       ACPI_ERROR((AE_INFO, "Invalid conversion opcode"));
                        return_ACPI_STATUS(AE_BAD_PARAMETER);
                }
 
@@ -531,22 +530,22 @@ if (((aml->irq.flags & 0x09) == 0x00) || ((aml->irq.flags & 0x09) == 0x09)) {
         * polarity/trigger interrupts are allowed (ACPI spec, section
         * "IRQ Format"), so 0x00 and 0x09 are illegal.
         */
-       ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
-                         "Invalid interrupt polarity/trigger in resource list, %X\n",
-                         aml->irq.flags));
+       ACPI_ERROR((AE_INFO,
+                   "Invalid interrupt polarity/trigger in resource list, %X",
+                   aml->irq.flags));
        return_ACPI_STATUS(AE_BAD_DATA);
 }
 
 resource->data.extended_irq.interrupt_count = temp8;
 if (temp8 < 1) {
+
        /* Must have at least one IRQ */
 
        return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
 }
 
 if (resource->data.dma.transfer == 0x03) {
-       ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
-                         "Invalid DMA.Transfer preference (3)\n"));
+       ACPI_ERROR((AE_INFO, "Invalid DMA.Transfer preference (3)"));
        return_ACPI_STATUS(AE_BAD_DATA);
 }
 #endif