psargs.c 21.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: psargs - Parse AML opcode arguments
 *
 *****************************************************************************/

/*
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
#include "accommon.h"
#include "acparser.h"
#include "amlcode.h"
#include "acnamesp.h"
#include "acdispat.h"
L
Linus Torvalds 已提交
50 51

#define _COMPONENT          ACPI_PARSER
L
Len Brown 已提交
52
ACPI_MODULE_NAME("psargs")
L
Linus Torvalds 已提交
53

R
Robert Moore 已提交
54 55
/* Local prototypes */
static u32
L
Len Brown 已提交
56
acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
R
Robert Moore 已提交
57

L
Len Brown 已提交
58 59
static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
						       *parser_state);
L
Linus Torvalds 已提交
60 61 62 63 64 65 66

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_next_package_length
 *
 * PARAMETERS:  parser_state        - Current parser state object
 *
B
Bob Moore 已提交
67
 * RETURN:      Decoded package length. On completion, the AML pointer points
L
Linus Torvalds 已提交
68 69
 *              past the length byte or bytes.
 *
B
Bob Moore 已提交
70 71
 * DESCRIPTION: Decode and return a package length field.
 *              Note: Largest package length is 28 bits, from ACPI specification
L
Linus Torvalds 已提交
72 73 74
 *
 ******************************************************************************/

