dsopcode.c 20.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/******************************************************************************
 *
3
 * Module Name: dsopcode - Dispatcher support for regions and fields
L
Linus Torvalds 已提交
4 5 6 7
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2017, Intel Corp.
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
L
Len Brown 已提交
45 46 47 48 49 50 51 52
#include "accommon.h"
#include "acparser.h"
#include "amlcode.h"
#include "acdispat.h"
#include "acinterp.h"
#include "acnamesp.h"
#include "acevents.h"
#include "actables.h"
L
Linus Torvalds 已提交
53 54

#define _COMPONENT          ACPI_DISPATCHER
L
Len Brown 已提交
55
ACPI_MODULE_NAME("dsopcode")
L
Linus Torvalds 已提交
56

R
Robert Moore 已提交
57 58
/* Local prototypes */
static acpi_status
L
Len Brown 已提交
59 60 61 62 63 64
acpi_ds_init_buffer_field(u16 aml_opcode,
			  union acpi_operand_object *obj_desc,
			  union acpi_operand_object *buffer_desc,
			  union acpi_operand_object *offset_desc,
			  union acpi_operand_object *length_desc,
			  union acpi_operand_object *result_desc);
R
Robert Moore 已提交
65 66

/*******************************************************************************
L
Linus Torvalds 已提交
67 68 69
 *
 * FUNCTION:    acpi_ds_initialize_region
 *
R
Robert Moore 已提交
70
 * PARAMETERS:  obj_handle      - Region namespace node
L
Linus Torvalds 已提交
71 72 73 74 75
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Front end to ev_initialize_region
 *
R
Robert Moore 已提交
76
 ******************************************************************************/
L
Linus Torvalds 已提交
77

L
Len Brown 已提交
78
acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
L
Linus Torvalds 已提交
79
{
L
Len Brown 已提交
80 81
	union acpi_operand_object *obj_desc;
	acpi_status status;
L
Linus Torvalds 已提交
82

L
Len Brown 已提交
83
	obj_desc = acpi_ns_get_attached_object(obj_handle);
L
Linus Torvalds 已提交
84 85 86

	/* Namespace is NOT locked */

87
	status = acpi_ev_initialize_region(obj_desc);
L
Linus Torvalds 已提交
88 89 90
	return (status);
}

R
Robert Moore 已提交
91
/*******************************************************************************
L
Linus Torvalds 已提交
92 93 94 95 96 97 98
 *
 * FUNCTION:    acpi_ds_init_buffer_field
 *
 * PARAMETERS:  aml_opcode      - create_xxx_field
 *              obj_desc        - buffer_field object
 *              buffer_desc     - Host Buffer
 *              offset_desc     - Offset into buffer
R
Robert Moore 已提交
99 100
 *              length_desc     - Length of field (CREATE_FIELD_OP only)
 *              result_desc     - Where to store the result
L
Linus Torvalds 已提交
101 102 103 104 105
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Perform actual initialization of a buffer field
 *
R
Robert Moore 已提交
106
 ******************************************************************************/
L
Linus Torvalds 已提交
107

R
Robert Moore 已提交
108
static acpi_status
L
Len Brown 已提交
109 110 111 112 113 114
acpi_ds_init_buffer_field(u16 aml_opcode,
			  union acpi_operand_object *obj_desc,
			  union acpi_operand_object *buffer_desc,
			  union acpi_operand_object *offset_desc,
			  union acpi_operand_object *length_desc,
			  union acpi_operand_object *result_desc)
L
Linus Torvalds 已提交
115
{
L
Len Brown 已提交
116 117 118 119 120
	u32 offset;
	u32 bit_offset;
	u32 bit_count;
	u8 field_flags;
	acpi_status status;
L
Linus Torvalds 已提交
121

B
Bob Moore 已提交
122
	ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc);
L
Linus Torvalds 已提交
123 124 125

	/* Host object must be a Buffer */

126
	if (buffer_desc->common.type != ACPI_TYPE_BUFFER) {
B
Bob Moore 已提交
127 128 129
		ACPI_ERROR((AE_INFO,
			    "Target of Create Field is not a Buffer object - %s",
			    acpi_ut_get_object_type_name(buffer_desc)));
L
Linus Torvalds 已提交
130 131 132 133 134 135 136 137 138 139

		status = AE_AML_OPERAND_TYPE;
		goto cleanup;
	}

	/*
	 * The last parameter to all of these opcodes (result_desc) started
	 * out as a name_string, and should therefore now be a NS node
	 * after resolution in acpi_ex_resolve_operands().
	 */
