dsfield.c 22.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: dsfield - Dispatcher field routines
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2012, 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
#include "accommon.h"
#include "amlcode.h"
#include "acdispat.h"
#include "acinterp.h"
#include "acnamesp.h"
#include "acparser.h"
L
Linus Torvalds 已提交
51 52

#define _COMPONENT          ACPI_DISPATCHER
L
Len Brown 已提交
53
ACPI_MODULE_NAME("dsfield")
L
Linus Torvalds 已提交
54

R
Robert Moore 已提交
55
/* Local prototypes */
56 57 58 59 60 61 62 63 64 65
#ifdef ACPI_ASL_COMPILER
#include "acdisasm.h"
static acpi_status
acpi_ds_create_external_region(acpi_status lookup_status,
			       union acpi_parse_object *op,
			       char *path,
			       struct acpi_walk_state *walk_state,
			       struct acpi_namespace_node **node);
#endif

R
Robert Moore 已提交
66
static acpi_status
L
Len Brown 已提交
67 68 69
acpi_ds_get_field_names(struct acpi_create_field_info *info,
			struct acpi_walk_state *walk_state,
			union acpi_parse_object *arg);
L
Linus Torvalds 已提交
70

71 72 73
#ifdef ACPI_ASL_COMPILER
/*******************************************************************************
 *
74
 * FUNCTION:    acpi_ds_create_external_region (iASL Disassembler only)
75 76
 *
 * PARAMETERS:  lookup_status   - Status from ns_lookup operation
77 78
 *              op              - Op containing the Field definition and args
 *              path            - Pathname of the region
79
 *  `           walk_state      - Current method state
80
 *              node            - Where the new region node is returned
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
 *              region node/object.
 *
 ******************************************************************************/

static acpi_status
acpi_ds_create_external_region(acpi_status lookup_status,
			       union acpi_parse_object *op,
			       char *path,
			       struct acpi_walk_state *walk_state,
			       struct acpi_namespace_node **node)
{
	acpi_status status;
	union acpi_operand_object *obj_desc;

	if (lookup_status != AE_NOT_FOUND) {
		return (lookup_status);
	}

	/*
	 * Table disassembly:
	 * operation_region not found. Generate an External for it, and
	 * insert the name into the namespace.
	 */
	acpi_dm_add_to_external_list(op, path, ACPI_TYPE_REGION, 0);
	status = acpi_ns_lookup(walk_state->scope_info, path, ACPI_TYPE_REGION,
				ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
				walk_state, node);
	if (ACPI_FAILURE(status)) {
		return (status);
	}

	/* Must create and install a region object for the new node */

	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
	if (!obj_desc) {
		return (AE_NO_MEMORY);
	}

	obj_desc->region.node = *node;
	status = acpi_ns_attach_object(*node, obj_desc, ACPI_TYPE_REGION);
	return (status);
}
#endif

L
Linus Torvalds 已提交
129 130 131 132
/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_buffer_field
 *
133
 * PARAMETERS:  op                  - Current parse op (create_XXField)
L
Linus Torvalds 已提交
134 135 136 137 138 139 140 141 142 143
 *              walk_state          - Current state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Execute the create_field operators:
 *              create_bit_field_op,
 *              create_byte_field_op,
 *              create_word_field_op,
 *              create_dword_field_op,
 *              create_qword_field_op,
R
Robert Moore 已提交
144
 *              create_field_op     (all of which define a field in a buffer)