R
Robert Moore 已提交
75
static u32
L
Len Brown 已提交
76
acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
L
Linus Torvalds 已提交
77
{
B
Bob Moore 已提交
78 79
	u8 *aml = parser_state->aml;
	u32 package_length = 0;
80
	u32 byte_count;
B
Bob Moore 已提交
81
	u8 byte_zero_mask = 0x3F;	/* Default [0:5] */
L
Linus Torvalds 已提交
82

B
Bob Moore 已提交
83
	ACPI_FUNCTION_TRACE(ps_get_next_package_length);
L
Linus Torvalds 已提交
84

B
Bob Moore 已提交
85 86 87 88 89
	/*
	 * Byte 0 bits [6:7] contain the number of additional bytes
	 * used to encode the package length, either 0,1,2, or 3
	 */
	byte_count = (aml[0] >> 6);
90
	parser_state->aml += ((acpi_size) byte_count + 1);
L
Linus Torvalds 已提交
91

B
Bob Moore 已提交
92
	/* Get bytes 3, 2, 1 as needed */
L
Linus Torvalds 已提交
93

B
Bob Moore 已提交
94 95 96 97 98 99 100 101 102
	while (byte_count) {
		/*
		 * Final bit positions for the package length bytes:
		 *      Byte3->[20:27]
		 *      Byte2->[12:19]
		 *      Byte1->[04:11]
		 *      Byte0->[00:03]
		 */
		package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
L
Linus Torvalds 已提交
103

B
Bob Moore 已提交
104 105
		byte_zero_mask = 0x0F;	/* Use bits [0:3] of byte 0 */
		byte_count--;
L
Linus Torvalds 已提交
106 107
	}

B
Bob Moore 已提交
108 109 110 111
	/* Byte 0 is a special case, either bits [0:3] or [0:5] are used */

	package_length |= (aml[0] & byte_zero_mask);
	return_UINT32(package_length);
L
Linus Torvalds 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_next_package_end
 *
 * PARAMETERS:  parser_state        - Current parser state object
 *
 * RETURN:      Pointer to end-of-package +1
 *
 * DESCRIPTION: Get next package length and return a pointer past the end of
 *              the package.  Consumes the package length field
 *
 ******************************************************************************/

L
Len Brown 已提交
127
u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state)
L
Linus Torvalds 已提交
128
{
L
Len Brown 已提交
129
	u8 *start = parser_state->aml;
B
Bob Moore 已提交
130
	u32 package_length;
L
Linus Torvalds 已提交
131

B
Bob Moore 已提交
132
	ACPI_FUNCTION_TRACE(ps_get_next_package_end);
L
Linus Torvalds 已提交
133

B
Bob Moore 已提交
134
	/* Function below updates parser_state->Aml */
L
Linus Torvalds 已提交
135

B
Bob Moore 已提交
136
	package_length = acpi_ps_get_next_package_length(parser_state);
L
Linus Torvalds 已提交
137

B
Bob Moore 已提交
138
	return_PTR(start + package_length);	/* end of package */
L
Linus Torvalds 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_next_namestring
 *
 * PARAMETERS:  parser_state        - Current parser state object
 *
 * RETURN:      Pointer to the start of the name string (pointer points into
 *              the AML.
 *
 * DESCRIPTION: Get next raw namestring within the AML stream.  Handles all name
 *              prefix characters.  Set parser state to point past the string.
 *              (Name is consumed from the AML.)
 *
 ******************************************************************************/

L
Len Brown 已提交
156
char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state)
L
Linus Torvalds 已提交
157
{
L
Len Brown 已提交
158 159
	u8 *start = parser_state->aml;
	u8 *end = parser_state->aml;
L
Linus Torvalds 已提交
160

B
Bob Moore 已提交
161
	ACPI_FUNCTION_TRACE(ps_get_next_namestring);
L
Linus Torvalds 已提交
162

B
Bob Moore 已提交
163
	/* Point past any namestring prefix characters (backslash or carat) */
L
Linus Torvalds 已提交
164

B
Bob Moore 已提交
165
	while (acpi_ps_is_prefix_char(*end)) {
L
Linus Torvalds 已提交
166 167 168
		end++;
	}

B
Bob Moore 已提交
169
	/* Decode the path prefix character */
L
Linus Torvalds 已提交
170

B
Bob Moore 已提交
171
	switch (*end) {
L
Linus Torvalds 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
	case 0:

		/* null_name */

		if (end == start) {
			start = NULL;
		}
		end++;
		break;

	case AML_DUAL_NAME_PREFIX:

		/* Two name segments */

		end += 1 + (2 * ACPI_NAME_SIZE);
		break;

	case AML_MULTI_NAME_PREFIX_OP:

B
Bob Moore 已提交
191
		/* Multiple name segments, 4 chars each, count in next byte */
L
Linus Torvalds 已提交
192

B
Bob Moore 已提交
193
		end += 2 + (*(end + 1) * ACPI_NAME_SIZE);
L
Linus Torvalds 已提交
194 195 196 197 198 199 200 201 202 203
		break;

	default:

		/* Single name segment */

		end += ACPI_NAME_SIZE;
		break;
	}

B
Bob Moore 已提交
204
	parser_state->aml = end;
L
Len Brown 已提交
205
	return_PTR((char *)start);
L
Linus Torvalds 已提交
206 207 208 209 210 211 212
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_next_namepath
 *
 * PARAMETERS:  parser_state        - Current parser state object
213
 *              arg                 - Where the namepath will be stored
L
Linus Torvalds 已提交
214 215
 *              arg_count           - If the namepath points to a control method
 *                                    the method's argument is returned here.
B
Bob Moore 已提交
216
 *              possible_method_call - Whether the namepath can possibly be the
L
Linus Torvalds 已提交
217 218 219 220 221 222 223 224 225 226 227 228 229
 *                                    start of a method call
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get next name (if method call, return # of required args).
 *              Names are looked up in the internal namespace to determine
 *              if the name represents a control method.  If a method
 *              is found, the number of arguments to the method is returned.
 *              This information is critical for parsing to continue correctly.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
230 231
acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
			  struct acpi_parse_state *parser_state,
B
Bob Moore 已提交
232
			  union acpi_parse_object *arg, u8 possible_method_call)
L
Linus Torvalds 已提交
233
{
234
	acpi_status status;
L
Len Brown 已提交
235 236 237 238
	char *path;
	union acpi_parse_object *name_op;
	union acpi_operand_object *method_desc;
	struct acpi_namespace_node *node;
239
	u8 *start = parser_state->aml;
L
Linus Torvalds 已提交
240

B
Bob Moore 已提交
241
	ACPI_FUNCTION_TRACE(ps_get_next_namepath);
L
Linus Torvalds 已提交
242

L
Len Brown 已提交
243
	path = acpi_ps_get_next_namestring(parser_state);
B
Bob Moore 已提交
244
	acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
L
Linus Torvalds 已提交
245

B
Bob Moore 已提交
246
	/* Null path case is allowed, just exit */
L
Linus Torvalds 已提交
247

B
Bob Moore 已提交
248 249 250 251 252 253
	if (!path) {
		arg->common.value.name = path;
		return_ACPI_STATUS(AE_OK);
	}

	/*
254 255 256
	 * Lookup the name in the internal namespace, starting with the current
	 * scope. We don't want to add anything new to the namespace here,
	 * however, so we use MODE_EXECUTE.
B
Bob Moore 已提交
257 258 259 260
	 * Allow searching of the parent tree, but don't open a new scope -
	 * we just want to lookup the object (must be mode EXECUTE to perform
	 * the upsearch)
	 */
261 262 263 264
	status = acpi_ns_lookup(walk_state->scope_info, path,
				ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
				ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
				NULL, &node);
B
Bob Moore 已提交
265 266 267 268 269 270 271

	/*
	 * If this name is a control method invocation, we must
	 * setup the method call
	 */
	if (ACPI_SUCCESS(status) &&
	    possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
272
		if (walk_state->opcode == AML_UNLOAD_OP) {
273 274 275 276 277 278 279 280 281
			/*
			 * acpi_ps_get_next_namestring has increased the AML pointer,
			 * so we need to restore the saved AML pointer for method call.
			 */
			walk_state->parser_state.aml = start;
			walk_state->arg_count = 1;
			acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
			return_ACPI_STATUS(AE_OK);
		}
B
Bob Moore 已提交
282

B
Bob Moore 已提交
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
		/* This name is actually a control method invocation */

		method_desc = acpi_ns_get_attached_object(node);
		ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
				  "Control Method - %p Desc %p Path=%p\n", node,
				  method_desc, path));

		name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
		if (!name_op) {
			return_ACPI_STATUS(AE_NO_MEMORY);
		}

		/* Change Arg into a METHOD CALL and attach name to it */

		acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
		name_op->common.value.name = path;

		/* Point METHODCALL/NAME to the METHOD Node */

		name_op->common.node = node;
		acpi_ps_append_arg(arg, name_op);

		if (!method_desc) {
B
Bob Moore 已提交
306 307 308
			ACPI_ERROR((AE_INFO,
				    "Control Method %p has no attached object",
				    node));
B
Bob Moore 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
			return_ACPI_STATUS(AE_AML_INTERNAL);
		}

		ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
				  "Control Method - %p Args %X\n",
				  node, method_desc->method.param_count));

		/* Get the number of arguments to expect */

		walk_state->arg_count = method_desc->method.param_count;
		return_ACPI_STATUS(AE_OK);
	}

	/*
	 * Special handling if the name was not found during the lookup -
	 * some not_found cases are allowed
	 */
	if (status == AE_NOT_FOUND) {
B
Bob Moore 已提交
327

B
Bob Moore 已提交
328 329 330 331 332 333 334 335 336 337 338 339
		/* 1) not_found is ok during load pass 1/2 (allow forward references) */

		if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
		    ACPI_PARSE_EXECUTE) {
			status = AE_OK;
		}

		/* 2) not_found during a cond_ref_of(x) is ok by definition */

		else if (walk_state->op->common.aml_opcode ==
			 AML_COND_REF_OF_OP) {
			status = AE_OK;
L
Linus Torvalds 已提交
340 341 342
		}

		/*
B
Bob Moore 已提交
343 344 345
		 * 3) not_found while building a Package is ok at this point, we
		 * may flag as an error later if slack mode is not enabled.
		 * (Some ASL code depends on allowing this behavior)
L
Linus Torvalds 已提交
346
		 */