L
Len Brown 已提交
140
	if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
B
Bob Moore 已提交
141 142 143 144
		ACPI_ERROR((AE_INFO,
			    "(%s) destination not a NS Node [%s]",
			    acpi_ps_get_opcode_name(aml_opcode),
			    acpi_ut_get_descriptor_name(result_desc)));
L
Linus Torvalds 已提交
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159

		status = AE_AML_OPERAND_TYPE;
		goto cleanup;
	}

	offset = (u32) offset_desc->integer.value;

	/*
	 * Setup the Bit offsets and counts, according to the opcode
	 */
	switch (aml_opcode) {
	case AML_CREATE_FIELD_OP:

		/* Offset is in bits, count is in bits */

R
Robert Moore 已提交
160
		field_flags = AML_FIELD_ACCESS_BYTE;
L
Linus Torvalds 已提交
161
		bit_offset = offset;
L
Len Brown 已提交
162
		bit_count = (u32) length_desc->integer.value;
R
Robert Moore 已提交
163 164 165 166

		/* Must have a valid (>0) bit count */

		if (bit_count == 0) {
B
Bob Moore 已提交
167
			ACPI_ERROR((AE_INFO,
B
Bob Moore 已提交
168
				    "Attempt to CreateField of length zero"));
R
Robert Moore 已提交
169 170 171
			status = AE_AML_OPERAND_VALUE;
			goto cleanup;
		}
L
Linus Torvalds 已提交
172 173 174 175 176 177 178
		break;

	case AML_CREATE_BIT_FIELD_OP:

		/* Offset is in bits, Field is one bit */

		bit_offset = offset;
L
Len Brown 已提交
179
		bit_count = 1;
L
Linus Torvalds 已提交
180 181 182 183 184 185 186 187
		field_flags = AML_FIELD_ACCESS_BYTE;
		break;

	case AML_CREATE_BYTE_FIELD_OP:

		/* Offset is in bytes, field is one byte */

		bit_offset = 8 * offset;
L
Len Brown 已提交
188
		bit_count = 8;
L
Linus Torvalds 已提交
189 190 191 192 193 194 195 196
		field_flags = AML_FIELD_ACCESS_BYTE;
		break;

	case AML_CREATE_WORD_FIELD_OP:

		/* Offset is in bytes, field is one word */

		bit_offset = 8 * offset;
L
Len Brown 已提交
197
		bit_count = 16;
L
Linus Torvalds 已提交
198 199 200 201 202 203 204 205
		field_flags = AML_FIELD_ACCESS_WORD;
		break;

	case AML_CREATE_DWORD_FIELD_OP:

		/* Offset is in bytes, field is one dword */

		bit_offset = 8 * offset;
L
Len Brown 已提交
206
		bit_count = 32;
L
Linus Torvalds 已提交
207 208 209 210 211 212 213 214
		field_flags = AML_FIELD_ACCESS_DWORD;
		break;

	case AML_CREATE_QWORD_FIELD_OP:

		/* Offset is in bytes, field is one qword */

		bit_offset = 8 * offset;
L
Len Brown 已提交
215
		bit_count = 64;
L
Linus Torvalds 已提交
216 217 218 219 220
		field_flags = AML_FIELD_ACCESS_QWORD;
		break;

	default:

B
Bob Moore 已提交
221
		ACPI_ERROR((AE_INFO,
222 223
			    "Unknown field creation opcode 0x%02X",
			    aml_opcode));
L
Linus Torvalds 已提交
224 225 226 227 228 229
		status = AE_AML_BAD_OPCODE;
		goto cleanup;
	}

	/* Entire field must fit within the current length of the buffer */

L
Len Brown 已提交
230
	if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
B
Bob Moore 已提交
231
		ACPI_ERROR((AE_INFO,
232
			    "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
B
Bob Moore 已提交
233 234 235 236
			    acpi_ut_get_node_name(result_desc),
			    bit_offset + bit_count,
			    acpi_ut_get_node_name(buffer_desc->buffer.node),
			    8 * (u32) buffer_desc->buffer.length));
L
Linus Torvalds 已提交
237 238 239 240 241 242
		status = AE_AML_BUFFER_LIMIT;
		goto cleanup;
	}

	/*
	 * Initialize areas of the field object that are common to all fields
R
Robert Moore 已提交
243 244
	 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
	 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
L
Linus Torvalds 已提交
245
	 */
