195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
295b482a8SLen Brown /******************************************************************************
395b482a8SLen Brown *
495b482a8SLen Brown * Module Name: pswalk - Parser routines to walk parsed op tree(s)
595b482a8SLen Brown *
6*612c2932SBob Moore * Copyright (C) 2000 - 2023, Intel Corp.
795b482a8SLen Brown *
895857638SErik Schmauss *****************************************************************************/
995b482a8SLen Brown
1095b482a8SLen Brown #include <acpi/acpi.h>
11e2f7a777SLen Brown #include "accommon.h"
12e2f7a777SLen Brown #include "acparser.h"
1395b482a8SLen Brown
1495b482a8SLen Brown #define _COMPONENT ACPI_PARSER
1595b482a8SLen Brown ACPI_MODULE_NAME("pswalk")
1695b482a8SLen Brown
1795b482a8SLen Brown /*******************************************************************************
1895b482a8SLen Brown *
1995b482a8SLen Brown * FUNCTION: acpi_ps_delete_parse_tree
2095b482a8SLen Brown *
2195b482a8SLen Brown * PARAMETERS: subtree_root - Root of tree (or subtree) to delete
2295b482a8SLen Brown *
2395b482a8SLen Brown * RETURN: None
2495b482a8SLen Brown *
2595b482a8SLen Brown * DESCRIPTION: Delete a portion of or an entire parse tree.
2695b482a8SLen Brown *
2795b482a8SLen Brown ******************************************************************************/
28fb30b298SBob Moore #include "amlcode.h"
acpi_ps_delete_parse_tree(union acpi_parse_object * subtree_root)2995b482a8SLen Brown void acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root)
3095b482a8SLen Brown {
3195b482a8SLen Brown union acpi_parse_object *op = subtree_root;
3295b482a8SLen Brown union acpi_parse_object *next = NULL;
3395b482a8SLen Brown union acpi_parse_object *parent = NULL;
34fb30b298SBob Moore u32 level = 0;
3595b482a8SLen Brown
3695b482a8SLen Brown ACPI_FUNCTION_TRACE_PTR(ps_delete_parse_tree, subtree_root);
3795b482a8SLen Brown
38fb30b298SBob Moore ACPI_DEBUG_PRINT((ACPI_DB_PARSE_TREES, " root %p\n", subtree_root));
39fb30b298SBob Moore
4095b482a8SLen Brown /* Visit all nodes in the subtree */
4195b482a8SLen Brown
4295b482a8SLen Brown while (op) {
4395b482a8SLen Brown if (op != parent) {
4495b482a8SLen Brown
45fb30b298SBob Moore /* This is the descending case */
46fb30b298SBob Moore
47fb30b298SBob Moore if (ACPI_IS_DEBUG_ENABLED
48fb30b298SBob Moore (ACPI_LV_PARSE_TREES, _COMPONENT)) {
49fb30b298SBob Moore
50fb30b298SBob Moore /* This debug option will print the entire parse tree */
51fb30b298SBob Moore
52fb30b298SBob Moore acpi_os_printf(" %*.s%s %p", (level * 4),
53fb30b298SBob Moore " ",
54fb30b298SBob Moore acpi_ps_get_opcode_name(op->
55fb30b298SBob Moore common.
56fb30b298SBob Moore aml_opcode),
57fb30b298SBob Moore op);
58fb30b298SBob Moore
59fb30b298SBob Moore if (op->named.aml_opcode == AML_INT_NAMEPATH_OP) {
60fb30b298SBob Moore acpi_os_printf(" %4.4s",
61fb30b298SBob Moore op->common.value.string);
62fb30b298SBob Moore }
63fb30b298SBob Moore if (op->named.aml_opcode == AML_STRING_OP) {
64fb30b298SBob Moore acpi_os_printf(" %s",
65fb30b298SBob Moore op->common.value.string);
66fb30b298SBob Moore }
67fb30b298SBob Moore acpi_os_printf("\n");
68fb30b298SBob Moore }
69fb30b298SBob Moore
7095b482a8SLen Brown /* Look for an argument or child of the current op */
7195b482a8SLen Brown
7295b482a8SLen Brown next = acpi_ps_get_arg(op, 0);
7395b482a8SLen Brown if (next) {
7495b482a8SLen Brown
7595b482a8SLen Brown /* Still going downward in tree (Op is not completed yet) */
7695b482a8SLen Brown
7795b482a8SLen Brown op = next;
78fb30b298SBob Moore level++;
7995b482a8SLen Brown continue;
8095b482a8SLen Brown }
8195b482a8SLen Brown }
8295b482a8SLen Brown
8395b482a8SLen Brown /* No more children, this Op is complete. */
8495b482a8SLen Brown
8595b482a8SLen Brown next = op->common.next;
8695b482a8SLen Brown parent = op->common.parent;
8795b482a8SLen Brown
8895b482a8SLen Brown acpi_ps_free_op(op);
8995b482a8SLen Brown
9095b482a8SLen Brown /* If we are back to the starting point, the walk is complete. */
9195b482a8SLen Brown
9295b482a8SLen Brown if (op == subtree_root) {
9395b482a8SLen Brown return_VOID;
9495b482a8SLen Brown }
951fad8738SBob Moore
9695b482a8SLen Brown if (next) {
9795b482a8SLen Brown op = next;
9895b482a8SLen Brown } else {
99fb30b298SBob Moore level--;
10095b482a8SLen Brown op = parent;
10195b482a8SLen Brown }
10295b482a8SLen Brown }
10395b482a8SLen Brown
10495b482a8SLen Brown return_VOID;
10595b482a8SLen Brown }
106