blob: 82448551781b43bf3d276df6ee9378416cb2a08b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: dsobject - Dispatcher object management routines
4 *
5 *****************************************************************************/
6
7/*
Bob Moore7735ca02017-02-08 11:00:08 +08008 * Copyright (C) 2000 - 2017, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acparser.h"
47#include "amlcode.h"
48#include "acdispat.h"
49#include "acnamesp.h"
50#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040053ACPI_MODULE_NAME("dsobject")
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#ifndef ACPI_NO_METHOD_EXECUTION
Robert Moore44f6c012005-04-18 22:49:35 -040056/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 *
58 * FUNCTION: acpi_ds_build_internal_object
59 *
60 * PARAMETERS: walk_state - Current walk state
Bob Mooreba494be2012-07-12 09:40:10 +080061 * op - Parser object to be translated
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * obj_desc_ptr - Where the ACPI internal object is returned
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
67 * Simple objects are any objects other than a package object!
68 *
Robert Moore44f6c012005-04-18 22:49:35 -040069 ******************************************************************************/
Bob Moorea62a7112017-08-03 14:27:22 +080070acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040071acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
72 union acpi_parse_object *op,
73 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Len Brown4be44fc2005-08-05 00:44:28 -040075 union acpi_operand_object *obj_desc;
76 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Bob Mooreb229cf92006-04-21 17:15:00 -040078 ACPI_FUNCTION_TRACE(ds_build_internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 *obj_desc_ptr = NULL;
81 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
82 /*
Bob Mooredefba1d2005-12-16 17:05:00 -050083 * This is a named object reference. If this name was
Bob Moorea62a7112017-08-03 14:27:22 +080084 * previously looked up in the namespace, it was stored in
85 * this op. Otherwise, go ahead and look it up now
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 */
87 if (!op->common.node) {
Bob Moore52fc0b02006-10-02 00:00:00 -040088
Bob Moorea62a7112017-08-03 14:27:22 +080089 /* Check if we are resolving a named reference within a package */
Bob Mooredefba1d2005-12-16 17:05:00 -050090
Bob Moorea62a7112017-08-03 14:27:22 +080091 if ((op->common.parent->common.aml_opcode ==
92 AML_PACKAGE_OP)
93 || (op->common.parent->common.aml_opcode ==
94 AML_VARIABLE_PACKAGE_OP)) {
95 /*
96 * We won't resolve package elements here, we will do this
97 * after all ACPI tables are loaded into the namespace. This
98 * behavior supports both forward references to named objects
99 * and external references to objects in other tables.
100 */
101 goto create_new_object;
102 } else {
103 status = acpi_ns_lookup(walk_state->scope_info,
104 op->common.value.string,
105 ACPI_TYPE_ANY,
106 ACPI_IMODE_EXECUTE,
107 ACPI_NS_SEARCH_PARENT |
108 ACPI_NS_DONT_OPEN_SCOPE,
109 NULL,
110 ACPI_CAST_INDIRECT_PTR
111 (struct
112 acpi_namespace_node,
113 &(op->common.node)));
114 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500115 ACPI_ERROR_NAMESPACE(op->common.value.
116 string, status);
Bob Moorea62a7112017-08-03 14:27:22 +0800117 return_ACPI_STATUS(status);
Bob Mooredefba1d2005-12-16 17:05:00 -0500118 }
Bob Moore152c3002007-10-17 16:10:18 -0400119 }
120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
Bob Moorea62a7112017-08-03 14:27:22 +0800123create_new_object:
124
Bob Mooredefba1d2005-12-16 17:05:00 -0500125 /* Create and init a new internal ACPI object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Len Brown4be44fc2005-08-05 00:44:28 -0400127 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
128 (op->common.aml_opcode))->
129 object_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400131 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
133
Len Brown4be44fc2005-08-05 00:44:28 -0400134 status =
135 acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
136 &obj_desc);
137 if (ACPI_FAILURE(status)) {
138 acpi_ut_remove_reference(obj_desc);
139 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141
Bob Moorea62a7112017-08-03 14:27:22 +0800142 /*
143 * Handling for unresolved package reference elements.
144 * These are elements that are namepaths.
145 */
146 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
147 (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) {
148 obj_desc->reference.resolved = TRUE;
149
150 if ((op->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
151 !obj_desc->reference.node) {
152 /*
153 * Name was unresolved above.
154 * Get the prefix node for later lookup
155 */
156 obj_desc->reference.node =
157 walk_state->scope_info->scope.node;
158 obj_desc->reference.aml = op->common.aml;
159 obj_desc->reference.resolved = FALSE;
160 }
161 }
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 *obj_desc_ptr = obj_desc;
Bob Moore9e41d932008-04-10 19:06:39 +0400164 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
Robert Moore44f6c012005-04-18 22:49:35 -0400167/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 *
169 * FUNCTION: acpi_ds_build_internal_buffer_obj
170 *
171 * PARAMETERS: walk_state - Current walk state
Bob Mooreba494be2012-07-12 09:40:10 +0800172 * op - Parser object to be translated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 * buffer_length - Length of the buffer
174 * obj_desc_ptr - Where the ACPI internal object is returned
175 *
176 * RETURN: Status
177 *
178 * DESCRIPTION: Translate a parser Op package object to the equivalent
179 * namespace object
180 *
Robert Moore44f6c012005-04-18 22:49:35 -0400181 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400184acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
185 union acpi_parse_object *op,
186 u32 buffer_length,
187 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
Len Brown4be44fc2005-08-05 00:44:28 -0400189 union acpi_parse_object *arg;
190 union acpi_operand_object *obj_desc;
191 union acpi_parse_object *byte_list;
192 u32 byte_list_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Bob Mooreb229cf92006-04-21 17:15:00 -0400194 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Bob Mooredefba1d2005-12-16 17:05:00 -0500196 /*
197 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
198 * The buffer object already exists (from the NS node), otherwise it must
199 * be created.
200 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 obj_desc = *obj_desc_ptr;
Bob Mooredefba1d2005-12-16 17:05:00 -0500202 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 /* Create a new buffer object */
205
Len Brown4be44fc2005-08-05 00:44:28 -0400206 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 *obj_desc_ptr = obj_desc;
208 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400209 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211 }
212
213 /*
214 * Second arg is the buffer data (optional) byte_list can be either
Bob Moore73a30902012-10-31 02:26:55 +0000215 * individual bytes or a string initializer. In either case, a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 * byte_list appears in the AML.
217 */
Len Brown4be44fc2005-08-05 00:44:28 -0400218 arg = op->common.value.arg; /* skip first arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 byte_list = arg->named.next;
221 if (byte_list) {
222 if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500223 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800224 "Expecting bytelist, found AML opcode 0x%X in op %p",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500225 byte_list->common.aml_opcode, byte_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Len Brown4be44fc2005-08-05 00:44:28 -0400227 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return (AE_TYPE);
229 }
230
231 byte_list_length = (u32) byte_list->common.value.integer;
232 }
233
234 /*
235 * The buffer length (number of bytes) will be the larger of:
236 * 1) The specified buffer length and
237 * 2) The length of the initializer byte list
238 */
239 obj_desc->buffer.length = buffer_length;
240 if (byte_list_length > buffer_length) {
241 obj_desc->buffer.length = byte_list_length;
242 }
243
244 /* Allocate the buffer */
245
246 if (obj_desc->buffer.length == 0) {
247 obj_desc->buffer.pointer = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400248 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
249 "Buffer defined with zero length in AML, creating\n"));
250 } else {
251 obj_desc->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400252 ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if (!obj_desc->buffer.pointer) {
Len Brown4be44fc2005-08-05 00:44:28 -0400254 acpi_ut_delete_object_desc(obj_desc);
255 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
258 /* Initialize buffer from the byte_list (if present) */
259
260 if (byte_list) {
Bob Moore4fa46162015-07-01 14:45:11 +0800261 memcpy(obj_desc->buffer.pointer, byte_list->named.data,
262 byte_list_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
264 }
265
266 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
Bob Moore8f9337c2007-02-02 19:48:18 +0300267 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400268 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
Robert Moore44f6c012005-04-18 22:49:35 -0400271/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 * FUNCTION: acpi_ds_create_node
274 *
275 * PARAMETERS: walk_state - Current walk state
Bob Mooreba494be2012-07-12 09:40:10 +0800276 * node - NS Node to be initialized
277 * op - Parser object to be translated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 *
279 * RETURN: Status
280 *
281 * DESCRIPTION: Create the object to be associated with a namespace node
282 *
Robert Moore44f6c012005-04-18 22:49:35 -0400283 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400286acpi_ds_create_node(struct acpi_walk_state *walk_state,
287 struct acpi_namespace_node *node,
288 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Len Brown4be44fc2005-08-05 00:44:28 -0400290 acpi_status status;
291 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Bob Mooreb229cf92006-04-21 17:15:00 -0400293 ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 /*
296 * Because of the execution pass through the non-control-method
Bob Moore73a30902012-10-31 02:26:55 +0000297 * parts of the table, we can arrive here twice. Only init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 * the named object node the first time through
299 */
Len Brown4be44fc2005-08-05 00:44:28 -0400300 if (acpi_ns_get_attached_object(node)) {
301 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303
304 if (!op->common.value.arg) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 /* No arguments, there is nothing to do */
307
Len Brown4be44fc2005-08-05 00:44:28 -0400308 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
310
311 /* Build an internal object for the argument(s) */
312
Bob Moore1fad8732015-12-29 13:54:36 +0800313 status =
314 acpi_ds_build_internal_object(walk_state, op->common.value.arg,
315 &obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400316 if (ACPI_FAILURE(status)) {
317 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 }
319
320 /* Re-type the object according to its argument */
321
Bob Moore3371c192009-02-18 14:44:03 +0800322 node->type = obj_desc->common.type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /* Attach obj to node */
325
Len Brown4be44fc2005-08-05 00:44:28 -0400326 status = acpi_ns_attach_object(node, obj_desc, node->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* Remove local reference to the object */
329
Len Brown4be44fc2005-08-05 00:44:28 -0400330 acpi_ut_remove_reference(obj_desc);
331 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Len Brown4be44fc2005-08-05 00:44:28 -0400334#endif /* ACPI_NO_METHOD_EXECUTION */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Robert Moore44f6c012005-04-18 22:49:35 -0400336/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 *
338 * FUNCTION: acpi_ds_init_object_from_op
339 *
340 * PARAMETERS: walk_state - Current walk state
Bob Mooreba494be2012-07-12 09:40:10 +0800341 * op - Parser op used to init the internal object
342 * opcode - AML opcode associated with the object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 * ret_obj_desc - Namespace object to be initialized
344 *
345 * RETURN: Status
346 *
347 * DESCRIPTION: Initialize a namespace object from a parser Op and its
Bob Moore73a30902012-10-31 02:26:55 +0000348 * associated arguments. The namespace object is a more compact
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 * representation of the Op and its arguments.
350 *
Robert Moore44f6c012005-04-18 22:49:35 -0400351 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400354acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
355 union acpi_parse_object *op,
356 u16 opcode,
357 union acpi_operand_object **ret_obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Len Brown4be44fc2005-08-05 00:44:28 -0400359 const struct acpi_opcode_info *op_info;
360 union acpi_operand_object *obj_desc;
361 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Bob Mooreb229cf92006-04-21 17:15:00 -0400363 ACPI_FUNCTION_TRACE(ds_init_object_from_op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 obj_desc = *ret_obj_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400366 op_info = acpi_ps_get_opcode_info(opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 if (op_info->class == AML_CLASS_UNKNOWN) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /* Unknown opcode */
370
Len Brown4be44fc2005-08-05 00:44:28 -0400371 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
373
374 /* Perform per-object initialization */
375
Bob Moore3371c192009-02-18 14:44:03 +0800376 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 case ACPI_TYPE_BUFFER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 /*
379 * Defer evaluation of Buffer term_arg operand
380 */
Bob Moore8f9337c2007-02-02 19:48:18 +0300381 obj_desc->buffer.node =
382 ACPI_CAST_PTR(struct acpi_namespace_node,
383 walk_state->operands[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 obj_desc->buffer.aml_start = op->named.data;
385 obj_desc->buffer.aml_length = op->named.length;
386 break;
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 case ACPI_TYPE_PACKAGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 /*
Bob Moorea62a7112017-08-03 14:27:22 +0800390 * Defer evaluation of Package term_arg operand and all
391 * package elements. (01/2017): We defer the element
392 * resolution to allow forward references from the package
393 * in order to provide compatibility with other ACPI
394 * implementations.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 */
Bob Moore8f9337c2007-02-02 19:48:18 +0300396 obj_desc->package.node =
397 ACPI_CAST_PTR(struct acpi_namespace_node,
398 walk_state->operands[0]);
Bob Moorea62a7112017-08-03 14:27:22 +0800399
400 if (!op->named.data) {
401 return_ACPI_STATUS(AE_OK);
402 }
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 obj_desc->package.aml_start = op->named.data;
405 obj_desc->package.aml_length = op->named.length;
406 break;
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 case ACPI_TYPE_INTEGER:
409
410 switch (op_info->type) {
411 case AML_TYPE_CONSTANT:
412 /*
413 * Resolve AML Constants here - AND ONLY HERE!
414 * All constants are integers.
Robert Moore44f6c012005-04-18 22:49:35 -0400415 * We mark the integer with a flag that indicates that it started
416 * life as a constant -- so that stores to constants will perform
417 * as expected (noop). zero_op is used as a placeholder for optional
418 * target operands.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 */
420 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
421
422 switch (opcode) {
423 case AML_ZERO_OP:
424
425 obj_desc->integer.value = 0;
426 break;
427
428 case AML_ONE_OP:
429
430 obj_desc->integer.value = 1;
431 break;
432
433 case AML_ONES_OP:
434
Bob Moore5df7e6c2010-01-21 10:06:32 +0800435 obj_desc->integer.value = ACPI_UINT64_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 /* Truncate value if we are executing from a 32-bit ACPI table */
438
439#ifndef ACPI_NO_METHOD_EXECUTION
Bob Mooreef42e532012-12-31 00:07:18 +0000440 (void)acpi_ex_truncate_for32bit_table(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#endif
442 break;
443
444 case AML_REVISION_OP:
445
446 obj_desc->integer.value = ACPI_CA_VERSION;
447 break;
448
449 default:
450
Bob Mooreb8e4d892006-01-27 16:43:00 -0500451 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800452 "Unknown constant opcode 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500453 opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 status = AE_AML_OPERAND_TYPE;
455 break;
456 }
457 break;
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 case AML_TYPE_LITERAL:
460
461 obj_desc->integer.value = op->common.value.integer;
Bob Mooreef42e532012-12-31 00:07:18 +0000462
Robert Moore6f42ccf2005-05-13 00:00:00 -0400463#ifndef ACPI_NO_METHOD_EXECUTION
Bob Mooreef42e532012-12-31 00:07:18 +0000464 if (acpi_ex_truncate_for32bit_table(obj_desc)) {
465
466 /* Warn if we found a 64-bit constant in a 32-bit table */
467
468 ACPI_WARNING((AE_INFO,
469 "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
470 ACPI_FORMAT_UINT64(op->common.
471 value.integer),
472 (u32)obj_desc->integer.value));
473 }
Robert Moore6f42ccf2005-05-13 00:00:00 -0400474#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 break;
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000478
Bob Mooref6a22b02010-03-05 17:56:40 +0800479 ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500480 op_info->type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 status = AE_AML_OPERAND_TYPE;
482 break;
483 }
484 break;
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 case ACPI_TYPE_STRING:
487
488 obj_desc->string.pointer = op->common.value.string;
Bob Moore4fa46162015-07-01 14:45:11 +0800489 obj_desc->string.length = (u32)strlen(op->common.value.string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 /*
492 * The string is contained in the ACPI table, don't ever try
493 * to delete it
494 */
495 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
496 break;
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 case ACPI_TYPE_METHOD:
499 break;
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 case ACPI_TYPE_LOCAL_REFERENCE:
502
503 switch (op_info->type) {
504 case AML_TYPE_LOCAL_VARIABLE:
505
Bob Moore9ff5a21a2017-04-26 16:18:40 +0800506 /* Local ID (0-7) is (AML opcode - base AML_FIRST_LOCAL_OP) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Bob Mooreba9c3f52009-04-22 13:13:48 +0800508 obj_desc->reference.value =
Bob Moore9ff5a21a2017-04-26 16:18:40 +0800509 ((u32)opcode) - AML_FIRST_LOCAL_OP;
Bob Moore1044f1f2008-09-27 11:08:41 +0800510 obj_desc->reference.class = ACPI_REFCLASS_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512#ifndef ACPI_NO_METHOD_EXECUTION
Bob Moore1044f1f2008-09-27 11:08:41 +0800513 status =
514 acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL,
515 obj_desc->reference.
516 value, walk_state,
517 ACPI_CAST_INDIRECT_PTR
518 (struct
519 acpi_namespace_node,
520 &obj_desc->reference.
521 object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#endif
523 break;
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 case AML_TYPE_METHOD_ARGUMENT:
526
Bob Moore9ff5a21a2017-04-26 16:18:40 +0800527 /* Arg ID (0-6) is (AML opcode - base AML_FIRST_ARG_OP) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Bob Moore9ff5a21a2017-04-26 16:18:40 +0800529 obj_desc->reference.value =
530 ((u32)opcode) - AML_FIRST_ARG_OP;
Bob Moore1044f1f2008-09-27 11:08:41 +0800531 obj_desc->reference.class = ACPI_REFCLASS_ARG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533#ifndef ACPI_NO_METHOD_EXECUTION
Bob Moore1044f1f2008-09-27 11:08:41 +0800534 status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG,
Len Brown4be44fc2005-08-05 00:44:28 -0400535 obj_desc->
Bob Moore1044f1f2008-09-27 11:08:41 +0800536 reference.value,
Len Brown4be44fc2005-08-05 00:44:28 -0400537 walk_state,
Bob Moore57e664c2008-09-27 10:40:39 +0800538 ACPI_CAST_INDIRECT_PTR
Len Brown4be44fc2005-08-05 00:44:28 -0400539 (struct
Bob Moore57e664c2008-09-27 10:40:39 +0800540 acpi_namespace_node,
541 &obj_desc->
542 reference.
543 object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544#endif
545 break;
546
Bob Moore1044f1f2008-09-27 11:08:41 +0800547 default: /* Object name or Debug object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Bob Moore1044f1f2008-09-27 11:08:41 +0800549 switch (op->common.aml_opcode) {
550 case AML_INT_NAMEPATH_OP:
Bob Moore52fc0b02006-10-02 00:00:00 -0400551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 /* Node was saved in Op */
553
554 obj_desc->reference.node = op->common.node;
Bob Moore1044f1f2008-09-27 11:08:41 +0800555 obj_desc->reference.class = ACPI_REFCLASS_NAME;
Bob Moorea62a7112017-08-03 14:27:22 +0800556 if (op->common.node) {
557 obj_desc->reference.object =
558 op->common.node->object;
559 }
Bob Moore1044f1f2008-09-27 11:08:41 +0800560 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
Bob Moore1044f1f2008-09-27 11:08:41 +0800562 case AML_DEBUG_OP:
563
564 obj_desc->reference.class = ACPI_REFCLASS_DEBUG;
565 break;
566
567 default:
568
569 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800570 "Unimplemented reference type for AML opcode: 0x%4.4X",
Bob Moore1044f1f2008-09-27 11:08:41 +0800571 opcode));
572 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 break;
575 }
576 break;
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 default:
579
Bob Mooref6a22b02010-03-05 17:56:40 +0800580 ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X",
Bob Moore3371c192009-02-18 14:44:03 +0800581 obj_desc->common.type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 status = AE_AML_OPERAND_TYPE;
584 break;
585 }
586
Len Brown4be44fc2005-08-05 00:44:28 -0400587 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}