246 247 248
	status =
	    acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
					     bit_offset, bit_count);
L
Len Brown 已提交
249
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
250 251 252 253 254 255 256
		goto cleanup;
	}

	obj_desc->buffer_field.buffer_obj = buffer_desc;

	/* Reference count for buffer_desc inherits obj_desc count */

R
Robert Moore 已提交
257
	buffer_desc->common.reference_count = (u16)
L
Len Brown 已提交
258 259
	    (buffer_desc->common.reference_count +
	     obj_desc->common.reference_count);
L
Linus Torvalds 已提交
260

261
cleanup:
L
Linus Torvalds 已提交
262 263 264

	/* Always delete the operands */

L
Len Brown 已提交
265 266
	acpi_ut_remove_reference(offset_desc);
	acpi_ut_remove_reference(buffer_desc);
L
Linus Torvalds 已提交
267 268

	if (aml_opcode == AML_CREATE_FIELD_OP) {
L
Len Brown 已提交
269
		acpi_ut_remove_reference(length_desc);
L
Linus Torvalds 已提交
270 271 272 273
	}

	/* On failure, delete the result descriptor */

L
Len Brown 已提交
274 275 276
	if (ACPI_FAILURE(status)) {
		acpi_ut_remove_reference(result_desc);	/* Result descriptor */
	} else {
L
Linus Torvalds 已提交
277 278 279 280 281
		/* Now the address and length are valid for this buffer_field */

		obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
	}

L
Len Brown 已提交
282
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
283 284
}

R
Robert Moore 已提交
285
/*******************************************************************************
L
Linus Torvalds 已提交
286 287 288 289
 *
 * FUNCTION:    acpi_ds_eval_buffer_field_operands
 *
 * PARAMETERS:  walk_state      - Current walk
290
 *              op              - A valid buffer_field Op object
L
Linus Torvalds 已提交
291 292 293 294 295 296
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get buffer_field Buffer and Index
 *              Called from acpi_ds_exec_end_op during buffer_field parse tree walk
 *
R
Robert Moore 已提交
297
 ******************************************************************************/
L
Linus Torvalds 已提交
298 299

acpi_status
L
Len Brown 已提交
300 301
acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
				   union acpi_parse_object *op)
L
Linus Torvalds 已提交
302
{
L
Len Brown 已提交
303 304 305 306
	acpi_status status;
	union acpi_operand_object *obj_desc;
	struct acpi_namespace_node *node;
	union acpi_parse_object *next_op;
L
Linus Torvalds 已提交
307

B
Bob Moore 已提交
308
	ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
L
Linus Torvalds 已提交
309 310 311 312 313

	/*
	 * This is where we evaluate the address and length fields of the
	 * create_xxx_field declaration
	 */
L
Len Brown 已提交
314
	node = op->common.node;
L
Linus Torvalds 已提交
315 316 317 318 319 320 321

	/* next_op points to the op that holds the Buffer */

	next_op = op->common.value.arg;

	/* Evaluate/create the address and length operands */

L
Len Brown 已提交
322 323 324
	status = acpi_ds_create_operands(walk_state, next_op);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
325 326
	}

L
Len Brown 已提交
327
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
328
	if (!obj_desc) {
L
Len Brown 已提交
329
		return_ACPI_STATUS(AE_NOT_EXIST);
L
Linus Torvalds 已提交
330 331 332 333
	}

	/* Resolve the operands */

334 335 336
	status =
	    acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
				     walk_state);
L
Len Brown 已提交
337
	if (ACPI_FAILURE(status)) {
338
		ACPI_ERROR((AE_INFO, "(%s) bad operand(s), status 0x%X",
B
Bob Moore 已提交
339 340
			    acpi_ps_get_opcode_name(op->common.aml_opcode),
			    status));
L
Linus Torvalds 已提交
341

L
Len Brown 已提交
342
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
343 344 345 346 347
	}

	/* Initialize the Buffer Field */

	if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
B
Bob Moore 已提交
348

L
Linus Torvalds 已提交
349 350
		/* NOTE: Slightly different operands for this opcode */

L
Len Brown 已提交
351 352 353 354 355 356 357
		status =
		    acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
					      walk_state->operands[0],
					      walk_state->operands[1],
					      walk_state->operands[2],
					      walk_state->operands[3]);
	} else {
L
Linus Torvalds 已提交
358 359
		/* All other, create_xxx_field opcodes */

L
Len Brown 已提交
360 361 362 363 364
		status =
		    acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
					      walk_state->operands[0],
					      walk_state->operands[1], NULL,
					      walk_state->operands[2]);
