Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: pswalk - Parser routines to walk parsed op tree(s)
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acparser.h"
0013 
0014 #define _COMPONENT          ACPI_PARSER
0015 ACPI_MODULE_NAME("pswalk")
0016 
0017 /*******************************************************************************
0018  *
0019  * FUNCTION:    acpi_ps_delete_parse_tree
0020  *
0021  * PARAMETERS:  subtree_root        - Root of tree (or subtree) to delete
0022  *
0023  * RETURN:      None
0024  *
0025  * DESCRIPTION: Delete a portion of or an entire parse tree.
0026  *
0027  ******************************************************************************/
0028 #include "amlcode.h"
0029 void acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root)
0030 {
0031     union acpi_parse_object *op = subtree_root;
0032     union acpi_parse_object *next = NULL;
0033     union acpi_parse_object *parent = NULL;
0034     u32 level = 0;
0035 
0036     ACPI_FUNCTION_TRACE_PTR(ps_delete_parse_tree, subtree_root);
0037 
0038     ACPI_DEBUG_PRINT((ACPI_DB_PARSE_TREES, " root %p\n", subtree_root));
0039 
0040     /* Visit all nodes in the subtree */
0041 
0042     while (op) {
0043         if (op != parent) {
0044 
0045             /* This is the descending case */
0046 
0047             if (ACPI_IS_DEBUG_ENABLED
0048                 (ACPI_LV_PARSE_TREES, _COMPONENT)) {
0049 
0050                 /* This debug option will print the entire parse tree */
0051 
0052                 acpi_os_printf("      %*.s%s %p", (level * 4),
0053                            " ",
0054                            acpi_ps_get_opcode_name(op->
0055                                        common.
0056                                        aml_opcode),
0057                            op);
0058 
0059                 if (op->named.aml_opcode == AML_INT_NAMEPATH_OP) {
0060                     acpi_os_printf("  %4.4s",
0061                                op->common.value.string);
0062                 }
0063                 if (op->named.aml_opcode == AML_STRING_OP) {
0064                     acpi_os_printf("  %s",
0065                                op->common.value.string);
0066                 }
0067                 acpi_os_printf("\n");
0068             }
0069 
0070             /* Look for an argument or child of the current op */
0071 
0072             next = acpi_ps_get_arg(op, 0);
0073             if (next) {
0074 
0075                 /* Still going downward in tree (Op is not completed yet) */
0076 
0077                 op = next;
0078                 level++;
0079                 continue;
0080             }
0081         }
0082 
0083         /* No more children, this Op is complete. */
0084 
0085         next = op->common.next;
0086         parent = op->common.parent;
0087 
0088         acpi_ps_free_op(op);
0089 
0090         /* If we are back to the starting point, the walk is complete. */
0091 
0092         if (op == subtree_root) {
0093             return_VOID;
0094         }
0095 
0096         if (next) {
0097             op = next;
0098         } else {
0099             level--;
0100             op = parent;
0101         }
0102     }
0103 
0104     return_VOID;
0105 }