blob: 04c2e16f2c0a6ef86ab734cd309cfb1ce41d49db [file] [log] [blame]
Bob Moore7db5d822008-12-30 11:04:48 +08001/******************************************************************************
2 *
3 * Module Name: hwxface - Public ACPICA hardware interfaces
4 *
5 *****************************************************************************/
6
7/*
Bob Moore25f044e2013-01-25 05:38:56 +00008 * Copyright (C) 2000 - 2013, Intel Corp.
Bob Moore7db5d822008-12-30 11:04:48 +08009 * 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
Paul Gortmaker214f2c92011-10-26 16:22:14 -040044#include <linux/export.h>
Bob Moore7db5d822008-12-30 11:04:48 +080045#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acnamesp.h"
Bob Moore7db5d822008-12-30 11:04:48 +080048
49#define _COMPONENT ACPI_HARDWARE
50ACPI_MODULE_NAME("hwxface")
51
52/******************************************************************************
53 *
Bob Moored3fd9022008-12-30 11:11:57 +080054 * FUNCTION: acpi_reset
55 *
56 * PARAMETERS: None
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
61 * support reset register in PCI config space, this must be
62 * handled separately.
63 *
64 ******************************************************************************/
65acpi_status acpi_reset(void)
66{
67 struct acpi_generic_address *reset_reg;
68 acpi_status status;
69
70 ACPI_FUNCTION_TRACE(acpi_reset);
71
72 reset_reg = &acpi_gbl_FADT.reset_register;
73
74 /* Check if the reset register is supported */
75
Linus Torvalds19244ad2012-04-20 11:19:35 -070076 if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) ||
77 !reset_reg->address) {
Bob Moored3fd9022008-12-30 11:11:57 +080078 return_ACPI_STATUS(AE_NOT_EXIST);
79 }
80
Bob Moore8a964232009-08-13 13:42:19 +080081 if (reset_reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
82 /*
Lv Zheng75c80442012-12-19 05:36:49 +000083 * For I/O space, write directly to the OSL. This bypasses the port
84 * validation mechanism, which may block a valid write to the reset
85 * register.
86 * Spec section 4.7.3.6 requires register width to be 8.
Bob Moore8a964232009-08-13 13:42:19 +080087 */
88 status =
89 acpi_os_write_port((acpi_io_address) reset_reg->address,
Matthew Garrettf17d9cb2011-03-11 16:12:18 -050090 acpi_gbl_FADT.reset_value, 8);
Bob Moore8a964232009-08-13 13:42:19 +080091 } else {
92 /* Write the reset value to the reset register */
Bob Moored3fd9022008-12-30 11:11:57 +080093
Bob Moore8a964232009-08-13 13:42:19 +080094 status = acpi_hw_write(acpi_gbl_FADT.reset_value, reset_reg);
95 }
96
Bob Moored3fd9022008-12-30 11:11:57 +080097 return_ACPI_STATUS(status);
98}
99
100ACPI_EXPORT_SYMBOL(acpi_reset)
101
102/******************************************************************************
103 *
Bob Moore7db5d822008-12-30 11:04:48 +0800104 * FUNCTION: acpi_read
105 *
Bob Mooreba494be2012-07-12 09:40:10 +0800106 * PARAMETERS: value - Where the value is returned
107 * reg - GAS register structure
Bob Moore7db5d822008-12-30 11:04:48 +0800108 *
109 * RETURN: Status
110 *
111 * DESCRIPTION: Read from either memory or IO space.
112 *
Bob Moorec6b57742009-06-24 09:44:06 +0800113 * LIMITATIONS: <These limitations also apply to acpi_write>
114 * bit_width must be exactly 8, 16, 32, or 64.
Bob Mooreba494be2012-07-12 09:40:10 +0800115 * space_ID must be system_memory or system_IO.
Bob Moorec6b57742009-06-24 09:44:06 +0800116 * bit_offset and access_width are currently ignored, as there has
117 * not been a need to implement these.
118 *
Bob Moore7db5d822008-12-30 11:04:48 +0800119 ******************************************************************************/
Bob Moorec6b57742009-06-24 09:44:06 +0800120acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
Bob Moore7db5d822008-12-30 11:04:48 +0800121{
Bob Moorec6b57742009-06-24 09:44:06 +0800122 u32 value;
Bob Moore7db5d822008-12-30 11:04:48 +0800123 u32 width;
124 u64 address;
125 acpi_status status;
126
127 ACPI_FUNCTION_NAME(acpi_read);
128
Bob Moorec6b57742009-06-24 09:44:06 +0800129 if (!return_value) {
Bob Mooreac0c8452009-02-18 14:28:02 +0800130 return (AE_BAD_PARAMETER);
Bob Moore7db5d822008-12-30 11:04:48 +0800131 }
132
Bob Moorec6b57742009-06-24 09:44:06 +0800133 /* Validate contents of the GAS register. Allow 64-bit transfers */
Bob Moore7db5d822008-12-30 11:04:48 +0800134
Bob Moorec6b57742009-06-24 09:44:06 +0800135 status = acpi_hw_validate_register(reg, 64, &address);
136 if (ACPI_FAILURE(status)) {
137 return (status);
Bob Moore7db5d822008-12-30 11:04:48 +0800138 }
139
Bob Moorec6b57742009-06-24 09:44:06 +0800140 /* Initialize entire 64-bit return value to zero */
Bob Moore7db5d822008-12-30 11:04:48 +0800141
Bob Moorec6b57742009-06-24 09:44:06 +0800142 *return_value = 0;
143 value = 0;
Bob Moore7db5d822008-12-30 11:04:48 +0800144
145 /*
Bob Moore88dcb042009-02-18 16:01:04 +0800146 * Two address spaces supported: Memory or IO. PCI_Config is
147 * not supported here because the GAS structure is insufficient
Bob Moore7db5d822008-12-30 11:04:48 +0800148 */
Bob Moorec6b57742009-06-24 09:44:06 +0800149 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
150 status = acpi_os_read_memory((acpi_physical_address)
Bob Moore653f4b52012-02-14 18:29:55 +0800151 address, return_value,
152 reg->bit_width);
Bob Moorec6b57742009-06-24 09:44:06 +0800153 if (ACPI_FAILURE(status)) {
154 return (status);
155 }
Bob Moorec6b57742009-06-24 09:44:06 +0800156 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
Bob Moore7db5d822008-12-30 11:04:48 +0800157
Bob Moore653f4b52012-02-14 18:29:55 +0800158 width = reg->bit_width;
159 if (width == 64) {
160 width = 32; /* Break into two 32-bit transfers */
161 }
162
Bob Moorec6b57742009-06-24 09:44:06 +0800163 status = acpi_hw_read_port((acpi_io_address)
164 address, &value, width);
165 if (ACPI_FAILURE(status)) {
166 return (status);
167 }
168 *return_value = value;
169
170 if (reg->bit_width == 64) {
171
172 /* Read the top 32 bits */
173
174 status = acpi_hw_read_port((acpi_io_address)
175 (address + 4), &value, 32);
176 if (ACPI_FAILURE(status)) {
177 return (status);
178 }
179 *return_value |= ((u64)value << 32);
180 }
Bob Moore7db5d822008-12-30 11:04:48 +0800181 }
182
183 ACPI_DEBUG_PRINT((ACPI_DB_IO,
Bob Moorec6b57742009-06-24 09:44:06 +0800184 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
185 ACPI_FORMAT_UINT64(*return_value), reg->bit_width,
186 ACPI_FORMAT_UINT64(address),
Bob Moore7db5d822008-12-30 11:04:48 +0800187 acpi_ut_get_region_name(reg->space_id)));
188
189 return (status);
190}
191
192ACPI_EXPORT_SYMBOL(acpi_read)
193
194/******************************************************************************
195 *
196 * FUNCTION: acpi_write
197 *
Bob Mooreba494be2012-07-12 09:40:10 +0800198 * PARAMETERS: value - Value to be written
199 * reg - GAS register structure
Bob Moore7db5d822008-12-30 11:04:48 +0800200 *
201 * RETURN: Status
202 *
203 * DESCRIPTION: Write to either memory or IO space.
204 *
205 ******************************************************************************/
Bob Moorec6b57742009-06-24 09:44:06 +0800206acpi_status acpi_write(u64 value, struct acpi_generic_address *reg)
Bob Moore7db5d822008-12-30 11:04:48 +0800207{
208 u32 width;
209 u64 address;
210 acpi_status status;
211
212 ACPI_FUNCTION_NAME(acpi_write);
213
Bob Moorec6b57742009-06-24 09:44:06 +0800214 /* Validate contents of the GAS register. Allow 64-bit transfers */
215
216 status = acpi_hw_validate_register(reg, 64, &address);
217 if (ACPI_FAILURE(status)) {
218 return (status);
Bob Moore7db5d822008-12-30 11:04:48 +0800219 }
220
Bob Moore7db5d822008-12-30 11:04:48 +0800221 /*
Bob Moorec6b57742009-06-24 09:44:06 +0800222 * Two address spaces supported: Memory or IO. PCI_Config is
223 * not supported here because the GAS structure is insufficient
Bob Moore7db5d822008-12-30 11:04:48 +0800224 */
Bob Moorec6b57742009-06-24 09:44:06 +0800225 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
226 status = acpi_os_write_memory((acpi_physical_address)
Bob Moore653f4b52012-02-14 18:29:55 +0800227 address, value, reg->bit_width);
Bob Moorec6b57742009-06-24 09:44:06 +0800228 if (ACPI_FAILURE(status)) {
229 return (status);
230 }
Bob Moorec6b57742009-06-24 09:44:06 +0800231 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
Bob Moore7db5d822008-12-30 11:04:48 +0800232
Bob Moore653f4b52012-02-14 18:29:55 +0800233 width = reg->bit_width;
234 if (width == 64) {
235 width = 32; /* Break into two 32-bit transfers */
236 }
237
Bob Moorec6b57742009-06-24 09:44:06 +0800238 status = acpi_hw_write_port((acpi_io_address)
239 address, ACPI_LODWORD(value),
Bob Moore7db5d822008-12-30 11:04:48 +0800240 width);
Bob Moorec6b57742009-06-24 09:44:06 +0800241 if (ACPI_FAILURE(status)) {
242 return (status);
243 }
Bob Moore7db5d822008-12-30 11:04:48 +0800244
Bob Moorec6b57742009-06-24 09:44:06 +0800245 if (reg->bit_width == 64) {
246 status = acpi_hw_write_port((acpi_io_address)
247 (address + 4),
248 ACPI_HIDWORD(value), 32);
249 if (ACPI_FAILURE(status)) {
250 return (status);
251 }
252 }
Bob Moore7db5d822008-12-30 11:04:48 +0800253 }
254
255 ACPI_DEBUG_PRINT((ACPI_DB_IO,
Bob Moorec6b57742009-06-24 09:44:06 +0800256 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
257 ACPI_FORMAT_UINT64(value), reg->bit_width,
258 ACPI_FORMAT_UINT64(address),
Bob Moore7db5d822008-12-30 11:04:48 +0800259 acpi_ut_get_region_name(reg->space_id)));
260
261 return (status);
262}
263
264ACPI_EXPORT_SYMBOL(acpi_write)
265
Bob Moore33620c52012-02-14 18:14:27 +0800266#if (!ACPI_REDUCED_HARDWARE)
Bob Moore7db5d822008-12-30 11:04:48 +0800267/*******************************************************************************
268 *
Bob Moore50ffba12009-02-23 15:02:07 +0800269 * FUNCTION: acpi_read_bit_register
Bob Moore7db5d822008-12-30 11:04:48 +0800270 *
Bob Moore9892dd22009-02-18 15:10:07 +0800271 * PARAMETERS: register_id - ID of ACPI Bit Register to access
272 * return_value - Value that was read from the register,
273 * normalized to bit position zero.
Bob Moore7db5d822008-12-30 11:04:48 +0800274 *
Bob Moore9892dd22009-02-18 15:10:07 +0800275 * RETURN: Status and the value read from the specified Register. Value
Bob Moore7db5d822008-12-30 11:04:48 +0800276 * returned is normalized to bit0 (is shifted all the way right)
277 *
278 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
279 *
Bob Moore9892dd22009-02-18 15:10:07 +0800280 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
281 * PM2 Control.
282 *
283 * Note: The hardware lock is not required when reading the ACPI bit registers
284 * since almost all of them are single bit and it does not matter that
285 * the parent hardware register can be split across two physical
286 * registers. The only multi-bit field is SLP_TYP in the PM1 control
287 * register, but this field does not cross an 8-bit boundary (nor does
288 * it make much sense to actually read this field.)
289 *
Bob Moore7db5d822008-12-30 11:04:48 +0800290 ******************************************************************************/
Bob Moore50ffba12009-02-23 15:02:07 +0800291acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value)
Bob Moore7db5d822008-12-30 11:04:48 +0800292{
Bob Moore7db5d822008-12-30 11:04:48 +0800293 struct acpi_bit_register_info *bit_reg_info;
Bob Moore88dcb042009-02-18 16:01:04 +0800294 u32 register_value;
295 u32 value;
Bob Moore7db5d822008-12-30 11:04:48 +0800296 acpi_status status;
297
Bob Moore88dcb042009-02-18 16:01:04 +0800298 ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id);
Bob Moore7db5d822008-12-30 11:04:48 +0800299
300 /* Get the info structure corresponding to the requested ACPI Register */
301
302 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
303 if (!bit_reg_info) {
304 return_ACPI_STATUS(AE_BAD_PARAMETER);
305 }
306
Bob Moore9892dd22009-02-18 15:10:07 +0800307 /* Read the entire parent register */
Bob Moore7db5d822008-12-30 11:04:48 +0800308
309 status = acpi_hw_register_read(bit_reg_info->parent_register,
310 &register_value);
Bob Moore88dcb042009-02-18 16:01:04 +0800311 if (ACPI_FAILURE(status)) {
312 return_ACPI_STATUS(status);
Bob Moore7db5d822008-12-30 11:04:48 +0800313 }
314
Bob Moore88dcb042009-02-18 16:01:04 +0800315 /* Normalize the value that was read, mask off other bits */
316
317 value = ((register_value & bit_reg_info->access_bit_mask)
318 >> bit_reg_info->bit_position);
319
320 ACPI_DEBUG_PRINT((ACPI_DB_IO,
321 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
322 register_id, bit_reg_info->parent_register,
323 register_value, value));
324
325 *return_value = value;
326 return_ACPI_STATUS(AE_OK);
Bob Moore7db5d822008-12-30 11:04:48 +0800327}
328
Bob Moore50ffba12009-02-23 15:02:07 +0800329ACPI_EXPORT_SYMBOL(acpi_read_bit_register)
Bob Moore7db5d822008-12-30 11:04:48 +0800330
331/*******************************************************************************
332 *
Bob Moore50ffba12009-02-23 15:02:07 +0800333 * FUNCTION: acpi_write_bit_register
Bob Moore7db5d822008-12-30 11:04:48 +0800334 *
Bob Moore9892dd22009-02-18 15:10:07 +0800335 * PARAMETERS: register_id - ID of ACPI Bit Register to access
Lv Zheng75c80442012-12-19 05:36:49 +0000336 * value - Value to write to the register, in bit
Justin P. Mattock42b2aa82011-11-28 20:31:00 -0800337 * position zero. The bit is automatically
Bob Moore9892dd22009-02-18 15:10:07 +0800338 * shifted to the correct position.
Bob Moore7db5d822008-12-30 11:04:48 +0800339 *
340 * RETURN: Status
341 *
Bob Moore9892dd22009-02-18 15:10:07 +0800342 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
343 * since most operations require a read/modify/write sequence.
344 *
345 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
346 * PM2 Control.
Bob Moore7db5d822008-12-30 11:04:48 +0800347 *
Bob Moore88dcb042009-02-18 16:01:04 +0800348 * Note that at this level, the fact that there may be actually two
349 * hardware registers (A and B - and B may not exist) is abstracted.
350 *
Bob Moore7db5d822008-12-30 11:04:48 +0800351 ******************************************************************************/
Bob Moore50ffba12009-02-23 15:02:07 +0800352acpi_status acpi_write_bit_register(u32 register_id, u32 value)
Bob Moore7db5d822008-12-30 11:04:48 +0800353{
Bob Moore7db5d822008-12-30 11:04:48 +0800354 struct acpi_bit_register_info *bit_reg_info;
Bob Moore7db5d822008-12-30 11:04:48 +0800355 acpi_cpu_flags lock_flags;
Bob Moore88dcb042009-02-18 16:01:04 +0800356 u32 register_value;
357 acpi_status status = AE_OK;
Bob Moore7db5d822008-12-30 11:04:48 +0800358
Bob Moore50ffba12009-02-23 15:02:07 +0800359 ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id);
Bob Moore7db5d822008-12-30 11:04:48 +0800360
361 /* Get the info structure corresponding to the requested ACPI Register */
362
363 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
364 if (!bit_reg_info) {
Bob Moore7db5d822008-12-30 11:04:48 +0800365 return_ACPI_STATUS(AE_BAD_PARAMETER);
366 }
367
368 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
369
Bob Moore7db5d822008-12-30 11:04:48 +0800370 /*
Bob Moore88dcb042009-02-18 16:01:04 +0800371 * At this point, we know that the parent register is one of the
372 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
Bob Moore7db5d822008-12-30 11:04:48 +0800373 */
Bob Moore88dcb042009-02-18 16:01:04 +0800374 if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) {
Bob Moore7db5d822008-12-30 11:04:48 +0800375 /*
Bob Moore88dcb042009-02-18 16:01:04 +0800376 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
377 *
378 * Perform a register read to preserve the bits that we are not
379 * interested in
Bob Moore7db5d822008-12-30 11:04:48 +0800380 */
Bob Moore88dcb042009-02-18 16:01:04 +0800381 status = acpi_hw_register_read(bit_reg_info->parent_register,
Bob Moore7db5d822008-12-30 11:04:48 +0800382 &register_value);
383 if (ACPI_FAILURE(status)) {
384 goto unlock_and_exit;
385 }
386
Bob Moore88dcb042009-02-18 16:01:04 +0800387 /*
388 * Insert the input bit into the value that was just read
389 * and write the register
390 */
Bob Moore7db5d822008-12-30 11:04:48 +0800391 ACPI_REGISTER_INSERT_VALUE(register_value,
392 bit_reg_info->bit_position,
393 bit_reg_info->access_bit_mask,
394 value);
395
Bob Moore88dcb042009-02-18 16:01:04 +0800396 status = acpi_hw_register_write(bit_reg_info->parent_register,
397 register_value);
398 } else {
399 /*
400 * 2) Case for PM1 Status
401 *
402 * The Status register is different from the rest. Clear an event
403 * by writing 1, writing 0 has no effect. So, the only relevant
404 * information is the single bit we're interested in, all others
405 * should be written as 0 so they will be left unchanged.
406 */
407 register_value = ACPI_REGISTER_PREPARE_BITS(value,
408 bit_reg_info->
409 bit_position,
410 bit_reg_info->
411 access_bit_mask);
Bob Moore7db5d822008-12-30 11:04:48 +0800412
Bob Moore88dcb042009-02-18 16:01:04 +0800413 /* No need to write the register if value is all zeros */
Bob Moore7db5d822008-12-30 11:04:48 +0800414
Bob Moore88dcb042009-02-18 16:01:04 +0800415 if (register_value) {
416 status =
417 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
418 register_value);
419 }
Bob Moore7db5d822008-12-30 11:04:48 +0800420 }
421
Bob Moore88dcb042009-02-18 16:01:04 +0800422 ACPI_DEBUG_PRINT((ACPI_DB_IO,
423 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
424 register_id, bit_reg_info->parent_register, value,
425 register_value));
426
427unlock_and_exit:
Bob Moore7db5d822008-12-30 11:04:48 +0800428
429 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Bob Moore7db5d822008-12-30 11:04:48 +0800430 return_ACPI_STATUS(status);
431}
432
Bob Moore50ffba12009-02-23 15:02:07 +0800433ACPI_EXPORT_SYMBOL(acpi_write_bit_register)
Bob Moore33620c52012-02-14 18:14:27 +0800434#endif /* !ACPI_REDUCED_HARDWARE */
Bob Moore7db5d822008-12-30 11:04:48 +0800435/*******************************************************************************
436 *
437 * FUNCTION: acpi_get_sleep_type_data
438 *
439 * PARAMETERS: sleep_state - Numeric sleep state
440 * *sleep_type_a - Where SLP_TYPa is returned
441 * *sleep_type_b - Where SLP_TYPb is returned
442 *
Bob Moore48ffb942013-01-25 05:41:00 +0000443 * RETURN: Status
Bob Moore7db5d822008-12-30 11:04:48 +0800444 *
Bob Moore48ffb942013-01-25 05:41:00 +0000445 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
446 * sleep state via the appropriate \_Sx object.
447 *
448 * The sleep state package returned from the corresponding \_Sx_ object
449 * must contain at least one integer.
450 *
451 * March 2005:
452 * Added support for a package that contains two integers. This
453 * goes against the ACPI specification which defines this object as a
454 * package with one encoded DWORD integer. However, existing practice
455 * by many BIOS vendors is to return a package with 2 or more integer
456 * elements, at least one per sleep type (A/B).
457 *
458 * January 2013:
459 * Therefore, we must be prepared to accept a package with either a
460 * single integer or multiple integers.
461 *
462 * The single integer DWORD format is as follows:
463 * BYTE 0 - Value for the PM1A SLP_TYP register
464 * BYTE 1 - Value for the PM1B SLP_TYP register
465 * BYTE 2-3 - Reserved
466 *
467 * The dual integer format is as follows:
468 * Integer 0 - Value for the PM1A SLP_TYP register
469 * Integer 1 - Value for the PM1A SLP_TYP register
Bob Moore7db5d822008-12-30 11:04:48 +0800470 *
471 ******************************************************************************/
472acpi_status
473acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
474{
Bob Moore48ffb942013-01-25 05:41:00 +0000475 acpi_status status;
Bob Moore7db5d822008-12-30 11:04:48 +0800476 struct acpi_evaluate_info *info;
Bob Moore48ffb942013-01-25 05:41:00 +0000477 union acpi_operand_object **elements;
Bob Moore7db5d822008-12-30 11:04:48 +0800478
479 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
480
481 /* Validate parameters */
482
483 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
484 return_ACPI_STATUS(AE_BAD_PARAMETER);
485 }
486
487 /* Allocate the evaluation information block */
488
489 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
490 if (!info) {
491 return_ACPI_STATUS(AE_NO_MEMORY);
492 }
493
Bob Moore48ffb942013-01-25 05:41:00 +0000494 /*
495 * Evaluate the \_Sx namespace object containing the register values
496 * for this state
497 */
Bob Moore7db5d822008-12-30 11:04:48 +0800498 info->pathname =
499 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
Bob Moore7db5d822008-12-30 11:04:48 +0800500 status = acpi_ns_evaluate(info);
501 if (ACPI_FAILURE(status)) {
Bob Moore7db5d822008-12-30 11:04:48 +0800502 goto cleanup;
503 }
504
505 /* Must have a return object */
506
507 if (!info->return_object) {
508 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
509 info->pathname));
Bob Moore48ffb942013-01-25 05:41:00 +0000510 status = AE_AML_NO_RETURN_VALUE;
511 goto cleanup;
Bob Moore7db5d822008-12-30 11:04:48 +0800512 }
513
Bob Moore48ffb942013-01-25 05:41:00 +0000514 /* Return object must be of type Package */
Bob Moore7db5d822008-12-30 11:04:48 +0800515
Bob Moore48ffb942013-01-25 05:41:00 +0000516 if (info->return_object->common.type != ACPI_TYPE_PACKAGE) {
Bob Moore7db5d822008-12-30 11:04:48 +0800517 ACPI_ERROR((AE_INFO,
518 "Sleep State return object is not a Package"));
519 status = AE_AML_OPERAND_TYPE;
Bob Moore48ffb942013-01-25 05:41:00 +0000520 goto cleanup1;
Bob Moore7db5d822008-12-30 11:04:48 +0800521 }
522
523 /*
Bob Moore48ffb942013-01-25 05:41:00 +0000524 * Any warnings about the package length or the object types have
525 * already been issued by the predefined name module -- there is no
526 * need to repeat them here.
Bob Moore7db5d822008-12-30 11:04:48 +0800527 */
Bob Moore48ffb942013-01-25 05:41:00 +0000528 elements = info->return_object->package.elements;
529 switch (info->return_object->package.count) {
530 case 0:
531 status = AE_AML_PACKAGE_LIMIT;
532 break;
533
534 case 1:
535 if (elements[0]->common.type != ACPI_TYPE_INTEGER) {
536 status = AE_AML_OPERAND_TYPE;
537 break;
538 }
539
540 /* A valid _Sx_ package with one integer */
541
542 *sleep_type_a = (u8)elements[0]->integer.value;
543 *sleep_type_b = (u8)(elements[0]->integer.value >> 8);
544 break;
545
546 case 2:
547 default:
548 if ((elements[0]->common.type != ACPI_TYPE_INTEGER) ||
549 (elements[1]->common.type != ACPI_TYPE_INTEGER)) {
550 status = AE_AML_OPERAND_TYPE;
551 break;
552 }
553
554 /* A valid _Sx_ package with two integers */
555
556 *sleep_type_a = (u8)elements[0]->integer.value;
557 *sleep_type_b = (u8)elements[1]->integer.value;
558 break;
Bob Moore7db5d822008-12-30 11:04:48 +0800559 }
560
Bob Moore48ffb942013-01-25 05:41:00 +0000561 cleanup1:
Bob Moore7db5d822008-12-30 11:04:48 +0800562 acpi_ut_remove_reference(info->return_object);
563
564 cleanup:
Bob Moore48ffb942013-01-25 05:41:00 +0000565 if (ACPI_FAILURE(status)) {
566 ACPI_EXCEPTION((AE_INFO, status,
567 "While evaluating Sleep State [%s]",
568 info->pathname));
569 }
570
Bob Moore7db5d822008-12-30 11:04:48 +0800571 ACPI_FREE(info);
572 return_ACPI_STATUS(status);
573}
574
575ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)