Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / acpi / acpica / pstree.c
blobf9fa88c79b32dfd99b66c04115868d99be9acc28
1 /******************************************************************************
3 * Module Name: pstree - Parser op tree manipulation/traversal/search
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2018, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acparser.h"
47 #include "amlcode.h"
48 #include "acconvert.h"
50 #define _COMPONENT ACPI_PARSER
51 ACPI_MODULE_NAME("pstree")
53 /* Local prototypes */
54 #ifdef ACPI_OBSOLETE_FUNCTIONS
55 union acpi_parse_object *acpi_ps_get_child(union acpi_parse_object *op);
56 #endif
58 /*******************************************************************************
60 * FUNCTION: acpi_ps_get_arg
62 * PARAMETERS: op - Get an argument for this op
63 * argn - Nth argument to get
65 * RETURN: The argument (as an Op object). NULL if argument does not exist
67 * DESCRIPTION: Get the specified op's argument.
69 ******************************************************************************/
71 union acpi_parse_object *acpi_ps_get_arg(union acpi_parse_object *op, u32 argn)
73 union acpi_parse_object *arg = NULL;
74 const struct acpi_opcode_info *op_info;
76 ACPI_FUNCTION_ENTRY();
79 if (Op->Common.aml_opcode == AML_INT_CONNECTION_OP)
81 return (Op->Common.Value.Arg);
84 /* Get the info structure for this opcode */
86 op_info = acpi_ps_get_opcode_info(op->common.aml_opcode);
87 if (op_info->class == AML_CLASS_UNKNOWN) {
89 /* Invalid opcode or ASCII character */
91 return (NULL);
94 /* Check if this opcode requires argument sub-objects */
96 if (!(op_info->flags & AML_HAS_ARGS)) {
98 /* Has no linked argument objects */
100 return (NULL);
103 /* Get the requested argument object */
105 arg = op->common.value.arg;
106 while (arg && argn) {
107 argn--;
108 arg = arg->common.next;
111 return (arg);
114 /*******************************************************************************
116 * FUNCTION: acpi_ps_append_arg
118 * PARAMETERS: op - Append an argument to this Op.
119 * arg - Argument Op to append
121 * RETURN: None.
123 * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
125 ******************************************************************************/
127 void
128 acpi_ps_append_arg(union acpi_parse_object *op, union acpi_parse_object *arg)
130 union acpi_parse_object *prev_arg;
131 const struct acpi_opcode_info *op_info;
133 ACPI_FUNCTION_TRACE(ps_append_arg);
135 if (!op) {
136 return_VOID;
139 /* Get the info structure for this opcode */
141 op_info = acpi_ps_get_opcode_info(op->common.aml_opcode);
142 if (op_info->class == AML_CLASS_UNKNOWN) {
144 /* Invalid opcode */
146 ACPI_ERROR((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
147 op->common.aml_opcode));
148 return_VOID;
151 /* Check if this opcode requires argument sub-objects */
153 if (!(op_info->flags & AML_HAS_ARGS)) {
155 /* Has no linked argument objects */
157 return_VOID;
160 /* Append the argument to the linked argument list */
162 if (op->common.value.arg) {
164 /* Append to existing argument list */
166 prev_arg = op->common.value.arg;
167 while (prev_arg->common.next) {
168 prev_arg = prev_arg->common.next;
170 prev_arg->common.next = arg;
171 } else {
172 /* No argument list, this will be the first argument */
174 op->common.value.arg = arg;
177 /* Set the parent in this arg and any args linked after it */
179 while (arg) {
180 arg->common.parent = op;
181 arg = arg->common.next;
183 op->common.arg_list_length++;
186 return_VOID;
189 /*******************************************************************************
191 * FUNCTION: acpi_ps_get_depth_next
193 * PARAMETERS: origin - Root of subtree to search
194 * op - Last (previous) Op that was found
196 * RETURN: Next Op found in the search.
198 * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
199 * Return NULL when reaching "origin" or when walking up from root
201 ******************************************************************************/
203 union acpi_parse_object *acpi_ps_get_depth_next(union acpi_parse_object *origin,
204 union acpi_parse_object *op)
206 union acpi_parse_object *next = NULL;
207 union acpi_parse_object *parent;
208 union acpi_parse_object *arg;
210 ACPI_FUNCTION_ENTRY();
212 if (!op) {
213 return (NULL);
216 /* Look for an argument or child */
218 next = acpi_ps_get_arg(op, 0);
219 if (next) {
220 ASL_CV_LABEL_FILENODE(next);
221 return (next);
224 /* Look for a sibling */
226 next = op->common.next;
227 if (next) {
228 ASL_CV_LABEL_FILENODE(next);
229 return (next);
232 /* Look for a sibling of parent */
234 parent = op->common.parent;
236 while (parent) {
237 arg = acpi_ps_get_arg(parent, 0);
238 while (arg && (arg != origin) && (arg != op)) {
240 ASL_CV_LABEL_FILENODE(arg);
241 arg = arg->common.next;
244 if (arg == origin) {
246 /* Reached parent of origin, end search */
248 return (NULL);
251 if (parent->common.next) {
253 /* Found sibling of parent */
255 ASL_CV_LABEL_FILENODE(parent->common.next);
256 return (parent->common.next);
259 op = parent;
260 parent = parent->common.parent;
263 ASL_CV_LABEL_FILENODE(next);
264 return (next);
267 #ifdef ACPI_OBSOLETE_FUNCTIONS
268 /*******************************************************************************
270 * FUNCTION: acpi_ps_get_child
272 * PARAMETERS: op - Get the child of this Op
274 * RETURN: Child Op, Null if none is found.
276 * DESCRIPTION: Get op's children or NULL if none
278 ******************************************************************************/
280 union acpi_parse_object *acpi_ps_get_child(union acpi_parse_object *op)
282 union acpi_parse_object *child = NULL;
284 ACPI_FUNCTION_ENTRY();
286 switch (op->common.aml_opcode) {
287 case AML_SCOPE_OP:
288 case AML_ELSE_OP:
289 case AML_DEVICE_OP:
290 case AML_THERMAL_ZONE_OP:
291 case AML_INT_METHODCALL_OP:
293 child = acpi_ps_get_arg(op, 0);
294 break;
296 case AML_BUFFER_OP:
297 case AML_PACKAGE_OP:
298 case AML_METHOD_OP:
299 case AML_IF_OP:
300 case AML_WHILE_OP:
301 case AML_FIELD_OP:
303 child = acpi_ps_get_arg(op, 1);
304 break;
306 case AML_POWER_RESOURCE_OP:
307 case AML_INDEX_FIELD_OP:
309 child = acpi_ps_get_arg(op, 2);
310 break;
312 case AML_PROCESSOR_OP:
313 case AML_BANK_FIELD_OP:
315 child = acpi_ps_get_arg(op, 3);
316 break;
318 default:
320 /* All others have no children */
322 break;
325 return (child);
327 #endif