L
Linus Torvalds 已提交
365 366
	}

L
Len Brown 已提交
367
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
368 369
}

R
Robert Moore 已提交
370
/*******************************************************************************
L
Linus Torvalds 已提交
371 372 373 374
 *
 * FUNCTION:    acpi_ds_eval_region_operands
 *
 * PARAMETERS:  walk_state      - Current walk
375
 *              op              - A valid region Op object
L
Linus Torvalds 已提交
376 377 378 379 380 381
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get region address and length
 *              Called from acpi_ds_exec_end_op during op_region parse tree walk
 *
R
Robert Moore 已提交
382
 ******************************************************************************/
L
Linus Torvalds 已提交
383 384

acpi_status
L
Len Brown 已提交
385 386
acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
			     union acpi_parse_object *op)
L
Linus Torvalds 已提交
387
{
L
Len Brown 已提交
388 389 390 391 392
	acpi_status status;
	union acpi_operand_object *obj_desc;
	union acpi_operand_object *operand_desc;
	struct acpi_namespace_node *node;
	union acpi_parse_object *next_op;
L
Linus Torvalds 已提交
393

B
Bob Moore 已提交
394
	ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
L
Linus Torvalds 已提交
395 396

	/*
R
Robert Moore 已提交
397 398
	 * This is where we evaluate the address and length fields of the
	 * op_region declaration
L
Linus Torvalds 已提交
399
	 */
L
Len Brown 已提交
400
	node = op->common.node;
L
Linus Torvalds 已提交
401

402
	/* next_op points to the op that holds the space_ID */
L
Linus Torvalds 已提交
403 404 405 406 407 408 409 410 411

	next_op = op->common.value.arg;

	/* next_op points to address op */

	next_op = next_op->common.next;

	/* Evaluate/create the address and length operands */

L
Len Brown 已提交
412 413 414
	status = acpi_ds_create_operands(walk_state, next_op);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
415 416 417 418
	}

	/* Resolve the length and address operands to numbers */

419 420 421
	status =
	    acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
				     walk_state);
L
Len Brown 已提交
422 423
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
424 425
	}

L
Len Brown 已提交
426
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
427
	if (!obj_desc) {
L
Len Brown 已提交
428
		return_ACPI_STATUS(AE_NOT_EXIST);
L
Linus Torvalds 已提交
429 430 431 432 433 434 435 436 437
	}

	/*
	 * Get the length operand and save it
	 * (at Top of stack)
	 */
	operand_desc = walk_state->operands[walk_state->num_operands - 1];

	obj_desc->region.length = (u32) operand_desc->integer.value;
L
Len Brown 已提交
438
	acpi_ut_remove_reference(operand_desc);
L
Linus Torvalds 已提交
439 440 441 442 443 444 445

	/*
	 * Get the address and save it
	 * (at top of stack - 1)
	 */
	operand_desc = walk_state->operands[walk_state->num_operands - 2];

R
Robert Moore 已提交
446
	obj_desc->region.address = (acpi_physical_address)
L
Len Brown 已提交
447 448
	    operand_desc->integer.value;
	acpi_ut_remove_reference(operand_desc);
L
Linus Torvalds 已提交
449

B
Bob Moore 已提交
450
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
L
Len Brown 已提交
451
			  obj_desc,
452
			  ACPI_FORMAT_UINT64(obj_desc->region.address),
L
Len Brown 已提交
453
			  obj_desc->region.length));
L
Linus Torvalds 已提交
454 455 456 457

	/* Now the address and length are valid for this opregion */

	obj_desc->region.flags |= AOPOBJ_DATA_VALID;
L
Len Brown 已提交
458
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
459 460
}

461 462 463 464 465
/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_eval_table_region_operands
 *
 * PARAMETERS:  walk_state      - Current walk
466
 *              op              - A valid region Op object
467 468 469
 *
 * RETURN:      Status
 *
470 471 472
 * DESCRIPTION: Get region address and length.
 *              Called from acpi_ds_exec_end_op during data_table_region parse
 *              tree walk.
473 474 475 476 477 478 479 480 481 482 483 484 485
 *
 ******************************************************************************/

