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> |
| 198 | * bit_width must be exactly 8, 16, or 32. |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 199 | * space_ID must be system_memory or system_IO. |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 200 | * bit_offset and access_width are currently ignored, as there has |
| 201 | * not been a need to implement these. |
| 202 | * |
| 203 | ******************************************************************************/ |
| 204 | |
| 205 | acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg) |
| 206 | { |
| 207 | u64 address; |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 208 | u64 value64; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 209 | acpi_status status; |
| 210 | |
| 211 | ACPI_FUNCTION_NAME(hw_read); |
| 212 | |
| 213 | /* Validate contents of the GAS register */ |
| 214 | |
| 215 | status = acpi_hw_validate_register(reg, 32, &address); |
| 216 | if (ACPI_FAILURE(status)) { |
| 217 | return (status); |
| 218 | } |
| 219 | |
| 220 | /* Initialize entire 32-bit return value to zero */ |
| 221 | |
| 222 | *value = 0; |
| 223 | |
| 224 | /* |
| 225 | * Two address spaces supported: Memory or IO. PCI_Config is |
| 226 | * not supported here because the GAS structure is insufficient |
| 227 | */ |
| 228 | if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 229 | status = acpi_os_read_memory((acpi_physical_address) |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 230 | address, &value64, reg->bit_width); |
| 231 | |
| 232 | *value = (u32)value64; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 233 | } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ |
| 234 | |
| 235 | status = acpi_hw_read_port((acpi_io_address) |
| 236 | address, value, reg->bit_width); |
| 237 | } |
| 238 | |
| 239 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 240 | "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", |
| 241 | *value, reg->bit_width, ACPI_FORMAT_UINT64(address), |
| 242 | acpi_ut_get_region_name(reg->space_id))); |
| 243 | |
| 244 | return (status); |
| 245 | } |
| 246 | |
| 247 | /****************************************************************************** |
| 248 | * |
| 249 | * FUNCTION: acpi_hw_write |
| 250 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 251 | * PARAMETERS: value - Value to be written |
| 252 | * reg - GAS register structure |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 253 | * |
| 254 | * RETURN: Status |
| 255 | * |
| 256 | * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max |
| 257 | * version of acpi_write, used internally since the overhead of |
| 258 | * 64-bit values is not needed. |
| 259 | * |
| 260 | ******************************************************************************/ |
| 261 | |
| 262 | acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg) |
| 263 | { |
| 264 | u64 address; |
| 265 | acpi_status status; |
| 266 | |
| 267 | ACPI_FUNCTION_NAME(hw_write); |
| 268 | |
| 269 | /* Validate contents of the GAS register */ |
| 270 | |
| 271 | status = acpi_hw_validate_register(reg, 32, &address); |
| 272 | if (ACPI_FAILURE(status)) { |
| 273 | return (status); |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * Two address spaces supported: Memory or IO. PCI_Config is |
| 278 | * not supported here because the GAS structure is insufficient |
| 279 | */ |
| 280 | if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 281 | status = acpi_os_write_memory((acpi_physical_address) |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 282 | address, (u64)value, |
| 283 | reg->bit_width); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 284 | } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ |
| 285 | |
| 286 | status = acpi_hw_write_port((acpi_io_address) |
| 287 | address, value, reg->bit_width); |
| 288 | } |
| 289 | |
| 290 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 291 | "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", |
| 292 | value, reg->bit_width, ACPI_FORMAT_UINT64(address), |
| 293 | acpi_ut_get_region_name(reg->space_id))); |
| 294 | |
| 295 | return (status); |
| 296 | } |
| 297 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 298 | #if (!ACPI_REDUCED_HARDWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /******************************************************************************* |
| 300 | * |
| 301 | * FUNCTION: acpi_hw_clear_acpi_status |
| 302 | * |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 303 | * PARAMETERS: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 305 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | * |
| 307 | * DESCRIPTION: Clears all fixed and general purpose status bits |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | * |
| 309 | ******************************************************************************/ |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 310 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 311 | acpi_status acpi_hw_clear_acpi_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 313 | acpi_status status; |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 314 | acpi_cpu_flags lock_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 316 | ACPI_FUNCTION_TRACE(hw_clear_acpi_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Bob Moore | 8eb7b24 | 2009-04-22 10:28:22 +0800 | [diff] [blame] | 318 | 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] | 319 | ACPI_BITMASK_ALL_FIXED_STATUS, |
Bob Moore | 8eb7b24 | 2009-04-22 10:28:22 +0800 | [diff] [blame] | 320 | ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 322 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Bob Moore | 227243a | 2009-02-18 14:24:50 +0800 | [diff] [blame] | 324 | /* Clear the fixed events in PM1 A/B */ |
Bob Moore | 531c633 | 2009-02-18 14:06:12 +0800 | [diff] [blame] | 325 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 326 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | ACPI_BITMASK_ALL_FIXED_STATUS); |
Rakib Mullick | f7f71cf | 2011-11-06 21:18:17 +0600 | [diff] [blame] | 328 | |
| 329 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); |
| 330 | |
Lv Zheng | 7d3e83b | 2014-07-08 10:08:19 +0800 | [diff] [blame] | 331 | if (ACPI_FAILURE(status)) { |
Rakib Mullick | f7f71cf | 2011-11-06 21:18:17 +0600 | [diff] [blame] | 332 | goto exit; |
Lv Zheng | 7d3e83b | 2014-07-08 10:08:19 +0800 | [diff] [blame] | 333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | /* Clear the GPE Bits in all GPE registers in all GPE blocks */ |
| 336 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 337 | status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Rakib Mullick | f7f71cf | 2011-11-06 21:18:17 +0600 | [diff] [blame] | 339 | exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /******************************************************************************* |
| 344 | * |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 345 | * FUNCTION: acpi_hw_get_bit_register_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | * |
| 347 | * PARAMETERS: register_id - Index of ACPI Register to access |
| 348 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 349 | * RETURN: The bitmask to be used when accessing the register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 351 | * DESCRIPTION: Map register_id into a register bitmask. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | * |
| 353 | ******************************************************************************/ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 354 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 355 | 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] | 356 | { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 357 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | if (register_id > ACPI_BITREG_MAX) { |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 360 | ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 361 | register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | return (NULL); |
| 363 | } |
| 364 | |
| 365 | return (&acpi_gbl_bit_register_info[register_id]); |
| 366 | } |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /****************************************************************************** |
| 369 | * |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 370 | * FUNCTION: acpi_hw_write_pm1_control |
| 371 | * |
| 372 | * PARAMETERS: pm1a_control - Value to be written to PM1A control |
| 373 | * pm1b_control - Value to be written to PM1B control |
| 374 | * |
| 375 | * RETURN: Status |
| 376 | * |
| 377 | * DESCRIPTION: Write the PM1 A/B control registers. These registers are |
| 378 | * different than than the PM1 A/B status and enable registers |
| 379 | * in that different values can be written to the A/B registers. |
| 380 | * Most notably, the SLP_TYP bits can be different, as per the |
| 381 | * values returned from the _Sx predefined methods. |
| 382 | * |
| 383 | ******************************************************************************/ |
| 384 | |
| 385 | acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control) |
| 386 | { |
| 387 | acpi_status status; |
| 388 | |
| 389 | ACPI_FUNCTION_TRACE(hw_write_pm1_control); |
| 390 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 391 | status = |
| 392 | acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block); |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 393 | if (ACPI_FAILURE(status)) { |
| 394 | return_ACPI_STATUS(status); |
| 395 | } |
| 396 | |
| 397 | if (acpi_gbl_FADT.xpm1b_control_block.address) { |
| 398 | status = |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 399 | acpi_hw_write(pm1b_control, |
| 400 | &acpi_gbl_FADT.xpm1b_control_block); |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 401 | } |
| 402 | return_ACPI_STATUS(status); |
| 403 | } |
| 404 | |
| 405 | /****************************************************************************** |
| 406 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | * FUNCTION: acpi_hw_register_read |
| 408 | * |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 409 | * PARAMETERS: register_id - ACPI Register ID |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 410 | * return_value - Where the register value is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | * |
| 412 | * RETURN: Status and the value read. |
| 413 | * |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 414 | * DESCRIPTION: Read from the specified ACPI register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | * |
| 416 | ******************************************************************************/ |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 417 | acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 419 | u32 value = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 422 | ACPI_FUNCTION_TRACE(hw_register_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | switch (register_id) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 425 | case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 427 | status = acpi_hw_read_multiple(&value, |
| 428 | &acpi_gbl_xpm1a_status, |
| 429 | &acpi_gbl_xpm1b_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | break; |
| 431 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 432 | case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 434 | status = acpi_hw_read_multiple(&value, |
| 435 | &acpi_gbl_xpm1a_enable, |
| 436 | &acpi_gbl_xpm1b_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | break; |
| 438 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 439 | case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 441 | status = acpi_hw_read_multiple(&value, |
| 442 | &acpi_gbl_FADT. |
| 443 | xpm1a_control_block, |
| 444 | &acpi_gbl_FADT. |
| 445 | xpm1b_control_block); |
Lin Ming | c3dd25f | 2009-03-19 09:51:01 +0800 | [diff] [blame] | 446 | |
| 447 | /* |
| 448 | * Zero the write-only bits. From the ACPI specification, "Hardware |
| 449 | * Write-Only Bits": "Upon reads to registers with write-only bits, |
| 450 | * software masks out all write-only bits." |
| 451 | */ |
| 452 | value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | break; |
| 454 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 455 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 457 | status = |
| 458 | acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | break; |
| 460 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 463 | status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | break; |
| 465 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 466 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 468 | status = |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 469 | acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | break; |
| 471 | |
| 472 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 473 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 474 | ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | status = AE_BAD_PARAMETER; |
| 476 | break; |
| 477 | } |
| 478 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 479 | if (ACPI_SUCCESS(status)) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 480 | *return_value = value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 483 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | /****************************************************************************** |
| 487 | * |
| 488 | * FUNCTION: acpi_hw_register_write |
| 489 | * |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 490 | * PARAMETERS: register_id - ACPI Register ID |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 491 | * value - The value to write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | * |
| 493 | * RETURN: Status |
| 494 | * |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 495 | * DESCRIPTION: Write to the specified ACPI register |
| 496 | * |
| 497 | * NOTE: In accordance with the ACPI specification, this function automatically |
| 498 | * preserves the value of the following bits, meaning that these bits cannot be |
| 499 | * changed via this interface: |
| 500 | * |
| 501 | * PM1_CONTROL[0] = SCI_EN |
| 502 | * PM1_CONTROL[9] |
| 503 | * PM1_STATUS[11] |
| 504 | * |
| 505 | * ACPI References: |
| 506 | * 1) Hardware Ignored Bits: When software writes to a register with ignored |
| 507 | * bit fields, it preserves the ignored bit fields |
| 508 | * 2) SCI_EN: OSPM always preserves this bit position |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | * |
| 510 | ******************************************************************************/ |
| 511 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 512 | acpi_status acpi_hw_register_write(u32 register_id, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | acpi_status status; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 515 | u32 read_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 517 | ACPI_FUNCTION_TRACE(hw_register_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | switch (register_id) { |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 520 | case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ |
Bob Moore | 8636f8d | 2009-03-09 16:32:20 +0800 | [diff] [blame] | 521 | /* |
| 522 | * Handle the "ignored" bit in PM1 Status. According to the ACPI |
| 523 | * specification, ignored bits are to be preserved when writing. |
| 524 | * Normally, this would mean a read/modify/write sequence. However, |
| 525 | * preserving a bit in the status register is different. Writing a |
| 526 | * one clears the status, and writing a zero preserves the status. |
| 527 | * Therefore, we must always write zero to the ignored bit. |
| 528 | * |
| 529 | * This behavior is clarified in the ACPI 4.0 specification. |
| 530 | */ |
| 531 | value &= ~ACPI_PM1_STATUS_PRESERVED_BITS; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 532 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 533 | status = acpi_hw_write_multiple(value, |
| 534 | &acpi_gbl_xpm1a_status, |
| 535 | &acpi_gbl_xpm1b_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | break; |
| 537 | |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 538 | case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 540 | status = acpi_hw_write_multiple(value, |
| 541 | &acpi_gbl_xpm1a_enable, |
| 542 | &acpi_gbl_xpm1b_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | break; |
| 544 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 545 | case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 546 | /* |
| 547 | * Perform a read first to preserve certain bits (per ACPI spec) |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 548 | * Note: This includes SCI_EN, we never want to change this bit |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 549 | */ |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 550 | status = acpi_hw_read_multiple(&read_value, |
| 551 | &acpi_gbl_FADT. |
| 552 | xpm1a_control_block, |
| 553 | &acpi_gbl_FADT. |
| 554 | xpm1b_control_block); |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 555 | if (ACPI_FAILURE(status)) { |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 556 | goto exit; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* Insert the bits to be preserved */ |
| 560 | |
| 561 | ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS, |
| 562 | read_value); |
| 563 | |
| 564 | /* Now we can write the data */ |
| 565 | |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 566 | status = acpi_hw_write_multiple(value, |
| 567 | &acpi_gbl_FADT. |
| 568 | xpm1a_control_block, |
| 569 | &acpi_gbl_FADT. |
| 570 | xpm1b_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | break; |
| 572 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
Bob Moore | 20869dc | 2009-03-13 09:10:46 +0800 | [diff] [blame] | 574 | /* |
| 575 | * For control registers, all reserved bits must be preserved, |
| 576 | * as per the ACPI spec. |
| 577 | */ |
| 578 | status = |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 579 | acpi_hw_read(&read_value, |
| 580 | &acpi_gbl_FADT.xpm2_control_block); |
Bob Moore | 20869dc | 2009-03-13 09:10:46 +0800 | [diff] [blame] | 581 | if (ACPI_FAILURE(status)) { |
| 582 | goto exit; |
| 583 | } |
| 584 | |
| 585 | /* Insert the bits to be preserved */ |
| 586 | |
| 587 | ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS, |
| 588 | read_value); |
| 589 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 590 | status = |
| 591 | acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | break; |
| 593 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 596 | status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | break; |
| 598 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 599 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
| 601 | /* SMI_CMD is currently always in IO space */ |
| 602 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 603 | status = |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 604 | acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | break; |
| 606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 608 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 609 | ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | status = AE_BAD_PARAMETER; |
| 611 | break; |
| 612 | } |
| 613 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 614 | exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 615 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 617 | |
| 618 | /****************************************************************************** |
| 619 | * |
| 620 | * FUNCTION: acpi_hw_read_multiple |
| 621 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 622 | * PARAMETERS: value - Where the register value is returned |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 623 | * register_a - First ACPI register (required) |
| 624 | * register_b - Second ACPI register (optional) |
| 625 | * |
| 626 | * RETURN: Status |
| 627 | * |
| 628 | * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B) |
| 629 | * |
| 630 | ******************************************************************************/ |
| 631 | |
| 632 | static acpi_status |
| 633 | acpi_hw_read_multiple(u32 *value, |
| 634 | struct acpi_generic_address *register_a, |
| 635 | struct acpi_generic_address *register_b) |
| 636 | { |
| 637 | u32 value_a = 0; |
| 638 | u32 value_b = 0; |
| 639 | acpi_status status; |
| 640 | |
| 641 | /* The first register is always required */ |
| 642 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 643 | status = acpi_hw_read(&value_a, register_a); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 644 | if (ACPI_FAILURE(status)) { |
| 645 | return (status); |
| 646 | } |
| 647 | |
| 648 | /* Second register is optional */ |
| 649 | |
| 650 | if (register_b->address) { |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 651 | status = acpi_hw_read(&value_b, register_b); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 652 | if (ACPI_FAILURE(status)) { |
| 653 | return (status); |
| 654 | } |
| 655 | } |
| 656 | |
Bob Moore | aefc7f9 | 2009-02-18 14:26:02 +0800 | [diff] [blame] | 657 | /* |
| 658 | * OR the two return values together. No shifting or masking is necessary, |
| 659 | * because of how the PM1 registers are defined in the ACPI specification: |
| 660 | * |
| 661 | * "Although the bits can be split between the two register blocks (each |
| 662 | * register block has a unique pointer within the FADT), the bit positions |
| 663 | * are maintained. The register block with unimplemented bits (that is, |
| 664 | * those implemented in the other register block) always returns zeros, |
| 665 | * and writes have no side effects" |
| 666 | */ |
| 667 | *value = (value_a | value_b); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 668 | return (AE_OK); |
| 669 | } |
| 670 | |
| 671 | /****************************************************************************** |
| 672 | * |
| 673 | * FUNCTION: acpi_hw_write_multiple |
| 674 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 675 | * PARAMETERS: value - The value to write |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 676 | * register_a - First ACPI register (required) |
| 677 | * register_b - Second ACPI register (optional) |
| 678 | * |
| 679 | * RETURN: Status |
| 680 | * |
| 681 | * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B) |
| 682 | * |
| 683 | ******************************************************************************/ |
| 684 | |
| 685 | static acpi_status |
| 686 | acpi_hw_write_multiple(u32 value, |
| 687 | struct acpi_generic_address *register_a, |
| 688 | struct acpi_generic_address *register_b) |
| 689 | { |
| 690 | acpi_status status; |
| 691 | |
| 692 | /* The first register is always required */ |
| 693 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 694 | status = acpi_hw_write(value, register_a); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 695 | if (ACPI_FAILURE(status)) { |
| 696 | return (status); |
| 697 | } |
| 698 | |
Bob Moore | aefc7f9 | 2009-02-18 14:26:02 +0800 | [diff] [blame] | 699 | /* |
| 700 | * Second register is optional |
| 701 | * |
| 702 | * No bit shifting or clearing is necessary, because of how the PM1 |
| 703 | * registers are defined in the ACPI specification: |
| 704 | * |
| 705 | * "Although the bits can be split between the two register blocks (each |
| 706 | * register block has a unique pointer within the FADT), the bit positions |
| 707 | * are maintained. The register block with unimplemented bits (that is, |
| 708 | * those implemented in the other register block) always returns zeros, |
| 709 | * and writes have no side effects" |
| 710 | */ |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 711 | if (register_b->address) { |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 712 | status = acpi_hw_write(value, register_b); |
Bob Moore | c520aba | 2009-02-18 14:20:12 +0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | return (status); |
| 716 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 717 | |
| 718 | #endif /* !ACPI_REDUCED_HARDWARE */ |