Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Module Name: exoparg3 - AML execution - opcodes with 3 arguments | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
75a44ce0 | 9 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
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 | ||
1da177e4 | 45 | #include <acpi/acpi.h> |
e2f7a777 LB |
46 | #include "accommon.h" |
47 | #include "acinterp.h" | |
48 | #include "acparser.h" | |
49 | #include "amlcode.h" | |
1da177e4 | 50 | |
1da177e4 | 51 | #define _COMPONENT ACPI_EXECUTER |
4be44fcd | 52 | ACPI_MODULE_NAME("exoparg3") |
1da177e4 LT |
53 | |
54 | /*! | |
55 | * Naming convention for AML interpreter execution routines. | |
56 | * | |
57 | * The routines that begin execution of AML opcodes are named with a common | |
58 | * convention based upon the number of arguments, the number of target operands, | |
59 | * and whether or not a value is returned: | |
60 | * | |
61 | * AcpiExOpcode_xA_yT_zR | |
62 | * | |
63 | * Where: | |
64 | * | |
65 | * xA - ARGUMENTS: The number of arguments (input operands) that are | |
66 | * required for this opcode type (1 through 6 args). | |
67 | * yT - TARGETS: The number of targets (output operands) that are required | |
68 | * for this opcode type (0, 1, or 2 targets). | |
69 | * zR - RETURN VALUE: Indicates whether this opcode type returns a value | |
70 | * as the function return (0 or 1). | |
71 | * | |
72 | * The AcpiExOpcode* functions are called via the Dispatcher component with | |
73 | * fully resolved operands. | |
74 | !*/ | |
1da177e4 LT |
75 | /******************************************************************************* |
76 | * | |
77 | * FUNCTION: acpi_ex_opcode_3A_0T_0R | |
78 | * | |
79 | * PARAMETERS: walk_state - Current walk state | |
80 | * | |
81 | * RETURN: Status | |
82 | * | |
83 | * DESCRIPTION: Execute Triadic operator (3 operands) | |
84 | * | |
85 | ******************************************************************************/ | |
4be44fcd | 86 | acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state) |
1da177e4 | 87 | { |
4be44fcd LB |
88 | union acpi_operand_object **operand = &walk_state->operands[0]; |
89 | struct acpi_signal_fatal_info *fatal; | |
90 | acpi_status status = AE_OK; | |
1da177e4 | 91 | |
b229cf92 | 92 | ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R, |
4be44fcd | 93 | acpi_ps_get_opcode_name(walk_state->opcode)); |
1da177e4 LT |
94 | |
95 | switch (walk_state->opcode) { | |
4be44fcd | 96 | case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */ |
1da177e4 | 97 | |
4be44fcd | 98 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
b229cf92 | 99 | "FatalOp: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", |
4be44fcd LB |
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); |
1da177e4 LT |
118 | break; |
119 | ||
1da177e4 LT |
120 | default: |
121 | ||
b8e4d893 BM |
122 | ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", |
123 | walk_state->opcode)); | |
1da177e4 LT |
124 | status = AE_AML_BAD_OPCODE; |
125 | goto cleanup; | |
126 | } | |
127 | ||
4be44fcd | 128 | cleanup: |
1da177e4 | 129 | |
4be44fcd | 130 | return_ACPI_STATUS(status); |
1da177e4 LT |
131 | } |
132 | ||
1da177e4 LT |
133 | /******************************************************************************* |
134 | * | |
135 | * FUNCTION: acpi_ex_opcode_3A_1T_1R | |
136 | * | |
137 | * PARAMETERS: walk_state - Current walk state | |
138 | * | |
139 | * RETURN: Status | |
140 | * | |
141 | * DESCRIPTION: Execute Triadic operator (3 operands) | |
142 | * | |
143 | ******************************************************************************/ | |
144 | ||
4be44fcd | 145 | acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state) |
1da177e4 | 146 | { |
4be44fcd LB |
147 | union acpi_operand_object **operand = &walk_state->operands[0]; |
148 | union acpi_operand_object *return_desc = NULL; | |
149 | char *buffer = NULL; | |
150 | acpi_status status = AE_OK; | |
151 | acpi_integer index; | |
152 | acpi_size length; | |
1da177e4 | 153 | |
b229cf92 | 154 | ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R, |
4be44fcd | 155 | acpi_ps_get_opcode_name(walk_state->opcode)); |
1da177e4 LT |
156 | |
157 | switch (walk_state->opcode) { | |
4be44fcd | 158 | case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */ |
1da177e4 LT |
159 | |
160 | /* | |
161 | * Create the return object. The Source operand is guaranteed to be | |
162 | * either a String or a Buffer, so just use its type. | |
163 | */ | |
4be44fcd LB |
164 | return_desc = |
165 | acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE | |
166 | (operand[0])); | |
1da177e4 LT |
167 | if (!return_desc) { |
168 | status = AE_NO_MEMORY; | |
169 | goto cleanup; | |
170 | } | |
171 | ||
172 | /* Get the Integer values from the objects */ | |
173 | ||
44f6c012 | 174 | index = operand[1]->integer.value; |
1da177e4 LT |
175 | length = (acpi_size) operand[2]->integer.value; |
176 | ||
177 | /* | |
178 | * If the index is beyond the length of the String/Buffer, or if the | |
179 | * requested length is zero, return a zero-length String/Buffer | |
180 | */ | |
73459f73 RM |
181 | if (index >= operand[0]->string.length) { |
182 | length = 0; | |
183 | } | |
184 | ||
185 | /* Truncate request if larger than the actual String/Buffer */ | |
186 | ||
187 | else if ((index + length) > operand[0]->string.length) { | |
188 | length = (acpi_size) operand[0]->string.length - | |
4be44fcd | 189 | (acpi_size) index; |
73459f73 | 190 | } |
1da177e4 | 191 | |
73459f73 RM |
192 | /* Strings always have a sub-pointer, not so for buffers */ |
193 | ||
4be44fcd | 194 | switch (ACPI_GET_OBJECT_TYPE(operand[0])) { |
73459f73 RM |
195 | case ACPI_TYPE_STRING: |
196 | ||
197 | /* Always allocate a new buffer for the String */ | |
1da177e4 | 198 | |
8313524a | 199 | buffer = ACPI_ALLOCATE_ZEROED((acpi_size) length + 1); |
1da177e4 LT |
200 | if (!buffer) { |
201 | status = AE_NO_MEMORY; | |
202 | goto cleanup; | |
203 | } | |
73459f73 RM |
204 | break; |
205 | ||
206 | case ACPI_TYPE_BUFFER: | |
207 | ||
208 | /* If the requested length is zero, don't allocate a buffer */ | |
209 | ||
210 | if (length > 0) { | |
52fc0b02 | 211 | |
73459f73 RM |
212 | /* Allocate a new buffer for the Buffer */ |
213 | ||
8313524a | 214 | buffer = ACPI_ALLOCATE_ZEROED(length); |
73459f73 RM |
215 | if (!buffer) { |
216 | status = AE_NO_MEMORY; | |
217 | goto cleanup; | |
218 | } | |
219 | } | |
220 | break; | |
1da177e4 | 221 | |
4be44fcd | 222 | default: /* Should not happen */ |
73459f73 RM |
223 | |
224 | status = AE_AML_OPERAND_TYPE; | |
225 | goto cleanup; | |
226 | } | |
227 | ||
defba1d8 | 228 | if (buffer) { |
52fc0b02 | 229 | |
defba1d8 | 230 | /* We have a buffer, copy the portion requested */ |
1da177e4 | 231 | |
4be44fcd LB |
232 | ACPI_MEMCPY(buffer, operand[0]->string.pointer + index, |
233 | length); | |
73459f73 | 234 | } |
1da177e4 | 235 | |
73459f73 | 236 | /* Set the length of the new String/Buffer */ |
1da177e4 | 237 | |
73459f73 RM |
238 | return_desc->string.pointer = buffer; |
239 | return_desc->string.length = (u32) length; | |
1da177e4 LT |
240 | |
241 | /* Mark buffer initialized */ | |
242 | ||
243 | return_desc->buffer.flags |= AOPOBJ_DATA_VALID; | |
244 | break; | |
245 | ||
1da177e4 LT |
246 | default: |
247 | ||
b8e4d893 BM |
248 | ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", |
249 | walk_state->opcode)); | |
1da177e4 LT |
250 | status = AE_AML_BAD_OPCODE; |
251 | goto cleanup; | |
252 | } | |
253 | ||
254 | /* Store the result in the target */ | |
255 | ||
4be44fcd | 256 | status = acpi_ex_store(return_desc, operand[3], walk_state); |
1da177e4 | 257 | |
4be44fcd | 258 | cleanup: |
1da177e4 LT |
259 | |
260 | /* Delete return object on error */ | |
261 | ||
4be44fcd LB |
262 | if (ACPI_FAILURE(status) || walk_state->result_obj) { |
263 | acpi_ut_remove_reference(return_desc); | |
4b6e16cf | 264 | walk_state->result_obj = NULL; |
1da177e4 LT |
265 | } |
266 | ||
267 | /* Set the return object and exit */ | |
268 | ||
73459f73 | 269 | else { |
1da177e4 LT |
270 | walk_state->result_obj = return_desc; |
271 | } | |
4be44fcd | 272 | return_ACPI_STATUS(status); |
1da177e4 | 273 | } |