xref: /openbmc/linux/drivers/acpi/acpica/hwxface.c (revision 612c2932)
195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
295b482a8SLen Brown /******************************************************************************
395b482a8SLen Brown  *
495b482a8SLen Brown  * Module Name: hwxface - Public ACPICA hardware interfaces
595b482a8SLen Brown  *
6*612c2932SBob Moore  * Copyright (C) 2000 - 2023, Intel Corp.
795b482a8SLen Brown  *
895857638SErik Schmauss  *****************************************************************************/
995b482a8SLen Brown 
10839e928fSLv Zheng #define EXPORT_ACPI_INTERFACES
11839e928fSLv Zheng 
1295b482a8SLen Brown #include <acpi/acpi.h>
13e2f7a777SLen Brown #include "accommon.h"
14e2f7a777SLen Brown #include "acnamesp.h"
1595b482a8SLen Brown 
1695b482a8SLen Brown #define _COMPONENT          ACPI_HARDWARE
1795b482a8SLen Brown ACPI_MODULE_NAME("hwxface")
1895b482a8SLen Brown 
1995b482a8SLen Brown /******************************************************************************
2095b482a8SLen Brown  *
2195b482a8SLen Brown  * FUNCTION:    acpi_reset
2295b482a8SLen Brown  *
2395b482a8SLen Brown  * PARAMETERS:  None
2495b482a8SLen Brown  *
2595b482a8SLen Brown  * RETURN:      Status
2695b482a8SLen Brown  *
2795b482a8SLen Brown  * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
2895b482a8SLen Brown  *              support reset register in PCI config space, this must be
2995b482a8SLen Brown  *              handled separately.
3095b482a8SLen Brown  *
3195b482a8SLen Brown  ******************************************************************************/
acpi_reset(void)3295b482a8SLen Brown acpi_status acpi_reset(void)
3395b482a8SLen Brown {
3495b482a8SLen Brown 	struct acpi_generic_address *reset_reg;
3595b482a8SLen Brown 	acpi_status status;
3695b482a8SLen Brown 
3795b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_reset);
3895b482a8SLen Brown 
3995b482a8SLen Brown 	reset_reg = &acpi_gbl_FADT.reset_register;
4095b482a8SLen Brown 
4195b482a8SLen Brown 	/* Check if the reset register is supported */
4295b482a8SLen Brown 
4319244ad0SLinus Torvalds 	if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) ||
4419244ad0SLinus Torvalds 	    !reset_reg->address) {
4595b482a8SLen Brown 		return_ACPI_STATUS(AE_NOT_EXIST);
4695b482a8SLen Brown 	}
4795b482a8SLen Brown 
488a964236SBob Moore 	if (reset_reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
498a964236SBob Moore 		/*
5075c8044fSLv Zheng 		 * For I/O space, write directly to the OSL. This bypasses the port
5175c8044fSLv Zheng 		 * validation mechanism, which may block a valid write to the reset
5275c8044fSLv Zheng 		 * register.
53e07fcfd8SBob Moore 		 *
54e07fcfd8SBob Moore 		 * NOTE:
55e07fcfd8SBob Moore 		 * The ACPI spec requires the reset register width to be 8, so we
56e07fcfd8SBob Moore 		 * hardcode it here and ignore the FADT value. This maintains
57e07fcfd8SBob Moore 		 * compatibility with other ACPI implementations that have allowed
58e07fcfd8SBob Moore 		 * BIOS code with bad register width values to go unnoticed.
598a964236SBob Moore 		 */
60f5c1e1c5SLv Zheng 		status = acpi_os_write_port((acpi_io_address)reset_reg->address,
61e07fcfd8SBob Moore 					    acpi_gbl_FADT.reset_value,
62e07fcfd8SBob Moore 					    ACPI_RESET_REGISTER_WIDTH);
638a964236SBob Moore 	} else {
6495b482a8SLen Brown 		/* Write the reset value to the reset register */
6595b482a8SLen Brown 
66c6b5774cSBob Moore 		status = acpi_hw_write(acpi_gbl_FADT.reset_value, reset_reg);
678a964236SBob Moore 	}
688a964236SBob Moore 
6995b482a8SLen Brown 	return_ACPI_STATUS(status);
7095b482a8SLen Brown }
7195b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_reset)7295b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_reset)
7395b482a8SLen Brown 
7495b482a8SLen Brown /******************************************************************************
7595b482a8SLen Brown  *
7695b482a8SLen Brown  * FUNCTION:    acpi_read
7795b482a8SLen Brown  *
78ba494beeSBob Moore  * PARAMETERS:  value               - Where the value is returned
79ba494beeSBob Moore  *              reg                 - GAS register structure
8095b482a8SLen Brown  *
8195b482a8SLen Brown  * RETURN:      Status
8295b482a8SLen Brown  *
8395b482a8SLen Brown  * DESCRIPTION: Read from either memory or IO space.
8495b482a8SLen Brown  *
85c6b5774cSBob Moore  * LIMITATIONS: <These limitations also apply to acpi_write>
86c6b5774cSBob Moore  *      bit_width must be exactly 8, 16, 32, or 64.
87ba494beeSBob Moore  *      space_ID must be system_memory or system_IO.
88c6b5774cSBob Moore  *      bit_offset and access_width are currently ignored, as there has
89c6b5774cSBob Moore  *          not been a need to implement these.
90c6b5774cSBob Moore  *
9195b482a8SLen Brown  ******************************************************************************/
92c6b5774cSBob Moore acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
9395b482a8SLen Brown {
9495b482a8SLen Brown 	acpi_status status;
9595b482a8SLen Brown 
9695b482a8SLen Brown 	ACPI_FUNCTION_NAME(acpi_read);
9795b482a8SLen Brown 
988381c54fSLv Zheng 	status = acpi_hw_read(return_value, reg);
99c6b5774cSBob Moore 	return (status);
10095b482a8SLen Brown }
10195b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_read)10295b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_read)
10395b482a8SLen Brown 
10495b482a8SLen Brown /******************************************************************************
10595b482a8SLen Brown  *
10695b482a8SLen Brown  * FUNCTION:    acpi_write
10795b482a8SLen Brown  *
108ba494beeSBob Moore  * PARAMETERS:  value               - Value to be written
109ba494beeSBob Moore  *              reg                 - GAS register structure
11095b482a8SLen Brown  *
11195b482a8SLen Brown  * RETURN:      Status
11295b482a8SLen Brown  *
11395b482a8SLen Brown  * DESCRIPTION: Write to either memory or IO space.
11495b482a8SLen Brown  *
11595b482a8SLen Brown  ******************************************************************************/
116c6b5774cSBob Moore acpi_status acpi_write(u64 value, struct acpi_generic_address *reg)
11795b482a8SLen Brown {
11895b482a8SLen Brown 	acpi_status status;
11995b482a8SLen Brown 
12095b482a8SLen Brown 	ACPI_FUNCTION_NAME(acpi_write);
12195b482a8SLen Brown 
1228381c54fSLv Zheng 	status = acpi_hw_write(value, reg);
12395b482a8SLen Brown 	return (status);
12495b482a8SLen Brown }
12595b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_write)12695b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_write)
12795b482a8SLen Brown 
12833620c54SBob Moore #if (!ACPI_REDUCED_HARDWARE)
12995b482a8SLen Brown /*******************************************************************************
13095b482a8SLen Brown  *
13150ffba1bSBob Moore  * FUNCTION:    acpi_read_bit_register
13295b482a8SLen Brown  *
1339892dd23SBob Moore  * PARAMETERS:  register_id     - ID of ACPI Bit Register to access
1349892dd23SBob Moore  *              return_value    - Value that was read from the register,
1359892dd23SBob Moore  *                                normalized to bit position zero.
13695b482a8SLen Brown  *
1379892dd23SBob Moore  * RETURN:      Status and the value read from the specified Register. Value
13895b482a8SLen Brown  *              returned is normalized to bit0 (is shifted all the way right)
13995b482a8SLen Brown  *
14095b482a8SLen Brown  * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
14195b482a8SLen Brown  *
1429892dd23SBob Moore  * SUPPORTS:    Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
1439892dd23SBob Moore  *              PM2 Control.
1449892dd23SBob Moore  *
1459892dd23SBob Moore  * Note: The hardware lock is not required when reading the ACPI bit registers
1469892dd23SBob Moore  *       since almost all of them are single bit and it does not matter that
1479892dd23SBob Moore  *       the parent hardware register can be split across two physical
1489892dd23SBob Moore  *       registers. The only multi-bit field is SLP_TYP in the PM1 control
1499892dd23SBob Moore  *       register, but this field does not cross an 8-bit boundary (nor does
1509892dd23SBob Moore  *       it make much sense to actually read this field.)
1519892dd23SBob Moore  *
15295b482a8SLen Brown  ******************************************************************************/
15350ffba1bSBob Moore acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value)
15495b482a8SLen Brown {
15595b482a8SLen Brown 	struct acpi_bit_register_info *bit_reg_info;
15688dcb04aSBob Moore 	u32 register_value;
15788dcb04aSBob Moore 	u32 value;
15895b482a8SLen Brown 	acpi_status status;
15995b482a8SLen Brown 
16088dcb04aSBob Moore 	ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id);
16195b482a8SLen Brown 
16295b482a8SLen Brown 	/* Get the info structure corresponding to the requested ACPI Register */
16395b482a8SLen Brown 
16495b482a8SLen Brown 	bit_reg_info = acpi_hw_get_bit_register_info(register_id);
16595b482a8SLen Brown 	if (!bit_reg_info) {
16695b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
16795b482a8SLen Brown 	}
16895b482a8SLen Brown 
1699892dd23SBob Moore 	/* Read the entire parent register */
17095b482a8SLen Brown 
17195b482a8SLen Brown 	status = acpi_hw_register_read(bit_reg_info->parent_register,
17295b482a8SLen Brown 				       &register_value);
17388dcb04aSBob Moore 	if (ACPI_FAILURE(status)) {
17488dcb04aSBob Moore 		return_ACPI_STATUS(status);
17595b482a8SLen Brown 	}
17695b482a8SLen Brown 
17788dcb04aSBob Moore 	/* Normalize the value that was read, mask off other bits */
17888dcb04aSBob Moore 
17988dcb04aSBob Moore 	value = ((register_value & bit_reg_info->access_bit_mask)
18088dcb04aSBob Moore 		 >> bit_reg_info->bit_position);
18188dcb04aSBob Moore 
18288dcb04aSBob Moore 	ACPI_DEBUG_PRINT((ACPI_DB_IO,
18388dcb04aSBob Moore 			  "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
18488dcb04aSBob Moore 			  register_id, bit_reg_info->parent_register,
18588dcb04aSBob Moore 			  register_value, value));
18688dcb04aSBob Moore 
18788dcb04aSBob Moore 	*return_value = value;
18888dcb04aSBob Moore 	return_ACPI_STATUS(AE_OK);
18995b482a8SLen Brown }
19095b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_read_bit_register)19150ffba1bSBob Moore ACPI_EXPORT_SYMBOL(acpi_read_bit_register)
19295b482a8SLen Brown 
19395b482a8SLen Brown /*******************************************************************************
19495b482a8SLen Brown  *
19550ffba1bSBob Moore  * FUNCTION:    acpi_write_bit_register
19695b482a8SLen Brown  *
1979892dd23SBob Moore  * PARAMETERS:  register_id     - ID of ACPI Bit Register to access
19875c8044fSLv Zheng  *              value           - Value to write to the register, in bit
19942b2aa86SJustin P. Mattock  *                                position zero. The bit is automatically
2009892dd23SBob Moore  *                                shifted to the correct position.
20195b482a8SLen Brown  *
20295b482a8SLen Brown  * RETURN:      Status
20395b482a8SLen Brown  *
2049892dd23SBob Moore  * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
2059892dd23SBob Moore  *              since most operations require a read/modify/write sequence.
2069892dd23SBob Moore  *
2079892dd23SBob Moore  * SUPPORTS:    Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
2089892dd23SBob Moore  *              PM2 Control.
20995b482a8SLen Brown  *
21088dcb04aSBob Moore  * Note that at this level, the fact that there may be actually two
21188dcb04aSBob Moore  * hardware registers (A and B - and B may not exist) is abstracted.
21288dcb04aSBob Moore  *
21395b482a8SLen Brown  ******************************************************************************/
21450ffba1bSBob Moore acpi_status acpi_write_bit_register(u32 register_id, u32 value)
21595b482a8SLen Brown {
21695b482a8SLen Brown 	struct acpi_bit_register_info *bit_reg_info;
21795b482a8SLen Brown 	acpi_cpu_flags lock_flags;
21888dcb04aSBob Moore 	u32 register_value;
21988dcb04aSBob Moore 	acpi_status status = AE_OK;
22095b482a8SLen Brown 
22150ffba1bSBob Moore 	ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id);
22295b482a8SLen Brown 
22395b482a8SLen Brown 	/* Get the info structure corresponding to the requested ACPI Register */
22495b482a8SLen Brown 
22595b482a8SLen Brown 	bit_reg_info = acpi_hw_get_bit_register_info(register_id);
22695b482a8SLen Brown 	if (!bit_reg_info) {
22795b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
22895b482a8SLen Brown 	}
22995b482a8SLen Brown 
230c57c0ad4SSteven Rostedt 	lock_flags = acpi_os_acquire_raw_lock(acpi_gbl_hardware_lock);
23195b482a8SLen Brown 
23288dcb04aSBob Moore 	/*
23388dcb04aSBob Moore 	 * At this point, we know that the parent register is one of the
23488dcb04aSBob Moore 	 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
23588dcb04aSBob Moore 	 */
23688dcb04aSBob Moore 	if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) {
23788dcb04aSBob Moore 		/*
23888dcb04aSBob Moore 		 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
23988dcb04aSBob Moore 		 *
24088dcb04aSBob Moore 		 * Perform a register read to preserve the bits that we are not
24188dcb04aSBob Moore 		 * interested in
24288dcb04aSBob Moore 		 */
24395b482a8SLen Brown 		status = acpi_hw_register_read(bit_reg_info->parent_register,
24495b482a8SLen Brown 					       &register_value);
24595b482a8SLen Brown 		if (ACPI_FAILURE(status)) {
24695b482a8SLen Brown 			goto unlock_and_exit;
24795b482a8SLen Brown 		}
24895b482a8SLen Brown 
24995b482a8SLen Brown 		/*
25088dcb04aSBob Moore 		 * Insert the input bit into the value that was just read
25188dcb04aSBob Moore 		 * and write the register
25295b482a8SLen Brown 		 */
25388dcb04aSBob Moore 		ACPI_REGISTER_INSERT_VALUE(register_value,
25495b482a8SLen Brown 					   bit_reg_info->bit_position,
25588dcb04aSBob Moore 					   bit_reg_info->access_bit_mask,
25688dcb04aSBob Moore 					   value);
25788dcb04aSBob Moore 
25888dcb04aSBob Moore 		status = acpi_hw_register_write(bit_reg_info->parent_register,
25988dcb04aSBob Moore 						register_value);
26088dcb04aSBob Moore 	} else {
26188dcb04aSBob Moore 		/*
26288dcb04aSBob Moore 		 * 2) Case for PM1 Status
26388dcb04aSBob Moore 		 *
26488dcb04aSBob Moore 		 * The Status register is different from the rest. Clear an event
26588dcb04aSBob Moore 		 * by writing 1, writing 0 has no effect. So, the only relevant
26688dcb04aSBob Moore 		 * information is the single bit we're interested in, all others
26788dcb04aSBob Moore 		 * should be written as 0 so they will be left unchanged.
26888dcb04aSBob Moore 		 */
26988dcb04aSBob Moore 		register_value = ACPI_REGISTER_PREPARE_BITS(value,
27088dcb04aSBob Moore 							    bit_reg_info->
27188dcb04aSBob Moore 							    bit_position,
27295b482a8SLen Brown 							    bit_reg_info->
27395b482a8SLen Brown 							    access_bit_mask);
27488dcb04aSBob Moore 
27588dcb04aSBob Moore 		/* No need to write the register if value is all zeros */
27688dcb04aSBob Moore 
27788dcb04aSBob Moore 		if (register_value) {
27895b482a8SLen Brown 			status =
27995b482a8SLen Brown 			    acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
28088dcb04aSBob Moore 						   register_value);
28195b482a8SLen Brown 		}
28288dcb04aSBob Moore 	}
28395b482a8SLen Brown 
28488dcb04aSBob Moore 	ACPI_DEBUG_PRINT((ACPI_DB_IO,
28588dcb04aSBob Moore 			  "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
28688dcb04aSBob Moore 			  register_id, bit_reg_info->parent_register, value,
28795b482a8SLen Brown 			  register_value));
28895b482a8SLen Brown 
28995b482a8SLen Brown unlock_and_exit:
29095b482a8SLen Brown 
291c57c0ad4SSteven Rostedt 	acpi_os_release_raw_lock(acpi_gbl_hardware_lock, lock_flags);
29295b482a8SLen Brown 	return_ACPI_STATUS(status);
29395b482a8SLen Brown }
29495b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_write_bit_register)29550ffba1bSBob Moore ACPI_EXPORT_SYMBOL(acpi_write_bit_register)
29633620c54SBob Moore #endif				/* !ACPI_REDUCED_HARDWARE */
29795b482a8SLen Brown /*******************************************************************************
29895b482a8SLen Brown  *
29995b482a8SLen Brown  * FUNCTION:    acpi_get_sleep_type_data
30095b482a8SLen Brown  *
30195b482a8SLen Brown  * PARAMETERS:  sleep_state         - Numeric sleep state
30295b482a8SLen Brown  *              *sleep_type_a        - Where SLP_TYPa is returned
30395b482a8SLen Brown  *              *sleep_type_b        - Where SLP_TYPb is returned
30495b482a8SLen Brown  *
30548ffb94fSBob Moore  * RETURN:      Status
30695b482a8SLen Brown  *
30748ffb94fSBob Moore  * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
30848ffb94fSBob Moore  *              sleep state via the appropriate \_Sx object.
30948ffb94fSBob Moore  *
31048ffb94fSBob Moore  *  The sleep state package returned from the corresponding \_Sx_ object
31148ffb94fSBob Moore  *  must contain at least one integer.
31248ffb94fSBob Moore  *
31348ffb94fSBob Moore  *  March 2005:
31448ffb94fSBob Moore  *  Added support for a package that contains two integers. This
31548ffb94fSBob Moore  *  goes against the ACPI specification which defines this object as a
31648ffb94fSBob Moore  *  package with one encoded DWORD integer. However, existing practice
31748ffb94fSBob Moore  *  by many BIOS vendors is to return a package with 2 or more integer
31848ffb94fSBob Moore  *  elements, at least one per sleep type (A/B).
31948ffb94fSBob Moore  *
32048ffb94fSBob Moore  *  January 2013:
32148ffb94fSBob Moore  *  Therefore, we must be prepared to accept a package with either a
32248ffb94fSBob Moore  *  single integer or multiple integers.
32348ffb94fSBob Moore  *
32448ffb94fSBob Moore  *  The single integer DWORD format is as follows:
32548ffb94fSBob Moore  *      BYTE 0 - Value for the PM1A SLP_TYP register
32648ffb94fSBob Moore  *      BYTE 1 - Value for the PM1B SLP_TYP register
32748ffb94fSBob Moore  *      BYTE 2-3 - Reserved
32848ffb94fSBob Moore  *
32948ffb94fSBob Moore  *  The dual integer format is as follows:
33048ffb94fSBob Moore  *      Integer 0 - Value for the PM1A SLP_TYP register
33148ffb94fSBob Moore  *      Integer 1 - Value for the PM1A SLP_TYP register
33295b482a8SLen Brown  *
33395b482a8SLen Brown  ******************************************************************************/
33495b482a8SLen Brown acpi_status
33595b482a8SLen Brown acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
33695b482a8SLen Brown {
33748ffb94fSBob Moore 	acpi_status status;
33895b482a8SLen Brown 	struct acpi_evaluate_info *info;
33948ffb94fSBob Moore 	union acpi_operand_object **elements;
34095b482a8SLen Brown 
34195b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
34295b482a8SLen Brown 
34395b482a8SLen Brown 	/* Validate parameters */
34495b482a8SLen Brown 
34595b482a8SLen Brown 	if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
34695b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
34795b482a8SLen Brown 	}
34895b482a8SLen Brown 
34995b482a8SLen Brown 	/* Allocate the evaluation information block */
35095b482a8SLen Brown 
35195b482a8SLen Brown 	info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
35295b482a8SLen Brown 	if (!info) {
35395b482a8SLen Brown 		return_ACPI_STATUS(AE_NO_MEMORY);
35495b482a8SLen Brown 	}
35595b482a8SLen Brown 
35648ffb94fSBob Moore 	/*
35748ffb94fSBob Moore 	 * Evaluate the \_Sx namespace object containing the register values
35848ffb94fSBob Moore 	 * for this state
35948ffb94fSBob Moore 	 */
3600dfaaa3dSBob Moore 	info->relative_pathname = acpi_gbl_sleep_state_names[sleep_state];
361a59b679aSPrarit Bhargava 
36295b482a8SLen Brown 	status = acpi_ns_evaluate(info);
36395b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
364a59b679aSPrarit Bhargava 		if (status == AE_NOT_FOUND) {
365a59b679aSPrarit Bhargava 
366a59b679aSPrarit Bhargava 			/* The _Sx states are optional, ignore NOT_FOUND */
367a59b679aSPrarit Bhargava 
368a59b679aSPrarit Bhargava 			goto final_cleanup;
369a59b679aSPrarit Bhargava 		}
370a59b679aSPrarit Bhargava 
371a59b679aSPrarit Bhargava 		goto warning_cleanup;
37295b482a8SLen Brown 	}
37395b482a8SLen Brown 
37495b482a8SLen Brown 	/* Must have a return object */
37595b482a8SLen Brown 
37695b482a8SLen Brown 	if (!info->return_object) {
37795b482a8SLen Brown 		ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
37829a241ccSBob Moore 			    info->relative_pathname));
37948ffb94fSBob Moore 		status = AE_AML_NO_RETURN_VALUE;
380a59b679aSPrarit Bhargava 		goto warning_cleanup;
38195b482a8SLen Brown 	}
38295b482a8SLen Brown 
38348ffb94fSBob Moore 	/* Return object must be of type Package */
38495b482a8SLen Brown 
38548ffb94fSBob Moore 	if (info->return_object->common.type != ACPI_TYPE_PACKAGE) {
38695b482a8SLen Brown 		ACPI_ERROR((AE_INFO,
38795b482a8SLen Brown 			    "Sleep State return object is not a Package"));
38895b482a8SLen Brown 		status = AE_AML_OPERAND_TYPE;
389a59b679aSPrarit Bhargava 		goto return_value_cleanup;
39095b482a8SLen Brown 	}
39195b482a8SLen Brown 
39295b482a8SLen Brown 	/*
39348ffb94fSBob Moore 	 * Any warnings about the package length or the object types have
39448ffb94fSBob Moore 	 * already been issued by the predefined name module -- there is no
39548ffb94fSBob Moore 	 * need to repeat them here.
39695b482a8SLen Brown 	 */
39748ffb94fSBob Moore 	elements = info->return_object->package.elements;
39848ffb94fSBob Moore 	switch (info->return_object->package.count) {
39948ffb94fSBob Moore 	case 0:
4001d1ea1b7SChao Guan 
40148ffb94fSBob Moore 		status = AE_AML_PACKAGE_LIMIT;
40248ffb94fSBob Moore 		break;
40395b482a8SLen Brown 
40448ffb94fSBob Moore 	case 1:
4051d1ea1b7SChao Guan 
40648ffb94fSBob Moore 		if (elements[0]->common.type != ACPI_TYPE_INTEGER) {
40795b482a8SLen Brown 			status = AE_AML_OPERAND_TYPE;
40848ffb94fSBob Moore 			break;
40995b482a8SLen Brown 		}
41095b482a8SLen Brown 
41148ffb94fSBob Moore 		/* A valid _Sx_ package with one integer */
41248ffb94fSBob Moore 
41348ffb94fSBob Moore 		*sleep_type_a = (u8)elements[0]->integer.value;
41448ffb94fSBob Moore 		*sleep_type_b = (u8)(elements[0]->integer.value >> 8);
41548ffb94fSBob Moore 		break;
41648ffb94fSBob Moore 
41748ffb94fSBob Moore 	case 2:
41848ffb94fSBob Moore 	default:
4191d1ea1b7SChao Guan 
42048ffb94fSBob Moore 		if ((elements[0]->common.type != ACPI_TYPE_INTEGER) ||
42148ffb94fSBob Moore 		    (elements[1]->common.type != ACPI_TYPE_INTEGER)) {
42248ffb94fSBob Moore 			status = AE_AML_OPERAND_TYPE;
42348ffb94fSBob Moore 			break;
42495b482a8SLen Brown 		}
42595b482a8SLen Brown 
42648ffb94fSBob Moore 		/* A valid _Sx_ package with two integers */
42748ffb94fSBob Moore 
42848ffb94fSBob Moore 		*sleep_type_a = (u8)elements[0]->integer.value;
42948ffb94fSBob Moore 		*sleep_type_b = (u8)elements[1]->integer.value;
43048ffb94fSBob Moore 		break;
43148ffb94fSBob Moore 	}
43248ffb94fSBob Moore 
433a59b679aSPrarit Bhargava return_value_cleanup:
43495b482a8SLen Brown 	acpi_ut_remove_reference(info->return_object);
43595b482a8SLen Brown 
436a59b679aSPrarit Bhargava warning_cleanup:
43748ffb94fSBob Moore 	if (ACPI_FAILURE(status)) {
43848ffb94fSBob Moore 		ACPI_EXCEPTION((AE_INFO, status,
43948ffb94fSBob Moore 				"While evaluating Sleep State [%s]",
44029a241ccSBob Moore 				info->relative_pathname));
44148ffb94fSBob Moore 	}
44248ffb94fSBob Moore 
443a59b679aSPrarit Bhargava final_cleanup:
44495b482a8SLen Brown 	ACPI_FREE(info);
44595b482a8SLen Brown 	return_ACPI_STATUS(status);
44695b482a8SLen Brown }
44795b482a8SLen Brown 
44895b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
449