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