L
Linus Torvalds 已提交
145 146 147 148
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
149 150
acpi_ds_create_buffer_field(union acpi_parse_object *op,
			    struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
151
{
L
Len Brown 已提交
152 153 154 155 156 157
	union acpi_parse_object *arg;
	struct acpi_namespace_node *node;
	acpi_status status;
	union acpi_operand_object *obj_desc;
	union acpi_operand_object *second_desc = NULL;
	u32 flags;
L
Linus Torvalds 已提交
158

B
Bob Moore 已提交
159
	ACPI_FUNCTION_TRACE(ds_create_buffer_field);
L
Linus Torvalds 已提交
160

161 162 163
	/*
	 * Get the name_string argument (name of the new buffer_field)
	 */
L
Linus Torvalds 已提交
164
	if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
165 166 167

		/* For create_field, name is the 4th argument */

L
Len Brown 已提交
168 169
		arg = acpi_ps_get_arg(op, 3);
	} else {
170
		/* For all other create_XXXField operators, name is the 3rd argument */
L
Linus Torvalds 已提交
171

L
Len Brown 已提交
172
		arg = acpi_ps_get_arg(op, 2);
L
Linus Torvalds 已提交
173 174 175
	}

	if (!arg) {
L
Len Brown 已提交
176
		return_ACPI_STATUS(AE_AML_NO_OPERAND);
L
Linus Torvalds 已提交
177 178 179 180 181
	}

	if (walk_state->deferred_node) {
		node = walk_state->deferred_node;
		status = AE_OK;
L
Len Brown 已提交
182
	} else {
183 184 185 186
		/* Execute flag should always be set when this function is entered */

		if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
			return_ACPI_STATUS(AE_AML_INTERNAL);
L
Linus Torvalds 已提交
187 188
		}

189 190 191 192 193
		/* Creating new namespace node, should not already exist */

		flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
		    ACPI_NS_ERROR_IF_FOUND;

194 195 196 197 198 199
		/*
		 * Mark node temporary if we are executing a normal control
		 * method. (Don't mark if this is a module-level code method)
		 */
		if (walk_state->method_node &&
		    !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
200 201 202 203 204
			flags |= ACPI_NS_TEMPORARY;
		}

		/* Enter the name_string into the namespace */

L
Len Brown 已提交
205 206 207 208
		status =
		    acpi_ns_lookup(walk_state->scope_info,
				   arg->common.value.string, ACPI_TYPE_ANY,
				   ACPI_IMODE_LOAD_PASS1, flags, walk_state,
209
				   &node);
L
Len Brown 已提交
210
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
211
			ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
L
Len Brown 已提交
212
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
213 214 215
		}
	}

216 217
	/*
	 * We could put the returned object (Node) on the object stack for later,
R
Robert Moore 已提交
218
	 * but for now, we will put it in the "op" object that the parser uses,
219
	 * so we can get it again at the end of this scope.
L
Linus Torvalds 已提交
220 221 222 223
	 */
	op->common.node = node;

	/*
R
Robert Moore 已提交
224
	 * If there is no object attached to the node, this node was just created
225
	 * and we need to create the field object. Otherwise, this was a lookup
R
Robert Moore 已提交
226
	 * of an existing node and we don't want to create the field object again.
L
Linus Torvalds 已提交
227
	 */
L
Len Brown 已提交
228
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
229
	if (obj_desc) {
L
Len Brown 已提交
230
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
231 232 233 234 235 236 237 238 239
	}

	/*
	 * The Field definition is not fully parsed at this time.
	 * (We must save the address of the AML for the buffer and index operands)
	 */

	/* Create the buffer field object */

L
Len Brown 已提交
240
	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
L
Linus Torvalds 已提交
241 242 243 244 245 246
	if (!obj_desc) {
		status = AE_NO_MEMORY;
		goto cleanup;
	}

	/*
247 248
	 * Remember location in AML stream of the field unit opcode and operands --
	 * since the buffer and index operands must be evaluated.
L
Linus Torvalds 已提交
249
	 */
L
Len Brown 已提交
250
	second_desc = obj_desc->common.next_object;
L
Linus Torvalds 已提交
251 252 253 254 255 256
	second_desc->extra.aml_start = op->named.data;
	second_desc->extra.aml_length = op->named.length;
	obj_desc->buffer_field.node = node;

	/* Attach constructed field descriptors to parent node */

L
Len Brown 已提交
257 258
	status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
259 260 261
		goto cleanup;
	}

L
Len Brown 已提交
262
      cleanup:
L
Linus Torvalds 已提交
263 264 265

	/* Remove local reference to the object */

L
Len Brown 已提交
266 267
	acpi_ut_remove_reference(obj_desc);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
268 269 270 271 272 273
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_get_field_names
 *
274
 * PARAMETERS:  info            - create_field info structure