acpi_status
acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
				   union acpi_parse_object *op)
{
	acpi_status status;
	union acpi_operand_object *obj_desc;
	union acpi_operand_object **operand;
	struct acpi_namespace_node *node;
	union acpi_parse_object *next_op;
	struct acpi_table_header *table;
486
	u32 table_index;
487 488 489 490

	ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);

	/*
L
Lv Zheng 已提交
491 492
	 * This is where we evaluate the Signature string, oem_id string,
	 * and oem_table_id string of the Data Table Region declaration
493 494 495
	 */
	node = op->common.node;

L
Lv Zheng 已提交
496
	/* next_op points to Signature string op */
497 498 499 500

	next_op = op->common.value.arg;

	/*
L
Lv Zheng 已提交
501 502
	 * Evaluate/create the Signature string, oem_id string,
	 * and oem_table_id string operands
503 504 505 506 507 508
	 */
	status = acpi_ds_create_operands(walk_state, next_op);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

509 510
	operand = &walk_state->operands[0];

511
	/*
L
Lv Zheng 已提交
512 513
	 * Resolve the Signature string, oem_id string,
	 * and oem_table_id string operands
514
	 */
515 516 517
	status =
	    acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
				     walk_state);
518
	if (ACPI_FAILURE(status)) {
519
		goto cleanup;
520 521 522 523 524 525 526 527
	}

	/* Find the ACPI table */

	status = acpi_tb_find_table(operand[0]->string.pointer,
				    operand[1]->string.pointer,
				    operand[2]->string.pointer, &table_index);
	if (ACPI_FAILURE(status)) {
528 529 530 531 532 533 534 535
		if (status == AE_NOT_FOUND) {
			ACPI_ERROR((AE_INFO,
				    "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
				    operand[0]->string.pointer,
				    operand[1]->string.pointer,
				    operand[2]->string.pointer));
		}
		goto cleanup;
536 537 538 539
	}

	status = acpi_get_table_by_index(table_index, &table);
	if (ACPI_FAILURE(status)) {
540
		goto cleanup;
541 542 543 544
	}

	obj_desc = acpi_ns_get_attached_object(node);
	if (!obj_desc) {
545 546
		status = AE_NOT_EXIST;
		goto cleanup;
547 548
	}

549
	obj_desc->region.address = ACPI_PTR_TO_PHYSADDR(table);
550 551 552 553
	obj_desc->region.length = table->length;

	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
			  obj_desc,
554
			  ACPI_FORMAT_UINT64(obj_desc->region.address),
555 556 557 558 559 560
			  obj_desc->region.length));

	/* Now the address and length are valid for this opregion */

	obj_desc->region.flags |= AOPOBJ_DATA_VALID;

561 562 563 564 565
cleanup:
	acpi_ut_remove_reference(operand[0]);
	acpi_ut_remove_reference(operand[1]);
	acpi_ut_remove_reference(operand[2]);

566 567 568
	return_ACPI_STATUS(status);
}

R
Robert Moore 已提交
569
/*******************************************************************************
L
Linus Torvalds 已提交
570 571 572 573
 *
 * FUNCTION:    acpi_ds_eval_data_object_operands
 *
 * PARAMETERS:  walk_state      - Current walk
574
 *              op              - A valid data_object Op object
L
Linus Torvalds 已提交
575 576 577 578 579 580 581
 *              obj_desc        - data_object
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get the operands and complete the following data object types:
 *              Buffer, Package.
 *
R
Robert Moore 已提交
582
 ******************************************************************************/
L
Linus Torvalds 已提交
583 584

acpi_status
L
Len Brown 已提交
585 586 587
acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
				  union acpi_parse_object *op,
				  union acpi_operand_object *obj_desc)
L
Linus Torvalds 已提交
588
{
L
Len Brown 已提交
589 590 591
	acpi_status status;
	union acpi_operand_object *arg_desc;
	u32 length;
L
Linus Torvalds 已提交
592

B
Bob Moore 已提交
593
	ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
L
Linus Torvalds 已提交
594 595 596

	/* The first operand (for all of these data objects) is the length */

597 598 599 600 601 602
	/*
	 * Set proper index into operand stack for acpi_ds_obj_stack_push
	 * invoked inside acpi_ds_create_operand.
	 */
	walk_state->operand_index = walk_state->num_operands;

L
Len Brown 已提交
603 604 605
	status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
606 607
	}

L
Len Brown 已提交
608 609 610 611 612 613
	status = acpi_ex_resolve_operands(walk_state->opcode,
					  &(walk_state->
					    operands[walk_state->num_operands -
						     1]), walk_state);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
