Skip to content

Commit

Permalink
ACPICA: Enhance the ACPI_GETx and ACPI_SETx macros.
Browse files Browse the repository at this point in the history
Improve the implementation of the macros.  Change the SETx macros
to the style of (destination, source).  Also add ACPI_CASTx
companion macros.  Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Lv Zheng authored and Rafael J. Wysocki committed Jan 10, 2013
1 parent 2f3faab commit 57bf6ae
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 45 deletions.
20 changes: 12 additions & 8 deletions drivers/acpi/acpica/acmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@
* get into potential aligment issues -- see the STORE macros below.
* Use with care.
*/
#define ACPI_GET8(ptr) *ACPI_CAST_PTR (u8, ptr)
#define ACPI_GET16(ptr) *ACPI_CAST_PTR (u16, ptr)
#define ACPI_GET32(ptr) *ACPI_CAST_PTR (u32, ptr)
#define ACPI_GET64(ptr) *ACPI_CAST_PTR (u64, ptr)
#define ACPI_SET8(ptr) *ACPI_CAST_PTR (u8, ptr)
#define ACPI_SET16(ptr) *ACPI_CAST_PTR (u16, ptr)
#define ACPI_SET32(ptr) *ACPI_CAST_PTR (u32, ptr)
#define ACPI_SET64(ptr) *ACPI_CAST_PTR (u64, ptr)
#define ACPI_CAST8(ptr) ACPI_CAST_PTR (u8, (ptr))
#define ACPI_CAST16(ptr) ACPI_CAST_PTR (u16, (ptr))
#define ACPI_CAST32(ptr) ACPI_CAST_PTR (u32, (ptr))
#define ACPI_CAST64(ptr) ACPI_CAST_PTR (u64, (ptr))
#define ACPI_GET8(ptr) (*ACPI_CAST8 (ptr))
#define ACPI_GET16(ptr) (*ACPI_CAST16 (ptr))
#define ACPI_GET32(ptr) (*ACPI_CAST32 (ptr))
#define ACPI_GET64(ptr) (*ACPI_CAST64 (ptr))
#define ACPI_SET8(ptr, val) (*ACPI_CAST8 (ptr) = (u8) (val))
#define ACPI_SET16(ptr, val) (*ACPI_CAST16 (ptr) = (u16) (val))
#define ACPI_SET32(ptr, val) (*ACPI_CAST32 (ptr) = (u32) (val))
#define ACPI_SET64(ptr, val) (*ACPI_CAST64 (ptr) = (u64) (val))

/*
* printf() format helpers
Expand Down
8 changes: 4 additions & 4 deletions drivers/acpi/acpica/exregion.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@ acpi_ex_system_memory_space_handler(u32 function,

switch (bit_width) {
case 8:
ACPI_SET8(logical_addr_ptr) = (u8)*value;
ACPI_SET8(logical_addr_ptr, *value);
break;

case 16:
ACPI_SET16(logical_addr_ptr) = (u16)*value;
ACPI_SET16(logical_addr_ptr, *value);
break;

case 32:
ACPI_SET32(logical_addr_ptr) = (u32)*value;
ACPI_SET32(logical_addr_ptr, *value);
break;

case 64:
ACPI_SET64(logical_addr_ptr) = (u64)*value;
ACPI_SET64(logical_addr_ptr, *value);
break;

default:
Expand Down
71 changes: 38 additions & 33 deletions drivers/acpi/acpica/rsmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,30 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
/*
* Mask and shift the flag bit
*/
ACPI_SET8(destination) = (u8)
((ACPI_GET8(source) >> info->value) & 0x01);
ACPI_SET8(destination,
((ACPI_GET8(source) >> info->value) & 0x01));
break;

case ACPI_RSC_2BITFLAG:
/*
* Mask and shift the flag bits
*/
ACPI_SET8(destination) = (u8)
((ACPI_GET8(source) >> info->value) & 0x03);
ACPI_SET8(destination,
((ACPI_GET8(source) >> info->value) & 0x03));
break;

case ACPI_RSC_3BITFLAG:
/*
* Mask and shift the flag bits
*/
ACPI_SET8(destination) = (u8)
((ACPI_GET8(source) >> info->value) & 0x07);
ACPI_SET8(destination,
((ACPI_GET8(source) >> info->value) & 0x07));
break;

case ACPI_RSC_COUNT:

item_count = ACPI_GET8(source);
ACPI_SET8(destination) = (u8)item_count;
ACPI_SET8(destination, item_count);

resource->length = resource->length +
(info->value * (item_count - 1));
Expand All @@ -168,7 +168,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
case ACPI_RSC_COUNT16:

item_count = aml_resource_length;
ACPI_SET16(destination) = item_count;
ACPI_SET16(destination, item_count);

resource->length = resource->length +
(info->value * (item_count - 1));
Expand All @@ -181,13 +181,13 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,

resource->length = resource->length + item_count;
item_count = item_count / 2;
ACPI_SET16(destination) = item_count;
ACPI_SET16(destination, item_count);
break;

case ACPI_RSC_COUNT_GPIO_VEN:

item_count = ACPI_GET8(source);
ACPI_SET8(destination) = (u8)item_count;
ACPI_SET8(destination, item_count);

