acpi_status acpi_ds_auto_serialize_method(struct acpi_namespace_node *node, union acpi_operand_object *obj_desc) { acpi_status status; union acpi_parse_object *op = NULL; struct acpi_walk_state *walk_state; ACPI_FUNCTION_TRACE_PTR(ds_auto_serialize_method, node); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Method auto-serialization parse [%4.4s] %p\n", acpi_ut_get_node_name(node), node)); acpi_ex_enter_interpreter(); /* Create/Init a root op for the method parse tree */ op = acpi_ps_alloc_op(AML_METHOD_OP, obj_desc->method.aml_start); if (!op) { status = AE_NO_MEMORY; goto unlock; } acpi_ps_set_name(op, node->name.integer); op->common.node = node; /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state(node->owner_id, NULL, NULL, NULL); if (!walk_state) { acpi_ps_free_op(op); status = AE_NO_MEMORY; goto unlock; } status = acpi_ds_init_aml_walk(walk_state, op, node, obj_desc->method.aml_start, obj_desc->method.aml_length, NULL, 0); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); acpi_ps_free_op(op); return_ACPI_STATUS(status); } walk_state->descending_callback = acpi_ds_detect_named_opcodes; /* Parse the method, scan for creation of named objects */ status = acpi_ps_parse_aml(walk_state); acpi_ps_delete_parse_tree(op); unlock: acpi_ex_exit_interpreter(); return_ACPI_STATUS(status); }
/******************************************************************************* * * FUNCTION: acpi_ps_create_scope_op * * PARAMETERS: None * * RETURN: A new Scope object, null on failure * * DESCRIPTION: Create a Scope and associated namepath op with the root name * ******************************************************************************/ union acpi_parse_object *acpi_ps_create_scope_op(void) { union acpi_parse_object *scope_op; scope_op = acpi_ps_alloc_op(AML_SCOPE_OP); if (!scope_op) { return (NULL); } scope_op->named.name = ACPI_ROOT_NAME; return (scope_op); }
acpi_status acpi_ns_one_complete_parse ( u32 pass_number, acpi_table_desc *table_desc) { acpi_parse_object *parse_root; acpi_status status; acpi_walk_state *walk_state; FUNCTION_TRACE ("Ns_one_complete_parse"); /* Create and init a Root Node */ parse_root = acpi_ps_alloc_op (AML_SCOPE_OP); if (!parse_root) { return_ACPI_STATUS (AE_NO_MEMORY); } ((acpi_parse2_object *) parse_root)->name = ACPI_ROOT_NAME; /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state (TABLE_ID_DSDT, NULL, NULL, NULL); if (!walk_state) { acpi_ps_free_op (parse_root); return_ACPI_STATUS (AE_NO_MEMORY); } status = acpi_ds_init_aml_walk (walk_state, parse_root, NULL, table_desc->aml_start, table_desc->aml_length, NULL, NULL, pass_number); if (ACPI_FAILURE (status)) { acpi_ds_delete_walk_state (walk_state); return_ACPI_STATUS (status); } /* Parse the AML */ ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %d parse\n", pass_number)); status = acpi_ps_parse_aml (walk_state); acpi_ps_delete_parse_tree (parse_root); return_ACPI_STATUS (status); }
acpi_status acpi_psx_execute ( acpi_namespace_node *method_node, acpi_operand_object **params, acpi_operand_object **return_obj_desc) { acpi_status status; acpi_operand_object *obj_desc; u32 i; acpi_parse_object *op; acpi_walk_state *walk_state; FUNCTION_TRACE ("Psx_execute"); /* Validate the Node and get the attached object */ if (!method_node) { return_ACPI_STATUS (AE_NULL_ENTRY); } obj_desc = acpi_ns_get_attached_object (method_node); if (!obj_desc) { return_ACPI_STATUS (AE_NULL_OBJECT); } /* Init for new method, wait on concurrency semaphore */ status = acpi_ds_begin_method_execution (method_node, obj_desc, NULL); if (ACPI_FAILURE (status)) { return_ACPI_STATUS (status); } if (params) { /* * The caller "owns" the parameters, so give each one an extra * reference */ for (i = 0; params[i]; i++) { acpi_ut_add_reference (params[i]); } } /* * 1) Perform the first pass parse of the method to enter any * named objects that it creates into the namespace */ ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "**** Begin Method Parse **** Entry=%p obj=%p\n", method_node, obj_desc)); /* Create and init a Root Node */ op = acpi_ps_alloc_op (AML_SCOPE_OP); if (!op) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state (TABLE_ID_DSDT, NULL, NULL, NULL); if (!walk_state) { return_ACPI_STATUS (AE_NO_MEMORY); } status = acpi_ds_init_aml_walk (walk_state, op, method_node, obj_desc->method.aml_start, obj_desc->method.aml_length, NULL, NULL, 1); if (ACPI_FAILURE (status)) { /* TBD: delete walk state */ return_ACPI_STATUS (status); } /* Parse the AML */ status = acpi_ps_parse_aml (walk_state); acpi_ps_delete_parse_tree (op); /* * 2) Execute the method. Performs second pass parse simultaneously */ ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "**** Begin Method Execution **** Entry=%p obj=%p\n", method_node, obj_desc)); /* Create and init a Root Node */ op = acpi_ps_alloc_op (AML_SCOPE_OP); if (!op) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Init new op with the method name and pointer back to the NS node */ acpi_ps_set_name (op, method_node->name); op->node = method_node; /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state (TABLE_ID_DSDT, NULL, NULL, NULL); if (!walk_state) { return_ACPI_STATUS (AE_NO_MEMORY); } status = acpi_ds_init_aml_walk (walk_state, op, method_node, obj_desc->method.aml_start, obj_desc->method.aml_length, params, return_obj_desc, 3); if (ACPI_FAILURE (status)) { /* TBD: delete walk state */ return_ACPI_STATUS (status); } /* * The walk of the parse tree is where we actually execute the method */ status = acpi_ps_parse_aml (walk_state); acpi_ps_delete_parse_tree (op); if (params) { /* Take away the extra reference that we gave the parameters above */ for (i = 0; params[i]; i++) { acpi_ut_update_object_reference (params[i], REF_DECREMENT); } } if (ACPI_FAILURE (status)) { DUMP_PATHNAME (method_node, "Ps_execute: method failed -", ACPI_LV_ERROR, _COMPONENT); } /* * If the method has returned an object, signal this to the caller with * a control exception code */ if (*return_obj_desc) { ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Method returned Obj_desc=%p\n", *return_obj_desc)); DUMP_STACK_ENTRY (*return_obj_desc); status = AE_CTRL_RETURN_VALUE; } return_ACPI_STATUS (status); }
acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state) { acpi_status status = AE_OK; acpi_status status2; union acpi_parse_object *op = NULL; /* current op */ union acpi_parse_object *arg = NULL; union acpi_parse_object *pre_op = NULL; struct acpi_parse_state *parser_state; u8 *aml_op_start = NULL; ACPI_FUNCTION_TRACE_PTR("ps_parse_loop", walk_state); if (walk_state->descending_callback == NULL) { return_ACPI_STATUS(AE_BAD_PARAMETER); } parser_state = &walk_state->parser_state; walk_state->arg_types = 0; #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { /* We are restarting a preempted control method */ if (acpi_ps_has_completed_scope(parser_state)) { /* * We must check if a predicate to an IF or WHILE statement * was just completed */ if ((parser_state->scope->parse_scope.op) && ((parser_state->scope->parse_scope.op->common. aml_opcode == AML_IF_OP) || (parser_state->scope->parse_scope.op->common. aml_opcode == AML_WHILE_OP)) && (walk_state->control_state) && (walk_state->control_state->common.state == ACPI_CONTROL_PREDICATE_EXECUTING)) { /* * A predicate was just completed, get the value of the * predicate and branch based on that value */ walk_state->op = NULL; status = acpi_ds_get_predicate_value(walk_state, ACPI_TO_POINTER (TRUE)); if (ACPI_FAILURE(status) && ((status & AE_CODE_MASK) != AE_CODE_CONTROL)) { if (status == AE_AML_NO_RETURN_VALUE) { ACPI_EXCEPTION((AE_INFO, status, "Invoked method did not return a value")); } ACPI_EXCEPTION((AE_INFO, status, "get_predicate Failed")); return_ACPI_STATUS(status); } status = acpi_ps_next_parse_state(walk_state, op, status); } acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, &walk_state->arg_count); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", op)); } else if (walk_state->prev_op) { /* We were in the middle of an op */ op = walk_state->prev_op; walk_state->arg_types = walk_state->prev_arg_types; } } #endif /* Iterative parsing loop, while there is more AML to process: */ while ((parser_state->aml < parser_state->aml_end) || (op)) { aml_op_start = parser_state->aml; if (!op) { /* Get the next opcode from the AML stream */ walk_state->aml_offset = (u32) ACPI_PTR_DIFF(parser_state->aml, parser_state->aml_start); walk_state->opcode = acpi_ps_peek_opcode(parser_state); /* * First cut to determine what we have found: * 1) A valid AML opcode * 2) A name string * 3) An unknown/invalid opcode */ walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode); switch (walk_state->op_info->class) { case AML_CLASS_ASCII: case AML_CLASS_PREFIX: /* * Starts with a valid prefix or ASCII char, this is a name * string. Convert the bare name string to a namepath. */ walk_state->opcode = AML_INT_NAMEPATH_OP; walk_state->arg_types = ARGP_NAMESTRING; break; case AML_CLASS_UNKNOWN: /* The opcode is unrecognized. Just skip unknown opcodes */ ACPI_ERROR((AE_INFO, "Found unknown opcode %X at AML address %p offset %X, ignoring", walk_state->opcode, parser_state->aml, walk_state->aml_offset)); ACPI_DUMP_BUFFER(parser_state->aml, 128); /* Assume one-byte bad opcode */ parser_state->aml++; continue; default: /* Found opcode info, this is a normal opcode */ parser_state->aml += acpi_ps_get_opcode_size(walk_state->opcode); walk_state->arg_types = walk_state->op_info->parse_args; break; } /* Create Op structure and append to parent's argument list */ if (walk_state->op_info->flags & AML_NAMED) { /* Allocate a new pre_op if necessary */ if (!pre_op) { pre_op = acpi_ps_alloc_op(walk_state-> opcode); if (!pre_op) { status = AE_NO_MEMORY; goto close_this_op; } } pre_op->common.value.arg = NULL; pre_op->common.aml_opcode = walk_state->opcode; /* * Get and append arguments until we find the node that contains * the name (the type ARGP_NAME). */ while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) && (GET_CURRENT_ARG_TYPE (walk_state->arg_types) != ARGP_NAME)) { status = acpi_ps_get_next_arg(walk_state, parser_state, GET_CURRENT_ARG_TYPE (walk_state-> arg_types), &arg); if (ACPI_FAILURE(status)) { goto close_this_op; } acpi_ps_append_arg(pre_op, arg); INCREMENT_ARG_LIST(walk_state-> arg_types); } /* * Make sure that we found a NAME and didn't run out of * arguments */ if (!GET_CURRENT_ARG_TYPE (walk_state->arg_types)) { status = AE_AML_NO_OPERAND; goto close_this_op; } /* We know that this arg is a name, move to next arg */ INCREMENT_ARG_LIST(walk_state->arg_types); /* * Find the object. This will either insert the object into * the namespace or simply look it up */ walk_state->op = NULL; status = walk_state->descending_callback(walk_state, &op); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "During name lookup/catalog")); goto close_this_op; } if (!op) { continue; } status = acpi_ps_next_parse_state(walk_state, op, status); if (status == AE_CTRL_PENDING) { status = AE_OK; goto close_this_op; } if (ACPI_FAILURE(status)) { goto close_this_op; } acpi_ps_append_arg(op, pre_op->common.value.arg); acpi_gbl_depth++; if (op->common.aml_opcode == AML_REGION_OP) { /* * Defer final parsing of an operation_region body, * because we don't have enough info in the first pass * to parse it correctly (i.e., there may be method * calls within the term_arg elements of the body.) * * However, we must continue parsing because * the opregion is not a standalone package -- * we don't know where the end is at this point. * * (Length is unknown until parse of the body complete) */ op->named.data = aml_op_start; op->named.length = 0; } } else { /* Not a named opcode, just allocate Op and append to parent */ walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode); op = acpi_ps_alloc_op(walk_state->opcode); if (!op) { status = AE_NO_MEMORY; goto close_this_op; } if (walk_state->op_info->flags & AML_CREATE) { /* * Backup to beginning of create_xXXfield declaration * body_length is unknown until we parse the body */ op->named.data = aml_op_start; op->named.length = 0; } acpi_ps_append_arg(acpi_ps_get_parent_scope (parser_state), op); if ((walk_state->descending_callback != NULL)) { /* * Find the object. This will either insert the object into * the namespace or simply look it up */ walk_state->op = op; status = walk_state-> descending_callback(walk_state, &op); status = acpi_ps_next_parse_state(walk_state, op, status); if (status == AE_CTRL_PENDING) { status = AE_OK; goto close_this_op; } if (ACPI_FAILURE(status)) { goto close_this_op; } } } op->common.aml_offset = walk_state->aml_offset; if (walk_state->op_info) { ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Opcode %4.4X [%s] Op %p Aml %p aml_offset %5.5X\n", (u32) op->common.aml_opcode, walk_state->op_info->name, op, parser_state->aml, op->common.aml_offset)); } } /* * Start arg_count at zero because we don't know if there are * any args yet */ walk_state->arg_count = 0; /* Are there any arguments that must be processed? */ if (walk_state->arg_types) { /* Get arguments */ switch (op->common.aml_opcode) { case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ case AML_WORD_OP: /* AML_WORDDATA_ARG */ case AML_DWORD_OP: /* AML_DWORDATA_ARG */ case AML_QWORD_OP: /* AML_QWORDATA_ARG */ case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */ /* Fill in constant or string argument directly */ acpi_ps_get_next_simple_arg(parser_state, GET_CURRENT_ARG_TYPE (walk_state-> arg_types), op); break; case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */ status = acpi_ps_get_next_namepath(walk_state, parser_state, op, 1); if (ACPI_FAILURE(status)) { goto close_this_op; } walk_state->arg_types = 0; break; default: /* * Op is not a constant or string, append each argument * to the Op */ while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) && !walk_state->arg_count) { walk_state->aml_offset = (u32) ACPI_PTR_DIFF(parser_state->aml, parser_state-> aml_start); status = acpi_ps_get_next_arg(walk_state, parser_state, GET_CURRENT_ARG_TYPE (walk_state-> arg_types), &arg); if (ACPI_FAILURE(status)) { goto close_this_op; } if (arg) { arg->common.aml_offset = walk_state->aml_offset; acpi_ps_append_arg(op, arg); } INCREMENT_ARG_LIST(walk_state-> arg_types); } /* Special processing for certain opcodes */ /* TBD (remove): Temporary mechanism to disable this code if needed */ #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS1) && ((walk_state-> parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) { /* * We want to skip If/Else/While constructs during Pass1 * because we want to actually conditionally execute the * code during Pass2. * * Except for disassembly, where we always want to * walk the If/Else/While packages */ switch (op->common.aml_opcode) { case AML_IF_OP: case AML_ELSE_OP: case AML_WHILE_OP: ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Pass1: Skipping an If/Else/While body\n")); /* Skip body of if/else/while in pass 1 */ parser_state->aml = parser_state->pkg_end; walk_state->arg_count = 0; break; default: break; } } #endif switch (op->common.aml_opcode) { case AML_METHOD_OP: /* * Skip parsing of control method * because we don't have enough info in the first pass * to parse it correctly. * * Save the length and address of the body */ op->named.data = parser_state->aml; op->named.length = (u32) (parser_state->pkg_end - parser_state->aml); /* Skip body of method */ parser_state->aml = parser_state->pkg_end; walk_state->arg_count = 0; break; case AML_BUFFER_OP: case AML_PACKAGE_OP: case AML_VAR_PACKAGE_OP: if ((op->common.parent) && (op->common.parent->common. aml_opcode == AML_NAME_OP) && (walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2)) { /* * Skip parsing of Buffers and Packages * because we don't have enough info in the first pass * to parse them correctly. */ op->named.data = aml_op_start; op->named.length = (u32) (parser_state-> pkg_end - aml_op_start); /* Skip body */ parser_state->aml = parser_state->pkg_end; walk_state->arg_count = 0; } break; case AML_WHILE_OP: if (walk_state->control_state) { walk_state->control_state-> control.package_end = parser_state->pkg_end; } break; default: /* No action for all other opcodes */ break; } break; } } /* Check for arguments that need to be processed */ if (walk_state->arg_count) { /* * There are arguments (complex ones), push Op and * prepare for argument */ status = acpi_ps_push_scope(parser_state, op, walk_state->arg_types, walk_state->arg_count); if (ACPI_FAILURE(status)) { goto close_this_op; } op = NULL; continue; } /* * All arguments have been processed -- Op is complete, * prepare for next */ walk_state->op_info = acpi_ps_get_opcode_info(op->common.aml_opcode); if (walk_state->op_info->flags & AML_NAMED) { if (acpi_gbl_depth) { acpi_gbl_depth--; } if (op->common.aml_opcode == AML_REGION_OP) { /* * Skip parsing of control method or opregion body, * because we don't have enough info in the first pass * to parse them correctly. * * Completed parsing an op_region declaration, we now * know the length. */ op->named.length = (u32) (parser_state->aml - op->named.data); } } if (walk_state->op_info->flags & AML_CREATE) { /* * Backup to beginning of create_xXXfield declaration (1 for * Opcode) * * body_length is unknown until we parse the body */ op->named.length = (u32) (parser_state->aml - op->named.data); } /* This op complete, notify the dispatcher */ if (walk_state->ascending_callback != NULL) { walk_state->op = op; walk_state->opcode = op->common.aml_opcode; status = walk_state->ascending_callback(walk_state); status = acpi_ps_next_parse_state(walk_state, op, status); if (status == AE_CTRL_PENDING) { status = AE_OK; goto close_this_op; } } close_this_op: /* * Finished one argument of the containing scope */ parser_state->scope->parse_scope.arg_count--; /* Finished with pre_op */ if (pre_op) { acpi_ps_free_op(pre_op); pre_op = NULL; } /* Close this Op (will result in parse subtree deletion) */ status2 = acpi_ps_complete_this_op(walk_state, op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } op = NULL; switch (status) { case AE_OK: break; case AE_CTRL_TRANSFER: /* We are about to transfer to a called method. */ walk_state->prev_op = op; walk_state->prev_arg_types = walk_state->arg_types; return_ACPI_STATUS(status); case AE_CTRL_END: acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, &walk_state->arg_count); if (op) { walk_state->op = op; walk_state->op_info = acpi_ps_get_opcode_info(op->common. aml_opcode); walk_state->opcode = op->common.aml_opcode; status = walk_state->ascending_callback(walk_state); status = acpi_ps_next_parse_state(walk_state, op, status); status2 = acpi_ps_complete_this_op(walk_state, op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } op = NULL; } status = AE_OK; break; case AE_CTRL_BREAK: case AE_CTRL_CONTINUE: /* Pop off scopes until we find the While */ while (!op || (op->common.aml_opcode != AML_WHILE_OP)) { acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, &walk_state->arg_count); if (op->common.aml_opcode != AML_WHILE_OP) { status2 = acpi_ds_result_stack_pop (walk_state); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } } } /* Close this iteration of the While loop */ walk_state->op = op; walk_state->op_info = acpi_ps_get_opcode_info(op->common.aml_opcode); walk_state->opcode = op->common.aml_opcode; status = walk_state->ascending_callback(walk_state); status = acpi_ps_next_parse_state(walk_state, op, status); status2 = acpi_ps_complete_this_op(walk_state, op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } op = NULL; status = AE_OK; break; case AE_CTRL_TERMINATE: status = AE_OK; /* Clean up */ do { if (op) { status2 = acpi_ps_complete_this_op(walk_state, op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } } acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, &walk_state->arg_count); } while (op); return_ACPI_STATUS(status); default: /* All other non-AE_OK status */ do { if (op) { status2 = acpi_ps_complete_this_op(walk_state, op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } } acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, &walk_state->arg_count); } while (op); /* * TBD: Cleanup parse ops on error */ #if 0 if (op == NULL) { acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, &walk_state->arg_count); } #endif walk_state->prev_op = op; walk_state->prev_arg_types = walk_state->arg_types; return_ACPI_STATUS(status); } /* This scope complete? */ if (acpi_ps_has_completed_scope(parser_state)) { acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, &walk_state->arg_count); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", op)); } else { op = NULL; } } /* while parser_state->Aml */
acpi_status acpi_ps_get_next_arg(struct acpi_walk_state *walk_state, struct acpi_parse_state *parser_state, u32 arg_type, union acpi_parse_object **return_arg) { union acpi_parse_object *arg = NULL; union acpi_parse_object *prev = NULL; union acpi_parse_object *field; u32 subop; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE_PTR("ps_get_next_arg", parser_state); switch (arg_type) { case ARGP_BYTEDATA: case ARGP_WORDDATA: case ARGP_DWORDDATA: case ARGP_CHARLIST: case ARGP_NAME: case ARGP_NAMESTRING: /* Constants, strings, and namestrings are all the same size */ arg = acpi_ps_alloc_op(AML_BYTE_OP); if (!arg) { return_ACPI_STATUS(AE_NO_MEMORY); } acpi_ps_get_next_simple_arg(parser_state, arg_type, arg); break; case ARGP_PKGLENGTH: /* Package length, nothing returned */ parser_state->pkg_end = acpi_ps_get_next_package_end(parser_state); break; case ARGP_FIELDLIST: if (parser_state->aml < parser_state->pkg_end) { /* Non-empty list */ while (parser_state->aml < parser_state->pkg_end) { field = acpi_ps_get_next_field(parser_state); if (!field) { return_ACPI_STATUS(AE_NO_MEMORY); } if (prev) { prev->common.next = field; } else { arg = field; } prev = field; } /* Skip to End of byte data */ parser_state->aml = parser_state->pkg_end; } break; case ARGP_BYTELIST: if (parser_state->aml < parser_state->pkg_end) { /* Non-empty list */ arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP); if (!arg) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Fill in bytelist data */ arg->common.value.size = (u32) ACPI_PTR_DIFF(parser_state->pkg_end, parser_state->aml); arg->named.data = parser_state->aml; /* Skip to End of byte data */ parser_state->aml = parser_state->pkg_end; } break; case ARGP_TARGET: case ARGP_SUPERNAME: case ARGP_SIMPLENAME: subop = acpi_ps_peek_opcode(parser_state); if (subop == 0 || acpi_ps_is_leading_char(subop) || acpi_ps_is_prefix_char(subop)) { /* null_name or name_string */ arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP); if (!arg) { return_ACPI_STATUS(AE_NO_MEMORY); } status = acpi_ps_get_next_namepath(walk_state, parser_state, arg, 0); } else { /* Single complex argument, nothing returned */ walk_state->arg_count = 1; } break; case ARGP_DATAOBJ: case ARGP_TERMARG: /* Single complex argument, nothing returned */ walk_state->arg_count = 1; break; case ARGP_DATAOBJLIST: case ARGP_TERMLIST: case ARGP_OBJLIST: if (parser_state->aml < parser_state->pkg_end) { /* Non-empty list of variable arguments, nothing returned */ walk_state->arg_count = ACPI_VAR_ARGS; } break; default: ACPI_REPORT_ERROR(("Invalid arg_type: %X\n", arg_type)); status = AE_AML_OPERAND_TYPE; break; } *return_arg = arg; return_ACPI_STATUS(status); }
void acpi_ps_get_next_namepath ( ACPI_PARSE_STATE *parser_state, ACPI_PARSE_OBJECT *arg, u32 *arg_count, u8 method_call) { NATIVE_CHAR *path; ACPI_PARSE_OBJECT *name_op; ACPI_PARSE_OBJECT *op; ACPI_PARSE_OBJECT *count; path = acpi_ps_get_next_namestring (parser_state); if (!path || !method_call) { /* Null name case, create a null namepath object */ acpi_ps_init_op (arg, AML_NAMEPATH_OP); arg->value.name = path; return; } if (acpi_gbl_parsed_namespace_root) { /* * Lookup the name in the parsed namespace */ op = NULL; if (method_call) { op = acpi_ps_find (acpi_ps_get_parent_scope (parser_state), path, AML_METHOD_OP, 0); } if (op) { if (op->opcode == AML_METHOD_OP) { /* * The name refers to a control method, so this namepath is a * method invocation. We need to 1) Get the number of arguments * associated with this method, and 2) Change the NAMEPATH * object into a METHODCALL object. */ count = acpi_ps_get_arg (op, 0); if (count && count->opcode == AML_BYTE_OP) { name_op = acpi_ps_alloc_op (AML_NAMEPATH_OP); if (name_op) { /* Change arg into a METHOD CALL and attach the name */ acpi_ps_init_op (arg, AML_METHODCALL_OP); name_op->value.name = path; /* Point METHODCALL/NAME to the METHOD Node */ name_op->node = (ACPI_NAMESPACE_NODE *) op; acpi_ps_append_arg (arg, name_op); *arg_count = count->value.integer & METHOD_FLAGS_ARG_COUNT; } } return; } /* * Else this is normal named object reference. * Just init the NAMEPATH object with the pathname. * (See code below) */ } } /* * Either we didn't find the object in the namespace, or the object is * something other than a control method. Just initialize the Op with the * pathname */ acpi_ps_init_op (arg, AML_NAMEPATH_OP); arg->value.name = path; return; }
/******************************************************************************* * * FUNCTION: acpi_ds_parse_method * * PARAMETERS: Node - Method node * * RETURN: Status * * DESCRIPTION: Parse the AML that is associated with the method. * * MUTEX: Assumes parser is locked * ******************************************************************************/ acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node) { acpi_status status; union acpi_operand_object *obj_desc; union acpi_parse_object *op; struct acpi_walk_state *walk_state; ACPI_FUNCTION_TRACE_PTR("ds_parse_method", node); /* Parameter Validation */ if (!node) { return_ACPI_STATUS(AE_NULL_ENTRY); } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Parsing [%4.4s] **** named_obj=%p\n", acpi_ut_get_node_name(node), node)); /* Extract the method object from the method Node */ obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { return_ACPI_STATUS(AE_NULL_OBJECT); } /* Create a mutex for the method if there is a concurrency limit */ if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) && (!obj_desc->method.semaphore)) { status = acpi_os_create_semaphore(obj_desc->method.concurrency, obj_desc->method.concurrency, &obj_desc->method.semaphore); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } /* * Allocate a new parser op to be the root of the parsed * method tree */ op = acpi_ps_alloc_op(AML_METHOD_OP); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Init new op with the method name and pointer back to the Node */ acpi_ps_set_name(op, node->name.integer); op->common.node = node; /* * Get a new owner_id for objects created by this method. Namespace * objects (such as Operation Regions) can be created during the * first pass parse. */ status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); if (ACPI_FAILURE(status)) { goto cleanup; } /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL, NULL); if (!walk_state) { status = AE_NO_MEMORY; goto cleanup2; } status = acpi_ds_init_aml_walk(walk_state, op, node, obj_desc->method.aml_start, obj_desc->method.aml_length, NULL, 1); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup2; } /* * Parse the method, first pass * * The first pass load is where newly declared named objects are added into * the namespace. Actual evaluation of the named objects (what would be * called a "second pass") happens during the actual execution of the * method so that operands to the named objects can take on dynamic * run-time values. */ status = acpi_ps_parse_aml(walk_state); if (ACPI_FAILURE(status)) { goto cleanup2; } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** [%4.4s] Parsed **** named_obj=%p Op=%p\n", acpi_ut_get_node_name(node), node, op)); /* * Delete the parse tree. We simply re-parse the method for every * execution since there isn't much overhead (compared to keeping lots * of parse trees around) */ acpi_ns_delete_namespace_subtree(node); acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id); cleanup2: acpi_ut_release_owner_id(&obj_desc->method.owner_id); cleanup: acpi_ps_delete_parse_tree(op); return_ACPI_STATUS(status); }
static acpi_status acpi_ds_execute_arguments(struct acpi_namespace_node *node, struct acpi_namespace_node *scope_node, u32 aml_length, u8 *aml_start) { acpi_status status; union acpi_parse_object *op; struct acpi_walk_state *walk_state; ACPI_FUNCTION_TRACE(ds_execute_arguments); /* Allocate a new parser op to be the root of the parsed tree */ op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Save the Node for use in acpi_ps_parse_aml */ op->common.node = scope_node; /* Create and initialize a new parser state */ walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL); if (!walk_state) { status = AE_NO_MEMORY; goto cleanup; } status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, aml_length, NULL, ACPI_IMODE_LOAD_PASS1); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup; } /* Mark this parse as a deferred opcode */ walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP; walk_state->deferred_node = node; /* Pass1: Parse the entire declaration */ status = acpi_ps_parse_aml(walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } /* Get and init the Op created above */ op->common.node = node; acpi_ps_delete_parse_tree(op); /* Evaluate the deferred arguments */ op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } op->common.node = scope_node; /* Create and initialize a new parser state */ walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL); if (!walk_state) { status = AE_NO_MEMORY; goto cleanup; } /* Execute the opcode and arguments */ status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, aml_length, NULL, ACPI_IMODE_EXECUTE); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup; } /* Mark this execution as a deferred opcode */ walk_state->deferred_node = node; status = acpi_ps_parse_aml(walk_state); cleanup: acpi_ps_delete_parse_tree(op); return_ACPI_STATUS(status); }
acpi_status acpi_ds_load1_begin_op ( acpi_walk_state *walk_state, acpi_parse_object **out_op) { acpi_parse_object *op; acpi_namespace_node *node; acpi_status status; acpi_object_type8 data_type; NATIVE_CHAR *path; PROC_NAME ("Ds_load1_begin_op"); op = walk_state->op; ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state)); /* We are only interested in opcodes that have an associated name */ if (walk_state->op) { if (!(walk_state->op_info->flags & AML_NAMED)) { *out_op = op; return (AE_OK); } /* Check if this object has already been installed in the namespace */ if (op->node) { *out_op = op; return (AE_OK); } } path = acpi_ps_get_next_namestring (&walk_state->parser_state); /* Map the raw opcode into an internal object type */ data_type = acpi_ds_map_named_opcode_to_data_type (walk_state->opcode); ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "State=%p Op=%p Type=%x\n", walk_state, op, data_type)); if (walk_state->opcode == AML_SCOPE_OP) { ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "State=%p Op=%p Type=%x\n", walk_state, op, data_type)); } /* * Enter the named type into the internal namespace. We enter the name * as we go downward in the parse tree. Any necessary subobjects that involve * arguments to the opcode must be created as we go back up the parse tree later. */ status = acpi_ns_lookup (walk_state->scope_info, path, data_type, IMODE_LOAD_PASS1, NS_NO_UPSEARCH, walk_state, &(node)); if (ACPI_FAILURE (status)) { return (status); } if (!op) { /* Create a new op */ op = acpi_ps_alloc_op (walk_state->opcode); if (!op) { return (AE_NO_MEMORY); } } /* Initialize */ ((acpi_parse2_object *)op)->name = node->name; /* * Put the Node in the "op" object that the parser uses, so we * can get it again quickly when this scope is closed */ op->node = node; acpi_ps_append_arg (acpi_ps_get_parent_scope (&walk_state->parser_state), op); *out_op = op; return (status); }
ACPI_STATUS acpi_ds_parse_method ( ACPI_HANDLE obj_handle) { ACPI_STATUS status; ACPI_OPERAND_OBJECT *obj_desc; ACPI_PARSE_OBJECT *op; ACPI_NAMESPACE_NODE *node; ACPI_OWNER_ID owner_id; /* Parameter Validation */ if (!obj_handle) { return (AE_NULL_ENTRY); } /* Extract the method object from the method Node */ node = (ACPI_NAMESPACE_NODE *) obj_handle; obj_desc = node->object; if (!obj_desc) { return (AE_NULL_OBJECT); } /* Create a mutex for the method if there is a concurrency limit */ if ((obj_desc->method.concurrency != INFINITE_CONCURRENCY) && (!obj_desc->method.semaphore)) { status = acpi_os_create_semaphore (1,obj_desc->method.concurrency, &obj_desc->method.semaphore); if (ACPI_FAILURE (status)) { return (status); } } /* * Allocate a new parser op to be the root of the parsed * method tree */ op = acpi_ps_alloc_op (AML_METHOD_OP); if (!op) { return (AE_NO_MEMORY); } /* Init new op with the method name and pointer back to the Node */ acpi_ps_set_name (op, node->name); op->node = node; /* * Parse the method, first pass * * The first pass load is * where newly declared named objects are * added into the namespace. Actual evaluation of * the named objects (what would be called a "second * pass") happens during the actual execution of the * method so that operands to the named objects can * take on dynamic run-time values. */ status = acpi_ps_parse_aml (op, obj_desc->method.pcode, obj_desc->method.pcode_length, ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE, node, NULL, NULL, acpi_ds_load1_begin_op, acpi_ds_load1_end_op); if (ACPI_FAILURE (status)) { return (status); } /* Get a new Owner_id for objects created by this method */ owner_id = acpi_cm_allocate_owner_id (OWNER_TYPE_METHOD); obj_desc->method.owning_id = owner_id; /* Install the parsed tree in the method object */ /* TBD: [Restructure] Obsolete field? */ acpi_ps_delete_parse_tree (op); return (status); }
ACPI_STATUS acpi_ds_call_control_method ( ACPI_WALK_LIST *walk_list, ACPI_WALK_STATE *this_walk_state, ACPI_PARSE_OBJECT *op) { ACPI_STATUS status; ACPI_NAMESPACE_NODE *method_node; ACPI_OPERAND_OBJECT *obj_desc; ACPI_WALK_STATE *next_walk_state; ACPI_PARSE_STATE *parser_state; u32 i; /* * Get the namespace entry for the control method we are about to call */ method_node = this_walk_state->method_call_node; if (!method_node) { return (AE_NULL_ENTRY); } obj_desc = acpi_ns_get_attached_object (method_node); if (!obj_desc) { return (AE_NULL_OBJECT); } /* Init for new method, wait on concurrency semaphore */ status = acpi_ds_begin_method_execution (method_node, obj_desc); if (ACPI_FAILURE (status)) { return (status); } /* Create and initialize a new parser state */ parser_state = acpi_ps_create_state (obj_desc->method.pcode, obj_desc->method.pcode_length); if (!parser_state) { return (AE_NO_MEMORY); } acpi_ps_init_scope (parser_state, NULL); parser_state->start_node = method_node; /* Create a new state for the preempting walk */ next_walk_state = acpi_ds_create_walk_state (obj_desc->method.owning_id, NULL, obj_desc, walk_list); if (!next_walk_state) { /* TBD: delete parser state */ return (AE_NO_MEMORY); } next_walk_state->walk_type = WALK_METHOD; next_walk_state->method_node = method_node; next_walk_state->parser_state = parser_state; next_walk_state->parse_flags = this_walk_state->parse_flags; next_walk_state->descending_callback = this_walk_state->descending_callback; next_walk_state->ascending_callback = this_walk_state->ascending_callback; /* The Next_op of the Next_walk will be the beginning of the method */ /* TBD: [Restructure] -- obsolete? */ next_walk_state->next_op = NULL; /* Open a new scope */ status = acpi_ds_scope_stack_push (method_node, ACPI_TYPE_METHOD, next_walk_state); if (ACPI_FAILURE (status)) { goto cleanup; } /* * Initialize the arguments for the method. The resolved * arguments were put on the previous walk state's operand * stack. Operands on the previous walk state stack always * start at index 0. */ status = acpi_ds_method_data_init_args (&this_walk_state->operands[0], this_walk_state->num_operands, next_walk_state); if (ACPI_FAILURE (status)) { goto cleanup; } /* Create and init a Root Node */ op = acpi_ps_alloc_op (AML_SCOPE_OP); if (!op) { return (AE_NO_MEMORY); } status = acpi_ps_parse_aml (op, obj_desc->method.pcode, obj_desc->method.pcode_length, ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE, method_node, NULL, NULL, acpi_ds_load1_begin_op, acpi_ds_load1_end_op); acpi_ps_delete_parse_tree (op); /* * Delete the operands on the previous walkstate operand stack * (they were copied to new objects) */ for (i = 0; i < obj_desc->method.param_count; i++) { acpi_cm_remove_reference (this_walk_state->operands [i]); this_walk_state->operands [i] = NULL; } /* Clear the operand stack */ this_walk_state->num_operands = 0; return (AE_OK); /* On error, we must delete the new walk state */ cleanup: acpi_ds_terminate_control_method (next_walk_state); acpi_ds_delete_walk_state (next_walk_state); return (status); }
ACPI_PARSE_OBJECT * acpi_ps_get_next_arg ( ACPI_PARSE_STATE *parser_state, u32 arg_type, u32 *arg_count) { ACPI_PARSE_OBJECT *arg = NULL; ACPI_PARSE_OBJECT *prev = NULL; ACPI_PARSE_OBJECT *field; u32 subop; switch (arg_type) { case ARGP_BYTEDATA: case ARGP_WORDDATA: case ARGP_DWORDDATA: case ARGP_CHARLIST: case ARGP_NAME: case ARGP_NAMESTRING: /* constants, strings, and namestrings are all the same size */ arg = acpi_ps_alloc_op (AML_BYTE_OP); if (arg) { acpi_ps_get_next_simple_arg (parser_state, arg_type, arg); } break; case ARGP_PKGLENGTH: /* package length, nothing returned */ parser_state->pkg_end = acpi_ps_get_next_package_end (parser_state); break; case ARGP_FIELDLIST: if (parser_state->aml < parser_state->pkg_end) { /* non-empty list */ while (parser_state->aml < parser_state->pkg_end) { field = acpi_ps_get_next_field (parser_state); if (!field) { break; } if (prev) { prev->next = field; } else { arg = field; } prev = field; } /* skip to End of byte data */ parser_state->aml = parser_state->pkg_end; } break; case ARGP_BYTELIST: if (parser_state->aml < parser_state->pkg_end) { /* non-empty list */ arg = acpi_ps_alloc_op (AML_BYTELIST_OP); if (arg) { /* fill in bytelist data */ arg->value.size = (parser_state->pkg_end - parser_state->aml); ((ACPI_PARSE2_OBJECT *) arg)->data = parser_state->aml; } /* skip to End of byte data */ parser_state->aml = parser_state->pkg_end; } break; case ARGP_TARGET: case ARGP_SUPERNAME: { subop = acpi_ps_peek_opcode (parser_state); if (subop == 0 || acpi_ps_is_leading_char (subop) || acpi_ps_is_prefix_char (subop)) { /* Null_name or Name_string */ arg = acpi_ps_alloc_op (AML_NAMEPATH_OP); if (arg) { acpi_ps_get_next_namepath (parser_state, arg, arg_count, 0); } } else { /* single complex argument, nothing returned */ *arg_count = 1; } } break; case ARGP_DATAOBJ: case ARGP_TERMARG: /* single complex argument, nothing returned */ *arg_count = 1; break; case ARGP_DATAOBJLIST: case ARGP_TERMLIST: case ARGP_OBJLIST: if (parser_state->aml < parser_state->pkg_end) { /* non-empty list of variable arguments, nothing returned */ *arg_count = ACPI_VAR_ARGS; } break; } return (arg); }
ACPI_PARSE_OBJECT * acpi_ps_get_next_field ( ACPI_PARSE_STATE *parser_state) { ACPI_PTRDIFF aml_offset = parser_state->aml - parser_state->aml_start; ACPI_PARSE_OBJECT *field; u16 opcode; u32 name; /* determine field type */ switch (GET8 (parser_state->aml)) { default: opcode = AML_NAMEDFIELD_OP; break; case 0x00: opcode = AML_RESERVEDFIELD_OP; parser_state->aml++; break; case 0x01: opcode = AML_ACCESSFIELD_OP; parser_state->aml++; break; } /* Allocate a new field op */ field = acpi_ps_alloc_op (opcode); if (field) { field->aml_offset = aml_offset; /* Decode the field type */ switch (opcode) { case AML_NAMEDFIELD_OP: /* Get the 4-character name */ MOVE_UNALIGNED32_TO_32 (&name, parser_state->aml); acpi_ps_set_name (field, name); parser_state->aml += 4; /* Get the length which is encoded as a package length */ field->value.size = acpi_ps_get_next_package_length (parser_state); break; case AML_RESERVEDFIELD_OP: /* Get the length which is encoded as a package length */ field->value.size = acpi_ps_get_next_package_length (parser_state); break; case AML_ACCESSFIELD_OP: /* Get Access_type and Access_atrib and merge into the field Op */ field->value.integer = ((GET8 (parser_state->aml) << 8) | GET8 (parser_state->aml)); parser_state->aml += 2; break; } } return (field); }
void acpi_ps_get_next_namepath ( ACPI_PARSE_STATE *parser_state, ACPI_PARSE_OBJECT *arg, u32 *arg_count, u8 method_call) { NATIVE_CHAR *path; ACPI_PARSE_OBJECT *name_op; ACPI_STATUS status; ACPI_NAMESPACE_NODE *method_node = NULL; ACPI_NAMESPACE_NODE *node; ACPI_GENERIC_STATE scope_info; path = acpi_ps_get_next_namestring (parser_state); if (!path || !method_call) { /* Null name case, create a null namepath object */ acpi_ps_init_op (arg, AML_NAMEPATH_OP); arg->value.name = path; return; } if (method_call) { /* * Lookup the name in the internal namespace */ scope_info.scope.node = NULL; node = parser_state->start_node; if (node) { scope_info.scope.node = node; } /* * Lookup object. We don't want to add anything new to the namespace * here, however. So we use MODE_EXECUTE. Allow searching of the * parent tree, but don't open a new scope -- we just want to lookup the * object (MUST BE mode EXECUTE to perform upsearch) */ status = acpi_ns_lookup (&scope_info, path, ACPI_TYPE_ANY, IMODE_EXECUTE, NS_SEARCH_PARENT | NS_DONT_OPEN_SCOPE, NULL, &node); if (ACPI_SUCCESS (status)) { if (node->type == ACPI_TYPE_METHOD) { method_node = node; name_op = acpi_ps_alloc_op (AML_NAMEPATH_OP); if (name_op) { /* Change arg into a METHOD CALL and attach name to it */ acpi_ps_init_op (arg, AML_METHODCALL_OP); name_op->value.name = path; /* Point METHODCALL/NAME to the METHOD Node */ name_op->node = method_node; acpi_ps_append_arg (arg, name_op); if (!(ACPI_OPERAND_OBJECT *) method_node->object) { return; } *arg_count = ((ACPI_OPERAND_OBJECT *) method_node->object)->method.param_count; } return; } /* * Else this is normal named object reference. * Just init the NAMEPATH object with the pathname. * (See code below) */ } } /* * Either we didn't find the object in the namespace, or the object is * something other than a control method. Just initialize the Op with the * pathname. */ acpi_ps_init_op (arg, AML_NAMEPATH_OP); arg->value.name = path; return; }
acpi_status acpi_ds_load2_begin_op ( acpi_walk_state *walk_state, acpi_parse_object **out_op) { acpi_parse_object *op; acpi_namespace_node *node; acpi_status status; acpi_object_type8 data_type; NATIVE_CHAR *buffer_ptr; void *original = NULL; PROC_NAME ("Ds_load2_begin_op"); op = walk_state->op; ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state)); if (op) { /* We only care about Namespace opcodes here */ if (!(walk_state->op_info->flags & AML_NSOPCODE) && walk_state->opcode != AML_INT_NAMEPATH_OP) { return (AE_OK); } /* TBD: [Restructure] Temp! same code as in psparse */ if (!(walk_state->op_info->flags & AML_NAMED)) { return (AE_OK); } /* * Get the name we are going to enter or lookup in the namespace */ if (walk_state->opcode == AML_INT_NAMEPATH_OP) { /* For Namepath op, get the path string */ buffer_ptr = op->value.string; if (!buffer_ptr) { /* No name, just exit */ return (AE_OK); } } else { /* Get name from the op */ buffer_ptr = (NATIVE_CHAR *) &((acpi_parse2_object *)op)->name; } } else { buffer_ptr = acpi_ps_get_next_namestring (&walk_state->parser_state); } /* Map the raw opcode into an internal object type */ data_type = acpi_ds_map_named_opcode_to_data_type (walk_state->opcode); ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "State=%p Op=%p Type=%x\n", walk_state, op, data_type)); if (walk_state->opcode == AML_FIELD_OP || walk_state->opcode == AML_BANK_FIELD_OP || walk_state->opcode == AML_INDEX_FIELD_OP) { node = NULL; status = AE_OK; } else if (walk_state->opcode == AML_INT_NAMEPATH_OP) { /* * The Name_path is an object reference to an existing object. Don't enter the * name into the namespace, but look it up for use later */ status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, data_type, IMODE_EXECUTE, NS_SEARCH_PARENT, walk_state, &(node)); } else { if (op && op->node) { original = op->node; node = op->node; if (acpi_ns_opens_scope (data_type)) { status = acpi_ds_scope_stack_push (node, data_type, walk_state); if (ACPI_FAILURE (status)) { return (status); } } return (AE_OK); } /* * Enter the named type into the internal namespace. We enter the name * as we go downward in the parse tree. Any necessary subobjects that involve * arguments to the opcode must be created as we go back up the parse tree later. */ status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, data_type, IMODE_EXECUTE, NS_NO_UPSEARCH, walk_state, &(node)); } if (ACPI_SUCCESS (status)) { if (!op) { /* Create a new op */ op = acpi_ps_alloc_op (walk_state->opcode); if (!op) { return (AE_NO_MEMORY); } /* Initialize */ ((acpi_parse2_object *)op)->name = node->name; *out_op = op; } /* * Put the Node in the "op" object that the parser uses, so we * can get it again quickly when this scope is closed */ op->node = node; if (original) { ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "old %p new %p\n", original, node)); if (original != node) { ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Lookup match error: old %p new %p\n", original, node)); } } } return (status); }
acpi_status acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state, struct acpi_parse_state *parser_state, union acpi_parse_object *arg, u8 method_call) { char *path; union acpi_parse_object *name_op; acpi_status status = AE_OK; union acpi_operand_object *method_desc; struct acpi_namespace_node *node; union acpi_generic_state scope_info; ACPI_FUNCTION_TRACE("ps_get_next_namepath"); path = acpi_ps_get_next_namestring(parser_state); /* Null path case is allowed */ if (path) { /* * Lookup the name in the internal namespace */ scope_info.scope.node = NULL; node = parser_state->start_node; if (node) { scope_info.scope.node = node; } /* * Lookup object. We don't want to add anything new to the namespace * here, however. So we use MODE_EXECUTE. Allow searching of the * parent tree, but don't open a new scope -- we just want to lookup the * object (MUST BE mode EXECUTE to perform upsearch) */ status = acpi_ns_lookup(&scope_info, path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &node); if (ACPI_SUCCESS(status) && method_call) { if (node->type == ACPI_TYPE_METHOD) { /* This name is actually a control method invocation */ method_desc = acpi_ns_get_attached_object(node); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Control Method - %p Desc %p Path=%p\n", node, method_desc, path)); name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP); if (!name_op) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Change arg into a METHOD CALL and attach name to it */ acpi_ps_init_op(arg, AML_INT_METHODCALL_OP); name_op->common.value.name = path; /* Point METHODCALL/NAME to the METHOD Node */ name_op->common.node = node; acpi_ps_append_arg(arg, name_op); if (!method_desc) { ACPI_REPORT_ERROR(("ps_get_next_namepath: Control Method %p has no attached object\n", node)); return_ACPI_STATUS(AE_AML_INTERNAL); } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Control Method - %p Args %X\n", node, method_desc->method. param_count)); /* Get the number of arguments to expect */ walk_state->arg_count = method_desc->method.param_count; return_ACPI_STATUS(AE_OK); } /* * Else this is normal named object reference. * Just init the NAMEPATH object with the pathname. * (See code below) */ } if (ACPI_FAILURE(status)) { /* * 1) Any error other than NOT_FOUND is always severe * 2) NOT_FOUND is only important if we are executing a method. * 3) If executing a cond_ref_of opcode, NOT_FOUND is ok. */ if ((((walk_state-> parse_flags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) && (status == AE_NOT_FOUND) && (walk_state->op->common.aml_opcode != AML_COND_REF_OF_OP)) || (status != AE_NOT_FOUND)) { ACPI_REPORT_NSERROR(path, status); acpi_os_printf ("search_node %p start_node %p return_node %p\n", scope_info.scope.node, parser_state->start_node, node); } else { /* * We got a NOT_FOUND during table load or we encountered * a cond_ref_of(x) where the target does not exist. * Either case is ok */ status = AE_OK; } } } /* * Regardless of success/failure above, * Just initialize the Op with the pathname. */ acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP); arg->common.value.name = path; return_ACPI_STATUS(status); }
acpi_status acpi_ps_create_op(struct acpi_walk_state *walk_state, u8 *aml_op_start, union acpi_parse_object **new_op) { acpi_status status = AE_OK; union acpi_parse_object *op; union acpi_parse_object *named_op = NULL; union acpi_parse_object *parent_scope; u8 argument_count; const struct acpi_opcode_info *op_info; ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state); status = acpi_ps_get_aml_opcode(walk_state); if (status == AE_CTRL_PARSE_CONTINUE) { return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); } if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Create Op structure and append to parent's argument list */ walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode); op = acpi_ps_alloc_op(walk_state->opcode, aml_op_start); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } if (walk_state->op_info->flags & AML_NAMED) { status = acpi_ps_build_named_op(walk_state, aml_op_start, op, &named_op); acpi_ps_free_op(op); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } *new_op = named_op; return_ACPI_STATUS(AE_OK); } /* Not a named opcode, just allocate Op and append to parent */ if (walk_state->op_info->flags & AML_CREATE) { /* * Backup to beginning of create_XXXfield declaration * body_length is unknown until we parse the body */ op->named.data = aml_op_start; op->named.length = 0; } if (walk_state->opcode == AML_BANK_FIELD_OP) { /* * Backup to beginning of bank_field declaration * body_length is unknown until we parse the body */ op->named.data = aml_op_start; op->named.length = 0; } parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state)); acpi_ps_append_arg(parent_scope, op); if (parent_scope) { op_info = acpi_ps_get_opcode_info(parent_scope->common.aml_opcode); if (op_info->flags & AML_HAS_TARGET) { argument_count = acpi_ps_get_argument_count(op_info->type); if (parent_scope->common.arg_list_length > argument_count) { op->common.flags |= ACPI_PARSEOP_TARGET; } } /* * Special case for both Increment() and Decrement(), where * the lone argument is both a source and a target. */ else if ((parent_scope->common.aml_opcode == AML_INCREMENT_OP) || (parent_scope->common.aml_opcode == AML_DECREMENT_OP)) { op->common.flags |= ACPI_PARSEOP_TARGET; } } if (walk_state->descending_callback != NULL) { /* * Find the object. This will either insert the object into * the namespace or simply look it up */ walk_state->op = *new_op = op; status = walk_state->descending_callback(walk_state, &op); status = acpi_ps_next_parse_state(walk_state, op, status); if (status == AE_CTRL_PENDING) { status = AE_CTRL_PARSE_PENDING; } } return_ACPI_STATUS(status); }
static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state *parser_state) { u32 aml_offset = (u32) ACPI_PTR_DIFF(parser_state->aml, parser_state->aml_start); union acpi_parse_object *field; u16 opcode; u32 name; ACPI_FUNCTION_TRACE("ps_get_next_field"); /* Determine field type */ switch (ACPI_GET8(parser_state->aml)) { default: opcode = AML_INT_NAMEDFIELD_OP; break; case 0x00: opcode = AML_INT_RESERVEDFIELD_OP; parser_state->aml++; break; case 0x01: opcode = AML_INT_ACCESSFIELD_OP; parser_state->aml++; break; } /* Allocate a new field op */ field = acpi_ps_alloc_op(opcode); if (!field) { return_PTR(NULL); } field->common.aml_offset = aml_offset; /* Decode the field type */ switch (opcode) { case AML_INT_NAMEDFIELD_OP: /* Get the 4-character name */ ACPI_MOVE_32_TO_32(&name, parser_state->aml); acpi_ps_set_name(field, name); parser_state->aml += ACPI_NAME_SIZE; /* Get the length which is encoded as a package length */ field->common.value.size = acpi_ps_get_next_package_length(parser_state); break; case AML_INT_RESERVEDFIELD_OP: /* Get the length which is encoded as a package length */ field->common.value.size = acpi_ps_get_next_package_length(parser_state); break; case AML_INT_ACCESSFIELD_OP: /* * Get access_type and access_attrib and merge into the field Op * access_type is first operand, access_attribute is second */ field->common.value.integer = (ACPI_GET8(parser_state->aml) << 8); parser_state->aml++; field->common.value.integer |= ACPI_GET8(parser_state->aml); parser_state->aml++; break; default: /* Opcode was set in previous switch */ break; } return_PTR(field); }
acpi_status acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state, union acpi_parse_object ** out_op) { union acpi_parse_object *op; struct acpi_namespace_node *node; acpi_status status; acpi_object_type object_type; char *path; u32 flags; ACPI_FUNCTION_TRACE(ds_load1_begin_op); op = walk_state->op; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state)); /* We are only interested in opcodes that have an associated name */ if (op) { if (!(walk_state->op_info->flags & AML_NAMED)) { *out_op = op; return_ACPI_STATUS(AE_OK); } /* Check if this object has already been installed in the namespace */ if (op->common.node) { *out_op = op; return_ACPI_STATUS(AE_OK); } } path = acpi_ps_get_next_namestring(&walk_state->parser_state); /* Map the raw opcode into an internal object type */ object_type = walk_state->op_info->object_type; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "State=%p Op=%p [%s]\n", walk_state, op, acpi_ut_get_type_name(object_type))); switch (walk_state->opcode) { case AML_SCOPE_OP: /* * The target name of the Scope() operator must exist at this point so * that we can actually open the scope to enter new names underneath it. * Allow search-to-root for single namesegs. */ status = acpi_ns_lookup(walk_state->scope_info, path, object_type, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); #ifdef ACPI_ASL_COMPILER if (status == AE_NOT_FOUND) { /* * Table disassembly: * Target of Scope() not found. Generate an External for it, and * insert the name into the namespace. */ acpi_dm_add_to_external_list(path, ACPI_TYPE_DEVICE, 0); status = acpi_ns_lookup(walk_state->scope_info, path, object_type, ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, walk_state, &node); } #endif if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(path, status); return_ACPI_STATUS(status); } /* * Check to make sure that the target is * one of the opcodes that actually opens a scope */ switch (node->type) { case ACPI_TYPE_ANY: case ACPI_TYPE_LOCAL_SCOPE: /* Scope */ case ACPI_TYPE_DEVICE: case ACPI_TYPE_POWER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: /* These are acceptable types */ break; case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* * These types we will allow, but we will change the type. This * enables some existing code of the form: * * Name (DEB, 0) * Scope (DEB) { ... } * * Note: silently change the type here. On the second pass, we will report * a warning */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", path, acpi_ut_get_type_name(node->type))); node->type = ACPI_TYPE_ANY; walk_state->scope_info->common.value = ACPI_TYPE_ANY; break; default: /* All other types are an error */ ACPI_ERROR((AE_INFO, "Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)", acpi_ut_get_type_name(node->type), path)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } break; default: /* * For all other named opcodes, we will enter the name into * the namespace. * * Setup the search flags. * Since we are entering a name into the namespace, we do not want to * enable the search-to-root upsearch. * * There are only two conditions where it is acceptable that the name * already exists: * 1) the Scope() operator can reopen a scoping object that was * previously defined (Scope, Method, Device, etc.) * 2) Whenever we are parsing a deferred opcode (op_region, Buffer, * buffer_field, or Package), the name of the object is already * in the namespace. */ if (walk_state->deferred_node) { /* This name is already in the namespace, get the node */ node = walk_state->deferred_node; status = AE_OK; break; } /* * If we are executing a method, do not create any namespace objects * during the load phase, only during execution. */ if (walk_state->method_node) { node = NULL; status = AE_OK; break; } flags = ACPI_NS_NO_UPSEARCH; if ((walk_state->opcode != AML_SCOPE_OP) && (!(walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP))) { flags |= ACPI_NS_ERROR_IF_FOUND; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n", acpi_ut_get_type_name(object_type))); } else { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[%s] Both Find or Create allowed\n", acpi_ut_get_type_name(object_type))); } /* * Enter the named type into the internal namespace. We enter the name * as we go downward in the parse tree. Any necessary subobjects that * involve arguments to the opcode must be created as we go back up the * parse tree later. */ status = acpi_ns_lookup(walk_state->scope_info, path, object_type, ACPI_IMODE_LOAD_PASS1, flags, walk_state, &node); if (ACPI_FAILURE(status)) { if (status == AE_ALREADY_EXISTS) { /* The name already exists in this scope */ if (node->flags & ANOBJ_IS_EXTERNAL) { /* * Allow one create on an object or segment that was * previously declared External */ node->flags &= ~ANOBJ_IS_EXTERNAL; node->type = (u8) object_type; /* Just retyped a node, probably will need to open a scope */ if (acpi_ns_opens_scope(object_type)) { status = acpi_ds_scope_stack_push (node, object_type, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS (status); } } status = AE_OK; } } if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(path, status); return_ACPI_STATUS(status); } } break; } /* Common exit */ if (!op) { /* Create a new op */ op = acpi_ps_alloc_op(walk_state->opcode); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } } /* Initialize the op */ #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)) op->named.path = ACPI_CAST_PTR(u8, path); #endif if (node) { /* * Put the Node in the "op" object that the parser uses, so we * can get it again quickly when this scope is closed */ op->common.node = node; op->named.name = node->name.integer; } acpi_ps_append_arg(acpi_ps_get_parent_scope(&walk_state->parser_state), op); *out_op = op; return_ACPI_STATUS(status); }
acpi_status acpi_ps_create_op(struct acpi_walk_state *walk_state, u8 *aml_op_start, union acpi_parse_object **new_op) { acpi_status status = AE_OK; union acpi_parse_object *op; union acpi_parse_object *named_op = NULL; union acpi_parse_object *parent_scope; u8 argument_count; const struct acpi_opcode_info *op_info; ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state); status = acpi_ps_get_aml_opcode(walk_state); if (status == AE_CTRL_PARSE_CONTINUE) { return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); } if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Create Op structure and append to parent's argument list */ walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode); op = acpi_ps_alloc_op(walk_state->opcode, aml_op_start); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } if (walk_state->op_info->flags & AML_NAMED) { status = acpi_ps_build_named_op(walk_state, aml_op_start, op, &named_op); acpi_ps_free_op(op); #ifdef ACPI_ASL_COMPILER if (acpi_gbl_disasm_flag && walk_state->opcode == AML_EXTERNAL_OP && status == AE_NOT_FOUND) { /* * If parsing of AML_EXTERNAL_OP's name path fails, then skip * past this opcode and keep parsing. This is a much better * alternative than to abort the entire disassembler. At this * point, the parser_state is at the end of the namepath of the * external declaration opcode. Setting walk_state->Aml to * walk_state->parser_state.Aml + 2 moves increments the * walk_state->Aml past the object type and the paramcount of the * external opcode. */ walk_state->aml = walk_state->parser_state.aml + 2; walk_state->parser_state.aml = walk_state->aml; return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); } #endif if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } *new_op = named_op; return_ACPI_STATUS(AE_OK); } /* Not a named opcode, just allocate Op and append to parent */ if (walk_state->op_info->flags & AML_CREATE) { /* * Backup to beginning of create_XXXfield declaration * body_length is unknown until we parse the body */ op->named.data = aml_op_start; op->named.length = 0; } if (walk_state->opcode == AML_BANK_FIELD_OP) { /* * Backup to beginning of bank_field declaration * body_length is unknown until we parse the body */ op->named.data = aml_op_start; op->named.length = 0; } parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state)); acpi_ps_append_arg(parent_scope, op); if (parent_scope) { op_info = acpi_ps_get_opcode_info(parent_scope->common.aml_opcode); if (op_info->flags & AML_HAS_TARGET) { argument_count = acpi_ps_get_argument_count(op_info->type); if (parent_scope->common.arg_list_length > argument_count) { op->common.flags |= ACPI_PARSEOP_TARGET; } } /* * Special case for both Increment() and Decrement(), where * the lone argument is both a source and a target. */ else if ((parent_scope->common.aml_opcode == AML_INCREMENT_OP) || (parent_scope->common.aml_opcode == AML_DECREMENT_OP)) { op->common.flags |= ACPI_PARSEOP_TARGET; } } if (walk_state->descending_callback != NULL) { /* * Find the object. This will either insert the object into * the namespace or simply look it up */ walk_state->op = *new_op = op; status = walk_state->descending_callback(walk_state, &op); status = acpi_ps_next_parse_state(walk_state, op, status); if (status == AE_CTRL_PENDING) { status = AE_CTRL_PARSE_PENDING; } } return_ACPI_STATUS(status); }