2018-03-14 23:13:07 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Module Name: pstree - Parser op tree manipulation/traversal/search
|
|
|
|
*
|
2018-01-04 18:06:38 +00:00
|
|
|
* Copyright (C) 2000 - 2018, Intel Corp.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2018-03-14 23:13:07 +00:00
|
|
|
*****************************************************************************/
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <acpi/acpi.h>
|
2009-01-09 05:30:03 +00:00
|
|
|
#include "accommon.h"
|
|
|
|
#include "acparser.h"
|
|
|
|
#include "amlcode.h"
|
2017-04-28 00:53:22 +00:00
|
|
|
#include "acconvert.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define _COMPONENT ACPI_PARSER
|
2005-08-05 04:44:28 +00:00
|
|
|
ACPI_MODULE_NAME("pstree")
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
/* Local prototypes */
|
|
|
|
#ifdef ACPI_OBSOLETE_FUNCTIONS
|
2005-08-05 04:44:28 +00:00
|
|
|
union acpi_parse_object *acpi_ps_get_child(union acpi_parse_object *op);
|
2005-04-19 02:49:35 +00:00
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: acpi_ps_get_arg
|
|
|
|
*
|
2012-07-12 01:40:10 +00:00
|
|
|
* PARAMETERS: op - Get an argument for this op
|
|
|
|
* argn - Nth argument to get
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2005-04-19 02:49:35 +00:00
|
|
|
* RETURN: The argument (as an Op object). NULL if argument does not exist
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* DESCRIPTION: Get the specified op's argument.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
union acpi_parse_object *acpi_ps_get_arg(union acpi_parse_object *op, u32 argn)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-08-05 04:44:28 +00:00
|
|
|
union acpi_parse_object *arg = NULL;
|
|
|
|
const struct acpi_opcode_info *op_info;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
ACPI_FUNCTION_ENTRY();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-11-16 05:39:07 +00:00
|
|
|
/*
|
|
|
|
if (Op->Common.aml_opcode == AML_INT_CONNECTION_OP)
|
|
|
|
{
|
|
|
|
return (Op->Common.Value.Arg);
|
|
|
|
}
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Get the info structure for this opcode */
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
op_info = acpi_ps_get_opcode_info(op->common.aml_opcode);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (op_info->class == AML_CLASS_UNKNOWN) {
|
2006-10-02 04:00:00 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Invalid opcode or ASCII character */
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this opcode requires argument sub-objects */
|
|
|
|
|
|
|
|
if (!(op_info->flags & AML_HAS_ARGS)) {
|
2006-10-02 04:00:00 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* 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
|
|
|
|
*
|
2012-07-12 01:40:10 +00:00
|
|
|
* PARAMETERS: op - Append an argument to this Op.
|
|
|
|
* arg - Argument Op to append
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* RETURN: None.
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void
|
2005-08-05 04:44:28 +00:00
|
|
|
acpi_ps_append_arg(union acpi_parse_object *op, union acpi_parse_object *arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-08-05 04:44:28 +00:00
|
|
|
union acpi_parse_object *prev_arg;
|
|
|
|
const struct acpi_opcode_info *op_info;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-12-28 07:29:43 +00:00
|
|
|
ACPI_FUNCTION_TRACE(ps_append_arg);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!op) {
|
2016-12-28 07:29:43 +00:00
|
|
|
return_VOID;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the info structure for this opcode */
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
op_info = acpi_ps_get_opcode_info(op->common.aml_opcode);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (op_info->class == AML_CLASS_UNKNOWN) {
|
2006-10-02 04:00:00 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Invalid opcode */
|
|
|
|
|
2006-01-27 21:43:00 +00:00
|
|
|
ACPI_ERROR((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
|
|
|
|
op->common.aml_opcode));
|
2016-12-28 07:29:43 +00:00
|
|
|
return_VOID;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this opcode requires argument sub-objects */
|
|
|
|
|
|
|
|
if (!(op_info->flags & AML_HAS_ARGS)) {
|
2006-10-02 04:00:00 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Has no linked argument objects */
|
|
|
|
|
2016-12-28 07:29:43 +00:00
|
|
|
return_VOID;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Append the argument to the linked argument list */
|
|
|
|
|
|
|
|
if (op->common.value.arg) {
|
2006-10-02 04:00:00 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* 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;
|
2005-08-05 04:44:28 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* 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;
|
2008-04-10 15:06:37 +00:00
|
|
|
|
|
|
|
op->common.arg_list_length++;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2016-12-28 07:29:43 +00:00
|
|
|
|
|
|
|
return_VOID;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: acpi_ps_get_depth_next
|
|
|
|
*
|
2012-07-12 01:40:10 +00:00
|
|
|
* PARAMETERS: origin - Root of subtree to search
|
|
|
|
* op - Last (previous) Op that was found
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
union acpi_parse_object *acpi_ps_get_depth_next(union acpi_parse_object *origin,
|
|
|
|
union acpi_parse_object *op)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-08-05 04:44:28 +00:00
|
|
|
union acpi_parse_object *next = NULL;
|
|
|
|
union acpi_parse_object *parent;
|
|
|
|
union acpi_parse_object *arg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
ACPI_FUNCTION_ENTRY();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!op) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
/* Look for an argument or child */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
next = acpi_ps_get_arg(op, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (next) {
|
2017-04-28 00:53:22 +00:00
|
|
|
ASL_CV_LABEL_FILENODE(next);
|
2005-04-16 22:20:36 +00:00
|
|
|
return (next);
|
|
|
|
}
|
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
/* Look for a sibling */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
next = op->common.next;
|
|
|
|
if (next) {
|
2017-04-28 00:53:22 +00:00
|
|
|
ASL_CV_LABEL_FILENODE(next);
|
2005-04-16 22:20:36 +00:00
|
|
|
return (next);
|
|
|
|
}
|
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
/* Look for a sibling of parent */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
parent = op->common.parent;
|
|
|
|
|
|
|
|
while (parent) {
|
2005-08-05 04:44:28 +00:00
|
|
|
arg = acpi_ps_get_arg(parent, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
while (arg && (arg != origin) && (arg != op)) {
|
2017-04-28 00:53:22 +00:00
|
|
|
|
|
|
|
ASL_CV_LABEL_FILENODE(arg);
|
2005-04-16 22:20:36 +00:00
|
|
|
arg = arg->common.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg == origin) {
|
2006-10-02 04:00:00 +00:00
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
/* Reached parent of origin, end search */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent->common.next) {
|
2006-10-02 04:00:00 +00:00
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
/* Found sibling of parent */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-04-28 00:53:22 +00:00
|
|
|
ASL_CV_LABEL_FILENODE(parent->common.next);
|
2005-04-16 22:20:36 +00:00
|
|
|
return (parent->common.next);
|
|
|
|
}
|
|
|
|
|
|
|
|
op = parent;
|
|
|
|
parent = parent->common.parent;
|
|
|
|
}
|
|
|
|
|
2017-04-28 00:53:22 +00:00
|
|
|
ASL_CV_LABEL_FILENODE(next);
|
2005-04-16 22:20:36 +00:00
|
|
|
return (next);
|
|
|
|
}
|
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
#ifdef ACPI_OBSOLETE_FUNCTIONS
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: acpi_ps_get_child
|
|
|
|
*
|
2012-07-12 01:40:10 +00:00
|
|
|
* PARAMETERS: op - Get the child of this Op
|
2005-04-19 02:49:35 +00:00
|
|
|
*
|
|
|
|
* RETURN: Child Op, Null if none is found.
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Get op's children or NULL if none
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
union acpi_parse_object *acpi_ps_get_child(union acpi_parse_object *op)
|
2005-04-19 02:49:35 +00:00
|
|
|
{
|
2005-08-05 04:44:28 +00:00
|
|
|
union acpi_parse_object *child = NULL;
|
2005-04-19 02:49:35 +00:00
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
ACPI_FUNCTION_ENTRY();
|
2005-04-19 02:49:35 +00:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
child = acpi_ps_get_arg(op, 0);
|
2005-04-19 02:49:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AML_BUFFER_OP:
|
|
|
|
case AML_PACKAGE_OP:
|
ACPICA: Integrate package handling with module-level code
ACPICA commit 8faf6fca445eb7219963d80543fb802302a7a8c7
This change completes the integration of the recent changes to
package object handling with the module-level code support.
For acpi_exec, the -ep flag is removed.
This change allows table load to behave as if it were a method
invocation. Before this, the definition block definition below would
have loaded all named objects at the root scope. After loading, it
would execute the if statements at the root scope.
DefinitionBlock (...)
{
Name(OBJ1, 0)
if (1)
{
Device (DEV1)
{
Name (_HID,0x0)
}
}
Scope (DEV1)
{
Name (OBJ2)
}
}
The above code would load OBJ1 to the namespace, defer the execution
of the if statement and attempt to add OBJ2 within the scope of DEV1.
Since DEV1 is not in scope, this would incur an AE_NOT_FOUND error.
After this error is emitted, the if block is invoked and DEV1 and its
_HID is added to the namespace.
This commit changes the behavior to execute the if block in place
rather than deferring it until all tables are loaded. The new
behavior is as follows: insert OBJ1 in the namespace, invoke the if
statement and add DEV1 and its _HID to the namespace, add OBJ2 to the
scope of DEV1.
Bug report links:
Link: https://bugs.acpica.org/show_bug.cgi?id=963
Link: https://bugzilla.kernel.org/show_bug.cgi?id=153541
Link: https://bugzilla.kernel.org/show_bug.cgi?id=196165
Link: https://bugzilla.kernel.org/show_bug.cgi?id=192621
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197207
Link: https://bugzilla.kernel.org/show_bug.cgi?id=198051
Link: https://bugzilla.kernel.org/show_bug.cgi?id=198515
ACPICA repo:
Link: https://github.com/acpica/acpica/commit/8faf6fca
Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Erik Schmauss <erik.schmauss@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2018-02-15 21:09:30 +00:00
|
|
|
case AML_VARIABLE_PACKAGE_OP:
|
2005-04-19 02:49:35 +00:00
|
|
|
case AML_METHOD_OP:
|
|
|
|
case AML_IF_OP:
|
|
|
|
case AML_WHILE_OP:
|
|
|
|
case AML_FIELD_OP:
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
child = acpi_ps_get_arg(op, 1);
|
2005-04-19 02:49:35 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-26 08:18:40 +00:00
|
|
|
case AML_POWER_RESOURCE_OP:
|
2005-04-19 02:49:35 +00:00
|
|
|
case AML_INDEX_FIELD_OP:
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
child = acpi_ps_get_arg(op, 2);
|
2005-04-19 02:49:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AML_PROCESSOR_OP:
|
|
|
|
case AML_BANK_FIELD_OP:
|
|
|
|
|
2005-08-05 04:44:28 +00:00
|
|
|
child = acpi_ps_get_arg(op, 3);
|
2005-04-19 02:49:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-06-08 00:58:14 +00:00
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
/* All others have no children */
|
2013-06-08 00:58:14 +00:00
|
|
|
|
2005-04-19 02:49:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (child);
|
|
|
|
}
|
|
|
|
#endif
|