195857638SErik Schmauss /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ 2e2f7a777SLen Brown /****************************************************************************** 3e2f7a777SLen Brown * 4e2f7a777SLen Brown * Module Name: acparser.h - AML Parser subcomponent prototypes and defines 5e2f7a777SLen Brown * 6*612c2932SBob Moore * Copyright (C) 2000 - 2023, Intel Corp. 7e2f7a777SLen Brown * 895857638SErik Schmauss *****************************************************************************/ 9e2f7a777SLen Brown 10e2f7a777SLen Brown #ifndef __ACPARSER_H__ 11e2f7a777SLen Brown #define __ACPARSER_H__ 12e2f7a777SLen Brown 13e2f7a777SLen Brown #define OP_HAS_RETURN_VALUE 1 14e2f7a777SLen Brown 15e2f7a777SLen Brown /* Variable number of arguments. This field must be 32 bits */ 16e2f7a777SLen Brown 17e2f7a777SLen Brown #define ACPI_VAR_ARGS ACPI_UINT32_MAX 18e2f7a777SLen Brown 19e2f7a777SLen Brown #define ACPI_PARSE_DELETE_TREE 0x0001 20e2f7a777SLen Brown #define ACPI_PARSE_NO_TREE_DELETE 0x0000 21e2f7a777SLen Brown #define ACPI_PARSE_TREE_MASK 0x0001 22e2f7a777SLen Brown 23e2f7a777SLen Brown #define ACPI_PARSE_LOAD_PASS1 0x0010 24e2f7a777SLen Brown #define ACPI_PARSE_LOAD_PASS2 0x0020 25e2f7a777SLen Brown #define ACPI_PARSE_EXECUTE 0x0030 26e2f7a777SLen Brown #define ACPI_PARSE_MODE_MASK 0x0030 27e2f7a777SLen Brown 28e2f7a777SLen Brown #define ACPI_PARSE_DEFERRED_OP 0x0100 29e2f7a777SLen Brown #define ACPI_PARSE_DISASSEMBLE 0x0200 30e2f7a777SLen Brown 317f0c826aSLin Ming #define ACPI_PARSE_MODULE_LEVEL 0x0400 327f0c826aSLin Ming 33e2f7a777SLen Brown /****************************************************************************** 34e2f7a777SLen Brown * 35e2f7a777SLen Brown * Parser interfaces 36e2f7a777SLen Brown * 37e2f7a777SLen Brown *****************************************************************************/ 38e2f7a777SLen Brown 39b0e01c72SBob Moore extern const u8 acpi_gbl_short_op_index[]; 40b0e01c72SBob Moore extern const u8 acpi_gbl_long_op_index[]; 41b0e01c72SBob Moore 42e2f7a777SLen Brown /* 43e2f7a777SLen Brown * psxface - Parser external interfaces 44e2f7a777SLen Brown */ 45e2f7a777SLen Brown acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info); 46e2f7a777SLen Brown 47de56ba95SLv Zheng acpi_status acpi_ps_execute_table(struct acpi_evaluate_info *info); 48de56ba95SLv Zheng 49e2f7a777SLen Brown /* 50e2f7a777SLen Brown * psargs - Parse AML opcode arguments 51e2f7a777SLen Brown */ 52e2f7a777SLen Brown u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state); 53e2f7a777SLen Brown 54e2f7a777SLen Brown char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state); 55e2f7a777SLen Brown 56e2f7a777SLen Brown void 57e2f7a777SLen Brown acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state, 58e2f7a777SLen Brown u32 arg_type, union acpi_parse_object *arg); 59e2f7a777SLen Brown 60e2f7a777SLen Brown acpi_status 61e2f7a777SLen Brown acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state, 62e2f7a777SLen Brown struct acpi_parse_state *parser_state, 6389438f96SBob Moore union acpi_parse_object *arg, 6489438f96SBob Moore u8 possible_method_call); 6589438f96SBob Moore 6689438f96SBob Moore /* Values for u8 above */ 6789438f96SBob Moore 6889438f96SBob Moore #define ACPI_NOT_METHOD_CALL FALSE 6989438f96SBob Moore #define ACPI_POSSIBLE_METHOD_CALL TRUE 70e2f7a777SLen Brown 71e2f7a777SLen Brown acpi_status 72e2f7a777SLen Brown acpi_ps_get_next_arg(struct acpi_walk_state *walk_state, 73e2f7a777SLen Brown struct acpi_parse_state *parser_state, 74e2f7a777SLen Brown u32 arg_type, union acpi_parse_object **return_arg); 75e2f7a777SLen Brown 76e2f7a777SLen Brown /* 77e2f7a777SLen Brown * psfind 78e2f7a777SLen Brown */ 79e2f7a777SLen Brown union acpi_parse_object *acpi_ps_find_name(union acpi_parse_object *scope, 80e2f7a777SLen Brown u32 name, u32 opcode); 81e2f7a777SLen Brown 82e2f7a777SLen Brown union acpi_parse_object *acpi_ps_get_parent(union acpi_parse_object *op); 83e2f7a777SLen Brown 84e2f7a777SLen Brown /* 8542f8fb75SBob Moore * psobject - support for parse object processing 8642f8fb75SBob Moore */ 8742f8fb75SBob Moore acpi_status 8842f8fb75SBob Moore acpi_ps_build_named_op(struct acpi_walk_state *walk_state, 8942f8fb75SBob Moore u8 *aml_op_start, 9042f8fb75SBob Moore union acpi_parse_object *unnamed_op, 9142f8fb75SBob Moore union acpi_parse_object **op); 9242f8fb75SBob Moore 9342f8fb75SBob Moore acpi_status 9442f8fb75SBob Moore acpi_ps_create_op(struct acpi_walk_state *walk_state, 9542f8fb75SBob Moore u8 *aml_op_start, union acpi_parse_object **new_op); 9642f8fb75SBob Moore 9742f8fb75SBob Moore acpi_status 9842f8fb75SBob Moore acpi_ps_complete_op(struct acpi_walk_state *walk_state, 9942f8fb75SBob Moore union acpi_parse_object **op, acpi_status status); 10042f8fb75SBob Moore 10142f8fb75SBob Moore acpi_status 10242f8fb75SBob Moore acpi_ps_complete_final_op(struct acpi_walk_state *walk_state, 10342f8fb75SBob Moore union acpi_parse_object *op, acpi_status status); 10442f8fb75SBob Moore 10542f8fb75SBob Moore /* 10642f8fb75SBob Moore * psopinfo - AML Opcode information 107e2f7a777SLen Brown */ 108e2f7a777SLen Brown const struct acpi_opcode_info *acpi_ps_get_opcode_info(u16 opcode); 109e2f7a777SLen Brown 1100dfaaa3dSBob Moore const char *acpi_ps_get_opcode_name(u16 opcode); 111e2f7a777SLen Brown 112e2f7a777SLen Brown u8 acpi_ps_get_argument_count(u32 op_type); 113e2f7a777SLen Brown 114e2f7a777SLen Brown /* 115e2f7a777SLen Brown * psparse - top level parsing routines 116e2f7a777SLen Brown */ 117e2f7a777SLen Brown acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state); 118e2f7a777SLen Brown 119e2f7a777SLen Brown u32 acpi_ps_get_opcode_size(u32 opcode); 120e2f7a777SLen Brown 121e2f7a777SLen Brown u16 acpi_ps_peek_opcode(struct acpi_parse_state *state); 122e2f7a777SLen Brown 123e2f7a777SLen Brown acpi_status 124e2f7a777SLen Brown acpi_ps_complete_this_op(struct acpi_walk_state *walk_state, 125e2f7a777SLen Brown union acpi_parse_object *op); 126e2f7a777SLen Brown 127e2f7a777SLen Brown acpi_status 128e2f7a777SLen Brown acpi_ps_next_parse_state(struct acpi_walk_state *walk_state, 129e2f7a777SLen Brown union acpi_parse_object *op, 130e2f7a777SLen Brown acpi_status callback_status); 131e2f7a777SLen Brown 132e2f7a777SLen Brown /* 133e2f7a777SLen Brown * psloop - main parse loop 134e2f7a777SLen Brown */ 135e2f7a777SLen Brown acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state); 136e2f7a777SLen Brown 137e2f7a777SLen Brown /* 138e2f7a777SLen Brown * psscope - Scope stack management routines 139e2f7a777SLen Brown */ 140e2f7a777SLen Brown acpi_status 141e2f7a777SLen Brown acpi_ps_init_scope(struct acpi_parse_state *parser_state, 142e2f7a777SLen Brown union acpi_parse_object *root); 143e2f7a777SLen Brown 144e2f7a777SLen Brown union acpi_parse_object *acpi_ps_get_parent_scope(struct acpi_parse_state 145e2f7a777SLen Brown *state); 146e2f7a777SLen Brown 147e2f7a777SLen Brown u8 acpi_ps_has_completed_scope(struct acpi_parse_state *parser_state); 148e2f7a777SLen Brown 149e2f7a777SLen Brown void 150e2f7a777SLen Brown acpi_ps_pop_scope(struct acpi_parse_state *parser_state, 1511f86e8c1SLv Zheng union acpi_parse_object **op, u32 *arg_list, u32 *arg_count); 152e2f7a777SLen Brown 153e2f7a777SLen Brown acpi_status 154e2f7a777SLen Brown acpi_ps_push_scope(struct acpi_parse_state *parser_state, 155e2f7a777SLen Brown union acpi_parse_object *op, 156e2f7a777SLen Brown u32 remaining_args, u32 arg_count); 157e2f7a777SLen Brown 158e2f7a777SLen Brown void acpi_ps_cleanup_scope(struct acpi_parse_state *state); 159e2f7a777SLen Brown 160e2f7a777SLen Brown /* 161e2f7a777SLen Brown * pstree - parse tree manipulation routines 162e2f7a777SLen Brown */ 163e2f7a777SLen Brown void 164e2f7a777SLen Brown acpi_ps_append_arg(union acpi_parse_object *op, union acpi_parse_object *arg); 165e2f7a777SLen Brown 166e2f7a777SLen Brown union acpi_parse_object *acpi_ps_find(union acpi_parse_object *scope, 167e2f7a777SLen Brown char *path, u16 opcode, u32 create); 168e2f7a777SLen Brown 169e2f7a777SLen Brown union acpi_parse_object *acpi_ps_get_arg(union acpi_parse_object *op, u32 argn); 170e2f7a777SLen Brown 171e2f7a777SLen Brown union acpi_parse_object *acpi_ps_get_depth_next(union acpi_parse_object *origin, 172e2f7a777SLen Brown union acpi_parse_object *op); 173e2f7a777SLen Brown 174e2f7a777SLen Brown /* 175e2f7a777SLen Brown * pswalk - parse tree walk routines 176e2f7a777SLen Brown */ 177e2f7a777SLen Brown acpi_status 178e2f7a777SLen Brown acpi_ps_walk_parsed_aml(union acpi_parse_object *start_op, 179e2f7a777SLen Brown union acpi_parse_object *end_op, 180e2f7a777SLen Brown union acpi_operand_object *mth_desc, 181e2f7a777SLen Brown struct acpi_namespace_node *start_node, 182e2f7a777SLen Brown union acpi_operand_object **params, 183e2f7a777SLen Brown union acpi_operand_object **caller_return_desc, 184e2f7a777SLen Brown acpi_owner_id owner_id, 185e2f7a777SLen Brown acpi_parse_downwards descending_callback, 186e2f7a777SLen Brown acpi_parse_upwards ascending_callback); 187e2f7a777SLen Brown 188e2f7a777SLen Brown acpi_status 189e2f7a777SLen Brown acpi_ps_get_next_walk_op(struct acpi_walk_state *walk_state, 190e2f7a777SLen Brown union acpi_parse_object *op, 191e2f7a777SLen Brown acpi_parse_upwards ascending_callback); 192e2f7a777SLen Brown 193e2f7a777SLen Brown acpi_status acpi_ps_delete_completed_op(struct acpi_walk_state *walk_state); 194e2f7a777SLen Brown 195e2f7a777SLen Brown void acpi_ps_delete_parse_tree(union acpi_parse_object *root); 196e2f7a777SLen Brown 197e2f7a777SLen Brown /* 198e2f7a777SLen Brown * psutils - parser utilities 199e2f7a777SLen Brown */ 20062eb935bSLv Zheng union acpi_parse_object *acpi_ps_create_scope_op(u8 *aml); 201e2f7a777SLen Brown 202e2f7a777SLen Brown void acpi_ps_init_op(union acpi_parse_object *op, u16 opcode); 203e2f7a777SLen Brown 20462eb935bSLv Zheng union acpi_parse_object *acpi_ps_alloc_op(u16 opcode, u8 *aml); 205e2f7a777SLen Brown 206e2f7a777SLen Brown void acpi_ps_free_op(union acpi_parse_object *op); 207e2f7a777SLen Brown 208e2f7a777SLen Brown u8 acpi_ps_is_leading_char(u32 c); 209e2f7a777SLen Brown 210e2f7a777SLen Brown u32 acpi_ps_get_name(union acpi_parse_object *op); 211e2f7a777SLen Brown 212e2f7a777SLen Brown void acpi_ps_set_name(union acpi_parse_object *op, u32 name); 213e2f7a777SLen Brown 214e2f7a777SLen Brown /* 215e2f7a777SLen Brown * psdump - display parser tree 216e2f7a777SLen Brown */ 217e2f7a777SLen Brown u32 218e2f7a777SLen Brown acpi_ps_sprint_path(char *buffer_start, 219e2f7a777SLen Brown u32 buffer_size, union acpi_parse_object *op); 220e2f7a777SLen Brown 221e2f7a777SLen Brown u32 222e2f7a777SLen Brown acpi_ps_sprint_op(char *buffer_start, 223e2f7a777SLen Brown u32 buffer_size, union acpi_parse_object *op); 224e2f7a777SLen Brown 225e2f7a777SLen Brown void acpi_ps_show(union acpi_parse_object *op); 226e2f7a777SLen Brown 227e2f7a777SLen Brown #endif /* __ACPARSER_H__ */ 228