blob: 7bfd649d1996e6945d2d21787858ca9d0dcbc0e0 [file] [log] [blame]
Bob Moore7db5d822008-12-30 11:04:48 +08001
2/******************************************************************************
3 *
4 * Module Name: hwxface - Public ACPICA hardware interfaces
5 *
6 *****************************************************************************/
7
8/*
Bob Moore77848132012-01-12 13:27:23 +08009 * Copyright (C) 2000 - 2012, Intel Corp.
Bob Moore7db5d822008-12-30 11:04:48 +080010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
Paul Gortmaker214f2c92011-10-26 16:22:14 -040045#include <linux/export.h>
Bob Moore7db5d822008-12-30 11:04:48 +080046#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050047#include "accommon.h"
48#include "acnamesp.h"
Bob Moore7db5d822008-12-30 11:04:48 +080049
50#define _COMPONENT ACPI_HARDWARE
51ACPI_MODULE_NAME("hwxface")
52
53/******************************************************************************
54 *
Bob Moored3fd9022008-12-30 11:11:57 +080055 * 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 ******************************************************************************/
66acpi_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 Torvalds19244ad2012-04-20 11:19:35 -070077 if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) ||
78 !reset_reg->address) {
Bob Moored3fd9022008-12-30 11:11:57 +080079 return_ACPI_STATUS(AE_NOT_EXIST);
80 }
81
Bob Moore8a964232009-08-13 13:42:19 +080082 if (reset_reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
83 /*
Matthew Garrettf17d9cb2011-03-11 16:12:18 -050084 * For I/O space, write directly to the OSL. This
85 * bypasses the port validation mechanism, which may
86 * block a valid write to the reset register. Spec
87 * section 4.7.3.6 requires register width to be 8.
Bob Moore8a964232009-08-13 13:42:19 +080088 */
89 status =
90 acpi_os_write_port((acpi_io_address) reset_reg->address,
Matthew Garrettf17d9cb2011-03-11 16:12:18 -050091 acpi_gbl_FADT.reset_value, 8);
Bob Moore8a964232009-08-13 13:42:19 +080092 } else {
93 /* Write the reset value to the reset register */
Bob Moored3fd9022008-12-30 11:11:57 +080094
Bob Moore8a964232009-08-13 13:42:19 +080095 status = acpi_hw_write(acpi_gbl_FADT.reset_value, reset_reg);
96 }
97
Bob Moored3fd9022008-12-30 11:11:57 +080098 return_ACPI_STATUS(status);
99}
100
101ACPI_EXPORT_SYMBOL(acpi_reset)
102
103/******************************************************************************
104 *
Bob Moore7db5d822008-12-30 11:04:48 +0800105 * FUNCTION: acpi_read
106 *
Bob Mooreba494be2012-07-12 09:40:10 +0800107 * PARAMETERS: value - Where the value is returned
108 * reg - GAS register structure
Bob Moore7db5d822008-12-30 11:04:48 +0800109 *
110 * RETURN: Status
111 *
112 * DESCRIPTION: Read from either memory or IO space.
113 *
Bob Moorec6b57742009-06-24 09:44:06 +0800114 * LIMITATIONS: <These limitations also apply to acpi_write>
115 * bit_width must be exactly 8, 16, 32, or 64.
Bob Mooreba494be2012-07-12 09:40:10 +0800116 * space_ID must be system_memory or system_IO.
Bob Moorec6b57742009-06-24 09:44:06 +0800117 * bit_offset and access_width are currently ignored, as there has
118 * not been a need to implement these.
119 *
Bob Moore7db5d822008-12-30 11:04:48 +0800120 ******************************************************************************/
Bob Moorec6b57742009-06-24 09:44:06 +0800121acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
Bob Moore7db5d822008-12-30 11:04:48 +0800122{
Bob Moorec6b57742009-06-24 09:44:06 +0800123 u32 value;
Bob Moore7db5d822008-12-30 11:04:48 +0800124 u32 width;
125 u64 address;
126 acpi_status status;
127
128 ACPI_FUNCTION_NAME(acpi_read);
129
Bob Moorec6b57742009-06-24 09:44:06 +0800130 if (!return_value) {
Bob Mooreac0c8452009-02-18 14:28:02 +0800131 return (AE_BAD_PARAMETER);
Bob Moore7db5d822008-12-30 11:04:48 +0800132 }
133
Bob Moorec6b57742009-06-24 09:44:06 +0800134 /* Validate contents of the GAS register. Allow 64-bit transfers */
Bob Moore7db5d822008-12-30 11:04:48 +0800135
Bob Moorec6b57742009-06-24 09:44:06 +0800136 status = acpi_hw_validate_register(reg, 64, &address);
137 if (ACPI_FAILURE(status)) {
138 return (status);
Bob Moore7db5d822008-12-30 11:04:48 +0800139 }
140
Bob Moorec6b57742009-06-24 09:44:06 +0800141 /* Initialize entire 64-bit return value to zero */
Bob Moore7db5d822008-12-30 11:04:48 +0800142
Bob Moorec6b57742009-06-24 09:44:06 +0800143 *return_value = 0;
144 value = 0;
Bob Moore7db5d822008-12-30 11:04:48 +0800145
146 /*
Bob Moore88dcb042009-02-18 16:01:04 +0800147 * Two address spaces supported: Memory or IO. PCI_Config is
148 * not supported here because the GAS structure is insufficient
Bob Moore7db5d822008-12-30 11:04:48 +0800149 */
Bob Moorec6b57742009-06-24 09:44:06 +0800150 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
151 status = acpi_os_read_memory((acpi_physical_address)
Bob Moore653f4b52012-02-14 18:29:55 +0800152 address, return_value,
153 reg->bit_width);
Bob Moorec6b57742009-06-24 09:44:06 +0800154 if (ACPI_FAILURE(status)) {
155 return (status);
156 }
Bob Moorec6b57742009-06-24 09:44:06 +0800157 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
Bob Moore7db5d822008-12-30 11:04:48 +0800158
Bob Moore653f4b52012-02-14 18:29:55 +0800159 width = reg->bit_width;
160 if (width == 64) {
161 width = 32; /* Break into two 32-bit transfers */
162 }
163
Bob Moorec6b57742009-06-24 09:44:06 +0800164 status = acpi_hw_read_port((acpi_io_address)
165 address, &value, width);
166 if (ACPI_FAILURE(status)) {
167 return (status);
168 }
169 *return_value = value;
170
171 if (reg->bit_width == 64) {
172
173 /* Read the top 32 bits */
174
175 status = acpi_hw_read_port((acpi_io_address)
176 (address + 4), &value, 32);
177 if (ACPI_FAILURE(status)) {
178 return (status);
179 }
180 *return_value |= ((u64)value << 32);
181 }
Bob Moore7db5d822008-12-30 11:04:48 +0800182 }
183
184 ACPI_DEBUG_PRINT((ACPI_DB_IO,
Bob Moorec6b57742009-06-24 09:44:06 +0800185 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
186 ACPI_FORMAT_UINT64(*return_value), reg->bit_width,
187 ACPI_FORMAT_UINT64(address),
Bob Moore7db5d822008-12-30 11:04:48 +0800188 acpi_ut_get_region_name(reg->space_id)));
189
190 return (status);
191}
192
193ACPI_EXPORT_SYMBOL(acpi_read)
194
195/******************************************************************************
196 *
197 * FUNCTION: acpi_write
198 *
Bob Mooreba494be2012-07-12 09:40:10 +0800199 * PARAMETERS: value - Value to be written
200 * reg - GAS register structure
Bob Moore7db5d822008-12-30 11:04:48 +0800201 *
202 * RETURN: Status
203 *
204 * DESCRIPTION: Write to either memory or IO space.
205 *
206 ******************************************************************************/
Bob Moorec6b57742009-06-24 09:44:06 +0800207acpi_status acpi_write(u64 value, struct acpi_generic_address *reg)
Bob Moore7db5d822008-12-30 11:04:48 +0800208{
209 u32 width;
210 u64 address;
211 acpi_status status;
212
213 ACPI_FUNCTION_NAME(acpi_write);
214
Bob Moorec6b57742009-06-24 09:44:06 +0800215 /* Validate contents of the GAS register. Allow 64-bit transfers */
216
217 status = acpi_hw_validate_register(reg, 64, &address);
218 if (ACPI_FAILURE(status)) {
219 return (status);
Bob Moore7db5d822008-12-30 11:04:48 +0800220 }
221
Bob Moore7db5d822008-12-30 11:04:48 +0800222 /*
Bob Moorec6b57742009-06-24 09:44:06 +0800223 * Two address spaces supported: Memory or IO. PCI_Config is
224 * not supported here because the GAS structure is insufficient
Bob Moore7db5d822008-12-30 11:04:48 +0800225 */
Bob Moorec6b57742009-06-24 09:44:06 +0800226 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
227 status = acpi_os_write_memory((acpi_physical_address)
Bob Moore653f4b52012-02-14 18:29:55 +0800228 address, value, reg->bit_width);
Bob Moorec6b57742009-06-24 09:44:06 +0800229 if (ACPI_FAILURE(status)) {
230 return (status);
231 }
Bob Moorec6b57742009-06-24 09:44:06 +0800232 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
Bob Moore7db5d822008-12-30 11:04:48 +0800233
Bob Moore653f4b52012-02-14 18:29:55 +0800234 width = reg->bit_width;
235 if (width == 64) {
236 width = 32; /* Break into two 32-bit transfers */
237 }
238
Bob Moorec6b57742009-06-24 09:44:06 +0800239 status = acpi_hw_write_port((acpi_io_address)
240 address, ACPI_LODWORD(value),
Bob Moore7db5d822008-12-30 11:04:48 +0800241 width);
Bob Moorec6b57742009-06-24 09:44:06 +0800242 if (ACPI_FAILURE(status)) {
243 return (status);
244 }
Bob Moore7db5d822008-12-30 11:04:48 +0800245
Bob Moorec6b57742009-06-24 09:44:06 +0800246 if (reg->bit_width == 64) {
247 status = acpi_hw_write_port((acpi_io_address)
248 (address + 4),
249 ACPI_HIDWORD(value), 32);
250 if (ACPI_FAILURE(status)) {
251 return (status);
252 }
253 }
Bob Moore7db5d822008-12-30 11:04:48 +0800254 }
255
256 ACPI_DEBUG_PRINT((ACPI_DB_IO,
Bob Moorec6b57742009-06-24 09:44:06 +0800257 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
258 ACPI_FORMAT_UINT64(value), reg->bit_width,
259 ACPI_FORMAT_UINT64(address),
Bob Moore7db5d822008-12-30 11:04:48 +0800260 acpi_ut_get_region_name(reg->space_id)));
261
262 return (status);
263}
264
265ACPI_EXPORT_SYMBOL(acpi_write)
266
Bob Moore33620c52012-02-14 18:14:27 +0800267#if (!ACPI_REDUCED_HARDWARE)
Bob Moore7db5d822008-12-30 11:04:48 +0800268/*******************************************************************************
269 *
Bob Moore50ffba12009-02-23 15:02:07 +0800270 * FUNCTION: acpi_read_bit_register
Bob Moore7db5d822008-12-30 11:04:48 +0800271 *
Bob Moore9892dd22009-02-18 15:10:07 +0800272 * PARAMETERS: register_id - ID of ACPI Bit Register to access
273 * return_value - Value that was read from the register,
274 * normalized to bit position zero.
Bob Moore7db5d822008-12-30 11:04:48 +0800275 *
Bob Moore9892dd22009-02-18 15:10:07 +0800276 * RETURN: Status and the value read from the specified Register. Value
Bob Moore7db5d822008-12-30 11:04:48 +0800277 * returned is normalized to bit0 (is shifted all the way right)
278 *
279 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
280 *
Bob Moore9892dd22009-02-18 15:10:07 +0800281 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
282 * PM2 Control.
283 *
284 * Note: The hardware lock is not required when reading the ACPI bit registers
285 * since almost all of them are single bit and it does not matter that
286 * the parent hardware register can be split across two physical
287 * registers. The only multi-bit field is SLP_TYP in the PM1 control
288 * register, but this field does not cross an 8-bit boundary (nor does
289 * it make much sense to actually read this field.)
290 *
Bob Moore7db5d822008-12-30 11:04:48 +0800291 ******************************************************************************/
Bob Moore50ffba12009-02-23 15:02:07 +0800292acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value)
Bob Moore7db5d822008-12-30 11:04:48 +0800293{
Bob Moore7db5d822008-12-30 11:04:48 +0800294 struct acpi_bit_register_info *bit_reg_info;
Bob Moore88dcb042009-02-18 16:01:04 +0800295 u32 register_value;
296 u32 value;
Bob Moore7db5d822008-12-30 11:04:48 +0800297 acpi_status status;
298
Bob Moore88dcb042009-02-18 16:01:04 +0800299 ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id);
Bob Moore7db5d822008-12-30 11:04:48 +0800300
301 /* Get the info structure corresponding to the requested ACPI Register */
302
303 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
304 if (!bit_reg_info) {
305 return_ACPI_STATUS(AE_BAD_PARAMETER);
306 }
307
Bob Moore9892dd22009-02-18 15:10:07 +0800308 /* Read the entire parent register */
Bob Moore7db5d822008-12-30 11:04:48 +0800309
310 status = acpi_hw_register_read(bit_reg_info->parent_register,
311 &register_value);
Bob Moore88dcb042009-02-18 16:01:04 +0800312 if (ACPI_FAILURE(status)) {
313 return_ACPI_STATUS(status);
Bob Moore7db5d822008-12-30 11:04:48 +0800314 }
315
Bob Moore88dcb042009-02-18 16:01:04 +0800316 /* Normalize the value that was read, mask off other bits */
317
318 value = ((register_value & bit_reg_info->access_bit_mask)
319 >> bit_reg_info->bit_position);
320
321 ACPI_DEBUG_PRINT((ACPI_DB_IO,
322 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
323 register_id, bit_reg_info->parent_register,
324 register_value, value));
325
326 *return_value = value;
327 return_ACPI_STATUS(AE_OK);
Bob Moore7db5d822008-12-30 11:04:48 +0800328}
329
Bob Moore50ffba12009-02-23 15:02:07 +0800330ACPI_EXPORT_SYMBOL(acpi_read_bit_register)
Bob Moore7db5d822008-12-30 11:04:48 +0800331
332/*******************************************************************************
333 *
Bob Moore50ffba12009-02-23 15:02:07 +0800334 * FUNCTION: acpi_write_bit_register
Bob Moore7db5d822008-12-30 11:04:48 +0800335 *
Bob Moore9892dd22009-02-18 15:10:07 +0800336 * PARAMETERS: register_id - ID of ACPI Bit Register to access
337 * Value - Value to write to the register, in bit
Justin P. Mattock42b2aa82011-11-28 20:31:00 -0800338 * position zero. The bit is automatically
Bob Moore9892dd22009-02-18 15:10:07 +0800339 * shifted to the correct position.
Bob Moore7db5d822008-12-30 11:04:48 +0800340 *
341 * RETURN: Status
342 *
Bob Moore9892dd22009-02-18 15:10:07 +0800343 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
344 * since most operations require a read/modify/write sequence.
345 *
346 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
347 * PM2 Control.
Bob Moore7db5d822008-12-30 11:04:48 +0800348 *
Bob Moore88dcb042009-02-18 16:01:04 +0800349 * Note that at this level, the fact that there may be actually two
350 * hardware registers (A and B - and B may not exist) is abstracted.
351 *
Bob Moore7db5d822008-12-30 11:04:48 +0800352 ******************************************************************************/
Bob Moore50ffba12009-02-23 15:02:07 +0800353acpi_status acpi_write_bit_register(u32 register_id, u32 value)
Bob Moore7db5d822008-12-30 11:04:48 +0800354{
Bob Moore7db5d822008-12-30 11:04:48 +0800355 struct acpi_bit_register_info *bit_reg_info;
Bob Moore7db5d822008-12-30 11:04:48 +0800356 acpi_cpu_flags lock_flags;
Bob Moore88dcb042009-02-18 16:01:04 +0800357 u32 register_value;
358 acpi_status status = AE_OK;
Bob Moore7db5d822008-12-30 11:04:48 +0800359
Bob Moore50ffba12009-02-23 15:02:07 +0800360 ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id);
Bob Moore7db5d822008-12-30 11:04:48 +0800361
362 /* Get the info structure corresponding to the requested ACPI Register */
363
364 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
365 if (!bit_reg_info) {
Bob Moore7db5d822008-12-30 11:04:48 +0800366 return_ACPI_STATUS(AE_BAD_PARAMETER);
367 }
368
369 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
370
Bob Moore7db5d822008-12-30 11:04:48 +0800371 /*
Bob Moore88dcb042009-02-18 16:01:04 +0800372 * At this point, we know that the parent register is one of the
373 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
Bob Moore7db5d822008-12-30 11:04:48 +0800374 */
Bob Moore88dcb042009-02-18 16:01:04 +0800375 if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) {
Bob Moore7db5d822008-12-30 11:04:48 +0800376 /*
Bob Moore88dcb042009-02-18 16:01:04 +0800377 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
378 *
379 * Perform a register read to preserve the bits that we are not
380 * interested in
Bob Moore7db5d822008-12-30 11:04:48 +0800381 */
Bob Moore88dcb042009-02-18 16:01:04 +0800382 status = acpi_hw_register_read(bit_reg_info->parent_register,
Bob Moore7db5d822008-12-30 11:04:48 +0800383 &register_value);
384 if (ACPI_FAILURE(status)) {
385 goto unlock_and_exit;
386 }
387
Bob Moore88dcb042009-02-18 16:01:04 +0800388 /*
389 * Insert the input bit into the value that was just read
390 * and write the register
391 */
Bob Moore7db5d822008-12-30 11:04:48 +0800392 ACPI_REGISTER_INSERT_VALUE(register_value,
393 bit_reg_info->bit_position,
394 bit_reg_info->access_bit_mask,
395 value);
396
Bob Moore88dcb042009-02-18 16:01:04 +0800397 status = acpi_hw_register_write(bit_reg_info->parent_register,
398 register_value);
399 } else {
400 /*
401 * 2) Case for PM1 Status
402 *
403 * The Status register is different from the rest. Clear an event
404 * by writing 1, writing 0 has no effect. So, the only relevant
405 * information is the single bit we're interested in, all others
406 * should be written as 0 so they will be left unchanged.
407 */
408 register_value = ACPI_REGISTER_PREPARE_BITS(value,
409 bit_reg_info->
410 bit_position,
411 bit_reg_info->
412 access_bit_mask);
Bob Moore7db5d822008-12-30 11:04:48 +0800413
Bob Moore88dcb042009-02-18 16:01:04 +0800414 /* No need to write the register if value is all zeros */
Bob Moore7db5d822008-12-30 11:04:48 +0800415
Bob Moore88dcb042009-02-18 16:01:04 +0800416 if (register_value) {
417 status =
418 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
419 register_value);
420 }
Bob Moore7db5d822008-12-30 11:04:48 +0800421 }
422
Bob Moore88dcb042009-02-18 16:01:04 +0800423 ACPI_DEBUG_PRINT((ACPI_DB_IO,
424 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
425 register_id, bit_reg_info->parent_register, value,
426 register_value));
427
428unlock_and_exit:
Bob Moore7db5d822008-12-30 11:04:48 +0800429
430 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Bob Moore7db5d822008-12-30 11:04:48 +0800431 return_ACPI_STATUS(status);
432}
433
Bob Moore50ffba12009-02-23 15:02:07 +0800434ACPI_EXPORT_SYMBOL(acpi_write_bit_register)
Bob Moore33620c52012-02-14 18:14:27 +0800435#endif /* !ACPI_REDUCED_HARDWARE */
Bob Moore7db5d822008-12-30 11:04:48 +0800436/*******************************************************************************
437 *
438 * FUNCTION: acpi_get_sleep_type_data
439 *
440 * PARAMETERS: sleep_state - Numeric sleep state
441 * *sleep_type_a - Where SLP_TYPa is returned
442 * *sleep_type_b - Where SLP_TYPb is returned
443 *
Bob Mooreba494be2012-07-12 09:40:10 +0800444 * RETURN: status - ACPI status
Bob Moore7db5d822008-12-30 11:04:48 +0800445 *
446 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
447 * state.
448 *
449 ******************************************************************************/
450acpi_status
451acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
452{
453 acpi_status status = AE_OK;
454 struct acpi_evaluate_info *info;
455
456 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
457
458 /* Validate parameters */
459
460 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
461 return_ACPI_STATUS(AE_BAD_PARAMETER);
462 }
463
464 /* Allocate the evaluation information block */
465
466 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
467 if (!info) {
468 return_ACPI_STATUS(AE_NO_MEMORY);
469 }
470
471 info->pathname =
472 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
473
474 /* Evaluate the namespace object containing the values for this state */
475
476 status = acpi_ns_evaluate(info);
477 if (ACPI_FAILURE(status)) {
478 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
479 "%s while evaluating SleepState [%s]\n",
480 acpi_format_exception(status),
481 info->pathname));
482
483 goto cleanup;
484 }
485
486 /* Must have a return object */
487
488 if (!info->return_object) {
489 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
490 info->pathname));
491 status = AE_NOT_EXIST;
492 }
493
494 /* It must be of type Package */
495
Bob Moore3371c192009-02-18 14:44:03 +0800496 else if (info->return_object->common.type != ACPI_TYPE_PACKAGE) {
Bob Moore7db5d822008-12-30 11:04:48 +0800497 ACPI_ERROR((AE_INFO,
498 "Sleep State return object is not a Package"));
499 status = AE_AML_OPERAND_TYPE;
500 }
501
502 /*
503 * The package must have at least two elements. NOTE (March 2005): This
504 * goes against the current ACPI spec which defines this object as a
505 * package with one encoded DWORD element. However, existing practice
506 * by BIOS vendors seems to be to have 2 or more elements, at least
507 * one per sleep type (A/B).
508 */
509 else if (info->return_object->package.count < 2) {
510 ACPI_ERROR((AE_INFO,
511 "Sleep State return package does not have at least two elements"));
512 status = AE_AML_NO_OPERAND;
513 }
514
515 /* The first two elements must both be of type Integer */
516
Bob Moore3371c192009-02-18 14:44:03 +0800517 else if (((info->return_object->package.elements[0])->common.type
Bob Moore7db5d822008-12-30 11:04:48 +0800518 != ACPI_TYPE_INTEGER) ||
Bob Moore3371c192009-02-18 14:44:03 +0800519 ((info->return_object->package.elements[1])->common.type
Bob Moore7db5d822008-12-30 11:04:48 +0800520 != ACPI_TYPE_INTEGER)) {
521 ACPI_ERROR((AE_INFO,
Bob Moored4913dc2009-03-06 10:05:18 +0800522 "Sleep State return package elements are not both Integers "
523 "(%s, %s)",
Bob Moore7db5d822008-12-30 11:04:48 +0800524 acpi_ut_get_object_type_name(info->return_object->
525 package.elements[0]),
526 acpi_ut_get_object_type_name(info->return_object->
527 package.elements[1])));
528 status = AE_AML_OPERAND_TYPE;
529 } else {
530 /* Valid _Sx_ package size, type, and value */
531
532 *sleep_type_a = (u8)
533 (info->return_object->package.elements[0])->integer.value;
534 *sleep_type_b = (u8)
535 (info->return_object->package.elements[1])->integer.value;
536 }
537
538 if (ACPI_FAILURE(status)) {
539 ACPI_EXCEPTION((AE_INFO, status,
540 "While evaluating SleepState [%s], bad Sleep object %p type %s",
541 info->pathname, info->return_object,
542 acpi_ut_get_object_type_name(info->
543 return_object)));
544 }
545
546 acpi_ut_remove_reference(info->return_object);
547
548 cleanup:
549 ACPI_FREE(info);
550 return_ACPI_STATUS(status);
551}
552
553ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)