Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: hwxface - Public ACPICA hardware interfaces |
| 5 | * |
Bob Moore | 4441e55 | 2021-01-15 10:48:25 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2021, Intel Corp. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 9 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 10 | #define EXPORT_ACPI_INTERFACES |
| 11 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 12 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 13 | #include "accommon.h" |
| 14 | #include "acnamesp.h" |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 15 | |
| 16 | #define _COMPONENT ACPI_HARDWARE |
| 17 | ACPI_MODULE_NAME("hwxface") |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 21 | * FUNCTION: acpi_reset |
| 22 | * |
| 23 | * PARAMETERS: None |
| 24 | * |
| 25 | * RETURN: Status |
| 26 | * |
| 27 | * DESCRIPTION: Set reset register in memory or IO space. Note: Does not |
| 28 | * support reset register in PCI config space, this must be |
| 29 | * handled separately. |
| 30 | * |
| 31 | ******************************************************************************/ |
| 32 | acpi_status acpi_reset(void) |
| 33 | { |
| 34 | struct acpi_generic_address *reset_reg; |
| 35 | acpi_status status; |
| 36 | |
| 37 | ACPI_FUNCTION_TRACE(acpi_reset); |
| 38 | |
| 39 | reset_reg = &acpi_gbl_FADT.reset_register; |
| 40 | |
| 41 | /* Check if the reset register is supported */ |
| 42 | |
Linus Torvalds | 19244ad | 2012-04-20 11:19:35 -0700 | [diff] [blame] | 43 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) || |
| 44 | !reset_reg->address) { |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 45 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 46 | } |
| 47 | |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 48 | if (reset_reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { |
| 49 | /* |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 50 | * For I/O space, write directly to the OSL. This bypasses the port |
| 51 | * validation mechanism, which may block a valid write to the reset |
| 52 | * register. |
Bob Moore | e07fcfd | 2013-10-29 09:29:45 +0800 | [diff] [blame] | 53 | * |
| 54 | * NOTE: |
| 55 | * The ACPI spec requires the reset register width to be 8, so we |
| 56 | * hardcode it here and ignore the FADT value. This maintains |
| 57 | * compatibility with other ACPI implementations that have allowed |
| 58 | * BIOS code with bad register width values to go unnoticed. |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 59 | */ |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 60 | status = acpi_os_write_port((acpi_io_address)reset_reg->address, |
| 61 | acpi_gbl_FADT.reset_value, |
| 62 | ACPI_RESET_REGISTER_WIDTH); |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 63 | } else { |
| 64 | /* Write the reset value to the reset register */ |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 65 | |
Bob Moore | 8a96423 | 2009-08-13 13:42:19 +0800 | [diff] [blame] | 66 | status = acpi_hw_write(acpi_gbl_FADT.reset_value, reset_reg); |
| 67 | } |
| 68 | |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 69 | return_ACPI_STATUS(status); |
| 70 | } |
| 71 | |
| 72 | ACPI_EXPORT_SYMBOL(acpi_reset) |
| 73 | |
| 74 | /****************************************************************************** |
| 75 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 76 | * FUNCTION: acpi_read |
| 77 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 78 | * PARAMETERS: value - Where the value is returned |
| 79 | * reg - GAS register structure |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 80 | * |
| 81 | * RETURN: Status |
| 82 | * |
| 83 | * DESCRIPTION: Read from either memory or IO space. |
| 84 | * |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 85 | * LIMITATIONS: <These limitations also apply to acpi_write> |
| 86 | * bit_width must be exactly 8, 16, 32, or 64. |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 87 | * space_ID must be system_memory or system_IO. |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 88 | * bit_offset and access_width are currently ignored, as there has |
| 89 | * not been a need to implement these. |
| 90 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 91 | ******************************************************************************/ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 92 | acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 93 | { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 94 | acpi_status status; |
| 95 | |
| 96 | ACPI_FUNCTION_NAME(acpi_read); |
| 97 | |
Lv Zheng | 8381c54 | 2017-09-20 10:00:11 +0800 | [diff] [blame] | 98 | status = acpi_hw_read(return_value, reg); |
| 99 | return (status); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | ACPI_EXPORT_SYMBOL(acpi_read) |
| 103 | |
| 104 | /****************************************************************************** |
| 105 | * |
| 106 | * FUNCTION: acpi_write |
| 107 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 108 | * PARAMETERS: value - Value to be written |
| 109 | * reg - GAS register structure |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 110 | * |
| 111 | * RETURN: Status |
| 112 | * |
| 113 | * DESCRIPTION: Write to either memory or IO space. |
| 114 | * |
| 115 | ******************************************************************************/ |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 116 | acpi_status acpi_write(u64 value, struct acpi_generic_address *reg) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 117 | { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 118 | acpi_status status; |
| 119 | |
| 120 | ACPI_FUNCTION_NAME(acpi_write); |
| 121 | |
Lv Zheng | 8381c54 | 2017-09-20 10:00:11 +0800 | [diff] [blame] | 122 | status = acpi_hw_write(value, reg); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 123 | return (status); |
| 124 | } |
| 125 | |
| 126 | ACPI_EXPORT_SYMBOL(acpi_write) |
| 127 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 128 | #if (!ACPI_REDUCED_HARDWARE) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 129 | /******************************************************************************* |
| 130 | * |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 131 | * FUNCTION: acpi_read_bit_register |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 132 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 133 | * PARAMETERS: register_id - ID of ACPI Bit Register to access |
| 134 | * return_value - Value that was read from the register, |
| 135 | * normalized to bit position zero. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 136 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 137 | * RETURN: Status and the value read from the specified Register. Value |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 138 | * returned is normalized to bit0 (is shifted all the way right) |
| 139 | * |
| 140 | * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock. |
| 141 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 142 | * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and |
| 143 | * PM2 Control. |
| 144 | * |
| 145 | * Note: The hardware lock is not required when reading the ACPI bit registers |
| 146 | * since almost all of them are single bit and it does not matter that |
| 147 | * the parent hardware register can be split across two physical |
| 148 | * registers. The only multi-bit field is SLP_TYP in the PM1 control |
| 149 | * register, but this field does not cross an 8-bit boundary (nor does |
| 150 | * it make much sense to actually read this field.) |
| 151 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 152 | ******************************************************************************/ |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 153 | acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 154 | { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 155 | struct acpi_bit_register_info *bit_reg_info; |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 156 | u32 register_value; |
| 157 | u32 value; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 158 | acpi_status status; |
| 159 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 160 | ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 161 | |
| 162 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 163 | |
| 164 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
| 165 | if (!bit_reg_info) { |
| 166 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 167 | } |
| 168 | |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 169 | /* Read the entire parent register */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 170 | |
| 171 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
| 172 | ®ister_value); |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 173 | if (ACPI_FAILURE(status)) { |
| 174 | return_ACPI_STATUS(status); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 175 | } |
| 176 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 177 | /* Normalize the value that was read, mask off other bits */ |
| 178 | |
| 179 | value = ((register_value & bit_reg_info->access_bit_mask) |
| 180 | >> bit_reg_info->bit_position); |
| 181 | |
| 182 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 183 | "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n", |
| 184 | register_id, bit_reg_info->parent_register, |
| 185 | register_value, value)); |
| 186 | |
| 187 | *return_value = value; |
| 188 | return_ACPI_STATUS(AE_OK); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 189 | } |
| 190 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 191 | ACPI_EXPORT_SYMBOL(acpi_read_bit_register) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 192 | |
| 193 | /******************************************************************************* |
| 194 | * |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 195 | * FUNCTION: acpi_write_bit_register |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 196 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 197 | * PARAMETERS: register_id - ID of ACPI Bit Register to access |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 198 | * value - Value to write to the register, in bit |
Justin P. Mattock | 42b2aa8 | 2011-11-28 20:31:00 -0800 | [diff] [blame] | 199 | * position zero. The bit is automatically |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 200 | * shifted to the correct position. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 201 | * |
| 202 | * RETURN: Status |
| 203 | * |
Bob Moore | 9892dd2 | 2009-02-18 15:10:07 +0800 | [diff] [blame] | 204 | * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock |
| 205 | * since most operations require a read/modify/write sequence. |
| 206 | * |
| 207 | * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and |
| 208 | * PM2 Control. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 209 | * |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 210 | * Note that at this level, the fact that there may be actually two |
| 211 | * hardware registers (A and B - and B may not exist) is abstracted. |
| 212 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 213 | ******************************************************************************/ |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 214 | acpi_status acpi_write_bit_register(u32 register_id, u32 value) |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 215 | { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 216 | struct acpi_bit_register_info *bit_reg_info; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 217 | acpi_cpu_flags lock_flags; |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 218 | u32 register_value; |
| 219 | acpi_status status = AE_OK; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 220 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 221 | ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 222 | |
| 223 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 224 | |
| 225 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
| 226 | if (!bit_reg_info) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 227 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 228 | } |
| 229 | |
Steven Rostedt | c57c0ad | 2018-04-25 16:28:27 +0200 | [diff] [blame] | 230 | lock_flags = acpi_os_acquire_raw_lock(acpi_gbl_hardware_lock); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 231 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 232 | /* |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 233 | * At this point, we know that the parent register is one of the |
| 234 | * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 235 | */ |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 236 | if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 237 | /* |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 238 | * 1) Case for PM1 Enable, PM1 Control, and PM2 Control |
| 239 | * |
| 240 | * Perform a register read to preserve the bits that we are not |
| 241 | * interested in |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 242 | */ |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 243 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 244 | ®ister_value); |
| 245 | if (ACPI_FAILURE(status)) { |
| 246 | goto unlock_and_exit; |
| 247 | } |
| 248 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 249 | /* |
| 250 | * Insert the input bit into the value that was just read |
| 251 | * and write the register |
| 252 | */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 253 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 254 | bit_reg_info->bit_position, |
| 255 | bit_reg_info->access_bit_mask, |
| 256 | value); |
| 257 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 258 | status = acpi_hw_register_write(bit_reg_info->parent_register, |
| 259 | register_value); |
| 260 | } else { |
| 261 | /* |
| 262 | * 2) Case for PM1 Status |
| 263 | * |
| 264 | * The Status register is different from the rest. Clear an event |
| 265 | * by writing 1, writing 0 has no effect. So, the only relevant |
| 266 | * information is the single bit we're interested in, all others |
| 267 | * should be written as 0 so they will be left unchanged. |
| 268 | */ |
| 269 | register_value = ACPI_REGISTER_PREPARE_BITS(value, |
| 270 | bit_reg_info-> |
| 271 | bit_position, |
| 272 | bit_reg_info-> |
| 273 | access_bit_mask); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 274 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 275 | /* No need to write the register if value is all zeros */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 276 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 277 | if (register_value) { |
| 278 | status = |
| 279 | acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
| 280 | register_value); |
| 281 | } |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 282 | } |
| 283 | |
Bob Moore | 88dcb04 | 2009-02-18 16:01:04 +0800 | [diff] [blame] | 284 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 285 | "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n", |
| 286 | register_id, bit_reg_info->parent_register, value, |
| 287 | register_value)); |
| 288 | |
| 289 | unlock_and_exit: |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 290 | |
Steven Rostedt | c57c0ad | 2018-04-25 16:28:27 +0200 | [diff] [blame] | 291 | acpi_os_release_raw_lock(acpi_gbl_hardware_lock, lock_flags); |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 292 | return_ACPI_STATUS(status); |
| 293 | } |
| 294 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 295 | ACPI_EXPORT_SYMBOL(acpi_write_bit_register) |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 296 | #endif /* !ACPI_REDUCED_HARDWARE */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 297 | /******************************************************************************* |
| 298 | * |
| 299 | * FUNCTION: acpi_get_sleep_type_data |
| 300 | * |
| 301 | * PARAMETERS: sleep_state - Numeric sleep state |
| 302 | * *sleep_type_a - Where SLP_TYPa is returned |
| 303 | * *sleep_type_b - Where SLP_TYPb is returned |
| 304 | * |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 305 | * RETURN: Status |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 306 | * |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 307 | * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested |
| 308 | * sleep state via the appropriate \_Sx object. |
| 309 | * |
| 310 | * The sleep state package returned from the corresponding \_Sx_ object |
| 311 | * must contain at least one integer. |
| 312 | * |
| 313 | * March 2005: |
| 314 | * Added support for a package that contains two integers. This |
| 315 | * goes against the ACPI specification which defines this object as a |
| 316 | * package with one encoded DWORD integer. However, existing practice |
| 317 | * by many BIOS vendors is to return a package with 2 or more integer |
| 318 | * elements, at least one per sleep type (A/B). |
| 319 | * |
| 320 | * January 2013: |
| 321 | * Therefore, we must be prepared to accept a package with either a |
| 322 | * single integer or multiple integers. |
| 323 | * |
| 324 | * The single integer DWORD format is as follows: |
| 325 | * BYTE 0 - Value for the PM1A SLP_TYP register |
| 326 | * BYTE 1 - Value for the PM1B SLP_TYP register |
| 327 | * BYTE 2-3 - Reserved |
| 328 | * |
| 329 | * The dual integer format is as follows: |
| 330 | * Integer 0 - Value for the PM1A SLP_TYP register |
| 331 | * Integer 1 - Value for the PM1A SLP_TYP register |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 332 | * |
| 333 | ******************************************************************************/ |
| 334 | acpi_status |
| 335 | acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b) |
| 336 | { |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 337 | acpi_status status; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 338 | struct acpi_evaluate_info *info; |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 339 | union acpi_operand_object **elements; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 340 | |
| 341 | ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data); |
| 342 | |
| 343 | /* Validate parameters */ |
| 344 | |
| 345 | if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) { |
| 346 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 347 | } |
| 348 | |
| 349 | /* Allocate the evaluation information block */ |
| 350 | |
| 351 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 352 | if (!info) { |
| 353 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 354 | } |
| 355 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 356 | /* |
| 357 | * Evaluate the \_Sx namespace object containing the register values |
| 358 | * for this state |
| 359 | */ |
Bob Moore | 0dfaaa3 | 2016-03-24 09:40:40 +0800 | [diff] [blame] | 360 | info->relative_pathname = acpi_gbl_sleep_state_names[sleep_state]; |
Prarit Bhargava | a59b679 | 2015-12-29 13:52:41 +0800 | [diff] [blame] | 361 | |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 362 | status = acpi_ns_evaluate(info); |
| 363 | if (ACPI_FAILURE(status)) { |
Prarit Bhargava | a59b679 | 2015-12-29 13:52:41 +0800 | [diff] [blame] | 364 | if (status == AE_NOT_FOUND) { |
| 365 | |
| 366 | /* The _Sx states are optional, ignore NOT_FOUND */ |
| 367 | |
| 368 | goto final_cleanup; |
| 369 | } |
| 370 | |
| 371 | goto warning_cleanup; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* Must have a return object */ |
| 375 | |
| 376 | if (!info->return_object) { |
| 377 | ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 378 | info->relative_pathname)); |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 379 | status = AE_AML_NO_RETURN_VALUE; |
Prarit Bhargava | a59b679 | 2015-12-29 13:52:41 +0800 | [diff] [blame] | 380 | goto warning_cleanup; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 381 | } |
| 382 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 383 | /* Return object must be of type Package */ |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 384 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 385 | if (info->return_object->common.type != ACPI_TYPE_PACKAGE) { |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 386 | ACPI_ERROR((AE_INFO, |
| 387 | "Sleep State return object is not a Package")); |
| 388 | status = AE_AML_OPERAND_TYPE; |
Prarit Bhargava | a59b679 | 2015-12-29 13:52:41 +0800 | [diff] [blame] | 389 | goto return_value_cleanup; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /* |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 393 | * Any warnings about the package length or the object types have |
| 394 | * already been issued by the predefined name module -- there is no |
| 395 | * need to repeat them here. |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 396 | */ |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 397 | elements = info->return_object->package.elements; |
| 398 | switch (info->return_object->package.count) { |
| 399 | case 0: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 400 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 401 | status = AE_AML_PACKAGE_LIMIT; |
| 402 | break; |
| 403 | |
| 404 | case 1: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 405 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 406 | if (elements[0]->common.type != ACPI_TYPE_INTEGER) { |
| 407 | status = AE_AML_OPERAND_TYPE; |
| 408 | break; |
| 409 | } |
| 410 | |
| 411 | /* A valid _Sx_ package with one integer */ |
| 412 | |
| 413 | *sleep_type_a = (u8)elements[0]->integer.value; |
| 414 | *sleep_type_b = (u8)(elements[0]->integer.value >> 8); |
| 415 | break; |
| 416 | |
| 417 | case 2: |
| 418 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 419 | |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 420 | if ((elements[0]->common.type != ACPI_TYPE_INTEGER) || |
| 421 | (elements[1]->common.type != ACPI_TYPE_INTEGER)) { |
| 422 | status = AE_AML_OPERAND_TYPE; |
| 423 | break; |
| 424 | } |
| 425 | |
| 426 | /* A valid _Sx_ package with two integers */ |
| 427 | |
| 428 | *sleep_type_a = (u8)elements[0]->integer.value; |
| 429 | *sleep_type_b = (u8)elements[1]->integer.value; |
| 430 | break; |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 431 | } |
| 432 | |
Prarit Bhargava | a59b679 | 2015-12-29 13:52:41 +0800 | [diff] [blame] | 433 | return_value_cleanup: |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 434 | acpi_ut_remove_reference(info->return_object); |
| 435 | |
Prarit Bhargava | a59b679 | 2015-12-29 13:52:41 +0800 | [diff] [blame] | 436 | warning_cleanup: |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 437 | if (ACPI_FAILURE(status)) { |
| 438 | ACPI_EXCEPTION((AE_INFO, status, |
| 439 | "While evaluating Sleep State [%s]", |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 440 | info->relative_pathname)); |
Bob Moore | 48ffb94 | 2013-01-25 05:41:00 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Prarit Bhargava | a59b679 | 2015-12-29 13:52:41 +0800 | [diff] [blame] | 443 | final_cleanup: |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 444 | ACPI_FREE(info); |
| 445 | return_ACPI_STATUS(status); |
| 446 | } |
| 447 | |
| 448 | ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data) |