blob: 1edd66f18907905a7d73b7e011bcf6f9e1168daf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
Masanari Iida02582e92012-08-22 19:11:26 +09003 * Module Name: dsopcode - Dispatcher support for regions and fields
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 *****************************************************************************/
6
7/*
David E. Box82a80942015-02-05 15:20:45 +08008 * Copyright (C) 2000 - 2015, 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 "acinterp.h"
50#include "acnamesp.h"
51#include "acevents.h"
52#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040055ACPI_MODULE_NAME("dsopcode")
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Robert Moore44f6c012005-04-18 22:49:35 -040057/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040058static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040059acpi_ds_init_buffer_field(u16 aml_opcode,
60 union acpi_operand_object *obj_desc,
61 union acpi_operand_object *buffer_desc,
62 union acpi_operand_object *offset_desc,
63 union acpi_operand_object *length_desc,
64 union acpi_operand_object *result_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040065
66/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 * FUNCTION: acpi_ds_initialize_region
69 *
Robert Moore44f6c012005-04-18 22:49:35 -040070 * PARAMETERS: obj_handle - Region namespace node
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 *
72 * RETURN: Status
73 *
74 * DESCRIPTION: Front end to ev_initialize_region
75 *
Robert Moore44f6c012005-04-18 22:49:35 -040076 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Len Brown4be44fc2005-08-05 00:44:28 -040078acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Len Brown4be44fc2005-08-05 00:44:28 -040080 union acpi_operand_object *obj_desc;
81 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Len Brown4be44fc2005-08-05 00:44:28 -040083 obj_desc = acpi_ns_get_attached_object(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 /* Namespace is NOT locked */
86
Len Brown4be44fc2005-08-05 00:44:28 -040087 status = acpi_ev_initialize_region(obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 return (status);
89}
90
Robert Moore44f6c012005-04-18 22:49:35 -040091/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 *
93 * FUNCTION: acpi_ds_init_buffer_field
94 *
95 * PARAMETERS: aml_opcode - create_xxx_field
96 * obj_desc - buffer_field object
97 * buffer_desc - Host Buffer
98 * offset_desc - Offset into buffer
Robert Moore44f6c012005-04-18 22:49:35 -040099 * length_desc - Length of field (CREATE_FIELD_OP only)
100 * result_desc - Where to store the result
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 *
102 * RETURN: Status
103 *
104 * DESCRIPTION: Perform actual initialization of a buffer field
105 *
Robert Moore44f6c012005-04-18 22:49:35 -0400106 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Robert Moore44f6c012005-04-18 22:49:35 -0400108static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400109acpi_ds_init_buffer_field(u16 aml_opcode,
110 union acpi_operand_object *obj_desc,
111 union acpi_operand_object *buffer_desc,
112 union acpi_operand_object *offset_desc,
113 union acpi_operand_object *length_desc,
114 union acpi_operand_object *result_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Len Brown4be44fc2005-08-05 00:44:28 -0400116 u32 offset;
117 u32 bit_offset;
118 u32 bit_count;
119 u8 field_flags;
120 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Bob Mooreb229cf92006-04-21 17:15:00 -0400122 ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /* Host object must be a Buffer */
125
Bob Moore3371c192009-02-18 14:44:03 +0800126 if (buffer_desc->common.type != ACPI_TYPE_BUFFER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500127 ACPI_ERROR((AE_INFO,
128 "Target of Create Field is not a Buffer object - %s",
129 acpi_ut_get_object_type_name(buffer_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 status = AE_AML_OPERAND_TYPE;
132 goto cleanup;
133 }
134
135 /*
136 * The last parameter to all of these opcodes (result_desc) started
137 * out as a name_string, and should therefore now be a NS node
138 * after resolution in acpi_ex_resolve_operands().
139 */
Len Brown4be44fc2005-08-05 00:44:28 -0400140 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500141 ACPI_ERROR((AE_INFO,
142 "(%s) destination not a NS Node [%s]",
143 acpi_ps_get_opcode_name(aml_opcode),
144 acpi_ut_get_descriptor_name(result_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 status = AE_AML_OPERAND_TYPE;
147 goto cleanup;
148 }
149
150 offset = (u32) offset_desc->integer.value;
151
152 /*
153 * Setup the Bit offsets and counts, according to the opcode
154 */
155 switch (aml_opcode) {
156 case AML_CREATE_FIELD_OP:
157
158 /* Offset is in bits, count is in bits */
159
Robert Moore44f6c012005-04-18 22:49:35 -0400160 field_flags = AML_FIELD_ACCESS_BYTE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 bit_offset = offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400162 bit_count = (u32) length_desc->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400163
164 /* Must have a valid (>0) bit count */
165
166 if (bit_count == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500167 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400168 "Attempt to CreateField of length zero"));
Robert Moore44f6c012005-04-18 22:49:35 -0400169 status = AE_AML_OPERAND_VALUE;
170 goto cleanup;
171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 break;
173
174 case AML_CREATE_BIT_FIELD_OP:
175
176 /* Offset is in bits, Field is one bit */
177
178 bit_offset = offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400179 bit_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 field_flags = AML_FIELD_ACCESS_BYTE;
181 break;
182
183 case AML_CREATE_BYTE_FIELD_OP:
184
185 /* Offset is in bytes, field is one byte */
186
187 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400188 bit_count = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 field_flags = AML_FIELD_ACCESS_BYTE;
190 break;
191
192 case AML_CREATE_WORD_FIELD_OP:
193
194 /* Offset is in bytes, field is one word */
195
196 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400197 bit_count = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 field_flags = AML_FIELD_ACCESS_WORD;
199 break;
200
201 case AML_CREATE_DWORD_FIELD_OP:
202
203 /* Offset is in bytes, field is one dword */
204
205 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400206 bit_count = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 field_flags = AML_FIELD_ACCESS_DWORD;
208 break;
209
210 case AML_CREATE_QWORD_FIELD_OP:
211
212 /* Offset is in bytes, field is one qword */
213
214 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400215 bit_count = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 field_flags = AML_FIELD_ACCESS_QWORD;
217 break;
218
219 default:
220
Bob Mooreb8e4d892006-01-27 16:43:00 -0500221 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800222 "Unknown field creation opcode 0x%02X",
223 aml_opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 status = AE_AML_BAD_OPCODE;
225 goto cleanup;
226 }
227
228 /* Entire field must fit within the current length of the buffer */
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500231 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800232 "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500233 acpi_ut_get_node_name(result_desc),
234 bit_offset + bit_count,
235 acpi_ut_get_node_name(buffer_desc->buffer.node),
236 8 * (u32) buffer_desc->buffer.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 status = AE_AML_BUFFER_LIMIT;
238 goto cleanup;
239 }
240
241 /*
242 * Initialize areas of the field object that are common to all fields
Robert Moore44f6c012005-04-18 22:49:35 -0400243 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
244 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 */
Bob Moore1fad8732015-12-29 13:54:36 +0800246 status =
247 acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
248 bit_offset, bit_count);
Len Brown4be44fc2005-08-05 00:44:28 -0400249 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 goto cleanup;
251 }
252
253 obj_desc->buffer_field.buffer_obj = buffer_desc;
254
255 /* Reference count for buffer_desc inherits obj_desc count */
256
Robert Moore44f6c012005-04-18 22:49:35 -0400257 buffer_desc->common.reference_count = (u16)
Len Brown4be44fc2005-08-05 00:44:28 -0400258 (buffer_desc->common.reference_count +
259 obj_desc->common.reference_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Lv Zheng10622bf2013-10-29 09:30:02 +0800261cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 /* Always delete the operands */
264
Len Brown4be44fc2005-08-05 00:44:28 -0400265 acpi_ut_remove_reference(offset_desc);
266 acpi_ut_remove_reference(buffer_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 if (aml_opcode == AML_CREATE_FIELD_OP) {
Len Brown4be44fc2005-08-05 00:44:28 -0400269 acpi_ut_remove_reference(length_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271
272 /* On failure, delete the result descriptor */
273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 if (ACPI_FAILURE(status)) {
275 acpi_ut_remove_reference(result_desc); /* Result descriptor */
276 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* Now the address and length are valid for this buffer_field */
278
279 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
280 }
281
Len Brown4be44fc2005-08-05 00:44:28 -0400282 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Robert Moore44f6c012005-04-18 22:49:35 -0400285/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 *
287 * FUNCTION: acpi_ds_eval_buffer_field_operands
288 *
289 * PARAMETERS: walk_state - Current walk
Bob Mooreba494be2012-07-12 09:40:10 +0800290 * op - A valid buffer_field Op object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 *
292 * RETURN: Status
293 *
294 * DESCRIPTION: Get buffer_field Buffer and Index
295 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
296 *
Robert Moore44f6c012005-04-18 22:49:35 -0400297 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400300acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
301 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Len Brown4be44fc2005-08-05 00:44:28 -0400303 acpi_status status;
304 union acpi_operand_object *obj_desc;
305 struct acpi_namespace_node *node;
306 union acpi_parse_object *next_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Bob Mooreb229cf92006-04-21 17:15:00 -0400308 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 /*
311 * This is where we evaluate the address and length fields of the
312 * create_xxx_field declaration
313 */
Len Brown4be44fc2005-08-05 00:44:28 -0400314 node = op->common.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 /* next_op points to the op that holds the Buffer */
317
318 next_op = op->common.value.arg;
319
320 /* Evaluate/create the address and length operands */
321
Len Brown4be44fc2005-08-05 00:44:28 -0400322 status = acpi_ds_create_operands(walk_state, next_op);
323 if (ACPI_FAILURE(status)) {
324 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326
Len Brown4be44fc2005-08-05 00:44:28 -0400327 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400329 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
331
332 /* Resolve the operands */
333
Bob Moore1fad8732015-12-29 13:54:36 +0800334 status =
335 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
336 walk_state);
Len Brown4be44fc2005-08-05 00:44:28 -0400337 if (ACPI_FAILURE(status)) {
Bob Mooref6a22b02010-03-05 17:56:40 +0800338 ACPI_ERROR((AE_INFO, "(%s) bad operand(s), status 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500339 acpi_ps_get_opcode_name(op->common.aml_opcode),
340 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Len Brown4be44fc2005-08-05 00:44:28 -0400342 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
344
345 /* Initialize the Buffer Field */
346
347 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 /* NOTE: Slightly different operands for this opcode */
350
Len Brown4be44fc2005-08-05 00:44:28 -0400351 status =
352 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
353 walk_state->operands[0],
354 walk_state->operands[1],
355 walk_state->operands[2],
356 walk_state->operands[3]);
357 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 /* All other, create_xxx_field opcodes */
359
Len Brown4be44fc2005-08-05 00:44:28 -0400360 status =
361 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
362 walk_state->operands[0],
363 walk_state->operands[1], NULL,
364 walk_state->operands[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366
Len Brown4be44fc2005-08-05 00:44:28 -0400367 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
Robert Moore44f6c012005-04-18 22:49:35 -0400370/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 *
372 * FUNCTION: acpi_ds_eval_region_operands
373 *
374 * PARAMETERS: walk_state - Current walk
Bob Mooreba494be2012-07-12 09:40:10 +0800375 * op - A valid region Op object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 *
377 * RETURN: Status
378 *
379 * DESCRIPTION: Get region address and length
380 * Called from acpi_ds_exec_end_op during op_region parse tree walk
381 *
Robert Moore44f6c012005-04-18 22:49:35 -0400382 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400385acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
386 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Len Brown4be44fc2005-08-05 00:44:28 -0400388 acpi_status status;
389 union acpi_operand_object *obj_desc;
390 union acpi_operand_object *operand_desc;
391 struct acpi_namespace_node *node;
392 union acpi_parse_object *next_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Bob Mooreb229cf92006-04-21 17:15:00 -0400394 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400397 * This is where we evaluate the address and length fields of the
398 * op_region declaration
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 */
Len Brown4be44fc2005-08-05 00:44:28 -0400400 node = op->common.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Bob Mooreba494be2012-07-12 09:40:10 +0800402 /* next_op points to the op that holds the space_ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 next_op = op->common.value.arg;
405
406 /* next_op points to address op */
407
408 next_op = next_op->common.next;
409
410 /* Evaluate/create the address and length operands */
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412 status = acpi_ds_create_operands(walk_state, next_op);
413 if (ACPI_FAILURE(status)) {
414 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
417 /* Resolve the length and address operands to numbers */
418
Bob Moore1fad8732015-12-29 13:54:36 +0800419 status =
420 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
421 walk_state);
Len Brown4be44fc2005-08-05 00:44:28 -0400422 if (ACPI_FAILURE(status)) {
423 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
425
Len Brown4be44fc2005-08-05 00:44:28 -0400426 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400428 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430
431 /*
432 * Get the length operand and save it
433 * (at Top of stack)
434 */
435 operand_desc = walk_state->operands[walk_state->num_operands - 1];
436
437 obj_desc->region.length = (u32) operand_desc->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400438 acpi_ut_remove_reference(operand_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 /*
441 * Get the address and save it
442 * (at top of stack - 1)
443 */
444 operand_desc = walk_state->operands[walk_state->num_operands - 2];
445
Robert Moore44f6c012005-04-18 22:49:35 -0400446 obj_desc->region.address = (acpi_physical_address)
Len Brown4be44fc2005-08-05 00:44:28 -0400447 operand_desc->integer.value;
448 acpi_ut_remove_reference(operand_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Bob Mooreb229cf92006-04-21 17:15:00 -0400450 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400451 obj_desc,
Lv Zheng1d0a0b22015-04-13 11:48:52 +0800452 ACPI_FORMAT_UINT64(obj_desc->region.address),
Len Brown4be44fc2005-08-05 00:44:28 -0400453 obj_desc->region.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 /* Now the address and length are valid for this opregion */
456
457 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
Len Brown4be44fc2005-08-05 00:44:28 -0400458 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
Robert Moore44f6c012005-04-18 22:49:35 -0400461/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 *
Lin Ming941f48b2008-04-10 19:06:41 +0400463 * FUNCTION: acpi_ds_eval_table_region_operands
464 *
465 * PARAMETERS: walk_state - Current walk
Bob Mooreba494be2012-07-12 09:40:10 +0800466 * op - A valid region Op object
Lin Ming941f48b2008-04-10 19:06:41 +0400467 *
468 * RETURN: Status
469 *
Bob Moore9ad19ac42011-02-14 16:09:40 +0800470 * DESCRIPTION: Get region address and length.
471 * Called from acpi_ds_exec_end_op during data_table_region parse
472 * tree walk.
Lin Ming941f48b2008-04-10 19:06:41 +0400473 *
474 ******************************************************************************/
475
476acpi_status
477acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
478 union acpi_parse_object *op)
479{
480 acpi_status status;
481 union acpi_operand_object *obj_desc;
482 union acpi_operand_object **operand;
483 struct acpi_namespace_node *node;
484 union acpi_parse_object *next_op;
Lin Ming941f48b2008-04-10 19:06:41 +0400485 struct acpi_table_header *table;
Bob Moore9f41fd82015-08-25 10:28:39 +0800486 u32 table_index;
Lin Ming941f48b2008-04-10 19:06:41 +0400487
488 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
489
490 /*
Lv Zheng75c80442012-12-19 05:36:49 +0000491 * This is where we evaluate the Signature string, oem_id string,
492 * and oem_table_id string of the Data Table Region declaration
Lin Ming941f48b2008-04-10 19:06:41 +0400493 */
494 node = op->common.node;
495
Lv Zheng75c80442012-12-19 05:36:49 +0000496 /* next_op points to Signature string op */
Lin Ming941f48b2008-04-10 19:06:41 +0400497
498 next_op = op->common.value.arg;
499
500 /*
Lv Zheng75c80442012-12-19 05:36:49 +0000501 * Evaluate/create the Signature string, oem_id string,
502 * and oem_table_id string operands
Lin Ming941f48b2008-04-10 19:06:41 +0400503 */
504 status = acpi_ds_create_operands(walk_state, next_op);
505 if (ACPI_FAILURE(status)) {
506 return_ACPI_STATUS(status);
507 }
508
Bob Moore9f41fd82015-08-25 10:28:39 +0800509 operand = &walk_state->operands[0];
510
Lin Ming941f48b2008-04-10 19:06:41 +0400511 /*
Lv Zheng75c80442012-12-19 05:36:49 +0000512 * Resolve the Signature string, oem_id string,
513 * and oem_table_id string operands
Lin Ming941f48b2008-04-10 19:06:41 +0400514 */
Bob Moore1fad8732015-12-29 13:54:36 +0800515 status =
516 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
517 walk_state);
Lin Ming941f48b2008-04-10 19:06:41 +0400518 if (ACPI_FAILURE(status)) {
Bob Moore9f41fd82015-08-25 10:28:39 +0800519 goto cleanup;
Lin Ming941f48b2008-04-10 19:06:41 +0400520 }
521
Lin Ming941f48b2008-04-10 19:06:41 +0400522 /* Find the ACPI table */
523
524 status = acpi_tb_find_table(operand[0]->string.pointer,
525 operand[1]->string.pointer,
526 operand[2]->string.pointer, &table_index);
527 if (ACPI_FAILURE(status)) {
Bob Moore9f41fd82015-08-25 10:28:39 +0800528 if (status == AE_NOT_FOUND) {
529 ACPI_ERROR((AE_INFO,
530 "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
531 operand[0]->string.pointer,
532 operand[1]->string.pointer,
533 operand[2]->string.pointer));
534 }
535 goto cleanup;
Lin Ming941f48b2008-04-10 19:06:41 +0400536 }
537
Lin Ming941f48b2008-04-10 19:06:41 +0400538 status = acpi_get_table_by_index(table_index, &table);
539 if (ACPI_FAILURE(status)) {
Bob Moore9f41fd82015-08-25 10:28:39 +0800540 goto cleanup;
Lin Ming941f48b2008-04-10 19:06:41 +0400541 }
542
543 obj_desc = acpi_ns_get_attached_object(node);
544 if (!obj_desc) {
Bob Moore9f41fd82015-08-25 10:28:39 +0800545 status = AE_NOT_EXIST;
546 goto cleanup;
Lin Ming941f48b2008-04-10 19:06:41 +0400547 }
548
Lv Zheng6d3fd3c2015-04-13 11:48:37 +0800549 obj_desc->region.address = ACPI_PTR_TO_PHYSADDR(table);
Lin Ming941f48b2008-04-10 19:06:41 +0400550 obj_desc->region.length = table->length;
551
552 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
553 obj_desc,
Lv Zheng1d0a0b22015-04-13 11:48:52 +0800554 ACPI_FORMAT_UINT64(obj_desc->region.address),
Lin Ming941f48b2008-04-10 19:06:41 +0400555 obj_desc->region.length));
556
557 /* Now the address and length are valid for this opregion */
558
559 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
560
Bob Moore9f41fd82015-08-25 10:28:39 +0800561cleanup:
562 acpi_ut_remove_reference(operand[0]);
563 acpi_ut_remove_reference(operand[1]);
564 acpi_ut_remove_reference(operand[2]);
565
Lin Ming941f48b2008-04-10 19:06:41 +0400566 return_ACPI_STATUS(status);
567}
568
569/*******************************************************************************
570 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * FUNCTION: acpi_ds_eval_data_object_operands
572 *
573 * PARAMETERS: walk_state - Current walk
Bob Mooreba494be2012-07-12 09:40:10 +0800574 * op - A valid data_object Op object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 * obj_desc - data_object
576 *
577 * RETURN: Status
578 *
579 * DESCRIPTION: Get the operands and complete the following data object types:
580 * Buffer, Package.
581 *
Robert Moore44f6c012005-04-18 22:49:35 -0400582 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400585acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
586 union acpi_parse_object *op,
587 union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588{
Len Brown4be44fc2005-08-05 00:44:28 -0400589 acpi_status status;
590 union acpi_operand_object *arg_desc;
591 u32 length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Bob Mooreb229cf92006-04-21 17:15:00 -0400593 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 /* The first operand (for all of these data objects) is the length */
596
Bob Moore773069d2008-04-10 19:06:36 +0400597 /*
598 * Set proper index into operand stack for acpi_ds_obj_stack_push
599 * invoked inside acpi_ds_create_operand.
600 */
601 walk_state->operand_index = walk_state->num_operands;
602
Len Brown4be44fc2005-08-05 00:44:28 -0400603 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
604 if (ACPI_FAILURE(status)) {
605 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 }
607
Len Brown4be44fc2005-08-05 00:44:28 -0400608 status = acpi_ex_resolve_operands(walk_state->opcode,
609 &(walk_state->
610 operands[walk_state->num_operands -
611 1]), walk_state);
612 if (ACPI_FAILURE(status)) {
613 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615
616 /* Extract length operand */
617
Len Brown4be44fc2005-08-05 00:44:28 -0400618 arg_desc = walk_state->operands[walk_state->num_operands - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 length = (u32) arg_desc->integer.value;
620
621 /* Cleanup for length operand */
622
Len Brown4be44fc2005-08-05 00:44:28 -0400623 status = acpi_ds_obj_stack_pop(1, walk_state);
624 if (ACPI_FAILURE(status)) {
625 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 }
627
Len Brown4be44fc2005-08-05 00:44:28 -0400628 acpi_ut_remove_reference(arg_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 /*
631 * Create the actual data object
632 */
633 switch (op->common.aml_opcode) {
634 case AML_BUFFER_OP:
635
Len Brown4be44fc2005-08-05 00:44:28 -0400636 status =
637 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
638 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 break;
640
641 case AML_PACKAGE_OP:
642 case AML_VAR_PACKAGE_OP:
643
Len Brown4be44fc2005-08-05 00:44:28 -0400644 status =
645 acpi_ds_build_internal_package_obj(walk_state, op, length,
646 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 break;
648
649 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000650
Len Brown4be44fc2005-08-05 00:44:28 -0400651 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
Len Brown4be44fc2005-08-05 00:44:28 -0400654 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400656 * Return the object in the walk_state, unless the parent is a package -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 * in this case, the return object will be stored in the parse tree
658 * for the package.
659 */
660 if ((!op->common.parent) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400661 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
662 (op->common.parent->common.aml_opcode !=
663 AML_VAR_PACKAGE_OP)
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000664 && (op->common.parent->common.aml_opcode !=
665 AML_NAME_OP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 walk_state->result_obj = obj_desc;
667 }
668 }
669
Len Brown4be44fc2005-08-05 00:44:28 -0400670 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673/*******************************************************************************
674 *
Lin Mingef805d92008-04-10 19:06:41 +0400675 * FUNCTION: acpi_ds_eval_bank_field_operands
676 *
677 * PARAMETERS: walk_state - Current walk
Bob Mooreba494be2012-07-12 09:40:10 +0800678 * op - A valid bank_field Op object
Lin Mingef805d92008-04-10 19:06:41 +0400679 *
680 * RETURN: Status
681 *
682 * DESCRIPTION: Get bank_field bank_value
683 * Called from acpi_ds_exec_end_op during bank_field parse tree walk
684 *
685 ******************************************************************************/
686
687acpi_status
688acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
689 union acpi_parse_object *op)
690{
691 acpi_status status;
692 union acpi_operand_object *obj_desc;
693 union acpi_operand_object *operand_desc;
694 struct acpi_namespace_node *node;
695 union acpi_parse_object *next_op;
696 union acpi_parse_object *arg;
697
698 ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op);
699
700 /*
701 * This is where we evaluate the bank_value field of the
702 * bank_field declaration
703 */
704
705 /* next_op points to the op that holds the Region */
706
707 next_op = op->common.value.arg;
708
709 /* next_op points to the op that holds the Bank Register */
710
711 next_op = next_op->common.next;
712
713 /* next_op points to the op that holds the Bank Value */
714
715 next_op = next_op->common.next;
716
717 /*
718 * Set proper index into operand stack for acpi_ds_obj_stack_push
719 * invoked inside acpi_ds_create_operand.
720 *
721 * We use walk_state->Operands[0] to store the evaluated bank_value
722 */
723 walk_state->operand_index = 0;
724
725 status = acpi_ds_create_operand(walk_state, next_op, 0);
726 if (ACPI_FAILURE(status)) {
727 return_ACPI_STATUS(status);
728 }
729
730 status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state);
731 if (ACPI_FAILURE(status)) {
732 return_ACPI_STATUS(status);
733 }
734
Bob Moore71d993e2008-06-10 14:25:05 +0800735 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
736 acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
Lin Mingef805d92008-04-10 19:06:41 +0400737 /*
738 * Get the bank_value operand and save it
739 * (at Top of stack)
740 */
741 operand_desc = walk_state->operands[0];
742
743 /* Arg points to the start Bank Field */
744
745 arg = acpi_ps_get_arg(op, 4);
746 while (arg) {
747
748 /* Ignore OFFSET and ACCESSAS terms here */
749
750 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
751 node = arg->common.node;
752
753 obj_desc = acpi_ns_get_attached_object(node);
754 if (!obj_desc) {
755 return_ACPI_STATUS(AE_NOT_EXIST);
756 }
757
758 obj_desc->bank_field.value =
759 (u32) operand_desc->integer.value;
760 }
761
762 /* Move to next field in the list */
763
764 arg = arg->common.next;
765 }
766
767 acpi_ut_remove_reference(operand_desc);
768 return_ACPI_STATUS(status);
769}