B
Bob Moore 已提交
347 348 349 350 351 352
		else if ((arg->common.parent) &&
			 ((arg->common.parent->common.aml_opcode ==
			   AML_PACKAGE_OP)
			  || (arg->common.parent->common.aml_opcode ==
			      AML_VAR_PACKAGE_OP))) {
			status = AE_OK;
L
Linus Torvalds 已提交
353
		}
B
Bob Moore 已提交
354 355 356 357 358
	}

	/* Final exception check (may have been changed from code above) */

	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
359
		ACPI_ERROR_NAMESPACE(path, status);
B
Bob Moore 已提交
360 361 362

		if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
		    ACPI_PARSE_EXECUTE) {
B
Bob Moore 已提交
363

B
Bob Moore 已提交
364
			/* Report a control method execution error */
L
Linus Torvalds 已提交
365

B
Bob Moore 已提交
366
			status = acpi_ds_method_error(status, walk_state);
L
Linus Torvalds 已提交
367 368 369
		}
	}

B
Bob Moore 已提交
370
	/* Save the namepath */
L
Linus Torvalds 已提交
371

B
Bob Moore 已提交
372
	arg->common.value.name = path;
L
Len Brown 已提交
373
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
374 375 376 377 378 379 380 381
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_next_simple_arg
 *
 * PARAMETERS:  parser_state        - Current parser state object
 *              arg_type            - The argument type (AML_*_ARG)
