Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: hwregs - Read/write access functions for the various ACPI |
| 4 | * control and status registers. |
| 5 | * |
| 6 | ******************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | c8100dc | 2016-01-15 08:17:03 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2016, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.h" |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 47 | #include "acevents.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_HARDWARE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("hwregs") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 52 | #if (!ACPI_REDUCED_HARDWARE) |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 53 | /* Local Prototypes */ |
Lv Zheng | b314a17 | 2016-05-05 12:58:39 +0800 | [diff] [blame] | 54 | static u8 |
| 55 | acpi_hw_get_access_bit_width(struct acpi_generic_address *reg, |
| 56 | u8 max_bit_width); |
| 57 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 58 | static acpi_status |
| 59 | acpi_hw_read_multiple(u32 *value, |
| 60 | struct acpi_generic_address *register_a, |
| 61 | struct acpi_generic_address *register_b); |
| 62 | |
| 63 | static acpi_status |
| 64 | acpi_hw_write_multiple(u32 value, |
| 65 | struct acpi_generic_address *register_a, |
| 66 | struct acpi_generic_address *register_b); |
| 67 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 68 | #endif /* !ACPI_REDUCED_HARDWARE */ |
| 69 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 70 | /****************************************************************************** |
| 71 | * |
Lv Zheng | b314a17 | 2016-05-05 12:58:39 +0800 | [diff] [blame] | 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 | * |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 114 | * FUNCTION: acpi_hw_validate_register |
| 115 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 116 | * PARAMETERS: reg - GAS register structure |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 117 | * max_bit_width - Max bit_width supported (32 or 64) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 118 | * address - Pointer to where the gas->address |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 119 | * is returned |
| 120 | * |
| 121 | * RETURN: Status |
| 122 | * |
| 123 | * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS |
| 124 | * pointer, Address, space_id, bit_width, and bit_offset. |
| 125 | * |
| 126 | ******************************************************************************/ |
| 127 | |
| 128 | acpi_status |
| 129 | acpi_hw_validate_register(struct acpi_generic_address *reg, |
| 130 | u8 max_bit_width, u64 *address) |
| 131 | { |
Lv Zheng | 920de6e | 2016-03-24 09:41:09 +0800 | [diff] [blame] | 132 | u8 bit_width; |
| 133 | u8 access_width; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 134 | |
| 135 | /* Must have a valid pointer to a GAS structure */ |
| 136 | |
| 137 | if (!reg) { |
| 138 | return (AE_BAD_PARAMETER); |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * Copy the target address. This handles possible alignment issues. |
| 143 | * Address must not be null. A null address also indicates an optional |
| 144 | * ACPI register that is not supported, so no error message. |
| 145 | */ |
| 146 | ACPI_MOVE_64_TO_64(address, ®->address); |
| 147 | if (!(*address)) { |
| 148 | return (AE_BAD_ADDRESS); |
| 149 | } |
| 150 | |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 151 | /* Validate the space_ID */ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 152 | |
| 153 | if ((reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) && |
| 154 | (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) { |
| 155 | ACPI_ERROR((AE_INFO, |
| 156 | "Unsupported address space: 0x%X", reg->space_id)); |
| 157 | return (AE_SUPPORT); |
| 158 | } |
| 159 | |
Lv Zheng | 920de6e | 2016-03-24 09:41:09 +0800 | [diff] [blame] | 160 | /* Validate the access_width */ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 161 | |
Lv Zheng | 920de6e | 2016-03-24 09:41:09 +0800 | [diff] [blame] | 162 | if (reg->access_width > 4) { |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 163 | ACPI_ERROR((AE_INFO, |
Lv Zheng | 920de6e | 2016-03-24 09:41:09 +0800 | [diff] [blame] | 164 | "Unsupported register access width: 0x%X", |
| 165 | reg->access_width)); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 166 | return (AE_SUPPORT); |
| 167 | } |
| 168 | |
Lv Zheng | 920de6e | 2016-03-24 09:41:09 +0800 | [diff] [blame] | 169 | /* Validate the bit_width, convert access_width into number of bits */ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 170 | |
Lv Zheng | b314a17 | 2016-05-05 12:58:39 +0800 | [diff] [blame] | 171 | access_width = acpi_hw_get_access_bit_width(reg, max_bit_width); |
Lv Zheng | 920de6e | 2016-03-24 09:41:09 +0800 | [diff] [blame] | 172 | bit_width = |
| 173 | ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width); |
| 174 | if (max_bit_width < bit_width) { |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 175 | ACPI_WARNING((AE_INFO, |
Lv Zheng | 920de6e | 2016-03-24 09:41:09 +0800 | [diff] [blame] | 176 | "Requested bit width 0x%X is smaller than register bit width 0x%X", |
| 177 | max_bit_width, bit_width)); |
| 178 | return (AE_SUPPORT); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | return (AE_OK); |
| 182 | } |
| 183 | |
| 184 | /****************************************************************************** |
| 185 | * |
| 186 | * FUNCTION: acpi_hw_read |
| 187 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 188 | * PARAMETERS: value - Where the value is returned |
| 189 | * reg - GAS register structure |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 190 | * |
| 191 | * RETURN: Status |
| 192 | * |
| 193 | * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max |
| 194 | * version of acpi_read, used internally since the overhead of |
| 195 | * 64-bit values is not needed. |
| 196 | * |
| 197 | * LIMITATIONS: <These limitations also apply to acpi_hw_write> |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 198 | * space_ID must be system_memory or system_IO. |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 199 | * |
| 200 | ******************************************************************************/ |
| 201 | |
| 202 | acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg) |
| 203 | { |
| 204 | u64 address; |
Lv Zheng | c3bc26d | 2016-05-05 12:58:52 +0800 | [diff] [blame] | 205 | u8 access_width; |
| 206 | u32 bit_width; |
| 207 | u8 bit_offset; |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 208 | u64 value64; |
Lv Zheng | c3bc26d | 2016-05-05 12:58:52 +0800 | [diff] [blame] | 209 | u32 value32; |
| 210 | u8 index; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 211 | acpi_status status; |
| 212 | |
| 213 | ACPI_FUNCTION_NAME(hw_read); |
| 214 | |
| 215 | /* Validate contents of the GAS register */ |
| 216 | |
| 217 | status = acpi_hw_validate_register(reg, 32, &address); |
| 218 | if (ACPI_FAILURE(status)) { |
| 219 | return (status); |
| 220 | } |
| 221 | |
Lv Zheng | c3bc26d | 2016-05-05 12:58:52 +0800 | [diff] [blame] | 222 | /* |
| 223 | * Initialize entire 32-bit return value to zero, convert access_width |
| 224 | * into number of bits based |
| 225 | */ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 226 | *value = 0; |
Lv Zheng | c3bc26d | 2016-05-05 12:58:52 +0800 | [diff] [blame] | 227 | access_width = acpi_hw_get_access_bit_width(reg, 32); |
| 228 | bit_width = reg->bit_offset + reg->bit_width; |
| 229 | bit_offset = reg->bit_offset; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * Two address spaces supported: Memory or IO. PCI_Config is |
| 233 | * not supported here because the GAS structure is insufficient |
| 234 | */ |
Lv Zheng | c3bc26d | 2016-05-05 12:58:52 +0800 | [diff] [blame] | 235 | index = 0; |
| 236 | while (bit_width) { |
| 237 | if (bit_offset >= access_width) { |
| 238 | value32 = 0; |
| 239 | bit_offset -= access_width; |
| 240 | } else { |
| 241 | if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 242 | status = |
| 243 | acpi_os_read_memory((acpi_physical_address) |
| 244 | address + |
| 245 | index * |
| 246 | ACPI_DIV_8 |
| 247 | (access_width), |
| 248 | &value64, access_width); |
| 249 | value32 = (u32)value64; |
| 250 | } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 251 | |
Lv Zheng | c3bc26d | 2016-05-05 12:58:52 +0800 | [diff] [blame] | 252 | status = acpi_hw_read_port((acpi_io_address) |
| 253 | address + |
| 254 | index * |
| 255 | ACPI_DIV_8 |
| 256 | (access_width), |
| 257 | &value32, |
| 258 | access_width); |
| 259 | } |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 260 | |
Lv Zheng | c3bc26d | 2016-05-05 12:58:52 +0800 | [diff] [blame] | 261 | /* |
| 262 | * Use offset style bit masks because: |
| 263 | * bit_offset < access_width/bit_width < access_width, and |
| 264 | * access_width is ensured to be less than 32-bits by |
| 265 | * acpi_hw_validate_register(). |
| 266 | */ |
| 267 | if (bit_offset) { |
| 268 | value32 &= ACPI_MASK_BITS_BELOW(bit_offset); |
| 269 | bit_offset = 0; |
| 270 | } |
| 271 | if (bit_width < access_width) { |
| 272 | value32 &= ACPI_MASK_BITS_ABOVE(bit_width); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * Use offset style bit writes because "Index * AccessWidth" is |
| 278 | * ensured to be less than 32-bits by acpi_hw_validate_register(). |
| 279 | */ |
| 280 | ACPI_SET_BITS(value, index * access_width, |
| 281 | ACPI_MASK_BITS_ABOVE_32(access_width), value32); |
| 282 | |
| 283 | bit_width -= |
| 284 | bit_width > access_width ? access_width : bit_width; |
| 285 | index++; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 289 | "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", |
Lv Zheng | c3bc26d | 2016-05-05 12:58:52 +0800 | [diff] [blame] | 290 | *value, access_width, ACPI_FORMAT_UINT64(address), |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 291 | acpi_ut_get_region_name(reg->space_id))); |
| 292 | |
| 293 | return (status); |
| 294 | } |
| 295 | |
| 296 | /****************************************************************************** |
| 297 | * |
| 298 | * FUNCTION: acpi_hw_write |
| 299 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 300 | * PARAMETERS: value - Value to be written |
| 301 | * reg - GAS register structure |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 302 | * |
| 303 | * RETURN: Status |
| 304 | * |
| 305 | * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max |
| 306 | * version of acpi_write, used internally since the overhead of |
| 307 | * 64-bit values is not needed. |
| 308 | * |
| 309 | ******************************************************************************/ |
| 310 | |
| 311 | acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg) |
| 312 | { |
| 313 | u64 address; |
Lv Zheng | 66b1ed5 | 2016-05-05 13:00:29 +0800 | [diff] [blame] | 314 | u8 access_width; |
| 315 | u32 bit_width; |
| 316 | u8 bit_offset; |
| 317 | u64 value64; |
| 318 | u32 new_value32, old_value32; |
| 319 | u8 index; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 320 | acpi_status status; |
| 321 | |
| 322 | ACPI_FUNCTION_NAME(hw_write); |
| 323 | |
| 324 | /* Validate contents of the GAS register */ |
| 325 | |
| 326 | status = acpi_hw_validate_register(reg, 32, &address); |
| 327 | if (ACPI_FAILURE(status)) { |
| 328 | return (status); |
| 329 | } |
| 330 | |
Lv Zheng | 66b1ed5 | 2016-05-05 13:00:29 +0800 | [diff] [blame] | 331 | /* Convert access_width into number of bits based */ |
| 332 | |
| 333 | access_width = acpi_hw_get_access_bit_width(reg, 32); |
| 334 | bit_width = reg->bit_offset + reg->bit_width; |
| 335 | bit_offset = reg->bit_offset; |
| 336 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 337 | /* |
| 338 | * Two address spaces supported: Memory or IO. PCI_Config is |
| 339 | * not supported here because the GAS structure is insufficient |
| 340 | */ |
Lv Zheng | 66b1ed5 | 2016-05-05 13:00:29 +0800 | [diff] [blame] | 341 | index = 0; |
| 342 | while (bit_width) { |
| 343 | /* |
| 344 | * Use offset style bit reads because "Index * AccessWidth" is |
| 345 | * ensured to be less than 32-bits by acpi_hw_validate_register(). |
| 346 | */ |
| 347 | new_value32 = ACPI_GET_BITS(&value, index * access_width, |
| 348 | ACPI_MASK_BITS_ABOVE_32 |
| 349 | (access_width)); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 350 | |
Lv Zheng | 66b1ed5 | 2016-05-05 13:00:29 +0800 | [diff] [blame] | 351 | if (bit_offset >= access_width) { |
| 352 | bit_offset -= access_width; |
| 353 | } else { |
| 354 | /* |
| 355 | * Use offset style bit masks because access_width is ensured |
| 356 | * to be less than 32-bits by acpi_hw_validate_register() and |
| 357 | * bit_offset/bit_width is less than access_width here. |
| 358 | */ |
| 359 | if (bit_offset) { |
| 360 | new_value32 &= ACPI_MASK_BITS_BELOW(bit_offset); |
| 361 | } |
| 362 | if (bit_width < access_width) { |
| 363 | new_value32 &= ACPI_MASK_BITS_ABOVE(bit_width); |
| 364 | } |
| 365 | |
| 366 | if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 367 | if (bit_offset || bit_width < access_width) { |
| 368 | /* |
| 369 | * Read old values in order not to modify the bits that |
| 370 | * are beyond the register bit_width/bit_offset setting. |
| 371 | */ |
| 372 | status = |
| 373 | acpi_os_read_memory((acpi_physical_address) |
| 374 | address + |
| 375 | index * |
| 376 | ACPI_DIV_8 |
| 377 | (access_width), |
| 378 | &value64, |
| 379 | access_width); |
| 380 | old_value32 = (u32)value64; |
| 381 | |
| 382 | /* |
| 383 | * Use offset style bit masks because access_width is |
| 384 | * ensured to be less than 32-bits by |
| 385 | * acpi_hw_validate_register() and bit_offset/bit_width is |
| 386 | * less than access_width here. |
| 387 | */ |
| 388 | if (bit_offset) { |
| 389 | old_value32 &= |
| 390 | ACPI_MASK_BITS_ABOVE |
| 391 | (bit_offset); |
| 392 | bit_offset = 0; |
| 393 | } |
| 394 | if (bit_width < access_width) { |
| 395 | old_value32 &= |
| 396 | ACPI_MASK_BITS_BELOW |
| 397 | (bit_width); |
| 398 | } |
| 399 | |
| 400 | new_value32 |= old_value32; |
| 401 | } |
| 402 | |
| 403 | value64 = (u64)new_value32; |
| 404 | status = |
| 405 | acpi_os_write_memory((acpi_physical_address) |
| 406 | address + |
| 407 | index * |
| 408 | ACPI_DIV_8 |
| 409 | (access_width), |
| 410 | value64, access_width); |
| 411 | } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ |
| 412 | |
| 413 | if (bit_offset || bit_width < access_width) { |
| 414 | /* |
| 415 | * Read old values in order not to modify the bits that |
| 416 | * are beyond the register bit_width/bit_offset setting. |
| 417 | */ |
| 418 | status = |
| 419 | acpi_hw_read_port((acpi_io_address) |
| 420 | address + |
| 421 | index * |
| 422 | ACPI_DIV_8 |
| 423 | (access_width), |
| 424 | &old_value32, |
| 425 | access_width); |
| 426 | |
| 427 | /* |
| 428 | * Use offset style bit masks because access_width is |
| 429 | * ensured to be less than 32-bits by |
| 430 | * acpi_hw_validate_register() and bit_offset/bit_width is |
| 431 | * less than access_width here. |
| 432 | */ |
| 433 | if (bit_offset) { |
| 434 | old_value32 &= |
| 435 | ACPI_MASK_BITS_ABOVE |
| 436 | (bit_offset); |
| 437 | bit_offset = 0; |
| 438 | } |
| 439 | if (bit_width < access_width) { |
| 440 | old_value32 &= |
| 441 | ACPI_MASK_BITS_BELOW |
| 442 | (bit_width); |
| 443 | } |
| 444 | |
| 445 | new_value32 |= old_value32; |
| 446 | } |
| 447 | |
| 448 | status = acpi_hw_write_port((acpi_io_address) |
| 449 | address + |
| 450 | index * |
| 451 | ACPI_DIV_8 |
| 452 | (access_width), |
| 453 | new_value32, |
| 454 | access_width); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Index * access_width is ensured to be less than 32-bits by |
| 460 | * acpi_hw_validate_register(). |
| 461 | */ |
| 462 | bit_width -= |
| 463 | bit_width > access_width ? access_width : bit_width; |
| 464 | index++; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 468 | "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", |
Lv Zheng | 66b1ed5 | 2016-05-05 13:00:29 +0800 | [diff] [blame] | 469 | value, access_width, ACPI_FORMAT_UINT64(address), |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 470 | acpi_ut_get_region_name(reg->space_id))); |
| 471 | |
| 472 | return (status); |
| 473 | } |
| 474 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 475 | #if (!ACPI_REDUCED_HARDWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | /******************************************************************************* |
| 477 | * |
| 478 | * FUNCTION: acpi_hw_clear_acpi_status |
| 479 | * |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 480 | * PARAMETERS: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 482 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | * |
| 484 | * DESCRIPTION: Clears all fixed and general purpose status bits |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | * |
| 486 | ******************************************************************************/ |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 487 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 488 | acpi_status acpi_hw_clear_acpi_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 490 | acpi_status status; |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 491 | acpi_cpu_flags lock_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 493 | ACPI_FUNCTION_TRACE(hw_clear_acpi_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Bob Moore | 8eb7b24 | 2009-04-22 10:28:22 +0800 | [diff] [blame] | 495 | ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | ACPI_BITMASK_ALL_FIXED_STATUS, |
Bob Moore | 8eb7b24 | 2009-04-22 10:28:22 +0800 | [diff] [blame] | 497 | ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 499 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Bob Moore | 227243a | 2009-02-18 14:24:50 +0800 | [diff] [blame] | 501 | /* Clear the fixed events in PM1 A/B */ |
Bob Moore | 531c633 | 2009-02-18 14:06:12 +0800 | [diff] [blame] | 502 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 503 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | ACPI_BITMASK_ALL_FIXED_STATUS); |
Rakib Mullick | f7f71cf | 2011-11-06 21:18:17 +0600 | [diff] [blame] | 505 | |
| 506 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); |
| 507 | |
Lv Zheng | 7d3e83b | 2014-07-08 10:08:19 +0800 | [diff] [blame] | 508 | if (ACPI_FAILURE(status)) { |
Rakib Mullick | f7f71cf | 2011-11-06 21:18:17 +0600 | [diff] [blame] | 509 | goto exit; |
Lv Zheng | 7d3e83b | 2014-07-08 10:08:19 +0800 | [diff] [blame] | 510 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | /* Clear the GPE Bits in all GPE registers in all GPE blocks */ |
| 513 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 514 | status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Rakib Mullick | f7f71cf | 2011-11-06 21:18:17 +0600 | [diff] [blame] | 516 | exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | /******************************************************************************* |
| 521 | * |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 522 | * FUNCTION: acpi_hw_get_bit_register_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | * |
| 524 | * PARAMETERS: register_id - Index of ACPI Register to access |
| 525 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 526 | * RETURN: The bitmask to be used when accessing the register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 528 | * DESCRIPTION: Map register_id into a register bitmask. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | * |
| 530 | ******************************************************************************/ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 531 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 534 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
| 536 | if (register_id > ACPI_BITREG_MAX) { |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 537 | ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 538 | register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return (NULL); |
| 540 | } |
| 541 | |
| 542 | return (&acpi_gbl_bit_register_info[register_id]); |
| 543 | } |
| 544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | /****************************************************************************** |
| 546 | * |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 547 | * FUNCTION: acpi_hw_write_pm1_control |
| 548 | * |
| 549 | * PARAMETERS: pm1a_control - Value to be written to PM1A control |
| 550 | * pm1b_control - Value to be written to PM1B control |
| 551 | * |
| 552 | * RETURN: Status |
| 553 | * |
| 554 | * DESCRIPTION: Write the PM1 A/B control registers. These registers are |
| 555 | * different than than the PM1 A/B status and enable registers |
| 556 | * in that different values can be written to the A/B registers. |
| 557 | * Most notably, the SLP_TYP bits can be different, as per the |
| 558 | * values returned from the _Sx predefined methods. |
| 559 | * |
| 560 | ******************************************************************************/ |
| 561 | |
| 562 | acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control) |
| 563 | { |
| 564 | acpi_status status; |
| 565 | |
| 566 | ACPI_FUNCTION_TRACE(hw_write_pm1_control); |
| 567 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 568 | status = |
| 569 | acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block); |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 570 | if (ACPI_FAILURE(status)) { |
| 571 | return_ACPI_STATUS(status); |
| 572 | } |
| 573 | |
| 574 | if (acpi_gbl_FADT.xpm1b_control_block.address) { |
| 575 | status = |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 576 | acpi_hw_write(pm1b_control, |
| 577 | &acpi_gbl_FADT.xpm1b_control_block); |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 578 | } |
| 579 | return_ACPI_STATUS(status); |
| 580 | } |
| 581 | |
| 582 | /****************************************************************************** |
| 583 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | * FUNCTION: acpi_hw_register_read |
| 585 | * |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 586 | * PARAMETERS: register_id - ACPI Register ID |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 587 | * return_value - Where the register value is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | * |
| 589 | * RETURN: Status and the value read. |
| 590 | * |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 591 | * DESCRIPTION: Read from the specified ACPI register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | * |
| 593 | ******************************************************************************/ |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 594 | acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 596 | u32 value = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 597 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 599 | ACPI_FUNCTION_TRACE(hw_register_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | switch (register_id) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 602 | case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 604 | status = acpi_hw_read_multiple(&value, |
| 605 | &acpi_gbl_xpm1a_status, |
| 606 | &acpi_gbl_xpm1b_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | break; |
| 608 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 609 | case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 611 | status = acpi_hw_read_multiple(&value, |
| 612 | &acpi_gbl_xpm1a_enable, |
| 613 | &acpi_gbl_xpm1b_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | break; |
| 615 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 616 | case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 618 | status = acpi_hw_read_multiple(&value, |
| 619 | &acpi_gbl_FADT. |
| 620 | xpm1a_control_block, |
| 621 | &acpi_gbl_FADT. |
| 622 | xpm1b_control_block); |
Lin Ming | c3dd25f | 2009-03-19 09:51:01 +0800 | [diff] [blame] | 623 | |
| 624 | /* |
| 625 | * Zero the write-only bits. From the ACPI specification, "Hardware |
| 626 | * Write-Only Bits": "Upon reads to registers with write-only bits, |
| 627 | * software masks out all write-only bits." |
| 628 | */ |
| 629 | value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | break; |
| 631 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 632 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 634 | status = |
| 635 | acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | break; |
| 637 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 638 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 640 | status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | break; |
| 642 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 643 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 645 | status = |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 646 | acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 650 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 651 | ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | status = AE_BAD_PARAMETER; |
| 653 | break; |
| 654 | } |
| 655 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 656 | if (ACPI_SUCCESS(status)) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 657 | *return_value = value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 660 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | /****************************************************************************** |
| 664 | * |
| 665 | * FUNCTION: acpi_hw_register_write |
| 666 | * |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 667 | * PARAMETERS: register_id - ACPI Register ID |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 668 | * value - The value to write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | * |
| 670 | * RETURN: Status |
| 671 | * |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 672 | * DESCRIPTION: Write to the specified ACPI register |
| 673 | * |
| 674 | * NOTE: In accordance with the ACPI specification, this function automatically |
| 675 | * preserves the value of the following bits, meaning that these bits cannot be |
| 676 | * changed via this interface: |
| 677 | * |
| 678 | * PM1_CONTROL[0] = SCI_EN |
| 679 | * PM1_CONTROL[9] |
| 680 | * PM1_STATUS[11] |
| 681 | * |
| 682 | * ACPI References: |
| 683 | * 1) Hardware Ignored Bits: When software writes to a register with ignored |
| 684 | * bit fields, it preserves the ignored bit fields |
| 685 | * 2) SCI_EN: OSPM always preserves this bit position |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | * |
| 687 | ******************************************************************************/ |
| 688 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 689 | acpi_status acpi_hw_register_write(u32 register_id, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 691 | acpi_status status; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 692 | u32 read_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 694 | ACPI_FUNCTION_TRACE(hw_register_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | switch (register_id) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 697 | case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ |
Bob Moore | 8636f8d | 2009-03-09 16:32:20 +0800 | [diff] [blame] | 698 | /* |
| 699 | * Handle the "ignored" bit in PM1 Status. According to the ACPI |
| 700 | * specification, ignored bits are to be preserved when writing. |
| 701 | * Normally, this would mean a read/modify/write sequence. However, |
| 702 | * preserving a bit in the status register is different. Writing a |
| 703 | * one clears the status, and writing a zero preserves the status. |
| 704 | * Therefore, we must always write zero to the ignored bit. |
| 705 | * |
| 706 | * This behavior is clarified in the ACPI 4.0 specification. |
| 707 | */ |
| 708 | value &= ~ACPI_PM1_STATUS_PRESERVED_BITS; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 709 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 710 | status = acpi_hw_write_multiple(value, |
| 711 | &acpi_gbl_xpm1a_status, |
| 712 | &acpi_gbl_xpm1b_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | break; |
| 714 | |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 715 | case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 717 | status = acpi_hw_write_multiple(value, |
| 718 | &acpi_gbl_xpm1a_enable, |
| 719 | &acpi_gbl_xpm1b_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 722 | case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 723 | /* |
| 724 | * Perform a read first to preserve certain bits (per ACPI spec) |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 725 | * Note: This includes SCI_EN, we never want to change this bit |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 726 | */ |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 727 | status = acpi_hw_read_multiple(&read_value, |
| 728 | &acpi_gbl_FADT. |
| 729 | xpm1a_control_block, |
| 730 | &acpi_gbl_FADT. |
| 731 | xpm1b_control_block); |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 732 | if (ACPI_FAILURE(status)) { |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 733 | goto exit; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | /* Insert the bits to be preserved */ |
| 737 | |
| 738 | ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS, |
| 739 | read_value); |
| 740 | |
| 741 | /* Now we can write the data */ |
| 742 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 743 | status = acpi_hw_write_multiple(value, |
| 744 | &acpi_gbl_FADT. |
| 745 | xpm1a_control_block, |
| 746 | &acpi_gbl_FADT. |
| 747 | xpm1b_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | break; |
| 749 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 750 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
Bob Moore | 20869dc | 2009-03-13 09:10:46 +0800 | [diff] [blame] | 751 | /* |
| 752 | * For control registers, all reserved bits must be preserved, |
| 753 | * as per the ACPI spec. |
| 754 | */ |
| 755 | status = |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 756 | acpi_hw_read(&read_value, |
| 757 | &acpi_gbl_FADT.xpm2_control_block); |
Bob Moore | 20869dc | 2009-03-13 09:10:46 +0800 | [diff] [blame] | 758 | if (ACPI_FAILURE(status)) { |
| 759 | goto exit; |
| 760 | } |
| 761 | |
| 762 | /* Insert the bits to be preserved */ |
| 763 | |
| 764 | ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS, |
| 765 | read_value); |
| 766 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 767 | status = |
| 768 | acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | break; |
| 770 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 771 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 773 | status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | break; |
| 775 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 776 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | /* SMI_CMD is currently always in IO space */ |
| 779 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 780 | status = |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 781 | acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | break; |
| 783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 785 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 786 | ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | status = AE_BAD_PARAMETER; |
| 788 | break; |
| 789 | } |
| 790 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 791 | exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 792 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | } |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 794 | |
| 795 | /****************************************************************************** |
| 796 | * |
| 797 | * FUNCTION: acpi_hw_read_multiple |
| 798 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 799 | * PARAMETERS: value - Where the register value is returned |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 800 | * register_a - First ACPI register (required) |
| 801 | * register_b - Second ACPI register (optional) |
| 802 | * |
| 803 | * RETURN: Status |
| 804 | * |
| 805 | * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B) |
| 806 | * |
| 807 | ******************************************************************************/ |
| 808 | |
| 809 | static acpi_status |
| 810 | acpi_hw_read_multiple(u32 *value, |
| 811 | struct acpi_generic_address *register_a, |
| 812 | struct acpi_generic_address *register_b) |
| 813 | { |
| 814 | u32 value_a = 0; |
| 815 | u32 value_b = 0; |
| 816 | acpi_status status; |
| 817 | |
| 818 | /* The first register is always required */ |
| 819 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 820 | status = acpi_hw_read(&value_a, register_a); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 821 | if (ACPI_FAILURE(status)) { |
| 822 | return (status); |
| 823 | } |
| 824 | |
| 825 | /* Second register is optional */ |
| 826 | |
| 827 | if (register_b->address) { |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 828 | status = acpi_hw_read(&value_b, register_b); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 829 | if (ACPI_FAILURE(status)) { |
| 830 | return (status); |
| 831 | } |
| 832 | } |
| 833 | |
Bob Moore | aefc7f9 | 2009-02-18 14:26:02 +0800 | [diff] [blame] | 834 | /* |
| 835 | * OR the two return values together. No shifting or masking is necessary, |
| 836 | * because of how the PM1 registers are defined in the ACPI specification: |
| 837 | * |
| 838 | * "Although the bits can be split between the two register blocks (each |
| 839 | * register block has a unique pointer within the FADT), the bit positions |
| 840 | * are maintained. The register block with unimplemented bits (that is, |
| 841 | * those implemented in the other register block) always returns zeros, |
| 842 | * and writes have no side effects" |
| 843 | */ |
| 844 | *value = (value_a | value_b); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 845 | return (AE_OK); |
| 846 | } |
| 847 | |
| 848 | /****************************************************************************** |
| 849 | * |
| 850 | * FUNCTION: acpi_hw_write_multiple |
| 851 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 852 | * PARAMETERS: value - The value to write |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 853 | * register_a - First ACPI register (required) |
| 854 | * register_b - Second ACPI register (optional) |
| 855 | * |
| 856 | * RETURN: Status |
| 857 | * |
| 858 | * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B) |
| 859 | * |
| 860 | ******************************************************************************/ |
| 861 | |
| 862 | static acpi_status |
| 863 | acpi_hw_write_multiple(u32 value, |
| 864 | struct acpi_generic_address *register_a, |
| 865 | struct acpi_generic_address *register_b) |
| 866 | { |
| 867 | acpi_status status; |
| 868 | |
| 869 | /* The first register is always required */ |
| 870 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 871 | status = acpi_hw_write(value, register_a); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 872 | if (ACPI_FAILURE(status)) { |
| 873 | return (status); |
| 874 | } |
| 875 | |
Bob Moore | aefc7f9 | 2009-02-18 14:26:02 +0800 | [diff] [blame] | 876 | /* |
| 877 | * Second register is optional |
| 878 | * |
| 879 | * No bit shifting or clearing is necessary, because of how the PM1 |
| 880 | * registers are defined in the ACPI specification: |
| 881 | * |
| 882 | * "Although the bits can be split between the two register blocks (each |
| 883 | * register block has a unique pointer within the FADT), the bit positions |
| 884 | * are maintained. The register block with unimplemented bits (that is, |
| 885 | * those implemented in the other register block) always returns zeros, |
| 886 | * and writes have no side effects" |
| 887 | */ |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 888 | if (register_b->address) { |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 889 | status = acpi_hw_write(value, register_b); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | return (status); |
| 893 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 894 | |
| 895 | #endif /* !ACPI_REDUCED_HARDWARE */ |