614 615 616 617
	}

	/* Extract length operand */

L
Len Brown 已提交
618
	arg_desc = walk_state->operands[walk_state->num_operands - 1];
L
Linus Torvalds 已提交
619 620 621 622
	length = (u32) arg_desc->integer.value;

	/* Cleanup for length operand */

L
Len Brown 已提交
623 624 625
	status = acpi_ds_obj_stack_pop(1, walk_state);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
626 627
	}

L
Len Brown 已提交
628
	acpi_ut_remove_reference(arg_desc);
L
Linus Torvalds 已提交
629 630 631 632 633 634 635

	/*
	 * Create the actual data object
	 */
	switch (op->common.aml_opcode) {
	case AML_BUFFER_OP:

L
Len Brown 已提交
636 637 638
		status =
		    acpi_ds_build_internal_buffer_obj(walk_state, op, length,
						      &obj_desc);
L
Linus Torvalds 已提交
639 640 641 642 643
		break;

	case AML_PACKAGE_OP:
	case AML_VAR_PACKAGE_OP:

L
Len Brown 已提交
644 645 646
		status =
		    acpi_ds_build_internal_package_obj(walk_state, op, length,
						       &obj_desc);
L
Linus Torvalds 已提交
647 648 649
		break;

	default:
650

L
Len Brown 已提交
651
		return_ACPI_STATUS(AE_AML_BAD_OPCODE);
L
Linus Torvalds 已提交
652 653
	}

L
Len Brown 已提交
654
	if (ACPI_SUCCESS(status)) {
L
Linus Torvalds 已提交
655
		/*
R
Robert Moore 已提交
656
		 * Return the object in the walk_state, unless the parent is a package -
L
Linus Torvalds 已提交
657 658 659 660
		 * in this case, the return object will be stored in the parse tree
		 * for the package.
		 */
		if ((!op->common.parent) ||
L
Len Brown 已提交
661 662 663
		    ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
		     (op->common.parent->common.aml_opcode !=
		      AML_VAR_PACKAGE_OP)
L
Lv Zheng 已提交
664 665
		     && (op->common.parent->common.aml_opcode !=
			 AML_NAME_OP))) {
L
Linus Torvalds 已提交
666 667 668 669
			walk_state->result_obj = obj_desc;
		}
	}

L
Len Brown 已提交
670
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
671 672
}

673 674 675 676 677
/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_eval_bank_field_operands
 *
 * PARAMETERS:  walk_state      - Current walk
678
 *              op              - A valid bank_field Op object
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get bank_field bank_value
 *              Called from acpi_ds_exec_end_op during bank_field parse tree walk
 *
 ******************************************************************************/

acpi_status
acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
				 union acpi_parse_object *op)
{
	acpi_status status;
	union acpi_operand_object *obj_desc;
	union acpi_operand_object *operand_desc;
	struct acpi_namespace_node *node;
	union acpi_parse_object *next_op;
	union acpi_parse_object *arg;

	ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op);

	/*
	 * This is where we evaluate the bank_value field of the
	 * bank_field declaration
	 */

	/* next_op points to the op that holds the Region */

	next_op = op->common.value.arg;

	/* next_op points to the op that holds the Bank Register */

	next_op = next_op->common.next;

	/* next_op points to the op that holds the Bank Value */

	next_op = next_op->common.next;

	/*
	 * Set proper index into operand stack for acpi_ds_obj_stack_push
	 * invoked inside acpi_ds_create_operand.
	 *
	 * We use walk_state->Operands[0] to store the evaluated bank_value
	 */
	walk_state->operand_index = 0;

	status = acpi_ds_create_operand(walk_state, next_op, 0);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

	status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

735 736
	ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
			   acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
	/*
	 * Get the bank_value operand and save it
	 * (at Top of stack)
	 */
	operand_desc = walk_state->operands[0];

	/* Arg points to the start Bank Field */

	arg = acpi_ps_get_arg(op, 4);
	while (arg) {

		/* Ignore OFFSET and ACCESSAS terms here */

		if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
			node = arg->common.node;

			obj_desc = acpi_ns_get_attached_object(node);
			if (!obj_desc) {
				return_ACPI_STATUS(AE_NOT_EXIST);
			}

			obj_desc->bank_field.value =
			    (u32) operand_desc->integer.value;
		}

		/* Move to next field in the list */

		arg = arg->common.next;
	}

	acpi_ut_remove_reference(operand_desc);
	return_ACPI_STATUS(status);
}