382
 *              arg                 - Where the argument is returned
L
Linus Torvalds 已提交
383 384 385 386 387 388 389 390
 *
 * RETURN:      None
 *
 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
 *
 ******************************************************************************/

void
L
Len Brown 已提交
391 392
acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
			    u32 arg_type, union acpi_parse_object *arg)
L
Linus Torvalds 已提交
393
{
B
Bob Moore 已提交
394 395 396
	u32 length;
	u16 opcode;
	u8 *aml = parser_state->aml;
L
Linus Torvalds 已提交
397

B
Bob Moore 已提交
398
	ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
L
Linus Torvalds 已提交
399 400 401 402

	switch (arg_type) {
	case ARGP_BYTEDATA:

B
Bob Moore 已提交
403 404 405
		/* Get 1 byte from the AML stream */

		opcode = AML_BYTE_OP;
406
		arg->common.value.integer = (u64) *aml;
B
Bob Moore 已提交
407
		length = 1;
L
Linus Torvalds 已提交
408 409 410 411 412 413
		break;

	case ARGP_WORDDATA:

		/* Get 2 bytes from the AML stream */

B
Bob Moore 已提交
414 415 416
		opcode = AML_WORD_OP;
		ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
		length = 2;
L
Linus Torvalds 已提交
417 418 419 420 421 422
		break;

	case ARGP_DWORDDATA:

		/* Get 4 bytes from the AML stream */

B
Bob Moore 已提交
423 424 425
		opcode = AML_DWORD_OP;
		ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
		length = 4;
L
Linus Torvalds 已提交
426 427 428 429 430 431
		break;

	case ARGP_QWORDDATA:

		/* Get 8 bytes from the AML stream */

B
Bob Moore 已提交
432 433 434
		opcode = AML_QWORD_OP;
		ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
		length = 8;
L
Linus Torvalds 已提交
435 436 437 438
		break;

	case ARGP_CHARLIST:

B
Bob Moore 已提交
439 440 441 442
		/* Get a pointer to the string, point past the string */

		opcode = AML_STRING_OP;
		arg->common.value.string = ACPI_CAST_PTR(char, aml);
L
Linus Torvalds 已提交
443

B
Bob Moore 已提交
444 445 446 447 448
		/* Find the null terminator */

		length = 0;
		while (aml[length]) {
			length++;
L
Linus Torvalds 已提交
449
		}
B
Bob Moore 已提交
450
		length++;
L
Linus Torvalds 已提交
451 452 453 454 455
		break;

	case ARGP_NAME:
	case ARGP_NAMESTRING:

L
Len Brown 已提交
456 457 458
		acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
		arg->common.value.name =
		    acpi_ps_get_next_namestring(parser_state);
B
Bob Moore 已提交
459
		return_VOID;
L
Linus Torvalds 已提交
460 461 462

	default:

463
		ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type));
B
Bob Moore 已提交
464
		return_VOID;
L
Linus Torvalds 已提交
465 466
	}

B
Bob Moore 已提交
467 468
	acpi_ps_init_op(arg, opcode);
	parser_state->aml += length;
L
Linus Torvalds 已提交
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
	return_VOID;
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_next_field
 *
 * PARAMETERS:  parser_state        - Current parser state object
 *
 * RETURN:      A newly allocated FIELD op
 *
 * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
 *
 ******************************************************************************/

L
Len Brown 已提交
484 485
static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
						       *parser_state)
