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

/*
L
Len Brown 已提交
8
 * Copyright (C) 2000 - 2008, 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>
45
#include <acpi/accommon.h>
L
Linus Torvalds 已提交
46 47 48 49 50 51 52
#include <acpi/amlcode.h>
#include <acpi/acdispat.h>
#include <acpi/acinterp.h>
#include <acpi/acnamesp.h>
#include <acpi/acparser.h>

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

R
Robert Moore 已提交
55 56
/* Local prototypes */
static acpi_status
L
Len Brown 已提交
57 58 59
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 已提交
60 61 62 63 64

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_buffer_field
 *
R
Robert Moore 已提交
65
 * PARAMETERS:  Op                  - Current parse op (create_xXField)
L
Linus Torvalds 已提交
66 67 68 69 70 71 72 73 74 75
 *              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 已提交
76
 *              create_field_op     (all of which define a field in a buffer)
L
Linus Torvalds 已提交
77 78 79 80
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
81 82
acpi_ds_create_buffer_field(union acpi_parse_object *op,
			    struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
83
{
L
Len Brown 已提交
84 85 86 87 88 89
	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 已提交
90

B
Bob Moore 已提交
91
	ACPI_FUNCTION_TRACE(ds_create_buffer_field);
L
Linus Torvalds 已提交
92

93 94 95
	/*
	 * Get the name_string argument (name of the new buffer_field)
	 */
L
Linus Torvalds 已提交
96
	if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
97 98 99

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

L
Len Brown 已提交
100 101
		arg = acpi_ps_get_arg(op, 3);
	} else {
102
		/* For all other create_xXXField operators, name is the 3rd argument */
L
Linus Torvalds 已提交
103

L
Len Brown 已提交
104
		arg = acpi_ps_get_arg(op, 2);
L
Linus Torvalds 已提交
105 106 107
	}

	if (!arg) {
L
Len Brown 已提交
108
		return_ACPI_STATUS(AE_AML_NO_OPERAND);
L
Linus Torvalds 已提交
109 110 111 112 113
	}

	if (walk_state->deferred_node) {
		node = walk_state->deferred_node;
		status = AE_OK;
L
Len Brown 已提交
114
	} else {
115 116 117 118
		/* 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 已提交
119 120
		}

121 122 123 124 125 126 127 128 129 130 131 132 133
		/* Creating new namespace node, should not already exist */

		flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
		    ACPI_NS_ERROR_IF_FOUND;

		/* Mark node temporary if we are executing a method */

		if (walk_state->method_node) {
			flags |= ACPI_NS_TEMPORARY;
		}

		/* Enter the name_string into the namespace */

L
Len Brown 已提交
134 135 136 137
		status =
		    acpi_ns_lookup(walk_state->scope_info,
				   arg->common.value.string, ACPI_TYPE_ANY,
				   ACPI_IMODE_LOAD_PASS1, flags, walk_state,
138
				   &node);
L
Len Brown 已提交
139
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
140
			ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
L
Len Brown 已提交
141
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
142 143 144
		}
	}

145 146
	/*
	 * We could put the returned object (Node) on the object stack for later,
R
Robert Moore 已提交
147
	 * but for now, we will put it in the "op" object that the parser uses,
148
	 * so we can get it again at the end of this scope.
L
Linus Torvalds 已提交
149 150 151 152
	 */
	op->common.node = node;

	/*
R
Robert Moore 已提交
153
	 * If there is no object attached to the node, this node was just created
154
	 * and we need to create the field object. Otherwise, this was a lookup
R
Robert Moore 已提交
155
	 * of an existing node and we don't want to create the field object again.
L
Linus Torvalds 已提交
156
	 */