L
Linus Torvalds 已提交
275
 *  `           walk_state      - Current method state
276
 *              arg             - First parser arg for the field name list
L
Linus Torvalds 已提交
277 278 279 280 281 282 283 284
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Process all named fields in a field declaration.  Names are
 *              entered into the namespace.
 *
 ******************************************************************************/

R
Robert Moore 已提交
285
static acpi_status
L
Len Brown 已提交
286 287 288
acpi_ds_get_field_names(struct acpi_create_field_info *info,
			struct acpi_walk_state *walk_state,
			union acpi_parse_object *arg)
L
Linus Torvalds 已提交
289
{
L
Len Brown 已提交
290
	acpi_status status;
291
	u64 position;
292
	union acpi_parse_object *child;
L
Linus Torvalds 已提交
293

B
Bob Moore 已提交
294
	ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
L
Linus Torvalds 已提交
295 296 297 298 299 300 301 302 303

	/* First field starts at bit zero */

	info->field_bit_position = 0;

	/* Process all elements in the field list (of parse nodes) */

	while (arg) {
		/*
304
		 * Four types of field elements are handled:
305 306
		 * 1) name - Enters a new named field into the namespace
		 * 2) offset - specifies a bit offset
307
		 * 3) access_as - changes the access mode/attributes
308
		 * 4) connection - Associate a resource template with the field
L
Linus Torvalds 已提交
309 310 311 312
		 */
		switch (arg->common.aml_opcode) {
		case AML_INT_RESERVEDFIELD_OP:

313 314
			position = (u64) info->field_bit_position
			    + (u64) arg->common.value.size;
L
Linus Torvalds 已提交
315 316

			if (position > ACPI_UINT32_MAX) {
B
Bob Moore 已提交
317 318
				ACPI_ERROR((AE_INFO,
					    "Bit offset within field too large (> 0xFFFFFFFF)"));
L
Len Brown 已提交
319
				return_ACPI_STATUS(AE_SUPPORT);
L
Linus Torvalds 已提交
320 321 322 323 324 325
			}

			info->field_bit_position = (u32) position;
			break;

		case AML_INT_ACCESSFIELD_OP:
326
		case AML_INT_EXTACCESSFIELD_OP:
L
Linus Torvalds 已提交
327
			/*
328 329 330 331 332
			 * Get new access_type, access_attribute, and access_length fields
			 * -- to be used for all field units that follow, until the
			 * end-of-field or another access_as keyword is encountered.
			 * NOTE. These three bytes are encoded in the integer value
			 * of the parseop for convenience.
L
Linus Torvalds 已提交
333
			 *
R
Robert Moore 已提交
334
			 * In field_flags, preserve the flag bits other than the
335
			 * ACCESS_TYPE bits.
L
Linus Torvalds 已提交
336
			 */
337 338 339

			/* access_type (byte_acc, word_acc, etc.) */

R
Robert Moore 已提交
340
			info->field_flags = (u8)
L
Len Brown 已提交
341 342
			    ((info->
			      field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
			     ((u8)((u32)(arg->common.value.integer & 0x07))));

			/* access_attribute (attrib_quick, attrib_byte, etc.) */

			info->attribute =
			    (u8)((arg->common.value.integer >> 8) & 0xFF);

			/* access_length (for serial/buffer protocols) */

			info->access_length =
			    (u8)((arg->common.value.integer >> 16) & 0xFF);
			break;

		case AML_INT_CONNECTION_OP:
			/*
			 * Clear any previous connection. New connection is used for all
			 * fields that follow, similar to access_as
			 */
			info->resource_buffer = NULL;
			info->connection_node = NULL;
L
Linus Torvalds 已提交
363

364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
			/*
			 * A Connection() is either an actual resource descriptor (buffer)
			 * or a named reference to a resource template
			 */
			child = arg->common.value.arg;
			if (child->common.aml_opcode == AML_INT_BYTELIST_OP) {
				info->resource_buffer = child->named.data;
				info->resource_length =
				    (u16)child->named.value.integer;
			} else {
				/* Lookup the Connection() namepath, it should already exist */

				status = acpi_ns_lookup(walk_state->scope_info,
							child->common.value.
							name, ACPI_TYPE_ANY,
							ACPI_IMODE_EXECUTE,
							ACPI_NS_DONT_OPEN_SCOPE,
							walk_state,
							&info->connection_node);
				if (ACPI_FAILURE(status)) {
					ACPI_ERROR_NAMESPACE(child->common.
							     value.name,
							     status);
					return_ACPI_STATUS(status);
				}
			}
L
Linus Torvalds 已提交
390 391 392 393
			break;

		case AML_INT_NAMEDFIELD_OP:

394
			/* Lookup the name, it should already exist */
L
Linus Torvalds 已提交
395

L
Len Brown 已提交
396 397 398 399 400 401 402
			status = acpi_ns_lookup(walk_state->scope_info,
						(char *)&arg->named.name,
						info->field_type,
						ACPI_IMODE_EXECUTE,
						ACPI_NS_DONT_OPEN_SCOPE,
						walk_state, &info->field_node);
			if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
403 404
				ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
						     status);
405
				return_ACPI_STATUS(status);
L
Len Brown 已提交
406
			} else {
L
Linus Torvalds 已提交
407 408 409
				arg->common.node = info->field_node;
				info->field_bit_length = arg->common.value.size;

410
				/*
411 412 413 414
				 * If there is no object attached to the node, this node was
				 * just created and we need to create the field object.
				 * Otherwise, this was a lookup of an existing node and we
				 * don't want to create the field object again.
415 416 417 418 419 420 421
				 */
				if (!acpi_ns_get_attached_object
				    (info->field_node)) {
					status = acpi_ex_prep_field_value(info);
					if (ACPI_FAILURE(status)) {
						return_ACPI_STATUS(status);
					}
L
Linus Torvalds 已提交
422 423 424 425 426
				}
			}

			/* Keep track of bit position for the next field */

427 428
			position = (u64) info->field_bit_position
			    + (u64) arg->common.value.size;
L
Linus Torvalds 已提交
429 430

			if (position > ACPI_UINT32_MAX) {
B
Bob Moore 已提交
431 432 433 434 435
				ACPI_ERROR((AE_INFO,
					    "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
					    ACPI_CAST_PTR(char,
							  &info->field_node->
							  name)));
L
Len Brown 已提交
436
				return_ACPI_STATUS(AE_SUPPORT);
L
Linus Torvalds 已提交
437 438 439 440 441 442 443
			}

			info->field_bit_position += info->field_bit_length;
			break;

		default:

B
Bob Moore 已提交
444
			ACPI_ERROR((AE_INFO,
445
				    "Invalid opcode in field list: 0x%X",
B
Bob Moore 已提交
446
				    arg->common.aml_opcode));
L
Len Brown 已提交
447
			return_ACPI_STATUS(AE_AML_BAD_OPCODE);
L
Linus Torvalds 已提交
448 449 450 451 452
		}

		arg = arg->common.next;
	}

L
Len Brown 已提交
453
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
454 455 456 457 458 459
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_field
 *
460
 * PARAMETERS:  op              - Op containing the Field definition and args
L
Linus Torvalds 已提交
461 462 463 464 465 466 467 468 469 470
 *              region_node     - Object for the containing Operation Region
 *  `           walk_state      - Current method state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create a new field in the specified operation region
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
471 472 473
acpi_ds_create_field(union acpi_parse_object *op,
		     struct acpi_namespace_node *region_node,
		     struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
474
{
L
Len Brown 已提交
475 476 477
	acpi_status status;
	union acpi_parse_object *arg;
	struct acpi_create_field_info info;
L
Linus Torvalds 已提交
478

B
Bob Moore 已提交
479
	ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
L
Linus Torvalds 已提交
480 481 482 483

	/* First arg is the name of the parent op_region (must already exist) */

	arg = op->common.value.arg;
484

L
Linus Torvalds 已提交
485
	if (!region_node) {
L
Len Brown 已提交
486 487 488 489 490
		status =
		    acpi_ns_lookup(walk_state->scope_info,
				   arg->common.value.name, ACPI_TYPE_REGION,
				   ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
				   walk_state, &region_node);
491 492 493 494 495 496
#ifdef ACPI_ASL_COMPILER
		status = acpi_ds_create_external_region(status, arg,
							arg->common.value.name,
							walk_state,
							&region_node);
#endif
L
Len Brown 已提交
497
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
498
			ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
L
Len Brown 已提交
499
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
500 501 502
		}
	}

503 504
	ACPI_MEMSET(&info, 0, sizeof(struct acpi_create_field_info));

L
Linus Torvalds 已提交
505 506 507 508 509 510 511 512 513 514 515
	/* Second arg is the field flags */

	arg = arg->common.next;
	info.field_flags = (u8) arg->common.value.integer;
	info.attribute = 0;

	/* Each remaining arg is a Named Field */

	info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
	info.region_node = region_node;

L
Len Brown 已提交
516 517
	status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
518 519 520 521 522 523
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_init_field_objects
 *
524
 * PARAMETERS:  op              - Op containing the Field definition and args
L
Linus Torvalds 已提交
525 526 527 528 529 530 531 532 533 534 535
 *  `           walk_state      - Current method state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: For each "Field Unit" name in the argument list that is
 *              part of the field declaration, enter the name into the
 *              namespace.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
536 537
acpi_ds_init_field_objects(union acpi_parse_object *op,
			   struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
538
{
L
Len Brown 已提交
539 540 541 542
	acpi_status status;
	union acpi_parse_object *arg = NULL;
	struct acpi_namespace_node *node;
	u8 type = 0;
543
	u32 flags;
L
Linus Torvalds 已提交
544

B
Bob Moore 已提交
545
	ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
L
Linus Torvalds 已提交
546

547 548 549 550 551 552 553 554 555 556 557
	/* Execute flag should always be set when this function is entered */

	if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
		if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) {

			/* bank_field Op is deferred, just return OK */

			return_ACPI_STATUS(AE_OK);
		}

		return_ACPI_STATUS(AE_AML_INTERNAL);
558 559
	}

560 561 562 563
	/*
	 * Get the field_list argument for this opcode. This is the start of the
	 * list of field elements.
	 */
L
Linus Torvalds 已提交
564 565
	switch (walk_state->opcode) {
	case AML_FIELD_OP:
L
Len Brown 已提交
566
		arg = acpi_ps_get_arg(op, 2);
L
Linus Torvalds 已提交
567 568 569 570
		type = ACPI_TYPE_LOCAL_REGION_FIELD;
		break;

	case AML_BANK_FIELD_OP:
L
Len Brown 已提交
571
		arg = acpi_ps_get_arg(op, 4);
L
Linus Torvalds 已提交
572 573 574 575
		type = ACPI_TYPE_LOCAL_BANK_FIELD;
		break;

	case AML_INDEX_FIELD_OP:
L
Len Brown 已提交
576
		arg = acpi_ps_get_arg(op, 3);
L
Linus Torvalds 已提交
577 578 579 580
		type = ACPI_TYPE_LOCAL_INDEX_FIELD;
		break;

	default:
L
Len Brown 已提交
581
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
582 583
	}

584 585 586 587 588
	/* Creating new namespace node(s), should not already exist */

	flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
	    ACPI_NS_ERROR_IF_FOUND;

589 590 591 592 593 594
	/*
	 * Mark node(s) temporary if we are executing a normal control
	 * method. (Don't mark if this is a module-level code method)
	 */
	if (walk_state->method_node &&
	    !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
595 596 597
		flags |= ACPI_NS_TEMPORARY;
	}

L
Linus Torvalds 已提交
598 599
	/*
	 * Walk the list of entries in the field_list
600
	 * Note: field_list can be of zero length. In this case, Arg will be NULL.
L
Linus Torvalds 已提交
601 602
	 */
	while (arg) {
603
		/*
604 605
		 * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
		 * in the field names in order to enter them into the namespace.
606
		 */
L
Linus Torvalds 已提交
607
		if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
L
Len Brown 已提交
608
			status = acpi_ns_lookup(walk_state->scope_info,
609 610 611
						(char *)&arg->named.name, type,
						ACPI_IMODE_LOAD_PASS1, flags,
						walk_state, &node);
L
Len Brown 已提交
612
			if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
613 614
				ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
						     status);
L
Linus Torvalds 已提交
615
				if (status != AE_ALREADY_EXISTS) {
L
Len Brown 已提交
616
					return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
617 618 619 620 621 622 623 624 625 626
				}

				/* Name already exists, just ignore this error */

				status = AE_OK;
			}

			arg->common.node = node;
		}

627
		/* Get the next field element in the list */
L
Linus Torvalds 已提交
628 629 630 631

		arg = arg->common.next;
	}

L
Len Brown 已提交
632
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
633 634 635 636 637 638
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_bank_field
 *
639
 * PARAMETERS:  op              - Op containing the Field definition and args
L
Linus Torvalds 已提交
640
 *              region_node     - Object for the containing Operation Region
641
 *              walk_state      - Current method state
L
Linus Torvalds 已提交
642 643 644 645 646 647 648 649
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create a new bank field in the specified operation region
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
650 651 652
acpi_ds_create_bank_field(union acpi_parse_object *op,
			  struct acpi_namespace_node *region_node,
			  struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
653
{
L
Len Brown 已提交
654 655 656
	acpi_status status;
	union acpi_parse_object *arg;
	struct acpi_create_field_info info;
L
Linus Torvalds 已提交
657

B
Bob Moore 已提交
658
	ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
L
Linus Torvalds 已提交
659 660 661 662 663

	/* First arg is the name of the parent op_region (must already exist) */

	arg = op->common.value.arg;
	if (!region_node) {
L
Len Brown 已提交
664 665 666 667 668
		status =
		    acpi_ns_lookup(walk_state->scope_info,
				   arg->common.value.name, ACPI_TYPE_REGION,
				   ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
				   walk_state, &region_node);
669 670 671 672 673 674
#ifdef ACPI_ASL_COMPILER
		status = acpi_ds_create_external_region(status, arg,
							arg->common.value.name,
							walk_state,
							&region_node);
#endif
L
Len Brown 已提交
675
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
676
			ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
L
Len Brown 已提交
677
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
678 679 680 681 682 683
		}
	}

	/* Second arg is the Bank Register (Field) (must already exist) */

	arg = arg->common.next;
L
Len Brown 已提交
684 685 686 687 688 689
	status =
	    acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
			   ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
			   ACPI_NS_SEARCH_PARENT, walk_state,
			   &info.register_node);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
690
		ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
L
Len Brown 已提交
691
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
692 693
	}

694 695 696 697 698
	/*
	 * Third arg is the bank_value
	 * This arg is a term_arg, not a constant
	 * It will be evaluated later, by acpi_ds_eval_bank_field_operands
	 */
L
Linus Torvalds 已提交
699
	arg = arg->common.next;
700

L
Linus Torvalds 已提交
701 702 703 704 705 706 707 708 709 710
	/* Fourth arg is the field flags */

	arg = arg->common.next;
	info.field_flags = (u8) arg->common.value.integer;

	/* Each remaining arg is a Named Field */

	info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
	info.region_node = region_node;

711 712 713 714 715 716 717 718 719
	/*
	 * Use Info.data_register_node to store bank_field Op
	 * It's safe because data_register_node will never be used when create bank field
	 * We store aml_start and aml_length in the bank_field Op for late evaluation
	 * Used in acpi_ex_prep_field_value(Info)
	 *
	 * TBD: Or, should we add a field in struct acpi_create_field_info, like "void *ParentOp"?
	 */
	info.data_register_node = (struct acpi_namespace_node *)op;
L
Linus Torvalds 已提交
720

721
	status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
L
Len Brown 已提交
722
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
723 724 725 726 727 728
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_index_field
 *
729
 * PARAMETERS:  op              - Op containing the Field definition and args
L
Linus Torvalds 已提交
730 731 732 733 734 735 736 737 738 739
 *              region_node     - Object for the containing Operation Region
 *  `           walk_state      - Current method state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create a new index field in the specified operation region
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
740 741 742
acpi_ds_create_index_field(union acpi_parse_object *op,
			   struct acpi_namespace_node *region_node,
			   struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
743
{
L
Len Brown 已提交
744 745 746
	acpi_status status;
	union acpi_parse_object *arg;
	struct acpi_create_field_info info;
L
Linus Torvalds 已提交
747

B
Bob Moore 已提交
748
	ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
L
Linus Torvalds 已提交
749 750 751 752

	/* First arg is the name of the Index register (must already exist) */

	arg = op->common.value.arg;
L
Len Brown 已提交
753 754 755 756 757 758
	status =
	    acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
			   ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
			   ACPI_NS_SEARCH_PARENT, walk_state,
			   &info.register_node);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
759
		ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
L
Len Brown 已提交
760
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
761 762 763 764 765
	}

	/* Second arg is the data register (must already exist) */

	arg = arg->common.next;
L
Len Brown 已提交
766 767 768 769 770 771
	status =
	    acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
			   ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
			   ACPI_NS_SEARCH_PARENT, walk_state,
			   &info.data_register_node);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
772
		ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
L
Len Brown 已提交
773
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
774 775 776 777 778 779 780 781 782 783 784 785
	}

	/* Next arg is the field flags */

	arg = arg->common.next;
	info.field_flags = (u8) arg->common.value.integer;

	/* Each remaining arg is a Named Field */

	info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
	info.region_node = region_node;

L
Len Brown 已提交
786 787
	status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
788
}