pstree.c 7.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: pstree - Parser op tree manipulation/traversal/search
 *
 *****************************************************************************/

/*
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
#include <acpi/acparser.h>
#include <acpi/amlcode.h>

#define _COMPONENT          ACPI_PARSER
L
Len Brown 已提交
50
ACPI_MODULE_NAME("pstree")
L
Linus Torvalds 已提交
51

52 53
/* Local prototypes */
#ifdef ACPI_OBSOLETE_FUNCTIONS
L
Len Brown 已提交
54
union acpi_parse_object *acpi_ps_get_child(union acpi_parse_object *op);
55 56
#endif

L
Linus Torvalds 已提交
57 58 59 60 61 62 63
/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_arg
 *
 * PARAMETERS:  Op              - Get an argument for this op
 *              Argn            - Nth argument to get
 *
64
 * RETURN:      The argument (as an Op object). NULL if argument does not exist
L
Linus Torvalds 已提交
65 66 67 68 69
 *
 * DESCRIPTION: Get the specified op's argument.
 *
 ******************************************************************************/

L
Len Brown 已提交
70
union acpi_parse_object *acpi_ps_get_arg(union acpi_parse_object *op, u32 argn)
L
Linus Torvalds 已提交
71
{
L
Len Brown 已提交
72 73
	union acpi_parse_object *arg = NULL;
	const struct acpi_opcode_info *op_info;
L
Linus Torvalds 已提交
74

L
Len Brown 已提交
75
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
76 77 78

	/* Get the info structure for this opcode */

L
Len Brown 已提交
79
	op_info = acpi_ps_get_opcode_info(op->common.aml_opcode);
L
Linus Torvalds 已提交
80
	if (op_info->class == AML_CLASS_UNKNOWN) {
B
Bob Moore 已提交
81

L
Linus Torvalds 已提交
82 83 84 85 86 87 88 89
		/* Invalid opcode or ASCII character */

		return (NULL);
	}

	/* Check if this opcode requires argument sub-objects */

	if (!(op_info->flags & AML_HAS_ARGS)) {
B
Bob Moore 已提交
90

L
Linus Torvalds 已提交
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
		/* Has no linked argument objects */

		return (NULL);
	}

	/* Get the requested argument object */

	arg = op->common.value.arg;
	while (arg && argn) {
		argn--;
		arg = arg->common.next;
	}

	return (arg);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_append_arg
 *
 * PARAMETERS:  Op              - Append an argument to this Op.
 *              Arg             - Argument Op to append
 *
 * RETURN:      None.
 *
 * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
 *
 ******************************************************************************/

void
L
Len Brown 已提交
121
acpi_ps_append_arg(union acpi_parse_object *op, union acpi_parse_object *arg)
L
Linus Torvalds 已提交
122
{
L
Len Brown 已提交
123 124
	union acpi_parse_object *prev_arg;
	const struct acpi_opcode_info *op_info;
L
Linus Torvalds 已提交
125

L
Len Brown 已提交
126
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
127 128 129 130 131 132 133

	if (!op) {
		return;
	}

	/* Get the info structure for this opcode */

L
Len Brown 已提交
134
	op_info = acpi_ps_get_opcode_info(op->common.aml_opcode);
L
Linus Torvalds 已提交
135
	if (op_info->class == AML_CLASS_UNKNOWN) {
B
Bob Moore 已提交
136

L
Linus Torvalds 已提交
137 138
		/* Invalid opcode */

B
Bob Moore 已提交
139 140
		ACPI_ERROR((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
			    op->common.aml_opcode));
L
Linus Torvalds 已提交
141 142 143 144 145 146
		return;
	}

	/* Check if this opcode requires argument sub-objects */

	if (!(op_info->flags & AML_HAS_ARGS)) {
B
Bob Moore 已提交
147

L
Linus Torvalds 已提交
148 149 150 151 152 153 154 155
		/* Has no linked argument objects */

		return;
	}

	/* Append the argument to the linked argument list */

	if (op->common.value.arg) {
B
Bob Moore 已提交
156

L
Linus Torvalds 已提交
157 158 159 160 161 162 163
		/* Append to existing argument list */

		prev_arg = op->common.value.arg;
		while (prev_arg->common.next) {
			prev_arg = prev_arg->common.next;
		}
		prev_arg->common.next = arg;
L
Len Brown 已提交
164
	} else {
L
Linus Torvalds 已提交
165 166 167 168 169 170 171 172 173 174
		/* No argument list, this will be the first argument */

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

	/* Set the parent in this arg and any args linked after it */

	while (arg) {
		arg->common.parent = op;
		arg = arg->common.next;
175 176

		op->common.arg_list_length++;
L
Linus Torvalds 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
	}
}

#ifdef ACPI_FUTURE_USAGE
/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_depth_next
 *
 * PARAMETERS:  Origin          - Root of subtree to search
 *              Op              - Last (previous) Op that was found
 *
 * RETURN:      Next Op found in the search.
 *
 * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
 *              Return NULL when reaching "origin" or when walking up from root
 *
 ******************************************************************************/

L
Len Brown 已提交
195 196
union acpi_parse_object *acpi_ps_get_depth_next(union acpi_parse_object *origin,
						union acpi_parse_object *op)
L
Linus Torvalds 已提交
197
{
L
Len Brown 已提交
198 199 200
	union acpi_parse_object *next = NULL;
	union acpi_parse_object *parent;
	union acpi_parse_object *arg;
L
Linus Torvalds 已提交
201

L
Len Brown 已提交
202
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
203 204 205 206 207

	if (!op) {
		return (NULL);
	}

208
	/* Look for an argument or child */
L
Linus Torvalds 已提交
209

L
Len Brown 已提交
210
	next = acpi_ps_get_arg(op, 0);
L
Linus Torvalds 已提交
211 212 213 214
	if (next) {
		return (next);
	}

215
	/* Look for a sibling */
L
Linus Torvalds 已提交
216 217 218 219 220 221

	next = op->common.next;
	if (next) {
		return (next);
	}

222
	/* Look for a sibling of parent */
L
Linus Torvalds 已提交
223 224 225 226

	parent = op->common.parent;

	while (parent) {
L
Len Brown 已提交
227
		arg = acpi_ps_get_arg(parent, 0);
L
Linus Torvalds 已提交
228 229 230 231 232
		while (arg && (arg != origin) && (arg != op)) {
			arg = arg->common.next;
		}

		if (arg == origin) {
B
Bob Moore 已提交
233

234
			/* Reached parent of origin, end search */
L
Linus Torvalds 已提交
235 236 237 238 239

			return (NULL);
		}

		if (parent->common.next) {
B
Bob Moore 已提交
240

241
			/* Found sibling of parent */
L
Linus Torvalds 已提交
242 243 244 245 246 247 248 249 250 251 252

			return (parent->common.next);
		}

		op = parent;
		parent = parent->common.parent;
	}

	return (next);
}

253 254 255 256 257 258 259 260 261 262 263 264 265
#ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_get_child
 *
 * PARAMETERS:  Op              - Get the child of this Op
 *
 * RETURN:      Child Op, Null if none is found.
 *
 * DESCRIPTION: Get op's children or NULL if none
 *
 ******************************************************************************/

L
Len Brown 已提交
266
union acpi_parse_object *acpi_ps_get_child(union acpi_parse_object *op)
267
{
L
Len Brown 已提交
268
	union acpi_parse_object *child = NULL;
269

L
Len Brown 已提交
270
	ACPI_FUNCTION_ENTRY();
271 272 273 274 275 276 277 278

	switch (op->common.aml_opcode) {
	case AML_SCOPE_OP:
	case AML_ELSE_OP:
	case AML_DEVICE_OP:
	case AML_THERMAL_ZONE_OP:
	case AML_INT_METHODCALL_OP:

L
Len Brown 已提交
279
		child = acpi_ps_get_arg(op, 0);
280 281 282 283 284 285 286 287 288
		break;

	case AML_BUFFER_OP:
	case AML_PACKAGE_OP:
	case AML_METHOD_OP:
	case AML_IF_OP:
	case AML_WHILE_OP:
	case AML_FIELD_OP:

L
Len Brown 已提交
289
		child = acpi_ps_get_arg(op, 1);
290 291 292 293 294
		break;

	case AML_POWER_RES_OP:
	case AML_INDEX_FIELD_OP:

L
Len Brown 已提交
295
		child = acpi_ps_get_arg(op, 2);
296 297 298 299 300
		break;

	case AML_PROCESSOR_OP:
	case AML_BANK_FIELD_OP:

L
Len Brown 已提交
301
		child = acpi_ps_get_arg(op, 3);
302 303 304 305 306 307 308 309 310 311
		break;

	default:
		/* All others have no children */
		break;
	}

	return (child);
}
#endif
L
Len Brown 已提交
312
#endif				/*  ACPI_FUTURE_USAGE  */
新手
引导
客服 返回
顶部