Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: hwxface - Public ACPICA hardware interfaces |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | fbb7a2d | 2014-02-08 09:42:25 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2014, Intel Corp. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 44 | #define EXPORT_ACPI_INTERFACES |
| 45 | |
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 | |
Linus Torvalds | 19244ad | 2012-04-20 11:19:35 -0700 | [diff] [blame] | 77 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) || |
| 78 | !reset_reg->address) { |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 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 | /* |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 84 | * For I/O space, write directly to the OSL. This bypasses the port |
| 85 | * validation mechanism, which may block a valid write to the reset |
| 86 | * register. |
Bob Moore | e07fcfd | 2013-10-29 09:29:45 +0800 | [diff] [blame] | 87 | * |
| 88 | * NOTE: |
| 89 | * The ACPI spec requires the reset register width to be 8, so we |
| 90 | * hardcode it here and ignore the FADT value. This maintains |
| 91 | * compatibility with other ACPI implementations that have allowed |
| 92 | * BIOS code with bad register width values to go unnoticed. |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 93 | */ |
| 94 | status = |
| 95 | acpi_os_write_port((acpi_io_address) reset_reg->address, |
Bob Moore | e07fcfd | 2013-10-29 09:29:45 +0800 | [diff] [blame] | 96 | acpi_gbl_FADT.reset_value, |
| 97 | ACPI_RESET_REGISTER_WIDTH); |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 98 | } else { |
| 99 | /* Write the reset value to the reset register */ |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 100 | |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 101 | status = acpi_hw_write(acpi_gbl_FADT.reset_value, reset_reg); |
| 102 | } |
| 103 | |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 104 | return_ACPI_STATUS(status); |
| 105 | } |
| 106 | |
| 107 | ACPI_EXPORT_SYMBOL(acpi_reset) |
| 108 | |
| 109 | /****************************************************************************** |
| 110 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 111 | * FUNCTION: acpi_read |
| 112 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 113 | * PARAMETERS: value - Where the value is returned |
| 114 | * reg - GAS register structure |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 115 | * |
| 116 | * RETURN: Status |
| 117 | * |
| 118 | * DESCRIPTION: Read from either memory or IO space. |
| 119 | * |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 120 | * LIMITATIONS: <These limitations also apply to acpi_write> |
| 121 | * bit_width must be exactly 8, 16, 32, or 64. |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 122 | * space_ID must be system_memory or system_IO. |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 123 | * bit_offset and access_width are currently ignored, as there has |
| 124 | * not been a need to implement these. |
| 125 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 126 | ******************************************************************************/ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 127 | acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 128 | { |
Bjorn Helgaas | c3faedc | 2013-09-23 09:51:22 +0800 | [diff] [blame] | 129 | u32 value_lo; |
| 130 | u32 value_hi; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 131 | u32 width; |
| 132 | u64 address; |
| 133 | acpi_status status; |
| 134 | |
| 135 | ACPI_FUNCTION_NAME(acpi_read); |
| 136 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 137 | if (!return_value) { |
Bob Moore | ac0c845 | 2009-02-18 14:28:02 +0800 | [diff] [blame] | 138 | return (AE_BAD_PARAMETER); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 139 | } |
| 140 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 141 | /* Validate contents of the GAS register. Allow 64-bit transfers */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 142 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 143 | status = acpi_hw_validate_register(reg, 64, &address); |
| 144 | if (ACPI_FAILURE(status)) { |
| 145 | return (status); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 146 | } |
| 147 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 148 | /* |
Bjorn Helgaas | c3faedc | 2013-09-23 09:51:22 +0800 | [diff] [blame] | 149 | * Two address spaces supported: Memory or I/O. PCI_Config is |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 150 | * not supported here because the GAS structure is insufficient |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 151 | */ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 152 | if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 153 | status = acpi_os_read_memory((acpi_physical_address) |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 154 | address, return_value, |
| 155 | reg->bit_width); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 156 | if (ACPI_FAILURE(status)) { |
| 157 | return (status); |
| 158 | } |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 159 | } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 160 | |
Bjorn Helgaas | c3faedc | 2013-09-23 09:51:22 +0800 | [diff] [blame] | 161 | value_lo = 0; |
| 162 | value_hi = 0; |
| 163 | |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 164 | width = reg->bit_width; |
| 165 | if (width == 64) { |
| 166 | width = 32; /* Break into two 32-bit transfers */ |
| 167 | } |
| 168 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 169 | status = acpi_hw_read_port((acpi_io_address) |
Bjorn Helgaas | c3faedc | 2013-09-23 09:51:22 +0800 | [diff] [blame] | 170 | address, &value_lo, width); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 171 | if (ACPI_FAILURE(status)) { |
| 172 | return (status); |
| 173 | } |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 174 | |
| 175 | if (reg->bit_width == 64) { |
| 176 | |
| 177 | /* Read the top 32 bits */ |
| 178 | |
| 179 | status = acpi_hw_read_port((acpi_io_address) |
Bjorn Helgaas | c3faedc | 2013-09-23 09:51:22 +0800 | [diff] [blame] | 180 | (address + 4), &value_hi, |
| 181 | 32); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 182 | if (ACPI_FAILURE(status)) { |
| 183 | return (status); |
| 184 | } |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 185 | } |
Bjorn Helgaas | c3faedc | 2013-09-23 09:51:22 +0800 | [diff] [blame] | 186 | |
| 187 | /* Set the return value only if status is AE_OK */ |
| 188 | |
| 189 | *return_value = (value_lo | ((u64)value_hi << 32)); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 193 | "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n", |
| 194 | ACPI_FORMAT_UINT64(*return_value), reg->bit_width, |
| 195 | ACPI_FORMAT_UINT64(address), |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 196 | acpi_ut_get_region_name(reg->space_id))); |
| 197 | |
Bjorn Helgaas | c3faedc | 2013-09-23 09:51:22 +0800 | [diff] [blame] | 198 | return (AE_OK); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | ACPI_EXPORT_SYMBOL(acpi_read) |
| 202 | |
| 203 | /****************************************************************************** |
| 204 | * |
| 205 | * FUNCTION: acpi_write |
| 206 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 207 | * PARAMETERS: value - Value to be written |
| 208 | * reg - GAS register structure |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 209 | * |
| 210 | * RETURN: Status |
| 211 | * |
| 212 | * DESCRIPTION: Write to either memory or IO space. |
| 213 | * |
| 214 | ******************************************************************************/ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 215 | acpi_status acpi_write(u64 value, struct acpi_generic_address *reg) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 216 | { |
| 217 | u32 width; |
| 218 | u64 address; |
| 219 | acpi_status status; |
| 220 | |
| 221 | ACPI_FUNCTION_NAME(acpi_write); |
| 222 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 223 | /* Validate contents of the GAS register. Allow 64-bit transfers */ |
| 224 | |
| 225 | status = acpi_hw_validate_register(reg, 64, &address); |
| 226 | if (ACPI_FAILURE(status)) { |
| 227 | return (status); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 228 | } |
| 229 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 230 | /* |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 231 | * Two address spaces supported: Memory or IO. PCI_Config is |
| 232 | * not supported here because the GAS structure is insufficient |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 233 | */ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 234 | if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
| 235 | status = acpi_os_write_memory((acpi_physical_address) |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 236 | address, value, reg->bit_width); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 237 | if (ACPI_FAILURE(status)) { |
| 238 | return (status); |
| 239 | } |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 240 | } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 241 | |
Bob Moore | 653f4b5 | 2012-02-14 18:29:55 +0800 | [diff] [blame] | 242 | width = reg->bit_width; |
| 243 | if (width == 64) { |
| 244 | width = 32; /* Break into two 32-bit transfers */ |
| 245 | } |
| 246 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 247 | status = acpi_hw_write_port((acpi_io_address) |
| 248 | address, ACPI_LODWORD(value), |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 249 | width); |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 250 | if (ACPI_FAILURE(status)) { |
| 251 | return (status); |
| 252 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 253 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 254 | if (reg->bit_width == 64) { |
| 255 | status = acpi_hw_write_port((acpi_io_address) |
| 256 | (address + 4), |
| 257 | ACPI_HIDWORD(value), 32); |
| 258 | if (ACPI_FAILURE(status)) { |
| 259 | return (status); |
| 260 | } |
| 261 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 265 | "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n", |
| 266 | ACPI_FORMAT_UINT64(value), reg->bit_width, |
| 267 | ACPI_FORMAT_UINT64(address), |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 268 | acpi_ut_get_region_name(reg->space_id))); |
| 269 | |
| 270 | return (status); |
| 271 | } |
| 272 | |
| 273 | ACPI_EXPORT_SYMBOL(acpi_write) |
| 274 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 275 | #if (!ACPI_REDUCED_HARDWARE) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 276 | /******************************************************************************* |
| 277 | * |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 278 | * FUNCTION: acpi_read_bit_register |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 279 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 280 | * PARAMETERS: register_id - ID of ACPI Bit Register to access |
| 281 | * return_value - Value that was read from the register, |
| 282 | * normalized to bit position zero. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 283 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 284 | * RETURN: Status and the value read from the specified Register. Value |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 285 | * returned is normalized to bit0 (is shifted all the way right) |
| 286 | * |
| 287 | * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock. |
| 288 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 289 | * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and |
| 290 | * PM2 Control. |
| 291 | * |
| 292 | * Note: The hardware lock is not required when reading the ACPI bit registers |
| 293 | * since almost all of them are single bit and it does not matter that |
| 294 | * the parent hardware register can be split across two physical |
| 295 | * registers. The only multi-bit field is SLP_TYP in the PM1 control |
| 296 | * register, but this field does not cross an 8-bit boundary (nor does |
| 297 | * it make much sense to actually read this field.) |
| 298 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 299 | ******************************************************************************/ |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 300 | acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 301 | { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 302 | struct acpi_bit_register_info *bit_reg_info; |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 303 | u32 register_value; |
| 304 | u32 value; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 305 | acpi_status status; |
| 306 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 307 | ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 308 | |
| 309 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 310 | |
| 311 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
| 312 | if (!bit_reg_info) { |
| 313 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 314 | } |
| 315 | |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 316 | /* Read the entire parent register */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 317 | |
| 318 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
| 319 | ®ister_value); |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 320 | if (ACPI_FAILURE(status)) { |
| 321 | return_ACPI_STATUS(status); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 322 | } |
| 323 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 324 | /* Normalize the value that was read, mask off other bits */ |
| 325 | |
| 326 | value = ((register_value & bit_reg_info->access_bit_mask) |
| 327 | >> bit_reg_info->bit_position); |
| 328 | |
| 329 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 330 | "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n", |
| 331 | register_id, bit_reg_info->parent_register, |
| 332 | register_value, value)); |
| 333 | |
| 334 | *return_value = value; |
| 335 | return_ACPI_STATUS(AE_OK); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 336 | } |
| 337 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 338 | ACPI_EXPORT_SYMBOL(acpi_read_bit_register) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 339 | |
| 340 | /******************************************************************************* |
| 341 | * |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 342 | * FUNCTION: acpi_write_bit_register |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 343 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 344 | * PARAMETERS: register_id - ID of ACPI Bit Register to access |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 345 | * value - Value to write to the register, in bit |
Justin P. Mattock | 42b2aa8 | 2011-11-28 20:31:00 -0800 | [diff] [blame] | 346 | * position zero. The bit is automatically |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 347 | * shifted to the correct position. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 348 | * |
| 349 | * RETURN: Status |
| 350 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 351 | * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock |
| 352 | * since most operations require a read/modify/write sequence. |
| 353 | * |
| 354 | * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and |
| 355 | * PM2 Control. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 356 | * |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 357 | * Note that at this level, the fact that there may be actually two |
| 358 | * hardware registers (A and B - and B may not exist) is abstracted. |
| 359 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 360 | ******************************************************************************/ |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 361 | acpi_status acpi_write_bit_register(u32 register_id, u32 value) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 362 | { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 363 | struct acpi_bit_register_info *bit_reg_info; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 364 | acpi_cpu_flags lock_flags; |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 365 | u32 register_value; |
| 366 | acpi_status status = AE_OK; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 367 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 368 | ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 369 | |
| 370 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 371 | |
| 372 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
| 373 | if (!bit_reg_info) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 374 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 375 | } |
| 376 | |
| 377 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
| 378 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 379 | /* |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 380 | * At this point, we know that the parent register is one of the |
| 381 | * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 382 | */ |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 383 | if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 384 | /* |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 385 | * 1) Case for PM1 Enable, PM1 Control, and PM2 Control |
| 386 | * |
| 387 | * Perform a register read to preserve the bits that we are not |
| 388 | * interested in |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 389 | */ |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 390 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 391 | ®ister_value); |
| 392 | if (ACPI_FAILURE(status)) { |
| 393 | goto unlock_and_exit; |
| 394 | } |
| 395 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 396 | /* |
| 397 | * Insert the input bit into the value that was just read |
| 398 | * and write the register |
| 399 | */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 400 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 401 | bit_reg_info->bit_position, |
| 402 | bit_reg_info->access_bit_mask, |
| 403 | value); |
| 404 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 405 | status = acpi_hw_register_write(bit_reg_info->parent_register, |
| 406 | register_value); |
| 407 | } else { |
| 408 | /* |
| 409 | * 2) Case for PM1 Status |
| 410 | * |
| 411 | * The Status register is different from the rest. Clear an event |
| 412 | * by writing 1, writing 0 has no effect. So, the only relevant |
| 413 | * information is the single bit we're interested in, all others |
| 414 | * should be written as 0 so they will be left unchanged. |
| 415 | */ |
| 416 | register_value = ACPI_REGISTER_PREPARE_BITS(value, |
| 417 | bit_reg_info-> |
| 418 | bit_position, |
| 419 | bit_reg_info-> |
| 420 | access_bit_mask); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 421 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 422 | /* No need to write the register if value is all zeros */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 423 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 424 | if (register_value) { |
| 425 | status = |
| 426 | acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
| 427 | register_value); |
| 428 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 429 | } |
| 430 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 431 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 432 | "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n", |
| 433 | register_id, bit_reg_info->parent_register, value, |
| 434 | register_value)); |
| 435 | |
| 436 | unlock_and_exit: |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 437 | |
| 438 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 439 | return_ACPI_STATUS(status); |
| 440 | } |
| 441 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 442 | ACPI_EXPORT_SYMBOL(acpi_write_bit_register) |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 443 | #endif /* !ACPI_REDUCED_HARDWARE */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 444 | /******************************************************************************* |
| 445 | * |
| 446 | * FUNCTION: acpi_get_sleep_type_data |
| 447 | * |
| 448 | * PARAMETERS: sleep_state - Numeric sleep state |
| 449 | * *sleep_type_a - Where SLP_TYPa is returned |
| 450 | * *sleep_type_b - Where SLP_TYPb is returned |
| 451 | * |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 452 | * RETURN: Status |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 453 | * |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 454 | * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested |
| 455 | * sleep state via the appropriate \_Sx object. |
| 456 | * |
| 457 | * The sleep state package returned from the corresponding \_Sx_ object |
| 458 | * must contain at least one integer. |
| 459 | * |
| 460 | * March 2005: |
| 461 | * Added support for a package that contains two integers. This |
| 462 | * goes against the ACPI specification which defines this object as a |
| 463 | * package with one encoded DWORD integer. However, existing practice |
| 464 | * by many BIOS vendors is to return a package with 2 or more integer |
| 465 | * elements, at least one per sleep type (A/B). |
| 466 | * |
| 467 | * January 2013: |
| 468 | * Therefore, we must be prepared to accept a package with either a |
| 469 | * single integer or multiple integers. |
| 470 | * |
| 471 | * The single integer DWORD format is as follows: |
| 472 | * BYTE 0 - Value for the PM1A SLP_TYP register |
| 473 | * BYTE 1 - Value for the PM1B SLP_TYP register |
| 474 | * BYTE 2-3 - Reserved |
| 475 | * |
| 476 | * The dual integer format is as follows: |
| 477 | * Integer 0 - Value for the PM1A SLP_TYP register |
| 478 | * Integer 1 - Value for the PM1A SLP_TYP register |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 479 | * |
| 480 | ******************************************************************************/ |
| 481 | acpi_status |
| 482 | acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b) |
| 483 | { |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 484 | acpi_status status; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 485 | struct acpi_evaluate_info *info; |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 486 | union acpi_operand_object **elements; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 487 | |
| 488 | ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data); |
| 489 | |
| 490 | /* Validate parameters */ |
| 491 | |
| 492 | if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) { |
| 493 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 494 | } |
| 495 | |
| 496 | /* Allocate the evaluation information block */ |
| 497 | |
| 498 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 499 | if (!info) { |
| 500 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 501 | } |
| 502 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 503 | /* |
| 504 | * Evaluate the \_Sx namespace object containing the register values |
| 505 | * for this state |
| 506 | */ |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 507 | info->relative_pathname = |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 508 | ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 509 | status = acpi_ns_evaluate(info); |
| 510 | if (ACPI_FAILURE(status)) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 511 | goto cleanup; |
| 512 | } |
| 513 | |
| 514 | /* Must have a return object */ |
| 515 | |
| 516 | if (!info->return_object) { |
| 517 | ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 518 | info->relative_pathname)); |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 519 | status = AE_AML_NO_RETURN_VALUE; |
| 520 | goto cleanup; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 521 | } |
| 522 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 523 | /* Return object must be of type Package */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 524 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 525 | if (info->return_object->common.type != ACPI_TYPE_PACKAGE) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 526 | ACPI_ERROR((AE_INFO, |
| 527 | "Sleep State return object is not a Package")); |
| 528 | status = AE_AML_OPERAND_TYPE; |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 529 | goto cleanup1; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /* |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 533 | * Any warnings about the package length or the object types have |
| 534 | * already been issued by the predefined name module -- there is no |
| 535 | * need to repeat them here. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 536 | */ |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 537 | elements = info->return_object->package.elements; |
| 538 | switch (info->return_object->package.count) { |
| 539 | case 0: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 540 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 541 | status = AE_AML_PACKAGE_LIMIT; |
| 542 | break; |
| 543 | |
| 544 | case 1: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 545 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 546 | if (elements[0]->common.type != ACPI_TYPE_INTEGER) { |
| 547 | status = AE_AML_OPERAND_TYPE; |
| 548 | break; |
| 549 | } |
| 550 | |
| 551 | /* A valid _Sx_ package with one integer */ |
| 552 | |
| 553 | *sleep_type_a = (u8)elements[0]->integer.value; |
| 554 | *sleep_type_b = (u8)(elements[0]->integer.value >> 8); |
| 555 | break; |
| 556 | |
| 557 | case 2: |
| 558 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 559 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 560 | if ((elements[0]->common.type != ACPI_TYPE_INTEGER) || |
| 561 | (elements[1]->common.type != ACPI_TYPE_INTEGER)) { |
| 562 | status = AE_AML_OPERAND_TYPE; |
| 563 | break; |
| 564 | } |
| 565 | |
| 566 | /* A valid _Sx_ package with two integers */ |
| 567 | |
| 568 | *sleep_type_a = (u8)elements[0]->integer.value; |
| 569 | *sleep_type_b = (u8)elements[1]->integer.value; |
| 570 | break; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 571 | } |
| 572 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 573 | cleanup1: |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 574 | acpi_ut_remove_reference(info->return_object); |
| 575 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 576 | cleanup: |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 577 | if (ACPI_FAILURE(status)) { |
| 578 | ACPI_EXCEPTION((AE_INFO, status, |
| 579 | "While evaluating Sleep State [%s]", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 580 | info->relative_pathname)); |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 583 | ACPI_FREE(info); |
| 584 | return_ACPI_STATUS(status); |
| 585 | } |
| 586 | |
| 587 | ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data) |