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