11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/******************************************************************************
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *****************************************************************************/
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
8fbb7a2dc2be493c87399550bdc2ddaa510cdf450Bob Moore * Copyright (C) 2000 - 2014, Intel Corp.
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * All rights reserved.
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Redistribution and use in source and binary forms, with or without
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * modification, are permitted provided that the following conditions
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are met:
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1. Redistributions of source code must retain the above copyright
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    notice, this list of conditions, and the following disclaimer,
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    without modification.
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2. Redistributions in binary form must reproduce at minimum a disclaimer
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    substantially similar to the "NO WARRANTY" disclaimer below
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    ("Disclaimer") and any redistribution must be conditioned upon
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    including a substantially similar Disclaimer requirement for further
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    binary redistribution.
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3. Neither the names of the above-listed copyright holders nor the names
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    of any contributors may be used to endorse or promote products derived
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    from this software without specific prior written permission.
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Alternatively, this software may be distributed under the terms of the
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License ("GPL") version 2 as published by the Free
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Software Foundation.
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NO WARRANTY
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * POSSIBILITY OF SUCH DAMAGES.
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <acpi/acpi.h>
45e2f7a7772880458edff1b1cc5a988947229fac26Len Brown#include "accommon.h"
46e2f7a7772880458edff1b1cc5a988947229fac26Len Brown#include "acinterp.h"
47e2f7a7772880458edff1b1cc5a988947229fac26Len Brown#include "acparser.h"
48e2f7a7772880458edff1b1cc5a988947229fac26Len Brown#include "amlcode.h"
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _COMPONENT          ACPI_EXECUTER
514be44fcd3bf648b782f4460fd06dfae6c42ded4bLen BrownACPI_MODULE_NAME("exoparg6")
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*!
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Naming convention for AML interpreter execution routines.
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The routines that begin execution of AML opcodes are named with a common
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * convention based upon the number of arguments, the number of target operands,
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and whether or not a value is returned:
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *      AcpiExOpcode_xA_yT_zR
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Where:
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * xA - ARGUMENTS:    The number of arguments (input operands) that are
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *                    required for this opcode type (1 through 6 args).
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * yT - TARGETS:      The number of targets (output operands) that are required
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *                    for this opcode type (0, 1, or 2 targets).
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * zR - RETURN VALUE: Indicates whether this opcode type returns a value
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *                    as the function return (0 or 1).
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The AcpiExOpcode* functions are called via the Dispatcher component with
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fully resolved operands.
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds!*/
7444f6c01242da4e162f28d8e1216a8c7a91174605Robert Moore/* Local prototypes */
7544f6c01242da4e162f28d8e1216a8c7a91174605Robert Moorestatic u8
764be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brownacpi_ex_do_match(u32 match_op,
774be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		 union acpi_operand_object *package_obj,
784be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		 union acpi_operand_object *match_obj);
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*******************************************************************************
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FUNCTION:    acpi_ex_do_match
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PARAMETERS:  match_op        - The AML match operand
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *              package_obj     - Object from the target package
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *              match_obj       - Object to be matched
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * RETURN:      TRUE if the match is successful, FALSE otherwise
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DESCRIPTION: Implements the low-level match for the ASL Match operator.
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *              Package elements will be implicitly converted to the type of
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *              the match object (Integer/Buffer/String).
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ******************************************************************************/
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9644f6c01242da4e162f28d8e1216a8c7a91174605Robert Moorestatic u8
974be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brownacpi_ex_do_match(u32 match_op,
984be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		 union acpi_operand_object *package_obj,
994be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		 union acpi_operand_object *match_obj)
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1014be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown	u8 logical_result = TRUE;
1024be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown	acpi_status status;
1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Note: Since the package_obj/match_obj ordering is opposite to that of
1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * the standard logical operators, we have to reverse them when we call
1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * do_logical_op in order to make the implicit conversion rules work
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * correctly. However, this means we have to flip the entire equation
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * also. A bit ugly perhaps, but overall, better than fussing the
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * parameters around at runtime, over and over again.
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 *
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Below, P[i] refers to the package element, M refers to the Match object.
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	switch (match_op) {
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	case MATCH_MTR:
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* Always true */
1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		break;
1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	case MATCH_MEQ:
1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * True if equal: (P[i] == M)
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * Change to:     (M == P[i])
1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
1264be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		status =
1274be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		    acpi_ex_do_logical_op(AML_LEQUAL_OP, match_obj, package_obj,
1284be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown					  &logical_result);
1294be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		if (ACPI_FAILURE(status)) {
1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return (FALSE);
1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		break;
1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	case MATCH_MLE:
1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * True if less than or equal: (P[i] <= M) (P[i] not_greater than M)
1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * Change to:                  (M >= P[i]) (M not_less than P[i])
1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
1394be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		status =
1404be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		    acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
1414be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown					  &logical_result);
1424be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		if (ACPI_FAILURE(status)) {
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return (FALSE);
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1454be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		logical_result = (u8) ! logical_result;
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		break;
1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	case MATCH_MLT:
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * True if less than: (P[i] < M)
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * Change to:         (M > P[i])
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
1534be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		status =
1544be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		    acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
1554be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown					  package_obj, &logical_result);
1564be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		if (ACPI_FAILURE(status)) {
1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return (FALSE);
1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		break;
1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	case MATCH_MGE:
1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * True if greater than or equal: (P[i] >= M) (P[i] not_less than M)
1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * Change to:                     (M <= P[i]) (M not_greater than P[i])
1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
1664be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		status =
1674be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		    acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
1684be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown					  package_obj, &logical_result);
1694be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		if (ACPI_FAILURE(status)) {
1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return (FALSE);
1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1724be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		logical_result = (u8) ! logical_result;
1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		break;
1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	case MATCH_MGT:
1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * True if greater than: (P[i] > M)
1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * Change to:            (M < P[i])
1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
1804be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		status =
1814be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		    acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
1824be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown					  &logical_result);
1834be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		if (ACPI_FAILURE(status)) {
1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return (FALSE);
1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		break;
1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	default:
1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* Undefined */
1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return (FALSE);
1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
19568aafc35161dcc9d365a32c2f9f077aedc61754dBob Moore	return (logical_result);
1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*******************************************************************************
1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FUNCTION:    acpi_ex_opcode_6A_0T_1R
2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PARAMETERS:  walk_state          - Current walk state
2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * RETURN:      Status
2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ******************************************************************************/
2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2104be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brownacpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
2111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
2124be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown	union acpi_operand_object **operand = &walk_state->operands[0];
2134be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown	union acpi_operand_object *return_desc = NULL;
2144be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown	acpi_status status = AE_OK;
2155df7e6cb42da36c7d878239bebc81907b15f3943Bob Moore	u64 index;
2164be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown	union acpi_operand_object *this_element;
2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
218b229cf92eee616c7cb5ad8cdb35a19b119f00bc8Bob Moore	ACPI_FUNCTION_TRACE_STR(ex_opcode_6A_0T_1R,
2194be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown				acpi_ps_get_opcode_name(walk_state->opcode));
2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	switch (walk_state->opcode) {
2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	case AML_MATCH_OP:
2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * Match (search_pkg[0], match_op1[1], match_obj1[2],
2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 *                      match_op2[3], match_obj2[4], start_index[5])
2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* Validate both Match Term Operators (MTR, MEQ, etc.) */
2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) ||
2314be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		    (operand[3]->integer.value > MAX_MATCH_OPERATOR)) {
232b8e4d89357fc434618a59c1047cac72641191805Bob Moore			ACPI_ERROR((AE_INFO, "Match operator out of range"));
2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			status = AE_AML_OPERAND_VALUE;
2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto cleanup;
2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* Get the package start_index, validate against the package length */
2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
23944f6c01242da4e162f28d8e1216a8c7a91174605Robert Moore		index = operand[5]->integer.value;
24044f6c01242da4e162f28d8e1216a8c7a91174605Robert Moore		if (index >= operand[0]->package.count) {
241b8e4d89357fc434618a59c1047cac72641191805Bob Moore			ACPI_ERROR((AE_INFO,
242f6a22b0bc417042e83117f52ab1a03696af185abBob Moore				    "Index (0x%8.8X%8.8X) beyond package end (0x%X)",
243b8e4d89357fc434618a59c1047cac72641191805Bob Moore				    ACPI_FORMAT_UINT64(index),
244b8e4d89357fc434618a59c1047cac72641191805Bob Moore				    operand[0]->package.count));
2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			status = AE_AML_PACKAGE_LIMIT;
2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto cleanup;
2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* Create an integer for the return value */
2505df7e6cb42da36c7d878239bebc81907b15f3943Bob Moore		/* Default return value is ACPI_UINT64_MAX if no match found */
2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2525df7e6cb42da36c7d878239bebc81907b15f3943Bob Moore		return_desc = acpi_ut_create_integer_object(ACPI_UINT64_MAX);
2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (!return_desc) {
2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			status = AE_NO_MEMORY;
2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto cleanup;
2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * Examine each element until a match is found. Both match conditions
2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * must be satisfied for a match to occur. Within the loop,
2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * "continue" signifies that the current element does not match
2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * and the next should be examined.
2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 *
2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * Upon finding a match, the loop will terminate via "break" at
26673a3090a2160fb01317f5a44af6ee5a064a29625Bob Moore		 * the bottom. If it terminates "normally", match_value will be
2675df7e6cb42da36c7d878239bebc81907b15f3943Bob Moore		 * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no
2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * match was found.
2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
2704be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		for (; index < operand[0]->package.count; index++) {
27152fc0b026e99b5d5d585095148d997d5634bbc25Bob Moore
2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			/* Get the current package element */
2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			this_element = operand[0]->package.elements[index];
2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			/* Treat any uninitialized (NULL) elements as non-matching */
2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			if (!this_element) {
2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				continue;
2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			}
2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			/*
2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 * Both match conditions must be satisfied. Execution of a continue
2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 * (proceed to next iteration of enclosing for loop) signifies a
2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 * non-match.
2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 */
2874be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown			if (!acpi_ex_do_match((u32) operand[1]->integer.value,
2884be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown					      this_element, operand[2])) {
2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				continue;
2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			}
2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2924be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown			if (!acpi_ex_do_match((u32) operand[3]->integer.value,
2934be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown					      this_element, operand[4])) {
2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				continue;
2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			}
2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			/* Match found: Index is the return value */
2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return_desc->integer.value = index;
3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			break;
3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		break;
3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	case AML_LOAD_TABLE_OP:
3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3064be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		status = acpi_ex_load_table_op(walk_state, &return_desc);
3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		break;
3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	default:
3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
311f6a22b0bc417042e83117f52ab1a03696af185abBob Moore		ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
312b8e4d89357fc434618a59c1047cac72641191805Bob Moore			    walk_state->opcode));
3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		status = AE_AML_BAD_OPCODE;
3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto cleanup;
3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
31710622bf8ce432e6a53fd3c37163e99e99c9e43eeLv Zhengcleanup:
3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Delete return object on error */
3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3214be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown	if (ACPI_FAILURE(status)) {
3224be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown		acpi_ut_remove_reference(return_desc);
3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3254b6e16cf2bacbf328535097fa74f1494b1873c54Bob Moore	/* Save return object on success */
3264b6e16cf2bacbf328535097fa74f1494b1873c54Bob Moore
3274b6e16cf2bacbf328535097fa74f1494b1873c54Bob Moore	else {
3284b6e16cf2bacbf328535097fa74f1494b1873c54Bob Moore		walk_state->result_obj = return_desc;
3294b6e16cf2bacbf328535097fa74f1494b1873c54Bob Moore	}
3304b6e16cf2bacbf328535097fa74f1494b1873c54Bob Moore
3314be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown	return_ACPI_STATUS(status);
3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
333