L
Len Brown 已提交
157
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
158
	if (obj_desc) {
L
Len Brown 已提交
159
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
160 161 162 163 164 165 166 167 168
	}

	/*
	 * 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 已提交
169
	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
L
Linus Torvalds 已提交
170 171 172 173 174 175
	if (!obj_desc) {
		status = AE_NO_MEMORY;
		goto cleanup;
	}

	/*
176 177
	 * Remember location in AML stream of the field unit opcode and operands --
	 * since the buffer and index operands must be evaluated.
L
Linus Torvalds 已提交
178
	 */
L
Len Brown 已提交
179
	second_desc = obj_desc->common.next_object;
L
Linus Torvalds 已提交
180 181 182 183 184 185
	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 已提交
186 187
	status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
188 189 190
		goto cleanup;
	}

L
Len Brown 已提交
191
      cleanup:
L
Linus Torvalds 已提交
192 193 194

	/* Remove local reference to the object */

L
Len Brown 已提交
195 196
	acpi_ut_remove_reference(obj_desc);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_get_field_names
 *
 * PARAMETERS:  Info            - create_field info structure
 *  `           walk_state      - Current method state
 *              Arg             - First parser arg for the field name list
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Process all named fields in a field declaration.  Names are
 *              entered into the namespace.
 *
 ******************************************************************************/

R
Robert Moore 已提交
214
static acpi_status
L
Len Brown 已提交
215 216 217
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 已提交
218
{
L
Len Brown 已提交
219 220
	acpi_status status;
	acpi_integer position;
L
Linus Torvalds 已提交
221

B
Bob Moore 已提交
222
	ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
L
Linus Torvalds 已提交
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240

	/* First field starts at bit zero */

	info->field_bit_position = 0;

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

	while (arg) {
		/*
		 * Three types of field elements are handled:
		 * 1) Offset - specifies a bit offset
		 * 2) access_as - changes the access mode
		 * 3) Name - Enters a new named field into the namespace
		 */
		switch (arg->common.aml_opcode) {
		case AML_INT_RESERVEDFIELD_OP:

			position = (acpi_integer) info->field_bit_position
L
Len Brown 已提交
241
			    + (acpi_integer) arg->common.value.size;
L
Linus Torvalds 已提交
242 243

			if (position > ACPI_UINT32_MAX) {
B
Bob Moore 已提交
244 245
				ACPI_ERROR((AE_INFO,
					    "Bit offset within field too large (> 0xFFFFFFFF)"));
L
Len Brown 已提交
246
				return_ACPI_STATUS(AE_SUPPORT);
L
Linus Torvalds 已提交
247 248 249 250 251 252 253 254 255
			}

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

		case AML_INT_ACCESSFIELD_OP:

			/*
			 * Get a new access_type and access_attribute -- to be used for all
R
Robert Moore 已提交
256 257
			 * field units that follow, until field end or another access_as
			 * keyword.
L
Linus Torvalds 已提交
258
			 *
R
Robert Moore 已提交
259 260
			 * In field_flags, preserve the flag bits other than the
			 * ACCESS_TYPE bits
L
Linus Torvalds 已提交
261
			 */
R
Robert Moore 已提交
262
			info->field_flags = (u8)
L
Len Brown 已提交
263 264 265
			    ((info->
			      field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
			     ((u8) ((u32) arg->common.value.integer >> 8)));
L
Linus Torvalds 已提交
266 267 268 269 270 271

			info->attribute = (u8) (arg->common.value.integer);
			break;

		case AML_INT_NAMEDFIELD_OP:

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

L
Len Brown 已提交
274 275 276 277 278 279 280
			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 已提交
281 282
				ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
						     status);
283
				return_ACPI_STATUS(status);
L
Len Brown 已提交
284
			} else {
L
Linus Torvalds 已提交
285 286 287
				arg->common.node = info->field_node;
				info->field_bit_length = arg->common.value.size;

288
				/*
289 290 291 292
				 * 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.
293 294 295 296 297 298 299
				 */
				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 已提交
300 301 302 303 304 305
				}
			}

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

			position = (acpi_integer) info->field_bit_position
L
Len Brown 已提交
306
			    + (acpi_integer) arg->common.value.size;
L
Linus Torvalds 已提交
307 308

			if (position > ACPI_UINT32_MAX) {
B
Bob Moore 已提交
309 310 311 312 313
				ACPI_ERROR((AE_INFO,
					    "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
					    ACPI_CAST_PTR(char,
							  &info->field_node->
							  name)));
L
Len Brown 已提交
314
				return_ACPI_STATUS(AE_SUPPORT);
L
Linus Torvalds 已提交
315 316 317 318 319 320 321
			}

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

		default:

B
Bob Moore 已提交
322 323 324
			ACPI_ERROR((AE_INFO,
				    "Invalid opcode in field list: %X",
				    arg->common.aml_opcode));
L
Len Brown 已提交
325
			return_ACPI_STATUS(AE_AML_BAD_OPCODE);
L
Linus Torvalds 已提交
326 327 328 329 330
		}

		arg = arg->common.next;
	}

L
Len Brown 已提交
331
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_field
 *
 * PARAMETERS:  Op              - Op containing the Field definition and args
 *              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 已提交
349 350 351
acpi_ds_create_field(union acpi_parse_object *op,
		     struct acpi_namespace_node *region_node,
		     struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
352
{
L
Len Brown 已提交
353 354 355
	acpi_status status;
	union acpi_parse_object *arg;
	struct acpi_create_field_info info;
L
Linus Torvalds 已提交
356

B
Bob Moore 已提交
357
	ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
L
Linus Torvalds 已提交
358 359 360 361 362

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

	arg = op->common.value.arg;
	if (!region_node) {
L
Len Brown 已提交
363 364 365 366 367 368
		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);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
369
			ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
L
Len Brown 已提交
370
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
371 372 373 374 375 376 377 378 379 380 381 382 383 384
		}
	}

	/* 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 已提交
385
	status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
L
Linus Torvalds 已提交
386

L
Len Brown 已提交
387
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_init_field_objects
 *
 * PARAMETERS:  Op              - Op containing the Field definition and args
 *  `           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 已提交
