diff options
author | Lv Zheng <lv.zheng@intel.com> | 2016-05-05 00:58:39 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-05-05 09:22:27 -0400 |
commit | b314a172ee968d45f72dffea68ab8af38aa80ded (patch) | |
tree | fde8dae9e9616f7acc4fab60a58463a9d16a49c7 | |
parent | e35d75024b28083b0a84cdb73b826f8450b29d49 (diff) |
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 <jhb@freebsd.org>, fixed by Lv Zheng <lv.zheng@intel.com>, tested
by Jung-uk Kim <jkim@freebsd.org>.
Link: https://github.com/acpica/acpica/commit/c49a751b
Reported-by: John Baldwin <jhb@freebsd.org>
Tested-by Jung-uk Kim <jkim@freebsd.org>.
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>
-rw-r--r-- | drivers/acpi/acpica/hwregs.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c index 035fb52c3bcd..892e677f524f 100644 --- a/drivers/acpi/acpica/hwregs.c +++ b/drivers/acpi/acpica/hwregs.c | |||
@@ -51,6 +51,10 @@ ACPI_MODULE_NAME("hwregs") | |||
51 | 51 | ||
52 | #if (!ACPI_REDUCED_HARDWARE) | 52 | #if (!ACPI_REDUCED_HARDWARE) |
53 | /* Local Prototypes */ | 53 | /* Local Prototypes */ |
54 | static u8 | ||
55 | acpi_hw_get_access_bit_width(struct acpi_generic_address *reg, | ||
56 | u8 max_bit_width); | ||
57 | |||
54 | static acpi_status | 58 | static acpi_status |
55 | acpi_hw_read_multiple(u32 *value, | 59 | acpi_hw_read_multiple(u32 *value, |
56 | struct acpi_generic_address *register_a, | 60 | struct acpi_generic_address *register_a, |
@@ -65,6 +69,48 @@ acpi_hw_write_multiple(u32 value, | |||
65 | 69 | ||
66 | /****************************************************************************** | 70 | /****************************************************************************** |
67 | * | 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, ®->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 | |||
112 | /****************************************************************************** | ||
113 | * | ||
68 | * FUNCTION: acpi_hw_validate_register | 114 | * FUNCTION: acpi_hw_validate_register |
69 | * | 115 | * |
70 | * PARAMETERS: reg - GAS register structure | 116 | * PARAMETERS: reg - GAS register structure |
@@ -122,8 +168,7 @@ acpi_hw_validate_register(struct acpi_generic_address *reg, | |||
122 | 168 | ||
123 | /* Validate the bit_width, convert access_width into number of bits */ | 169 | /* Validate the bit_width, convert access_width into number of bits */ |
124 | 170 | ||
125 | access_width = reg->access_width ? reg->access_width : 1; | 171 | access_width = acpi_hw_get_access_bit_width(reg, max_bit_width); |
126 | access_width = 1 << (access_width + 2); | ||
127 | bit_width = | 172 | bit_width = |
128 | ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width); | 173 | ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width); |
129 | if (max_bit_width < bit_width) { | 174 | if (max_bit_width < bit_width) { |