L
Linus Torvalds 已提交
486
{
487
	u32 aml_offset;
L
Len Brown 已提交
488
	union acpi_parse_object *field;
489
	union acpi_parse_object *arg = NULL;
L
Len Brown 已提交
490 491
	u16 opcode;
	u32 name;
492 493 494 495 496 497
	u8 access_type;
	u8 access_attribute;
	u8 access_length;
	u32 pkg_length;
	u8 *pkg_end;
	u32 buffer_length;
L
Linus Torvalds 已提交
498

B
Bob Moore 已提交
499
	ACPI_FUNCTION_TRACE(ps_get_next_field);
L
Linus Torvalds 已提交
500

501 502 503
	aml_offset =
	    (u32)ACPI_PTR_DIFF(parser_state->aml, parser_state->aml_start);

R
Robert Moore 已提交
504
	/* Determine field type */
L
Linus Torvalds 已提交
505

L
Len Brown 已提交
506
	switch (ACPI_GET8(parser_state->aml)) {
507
	case AML_FIELD_OFFSET_OP:
L
Linus Torvalds 已提交
508

509 510
		opcode = AML_INT_RESERVEDFIELD_OP;
		parser_state->aml++;
L
Linus Torvalds 已提交
511 512
		break;

513
	case AML_FIELD_ACCESS_OP:
L
Linus Torvalds 已提交
514

515
		opcode = AML_INT_ACCESSFIELD_OP;
L
Linus Torvalds 已提交
516 517 518
		parser_state->aml++;
		break;

519
	case AML_FIELD_CONNECTION_OP:
L
Linus Torvalds 已提交
520

521 522 523 524 525 526 527
		opcode = AML_INT_CONNECTION_OP;
		parser_state->aml++;
		break;

	case AML_FIELD_EXT_ACCESS_OP:

		opcode = AML_INT_EXTACCESSFIELD_OP;
L
Linus Torvalds 已提交
528 529
		parser_state->aml++;
		break;
530 531 532 533 534

	default:

		opcode = AML_INT_NAMEDFIELD_OP;
		break;
L
Linus Torvalds 已提交
535 536 537 538
	}

	/* Allocate a new field op */

L
Len Brown 已提交
539
	field = acpi_ps_alloc_op(opcode);
L
Linus Torvalds 已提交
540
	if (!field) {
L
Len Brown 已提交
541
		return_PTR(NULL);
L
Linus Torvalds 已提交
542 543 544 545 546 547 548 549 550 551 552
	}

	field->common.aml_offset = aml_offset;

	/* Decode the field type */

	switch (opcode) {
	case AML_INT_NAMEDFIELD_OP:

		/* Get the 4-character name */

L
Len Brown 已提交
553 554
		ACPI_MOVE_32_TO_32(&name, parser_state->aml);
		acpi_ps_set_name(field, name);
L
Linus Torvalds 已提交
555 556 557 558
		parser_state->aml += ACPI_NAME_SIZE;

		/* Get the length which is encoded as a package length */

L
Len Brown 已提交
559 560
		field->common.value.size =
		    acpi_ps_get_next_package_length(parser_state);
L
Linus Torvalds 已提交
561 562 563 564 565 566
		break;

	case AML_INT_RESERVEDFIELD_OP:

		/* Get the length which is encoded as a package length */

L
Len Brown 已提交
567 568
		field->common.value.size =
		    acpi_ps_get_next_package_length(parser_state);
L
Linus Torvalds 已提交
569 570 571
		break;

	case AML_INT_ACCESSFIELD_OP:
572
	case AML_INT_EXTACCESSFIELD_OP:
L
Linus Torvalds 已提交
573 574 575

		/*
		 * Get access_type and access_attrib and merge into the field Op
576 577
		 * access_type is first operand, access_attribute is second. stuff
		 * these bytes into the node integer value for convenience.
L
Linus Torvalds 已提交
578
		 */
579 580 581 582

		/* Get the two bytes (Type/Attribute) */

		access_type = ACPI_GET8(parser_state->aml);
L
Linus Torvalds 已提交
583
		parser_state->aml++;
584
		access_attribute = ACPI_GET8(parser_state->aml);
L
Linus Torvalds 已提交
585
		parser_state->aml++;
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620

		field->common.value.integer = (u8)access_type;
		field->common.value.integer |= (u16)(access_attribute << 8);

		/* This opcode has a third byte, access_length */

		if (opcode == AML_INT_EXTACCESSFIELD_OP) {
			access_length = ACPI_GET8(parser_state->aml);
			parser_state->aml++;

			field->common.value.integer |=
			    (u32)(access_length << 16);
		}
		break;

	case AML_INT_CONNECTION_OP:

		/*
		 * Argument for Connection operator can be either a Buffer
		 * (resource descriptor), or a name_string.
		 */
		if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) {
			parser_state->aml++;

			pkg_end = parser_state->aml;
			pkg_length =
			    acpi_ps_get_next_package_length(parser_state);
			pkg_end += pkg_length;

			if (parser_state->aml < pkg_end) {

				/* Non-empty list */

				arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP);
				if (!arg) {
621
					acpi_ps_free_op(field);
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
					return_PTR(NULL);
				}

				/* Get the actual buffer length argument */

				opcode = ACPI_GET8(parser_state->aml);
				parser_state->aml++;

				switch (opcode) {
				case AML_BYTE_OP:	/* AML_BYTEDATA_ARG */
					buffer_length =
					    ACPI_GET8(parser_state->aml);
					parser_state->aml += 1;
					break;

				case AML_WORD_OP:	/* AML_WORDDATA_ARG */
					buffer_length =
					    ACPI_GET16(parser_state->aml);
					parser_state->aml += 2;
					break;

				case AML_DWORD_OP:	/* AML_DWORDATA_ARG */
					buffer_length =
					    ACPI_GET32(parser_state->aml);
					parser_state->aml += 4;
					break;

				default:
					buffer_length = 0;
					break;
				}

				/* Fill in bytelist data */

				arg->named.value.size = buffer_length;
				arg->named.data = parser_state->aml;
			}

			/* Skip to End of byte data */

			parser_state->aml = pkg_end;
		} else {
			arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
			if (!arg) {
666
				acpi_ps_free_op(field);
667 668 669 670 671 672 673 674 675 676 677 678
				return_PTR(NULL);
			}

			/* Get the Namestring argument */

			arg->common.value.name =
			    acpi_ps_get_next_namestring(parser_state);
		}

		/* Link the buffer/namestring to parent (CONNECTION_OP) */

		acpi_ps_append_arg(field, arg);
