Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 1 | |
| 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: hwxface - Public ACPICA hardware interfaces |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2012, Intel Corp. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [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 | |
Paul Gortmaker | 214f2c9 | 2011-10-26 16:22:14 -0400 | [diff] [blame] | 45 | #include <linux/export.h> |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 47 | #include "accommon.h" |
| 48 | #include "acnamesp.h" |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 49 | |
| 50 | #define _COMPONENT ACPI_HARDWARE |
| 51 | ACPI_MODULE_NAME("hwxface") |
| 52 | |
| 53 | /****************************************************************************** |
| 54 | * |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 55 | * FUNCTION: acpi_reset |
| 56 | * |
| 57 | * PARAMETERS: None |
| 58 | * |
| 59 | * RETURN: Status |
| 60 | * |
| 61 | * DESCRIPTION: Set reset register in memory or IO space. Note: Does not |
| 62 | * support reset register in PCI config space, this must be |
| 63 | * handled separately. |
| 64 | * |
| 65 | ******************************************************************************/ |
| 66 | acpi_status acpi_reset(void) |
| 67 | { |
| 68 | struct acpi_generic_address *reset_reg; |
| 69 | acpi_status status; |
| 70 | |
| 71 | ACPI_FUNCTION_TRACE(acpi_reset); |
| 72 | |
| 73 | reset_reg = &acpi_gbl_FADT.reset_register; |
| 74 | |
| 75 | /* Check if the reset register is supported */ |
| 76 | |
| 77 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) || |
| 78 | !reset_reg->address) { |
| 79 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 80 | } |
| 81 | |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 82 | if (reset_reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { |
| 83 | /* |
Matthew Garrett | f17d9cb | 2011-03-11 16:12:18 -0500 | [diff] [blame] | 84 | * For I/O space, write directly to the OSL. This |
| 85 | * bypasses the port validation mechanism, which may |
| 86 | * block a valid write to the reset register. Spec |
| 87 | * section 4.7.3.6 requires register width to be 8. |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 88 | */ |
| 89 | status = |
| 90 | acpi_os_write_port((acpi_io_address) reset_reg->address, |
Matthew Garrett | f17d9cb | 2011-03-11 16:12:18 -0500 | [diff] [blame] | 91 | acpi_gbl_FADT.reset_value, 8); |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 92 | } else { |
| 93 | /* Write the reset value to the reset register */ |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 94 | |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 95 | status = acpi_hw_write(acpi_gbl_FADT.reset_value, reset_reg); |
| 96 | } |
| 97 | |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 98 | return_ACPI_STATUS(status); |
| 99 | } |
| 100 | |
| 101 | ACPI_EXPORT_SYMBOL(acpi_reset) |
| 102 | |
| 103 | /****************************************************************************** |
| 104 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 105 | * FUNCTION: acpi_read |
| 106 | * |
| 107 | * PARAMETERS: Value - Where the value is returned |
| 108 | * Reg - GAS register structure |
| 109 | * |
| 110 | * RETURN: Status |
| 111 | * |
| 112 | * DESCRIPTION: Read from either memory or IO space. |
| 113 | * |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 114 | * LIMITATIONS: <These limitations also apply to acpi_write> |
| 115 | * bit_width must be exactly 8, 16, 32, or 64. |
| 116 | * space_iD must be system_memory or system_iO. |
| 117 | * bit_offset and access_width are currently ignored, as there has |
| 118 | * not been a need to implement these. |
| 119 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 120 | ******************************************************************************/ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 121 | acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 122 | { |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 123 | u32 value; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 124 | u32 width; |
| 125 | u64 address; |
| 126 | acpi_status status; |
| 127 | |
| 128 | ACPI_FUNCTION_NAME(acpi_read); |
| 129 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 130 | if (!return_value) { |
Bob Moore | ac0c845 | 2009-02-18 14:28:02 +0800 | [diff] [blame] | 131 | return (AE_BAD_PARAMETER); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 132 | } |
| 133 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 134 | /* Validate contents of the GAS register. Allow 64-bit transfers */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 135 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 136 | status = acpi_hw_validate_register(reg, 64, &address); |
| 137 | if (ACPI_FAILURE(status)) { |
| 138 | return (status); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 139 | } |
| 140 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 141 | width = reg->bit_width; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 142 | if (width == 64) { |
| 143 | width = 32; /* Break into two 32-bit transfers */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 144 | } |
| 145 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 146 | /* Initialize entire 64-bit return value to zero */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 147 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 148 | *return_value = 0; |
| 149 | value = 0; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 150 | |
| 151 | /* |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 152 | * Two address spaces supported: Memory or IO. PCI_Config is |
| 153 | * not supported here because the GAS structure is insufficient |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 154 | */ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 155 | if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 156 | status = acpi_os_read_memory((acpi_physical_address) |
| 157 | address, &value, width); |
| 158 | if (ACPI_FAILURE(status)) { |
| 159 | return (status); |
| 160 | } |
| 161 | *return_value = value; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 162 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 163 | if (reg->bit_width == 64) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 164 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 165 | /* Read the top 32 bits */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 166 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 167 | status = acpi_os_read_memory((acpi_physical_address) |
| 168 | (address + 4), &value, 32); |
| 169 | if (ACPI_FAILURE(status)) { |
| 170 | return (status); |
| 171 | } |
| 172 | *return_value |= ((u64)value << 32); |
| 173 | } |
| 174 | } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 175 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 176 | status = acpi_hw_read_port((acpi_io_address) |
| 177 | address, &value, width); |
| 178 | if (ACPI_FAILURE(status)) { |
| 179 | return (status); |
| 180 | } |
| 181 | *return_value = value; |
| 182 | |
| 183 | if (reg->bit_width == 64) { |
| 184 | |
| 185 | /* Read the top 32 bits */ |
| 186 | |
| 187 | status = acpi_hw_read_port((acpi_io_address) |
| 188 | (address + 4), &value, 32); |
| 189 | if (ACPI_FAILURE(status)) { |
| 190 | return (status); |
| 191 | } |
| 192 | *return_value |= ((u64)value << 32); |
| 193 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 197 | "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n", |
| 198 | ACPI_FORMAT_UINT64(*return_value), reg->bit_width, |
| 199 | ACPI_FORMAT_UINT64(address), |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 200 | acpi_ut_get_region_name(reg->space_id))); |
| 201 | |
| 202 | return (status); |
| 203 | } |
| 204 | |
| 205 | ACPI_EXPORT_SYMBOL(acpi_read) |
| 206 | |
| 207 | /****************************************************************************** |
| 208 | * |
| 209 | * FUNCTION: acpi_write |
| 210 | * |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 211 | * PARAMETERS: Value - Value to be written |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 212 | * Reg - GAS register structure |
| 213 | * |
| 214 | * RETURN: Status |
| 215 | * |
| 216 | * DESCRIPTION: Write to either memory or IO space. |
| 217 | * |
| 218 | ******************************************************************************/ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 219 | acpi_status acpi_write(u64 value, struct acpi_generic_address *reg) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 220 | { |
| 221 | u32 width; |
| 222 | u64 address; |
| 223 | acpi_status status; |
| 224 | |
| 225 | ACPI_FUNCTION_NAME(acpi_write); |
| 226 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 227 | /* Validate contents of the GAS register. Allow 64-bit transfers */ |
| 228 | |
| 229 | status = acpi_hw_validate_register(reg, 64, &address); |
| 230 | if (ACPI_FAILURE(status)) { |
| 231 | return (status); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 232 | } |
| 233 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 234 | width = reg->bit_width; |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 235 | if (width == 64) { |
| 236 | width = 32; /* Break into two 32-bit transfers */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | /* |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 240 | * Two address spaces supported: Memory or IO. PCI_Config is |
| 241 | * not supported here because the GAS structure is insufficient |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 242 | */ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 243 | if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 244 | status = acpi_os_write_memory((acpi_physical_address) |
| 245 | address, ACPI_LODWORD(value), |
| 246 | width); |
| 247 | if (ACPI_FAILURE(status)) { |
| 248 | return (status); |
| 249 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 250 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 251 | if (reg->bit_width == 64) { |
| 252 | status = acpi_os_write_memory((acpi_physical_address) |
| 253 | (address + 4), |
| 254 | ACPI_HIDWORD(value), 32); |
| 255 | if (ACPI_FAILURE(status)) { |
| 256 | return (status); |
| 257 | } |
| 258 | } |
| 259 | } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 260 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 261 | status = acpi_hw_write_port((acpi_io_address) |
| 262 | address, ACPI_LODWORD(value), |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 263 | width); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 264 | if (ACPI_FAILURE(status)) { |
| 265 | return (status); |
| 266 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 267 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 268 | if (reg->bit_width == 64) { |
| 269 | status = acpi_hw_write_port((acpi_io_address) |
| 270 | (address + 4), |
| 271 | ACPI_HIDWORD(value), 32); |
| 272 | if (ACPI_FAILURE(status)) { |
| 273 | return (status); |
| 274 | } |
| 275 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 279 | "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n", |
| 280 | ACPI_FORMAT_UINT64(value), reg->bit_width, |
| 281 | ACPI_FORMAT_UINT64(address), |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 282 | acpi_ut_get_region_name(reg->space_id))); |
| 283 | |
| 284 | return (status); |
| 285 | } |
| 286 | |
| 287 | ACPI_EXPORT_SYMBOL(acpi_write) |
| 288 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame^] | 289 | #if (!ACPI_REDUCED_HARDWARE) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 290 | /******************************************************************************* |
| 291 | * |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 292 | * FUNCTION: acpi_read_bit_register |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 293 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 294 | * PARAMETERS: register_id - ID of ACPI Bit Register to access |
| 295 | * return_value - Value that was read from the register, |
| 296 | * normalized to bit position zero. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 297 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 298 | * RETURN: Status and the value read from the specified Register. Value |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 299 | * returned is normalized to bit0 (is shifted all the way right) |
| 300 | * |
| 301 | * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock. |
| 302 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 303 | * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and |
| 304 | * PM2 Control. |
| 305 | * |
| 306 | * Note: The hardware lock is not required when reading the ACPI bit registers |
| 307 | * since almost all of them are single bit and it does not matter that |
| 308 | * the parent hardware register can be split across two physical |
| 309 | * registers. The only multi-bit field is SLP_TYP in the PM1 control |
| 310 | * register, but this field does not cross an 8-bit boundary (nor does |
| 311 | * it make much sense to actually read this field.) |
| 312 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 313 | ******************************************************************************/ |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 314 | acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 315 | { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 316 | struct acpi_bit_register_info *bit_reg_info; |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 317 | u32 register_value; |
| 318 | u32 value; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 319 | acpi_status status; |
| 320 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 321 | ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 322 | |
| 323 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 324 | |
| 325 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
| 326 | if (!bit_reg_info) { |
| 327 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 328 | } |
| 329 | |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 330 | /* Read the entire parent register */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 331 | |
| 332 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
| 333 | ®ister_value); |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 334 | if (ACPI_FAILURE(status)) { |
| 335 | return_ACPI_STATUS(status); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 336 | } |
| 337 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 338 | /* Normalize the value that was read, mask off other bits */ |
| 339 | |
| 340 | value = ((register_value & bit_reg_info->access_bit_mask) |
| 341 | >> bit_reg_info->bit_position); |
| 342 | |
| 343 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 344 | "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n", |
| 345 | register_id, bit_reg_info->parent_register, |
| 346 | register_value, value)); |
| 347 | |
| 348 | *return_value = value; |
| 349 | return_ACPI_STATUS(AE_OK); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 350 | } |
| 351 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 352 | ACPI_EXPORT_SYMBOL(acpi_read_bit_register) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 353 | |
| 354 | /******************************************************************************* |
| 355 | * |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 356 | * FUNCTION: acpi_write_bit_register |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 357 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 358 | * PARAMETERS: register_id - ID of ACPI Bit Register to access |
| 359 | * Value - Value to write to the register, in bit |
Justin P. Mattock | 42b2aa8 | 2011-11-28 20:31:00 -0800 | [diff] [blame] | 360 | * position zero. The bit is automatically |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 361 | * shifted to the correct position. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 362 | * |
| 363 | * RETURN: Status |
| 364 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 365 | * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock |
| 366 | * since most operations require a read/modify/write sequence. |
| 367 | * |
| 368 | * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and |
| 369 | * PM2 Control. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 370 | * |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 371 | * Note that at this level, the fact that there may be actually two |
| 372 | * hardware registers (A and B - and B may not exist) is abstracted. |
| 373 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 374 | ******************************************************************************/ |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 375 | acpi_status acpi_write_bit_register(u32 register_id, u32 value) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 376 | { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 377 | struct acpi_bit_register_info *bit_reg_info; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 378 | acpi_cpu_flags lock_flags; |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 379 | u32 register_value; |
| 380 | acpi_status status = AE_OK; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 381 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 382 | ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 383 | |
| 384 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 385 | |
| 386 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
| 387 | if (!bit_reg_info) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 388 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 389 | } |
| 390 | |
| 391 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
| 392 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 393 | /* |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 394 | * At this point, we know that the parent register is one of the |
| 395 | * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 396 | */ |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 397 | if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 398 | /* |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 399 | * 1) Case for PM1 Enable, PM1 Control, and PM2 Control |
| 400 | * |
| 401 | * Perform a register read to preserve the bits that we are not |
| 402 | * interested in |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 403 | */ |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 404 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 405 | ®ister_value); |
| 406 | if (ACPI_FAILURE(status)) { |
| 407 | goto unlock_and_exit; |
| 408 | } |
| 409 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 410 | /* |
| 411 | * Insert the input bit into the value that was just read |
| 412 | * and write the register |
| 413 | */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 414 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 415 | bit_reg_info->bit_position, |
| 416 | bit_reg_info->access_bit_mask, |
| 417 | value); |
| 418 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 419 | status = acpi_hw_register_write(bit_reg_info->parent_register, |
| 420 | register_value); |
| 421 | } else { |
| 422 | /* |
| 423 | * 2) Case for PM1 Status |
| 424 | * |
| 425 | * The Status register is different from the rest. Clear an event |
| 426 | * by writing 1, writing 0 has no effect. So, the only relevant |
| 427 | * information is the single bit we're interested in, all others |
| 428 | * should be written as 0 so they will be left unchanged. |
| 429 | */ |
| 430 | register_value = ACPI_REGISTER_PREPARE_BITS(value, |
| 431 | bit_reg_info-> |
| 432 | bit_position, |
| 433 | bit_reg_info-> |
| 434 | access_bit_mask); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 435 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 436 | /* No need to write the register if value is all zeros */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 437 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 438 | if (register_value) { |
| 439 | status = |
| 440 | acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
| 441 | register_value); |
| 442 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 443 | } |
| 444 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 445 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 446 | "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n", |
| 447 | register_id, bit_reg_info->parent_register, value, |
| 448 | register_value)); |
| 449 | |
| 450 | unlock_and_exit: |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 451 | |
| 452 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 453 | return_ACPI_STATUS(status); |
| 454 | } |
| 455 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 456 | ACPI_EXPORT_SYMBOL(acpi_write_bit_register) |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame^] | 457 | #endif /* !ACPI_REDUCED_HARDWARE */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 458 | /******************************************************************************* |
| 459 | * |
| 460 | * FUNCTION: acpi_get_sleep_type_data |
| 461 | * |
| 462 | * PARAMETERS: sleep_state - Numeric sleep state |
| 463 | * *sleep_type_a - Where SLP_TYPa is returned |
| 464 | * *sleep_type_b - Where SLP_TYPb is returned |
| 465 | * |
| 466 | * RETURN: Status - ACPI status |
| 467 | * |
| 468 | * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep |
| 469 | * state. |
| 470 | * |
| 471 | ******************************************************************************/ |
| 472 | acpi_status |
| 473 | acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b) |
| 474 | { |
| 475 | acpi_status status = AE_OK; |
| 476 | struct acpi_evaluate_info *info; |
| 477 | |
| 478 | ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data); |
| 479 | |
| 480 | /* Validate parameters */ |
| 481 | |
| 482 | if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) { |
| 483 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 484 | } |
| 485 | |
| 486 | /* Allocate the evaluation information block */ |
| 487 | |
| 488 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 489 | if (!info) { |
| 490 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 491 | } |
| 492 | |
| 493 | info->pathname = |
| 494 | ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]); |
| 495 | |
| 496 | /* Evaluate the namespace object containing the values for this state */ |
| 497 | |
| 498 | status = acpi_ns_evaluate(info); |
| 499 | if (ACPI_FAILURE(status)) { |
| 500 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 501 | "%s while evaluating SleepState [%s]\n", |
| 502 | acpi_format_exception(status), |
| 503 | info->pathname)); |
| 504 | |
| 505 | goto cleanup; |
| 506 | } |
| 507 | |
| 508 | /* Must have a return object */ |
| 509 | |
| 510 | if (!info->return_object) { |
| 511 | ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]", |
| 512 | info->pathname)); |
| 513 | status = AE_NOT_EXIST; |
| 514 | } |
| 515 | |
| 516 | /* It must be of type Package */ |
| 517 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 518 | else if (info->return_object->common.type != ACPI_TYPE_PACKAGE) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 519 | ACPI_ERROR((AE_INFO, |
| 520 | "Sleep State return object is not a Package")); |
| 521 | status = AE_AML_OPERAND_TYPE; |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * The package must have at least two elements. NOTE (March 2005): This |
| 526 | * goes against the current ACPI spec which defines this object as a |
| 527 | * package with one encoded DWORD element. However, existing practice |
| 528 | * by BIOS vendors seems to be to have 2 or more elements, at least |
| 529 | * one per sleep type (A/B). |
| 530 | */ |
| 531 | else if (info->return_object->package.count < 2) { |
| 532 | ACPI_ERROR((AE_INFO, |
| 533 | "Sleep State return package does not have at least two elements")); |
| 534 | status = AE_AML_NO_OPERAND; |
| 535 | } |
| 536 | |
| 537 | /* The first two elements must both be of type Integer */ |
| 538 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 539 | else if (((info->return_object->package.elements[0])->common.type |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 540 | != ACPI_TYPE_INTEGER) || |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 541 | ((info->return_object->package.elements[1])->common.type |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 542 | != ACPI_TYPE_INTEGER)) { |
| 543 | ACPI_ERROR((AE_INFO, |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 544 | "Sleep State return package elements are not both Integers " |
| 545 | "(%s, %s)", |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 546 | acpi_ut_get_object_type_name(info->return_object-> |
| 547 | package.elements[0]), |
| 548 | acpi_ut_get_object_type_name(info->return_object-> |
| 549 | package.elements[1]))); |
| 550 | status = AE_AML_OPERAND_TYPE; |
| 551 | } else { |
| 552 | /* Valid _Sx_ package size, type, and value */ |
| 553 | |
| 554 | *sleep_type_a = (u8) |
| 555 | (info->return_object->package.elements[0])->integer.value; |
| 556 | *sleep_type_b = (u8) |
| 557 | (info->return_object->package.elements[1])->integer.value; |
| 558 | } |
| 559 | |
| 560 | if (ACPI_FAILURE(status)) { |
| 561 | ACPI_EXCEPTION((AE_INFO, status, |
| 562 | "While evaluating SleepState [%s], bad Sleep object %p type %s", |
| 563 | info->pathname, info->return_object, |
| 564 | acpi_ut_get_object_type_name(info-> |
| 565 | return_object))); |
| 566 | } |
| 567 | |
| 568 | acpi_ut_remove_reference(info->return_object); |
| 569 | |
| 570 | cleanup: |
| 571 | ACPI_FREE(info); |
| 572 | return_ACPI_STATUS(status); |
| 573 | } |
| 574 | |
| 575 | ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data) |