406 407
acpi_ds_init_field_objects(union acpi_parse_object *op,
			   struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
408
{
L
Len Brown 已提交
409 410 411 412
	acpi_status status;
	union acpi_parse_object *arg = NULL;
	struct acpi_namespace_node *node;
	u8 type = 0;
413
	u32 flags;
L
Linus Torvalds 已提交
414

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

417 418 419 420 421 422 423 424 425 426 427
	/* 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);
428 429
	}

430 431 432 433
	/*
	 * Get the field_list argument for this opcode. This is the start of the
	 * list of field elements.
	 */
L
Linus Torvalds 已提交
434 435
	switch (walk_state->opcode) {
	case AML_FIELD_OP:
L
Len Brown 已提交
436
		arg = acpi_ps_get_arg(op, 2);
L
Linus Torvalds 已提交
437 438 439 440
		type = ACPI_TYPE_LOCAL_REGION_FIELD;
		break;

	case AML_BANK_FIELD_OP:
L
Len Brown 已提交
441
		arg = acpi_ps_get_arg(op, 4);
L
Linus Torvalds 已提交
442 443 444 445
		type = ACPI_TYPE_LOCAL_BANK_FIELD;
		break;

	case AML_INDEX_FIELD_OP:
L
Len Brown 已提交
446
		arg = acpi_ps_get_arg(op, 3);
L
Linus Torvalds 已提交
447 448 449 450
		type = ACPI_TYPE_LOCAL_INDEX_FIELD;
		break;

	default:
L
Len Brown 已提交
451
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
452 453
	}

454 455 456 457 458 459 460 461 462 463 464
	/* Creating new namespace node(s), should not already exist */

	flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
	    ACPI_NS_ERROR_IF_FOUND;

	/* Mark node(s) temporary if we are executing a method */

	if (walk_state->method_node) {
		flags |= ACPI_NS_TEMPORARY;
	}

L
Linus Torvalds 已提交
465 466
	/*
	 * Walk the list of entries in the field_list
467
	 * Note: field_list can be of zero length. In this case, Arg will be NULL.
L
Linus Torvalds 已提交
468 469
	 */
	while (arg) {
470 471 472 473
		/*
		 * Ignore OFFSET and ACCESSAS terms here; we are only interested in the
		 * field names in order to enter them into the namespace.
		 */
L
Linus Torvalds 已提交
474
		if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
L
Len Brown 已提交
475
			status = acpi_ns_lookup(walk_state->scope_info,
476 477 478
						(char *)&arg->named.name, type,
						ACPI_IMODE_LOAD_PASS1, flags,
						walk_state, &node);
L
Len Brown 已提交
479
			if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
480 481
				ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
						     status);
L
Linus Torvalds 已提交
482
				if (status != AE_ALREADY_EXISTS) {
L
Len Brown 已提交
483
					return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
484 485 486 487 488 489 490 491 492 493
				}

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

				status = AE_OK;
			}

			arg->common.node = node;
		}