L
Linus Torvalds 已提交
679 680 681 682 683 684 685 686
		break;

	default:

		/* Opcode was set in previous switch */
		break;
	}

L
Len Brown 已提交
687
	return_PTR(field);
L
Linus Torvalds 已提交
688 689 690 691 692 693
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_next_arg
 *
R
Robert Moore 已提交
694 695
 * PARAMETERS:  walk_state          - Current state
 *              parser_state        - Current parser state object
L
Linus Torvalds 已提交
696
 *              arg_type            - The argument type (AML_*_ARG)
R
Robert Moore 已提交
697
 *              return_arg          - Where the next arg is returned
L
Linus Torvalds 已提交
698 699 700 701 702 703 704 705 706
 *
 * RETURN:      Status, and an op object containing the next argument.
 *
 * DESCRIPTION: Get next argument (including complex list arguments that require
 *              pushing the parser stack)
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
707 708 709
acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
		     struct acpi_parse_state *parser_state,
		     u32 arg_type, union acpi_parse_object **return_arg)
L
Linus Torvalds 已提交
710
{
L
Len Brown 已提交
711 712 713 714 715
	union acpi_parse_object *arg = NULL;
	union acpi_parse_object *prev = NULL;
	union acpi_parse_object *field;
	u32 subop;
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
716

B
Bob Moore 已提交
717
	ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
L
Linus Torvalds 已提交
718 719 720 721 722 723 724 725 726

	switch (arg_type) {
	case ARGP_BYTEDATA:
	case ARGP_WORDDATA:
	case ARGP_DWORDDATA:
	case ARGP_CHARLIST:
	case ARGP_NAME:
	case ARGP_NAMESTRING:

R
Robert Moore 已提交
727
		/* Constants, strings, and namestrings are all the same size */
L
Linus Torvalds 已提交
728

L
Len Brown 已提交
729
		arg = acpi_ps_alloc_op(AML_BYTE_OP);
L
Linus Torvalds 已提交
730
		if (!arg) {
L
Len Brown 已提交
731
			return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
732
		}
L
Len Brown 已提交
733
		acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
L
Linus Torvalds 已提交
734 735 736 737 738 739
		break;

	case ARGP_PKGLENGTH:

		/* Package length, nothing returned */

L
Len Brown 已提交
740 741
		parser_state->pkg_end =
		    acpi_ps_get_next_package_end(parser_state);
L
Linus Torvalds 已提交
742 743 744 745 746
		break;

	case ARGP_FIELDLIST:

		if (parser_state->aml < parser_state->pkg_end) {
B
Bob Moore 已提交
747

L
Linus Torvalds 已提交
748 749 750
			/* Non-empty list */

			while (parser_state->aml < parser_state->pkg_end) {
L
Len Brown 已提交
751
				field = acpi_ps_get_next_field(parser_state);
L
Linus Torvalds 已提交
752
				if (!field) {
L
Len Brown 已提交
753
					return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
754 755 756 757
				}

				if (prev) {
					prev->common.next = field;
L
Len Brown 已提交
758
				} else {
L
Linus Torvalds 已提交
759 760 761 762 763 764 765 766 767 768 769 770 771 772
					arg = field;
				}
				prev = field;
			}

			/* Skip to End of byte data */

			parser_state->aml = parser_state->pkg_end;
		}
		break;

	case ARGP_BYTELIST:

		if (parser_state->aml < parser_state->pkg_end) {
B
Bob Moore 已提交
773

L
Linus Torvalds 已提交
774 775
			/* Non-empty list */

L
Len Brown 已提交
776
			arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP);
L
Linus Torvalds 已提交
777
			if (!arg) {
L
Len Brown 已提交
778
				return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
779 780 781 782
			}

			/* Fill in bytelist data */

R
Robert Moore 已提交
783
			arg->common.value.size = (u32)
L
Len Brown 已提交
784 785
			    ACPI_PTR_DIFF(parser_state->pkg_end,
					  parser_state->aml);
L
Linus Torvalds 已提交
786 787 788 789 790 791 792 793 794 795 796 797
			arg->named.data = parser_state->aml;

			/* Skip to End of byte data */

			parser_state->aml = parser_state->pkg_end;
		}
		break;

	case ARGP_TARGET:
	case ARGP_SUPERNAME:
	case ARGP_SIMPLENAME:

L
Len Brown 已提交
798 799 800 801
		subop = acpi_ps_peek_opcode(parser_state);
		if (subop == 0 ||
		    acpi_ps_is_leading_char(subop) ||
		    acpi_ps_is_prefix_char(subop)) {
B
Bob Moore 已提交
802

L
Linus Torvalds 已提交
803 804
			/* null_name or name_string */

L
Len Brown 已提交
805
			arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
L
Linus Torvalds 已提交
806
			if (!arg) {
L
Len Brown 已提交
807
				return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
808 809
			}

810 811
			/* To support super_name arg of Unload */

812
			if (walk_state->opcode == AML_UNLOAD_OP) {
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
				status =
				    acpi_ps_get_next_namepath(walk_state,
							      parser_state, arg,
							      1);

				/*
				 * If the super_name arg of Unload is a method call,
				 * we have restored the AML pointer, just free this Arg
				 */
				if (arg->common.aml_opcode ==
				    AML_INT_METHODCALL_OP) {
					acpi_ps_free_op(arg);
					arg = NULL;
				}
			} else {
				status =
				    acpi_ps_get_next_namepath(walk_state,
							      parser_state, arg,
							      0);
			}
L
Len Brown 已提交
833
		} else {
R
Robert Moore 已提交
834
			/* Single complex argument, nothing returned */
L
Linus Torvalds 已提交
835 836 837 838 839 840 841 842

			walk_state->arg_count = 1;
		}
		break;

	case ARGP_DATAOBJ:
	case ARGP_TERMARG:

R
Robert Moore 已提交
843
		/* Single complex argument, nothing returned */
L
Linus Torvalds 已提交
844 845 846 847 848 849 850 851 852

		walk_state->arg_count = 1;
		break;

	case ARGP_DATAOBJLIST:
	case ARGP_TERMLIST:
	case ARGP_OBJLIST:

		if (parser_state->aml < parser_state->pkg_end) {
B
Bob Moore 已提交
853

R
Robert Moore 已提交
854
			/* Non-empty list of variable arguments, nothing returned */
L
Linus Torvalds 已提交
855 856 857 858 859 860 861

			walk_state->arg_count = ACPI_VAR_ARGS;
		}
		break;

	default:

862
		ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
L
Linus Torvalds 已提交
863 864 865 866 867
		status = AE_AML_OPERAND_TYPE;
		break;
	}

	*return_arg = arg;
L
Len Brown 已提交
868
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
869
}