Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: exoparg3 - AML execution - opcodes with 3 arguments | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
25f044e6 | 8 | * Copyright (C) 2000 - 2013, 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 | 51 | ACPI_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 | 85 | acpi_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, |
b229cf92 | 98 | "FatalOp: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", |
4be44fcd LB |
99 | (u32) operand[0]->integer.value, |
100 | (u32) operand[1]->integer.value, | |
101 | (u32) operand[2]->integer.value)); | |
1da177e4 | 102 | |
8313524a | 103 | fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info)); |
1da177e4 | 104 | if (fatal) { |
4be44fcd LB |
105 | fatal->type = (u32) operand[0]->integer.value; |
106 | fatal->code = (u32) operand[1]->integer.value; | |
1da177e4 LT |
107 | fatal->argument = (u32) operand[2]->integer.value; |
108 | } | |
109 | ||
44f6c012 RM |
110 | /* Always signal the OS! */ |
111 | ||
4be44fcd | 112 | status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal); |
1da177e4 LT |
113 | |
114 | /* Might return while OS is shutting down, just continue */ | |
115 | ||
8313524a | 116 | ACPI_FREE(fatal); |
1da177e4 LT |
117 | break; |
118 | ||
1da177e4 LT |
119 | default: |
120 | ||
f6a22b0b | 121 | ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", |
b8e4d893 | 122 | walk_state->opcode)); |
1da177e4 LT |
123 | status = AE_AML_BAD_OPCODE; |
124 | goto cleanup; | |
125 | } | |
126 | ||
4be44fcd | 127 | cleanup: |
1da177e4 | 128 | |
4be44fcd | 129 | return_ACPI_STATUS(status); |
1da177e4 LT |
130 | } |
131 | ||
1da177e4 LT |
132 | /******************************************************************************* |
133 | * | |
134 | * FUNCTION: acpi_ex_opcode_3A_1T_1R | |
135 | * | |
136 | * PARAMETERS: walk_state - Current walk state | |
137 | * | |
138 | * RETURN: Status | |
139 | * | |
140 | * DESCRIPTION: Execute Triadic operator (3 operands) | |
141 | * | |
142 | ******************************************************************************/ | |
143 | ||
4be44fcd | 144 | acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state) |
1da177e4 | 145 | { |
4be44fcd LB |
146 | union acpi_operand_object **operand = &walk_state->operands[0]; |
147 | union acpi_operand_object *return_desc = NULL; | |
148 | char *buffer = NULL; | |
149 | acpi_status status = AE_OK; | |
5df7e6cb | 150 | u64 index; |
4be44fcd | 151 | acpi_size length; |
1da177e4 | 152 | |
b229cf92 | 153 | ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R, |
4be44fcd | 154 | acpi_ps_get_opcode_name(walk_state->opcode)); |
1da177e4 LT |
155 | |
156 | switch (walk_state->opcode) { | |
4be44fcd | 157 | case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */ |
1da177e4 | 158 | /* |
73a3090a | 159 | * Create the return object. The Source operand is guaranteed to be |
1da177e4 LT |
160 | * either a String or a Buffer, so just use its type. |
161 | */ | |
3371c19c BM |
162 | return_desc = acpi_ut_create_internal_object((operand[0])-> |
163 | common.type); | |
1da177e4 LT |
164 | if (!return_desc) { |
165 | status = AE_NO_MEMORY; | |
166 | goto cleanup; | |
167 | } | |
168 | ||
169 | /* Get the Integer values from the objects */ | |
170 | ||
44f6c012 | 171 | index = operand[1]->integer.value; |
1da177e4 LT |
172 | length = (acpi_size) operand[2]->integer.value; |
173 | ||
174 | /* | |
175 | * If the index is beyond the length of the String/Buffer, or if the | |
176 | * requested length is zero, return a zero-length String/Buffer | |
177 | */ | |
73459f73 RM |
178 | if (index >= operand[0]->string.length) { |
179 | length = 0; | |
180 | } | |
181 | ||
182 | /* Truncate request if larger than the actual String/Buffer */ | |
183 | ||
184 | else if ((index + length) > operand[0]->string.length) { | |
185 | length = (acpi_size) operand[0]->string.length - | |
4be44fcd | 186 | (acpi_size) index; |
73459f73 | 187 | } |
1da177e4 | 188 | |
73459f73 RM |
189 | /* Strings always have a sub-pointer, not so for buffers */ |
190 | ||
3371c19c | 191 | switch ((operand[0])->common.type) { |
73459f73 RM |
192 | case ACPI_TYPE_STRING: |
193 | ||
194 | /* Always allocate a new buffer for the String */ | |
1da177e4 | 195 | |
8313524a | 196 | buffer = ACPI_ALLOCATE_ZEROED((acpi_size) length + 1); |
1da177e4 LT |
197 | if (!buffer) { |
198 | status = AE_NO_MEMORY; | |
199 | goto cleanup; | |
200 | } | |
73459f73 RM |
201 | break; |
202 | ||
203 | case ACPI_TYPE_BUFFER: | |
204 | ||
205 | /* If the requested length is zero, don't allocate a buffer */ | |
206 | ||
207 | if (length > 0) { | |
52fc0b02 | 208 | |
73459f73 RM |
209 | /* Allocate a new buffer for the Buffer */ |
210 | ||
8313524a | 211 | buffer = ACPI_ALLOCATE_ZEROED(length); |
73459f73 RM |
212 | if (!buffer) { |
213 | status = AE_NO_MEMORY; | |
214 | goto cleanup; | |
215 | } | |
216 | } | |
217 | break; | |
1da177e4 | 218 | |
4be44fcd | 219 | default: /* Should not happen */ |
73459f73 RM |
220 | |
221 | status = AE_AML_OPERAND_TYPE; | |
222 | goto cleanup; | |
223 | } | |
224 | ||
defba1d8 | 225 | if (buffer) { |
52fc0b02 | 226 | |
defba1d8 | 227 | /* We have a buffer, copy the portion requested */ |
1da177e4 | 228 | |
4be44fcd LB |
229 | ACPI_MEMCPY(buffer, operand[0]->string.pointer + index, |
230 | length); | |
73459f73 | 231 | } |
1da177e4 | 232 | |
73459f73 | 233 | /* Set the length of the new String/Buffer */ |
1da177e4 | 234 | |
73459f73 RM |
235 | return_desc->string.pointer = buffer; |
236 | return_desc->string.length = (u32) length; | |
1da177e4 LT |
237 | |
238 | /* Mark buffer initialized */ | |
239 | ||
240 | return_desc->buffer.flags |= AOPOBJ_DATA_VALID; | |
241 | break; | |
242 | ||
1da177e4 LT |
243 | default: |
244 | ||
f6a22b0b | 245 | ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", |
b8e4d893 | 246 | walk_state->opcode)); |
1da177e4 LT |
247 | status = AE_AML_BAD_OPCODE; |
248 | goto cleanup; | |
249 | } | |
250 | ||
251 | /* Store the result in the target */ | |
252 | ||
4be44fcd | 253 | status = acpi_ex_store(return_desc, operand[3], walk_state); |
1da177e4 | 254 | |
4be44fcd | 255 | cleanup: |
1da177e4 LT |
256 | |
257 | /* Delete return object on error */ | |
258 | ||
4be44fcd LB |
259 | if (ACPI_FAILURE(status) || walk_state->result_obj) { |
260 | acpi_ut_remove_reference(return_desc); | |
4b6e16cf | 261 | walk_state->result_obj = NULL; |
1da177e4 LT |
262 | } |
263 | ||
264 | /* Set the return object and exit */ | |
265 | ||
73459f73 | 266 | else { |
1da177e4 LT |
267 | walk_state->result_obj = return_desc; |
268 | } | |
4be44fcd | 269 | return_ACPI_STATUS(status); |
1da177e4 | 270 | } |