494
		/* Get the next field element in the list */
L
Linus Torvalds 已提交
495 496 497 498

		arg = arg->common.next;
	}

L
Len Brown 已提交
499
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
500 501 502 503 504 505 506 507
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_bank_field
 *
 * PARAMETERS:  Op              - Op containing the Field definition and args
 *              region_node     - Object for the containing Operation Region
508
 *              walk_state      - Current method state
L
Linus Torvalds 已提交
509 510 511 512 513 514 515 516
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create a new bank field in the specified operation region
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
517 518 519
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 已提交
520
{
L
Len Brown 已提交
521 522 523
	acpi_status status;
	union acpi_parse_object *arg;
	struct acpi_create_field_info info;
L
Linus Torvalds 已提交
524

B
Bob Moore 已提交
525
	ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
L
Linus Torvalds 已提交
526 527 528 529 530

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

	arg = op->common.value.arg;
	if (!region_node) {
L
Len Brown 已提交
531 532 533 534 535 536
		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);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
537
			ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
L
Len Brown 已提交
538
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
539 540 541 542 543 544
		}
	}

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

	arg = arg->common.next;
L
Len Brown 已提交
545 546 547 548 549 550
	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 已提交
551
		ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
L
Len Brown 已提交
552
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
553 554
	}

555 556 557 558 559
	/*
	 * 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 已提交
560
	arg = arg->common.next;
561

L
Linus Torvalds 已提交
562 563 564 565 566 567 568 569 570 571
	/* 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;

572 573 574 575 576 577 578 579 580
	/*
	 * 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 已提交
581

582
	status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
L
Len Brown 已提交
583
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_index_field
 *
 * PARAMETERS:  Op              - Op containing the Field definition and args
 *              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 已提交
601 602 603
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 已提交
604
{
L
Len Brown 已提交
605 606 607
	acpi_status status;
	union acpi_parse_object *arg;
	struct acpi_create_field_info info;
L
Linus Torvalds 已提交
608

B
Bob Moore 已提交
609
	ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
L
Linus Torvalds 已提交
610 611 612 613

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

	arg = op->common.value.arg;
L
Len Brown 已提交
614 615 616 617 618 619
	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 已提交
620
		ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
L
Len Brown 已提交
621
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
622 623 624 625 626
	}

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

	arg = arg->common.next;
L
Len Brown 已提交
627 628 629 630 631 632
	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 已提交
633
		ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
L
Len Brown 已提交
634
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
635 636 637 638 639 640 641 642 643 644 645 646
	}

	/* 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 已提交
647
	status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
L
Linus Torvalds 已提交
648

L
Len Brown 已提交
649
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
650
}