| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 |  | 
 | 2 | /****************************************************************************** | 
 | 3 |  * | 
 | 4 |  * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes | 
 | 5 |  * | 
 | 6 |  *****************************************************************************/ | 
 | 7 |  | 
 | 8 | /* | 
| Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 9 |  * Copyright (C) 2000 - 2008, Intel Corp. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 |  * All rights reserved. | 
 | 11 |  * | 
 | 12 |  * Redistribution and use in source and binary forms, with or without | 
 | 13 |  * modification, are permitted provided that the following conditions | 
 | 14 |  * are met: | 
 | 15 |  * 1. Redistributions of source code must retain the above copyright | 
 | 16 |  *    notice, this list of conditions, and the following disclaimer, | 
 | 17 |  *    without modification. | 
 | 18 |  * 2. Redistributions in binary form must reproduce at minimum a disclaimer | 
 | 19 |  *    substantially similar to the "NO WARRANTY" disclaimer below | 
 | 20 |  *    ("Disclaimer") and any redistribution must be conditioned upon | 
 | 21 |  *    including a substantially similar Disclaimer requirement for further | 
 | 22 |  *    binary redistribution. | 
 | 23 |  * 3. Neither the names of the above-listed copyright holders nor the names | 
 | 24 |  *    of any contributors may be used to endorse or promote products derived | 
 | 25 |  *    from this software without specific prior written permission. | 
 | 26 |  * | 
 | 27 |  * Alternatively, this software may be distributed under the terms of the | 
 | 28 |  * GNU General Public License ("GPL") version 2 as published by the Free | 
 | 29 |  * Software Foundation. | 
 | 30 |  * | 
 | 31 |  * NO WARRANTY | 
 | 32 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
 | 33 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
 | 34 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | 
 | 35 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
 | 36 |  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
 | 37 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
 | 38 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
 | 39 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 
 | 40 |  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 
 | 41 |  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
 | 42 |  * POSSIBILITY OF SUCH DAMAGES. | 
 | 43 |  */ | 
 | 44 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> | 
| Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.h" | 
 | 47 | #include "acinterp.h" | 
 | 48 | #include "amlcode.h" | 
 | 49 | #include "amlresrc.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define _COMPONENT          ACPI_EXECUTER | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("exmisc") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
 | 54 | /******************************************************************************* | 
 | 55 |  * | 
 | 56 |  * FUNCTION:    acpi_ex_get_object_reference | 
 | 57 |  * | 
 | 58 |  * PARAMETERS:  obj_desc            - Create a reference to this object | 
 | 59 |  *              return_desc         - Where to store the reference | 
 | 60 |  *              walk_state          - Current state | 
 | 61 |  * | 
 | 62 |  * RETURN:      Status | 
 | 63 |  * | 
 | 64 |  * DESCRIPTION: Obtain and return a "reference" to the target object | 
 | 65 |  *              Common code for the ref_of_op and the cond_ref_of_op. | 
 | 66 |  * | 
 | 67 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | acpi_ex_get_object_reference(union acpi_operand_object *obj_desc, | 
 | 70 | 			     union acpi_operand_object **return_desc, | 
 | 71 | 			     struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | 	union acpi_operand_object *reference_obj; | 
 | 74 | 	union acpi_operand_object *referenced_obj; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 76 | 	ACPI_FUNCTION_TRACE_PTR(ex_get_object_reference, obj_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 |  | 
 | 78 | 	*return_desc = NULL; | 
 | 79 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | 	switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | 	case ACPI_DESC_TYPE_OPERAND: | 
 | 82 |  | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 83 | 		if (obj_desc->common.type != ACPI_TYPE_LOCAL_REFERENCE) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | 			return_ACPI_STATUS(AE_AML_OPERAND_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | 		} | 
 | 86 |  | 
 | 87 | 		/* | 
 | 88 | 		 * Must be a reference to a Local or Arg | 
 | 89 | 		 */ | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 90 | 		switch (obj_desc->reference.class) { | 
 | 91 | 		case ACPI_REFCLASS_LOCAL: | 
 | 92 | 		case ACPI_REFCLASS_ARG: | 
 | 93 | 		case ACPI_REFCLASS_DEBUG: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 |  | 
 | 95 | 			/* The referenced object is the pseudo-node for the local/arg */ | 
 | 96 |  | 
 | 97 | 			referenced_obj = obj_desc->reference.object; | 
 | 98 | 			break; | 
 | 99 |  | 
 | 100 | 		default: | 
 | 101 |  | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 102 | 			ACPI_ERROR((AE_INFO, "Unknown Reference Class %2.2X", | 
 | 103 | 				    obj_desc->reference.class)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | 			return_ACPI_STATUS(AE_AML_INTERNAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | 		} | 
 | 106 | 		break; | 
 | 107 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | 	case ACPI_DESC_TYPE_NAMED: | 
 | 109 |  | 
 | 110 | 		/* | 
 | 111 | 		 * A named reference that has already been resolved to a Node | 
 | 112 | 		 */ | 
 | 113 | 		referenced_obj = obj_desc; | 
 | 114 | 		break; | 
 | 115 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | 	default: | 
 | 117 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 118 | 		ACPI_ERROR((AE_INFO, "Invalid descriptor type %X", | 
 | 119 | 			    ACPI_GET_DESCRIPTOR_TYPE(obj_desc))); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | 		return_ACPI_STATUS(AE_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | 	} | 
 | 122 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | 	/* Create a new reference object */ | 
 | 124 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | 	reference_obj = | 
 | 126 | 	    acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | 	if (!reference_obj) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | 		return_ACPI_STATUS(AE_NO_MEMORY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | 	} | 
 | 130 |  | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 131 | 	reference_obj->reference.class = ACPI_REFCLASS_REFOF; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | 	reference_obj->reference.object = referenced_obj; | 
 | 133 | 	*return_desc = reference_obj; | 
 | 134 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | 	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
 | 136 | 			  "Object %p Type [%s], returning Reference %p\n", | 
 | 137 | 			  obj_desc, acpi_ut_get_object_type_name(obj_desc), | 
 | 138 | 			  *return_desc)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | 	return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } | 
 | 142 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /******************************************************************************* | 
 | 144 |  * | 
 | 145 |  * FUNCTION:    acpi_ex_concat_template | 
 | 146 |  * | 
 | 147 |  * PARAMETERS:  Operand0            - First source object | 
 | 148 |  *              Operand1            - Second source object | 
 | 149 |  *              actual_return_desc  - Where to place the return object | 
 | 150 |  *              walk_state          - Current walk state | 
 | 151 |  * | 
 | 152 |  * RETURN:      Status | 
 | 153 |  * | 
 | 154 |  * DESCRIPTION: Concatenate two resource templates | 
 | 155 |  * | 
 | 156 |  ******************************************************************************/ | 
 | 157 |  | 
 | 158 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | acpi_ex_concat_template(union acpi_operand_object *operand0, | 
 | 160 | 			union acpi_operand_object *operand1, | 
 | 161 | 			union acpi_operand_object **actual_return_desc, | 
 | 162 | 			struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 164 | 	acpi_status status; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | 	union acpi_operand_object *return_desc; | 
 | 166 | 	u8 *new_buf; | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 167 | 	u8 *end_tag; | 
 | 168 | 	acpi_size length0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | 	acpi_size length1; | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 170 | 	acpi_size new_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 172 | 	ACPI_FUNCTION_TRACE(ex_concat_template); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 |  | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 174 | 	/* | 
 | 175 | 	 * Find the end_tag descriptor in each resource template. | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 176 | 	 * Note1: returned pointers point TO the end_tag, not past it. | 
 | 177 | 	 * Note2: zero-length buffers are allowed; treated like one end_tag | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 178 | 	 */ | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 179 |  | 
 | 180 | 	/* Get the length of the first resource template */ | 
 | 181 |  | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 182 | 	status = acpi_ut_get_resource_end_tag(operand0, &end_tag); | 
 | 183 | 	if (ACPI_FAILURE(status)) { | 
 | 184 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | 	} | 
 | 186 |  | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 187 | 	length0 = ACPI_PTR_DIFF(end_tag, operand0->buffer.pointer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 189 | 	/* Get the length of the second resource template */ | 
 | 190 |  | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 191 | 	status = acpi_ut_get_resource_end_tag(operand1, &end_tag); | 
 | 192 | 	if (ACPI_FAILURE(status)) { | 
 | 193 | 		return_ACPI_STATUS(status); | 
 | 194 | 	} | 
 | 195 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 196 | 	length1 = ACPI_PTR_DIFF(end_tag, operand1->buffer.pointer); | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 197 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 198 | 	/* Combine both lengths, minimum size will be 2 for end_tag */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 200 | 	new_length = length0 + length1 + sizeof(struct aml_resource_end_tag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 202 | 	/* Create a new buffer object for the result (with one end_tag) */ | 
 | 203 |  | 
 | 204 | 	return_desc = acpi_ut_create_buffer_object(new_length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | 	if (!return_desc) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | 		return_ACPI_STATUS(AE_NO_MEMORY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | 	} | 
 | 208 |  | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 209 | 	/* | 
 | 210 | 	 * Copy the templates to the new buffer, 0 first, then 1 follows. One | 
 | 211 | 	 * end_tag descriptor is copied from Operand1. | 
 | 212 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | 	new_buf = return_desc->buffer.pointer; | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 214 | 	ACPI_MEMCPY(new_buf, operand0->buffer.pointer, length0); | 
 | 215 | 	ACPI_MEMCPY(new_buf + length0, operand1->buffer.pointer, length1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 217 | 	/* Insert end_tag and set the checksum to zero, means "ignore checksum" */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 219 | 	new_buf[new_length - 1] = 0; | 
 | 220 | 	new_buf[new_length - 2] = ACPI_RESOURCE_NAME_END_TAG | 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 |  | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 222 | 	/* Return the completed resource template */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 |  | 
 | 224 | 	*actual_return_desc = return_desc; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | 	return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } | 
 | 227 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /******************************************************************************* | 
 | 229 |  * | 
 | 230 |  * FUNCTION:    acpi_ex_do_concatenate | 
 | 231 |  * | 
 | 232 |  * PARAMETERS:  Operand0            - First source object | 
 | 233 |  *              Operand1            - Second source object | 
 | 234 |  *              actual_return_desc  - Where to place the return object | 
 | 235 |  *              walk_state          - Current walk state | 
 | 236 |  * | 
 | 237 |  * RETURN:      Status | 
 | 238 |  * | 
 | 239 |  * DESCRIPTION: Concatenate two objects OF THE SAME TYPE. | 
 | 240 |  * | 
 | 241 |  ******************************************************************************/ | 
 | 242 |  | 
 | 243 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | acpi_ex_do_concatenate(union acpi_operand_object *operand0, | 
 | 245 | 		       union acpi_operand_object *operand1, | 
 | 246 | 		       union acpi_operand_object **actual_return_desc, | 
 | 247 | 		       struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | 	union acpi_operand_object *local_operand1 = operand1; | 
 | 250 | 	union acpi_operand_object *return_desc; | 
 | 251 | 	char *new_buf; | 
 | 252 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 254 | 	ACPI_FUNCTION_TRACE(ex_do_concatenate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 |  | 
 | 256 | 	/* | 
 | 257 | 	 * Convert the second operand if necessary.  The first operand | 
 | 258 | 	 * determines the type of the second operand, (See the Data Types | 
 | 259 | 	 * section of the ACPI specification.)  Both object types are | 
 | 260 | 	 * guaranteed to be either Integer/String/Buffer by the operand | 
 | 261 | 	 * resolution mechanism. | 
 | 262 | 	 */ | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 263 | 	switch (operand0->common.type) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | 	case ACPI_TYPE_INTEGER: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | 		status = | 
 | 266 | 		    acpi_ex_convert_to_integer(operand1, &local_operand1, 16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | 		break; | 
 | 268 |  | 
 | 269 | 	case ACPI_TYPE_STRING: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | 		status = acpi_ex_convert_to_string(operand1, &local_operand1, | 
 | 271 | 						   ACPI_IMPLICIT_CONVERT_HEX); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | 		break; | 
 | 273 |  | 
 | 274 | 	case ACPI_TYPE_BUFFER: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | 		status = acpi_ex_convert_to_buffer(operand1, &local_operand1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | 		break; | 
 | 277 |  | 
 | 278 | 	default: | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 279 | 		ACPI_ERROR((AE_INFO, "Invalid object type: %X", | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 280 | 			    operand0->common.type)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | 		status = AE_AML_INTERNAL; | 
 | 282 | 	} | 
 | 283 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | 		goto cleanup; | 
 | 286 | 	} | 
 | 287 |  | 
 | 288 | 	/* | 
 | 289 | 	 * Both operands are now known to be the same object type | 
 | 290 | 	 * (Both are Integer, String, or Buffer), and we can now perform the | 
 | 291 | 	 * concatenation. | 
 | 292 | 	 */ | 
 | 293 |  | 
 | 294 | 	/* | 
 | 295 | 	 * There are three cases to handle: | 
 | 296 | 	 * | 
 | 297 | 	 * 1) Two Integers concatenated to produce a new Buffer | 
 | 298 | 	 * 2) Two Strings concatenated to produce a new String | 
 | 299 | 	 * 3) Two Buffers concatenated to produce a new Buffer | 
 | 300 | 	 */ | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 301 | 	switch (operand0->common.type) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | 	case ACPI_TYPE_INTEGER: | 
 | 303 |  | 
 | 304 | 		/* Result of two Integers is a Buffer */ | 
 | 305 | 		/* Need enough buffer space for two integers */ | 
 | 306 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | 		return_desc = acpi_ut_create_buffer_object((acpi_size) | 
 | 308 | 							   ACPI_MUL_2 | 
 | 309 | 							   (acpi_gbl_integer_byte_width)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | 		if (!return_desc) { | 
 | 311 | 			status = AE_NO_MEMORY; | 
 | 312 | 			goto cleanup; | 
 | 313 | 		} | 
 | 314 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | 		new_buf = (char *)return_desc->buffer.pointer; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 |  | 
 | 317 | 		/* Copy the first integer, LSB first */ | 
 | 318 |  | 
| Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 319 | 		ACPI_MEMCPY(new_buf, &operand0->integer.value, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | 			    acpi_gbl_integer_byte_width); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 |  | 
 | 322 | 		/* Copy the second integer (LSB first) after the first */ | 
 | 323 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | 		ACPI_MEMCPY(new_buf + acpi_gbl_integer_byte_width, | 
 | 325 | 			    &local_operand1->integer.value, | 
 | 326 | 			    acpi_gbl_integer_byte_width); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | 		break; | 
 | 328 |  | 
 | 329 | 	case ACPI_TYPE_STRING: | 
 | 330 |  | 
 | 331 | 		/* Result of two Strings is a String */ | 
 | 332 |  | 
| Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 333 | 		return_desc = acpi_ut_create_string_object(((acpi_size) | 
 | 334 | 							    operand0->string. | 
| Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 335 | 							    length + | 
 | 336 | 							    local_operand1-> | 
 | 337 | 							    string.length)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | 		if (!return_desc) { | 
 | 339 | 			status = AE_NO_MEMORY; | 
 | 340 | 			goto cleanup; | 
 | 341 | 		} | 
 | 342 |  | 
 | 343 | 		new_buf = return_desc->string.pointer; | 
 | 344 |  | 
 | 345 | 		/* Concatenate the strings */ | 
 | 346 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | 		ACPI_STRCPY(new_buf, operand0->string.pointer); | 
 | 348 | 		ACPI_STRCPY(new_buf + operand0->string.length, | 
 | 349 | 			    local_operand1->string.pointer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | 		break; | 
 | 351 |  | 
 | 352 | 	case ACPI_TYPE_BUFFER: | 
 | 353 |  | 
 | 354 | 		/* Result of two Buffers is a Buffer */ | 
 | 355 |  | 
| Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 356 | 		return_desc = acpi_ut_create_buffer_object(((acpi_size) | 
 | 357 | 							    operand0->buffer. | 
| Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 358 | 							    length + | 
 | 359 | 							    local_operand1-> | 
 | 360 | 							    buffer.length)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | 		if (!return_desc) { | 
 | 362 | 			status = AE_NO_MEMORY; | 
 | 363 | 			goto cleanup; | 
 | 364 | 		} | 
 | 365 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | 		new_buf = (char *)return_desc->buffer.pointer; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 |  | 
 | 368 | 		/* Concatenate the buffers */ | 
 | 369 |  | 
| Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 370 | 		ACPI_MEMCPY(new_buf, operand0->buffer.pointer, | 
 | 371 | 			    operand0->buffer.length); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | 		ACPI_MEMCPY(new_buf + operand0->buffer.length, | 
 | 373 | 			    local_operand1->buffer.pointer, | 
 | 374 | 			    local_operand1->buffer.length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | 		break; | 
 | 376 |  | 
 | 377 | 	default: | 
 | 378 |  | 
 | 379 | 		/* Invalid object type, should not happen here */ | 
 | 380 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 381 | 		ACPI_ERROR((AE_INFO, "Invalid object type: %X", | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 382 | 			    operand0->common.type)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | 		status = AE_AML_INTERNAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | 		goto cleanup; | 
 | 385 | 	} | 
 | 386 |  | 
 | 387 | 	*actual_return_desc = return_desc; | 
 | 388 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 |       cleanup: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | 	if (local_operand1 != operand1) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | 		acpi_ut_remove_reference(local_operand1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | 	} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 393 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } | 
 | 395 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | /******************************************************************************* | 
 | 397 |  * | 
 | 398 |  * FUNCTION:    acpi_ex_do_math_op | 
 | 399 |  * | 
 | 400 |  * PARAMETERS:  Opcode              - AML opcode | 
 | 401 |  *              Integer0            - Integer operand #0 | 
 | 402 |  *              Integer1            - Integer operand #1 | 
 | 403 |  * | 
 | 404 |  * RETURN:      Integer result of the operation | 
 | 405 |  * | 
 | 406 |  * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the | 
 | 407 |  *              math functions here is to prevent a lot of pointer dereferencing | 
 | 408 |  *              to obtain the operands. | 
 | 409 |  * | 
 | 410 |  ******************************************************************************/ | 
 | 411 |  | 
 | 412 | acpi_integer | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 413 | acpi_ex_do_math_op(u16 opcode, acpi_integer integer0, acpi_integer integer1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { | 
 | 415 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | 	ACPI_FUNCTION_ENTRY(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 |  | 
 | 418 | 	switch (opcode) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 419 | 	case AML_ADD_OP:	/* Add (Integer0, Integer1, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 |  | 
 | 421 | 		return (integer0 + integer1); | 
 | 422 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 423 | 	case AML_BIT_AND_OP:	/* And (Integer0, Integer1, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 |  | 
 | 425 | 		return (integer0 & integer1); | 
 | 426 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 427 | 	case AML_BIT_NAND_OP:	/* NAnd (Integer0, Integer1, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 |  | 
 | 429 | 		return (~(integer0 & integer1)); | 
 | 430 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 431 | 	case AML_BIT_OR_OP:	/* Or (Integer0, Integer1, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 |  | 
 | 433 | 		return (integer0 | integer1); | 
 | 434 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 435 | 	case AML_BIT_NOR_OP:	/* NOr (Integer0, Integer1, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 |  | 
 | 437 | 		return (~(integer0 | integer1)); | 
 | 438 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 439 | 	case AML_BIT_XOR_OP:	/* XOr (Integer0, Integer1, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 |  | 
 | 441 | 		return (integer0 ^ integer1); | 
 | 442 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 443 | 	case AML_MULTIPLY_OP:	/* Multiply (Integer0, Integer1, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 |  | 
 | 445 | 		return (integer0 * integer1); | 
 | 446 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 447 | 	case AML_SHIFT_LEFT_OP:	/* shift_left (Operand, shift_count, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 449 | 		/* | 
 | 450 | 		 * We need to check if the shiftcount is larger than the integer bit | 
 | 451 | 		 * width since the behavior of this is not well-defined in the C language. | 
 | 452 | 		 */ | 
 | 453 | 		if (integer1 >= acpi_gbl_integer_bit_width) { | 
 | 454 | 			return (0); | 
 | 455 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | 		return (integer0 << integer1); | 
 | 457 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 458 | 	case AML_SHIFT_RIGHT_OP:	/* shift_right (Operand, shift_count, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 460 | 		/* | 
 | 461 | 		 * We need to check if the shiftcount is larger than the integer bit | 
 | 462 | 		 * width since the behavior of this is not well-defined in the C language. | 
 | 463 | 		 */ | 
 | 464 | 		if (integer1 >= acpi_gbl_integer_bit_width) { | 
 | 465 | 			return (0); | 
 | 466 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | 		return (integer0 >> integer1); | 
 | 468 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 469 | 	case AML_SUBTRACT_OP:	/* Subtract (Integer0, Integer1, Result) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 |  | 
 | 471 | 		return (integer0 - integer1); | 
 | 472 |  | 
 | 473 | 	default: | 
 | 474 |  | 
 | 475 | 		return (0); | 
 | 476 | 	} | 
 | 477 | } | 
 | 478 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /******************************************************************************* | 
 | 480 |  * | 
 | 481 |  * FUNCTION:    acpi_ex_do_logical_numeric_op | 
 | 482 |  * | 
 | 483 |  * PARAMETERS:  Opcode              - AML opcode | 
 | 484 |  *              Integer0            - Integer operand #0 | 
 | 485 |  *              Integer1            - Integer operand #1 | 
 | 486 |  *              logical_result      - TRUE/FALSE result of the operation | 
 | 487 |  * | 
 | 488 |  * RETURN:      Status | 
 | 489 |  * | 
 | 490 |  * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric | 
 | 491 |  *              operators (LAnd and LOr), both operands must be integers. | 
 | 492 |  * | 
 | 493 |  *              Note: cleanest machine code seems to be produced by the code | 
 | 494 |  *              below, rather than using statements of the form: | 
 | 495 |  *                  Result = (Integer0 && Integer1); | 
 | 496 |  * | 
 | 497 |  ******************************************************************************/ | 
 | 498 |  | 
 | 499 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 500 | acpi_ex_do_logical_numeric_op(u16 opcode, | 
 | 501 | 			      acpi_integer integer0, | 
 | 502 | 			      acpi_integer integer1, u8 * logical_result) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | 	acpi_status status = AE_OK; | 
 | 505 | 	u8 local_result = FALSE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 507 | 	ACPI_FUNCTION_TRACE(ex_do_logical_numeric_op); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 |  | 
 | 509 | 	switch (opcode) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 510 | 	case AML_LAND_OP:	/* LAnd (Integer0, Integer1) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 |  | 
 | 512 | 		if (integer0 && integer1) { | 
 | 513 | 			local_result = TRUE; | 
 | 514 | 		} | 
 | 515 | 		break; | 
 | 516 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | 	case AML_LOR_OP:	/* LOr (Integer0, Integer1) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 |  | 
 | 519 | 		if (integer0 || integer1) { | 
 | 520 | 			local_result = TRUE; | 
 | 521 | 		} | 
 | 522 | 		break; | 
 | 523 |  | 
 | 524 | 	default: | 
 | 525 | 		status = AE_AML_INTERNAL; | 
 | 526 | 		break; | 
 | 527 | 	} | 
 | 528 |  | 
 | 529 | 	/* Return the logical result and status */ | 
 | 530 |  | 
 | 531 | 	*logical_result = local_result; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } | 
 | 534 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | /******************************************************************************* | 
 | 536 |  * | 
 | 537 |  * FUNCTION:    acpi_ex_do_logical_op | 
 | 538 |  * | 
 | 539 |  * PARAMETERS:  Opcode              - AML opcode | 
 | 540 |  *              Operand0            - operand #0 | 
 | 541 |  *              Operand1            - operand #1 | 
 | 542 |  *              logical_result      - TRUE/FALSE result of the operation | 
 | 543 |  * | 
 | 544 |  * RETURN:      Status | 
 | 545 |  * | 
 | 546 |  * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the | 
 | 547 |  *              functions here is to prevent a lot of pointer dereferencing | 
 | 548 |  *              to obtain the operands and to simplify the generation of the | 
 | 549 |  *              logical value. For the Numeric operators (LAnd and LOr), both | 
 | 550 |  *              operands must be integers. For the other logical operators, | 
 | 551 |  *              operands can be any combination of Integer/String/Buffer. The | 
 | 552 |  *              first operand determines the type to which the second operand | 
 | 553 |  *              will be converted. | 
 | 554 |  * | 
 | 555 |  *              Note: cleanest machine code seems to be produced by the code | 
 | 556 |  *              below, rather than using statements of the form: | 
 | 557 |  *                  Result = (Operand0 == Operand1); | 
 | 558 |  * | 
 | 559 |  ******************************************************************************/ | 
 | 560 |  | 
 | 561 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 562 | acpi_ex_do_logical_op(u16 opcode, | 
 | 563 | 		      union acpi_operand_object *operand0, | 
 | 564 | 		      union acpi_operand_object *operand1, u8 * logical_result) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 566 | 	union acpi_operand_object *local_operand1 = operand1; | 
 | 567 | 	acpi_integer integer0; | 
 | 568 | 	acpi_integer integer1; | 
 | 569 | 	u32 length0; | 
 | 570 | 	u32 length1; | 
 | 571 | 	acpi_status status = AE_OK; | 
 | 572 | 	u8 local_result = FALSE; | 
 | 573 | 	int compare; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 575 | 	ACPI_FUNCTION_TRACE(ex_do_logical_op); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 |  | 
 | 577 | 	/* | 
 | 578 | 	 * Convert the second operand if necessary.  The first operand | 
 | 579 | 	 * determines the type of the second operand, (See the Data Types | 
 | 580 | 	 * section of the ACPI 3.0+ specification.)  Both object types are | 
 | 581 | 	 * guaranteed to be either Integer/String/Buffer by the operand | 
 | 582 | 	 * resolution mechanism. | 
 | 583 | 	 */ | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 584 | 	switch (operand0->common.type) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | 	case ACPI_TYPE_INTEGER: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 586 | 		status = | 
 | 587 | 		    acpi_ex_convert_to_integer(operand1, &local_operand1, 16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | 		break; | 
 | 589 |  | 
 | 590 | 	case ACPI_TYPE_STRING: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 591 | 		status = acpi_ex_convert_to_string(operand1, &local_operand1, | 
 | 592 | 						   ACPI_IMPLICIT_CONVERT_HEX); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | 		break; | 
 | 594 |  | 
 | 595 | 	case ACPI_TYPE_BUFFER: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 596 | 		status = acpi_ex_convert_to_buffer(operand1, &local_operand1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | 		break; | 
 | 598 |  | 
 | 599 | 	default: | 
 | 600 | 		status = AE_AML_INTERNAL; | 
 | 601 | 		break; | 
 | 602 | 	} | 
 | 603 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 604 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | 		goto cleanup; | 
 | 606 | 	} | 
 | 607 |  | 
 | 608 | 	/* | 
 | 609 | 	 * Two cases: 1) Both Integers, 2) Both Strings or Buffers | 
 | 610 | 	 */ | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 611 | 	if (operand0->common.type == ACPI_TYPE_INTEGER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | 		/* | 
 | 613 | 		 * 1) Both operands are of type integer | 
 | 614 | 		 *    Note: local_operand1 may have changed above | 
 | 615 | 		 */ | 
 | 616 | 		integer0 = operand0->integer.value; | 
 | 617 | 		integer1 = local_operand1->integer.value; | 
 | 618 |  | 
 | 619 | 		switch (opcode) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 620 | 		case AML_LEQUAL_OP:	/* LEqual (Operand0, Operand1) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 |  | 
 | 622 | 			if (integer0 == integer1) { | 
 | 623 | 				local_result = TRUE; | 
 | 624 | 			} | 
 | 625 | 			break; | 
 | 626 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 627 | 		case AML_LGREATER_OP:	/* LGreater (Operand0, Operand1) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 |  | 
 | 629 | 			if (integer0 > integer1) { | 
 | 630 | 				local_result = TRUE; | 
 | 631 | 			} | 
 | 632 | 			break; | 
 | 633 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 634 | 		case AML_LLESS_OP:	/* LLess (Operand0, Operand1) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 |  | 
 | 636 | 			if (integer0 < integer1) { | 
 | 637 | 				local_result = TRUE; | 
 | 638 | 			} | 
 | 639 | 			break; | 
 | 640 |  | 
 | 641 | 		default: | 
 | 642 | 			status = AE_AML_INTERNAL; | 
 | 643 | 			break; | 
 | 644 | 		} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 645 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | 		/* | 
 | 647 | 		 * 2) Both operands are Strings or both are Buffers | 
 | 648 | 		 *    Note: Code below takes advantage of common Buffer/String | 
 | 649 | 		 *          object fields. local_operand1 may have changed above. Use | 
 | 650 | 		 *          memcmp to handle nulls in buffers. | 
 | 651 | 		 */ | 
 | 652 | 		length0 = operand0->buffer.length; | 
 | 653 | 		length1 = local_operand1->buffer.length; | 
 | 654 |  | 
 | 655 | 		/* Lexicographic compare: compare the data bytes */ | 
 | 656 |  | 
| Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 657 | 		compare = ACPI_MEMCMP(operand0->buffer.pointer, | 
 | 658 | 				      local_operand1->buffer.pointer, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 659 | 				      (length0 > length1) ? length1 : length0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 |  | 
 | 661 | 		switch (opcode) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 662 | 		case AML_LEQUAL_OP:	/* LEqual (Operand0, Operand1) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 |  | 
 | 664 | 			/* Length and all bytes must be equal */ | 
 | 665 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 666 | 			if ((length0 == length1) && (compare == 0)) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 667 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | 				/* Length and all bytes match ==> TRUE */ | 
 | 669 |  | 
 | 670 | 				local_result = TRUE; | 
 | 671 | 			} | 
 | 672 | 			break; | 
 | 673 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 674 | 		case AML_LGREATER_OP:	/* LGreater (Operand0, Operand1) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 |  | 
 | 676 | 			if (compare > 0) { | 
 | 677 | 				local_result = TRUE; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 678 | 				goto cleanup;	/* TRUE */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | 			} | 
 | 680 | 			if (compare < 0) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 681 | 				goto cleanup;	/* FALSE */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | 			} | 
 | 683 |  | 
 | 684 | 			/* Bytes match (to shortest length), compare lengths */ | 
 | 685 |  | 
 | 686 | 			if (length0 > length1) { | 
 | 687 | 				local_result = TRUE; | 
 | 688 | 			} | 
 | 689 | 			break; | 
 | 690 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 691 | 		case AML_LLESS_OP:	/* LLess (Operand0, Operand1) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 |  | 
 | 693 | 			if (compare > 0) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 694 | 				goto cleanup;	/* FALSE */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | 			} | 
 | 696 | 			if (compare < 0) { | 
 | 697 | 				local_result = TRUE; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 698 | 				goto cleanup;	/* TRUE */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | 			} | 
 | 700 |  | 
 | 701 | 			/* Bytes match (to shortest length), compare lengths */ | 
 | 702 |  | 
 | 703 | 			if (length0 < length1) { | 
 | 704 | 				local_result = TRUE; | 
 | 705 | 			} | 
 | 706 | 			break; | 
 | 707 |  | 
 | 708 | 		default: | 
 | 709 | 			status = AE_AML_INTERNAL; | 
 | 710 | 			break; | 
 | 711 | 		} | 
 | 712 | 	} | 
 | 713 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 714 |       cleanup: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 |  | 
 | 716 | 	/* New object was created if implicit conversion performed - delete */ | 
 | 717 |  | 
 | 718 | 	if (local_operand1 != operand1) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 719 | 		acpi_ut_remove_reference(local_operand1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | 	} | 
 | 721 |  | 
 | 722 | 	/* Return the logical result and status */ | 
 | 723 |  | 
 | 724 | 	*logical_result = local_result; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 725 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |