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