📄 dswstate.c
字号:
/****************************************************************************** * * Module Name: dswstate - Dispatcher parse tree walk management routines * *****************************************************************************//* * Copyright (C) 2000 - 2005, R. Byron Moore * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */#include <acpi/acpi.h>#include <acpi/acparser.h>#include <acpi/acdispat.h>#include <acpi/acnamesp.h>#define _COMPONENT ACPI_DISPATCHERACPI_MODULE_NAME("dswstate")/* Local prototypes */#ifdef ACPI_OBSOLETE_FUNCTIONSacpi_statusacpi_ds_result_insert(void *object, u32 index, struct acpi_walk_state *walk_state);acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state *walk_state);acpi_statusacpi_ds_obj_stack_pop_object(union acpi_operand_object **object, struct acpi_walk_state *walk_state);void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state);#endif#ifdef ACPI_FUTURE_USAGE/******************************************************************************* * * FUNCTION: acpi_ds_result_remove * * PARAMETERS: Object - Where to return the popped object * Index - Where to extract the object * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In * other words, this is a FIFO. * ******************************************************************************/acpi_statusacpi_ds_result_remove(union acpi_operand_object **object, u32 index, struct acpi_walk_state *walk_state){ union acpi_generic_state *state; ACPI_FUNCTION_NAME("ds_result_remove"); state = walk_state->results; if (!state) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No result object pushed! State=%p\n", walk_state)); return (AE_NOT_EXIST); } if (index >= ACPI_OBJ_MAX_OPERAND) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Index out of range: %X State=%p Num=%X\n", index, walk_state, state->results.num_results)); } /* Check for a valid result object */ if (!state->results.obj_desc[index]) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Null operand! State=%p #Ops=%X, Index=%X\n", walk_state, state->results.num_results, index)); return (AE_AML_NO_RETURN_VALUE); } /* Remove the object */ state->results.num_results--; *object = state->results.obj_desc[index]; state->results.obj_desc[index] = NULL; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object, (*object) ? acpi_ut_get_object_type_name(*object) : "NULL", index, walk_state, state->results.num_results)); return (AE_OK);}#endif /* ACPI_FUTURE_USAGE *//******************************************************************************* * * FUNCTION: acpi_ds_result_pop * * PARAMETERS: Object - Where to return the popped object * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In * other words, this is a FIFO. * ******************************************************************************/acpi_statusacpi_ds_result_pop(union acpi_operand_object ** object, struct acpi_walk_state * walk_state){ acpi_native_uint index; union acpi_generic_state *state; ACPI_FUNCTION_NAME("ds_result_pop"); state = walk_state->results; if (!state) { return (AE_OK); } if (!state->results.num_results) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Result stack is empty! State=%p\n", walk_state)); return (AE_AML_NO_RETURN_VALUE); } /* Remove top element */ state->results.num_results--; for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) { /* Check for a valid result object */ if (state->results.obj_desc[index - 1]) { *object = state->results.obj_desc[index - 1]; state->results.obj_desc[index - 1] = NULL; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object, (*object) ? acpi_ut_get_object_type_name(*object) : "NULL", (u32) index - 1, walk_state, state->results.num_results)); return (AE_OK); } } ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No result objects! State=%p\n", walk_state)); return (AE_AML_NO_RETURN_VALUE);}/******************************************************************************* * * FUNCTION: acpi_ds_result_pop_from_bottom * * PARAMETERS: Object - Where to return the popped object * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In * other words, this is a FIFO. * ******************************************************************************/acpi_statusacpi_ds_result_pop_from_bottom(union acpi_operand_object ** object, struct acpi_walk_state * walk_state){ acpi_native_uint index; union acpi_generic_state *state; ACPI_FUNCTION_NAME("ds_result_pop_from_bottom"); state = walk_state->results; if (!state) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Warning: No result object pushed! State=%p\n", walk_state)); return (AE_NOT_EXIST); } if (!state->results.num_results) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No result objects! State=%p\n", walk_state)); return (AE_AML_NO_RETURN_VALUE); } /* Remove Bottom element */ *object = state->results.obj_desc[0]; /* Push entire stack down one element */ for (index = 0; index < state->results.num_results; index++) { state->results.obj_desc[index] = state->results.obj_desc[index + 1]; } state->results.num_results--; /* Check for a valid result object */ if (!*object) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Null operand! State=%p #Ops=%X Index=%X\n", walk_state, state->results.num_results, (u32) index)); return (AE_AML_NO_RETURN_VALUE); } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n", *object, (*object) ? acpi_ut_get_object_type_name(*object) : "NULL", state, walk_state)); return (AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ds_result_push * * PARAMETERS: Object - Where to return the popped object * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Push an object onto the current result stack * ******************************************************************************/acpi_statusacpi_ds_result_push(union acpi_operand_object * object, struct acpi_walk_state * walk_state){ union acpi_generic_state *state; ACPI_FUNCTION_NAME("ds_result_push"); state = walk_state->results; if (!state) { ACPI_REPORT_ERROR(("No result stack frame during push\n")); return (AE_AML_INTERNAL); } if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Result stack overflow: Obj=%p State=%p Num=%X\n", object, walk_state, state->results.num_results)); return (AE_STACK_OVERFLOW); } if (!object) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Null Object! Obj=%p State=%p Num=%X\n", object, walk_state, state->results.num_results)); return (AE_BAD_PARAMETER); } state->results.obj_desc[state->results.num_results] = object; state->results.num_results++; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n", object, object ? acpi_ut_get_object_type_name((union acpi_operand_object *) object) : "NULL", walk_state, state->results.num_results, walk_state->current_result)); return (AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ds_result_stack_push * * PARAMETERS: walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Push an object onto the walk_state result stack. * ******************************************************************************/acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state){ union acpi_generic_state *state; ACPI_FUNCTION_NAME("ds_result_stack_push"); state = acpi_ut_create_generic_state(); if (!state) { return (AE_NO_MEMORY); } state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT; acpi_ut_push_generic_state(&walk_state->results, state); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n", state, walk_state)); return (AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ds_result_stack_pop * * PARAMETERS: walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop an object off of the walk_state result stack. * ******************************************************************************/acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state){ union acpi_generic_state *state; ACPI_FUNCTION_NAME("ds_result_stack_pop"); /* Check for stack underflow */ if (walk_state->results == NULL) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n", walk_state)); return (AE_AML_NO_OPERAND); } state = acpi_ut_pop_generic_state(&walk_state->results); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Result=%p remaining_results=%X State=%p\n", state, state->results.num_results, walk_state)); acpi_ut_delete_generic_state(state); return (AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ds_obj_stack_push * * PARAMETERS: Object - Object to push * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Push an object onto this walk's object/operand stack * ******************************************************************************/acpi_statusacpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state){ ACPI_FUNCTION_NAME("ds_obj_stack_push"); /* Check for stack overflow */ if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "overflow! Obj=%p State=%p #Ops=%X\n", object, walk_state, walk_state->num_operands)); return (AE_STACK_OVERFLOW); } /* Put the object onto the stack */ walk_state->operands[walk_state->num_operands] = object; walk_state->num_operands++; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n", object, acpi_ut_get_object_type_name((union acpi_operand_object *) object), walk_state, walk_state->num_operands)); return (AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ds_obj_stack_pop * * PARAMETERS: pop_count - Number of objects/entries to pop * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT * deleted by this routine. * ******************************************************************************/acpi_statusacpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state){ u32 i; ACPI_FUNCTION_NAME("ds_obj_stack_pop"); for (i = 0; i < pop_count; i++) { /* Check for stack underflow */ if (walk_state->num_operands == 0) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Underflow! Count=%X State=%p #Ops=%X\n", pop_count, walk_state, walk_state->num_operands)); return (AE_STACK_UNDERFLOW); } /* Just set the stack entry to null */ walk_state->num_operands--; walk_state->operands[walk_state->num_operands] = NULL; } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n", pop_count, walk_state, walk_state->num_operands)); return (AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ds_obj_stack_pop_and_delete * * PARAMETERS: pop_count - Number of objects/entries to pop * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop this walk's object stack and delete each object that is * popped off. * ******************************************************************************/acpi_statusacpi_ds_obj_stack_pop_and_delete(u32 pop_count, struct acpi_walk_state * walk_state){ u32 i; union acpi_operand_object *obj_desc; ACPI_FUNCTION_NAME("ds_obj_stack_pop_and_delete"); for (i = 0; i < pop_count; i++) { /* Check for stack underflow */ if (walk_state->num_operands == 0) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Underflow! Count=%X State=%p #Ops=%X\n", pop_count, walk_state, walk_state->num_operands)); return (AE_STACK_UNDERFLOW); } /* Pop the stack and delete an object if present in this stack entry */ walk_state->num_operands--; obj_desc = walk_state->operands[walk_state->num_operands]; if (obj_desc) { acpi_ut_remove_reference(walk_state-> operands[walk_state-> num_operands]); walk_state->operands[walk_state->num_operands] = NULL; } } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n", pop_count, walk_state, walk_state->num_operands));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -