Skip to content

Commit b314a17

Browse files
Lv Zhengrafaeljw
authored andcommitted
ACPICA: Hardware: Add optimized access bit width support
ACPICA commit c49a751b4dae7baec1790748a2b4b6e8ab599f51 For Access Size = 0, it actually can use user expected access bit width. This patch implements this. Besides of the ACPICA upstream commit, this patch also includes a fix fixing the issue reported by the FreeBSD community. The old register descriptors are translated in acpi_tb_init_generic_address() with access_width being filled with 0. This breaks code in acpi_hw_get_access_bit_width() when the registers are 16-bit IO ports and their bit_width fields are filled with 16. The rapid fix is meant to make code written for acpi_hw_get_access_bit_width() regression safer before the issue is correctly fixed from acpi_tb_init_generic_address(). Reported by John Baldwin <[email protected]>, fixed by Lv Zheng <[email protected]>, tested by Jung-uk Kim <[email protected]>. Link: acpica/acpica@c49a751b Reported-by: John Baldwin <[email protected]> Tested-by Jung-uk Kim <[email protected]>. Signed-off-by: Lv Zheng <[email protected]> Signed-off-by: Bob Moore <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e35d750 commit b314a17

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

drivers/acpi/acpica/hwregs.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ ACPI_MODULE_NAME("hwregs")
5151

5252
#if (!ACPI_REDUCED_HARDWARE)
5353
/* Local Prototypes */
54+
static u8
55+
acpi_hw_get_access_bit_width(struct acpi_generic_address *reg,
56+
u8 max_bit_width);
57+
5458
static acpi_status
5559
acpi_hw_read_multiple(u32 *value,
5660
struct acpi_generic_address *register_a,
@@ -63,6 +67,48 @@ acpi_hw_write_multiple(u32 value,
6367

6468
#endif /* !ACPI_REDUCED_HARDWARE */
6569

70+
/******************************************************************************
71+
*
72+
* FUNCTION: acpi_hw_get_access_bit_width
73+
*
74+
* PARAMETERS: reg - GAS register structure
75+
* max_bit_width - Max bit_width supported (32 or 64)
76+
*
77+
* RETURN: Status
78+
*
79+
* DESCRIPTION: Obtain optimal access bit width
80+
*
81+
******************************************************************************/
82+
83+
static u8
84+
acpi_hw_get_access_bit_width(struct acpi_generic_address *reg, u8 max_bit_width)
85+
{
86+
u64 address;
87+
88+
if (!reg->access_width) {
89+
/*
90+
* Detect old register descriptors where only the bit_width field
91+
* makes senses. The target address is copied to handle possible
92+
* alignment issues.
93+
*/
94+
ACPI_MOVE_64_TO_64(&address, &reg->address);
95+
if (!reg->bit_offset && reg->bit_width &&
96+
ACPI_IS_POWER_OF_TWO(reg->bit_width) &&
97+
ACPI_IS_ALIGNED(reg->bit_width, 8) &&
98+
ACPI_IS_ALIGNED(address, reg->bit_width)) {
99+
return (reg->bit_width);
100+
} else {
101+
if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
102+
return (32);
103+
} else {
104+
return (max_bit_width);
105+
}
106+
}
107+
} else {
108+
return (1 << (reg->access_width + 2));
109+
}
110+
}
111+
66112
/******************************************************************************
67113
*
68114
* FUNCTION: acpi_hw_validate_register
@@ -122,8 +168,7 @@ acpi_hw_validate_register(struct acpi_generic_address *reg,
122168

123169
/* Validate the bit_width, convert access_width into number of bits */
124170

125-
access_width = reg->access_width ? reg->access_width : 1;
126-
access_width = 1 << (access_width + 2);
171+
access_width = acpi_hw_get_access_bit_width(reg, max_bit_width);
127172
bit_width =
128173
ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width);
129174
if (max_bit_width < bit_width) {

0 commit comments

Comments
 (0)