exoparg1.c revision 1.1.1.16 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: exoparg1 - AML execution - opcodes with 1 argument
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.16 christos * Copyright (C) 2000 - 2022, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.14 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acparser.h"
47 1.1 jruoho #include "acdispat.h"
48 1.1 jruoho #include "acinterp.h"
49 1.1 jruoho #include "amlcode.h"
50 1.1 jruoho #include "acnamesp.h"
51 1.1 jruoho
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
54 1.1 jruoho ACPI_MODULE_NAME ("exoparg1")
55 1.1 jruoho
56 1.1 jruoho
57 1.1 jruoho /*!
58 1.1 jruoho * Naming convention for AML interpreter execution routines.
59 1.1 jruoho *
60 1.1 jruoho * The routines that begin execution of AML opcodes are named with a common
61 1.1 jruoho * convention based upon the number of arguments, the number of target operands,
62 1.1 jruoho * and whether or not a value is returned:
63 1.1 jruoho *
64 1.1 jruoho * AcpiExOpcode_xA_yT_zR
65 1.1 jruoho *
66 1.1 jruoho * Where:
67 1.1 jruoho *
68 1.1 jruoho * xA - ARGUMENTS: The number of arguments (input operands) that are
69 1.1 jruoho * required for this opcode type (0 through 6 args).
70 1.1 jruoho * yT - TARGETS: The number of targets (output operands) that are required
71 1.1 jruoho * for this opcode type (0, 1, or 2 targets).
72 1.1 jruoho * zR - RETURN VALUE: Indicates whether this opcode type returns a value
73 1.1 jruoho * as the function return (0 or 1).
74 1.1 jruoho *
75 1.1 jruoho * The AcpiExOpcode* functions are called via the Dispatcher component with
76 1.1 jruoho * fully resolved operands.
77 1.1 jruoho !*/
78 1.1 jruoho
79 1.1 jruoho /*******************************************************************************
80 1.1 jruoho *
81 1.1 jruoho * FUNCTION: AcpiExOpcode_0A_0T_1R
82 1.1 jruoho *
83 1.1 jruoho * PARAMETERS: WalkState - Current state (contains AML opcode)
84 1.1 jruoho *
85 1.1 jruoho * RETURN: Status
86 1.1 jruoho *
87 1.1 jruoho * DESCRIPTION: Execute operator with no operands, one return value
88 1.1 jruoho *
89 1.1 jruoho ******************************************************************************/
90 1.1 jruoho
91 1.1 jruoho ACPI_STATUS
92 1.1 jruoho AcpiExOpcode_0A_0T_1R (
93 1.1 jruoho ACPI_WALK_STATE *WalkState)
94 1.1 jruoho {
95 1.1 jruoho ACPI_STATUS Status = AE_OK;
96 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
97 1.1 jruoho
98 1.1 jruoho
99 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R,
100 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
101 1.1 jruoho
102 1.1 jruoho
103 1.1 jruoho /* Examine the AML opcode */
104 1.1 jruoho
105 1.1 jruoho switch (WalkState->Opcode)
106 1.1 jruoho {
107 1.1 jruoho case AML_TIMER_OP: /* Timer () */
108 1.1 jruoho
109 1.1 jruoho /* Create a return object of type Integer */
110 1.1 jruoho
111 1.1 jruoho ReturnDesc = AcpiUtCreateIntegerObject (AcpiOsGetTimer ());
112 1.1 jruoho if (!ReturnDesc)
113 1.1 jruoho {
114 1.1 jruoho Status = AE_NO_MEMORY;
115 1.1 jruoho goto Cleanup;
116 1.1 jruoho }
117 1.1 jruoho break;
118 1.1 jruoho
119 1.1 jruoho default: /* Unknown opcode */
120 1.1 jruoho
121 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
122 1.1 jruoho WalkState->Opcode));
123 1.1 jruoho Status = AE_AML_BAD_OPCODE;
124 1.1 jruoho break;
125 1.1 jruoho }
126 1.1 jruoho
127 1.1 jruoho Cleanup:
128 1.1 jruoho
129 1.1 jruoho /* Delete return object on error */
130 1.1 jruoho
131 1.1 jruoho if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
132 1.1 jruoho {
133 1.1 jruoho AcpiUtRemoveReference (ReturnDesc);
134 1.1 jruoho WalkState->ResultObj = NULL;
135 1.1 jruoho }
136 1.1 jruoho else
137 1.1 jruoho {
138 1.1 jruoho /* Save the return value */
139 1.1 jruoho
140 1.1 jruoho WalkState->ResultObj = ReturnDesc;
141 1.1 jruoho }
142 1.1 jruoho
143 1.1 jruoho return_ACPI_STATUS (Status);
144 1.1 jruoho }
145 1.1 jruoho
146 1.1 jruoho
147 1.1 jruoho /*******************************************************************************
148 1.1 jruoho *
149 1.1 jruoho * FUNCTION: AcpiExOpcode_1A_0T_0R
150 1.1 jruoho *
151 1.1 jruoho * PARAMETERS: WalkState - Current state (contains AML opcode)
152 1.1 jruoho *
153 1.1 jruoho * RETURN: Status
154 1.1 jruoho *
155 1.1 jruoho * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
156 1.1 jruoho * object stack
157 1.1 jruoho *
158 1.1 jruoho ******************************************************************************/
159 1.1 jruoho
160 1.1 jruoho ACPI_STATUS
161 1.1 jruoho AcpiExOpcode_1A_0T_0R (
162 1.1 jruoho ACPI_WALK_STATE *WalkState)
163 1.1 jruoho {
164 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
165 1.1 jruoho ACPI_STATUS Status = AE_OK;
166 1.1 jruoho
167 1.1 jruoho
168 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_0R,
169 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
170 1.1 jruoho
171 1.1 jruoho
172 1.1 jruoho /* Examine the AML opcode */
173 1.1 jruoho
174 1.1 jruoho switch (WalkState->Opcode)
175 1.1 jruoho {
176 1.1 jruoho case AML_RELEASE_OP: /* Release (MutexObject) */
177 1.1 jruoho
178 1.1 jruoho Status = AcpiExReleaseMutex (Operand[0], WalkState);
179 1.1 jruoho break;
180 1.1 jruoho
181 1.1 jruoho case AML_RESET_OP: /* Reset (EventObject) */
182 1.1 jruoho
183 1.1 jruoho Status = AcpiExSystemResetEvent (Operand[0]);
184 1.1 jruoho break;
185 1.1 jruoho
186 1.1 jruoho case AML_SIGNAL_OP: /* Signal (EventObject) */
187 1.1 jruoho
188 1.1 jruoho Status = AcpiExSystemSignalEvent (Operand[0]);
189 1.1 jruoho break;
190 1.1 jruoho
191 1.1 jruoho case AML_SLEEP_OP: /* Sleep (MsecTime) */
192 1.1 jruoho
193 1.1 jruoho Status = AcpiExSystemDoSleep (Operand[0]->Integer.Value);
194 1.1 jruoho break;
195 1.1 jruoho
196 1.1 jruoho case AML_STALL_OP: /* Stall (UsecTime) */
197 1.1 jruoho
198 1.1 jruoho Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
199 1.1 jruoho break;
200 1.1 jruoho
201 1.1 jruoho case AML_UNLOAD_OP: /* Unload (Handle) */
202 1.1 jruoho
203 1.1 jruoho Status = AcpiExUnloadTable (Operand[0]);
204 1.1 jruoho break;
205 1.1 jruoho
206 1.1 jruoho default: /* Unknown opcode */
207 1.1 jruoho
208 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
209 1.1 jruoho WalkState->Opcode));
210 1.1 jruoho Status = AE_AML_BAD_OPCODE;
211 1.1 jruoho break;
212 1.1 jruoho }
213 1.1 jruoho
214 1.1 jruoho return_ACPI_STATUS (Status);
215 1.1 jruoho }
216 1.1 jruoho
217 1.1 jruoho
218 1.1.1.16 christos #ifdef _OBSOLETE_CODE /* Was originally used for Load() operator */
219 1.1 jruoho /*******************************************************************************
220 1.1 jruoho *
221 1.1 jruoho * FUNCTION: AcpiExOpcode_1A_1T_0R
222 1.1 jruoho *
223 1.1 jruoho * PARAMETERS: WalkState - Current state (contains AML opcode)
224 1.1 jruoho *
225 1.1 jruoho * RETURN: Status
226 1.1 jruoho *
227 1.1 jruoho * DESCRIPTION: Execute opcode with one argument, one target, and no
228 1.1 jruoho * return value.
229 1.1 jruoho *
230 1.1 jruoho ******************************************************************************/
231 1.1 jruoho
232 1.1 jruoho ACPI_STATUS
233 1.1 jruoho AcpiExOpcode_1A_1T_0R (
234 1.1 jruoho ACPI_WALK_STATE *WalkState)
235 1.1 jruoho {
236 1.1 jruoho ACPI_STATUS Status = AE_OK;
237 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
238 1.1 jruoho
239 1.1 jruoho
240 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_0R,
241 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
242 1.1 jruoho
243 1.1 jruoho
244 1.1 jruoho /* Examine the AML opcode */
245 1.1 jruoho
246 1.1 jruoho switch (WalkState->Opcode)
247 1.1 jruoho {
248 1.1.1.16 christos #ifdef _OBSOLETE_CODE
249 1.1 jruoho case AML_LOAD_OP:
250 1.1 jruoho
251 1.1 jruoho Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
252 1.1 jruoho break;
253 1.1.1.16 christos #endif
254 1.1 jruoho
255 1.1 jruoho default: /* Unknown opcode */
256 1.1 jruoho
257 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
258 1.1 jruoho WalkState->Opcode));
259 1.1 jruoho Status = AE_AML_BAD_OPCODE;
260 1.1 jruoho goto Cleanup;
261 1.1 jruoho }
262 1.1 jruoho
263 1.1 jruoho
264 1.1 jruoho Cleanup:
265 1.1 jruoho
266 1.1 jruoho return_ACPI_STATUS (Status);
267 1.1 jruoho }
268 1.1.1.16 christos #endif
269 1.1 jruoho
270 1.1 jruoho /*******************************************************************************
271 1.1 jruoho *
272 1.1 jruoho * FUNCTION: AcpiExOpcode_1A_1T_1R
273 1.1 jruoho *
274 1.1 jruoho * PARAMETERS: WalkState - Current state (contains AML opcode)
275 1.1 jruoho *
276 1.1 jruoho * RETURN: Status
277 1.1 jruoho *
278 1.1 jruoho * DESCRIPTION: Execute opcode with one argument, one target, and a
279 1.1 jruoho * return value.
280 1.1.1.16 christos * January 2022: Added Load operator, with new ACPI 6.4
281 1.1.1.16 christos * semantics.
282 1.1 jruoho *
283 1.1 jruoho ******************************************************************************/
284 1.1 jruoho
285 1.1 jruoho ACPI_STATUS
286 1.1 jruoho AcpiExOpcode_1A_1T_1R (
287 1.1 jruoho ACPI_WALK_STATE *WalkState)
288 1.1 jruoho {
289 1.1 jruoho ACPI_STATUS Status = AE_OK;
290 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
291 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
292 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
293 1.1 jruoho UINT32 Temp32;
294 1.1 jruoho UINT32 i;
295 1.1 jruoho UINT64 PowerOfTen;
296 1.1 jruoho UINT64 Digit;
297 1.1 jruoho
298 1.1 jruoho
299 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_1R,
300 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
301 1.1 jruoho
302 1.1 jruoho
303 1.1 jruoho /* Examine the AML opcode */
304 1.1 jruoho
305 1.1 jruoho switch (WalkState->Opcode)
306 1.1 jruoho {
307 1.1 jruoho case AML_BIT_NOT_OP:
308 1.1 jruoho case AML_FIND_SET_LEFT_BIT_OP:
309 1.1 jruoho case AML_FIND_SET_RIGHT_BIT_OP:
310 1.1 jruoho case AML_FROM_BCD_OP:
311 1.1.1.16 christos case AML_LOAD_OP:
312 1.1 jruoho case AML_TO_BCD_OP:
313 1.1.1.9 christos case AML_CONDITIONAL_REF_OF_OP:
314 1.1 jruoho
315 1.1 jruoho /* Create a return object of type Integer for these opcodes */
316 1.1 jruoho
317 1.1 jruoho ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
318 1.1 jruoho if (!ReturnDesc)
319 1.1 jruoho {
320 1.1 jruoho Status = AE_NO_MEMORY;
321 1.1 jruoho goto Cleanup;
322 1.1 jruoho }
323 1.1 jruoho
324 1.1 jruoho switch (WalkState->Opcode)
325 1.1 jruoho {
326 1.1 jruoho case AML_BIT_NOT_OP: /* Not (Operand, Result) */
327 1.1 jruoho
328 1.1 jruoho ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
329 1.1 jruoho break;
330 1.1 jruoho
331 1.1 jruoho case AML_FIND_SET_LEFT_BIT_OP: /* FindSetLeftBit (Operand, Result) */
332 1.1 jruoho
333 1.1 jruoho ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
334 1.1 jruoho
335 1.1 jruoho /*
336 1.1 jruoho * Acpi specification describes Integer type as a little
337 1.1 jruoho * endian unsigned value, so this boundary condition is valid.
338 1.1 jruoho */
339 1.1 jruoho for (Temp32 = 0; ReturnDesc->Integer.Value &&
340 1.1.1.6 christos Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
341 1.1 jruoho {
342 1.1 jruoho ReturnDesc->Integer.Value >>= 1;
343 1.1 jruoho }
344 1.1 jruoho
345 1.1 jruoho ReturnDesc->Integer.Value = Temp32;
346 1.1 jruoho break;
347 1.1 jruoho
348 1.1 jruoho case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
349 1.1 jruoho
350 1.1 jruoho ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
351 1.1 jruoho
352 1.1 jruoho /*
353 1.1 jruoho * The Acpi specification describes Integer type as a little
354 1.1 jruoho * endian unsigned value, so this boundary condition is valid.
355 1.1 jruoho */
356 1.1 jruoho for (Temp32 = 0; ReturnDesc->Integer.Value &&
357 1.1.1.6 christos Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
358 1.1 jruoho {
359 1.1 jruoho ReturnDesc->Integer.Value <<= 1;
360 1.1 jruoho }
361 1.1 jruoho
362 1.1 jruoho /* Since the bit position is one-based, subtract from 33 (65) */
363 1.1 jruoho
364 1.1 jruoho ReturnDesc->Integer.Value =
365 1.1 jruoho Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
366 1.1 jruoho break;
367 1.1 jruoho
368 1.1 jruoho case AML_FROM_BCD_OP: /* FromBcd (BCDValue, Result) */
369 1.1 jruoho /*
370 1.1 jruoho * The 64-bit ACPI integer can hold 16 4-bit BCD characters
371 1.1 jruoho * (if table is 32-bit, integer can hold 8 BCD characters)
372 1.1 jruoho * Convert each 4-bit BCD value
373 1.1 jruoho */
374 1.1 jruoho PowerOfTen = 1;
375 1.1 jruoho ReturnDesc->Integer.Value = 0;
376 1.1 jruoho Digit = Operand[0]->Integer.Value;
377 1.1 jruoho
378 1.1 jruoho /* Convert each BCD digit (each is one nybble wide) */
379 1.1 jruoho
380 1.1 jruoho for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
381 1.1 jruoho {
382 1.1 jruoho /* Get the least significant 4-bit BCD digit */
383 1.1 jruoho
384 1.1 jruoho Temp32 = ((UINT32) Digit) & 0xF;
385 1.1 jruoho
386 1.1 jruoho /* Check the range of the digit */
387 1.1 jruoho
388 1.1 jruoho if (Temp32 > 9)
389 1.1 jruoho {
390 1.1 jruoho ACPI_ERROR ((AE_INFO,
391 1.1 jruoho "BCD digit too large (not decimal): 0x%X",
392 1.1 jruoho Temp32));
393 1.1 jruoho
394 1.1 jruoho Status = AE_AML_NUMERIC_OVERFLOW;
395 1.1 jruoho goto Cleanup;
396 1.1 jruoho }
397 1.1 jruoho
398 1.1 jruoho /* Sum the digit into the result with the current power of 10 */
399 1.1 jruoho
400 1.1 jruoho ReturnDesc->Integer.Value +=
401 1.1 jruoho (((UINT64) Temp32) * PowerOfTen);
402 1.1 jruoho
403 1.1 jruoho /* Shift to next BCD digit */
404 1.1 jruoho
405 1.1 jruoho Digit >>= 4;
406 1.1 jruoho
407 1.1 jruoho /* Next power of 10 */
408 1.1 jruoho
409 1.1 jruoho PowerOfTen *= 10;
410 1.1 jruoho }
411 1.1 jruoho break;
412 1.1 jruoho
413 1.1.1.16 christos case AML_LOAD_OP: /* Result1 = Load (Operand[0], Result1) */
414 1.1.1.16 christos
415 1.1.1.16 christos ReturnDesc->Integer.Value = 0;
416 1.1.1.16 christos Status = AcpiExLoadOp (Operand[0], ReturnDesc, WalkState);
417 1.1.1.16 christos if (ACPI_SUCCESS (Status))
418 1.1.1.16 christos {
419 1.1.1.16 christos /* Return -1 (non-zero) indicates success */
420 1.1.1.16 christos
421 1.1.1.16 christos ReturnDesc->Integer.Value = 0xFFFFFFFFFFFFFFFF;
422 1.1.1.16 christos }
423 1.1.1.16 christos break;
424 1.1.1.16 christos
425 1.1 jruoho case AML_TO_BCD_OP: /* ToBcd (Operand, Result) */
426 1.1 jruoho
427 1.1 jruoho ReturnDesc->Integer.Value = 0;
428 1.1 jruoho Digit = Operand[0]->Integer.Value;
429 1.1 jruoho
430 1.1 jruoho /* Each BCD digit is one nybble wide */
431 1.1 jruoho
432 1.1 jruoho for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
433 1.1 jruoho {
434 1.1 jruoho (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
435 1.1 jruoho
436 1.1 jruoho /*
437 1.1 jruoho * Insert the BCD digit that resides in the
438 1.1 jruoho * remainder from above
439 1.1 jruoho */
440 1.1 jruoho ReturnDesc->Integer.Value |=
441 1.1 jruoho (((UINT64) Temp32) << ACPI_MUL_4 (i));
442 1.1 jruoho }
443 1.1 jruoho
444 1.1 jruoho /* Overflow if there is any data left in Digit */
445 1.1 jruoho
446 1.1 jruoho if (Digit > 0)
447 1.1 jruoho {
448 1.1 jruoho ACPI_ERROR ((AE_INFO,
449 1.1 jruoho "Integer too large to convert to BCD: 0x%8.8X%8.8X",
450 1.1 jruoho ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
451 1.1 jruoho Status = AE_AML_NUMERIC_OVERFLOW;
452 1.1 jruoho goto Cleanup;
453 1.1 jruoho }
454 1.1 jruoho break;
455 1.1 jruoho
456 1.1.1.9 christos case AML_CONDITIONAL_REF_OF_OP: /* CondRefOf (SourceObject, Result) */
457 1.1 jruoho /*
458 1.1 jruoho * This op is a little strange because the internal return value is
459 1.1 jruoho * different than the return value stored in the result descriptor
460 1.1 jruoho * (There are really two return values)
461 1.1 jruoho */
462 1.1 jruoho if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
463 1.1 jruoho {
464 1.1 jruoho /*
465 1.1 jruoho * This means that the object does not exist in the namespace,
466 1.1 jruoho * return FALSE
467 1.1 jruoho */
468 1.1 jruoho ReturnDesc->Integer.Value = 0;
469 1.1 jruoho goto Cleanup;
470 1.1 jruoho }
471 1.1 jruoho
472 1.1 jruoho /* Get the object reference, store it, and remove our reference */
473 1.1 jruoho
474 1.1 jruoho Status = AcpiExGetObjectReference (Operand[0],
475 1.1.1.6 christos &ReturnDesc2, WalkState);
476 1.1 jruoho if (ACPI_FAILURE (Status))
477 1.1 jruoho {
478 1.1 jruoho goto Cleanup;
479 1.1 jruoho }
480 1.1 jruoho
481 1.1 jruoho Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
482 1.1 jruoho AcpiUtRemoveReference (ReturnDesc2);
483 1.1 jruoho
484 1.1 jruoho /* The object exists in the namespace, return TRUE */
485 1.1 jruoho
486 1.1 jruoho ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
487 1.1 jruoho goto Cleanup;
488 1.1 jruoho
489 1.1 jruoho
490 1.1 jruoho default:
491 1.1.1.3 christos
492 1.1 jruoho /* No other opcodes get here */
493 1.1.1.3 christos
494 1.1 jruoho break;
495 1.1 jruoho }
496 1.1 jruoho break;
497 1.1 jruoho
498 1.1 jruoho case AML_STORE_OP: /* Store (Source, Target) */
499 1.1 jruoho /*
500 1.1 jruoho * A store operand is typically a number, string, buffer or lvalue
501 1.1 jruoho * Be careful about deleting the source object,
502 1.1 jruoho * since the object itself may have been stored.
503 1.1 jruoho */
504 1.1 jruoho Status = AcpiExStore (Operand[0], Operand[1], WalkState);
505 1.1 jruoho if (ACPI_FAILURE (Status))
506 1.1 jruoho {
507 1.1 jruoho return_ACPI_STATUS (Status);
508 1.1 jruoho }
509 1.1 jruoho
510 1.1 jruoho /* It is possible that the Store already produced a return object */
511 1.1 jruoho
512 1.1 jruoho if (!WalkState->ResultObj)
513 1.1 jruoho {
514 1.1 jruoho /*
515 1.1 jruoho * Normally, we would remove a reference on the Operand[0]
516 1.1 jruoho * parameter; But since it is being used as the internal return
517 1.1 jruoho * object (meaning we would normally increment it), the two
518 1.1 jruoho * cancel out, and we simply don't do anything.
519 1.1 jruoho */
520 1.1 jruoho WalkState->ResultObj = Operand[0];
521 1.1 jruoho WalkState->Operands[0] = NULL; /* Prevent deletion */
522 1.1 jruoho }
523 1.1 jruoho return_ACPI_STATUS (Status);
524 1.1 jruoho
525 1.1 jruoho /*
526 1.1 jruoho * ACPI 2.0 Opcodes
527 1.1 jruoho */
528 1.1.1.9 christos case AML_COPY_OBJECT_OP: /* CopyObject (Source, Target) */
529 1.1 jruoho
530 1.1.1.6 christos Status = AcpiUtCopyIobjectToIobject (
531 1.1.1.6 christos Operand[0], &ReturnDesc, WalkState);
532 1.1 jruoho break;
533 1.1 jruoho
534 1.1.1.9 christos case AML_TO_DECIMAL_STRING_OP: /* ToDecimalString (Data, Result) */
535 1.1 jruoho
536 1.1.1.6 christos Status = AcpiExConvertToString (
537 1.1.1.6 christos Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_DECIMAL);
538 1.1 jruoho if (ReturnDesc == Operand[0])
539 1.1 jruoho {
540 1.1 jruoho /* No conversion performed, add ref to handle return value */
541 1.1.1.6 christos
542 1.1 jruoho AcpiUtAddReference (ReturnDesc);
543 1.1 jruoho }
544 1.1 jruoho break;
545 1.1 jruoho
546 1.1.1.9 christos case AML_TO_HEX_STRING_OP: /* ToHexString (Data, Result) */
547 1.1 jruoho
548 1.1.1.6 christos Status = AcpiExConvertToString (
549 1.1.1.6 christos Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_HEX);
550 1.1 jruoho if (ReturnDesc == Operand[0])
551 1.1 jruoho {
552 1.1 jruoho /* No conversion performed, add ref to handle return value */
553 1.1.1.6 christos
554 1.1 jruoho AcpiUtAddReference (ReturnDesc);
555 1.1 jruoho }
556 1.1 jruoho break;
557 1.1 jruoho
558 1.1 jruoho case AML_TO_BUFFER_OP: /* ToBuffer (Data, Result) */
559 1.1 jruoho
560 1.1 jruoho Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
561 1.1 jruoho if (ReturnDesc == Operand[0])
562 1.1 jruoho {
563 1.1 jruoho /* No conversion performed, add ref to handle return value */
564 1.1.1.6 christos
565 1.1 jruoho AcpiUtAddReference (ReturnDesc);
566 1.1 jruoho }
567 1.1 jruoho break;
568 1.1 jruoho
569 1.1 jruoho case AML_TO_INTEGER_OP: /* ToInteger (Data, Result) */
570 1.1 jruoho
571 1.1.1.7 christos /* Perform "explicit" conversion */
572 1.1.1.7 christos
573 1.1.1.7 christos Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc, 0);
574 1.1 jruoho if (ReturnDesc == Operand[0])
575 1.1 jruoho {
576 1.1 jruoho /* No conversion performed, add ref to handle return value */
577 1.1.1.6 christos
578 1.1 jruoho AcpiUtAddReference (ReturnDesc);
579 1.1 jruoho }
580 1.1 jruoho break;
581 1.1 jruoho
582 1.1 jruoho case AML_SHIFT_LEFT_BIT_OP: /* ShiftLeftBit (Source, BitNum) */
583 1.1 jruoho case AML_SHIFT_RIGHT_BIT_OP: /* ShiftRightBit (Source, BitNum) */
584 1.1 jruoho
585 1.1 jruoho /* These are two obsolete opcodes */
586 1.1 jruoho
587 1.1 jruoho ACPI_ERROR ((AE_INFO,
588 1.1 jruoho "%s is obsolete and not implemented",
589 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode)));
590 1.1 jruoho Status = AE_SUPPORT;
591 1.1 jruoho goto Cleanup;
592 1.1 jruoho
593 1.1 jruoho default: /* Unknown opcode */
594 1.1 jruoho
595 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
596 1.1 jruoho WalkState->Opcode));
597 1.1 jruoho Status = AE_AML_BAD_OPCODE;
598 1.1 jruoho goto Cleanup;
599 1.1 jruoho }
600 1.1 jruoho
601 1.1 jruoho if (ACPI_SUCCESS (Status))
602 1.1 jruoho {
603 1.1 jruoho /* Store the return value computed above into the target object */
604 1.1 jruoho
605 1.1 jruoho Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
606 1.1 jruoho }
607 1.1 jruoho
608 1.1 jruoho
609 1.1 jruoho Cleanup:
610 1.1 jruoho
611 1.1 jruoho /* Delete return object on error */
612 1.1 jruoho
613 1.1 jruoho if (ACPI_FAILURE (Status))
614 1.1 jruoho {
615 1.1 jruoho AcpiUtRemoveReference (ReturnDesc);
616 1.1 jruoho }
617 1.1 jruoho
618 1.1 jruoho /* Save return object on success */
619 1.1 jruoho
620 1.1 jruoho else if (!WalkState->ResultObj)
621 1.1 jruoho {
622 1.1 jruoho WalkState->ResultObj = ReturnDesc;
623 1.1 jruoho }
624 1.1 jruoho
625 1.1 jruoho return_ACPI_STATUS (Status);
626 1.1 jruoho }
627 1.1 jruoho
628 1.1 jruoho
629 1.1 jruoho /*******************************************************************************
630 1.1 jruoho *
631 1.1 jruoho * FUNCTION: AcpiExOpcode_1A_0T_1R
632 1.1 jruoho *
633 1.1 jruoho * PARAMETERS: WalkState - Current state (contains AML opcode)
634 1.1 jruoho *
635 1.1 jruoho * RETURN: Status
636 1.1 jruoho *
637 1.1 jruoho * DESCRIPTION: Execute opcode with one argument, no target, and a return value
638 1.1 jruoho *
639 1.1 jruoho ******************************************************************************/
640 1.1 jruoho
641 1.1 jruoho ACPI_STATUS
642 1.1 jruoho AcpiExOpcode_1A_0T_1R (
643 1.1 jruoho ACPI_WALK_STATE *WalkState)
644 1.1 jruoho {
645 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
646 1.1 jruoho ACPI_OPERAND_OBJECT *TempDesc;
647 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
648 1.1 jruoho ACPI_STATUS Status = AE_OK;
649 1.1 jruoho UINT32 Type;
650 1.1 jruoho UINT64 Value;
651 1.1 jruoho
652 1.1 jruoho
653 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R,
654 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
655 1.1 jruoho
656 1.1 jruoho
657 1.1 jruoho /* Examine the AML opcode */
658 1.1 jruoho
659 1.1 jruoho switch (WalkState->Opcode)
660 1.1 jruoho {
661 1.1.1.9 christos case AML_LOGICAL_NOT_OP: /* LNot (Operand) */
662 1.1 jruoho
663 1.1 jruoho ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
664 1.1 jruoho if (!ReturnDesc)
665 1.1 jruoho {
666 1.1 jruoho Status = AE_NO_MEMORY;
667 1.1 jruoho goto Cleanup;
668 1.1 jruoho }
669 1.1 jruoho
670 1.1 jruoho /*
671 1.1.1.3 christos * Set result to ONES (TRUE) if Value == 0. Note:
672 1.1 jruoho * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
673 1.1 jruoho */
674 1.1 jruoho if (!Operand[0]->Integer.Value)
675 1.1 jruoho {
676 1.1 jruoho ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
677 1.1 jruoho }
678 1.1 jruoho break;
679 1.1 jruoho
680 1.1 jruoho case AML_DECREMENT_OP: /* Decrement (Operand) */
681 1.1 jruoho case AML_INCREMENT_OP: /* Increment (Operand) */
682 1.1 jruoho /*
683 1.1.1.3 christos * Create a new integer. Can't just get the base integer and
684 1.1 jruoho * increment it because it may be an Arg or Field.
685 1.1 jruoho */
686 1.1 jruoho ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
687 1.1 jruoho if (!ReturnDesc)
688 1.1 jruoho {
689 1.1 jruoho Status = AE_NO_MEMORY;
690 1.1 jruoho goto Cleanup;
691 1.1 jruoho }
692 1.1 jruoho
693 1.1 jruoho /*
694 1.1 jruoho * Since we are expecting a Reference operand, it can be either a
695 1.1 jruoho * NS Node or an internal object.
696 1.1 jruoho */
697 1.1 jruoho TempDesc = Operand[0];
698 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
699 1.1 jruoho {
700 1.1 jruoho /* Internal reference object - prevent deletion */
701 1.1 jruoho
702 1.1 jruoho AcpiUtAddReference (TempDesc);
703 1.1 jruoho }
704 1.1 jruoho
705 1.1 jruoho /*
706 1.1 jruoho * Convert the Reference operand to an Integer (This removes a
707 1.1 jruoho * reference on the Operand[0] object)
708 1.1 jruoho *
709 1.1 jruoho * NOTE: We use LNOT_OP here in order to force resolution of the
710 1.1 jruoho * reference operand to an actual integer.
711 1.1 jruoho */
712 1.1.1.9 christos Status = AcpiExResolveOperands (AML_LOGICAL_NOT_OP,
713 1.1.1.9 christos &TempDesc, WalkState);
714 1.1 jruoho if (ACPI_FAILURE (Status))
715 1.1 jruoho {
716 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
717 1.1 jruoho "While resolving operands for [%s]",
718 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode)));
719 1.1 jruoho
720 1.1 jruoho goto Cleanup;
721 1.1 jruoho }
722 1.1 jruoho
723 1.1 jruoho /*
724 1.1 jruoho * TempDesc is now guaranteed to be an Integer object --
725 1.1 jruoho * Perform the actual increment or decrement
726 1.1 jruoho */
727 1.1 jruoho if (WalkState->Opcode == AML_INCREMENT_OP)
728 1.1 jruoho {
729 1.1.1.6 christos ReturnDesc->Integer.Value = TempDesc->Integer.Value + 1;
730 1.1 jruoho }
731 1.1 jruoho else
732 1.1 jruoho {
733 1.1.1.6 christos ReturnDesc->Integer.Value = TempDesc->Integer.Value - 1;
734 1.1 jruoho }
735 1.1 jruoho
736 1.1 jruoho /* Finished with this Integer object */
737 1.1 jruoho
738 1.1 jruoho AcpiUtRemoveReference (TempDesc);
739 1.1 jruoho
740 1.1 jruoho /*
741 1.1 jruoho * Store the result back (indirectly) through the original
742 1.1 jruoho * Reference object
743 1.1 jruoho */
744 1.1 jruoho Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
745 1.1 jruoho break;
746 1.1 jruoho
747 1.1.1.6 christos case AML_OBJECT_TYPE_OP: /* ObjectType (SourceObject) */
748 1.1 jruoho /*
749 1.1 jruoho * Note: The operand is not resolved at this point because we want to
750 1.1.1.3 christos * get the associated object, not its value. For example, we don't
751 1.1 jruoho * want to resolve a FieldUnit to its value, we want the actual
752 1.1 jruoho * FieldUnit object.
753 1.1 jruoho */
754 1.1 jruoho
755 1.1 jruoho /* Get the type of the base object */
756 1.1 jruoho
757 1.1 jruoho Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
758 1.1 jruoho if (ACPI_FAILURE (Status))
759 1.1 jruoho {
760 1.1 jruoho goto Cleanup;
761 1.1 jruoho }
762 1.1 jruoho
763 1.1 jruoho /* Allocate a descriptor to hold the type. */
764 1.1 jruoho
765 1.1 jruoho ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) Type);
766 1.1 jruoho if (!ReturnDesc)
767 1.1 jruoho {
768 1.1 jruoho Status = AE_NO_MEMORY;
769 1.1 jruoho goto Cleanup;
770 1.1 jruoho }
771 1.1 jruoho break;
772 1.1 jruoho
773 1.1 jruoho case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */
774 1.1 jruoho /*
775 1.1 jruoho * Note: The operand is not resolved at this point because we want to
776 1.1 jruoho * get the associated object, not its value.
777 1.1 jruoho */
778 1.1 jruoho
779 1.1 jruoho /* Get the base object */
780 1.1 jruoho
781 1.1.1.6 christos Status = AcpiExResolveMultiple (
782 1.1.1.6 christos WalkState, Operand[0], &Type, &TempDesc);
783 1.1 jruoho if (ACPI_FAILURE (Status))
784 1.1 jruoho {
785 1.1 jruoho goto Cleanup;
786 1.1 jruoho }
787 1.1 jruoho
788 1.1 jruoho /*
789 1.1 jruoho * The type of the base object must be integer, buffer, string, or
790 1.1.1.3 christos * package. All others are not supported.
791 1.1 jruoho *
792 1.1 jruoho * NOTE: Integer is not specifically supported by the ACPI spec,
793 1.1 jruoho * but is supported implicitly via implicit operand conversion.
794 1.1 jruoho * rather than bother with conversion, we just use the byte width
795 1.1 jruoho * global (4 or 8 bytes).
796 1.1 jruoho */
797 1.1 jruoho switch (Type)
798 1.1 jruoho {
799 1.1 jruoho case ACPI_TYPE_INTEGER:
800 1.1.1.3 christos
801 1.1 jruoho Value = AcpiGbl_IntegerByteWidth;
802 1.1 jruoho break;
803 1.1 jruoho
804 1.1 jruoho case ACPI_TYPE_STRING:
805 1.1.1.3 christos
806 1.1 jruoho Value = TempDesc->String.Length;
807 1.1 jruoho break;
808 1.1 jruoho
809 1.1 jruoho case ACPI_TYPE_BUFFER:
810 1.1 jruoho
811 1.1 jruoho /* Buffer arguments may not be evaluated at this point */
812 1.1 jruoho
813 1.1 jruoho Status = AcpiDsGetBufferArguments (TempDesc);
814 1.1 jruoho Value = TempDesc->Buffer.Length;
815 1.1 jruoho break;
816 1.1 jruoho
817 1.1 jruoho case ACPI_TYPE_PACKAGE:
818 1.1 jruoho
819 1.1 jruoho /* Package arguments may not be evaluated at this point */
820 1.1 jruoho
821 1.1 jruoho Status = AcpiDsGetPackageArguments (TempDesc);
822 1.1 jruoho Value = TempDesc->Package.Count;
823 1.1 jruoho break;
824 1.1 jruoho
825 1.1 jruoho default:
826 1.1.1.3 christos
827 1.1 jruoho ACPI_ERROR ((AE_INFO,
828 1.1.1.6 christos "Operand must be Buffer/Integer/String/Package"
829 1.1.1.6 christos " - found type %s",
830 1.1 jruoho AcpiUtGetTypeName (Type)));
831 1.1.1.6 christos
832 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
833 1.1 jruoho goto Cleanup;
834 1.1 jruoho }
835 1.1 jruoho
836 1.1 jruoho if (ACPI_FAILURE (Status))
837 1.1 jruoho {
838 1.1 jruoho goto Cleanup;
839 1.1 jruoho }
840 1.1 jruoho
841 1.1 jruoho /*
842 1.1 jruoho * Now that we have the size of the object, create a result
843 1.1 jruoho * object to hold the value
844 1.1 jruoho */
845 1.1 jruoho ReturnDesc = AcpiUtCreateIntegerObject (Value);
846 1.1 jruoho if (!ReturnDesc)
847 1.1 jruoho {
848 1.1 jruoho Status = AE_NO_MEMORY;
849 1.1 jruoho goto Cleanup;
850 1.1 jruoho }
851 1.1 jruoho break;
852 1.1 jruoho
853 1.1 jruoho
854 1.1 jruoho case AML_REF_OF_OP: /* RefOf (SourceObject) */
855 1.1 jruoho
856 1.1.1.6 christos Status = AcpiExGetObjectReference (
857 1.1.1.6 christos Operand[0], &ReturnDesc, WalkState);
858 1.1 jruoho if (ACPI_FAILURE (Status))
859 1.1 jruoho {
860 1.1 jruoho goto Cleanup;
861 1.1 jruoho }
862 1.1 jruoho break;
863 1.1 jruoho
864 1.1 jruoho
865 1.1 jruoho case AML_DEREF_OF_OP: /* DerefOf (ObjReference | String) */
866 1.1 jruoho
867 1.1 jruoho /* Check for a method local or argument, or standalone String */
868 1.1 jruoho
869 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
870 1.1 jruoho {
871 1.1 jruoho TempDesc = AcpiNsGetAttachedObject (
872 1.1.1.10 christos (ACPI_NAMESPACE_NODE *) Operand[0]);
873 1.1 jruoho if (TempDesc &&
874 1.1 jruoho ((TempDesc->Common.Type == ACPI_TYPE_STRING) ||
875 1.1 jruoho (TempDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)))
876 1.1 jruoho {
877 1.1 jruoho Operand[0] = TempDesc;
878 1.1 jruoho AcpiUtAddReference (TempDesc);
879 1.1 jruoho }
880 1.1 jruoho else
881 1.1 jruoho {
882 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
883 1.1 jruoho goto Cleanup;
884 1.1 jruoho }
885 1.1 jruoho }
886 1.1 jruoho else
887 1.1 jruoho {
888 1.1 jruoho switch ((Operand[0])->Common.Type)
889 1.1 jruoho {
890 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
891 1.1 jruoho /*
892 1.1 jruoho * This is a DerefOf (LocalX | ArgX)
893 1.1 jruoho *
894 1.1 jruoho * Must resolve/dereference the local/arg reference first
895 1.1 jruoho */
896 1.1 jruoho switch (Operand[0]->Reference.Class)
897 1.1 jruoho {
898 1.1 jruoho case ACPI_REFCLASS_LOCAL:
899 1.1 jruoho case ACPI_REFCLASS_ARG:
900 1.1 jruoho
901 1.1 jruoho /* Set Operand[0] to the value of the local/arg */
902 1.1 jruoho
903 1.1 jruoho Status = AcpiDsMethodDataGetValue (
904 1.1.1.6 christos Operand[0]->Reference.Class,
905 1.1.1.6 christos Operand[0]->Reference.Value,
906 1.1.1.6 christos WalkState, &TempDesc);
907 1.1 jruoho if (ACPI_FAILURE (Status))
908 1.1 jruoho {
909 1.1 jruoho goto Cleanup;
910 1.1 jruoho }
911 1.1 jruoho
912 1.1 jruoho /*
913 1.1 jruoho * Delete our reference to the input object and
914 1.1 jruoho * point to the object just retrieved
915 1.1 jruoho */
916 1.1 jruoho AcpiUtRemoveReference (Operand[0]);
917 1.1 jruoho Operand[0] = TempDesc;
918 1.1 jruoho break;
919 1.1 jruoho
920 1.1 jruoho case ACPI_REFCLASS_REFOF:
921 1.1 jruoho
922 1.1 jruoho /* Get the object to which the reference refers */
923 1.1 jruoho
924 1.1 jruoho TempDesc = Operand[0]->Reference.Object;
925 1.1 jruoho AcpiUtRemoveReference (Operand[0]);
926 1.1 jruoho Operand[0] = TempDesc;
927 1.1 jruoho break;
928 1.1 jruoho
929 1.1 jruoho default:
930 1.1 jruoho
931 1.1 jruoho /* Must be an Index op - handled below */
932 1.1 jruoho break;
933 1.1 jruoho }
934 1.1 jruoho break;
935 1.1 jruoho
936 1.1 jruoho case ACPI_TYPE_STRING:
937 1.1.1.3 christos
938 1.1 jruoho break;
939 1.1 jruoho
940 1.1 jruoho default:
941 1.1.1.3 christos
942 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
943 1.1 jruoho goto Cleanup;
944 1.1 jruoho }
945 1.1 jruoho }
946 1.1 jruoho
947 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
948 1.1 jruoho {
949 1.1 jruoho if ((Operand[0])->Common.Type == ACPI_TYPE_STRING)
950 1.1 jruoho {
951 1.1 jruoho /*
952 1.1 jruoho * This is a DerefOf (String). The string is a reference
953 1.1 jruoho * to a named ACPI object.
954 1.1 jruoho *
955 1.1 jruoho * 1) Find the owning Node
956 1.1 jruoho * 2) Dereference the node to an actual object. Could be a
957 1.1 jruoho * Field, so we need to resolve the node to a value.
958 1.1 jruoho */
959 1.1.1.7 christos Status = AcpiNsGetNodeUnlocked (WalkState->ScopeInfo->Scope.Node,
960 1.1.1.6 christos Operand[0]->String.Pointer,
961 1.1.1.6 christos ACPI_NS_SEARCH_PARENT,
962 1.1.1.6 christos ACPI_CAST_INDIRECT_PTR (
963 1.1.1.6 christos ACPI_NAMESPACE_NODE, &ReturnDesc));
964 1.1 jruoho if (ACPI_FAILURE (Status))
965 1.1 jruoho {
966 1.1 jruoho goto Cleanup;
967 1.1 jruoho }
968 1.1 jruoho
969 1.1 jruoho Status = AcpiExResolveNodeToValue (
970 1.1.1.6 christos ACPI_CAST_INDIRECT_PTR (
971 1.1.1.6 christos ACPI_NAMESPACE_NODE, &ReturnDesc),
972 1.1.1.6 christos WalkState);
973 1.1 jruoho goto Cleanup;
974 1.1 jruoho }
975 1.1 jruoho }
976 1.1 jruoho
977 1.1 jruoho /* Operand[0] may have changed from the code above */
978 1.1 jruoho
979 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
980 1.1 jruoho {
981 1.1 jruoho /*
982 1.1 jruoho * This is a DerefOf (ObjectReference)
983 1.1 jruoho * Get the actual object from the Node (This is the dereference).
984 1.1 jruoho * This case may only happen when a LocalX or ArgX is
985 1.1.1.10 christos * dereferenced above, or for references to device and
986 1.1.1.10 christos * thermal objects.
987 1.1 jruoho */
988 1.1.1.10 christos switch (((ACPI_NAMESPACE_NODE *) Operand[0])->Type)
989 1.1.1.10 christos {
990 1.1.1.10 christos case ACPI_TYPE_DEVICE:
991 1.1.1.10 christos case ACPI_TYPE_THERMAL:
992 1.1.1.10 christos
993 1.1.1.10 christos /* These types have no node subobject, return the NS node */
994 1.1.1.10 christos
995 1.1.1.10 christos ReturnDesc = Operand[0];
996 1.1.1.10 christos break;
997 1.1.1.10 christos
998 1.1.1.10 christos default:
999 1.1.1.10 christos /* For most types, get the object attached to the node */
1000 1.1.1.10 christos
1001 1.1.1.10 christos ReturnDesc = AcpiNsGetAttachedObject (
1002 1.1.1.10 christos (ACPI_NAMESPACE_NODE *) Operand[0]);
1003 1.1.1.10 christos AcpiUtAddReference (ReturnDesc);
1004 1.1.1.10 christos break;
1005 1.1.1.10 christos }
1006 1.1 jruoho }
1007 1.1 jruoho else
1008 1.1 jruoho {
1009 1.1 jruoho /*
1010 1.1 jruoho * This must be a reference object produced by either the
1011 1.1 jruoho * Index() or RefOf() operator
1012 1.1 jruoho */
1013 1.1 jruoho switch (Operand[0]->Reference.Class)
1014 1.1 jruoho {
1015 1.1 jruoho case ACPI_REFCLASS_INDEX:
1016 1.1 jruoho /*
1017 1.1 jruoho * The target type for the Index operator must be
1018 1.1 jruoho * either a Buffer or a Package
1019 1.1 jruoho */
1020 1.1 jruoho switch (Operand[0]->Reference.TargetType)
1021 1.1 jruoho {
1022 1.1 jruoho case ACPI_TYPE_BUFFER_FIELD:
1023 1.1 jruoho
1024 1.1 jruoho TempDesc = Operand[0]->Reference.Object;
1025 1.1 jruoho
1026 1.1 jruoho /*
1027 1.1 jruoho * Create a new object that contains one element of the
1028 1.1 jruoho * buffer -- the element pointed to by the index.
1029 1.1 jruoho *
1030 1.1 jruoho * NOTE: index into a buffer is NOT a pointer to a
1031 1.1 jruoho * sub-buffer of the main buffer, it is only a pointer to a
1032 1.1 jruoho * single element (byte) of the buffer!
1033 1.1 jruoho *
1034 1.1 jruoho * Since we are returning the value of the buffer at the
1035 1.1 jruoho * indexed location, we don't need to add an additional
1036 1.1 jruoho * reference to the buffer itself.
1037 1.1 jruoho */
1038 1.1 jruoho ReturnDesc = AcpiUtCreateIntegerObject ((UINT64)
1039 1.1 jruoho TempDesc->Buffer.Pointer[Operand[0]->Reference.Value]);
1040 1.1 jruoho if (!ReturnDesc)
1041 1.1 jruoho {
1042 1.1 jruoho Status = AE_NO_MEMORY;
1043 1.1 jruoho goto Cleanup;
1044 1.1 jruoho }
1045 1.1 jruoho break;
1046 1.1 jruoho
1047 1.1 jruoho case ACPI_TYPE_PACKAGE:
1048 1.1 jruoho /*
1049 1.1.1.3 christos * Return the referenced element of the package. We must
1050 1.1 jruoho * add another reference to the referenced object, however.
1051 1.1 jruoho */
1052 1.1 jruoho ReturnDesc = *(Operand[0]->Reference.Where);
1053 1.1.1.3 christos if (!ReturnDesc)
1054 1.1 jruoho {
1055 1.1.1.3 christos /*
1056 1.1.1.3 christos * Element is NULL, do not allow the dereference.
1057 1.1.1.3 christos * This provides compatibility with other ACPI
1058 1.1.1.3 christos * implementations.
1059 1.1.1.3 christos */
1060 1.1.1.3 christos return_ACPI_STATUS (AE_AML_UNINITIALIZED_ELEMENT);
1061 1.1 jruoho }
1062 1.1 jruoho
1063 1.1.1.3 christos AcpiUtAddReference (ReturnDesc);
1064 1.1.1.3 christos break;
1065 1.1 jruoho
1066 1.1 jruoho default:
1067 1.1 jruoho
1068 1.1 jruoho ACPI_ERROR ((AE_INFO,
1069 1.1 jruoho "Unknown Index TargetType 0x%X in reference object %p",
1070 1.1 jruoho Operand[0]->Reference.TargetType, Operand[0]));
1071 1.1.1.6 christos
1072 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
1073 1.1 jruoho goto Cleanup;
1074 1.1 jruoho }
1075 1.1 jruoho break;
1076 1.1 jruoho
1077 1.1 jruoho case ACPI_REFCLASS_REFOF:
1078 1.1 jruoho
1079 1.1 jruoho ReturnDesc = Operand[0]->Reference.Object;
1080 1.1 jruoho
1081 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1082 1.1.1.3 christos ACPI_DESC_TYPE_NAMED)
1083 1.1 jruoho {
1084 1.1 jruoho ReturnDesc = AcpiNsGetAttachedObject (
1085 1.1.1.3 christos (ACPI_NAMESPACE_NODE *) ReturnDesc);
1086 1.1.1.3 christos if (!ReturnDesc)
1087 1.1.1.3 christos {
1088 1.1.1.3 christos break;
1089 1.1.1.3 christos }
1090 1.1 jruoho
1091 1.1.1.3 christos /*
1092 1.1.1.3 christos * June 2013:
1093 1.1.1.3 christos * BufferFields/FieldUnits require additional resolution
1094 1.1.1.3 christos */
1095 1.1.1.3 christos switch (ReturnDesc->Common.Type)
1096 1.1.1.3 christos {
1097 1.1.1.3 christos case ACPI_TYPE_BUFFER_FIELD:
1098 1.1.1.3 christos case ACPI_TYPE_LOCAL_REGION_FIELD:
1099 1.1.1.3 christos case ACPI_TYPE_LOCAL_BANK_FIELD:
1100 1.1.1.3 christos case ACPI_TYPE_LOCAL_INDEX_FIELD:
1101 1.1.1.3 christos
1102 1.1.1.6 christos Status = AcpiExReadDataFromField (
1103 1.1.1.6 christos WalkState, ReturnDesc, &TempDesc);
1104 1.1.1.3 christos if (ACPI_FAILURE (Status))
1105 1.1.1.3 christos {
1106 1.1.1.15 christos return_ACPI_STATUS (Status);
1107 1.1.1.3 christos }
1108 1.1 jruoho
1109 1.1.1.3 christos ReturnDesc = TempDesc;
1110 1.1.1.3 christos break;
1111 1.1.1.3 christos
1112 1.1.1.3 christos default:
1113 1.1.1.3 christos
1114 1.1.1.3 christos /* Add another reference to the object */
1115 1.1 jruoho
1116 1.1.1.3 christos AcpiUtAddReference (ReturnDesc);
1117 1.1.1.3 christos break;
1118 1.1.1.3 christos }
1119 1.1.1.3 christos }
1120 1.1.1.3 christos break;
1121 1.1 jruoho
1122 1.1 jruoho default:
1123 1.1.1.3 christos
1124 1.1 jruoho ACPI_ERROR ((AE_INFO,
1125 1.1 jruoho "Unknown class in reference(%p) - 0x%2.2X",
1126 1.1 jruoho Operand[0], Operand[0]->Reference.Class));
1127 1.1 jruoho
1128 1.1 jruoho Status = AE_TYPE;
1129 1.1 jruoho goto Cleanup;
1130 1.1 jruoho }
1131 1.1 jruoho }
1132 1.1 jruoho break;
1133 1.1 jruoho
1134 1.1 jruoho default:
1135 1.1 jruoho
1136 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
1137 1.1 jruoho WalkState->Opcode));
1138 1.1.1.6 christos
1139 1.1 jruoho Status = AE_AML_BAD_OPCODE;
1140 1.1 jruoho goto Cleanup;
1141 1.1 jruoho }
1142 1.1 jruoho
1143 1.1 jruoho
1144 1.1 jruoho Cleanup:
1145 1.1 jruoho
1146 1.1 jruoho /* Delete return object on error */
1147 1.1 jruoho
1148 1.1 jruoho if (ACPI_FAILURE (Status))
1149 1.1 jruoho {
1150 1.1 jruoho AcpiUtRemoveReference (ReturnDesc);
1151 1.1 jruoho }
1152 1.1 jruoho
1153 1.1 jruoho /* Save return object on success */
1154 1.1 jruoho
1155 1.1 jruoho else
1156 1.1 jruoho {
1157 1.1 jruoho WalkState->ResultObj = ReturnDesc;
1158 1.1 jruoho }
1159 1.1 jruoho
1160 1.1 jruoho return_ACPI_STATUS (Status);
1161 1.1 jruoho }
1162