xref: /openbmc/linux/drivers/acpi/acpica/exmisc.c (revision 9ff5a21a50301ef16aeb2e3937867de7eb0af030)
195b482a8SLen Brown /******************************************************************************
295b482a8SLen Brown  *
395b482a8SLen Brown  * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
495b482a8SLen Brown  *
595b482a8SLen Brown  *****************************************************************************/
695b482a8SLen Brown 
795b482a8SLen Brown /*
87735ca0eSBob Moore  * Copyright (C) 2000 - 2017, Intel Corp.
995b482a8SLen Brown  * All rights reserved.
1095b482a8SLen Brown  *
1195b482a8SLen Brown  * Redistribution and use in source and binary forms, with or without
1295b482a8SLen Brown  * modification, are permitted provided that the following conditions
1395b482a8SLen Brown  * are met:
1495b482a8SLen Brown  * 1. Redistributions of source code must retain the above copyright
1595b482a8SLen Brown  *    notice, this list of conditions, and the following disclaimer,
1695b482a8SLen Brown  *    without modification.
1795b482a8SLen Brown  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1895b482a8SLen Brown  *    substantially similar to the "NO WARRANTY" disclaimer below
1995b482a8SLen Brown  *    ("Disclaimer") and any redistribution must be conditioned upon
2095b482a8SLen Brown  *    including a substantially similar Disclaimer requirement for further
2195b482a8SLen Brown  *    binary redistribution.
2295b482a8SLen Brown  * 3. Neither the names of the above-listed copyright holders nor the names
2395b482a8SLen Brown  *    of any contributors may be used to endorse or promote products derived
2495b482a8SLen Brown  *    from this software without specific prior written permission.
2595b482a8SLen Brown  *
2695b482a8SLen Brown  * Alternatively, this software may be distributed under the terms of the
2795b482a8SLen Brown  * GNU General Public License ("GPL") version 2 as published by the Free
2895b482a8SLen Brown  * Software Foundation.
2995b482a8SLen Brown  *
3095b482a8SLen Brown  * NO WARRANTY
3195b482a8SLen Brown  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3295b482a8SLen Brown  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3395b482a8SLen Brown  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3495b482a8SLen Brown  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3595b482a8SLen Brown  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3695b482a8SLen Brown  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3795b482a8SLen Brown  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3895b482a8SLen Brown  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3995b482a8SLen Brown  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4095b482a8SLen Brown  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4195b482a8SLen Brown  * POSSIBILITY OF SUCH DAMAGES.
4295b482a8SLen Brown  */
4395b482a8SLen Brown 
4495b482a8SLen Brown #include <acpi/acpi.h>
45e2f7a777SLen Brown #include "accommon.h"
46e2f7a777SLen Brown #include "acinterp.h"
47e2f7a777SLen Brown #include "amlcode.h"
4895b482a8SLen Brown 
4995b482a8SLen Brown #define _COMPONENT          ACPI_EXECUTER
5095b482a8SLen Brown ACPI_MODULE_NAME("exmisc")
5195b482a8SLen Brown 
5295b482a8SLen Brown /*******************************************************************************
5395b482a8SLen Brown  *
5495b482a8SLen Brown  * FUNCTION:    acpi_ex_get_object_reference
5595b482a8SLen Brown  *
5695b482a8SLen Brown  * PARAMETERS:  obj_desc            - Create a reference to this object
5795b482a8SLen Brown  *              return_desc         - Where to store the reference
5895b482a8SLen Brown  *              walk_state          - Current state
5995b482a8SLen Brown  *
6095b482a8SLen Brown  * RETURN:      Status
6195b482a8SLen Brown  *
6295b482a8SLen Brown  * DESCRIPTION: Obtain and return a "reference" to the target object
6395b482a8SLen Brown  *              Common code for the ref_of_op and the cond_ref_of_op.
6495b482a8SLen Brown  *
6595b482a8SLen Brown  ******************************************************************************/
6695b482a8SLen Brown acpi_status
6795b482a8SLen Brown acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
6895b482a8SLen Brown 			     union acpi_operand_object **return_desc,
6995b482a8SLen Brown 			     struct acpi_walk_state *walk_state)
7095b482a8SLen Brown {
7195b482a8SLen Brown 	union acpi_operand_object *reference_obj;
7295b482a8SLen Brown 	union acpi_operand_object *referenced_obj;
7395b482a8SLen Brown 
7495b482a8SLen Brown 	ACPI_FUNCTION_TRACE_PTR(ex_get_object_reference, obj_desc);
7595b482a8SLen Brown 
7695b482a8SLen Brown 	*return_desc = NULL;
7795b482a8SLen Brown 
7895b482a8SLen Brown 	switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
7995b482a8SLen Brown 	case ACPI_DESC_TYPE_OPERAND:
8095b482a8SLen Brown 
813371c19cSBob Moore 		if (obj_desc->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
8295b482a8SLen Brown 			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
8395b482a8SLen Brown 		}
8495b482a8SLen Brown 
8595b482a8SLen Brown 		/*
8695b482a8SLen Brown 		 * Must be a reference to a Local or Arg
8795b482a8SLen Brown 		 */
8895b482a8SLen Brown 		switch (obj_desc->reference.class) {
8995b482a8SLen Brown 		case ACPI_REFCLASS_LOCAL:
9095b482a8SLen Brown 		case ACPI_REFCLASS_ARG:
9195b482a8SLen Brown 		case ACPI_REFCLASS_DEBUG:
9295b482a8SLen Brown 
9395b482a8SLen Brown 			/* The referenced object is the pseudo-node for the local/arg */
9495b482a8SLen Brown 
9595b482a8SLen Brown 			referenced_obj = obj_desc->reference.object;
9695b482a8SLen Brown 			break;
9795b482a8SLen Brown 
9895b482a8SLen Brown 		default:
9995b482a8SLen Brown 
100395ec731SBob Moore 			ACPI_ERROR((AE_INFO, "Invalid Reference Class 0x%2.2X",
10195b482a8SLen Brown 				    obj_desc->reference.class));
102395ec731SBob Moore 			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
10395b482a8SLen Brown 		}
10495b482a8SLen Brown 		break;
10595b482a8SLen Brown 
10695b482a8SLen Brown 	case ACPI_DESC_TYPE_NAMED:
10795b482a8SLen Brown 		/*
10895b482a8SLen Brown 		 * A named reference that has already been resolved to a Node
10995b482a8SLen Brown 		 */
11095b482a8SLen Brown 		referenced_obj = obj_desc;
11195b482a8SLen Brown 		break;
11295b482a8SLen Brown 
11395b482a8SLen Brown 	default:
11495b482a8SLen Brown 
115f6a22b0bSBob Moore 		ACPI_ERROR((AE_INFO, "Invalid descriptor type 0x%X",
11695b482a8SLen Brown 			    ACPI_GET_DESCRIPTOR_TYPE(obj_desc)));
11795b482a8SLen Brown 		return_ACPI_STATUS(AE_TYPE);
11895b482a8SLen Brown 	}
11995b482a8SLen Brown 
12095b482a8SLen Brown 	/* Create a new reference object */
12195b482a8SLen Brown 
12295b482a8SLen Brown 	reference_obj =
12395b482a8SLen Brown 	    acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
12495b482a8SLen Brown 	if (!reference_obj) {
12595b482a8SLen Brown 		return_ACPI_STATUS(AE_NO_MEMORY);
12695b482a8SLen Brown 	}
12795b482a8SLen Brown 
12895b482a8SLen Brown 	reference_obj->reference.class = ACPI_REFCLASS_REFOF;
12995b482a8SLen Brown 	reference_obj->reference.object = referenced_obj;
13095b482a8SLen Brown 	*return_desc = reference_obj;
13195b482a8SLen Brown 
13295b482a8SLen Brown 	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
13395b482a8SLen Brown 			  "Object %p Type [%s], returning Reference %p\n",
13495b482a8SLen Brown 			  obj_desc, acpi_ut_get_object_type_name(obj_desc),
13595b482a8SLen Brown 			  *return_desc));
13695b482a8SLen Brown 
13795b482a8SLen Brown 	return_ACPI_STATUS(AE_OK);
13895b482a8SLen Brown }
13995b482a8SLen Brown 
14095b482a8SLen Brown /*******************************************************************************
14195b482a8SLen Brown  *
14295b482a8SLen Brown  * FUNCTION:    acpi_ex_do_math_op
14395b482a8SLen Brown  *
144ba494beeSBob Moore  * PARAMETERS:  opcode              - AML opcode
145ba494beeSBob Moore  *              integer0            - Integer operand #0
146ba494beeSBob Moore  *              integer1            - Integer operand #1
14795b482a8SLen Brown  *
14895b482a8SLen Brown  * RETURN:      Integer result of the operation
14995b482a8SLen Brown  *
15095b482a8SLen Brown  * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
15195b482a8SLen Brown  *              math functions here is to prevent a lot of pointer dereferencing
15295b482a8SLen Brown  *              to obtain the operands.
15395b482a8SLen Brown  *
15495b482a8SLen Brown  ******************************************************************************/
15595b482a8SLen Brown 
1565df7e6cbSBob Moore u64 acpi_ex_do_math_op(u16 opcode, u64 integer0, u64 integer1)
15795b482a8SLen Brown {
15895b482a8SLen Brown 
15995b482a8SLen Brown 	ACPI_FUNCTION_ENTRY();
16095b482a8SLen Brown 
16195b482a8SLen Brown 	switch (opcode) {
16295b482a8SLen Brown 	case AML_ADD_OP:	/* Add (Integer0, Integer1, Result) */
16395b482a8SLen Brown 
16495b482a8SLen Brown 		return (integer0 + integer1);
16595b482a8SLen Brown 
16695b482a8SLen Brown 	case AML_BIT_AND_OP:	/* And (Integer0, Integer1, Result) */
16795b482a8SLen Brown 
16895b482a8SLen Brown 		return (integer0 & integer1);
16995b482a8SLen Brown 
17095b482a8SLen Brown 	case AML_BIT_NAND_OP:	/* NAnd (Integer0, Integer1, Result) */
17195b482a8SLen Brown 
17295b482a8SLen Brown 		return (~(integer0 & integer1));
17395b482a8SLen Brown 
17495b482a8SLen Brown 	case AML_BIT_OR_OP:	/* Or (Integer0, Integer1, Result) */
17595b482a8SLen Brown 
17695b482a8SLen Brown 		return (integer0 | integer1);
17795b482a8SLen Brown 
17895b482a8SLen Brown 	case AML_BIT_NOR_OP:	/* NOr (Integer0, Integer1, Result) */
17995b482a8SLen Brown 
18095b482a8SLen Brown 		return (~(integer0 | integer1));
18195b482a8SLen Brown 
18295b482a8SLen Brown 	case AML_BIT_XOR_OP:	/* XOr (Integer0, Integer1, Result) */
18395b482a8SLen Brown 
18495b482a8SLen Brown 		return (integer0 ^ integer1);
18595b482a8SLen Brown 
18695b482a8SLen Brown 	case AML_MULTIPLY_OP:	/* Multiply (Integer0, Integer1, Result) */
18795b482a8SLen Brown 
18895b482a8SLen Brown 		return (integer0 * integer1);
18995b482a8SLen Brown 
19095b482a8SLen Brown 	case AML_SHIFT_LEFT_OP:	/* shift_left (Operand, shift_count, Result) */
19195b482a8SLen Brown 
19295b482a8SLen Brown 		/*
19395b482a8SLen Brown 		 * We need to check if the shiftcount is larger than the integer bit
19495b482a8SLen Brown 		 * width since the behavior of this is not well-defined in the C language.
19595b482a8SLen Brown 		 */
19695b482a8SLen Brown 		if (integer1 >= acpi_gbl_integer_bit_width) {
19795b482a8SLen Brown 			return (0);
19895b482a8SLen Brown 		}
19995b482a8SLen Brown 		return (integer0 << integer1);
20095b482a8SLen Brown 
20195b482a8SLen Brown 	case AML_SHIFT_RIGHT_OP:	/* shift_right (Operand, shift_count, Result) */
20295b482a8SLen Brown 
20395b482a8SLen Brown 		/*
20495b482a8SLen Brown 		 * We need to check if the shiftcount is larger than the integer bit
20595b482a8SLen Brown 		 * width since the behavior of this is not well-defined in the C language.
20695b482a8SLen Brown 		 */
20795b482a8SLen Brown 		if (integer1 >= acpi_gbl_integer_bit_width) {
20895b482a8SLen Brown 			return (0);
20995b482a8SLen Brown 		}
21095b482a8SLen Brown 		return (integer0 >> integer1);
21195b482a8SLen Brown 
21295b482a8SLen Brown 	case AML_SUBTRACT_OP:	/* Subtract (Integer0, Integer1, Result) */
21395b482a8SLen Brown 
21495b482a8SLen Brown 		return (integer0 - integer1);
21595b482a8SLen Brown 
21695b482a8SLen Brown 	default:
21795b482a8SLen Brown 
21895b482a8SLen Brown 		return (0);
21995b482a8SLen Brown 	}
22095b482a8SLen Brown }
22195b482a8SLen Brown 
22295b482a8SLen Brown /*******************************************************************************
22395b482a8SLen Brown  *
22495b482a8SLen Brown  * FUNCTION:    acpi_ex_do_logical_numeric_op
22595b482a8SLen Brown  *
226ba494beeSBob Moore  * PARAMETERS:  opcode              - AML opcode
227ba494beeSBob Moore  *              integer0            - Integer operand #0
228ba494beeSBob Moore  *              integer1            - Integer operand #1
22995b482a8SLen Brown  *              logical_result      - TRUE/FALSE result of the operation
23095b482a8SLen Brown  *
23195b482a8SLen Brown  * RETURN:      Status
23295b482a8SLen Brown  *
23395b482a8SLen Brown  * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
23495b482a8SLen Brown  *              operators (LAnd and LOr), both operands must be integers.
23595b482a8SLen Brown  *
23695b482a8SLen Brown  *              Note: cleanest machine code seems to be produced by the code
23795b482a8SLen Brown  *              below, rather than using statements of the form:
23895b482a8SLen Brown  *                  Result = (Integer0 && Integer1);
23995b482a8SLen Brown  *
24095b482a8SLen Brown  ******************************************************************************/
24195b482a8SLen Brown 
24295b482a8SLen Brown acpi_status
24395b482a8SLen Brown acpi_ex_do_logical_numeric_op(u16 opcode,
2445df7e6cbSBob Moore 			      u64 integer0, u64 integer1, u8 *logical_result)
24595b482a8SLen Brown {
24695b482a8SLen Brown 	acpi_status status = AE_OK;
24795b482a8SLen Brown 	u8 local_result = FALSE;
24895b482a8SLen Brown 
24995b482a8SLen Brown 	ACPI_FUNCTION_TRACE(ex_do_logical_numeric_op);
25095b482a8SLen Brown 
25195b482a8SLen Brown 	switch (opcode) {
252*9ff5a21aSBob Moore 	case AML_LOGICAL_AND_OP:	/* LAnd (Integer0, Integer1) */
25395b482a8SLen Brown 
25495b482a8SLen Brown 		if (integer0 && integer1) {
25595b482a8SLen Brown 			local_result = TRUE;
25695b482a8SLen Brown 		}
25795b482a8SLen Brown 		break;
25895b482a8SLen Brown 
259*9ff5a21aSBob Moore 	case AML_LOGICAL_OR_OP:	/* LOr (Integer0, Integer1) */
26095b482a8SLen Brown 
26195b482a8SLen Brown 		if (integer0 || integer1) {
26295b482a8SLen Brown 			local_result = TRUE;
26395b482a8SLen Brown 		}
26495b482a8SLen Brown 		break;
26595b482a8SLen Brown 
26695b482a8SLen Brown 	default:
2671d1ea1b7SChao Guan 
26895b482a8SLen Brown 		status = AE_AML_INTERNAL;
26995b482a8SLen Brown 		break;
27095b482a8SLen Brown 	}
27195b482a8SLen Brown 
27295b482a8SLen Brown 	/* Return the logical result and status */
27395b482a8SLen Brown 
27495b482a8SLen Brown 	*logical_result = local_result;
27595b482a8SLen Brown 	return_ACPI_STATUS(status);
27695b482a8SLen Brown }
27795b482a8SLen Brown 
27895b482a8SLen Brown /*******************************************************************************
27995b482a8SLen Brown  *
28095b482a8SLen Brown  * FUNCTION:    acpi_ex_do_logical_op
28195b482a8SLen Brown  *
282ba494beeSBob Moore  * PARAMETERS:  opcode              - AML opcode
283ba494beeSBob Moore  *              operand0            - operand #0
284ba494beeSBob Moore  *              operand1            - operand #1
28595b482a8SLen Brown  *              logical_result      - TRUE/FALSE result of the operation
28695b482a8SLen Brown  *
28795b482a8SLen Brown  * RETURN:      Status
28895b482a8SLen Brown  *
28995b482a8SLen Brown  * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
29095b482a8SLen Brown  *              functions here is to prevent a lot of pointer dereferencing
29195b482a8SLen Brown  *              to obtain the operands and to simplify the generation of the
29295b482a8SLen Brown  *              logical value. For the Numeric operators (LAnd and LOr), both
29395b482a8SLen Brown  *              operands must be integers. For the other logical operators,
29495b482a8SLen Brown  *              operands can be any combination of Integer/String/Buffer. The
29595b482a8SLen Brown  *              first operand determines the type to which the second operand
29695b482a8SLen Brown  *              will be converted.
29795b482a8SLen Brown  *
29895b482a8SLen Brown  *              Note: cleanest machine code seems to be produced by the code
29995b482a8SLen Brown  *              below, rather than using statements of the form:
30095b482a8SLen Brown  *                  Result = (Operand0 == Operand1);
30195b482a8SLen Brown  *
30295b482a8SLen Brown  ******************************************************************************/
30395b482a8SLen Brown 
30495b482a8SLen Brown acpi_status
30595b482a8SLen Brown acpi_ex_do_logical_op(u16 opcode,
30695b482a8SLen Brown 		      union acpi_operand_object *operand0,
30795b482a8SLen Brown 		      union acpi_operand_object *operand1, u8 * logical_result)
30895b482a8SLen Brown {
30995b482a8SLen Brown 	union acpi_operand_object *local_operand1 = operand1;
3105df7e6cbSBob Moore 	u64 integer0;
3115df7e6cbSBob Moore 	u64 integer1;
31295b482a8SLen Brown 	u32 length0;
31395b482a8SLen Brown 	u32 length1;
31495b482a8SLen Brown 	acpi_status status = AE_OK;
31595b482a8SLen Brown 	u8 local_result = FALSE;
31695b482a8SLen Brown 	int compare;
31795b482a8SLen Brown 
31895b482a8SLen Brown 	ACPI_FUNCTION_TRACE(ex_do_logical_op);
31995b482a8SLen Brown 
32095b482a8SLen Brown 	/*
32195b482a8SLen Brown 	 * Convert the second operand if necessary. The first operand
32295b482a8SLen Brown 	 * determines the type of the second operand, (See the Data Types
32395b482a8SLen Brown 	 * section of the ACPI 3.0+ specification.)  Both object types are
32495b482a8SLen Brown 	 * guaranteed to be either Integer/String/Buffer by the operand
32595b482a8SLen Brown 	 * resolution mechanism.
32695b482a8SLen Brown 	 */
3273371c19cSBob Moore 	switch (operand0->common.type) {
32895b482a8SLen Brown 	case ACPI_TYPE_INTEGER:
3291d1ea1b7SChao Guan 
3305ebd2eaaSBob Moore 		status = acpi_ex_convert_to_integer(operand1, &local_operand1,
3315ebd2eaaSBob Moore 						    ACPI_STRTOUL_BASE16);
33295b482a8SLen Brown 		break;
33395b482a8SLen Brown 
33495b482a8SLen Brown 	case ACPI_TYPE_STRING:
3351d1ea1b7SChao Guan 
3361fad8738SBob Moore 		status =
3371fad8738SBob Moore 		    acpi_ex_convert_to_string(operand1, &local_operand1,
33895b482a8SLen Brown 					      ACPI_IMPLICIT_CONVERT_HEX);
33995b482a8SLen Brown 		break;
34095b482a8SLen Brown 
34195b482a8SLen Brown 	case ACPI_TYPE_BUFFER:
3421d1ea1b7SChao Guan 
34395b482a8SLen Brown 		status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
34495b482a8SLen Brown 		break;
34595b482a8SLen Brown 
34695b482a8SLen Brown 	default:
3471d1ea1b7SChao Guan 
34895b482a8SLen Brown 		status = AE_AML_INTERNAL;
34995b482a8SLen Brown 		break;
35095b482a8SLen Brown 	}
35195b482a8SLen Brown 
35295b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
35395b482a8SLen Brown 		goto cleanup;
35495b482a8SLen Brown 	}
35595b482a8SLen Brown 
35695b482a8SLen Brown 	/*
35795b482a8SLen Brown 	 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
35895b482a8SLen Brown 	 */
3593371c19cSBob Moore 	if (operand0->common.type == ACPI_TYPE_INTEGER) {
36095b482a8SLen Brown 		/*
36195b482a8SLen Brown 		 * 1) Both operands are of type integer
36295b482a8SLen Brown 		 *    Note: local_operand1 may have changed above
36395b482a8SLen Brown 		 */
36495b482a8SLen Brown 		integer0 = operand0->integer.value;
36595b482a8SLen Brown 		integer1 = local_operand1->integer.value;
36695b482a8SLen Brown 
36795b482a8SLen Brown 		switch (opcode) {
368*9ff5a21aSBob Moore 		case AML_LOGICAL_EQUAL_OP:	/* LEqual (Operand0, Operand1) */
36995b482a8SLen Brown 
37095b482a8SLen Brown 			if (integer0 == integer1) {
37195b482a8SLen Brown 				local_result = TRUE;
37295b482a8SLen Brown 			}
37395b482a8SLen Brown 			break;
37495b482a8SLen Brown 
375*9ff5a21aSBob Moore 		case AML_LOGICAL_GREATER_OP:	/* LGreater (Operand0, Operand1) */
37695b482a8SLen Brown 
37795b482a8SLen Brown 			if (integer0 > integer1) {
37895b482a8SLen Brown 				local_result = TRUE;
37995b482a8SLen Brown 			}
38095b482a8SLen Brown 			break;
38195b482a8SLen Brown 
382*9ff5a21aSBob Moore 		case AML_LOGICAL_LESS_OP:	/* LLess (Operand0, Operand1) */
38395b482a8SLen Brown 
38495b482a8SLen Brown 			if (integer0 < integer1) {
38595b482a8SLen Brown 				local_result = TRUE;
38695b482a8SLen Brown 			}
38795b482a8SLen Brown 			break;
38895b482a8SLen Brown 
38995b482a8SLen Brown 		default:
3901d1ea1b7SChao Guan 
39195b482a8SLen Brown 			status = AE_AML_INTERNAL;
39295b482a8SLen Brown 			break;
39395b482a8SLen Brown 		}
39495b482a8SLen Brown 	} else {
39595b482a8SLen Brown 		/*
39695b482a8SLen Brown 		 * 2) Both operands are Strings or both are Buffers
39795b482a8SLen Brown 		 *    Note: Code below takes advantage of common Buffer/String
39895b482a8SLen Brown 		 *          object fields. local_operand1 may have changed above. Use
39995b482a8SLen Brown 		 *          memcmp to handle nulls in buffers.
40095b482a8SLen Brown 		 */
40195b482a8SLen Brown 		length0 = operand0->buffer.length;
40295b482a8SLen Brown 		length1 = local_operand1->buffer.length;
40395b482a8SLen Brown 
40495b482a8SLen Brown 		/* Lexicographic compare: compare the data bytes */
40595b482a8SLen Brown 
4064fa4616eSBob Moore 		compare = memcmp(operand0->buffer.pointer,
40795b482a8SLen Brown 				 local_operand1->buffer.pointer,
40895b482a8SLen Brown 				 (length0 > length1) ? length1 : length0);
40995b482a8SLen Brown 
41095b482a8SLen Brown 		switch (opcode) {
411*9ff5a21aSBob Moore 		case AML_LOGICAL_EQUAL_OP:	/* LEqual (Operand0, Operand1) */
41295b482a8SLen Brown 
41395b482a8SLen Brown 			/* Length and all bytes must be equal */
41495b482a8SLen Brown 
41595b482a8SLen Brown 			if ((length0 == length1) && (compare == 0)) {
41695b482a8SLen Brown 
41795b482a8SLen Brown 				/* Length and all bytes match ==> TRUE */
41895b482a8SLen Brown 
41995b482a8SLen Brown 				local_result = TRUE;
42095b482a8SLen Brown 			}
42195b482a8SLen Brown 			break;
42295b482a8SLen Brown 
423*9ff5a21aSBob Moore 		case AML_LOGICAL_GREATER_OP:	/* LGreater (Operand0, Operand1) */
42495b482a8SLen Brown 
42595b482a8SLen Brown 			if (compare > 0) {
42695b482a8SLen Brown 				local_result = TRUE;
42795b482a8SLen Brown 				goto cleanup;	/* TRUE */
42895b482a8SLen Brown 			}
42995b482a8SLen Brown 			if (compare < 0) {
43095b482a8SLen Brown 				goto cleanup;	/* FALSE */
43195b482a8SLen Brown 			}
43295b482a8SLen Brown 
43395b482a8SLen Brown 			/* Bytes match (to shortest length), compare lengths */
43495b482a8SLen Brown 
43595b482a8SLen Brown 			if (length0 > length1) {
43695b482a8SLen Brown 				local_result = TRUE;
43795b482a8SLen Brown 			}
43895b482a8SLen Brown 			break;
43995b482a8SLen Brown 
440*9ff5a21aSBob Moore 		case AML_LOGICAL_LESS_OP:	/* LLess (Operand0, Operand1) */
44195b482a8SLen Brown 
44295b482a8SLen Brown 			if (compare > 0) {
44395b482a8SLen Brown 				goto cleanup;	/* FALSE */
44495b482a8SLen Brown 			}
44595b482a8SLen Brown 			if (compare < 0) {
44695b482a8SLen Brown 				local_result = TRUE;
44795b482a8SLen Brown 				goto cleanup;	/* TRUE */
44895b482a8SLen Brown 			}
44995b482a8SLen Brown 
45095b482a8SLen Brown 			/* Bytes match (to shortest length), compare lengths */
45195b482a8SLen Brown 
45295b482a8SLen Brown 			if (length0 < length1) {
45395b482a8SLen Brown 				local_result = TRUE;
45495b482a8SLen Brown 			}
45595b482a8SLen Brown 			break;
45695b482a8SLen Brown 
45795b482a8SLen Brown 		default:
4581d1ea1b7SChao Guan 
45995b482a8SLen Brown 			status = AE_AML_INTERNAL;
46095b482a8SLen Brown 			break;
46195b482a8SLen Brown 		}
46295b482a8SLen Brown 	}
46395b482a8SLen Brown 
46495b482a8SLen Brown cleanup:
46595b482a8SLen Brown 
46695b482a8SLen Brown 	/* New object was created if implicit conversion performed - delete */
46795b482a8SLen Brown 
46895b482a8SLen Brown 	if (local_operand1 != operand1) {
46995b482a8SLen Brown 		acpi_ut_remove_reference(local_operand1);
47095b482a8SLen Brown 	}
47195b482a8SLen Brown 
47295b482a8SLen Brown 	/* Return the logical result and status */
47395b482a8SLen Brown 
47495b482a8SLen Brown 	*logical_result = local_result;
47595b482a8SLen Brown 	return_ACPI_STATUS(status);
47695b482a8SLen Brown }
477