167754Smsmith/****************************************************************************** 267754Smsmith * 367754Smsmith * Module Name: pswalk - Parser routines to walk parsed op tree(s) 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7217365Sjkim/* 8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp. 970243Smsmith * All rights reserved. 1067754Smsmith * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 2567754Smsmith * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 2967754Smsmith * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 4367754Smsmith 44193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 45193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 46193341Sjkim#include <contrib/dev/acpica/include/acparser.h> 4767754Smsmith 4877424Smsmith#define _COMPONENT ACPI_PARSER 4991116Smsmith ACPI_MODULE_NAME ("pswalk") 5067754Smsmith 5167754Smsmith 5267754Smsmith/******************************************************************************* 5367754Smsmith * 5469450Smsmith * FUNCTION: AcpiPsDeleteParseTree 5567754Smsmith * 5669450Smsmith * PARAMETERS: SubtreeRoot - Root of tree (or subtree) to delete 5767754Smsmith * 5869450Smsmith * RETURN: None 5967754Smsmith * 6069450Smsmith * DESCRIPTION: Delete a portion of or an entire parse tree. 6167754Smsmith * 6267754Smsmith ******************************************************************************/ 6367754Smsmith 6469450Smsmithvoid 6569450SmsmithAcpiPsDeleteParseTree ( 6669450Smsmith ACPI_PARSE_OBJECT *SubtreeRoot) 6767754Smsmith{ 68151937Sjkim ACPI_PARSE_OBJECT *Op = SubtreeRoot; 69151937Sjkim ACPI_PARSE_OBJECT *Next = NULL; 70151937Sjkim ACPI_PARSE_OBJECT *Parent = NULL; 7167754Smsmith 7267754Smsmith 73167802Sjkim ACPI_FUNCTION_TRACE_PTR (PsDeleteParseTree, SubtreeRoot); 7467754Smsmith 7567754Smsmith 76151937Sjkim /* Visit all nodes in the subtree */ 77151937Sjkim 78151937Sjkim while (Op) 7967754Smsmith { 80151937Sjkim /* Check if we are not ascending */ 8167754Smsmith 82151937Sjkim if (Op != Parent) 83151937Sjkim { 84151937Sjkim /* Look for an argument or child of the current op */ 8567754Smsmith 86151937Sjkim Next = AcpiPsGetArg (Op, 0); 87151937Sjkim if (Next) 88151937Sjkim { 89151937Sjkim /* Still going downward in tree (Op is not completed yet) */ 9077424Smsmith 91151937Sjkim Op = Next; 92151937Sjkim continue; 93151937Sjkim } 94151937Sjkim } 9567754Smsmith 96151937Sjkim /* No more children, this Op is complete. */ 9767754Smsmith 98151937Sjkim Next = Op->Common.Next; 99151937Sjkim Parent = Op->Common.Parent; 10067754Smsmith 101151937Sjkim AcpiPsFreeOp (Op); 10267754Smsmith 103151937Sjkim /* If we are back to the starting point, the walk is complete. */ 10467754Smsmith 105151937Sjkim if (Op == SubtreeRoot) 10699679Siwasaki { 107151937Sjkim return_VOID; 10899679Siwasaki } 109306536Sjkim 110151937Sjkim if (Next) 111151937Sjkim { 112151937Sjkim Op = Next; 113151937Sjkim } 114151937Sjkim else 115151937Sjkim { 116151937Sjkim Op = Parent; 117151937Sjkim } 11867754Smsmith } 11967754Smsmith 12069450Smsmith return_VOID; 12167754Smsmith} 122