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