dsopcode.c 20.5 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 */

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

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

	obj_desc->buffer_field.buffer_obj = buffer_desc;

	/* Reference count for buffer_desc inherits obj_desc count */

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

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

	/* Always delete the operands */

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

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

	/* On failure, delete the result descriptor */

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

		obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
	}

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

R
Robert Moore 已提交
284
/*******************************************************************************
L
Linus Torvalds 已提交
285 286 287 288
 *
 * FUNCTION:    acpi_ds_eval_buffer_field_operands
 *
 * PARAMETERS:  walk_state      - Current walk
289
 *              op              - A valid buffer_field Op object
L
Linus Torvalds 已提交
290 291 292 293 294 295
 *
 * 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 已提交
296
 ******************************************************************************/
L
Linus Torvalds 已提交
297 298

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

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

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

	/* 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 已提交
321 322 323
	status = acpi_ds_create_operands(walk_state, next_op);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
324 325
	}

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

	/* Resolve the operands */

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

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

	/* Initialize the Buffer Field */

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

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

L
Len Brown 已提交
350 351 352 353 354 355 356
		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 已提交
357 358
		/* All other, create_xxx_field opcodes */

L
Len Brown 已提交
359 360 361 362 363
		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 已提交
364 365
	}

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

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

acpi_status
L
Len Brown 已提交
384 385
acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
			     union acpi_parse_object *op)
L
Linus Torvalds 已提交
386
{
L
Len Brown 已提交
387 388 389 390 391
	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 已提交
392

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

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

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

	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 已提交
411 412 413
	status = acpi_ds_create_operands(walk_state, next_op);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
414 415 416 417
	}

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

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

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

	/*
	 * 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 已提交
437
	acpi_ut_remove_reference(operand_desc);
L
Linus Torvalds 已提交
438 439 440 441 442 443 444

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

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

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

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

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

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

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;
485
	u32 table_index;
486 487 488 489

	ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);

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

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

	next_op = op->common.value.arg;

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

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

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

	/* 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)) {
527 528 529 530 531 532 533 534
		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;
535 536 537 538
	}

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

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

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

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

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

	obj_desc->region.flags |= AOPOBJ_DATA_VALID;

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

565 566 567
	return_ACPI_STATUS(status);
}

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

acpi_status
L
Len Brown 已提交
584 585 586
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 已提交
587
{
L
Len Brown 已提交
588 589 590
	acpi_status status;
	union acpi_operand_object *arg_desc;
	u32 length;
L
Linus Torvalds 已提交
591

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

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

596 597 598 599 600 601
	/*
	 * 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 已提交
602 603 604
	status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
605 606
	}

L
Len Brown 已提交
607 608 609 610 611 612
	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 已提交
613 614 615 616
	}

	/* Extract length operand */

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

	/* Cleanup for length operand */

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

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

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

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

	case AML_PACKAGE_OP:
641
	case AML_VARIABLE_PACKAGE_OP:
L
Linus Torvalds 已提交
642

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

	default:
649

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

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

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

672 673 674 675 676
/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_eval_bank_field_operands
 *
 * PARAMETERS:  walk_state      - Current walk
677
 *              op              - A valid bank_field Op object
678 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
 *
 * 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);
	}

734 735
	ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
			   acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
736 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
	/*
	 * 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);
}