resource->length = resource->length +
(info->value * item_count);
Expand Down Expand Up @@ -216,15 +216,15 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
}

resource->length = resource->length + item_count;
ACPI_SET16(destination) = item_count;
ACPI_SET16(destination, item_count);
break;

case ACPI_RSC_COUNT_SERIAL_VEN:

item_count = ACPI_GET16(source) - info->value;

resource->length = resource->length + item_count;
ACPI_SET16(destination) = item_count;
ACPI_SET16(destination, item_count);
break;

case ACPI_RSC_COUNT_SERIAL_RES:
Expand All @@ -234,7 +234,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
- ACPI_GET16(source) - info->value;

resource->length = resource->length + item_count;
ACPI_SET16(destination) = item_count;
ACPI_SET16(destination, item_count);
break;

case ACPI_RSC_LENGTH:
Expand Down Expand Up @@ -385,7 +385,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
}

target = ACPI_ADD_PTR(char, resource, info->value);
ACPI_SET8(target) = (u8)item_count;
ACPI_SET8(target, item_count);
break;

case ACPI_RSC_BITMASK16:
Expand All @@ -401,7 +401,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
}

target = ACPI_ADD_PTR(char, resource, info->value);
ACPI_SET8(target) = (u8)item_count;
ACPI_SET8(target, item_count);
break;

case ACPI_RSC_EXIT_NE:
Expand Down Expand Up @@ -514,37 +514,40 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
/*
* Clear the flag byte
*/
ACPI_SET8(destination) = 0;
ACPI_SET8(destination, 0);
break;

case ACPI_RSC_1BITFLAG:
/*
* Mask and shift the flag bit
*/
ACPI_SET8(destination) |= (u8)
((ACPI_GET8(source) & 0x01) << info->value);
ACPI_SET_BIT(*ACPI_CAST8(destination), (u8)
((ACPI_GET8(source) & 0x01) << info->
value));
break;

case ACPI_RSC_2BITFLAG:
/*
* Mask and shift the flag bits
*/
ACPI_SET8(destination) |= (u8)
((ACPI_GET8(source) & 0x03) << info->value);
ACPI_SET_BIT(*ACPI_CAST8(destination), (u8)
((ACPI_GET8(source) & 0x03) << info->
value));
break;

case ACPI_RSC_3BITFLAG:
/*
* Mask and shift the flag bits
*/
ACPI_SET8(destination) |= (u8)
((ACPI_GET8(source) & 0x07) << info->value);
ACPI_SET_BIT(*ACPI_CAST8(destination), (u8)
((ACPI_GET8(source) & 0x07) << info->
value));
break;

case ACPI_RSC_COUNT:

item_count = ACPI_GET8(source);
ACPI_SET8(destination) = (u8)item_count;
ACPI_SET8(destination, item_count);

aml_length =
(u16) (aml_length +
Expand All @@ -561,18 +564,18 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
case ACPI_RSC_COUNT_GPIO_PIN:

item_count = ACPI_GET16(source);
ACPI_SET16(destination) = (u16)aml_length;
ACPI_SET16(destination, aml_length);

aml_length = (u16)(aml_length + item_count * 2);
target = ACPI_ADD_PTR(void, aml, info->value);
ACPI_SET16(target) = (u16)aml_length;
ACPI_SET16(target, aml_length);
acpi_rs_set_resource_length(aml_length, aml);
break;

case ACPI_RSC_COUNT_GPIO_VEN:

item_count = ACPI_GET16(source);
ACPI_SET16(destination) = (u16)item_count;
ACPI_SET16(destination, item_count);

aml_length =
(u16)(aml_length + (info->value * item_count));
Expand All @@ -584,7 +587,7 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
/* Set resource source string length */

item_count = ACPI_GET16(source);
ACPI_SET16(destination) = (u16)aml_length;
ACPI_SET16(destination, aml_length);

/* Compute offset for the Vendor Data */

Expand All @@ -594,7 +597,7 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
/* Set vendor offset only if there is vendor data */

if (resource->data.gpio.vendor_length) {
ACPI_SET16(target) = (u16)aml_length;
ACPI_SET16(target, aml_length);
}

acpi_rs_set_resource_length(aml_length, aml);
Expand All @@ -603,7 +606,7 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
case ACPI_RSC_COUNT_SERIAL_VEN:

item_count = ACPI_GET16(source);
ACPI_SET16(destination) = item_count + info->value;
ACPI_SET16(destination, item_count + info->value);
aml_length = (u16)(aml_length + item_count);
acpi_rs_set_resource_length(aml_length, aml);
break;
Expand Down Expand Up @@ -707,10 +710,12 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
/*
* 8-bit encoded bitmask (DMA macro)
*/
ACPI_SET8(destination) = (u8)
acpi_rs_encode_bitmask(source,
*ACPI_ADD_PTR(u8, resource,
info->value));
ACPI_SET8(destination,
acpi_rs_encode_bitmask(source,
*ACPI_ADD_PTR(u8,
resource,
info->
value)));
break;

case ACPI_RSC_BITMASK16:
Expand Down

0 comments on commit 57bf6ae

Please sign in to comment.