]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/exoparg3.c
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / exoparg3.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
4 *
5 *****************************************************************************/
6
7/*
7735ca0e 8 * Copyright (C) 2000 - 2017, Intel Corp.
1da177e4
LT
9 * 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
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acinterp.h"
47#include "acparser.h"
48#include "amlcode.h"
1da177e4 49
1da177e4 50#define _COMPONENT ACPI_EXECUTER
4be44fcd 51ACPI_MODULE_NAME("exoparg3")
1da177e4
LT
52
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!*/
1da177e4
LT
74/*******************************************************************************
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 ******************************************************************************/
4be44fcd 85acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
1da177e4 86{
4be44fcd
LB
87 union acpi_operand_object **operand = &walk_state->operands[0];
88 struct acpi_signal_fatal_info *fatal;
89 acpi_status status = AE_OK;
1da177e4 90
b229cf92 91 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
4be44fcd 92 acpi_ps_get_opcode_name(walk_state->opcode));
1da177e4
LT
93
94 switch (walk_state->opcode) {
4be44fcd 95 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
1da177e4 96
4be44fcd 97 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1fad8738
BM
98 "FatalOp: Type %X Code %X Arg %X "
99 "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
5431b654
LZ
100 (u32)operand[0]->integer.value,
101 (u32)operand[1]->integer.value,
102 (u32)operand[2]->integer.value));
1da177e4 103
8313524a 104 fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
1da177e4 105 if (fatal) {
4be44fcd
LB
106 fatal->type = (u32) operand[0]->integer.value;
107 fatal->code = (u32) operand[1]->integer.value;
1da177e4
LT
108 fatal->argument = (u32) operand[2]->integer.value;
109 }
110
44f6c012
RM
111 /* Always signal the OS! */
112
4be44fcd 113 status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
1da177e4
LT
114
115 /* Might return while OS is shutting down, just continue */
116
8313524a 117 ACPI_FREE(fatal);
56a3d5e7
BM
118 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
b3aec972
DB
126 * AML interpreters never see the opcode. Thus, something is
127 * wrong if an external opcode ever gets here.
56a3d5e7 128 */
b3aec972 129 ACPI_ERROR((AE_INFO, "Executed External Op"));
56a3d5e7
BM
130 status = AE_OK;
131 goto cleanup;
1da177e4 132
1da177e4
LT
133 default:
134
f6a22b0b 135 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
b8e4d893 136 walk_state->opcode));
1fad8738 137
1da177e4
LT
138 status = AE_AML_BAD_OPCODE;
139 goto cleanup;
140 }
141
10622bf8 142cleanup:
1da177e4 143
4be44fcd 144 return_ACPI_STATUS(status);
1da177e4
LT
145}
146
1da177e4
LT
147/*******************************************************************************
148 *
149 * FUNCTION: acpi_ex_opcode_3A_1T_1R
150 *
151 * PARAMETERS: walk_state - Current walk state
152 *
153 * RETURN: Status
154 *
155 * DESCRIPTION: Execute Triadic operator (3 operands)
156 *
157 ******************************************************************************/
158
4be44fcd 159acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
1da177e4 160{
4be44fcd
LB
161 union acpi_operand_object **operand = &walk_state->operands[0];
162 union acpi_operand_object *return_desc = NULL;
163 char *buffer = NULL;
164 acpi_status status = AE_OK;
5df7e6cb 165 u64 index;
4be44fcd 166 acpi_size length;
1da177e4 167
b229cf92 168 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
4be44fcd 169 acpi_ps_get_opcode_name(walk_state->opcode));
1da177e4
LT
170
171 switch (walk_state->opcode) {
4be44fcd 172 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
1da177e4 173 /*
73a3090a 174 * Create the return object. The Source operand is guaranteed to be
1da177e4
LT
175 * either a String or a Buffer, so just use its type.
176 */
3371c19c
BM
177 return_desc = acpi_ut_create_internal_object((operand[0])->
178 common.type);
1da177e4
LT
179 if (!return_desc) {
180 status = AE_NO_MEMORY;
181 goto cleanup;
182 }
183
184 /* Get the Integer values from the objects */
185
44f6c012 186 index = operand[1]->integer.value;
f5c1e1c5 187 length = (acpi_size)operand[2]->integer.value;
1da177e4
LT
188
189 /*
190 * If the index is beyond the length of the String/Buffer, or if the
191 * requested length is zero, return a zero-length String/Buffer
192 */
73459f73
RM
193 if (index >= operand[0]->string.length) {
194 length = 0;
195 }
196
197 /* Truncate request if larger than the actual String/Buffer */
198
199 else if ((index + length) > operand[0]->string.length) {
1fad8738 200 length =
f5c1e1c5
LZ
201 (acpi_size)operand[0]->string.length -
202 (acpi_size)index;
73459f73 203 }
1da177e4 204
73459f73
RM
205 /* Strings always have a sub-pointer, not so for buffers */
206
3371c19c 207 switch ((operand[0])->common.type) {
73459f73
RM
208 case ACPI_TYPE_STRING:
209
210 /* Always allocate a new buffer for the String */
1da177e4 211
f5c1e1c5 212 buffer = ACPI_ALLOCATE_ZEROED((acpi_size)length + 1);
1da177e4
LT
213 if (!buffer) {
214 status = AE_NO_MEMORY;
215 goto cleanup;
216 }
73459f73
RM
217 break;
218
219 case ACPI_TYPE_BUFFER:
220
221 /* If the requested length is zero, don't allocate a buffer */
222
223 if (length > 0) {
52fc0b02 224
73459f73
RM
225 /* Allocate a new buffer for the Buffer */
226
8313524a 227 buffer = ACPI_ALLOCATE_ZEROED(length);
73459f73
RM
228 if (!buffer) {
229 status = AE_NO_MEMORY;
230 goto cleanup;
231 }
232 }
233 break;
1da177e4 234
4be44fcd 235 default: /* Should not happen */
73459f73
RM
236
237 status = AE_AML_OPERAND_TYPE;
238 goto cleanup;
239 }
240
defba1d8 241 if (buffer) {
52fc0b02 242
defba1d8 243 /* We have a buffer, copy the portion requested */
1da177e4 244
1fad8738
BM
245 memcpy(buffer,
246 operand[0]->string.pointer + index, length);
73459f73 247 }
1da177e4 248
73459f73 249 /* Set the length of the new String/Buffer */
1da177e4 250
73459f73
RM
251 return_desc->string.pointer = buffer;
252 return_desc->string.length = (u32) length;
1da177e4
LT
253
254 /* Mark buffer initialized */
255
256 return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
257 break;
258
1da177e4
LT
259 default:
260
f6a22b0b 261 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
b8e4d893 262 walk_state->opcode));
1fad8738 263
1da177e4
LT
264 status = AE_AML_BAD_OPCODE;
265 goto cleanup;
266 }
267
268 /* Store the result in the target */
269
4be44fcd 270 status = acpi_ex_store(return_desc, operand[3], walk_state);
1da177e4 271
10622bf8 272cleanup:
1da177e4
LT
273
274 /* Delete return object on error */
275
4be44fcd
LB
276 if (ACPI_FAILURE(status) || walk_state->result_obj) {
277 acpi_ut_remove_reference(return_desc);
4b6e16cf 278 walk_state->result_obj = NULL;
1fad8738
BM
279 } else {
280 /* Set the return object and exit */
1da177e4 281
1da177e4
LT
282 walk_state->result_obj = return_desc;
283 }
1fad8738 284
4be44fcd 285 return_ACPI_STATUS(status);
1da177e4 286}