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