2000-10-28 05:01:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Module Name: pstree - Parser op tree manipulation/traversal/search
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-01-13 16:12:34 +00:00
|
|
|
/*
|
2012-01-11 21:25:42 +00:00
|
|
|
* Copyright (C) 2000 - 2012, Intel Corp.
|
2000-12-21 06:56:46 +00:00
|
|
|
* All rights reserved.
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2011-01-13 16:12:34 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define __PSTREE_C__
|
|
|
|
|
2009-06-02 20:02:58 +00:00
|
|
|
#include <contrib/dev/acpica/include/acpi.h>
|
|
|
|
#include <contrib/dev/acpica/include/accommon.h>
|
|
|
|
#include <contrib/dev/acpica/include/acparser.h>
|
|
|
|
#include <contrib/dev/acpica/include/amlcode.h>
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
#define _COMPONENT ACPI_PARSER
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_MODULE_NAME ("pstree")
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Local prototypes */
|
|
|
|
|
|
|
|
#ifdef ACPI_OBSOLETE_FUNCTIONS
|
|
|
|
ACPI_PARSE_OBJECT *
|
|
|
|
AcpiPsGetChild (
|
|
|
|
ACPI_PARSE_OBJECT *op);
|
|
|
|
#endif
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsGetArg
|
|
|
|
*
|
|
|
|
* PARAMETERS: Op - Get an argument for this op
|
|
|
|
* Argn - Nth argument to get
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: The argument (as an Op object). NULL if argument does not exist
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
* DESCRIPTION: Get the specified op's argument.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_PARSE_OBJECT *
|
|
|
|
AcpiPsGetArg (
|
|
|
|
ACPI_PARSE_OBJECT *Op,
|
|
|
|
UINT32 Argn)
|
|
|
|
{
|
|
|
|
ACPI_PARSE_OBJECT *Arg = NULL;
|
2001-09-07 01:22:25 +00:00
|
|
|
const ACPI_OPCODE_INFO *OpInfo;
|
|
|
|
|
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_FUNCTION_ENTRY ();
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2011-11-23 18:05:37 +00:00
|
|
|
/*
|
|
|
|
if (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP)
|
|
|
|
{
|
|
|
|
return (Op->Common.Value.Arg);
|
|
|
|
}
|
|
|
|
*/
|
2000-10-28 05:01:06 +00:00
|
|
|
/* Get the info structure for this opcode */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
|
2001-10-31 02:32:29 +00:00
|
|
|
if (OpInfo->Class == AML_CLASS_UNKNOWN)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
|
|
|
/* Invalid opcode or ASCII character */
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this opcode requires argument sub-objects */
|
|
|
|
|
2001-10-31 02:32:29 +00:00
|
|
|
if (!(OpInfo->Flags & AML_HAS_ARGS))
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
|
|
|
/* Has no linked argument objects */
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the requested argument object */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
Arg = Op->Common.Value.Arg;
|
2000-10-28 05:01:06 +00:00
|
|
|
while (Arg && Argn)
|
|
|
|
{
|
|
|
|
Argn--;
|
2002-07-09 17:51:31 +00:00
|
|
|
Arg = Arg->Common.Next;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (Arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsAppendArg
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
AcpiPsAppendArg (
|
|
|
|
ACPI_PARSE_OBJECT *Op,
|
|
|
|
ACPI_PARSE_OBJECT *Arg)
|
|
|
|
{
|
|
|
|
ACPI_PARSE_OBJECT *PrevArg;
|
2001-09-07 01:22:25 +00:00
|
|
|
const ACPI_OPCODE_INFO *OpInfo;
|
|
|
|
|
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_FUNCTION_ENTRY ();
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!Op)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the info structure for this opcode */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
|
2001-10-31 02:32:29 +00:00
|
|
|
if (OpInfo->Class == AML_CLASS_UNKNOWN)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
|
|
|
/* Invalid opcode */
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_ERROR ((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
|
2002-07-09 17:51:31 +00:00
|
|
|
Op->Common.AmlOpcode));
|
2000-10-28 05:01:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this opcode requires argument sub-objects */
|
|
|
|
|
2001-10-31 02:32:29 +00:00
|
|
|
if (!(OpInfo->Flags & AML_HAS_ARGS))
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
|
|
|
/* Has no linked argument objects */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append the argument to the linked argument list */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
if (Op->Common.Value.Arg)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
|
|
|
/* Append to existing argument list */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
PrevArg = Op->Common.Value.Arg;
|
|
|
|
while (PrevArg->Common.Next)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2002-07-09 17:51:31 +00:00
|
|
|
PrevArg = PrevArg->Common.Next;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
2002-07-09 17:51:31 +00:00
|
|
|
PrevArg->Common.Next = Arg;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No argument list, this will be the first argument */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
Op->Common.Value.Arg = Arg;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the parent in this arg and any args linked after it */
|
|
|
|
|
|
|
|
while (Arg)
|
|
|
|
{
|
2002-07-09 17:51:31 +00:00
|
|
|
Arg->Common.Parent = Op;
|
|
|
|
Arg = Arg->Common.Next;
|
2007-03-22 17:24:05 +00:00
|
|
|
|
|
|
|
Op->Common.ArgListLength++;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsGetDepthNext
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_PARSE_OBJECT *
|
|
|
|
AcpiPsGetDepthNext (
|
|
|
|
ACPI_PARSE_OBJECT *Origin,
|
|
|
|
ACPI_PARSE_OBJECT *Op)
|
|
|
|
{
|
|
|
|
ACPI_PARSE_OBJECT *Next = NULL;
|
|
|
|
ACPI_PARSE_OBJECT *Parent;
|
|
|
|
ACPI_PARSE_OBJECT *Arg;
|
|
|
|
|
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_FUNCTION_ENTRY ();
|
2001-09-07 01:22:25 +00:00
|
|
|
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
if (!Op)
|
|
|
|
{
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Look for an argument or child */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
Next = AcpiPsGetArg (Op, 0);
|
|
|
|
if (Next)
|
|
|
|
{
|
|
|
|
return (Next);
|
|
|
|
}
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Look for a sibling */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
Next = Op->Common.Next;
|
2000-10-28 05:01:06 +00:00
|
|
|
if (Next)
|
|
|
|
{
|
|
|
|
return (Next);
|
|
|
|
}
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Look for a sibling of parent */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
Parent = Op->Common.Parent;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
while (Parent)
|
|
|
|
{
|
|
|
|
Arg = AcpiPsGetArg (Parent, 0);
|
|
|
|
while (Arg && (Arg != Origin) && (Arg != Op))
|
|
|
|
{
|
2002-07-09 17:51:31 +00:00
|
|
|
Arg = Arg->Common.Next;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Arg == Origin)
|
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Reached parent of origin, end search */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
if (Parent->Common.Next)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Found sibling of parent */
|
2002-07-09 17:51:31 +00:00
|
|
|
|
|
|
|
return (Parent->Common.Next);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Op = Parent;
|
2002-07-09 17:51:31 +00:00
|
|
|
Parent = Parent->Common.Parent;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (Next);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
#ifdef ACPI_OBSOLETE_FUNCTIONS
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsGetChild
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_PARSE_OBJECT *
|
|
|
|
AcpiPsGetChild (
|
|
|
|
ACPI_PARSE_OBJECT *Op)
|
|
|
|
{
|
|
|
|
ACPI_PARSE_OBJECT *Child = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
ACPI_FUNCTION_ENTRY ();
|
|
|
|
|
|
|
|
|
|
|
|
switch (Op->Common.AmlOpcode)
|
|
|
|
{
|
|
|
|
case AML_SCOPE_OP:
|
|
|
|
case AML_ELSE_OP:
|
|
|
|
case AML_DEVICE_OP:
|
|
|
|
case AML_THERMAL_ZONE_OP:
|
|
|
|
case AML_INT_METHODCALL_OP:
|
|
|
|
|
|
|
|
Child = AcpiPsGetArg (Op, 0);
|
|
|
|
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:
|
|
|
|
|
|
|
|
Child = AcpiPsGetArg (Op, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case AML_POWER_RES_OP:
|
|
|
|
case AML_INDEX_FIELD_OP:
|
|
|
|
|
|
|
|
Child = AcpiPsGetArg (Op, 2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case AML_PROCESSOR_OP:
|
|
|
|
case AML_BANK_FIELD_OP:
|
|
|
|
|
|
|
|
Child = AcpiPsGetArg (Op, 3);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* All others have no children */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (Child);
|
|
|
|
}
|
|
|
|
#endif
|