11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/****************************************************************************** 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Module Name: pswalk - Parser routines to walk parsed op tree(s) 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *****************************************************************************/ 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 8fbb7a2dc2be493c87399550bdc2ddaa510cdf450Bob Moore * Copyright (C) 2000 - 2014, Intel Corp. 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * All rights reserved. 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Redistribution and use in source and binary forms, with or without 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * modification, are permitted provided that the following conditions 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are met: 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1. Redistributions of source code must retain the above copyright 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * notice, this list of conditions, and the following disclaimer, 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * without modification. 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2. Redistributions in binary form must reproduce at minimum a disclaimer 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * substantially similar to the "NO WARRANTY" disclaimer below 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ("Disclaimer") and any redistribution must be conditioned upon 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * including a substantially similar Disclaimer requirement for further 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * binary redistribution. 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3. Neither the names of the above-listed copyright holders nor the names 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of any contributors may be used to endorse or promote products derived 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * from this software without specific prior written permission. 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Alternatively, this software may be distributed under the terms of the 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License ("GPL") version 2 as published by the Free 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Software Foundation. 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NO WARRANTY 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * POSSIBILITY OF SUCH DAMAGES. 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <acpi/acpi.h> 45e2f7a7772880458edff1b1cc5a988947229fac26Len Brown#include "accommon.h" 46e2f7a7772880458edff1b1cc5a988947229fac26Len Brown#include "acparser.h" 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _COMPONENT ACPI_PARSER 494be44fcd3bf648b782f4460fd06dfae6c42ded4bLen BrownACPI_MODULE_NAME("pswalk") 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/******************************************************************************* 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FUNCTION: acpi_ps_delete_parse_tree 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PARAMETERS: subtree_root - Root of tree (or subtree) to delete 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * RETURN: None 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DESCRIPTION: Delete a portion of or an entire parse tree. 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ******************************************************************************/ 624be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brownvoid acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root) 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 644be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown union acpi_parse_object *op = subtree_root; 654be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown union acpi_parse_object *next = NULL; 664be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown union acpi_parse_object *parent = NULL; 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 68b229cf92eee616c7cb5ad8cdb35a19b119f00bc8Bob Moore ACPI_FUNCTION_TRACE_PTR(ps_delete_parse_tree, subtree_root); 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Visit all nodes in the subtree */ 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (op) { 7352fc0b026e99b5d5d585095148d997d5634bbc25Bob Moore 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Check if we are not ascending */ 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (op != parent) { 7752fc0b026e99b5d5d585095148d997d5634bbc25Bob Moore 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Look for an argument or child of the current op */ 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 804be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown next = acpi_ps_get_arg(op, 0); 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (next) { 8252fc0b026e99b5d5d585095148d997d5634bbc25Bob Moore 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Still going downward in tree (Op is not completed yet) */ 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds op = next; 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9044f6c01242da4e162f28d8e1216a8c7a91174605Robert Moore /* No more children, this Op is complete. */ 9144f6c01242da4e162f28d8e1216a8c7a91174605Robert Moore 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds next = op->common.next; 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds parent = op->common.parent; 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 954be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown acpi_ps_free_op(op); 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9744f6c01242da4e162f28d8e1216a8c7a91174605Robert Moore /* If we are back to the starting point, the walk is complete. */ 9844f6c01242da4e162f28d8e1216a8c7a91174605Robert Moore 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (op == subtree_root) { 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return_VOID; 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (next) { 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds op = next; 1044be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown } else { 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds op = parent; 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 10844f6c01242da4e162f28d8e1216a8c7a91174605Robert Moore 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return_VOID; 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 111