blob: 28eb861c44ebeaab2715ee19cae7c9e202daea00 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
4 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acinterp.h"
47#include "acparser.h"
48#include "amlcode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("exoparg3")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*!
54 * Naming convention for AML interpreter execution routines.
55 *
56 * The routines that begin execution of AML opcodes are named with a common
57 * convention based upon the number of arguments, the number of target operands,
58 * and whether or not a value is returned:
59 *
60 * AcpiExOpcode_xA_yT_zR
61 *
62 * Where:
63 *
64 * xA - ARGUMENTS: The number of arguments (input operands) that are
65 * required for this opcode type (1 through 6 args).
66 * yT - TARGETS: The number of targets (output operands) that are required
67 * for this opcode type (0, 1, or 2 targets).
68 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
69 * as the function return (0 or 1).
70 *
71 * The AcpiExOpcode* functions are called via the Dispatcher component with
72 * fully resolved operands.
73!*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070074/*******************************************************************************
75 *
76 * FUNCTION: acpi_ex_opcode_3A_0T_0R
77 *
78 * PARAMETERS: walk_state - Current walk state
79 *
80 * RETURN: Status
81 *
82 * DESCRIPTION: Execute Triadic operator (3 operands)
83 *
84 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040085acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Len Brown4be44fc2005-08-05 00:44:28 -040087 union acpi_operand_object **operand = &walk_state->operands[0];
88 struct acpi_signal_fatal_info *fatal;
89 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Bob Mooreb229cf92006-04-21 17:15:00 -040091 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
Len Brown4be44fc2005-08-05 00:44:28 -040092 acpi_ps_get_opcode_name(walk_state->opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 switch (walk_state->opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -040095 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Len Brown4be44fc2005-08-05 00:44:28 -040097 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore1fad8732015-12-29 13:54:36 +080098 "FatalOp: Type %X Code %X Arg %X "
99 "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
Lv Zheng5431b652015-12-29 13:52:32 +0800100 (u32)operand[0]->integer.value,
101 (u32)operand[1]->integer.value,
102 (u32)operand[2]->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Bob Moore83135242006-10-03 00:00:00 -0400104 fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 if (fatal) {
Len Brown4be44fc2005-08-05 00:44:28 -0400106 fatal->type = (u32) operand[0]->integer.value;
107 fatal->code = (u32) operand[1]->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 fatal->argument = (u32) operand[2]->integer.value;
109 }
110
Robert Moore44f6c012005-04-18 22:49:35 -0400111 /* Always signal the OS! */
112
Len Brown4be44fc2005-08-05 00:44:28 -0400113 status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* Might return while OS is shutting down, just continue */
116
Bob Moore83135242006-10-03 00:00:00 -0400117 ACPI_FREE(fatal);
Bob Moore56a3d5e2015-04-13 11:50:32 +0800118 goto cleanup;
119
120 case AML_EXTERNAL_OP:
121 /*
122 * If the interpreter sees this opcode, just ignore it. The External
123 * op is intended for use by disassemblers in order to properly
124 * disassemble control method invocations. The opcode or group of
125 * opcodes should be surrounded by an "if (0)" clause to ensure that
126 * AML interpreters never see the opcode.
127 */
128 status = AE_OK;
129 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 default:
132
Bob Mooref6a22b02010-03-05 17:56:40 +0800133 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500134 walk_state->opcode));
Bob Moore1fad8732015-12-29 13:54:36 +0800135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 status = AE_AML_BAD_OPCODE;
137 goto cleanup;
138 }
139
Lv Zheng10622bf2013-10-29 09:30:02 +0800140cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Len Brown4be44fc2005-08-05 00:44:28 -0400142 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*******************************************************************************
146 *
147 * FUNCTION: acpi_ex_opcode_3A_1T_1R
148 *
149 * PARAMETERS: walk_state - Current walk state
150 *
151 * RETURN: Status
152 *
153 * DESCRIPTION: Execute Triadic operator (3 operands)
154 *
155 ******************************************************************************/
156
Len Brown4be44fc2005-08-05 00:44:28 -0400157acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Len Brown4be44fc2005-08-05 00:44:28 -0400159 union acpi_operand_object **operand = &walk_state->operands[0];
160 union acpi_operand_object *return_desc = NULL;
161 char *buffer = NULL;
162 acpi_status status = AE_OK;
Bob Moore5df7e6c2010-01-21 10:06:32 +0800163 u64 index;
Len Brown4be44fc2005-08-05 00:44:28 -0400164 acpi_size length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Bob Mooreb229cf92006-04-21 17:15:00 -0400166 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
Len Brown4be44fc2005-08-05 00:44:28 -0400167 acpi_ps_get_opcode_name(walk_state->opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 switch (walk_state->opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400170 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 /*
Bob Moore73a30902012-10-31 02:26:55 +0000172 * Create the return object. The Source operand is guaranteed to be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 * either a String or a Buffer, so just use its type.
174 */
Bob Moore3371c192009-02-18 14:44:03 +0800175 return_desc = acpi_ut_create_internal_object((operand[0])->
176 common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (!return_desc) {
178 status = AE_NO_MEMORY;
179 goto cleanup;
180 }
181
182 /* Get the Integer values from the objects */
183
Robert Moore44f6c012005-04-18 22:49:35 -0400184 index = operand[1]->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 length = (acpi_size) operand[2]->integer.value;
186
187 /*
188 * If the index is beyond the length of the String/Buffer, or if the
189 * requested length is zero, return a zero-length String/Buffer
190 */
Robert Moore73459f72005-06-24 00:00:00 -0400191 if (index >= operand[0]->string.length) {
192 length = 0;
193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Robert Moore73459f72005-06-24 00:00:00 -0400195 /* Truncate request if larger than the actual String/Buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Robert Moore73459f72005-06-24 00:00:00 -0400197 else if ((index + length) > operand[0]->string.length) {
Bob Moore1fad8732015-12-29 13:54:36 +0800198 length =
199 (acpi_size) operand[0]->string.length -
Len Brown4be44fc2005-08-05 00:44:28 -0400200 (acpi_size) index;
Robert Moore73459f72005-06-24 00:00:00 -0400201 }
202
203 /* Strings always have a sub-pointer, not so for buffers */
204
Bob Moore3371c192009-02-18 14:44:03 +0800205 switch ((operand[0])->common.type) {
Robert Moore73459f72005-06-24 00:00:00 -0400206 case ACPI_TYPE_STRING:
207
208 /* Always allocate a new buffer for the String */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Bob Moore83135242006-10-03 00:00:00 -0400210 buffer = ACPI_ALLOCATE_ZEROED((acpi_size) length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 if (!buffer) {
212 status = AE_NO_MEMORY;
213 goto cleanup;
214 }
Robert Moore73459f72005-06-24 00:00:00 -0400215 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Robert Moore73459f72005-06-24 00:00:00 -0400217 case ACPI_TYPE_BUFFER:
218
219 /* If the requested length is zero, don't allocate a buffer */
220
221 if (length > 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400222
Robert Moore73459f72005-06-24 00:00:00 -0400223 /* Allocate a new buffer for the Buffer */
224
Bob Moore83135242006-10-03 00:00:00 -0400225 buffer = ACPI_ALLOCATE_ZEROED(length);
Robert Moore73459f72005-06-24 00:00:00 -0400226 if (!buffer) {
227 status = AE_NO_MEMORY;
228 goto cleanup;
229 }
230 }
231 break;
232
Len Brown4be44fc2005-08-05 00:44:28 -0400233 default: /* Should not happen */
Robert Moore73459f72005-06-24 00:00:00 -0400234
235 status = AE_AML_OPERAND_TYPE;
236 goto cleanup;
237 }
238
Bob Mooredefba1d2005-12-16 17:05:00 -0500239 if (buffer) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400240
Bob Mooredefba1d2005-12-16 17:05:00 -0500241 /* We have a buffer, copy the portion requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Bob Moore1fad8732015-12-29 13:54:36 +0800243 memcpy(buffer,
244 operand[0]->string.pointer + index, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
246
Robert Moore73459f72005-06-24 00:00:00 -0400247 /* Set the length of the new String/Buffer */
248
249 return_desc->string.pointer = buffer;
250 return_desc->string.length = (u32) length;
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 /* Mark buffer initialized */
253
254 return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
255 break;
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 default:
258
Bob Mooref6a22b02010-03-05 17:56:40 +0800259 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500260 walk_state->opcode));
Bob Moore1fad8732015-12-29 13:54:36 +0800261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 status = AE_AML_BAD_OPCODE;
263 goto cleanup;
264 }
265
266 /* Store the result in the target */
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268 status = acpi_ex_store(return_desc, operand[3], walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Lv Zheng10622bf2013-10-29 09:30:02 +0800270cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 /* Delete return object on error */
273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 if (ACPI_FAILURE(status) || walk_state->result_obj) {
275 acpi_ut_remove_reference(return_desc);
Bob Moore4b6e16c2008-04-10 19:06:37 +0400276 walk_state->result_obj = NULL;
Bob Moore1fad8732015-12-29 13:54:36 +0800277 } else {
278 /* Set the return object and exit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 walk_state->result_obj = return_desc;
281 }
Bob Moore1fad8732015-12-29 13:54:36 +0800282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}