195b482a8SLen Brown /******************************************************************************* 295b482a8SLen Brown * 395b482a8SLen Brown * Module Name: nsxfeval - Public interfaces to the ACPI subsystem 495b482a8SLen Brown * ACPI Object evaluation interfaces 595b482a8SLen Brown * 695b482a8SLen Brown ******************************************************************************/ 795b482a8SLen Brown 895b482a8SLen Brown /* 995b482a8SLen Brown * Copyright (C) 2000 - 2008, Intel Corp. 1095b482a8SLen Brown * All rights reserved. 1195b482a8SLen Brown * 1295b482a8SLen Brown * Redistribution and use in source and binary forms, with or without 1395b482a8SLen Brown * modification, are permitted provided that the following conditions 1495b482a8SLen Brown * are met: 1595b482a8SLen Brown * 1. Redistributions of source code must retain the above copyright 1695b482a8SLen Brown * notice, this list of conditions, and the following disclaimer, 1795b482a8SLen Brown * without modification. 1895b482a8SLen Brown * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1995b482a8SLen Brown * substantially similar to the "NO WARRANTY" disclaimer below 2095b482a8SLen Brown * ("Disclaimer") and any redistribution must be conditioned upon 2195b482a8SLen Brown * including a substantially similar Disclaimer requirement for further 2295b482a8SLen Brown * binary redistribution. 2395b482a8SLen Brown * 3. Neither the names of the above-listed copyright holders nor the names 2495b482a8SLen Brown * of any contributors may be used to endorse or promote products derived 2595b482a8SLen Brown * from this software without specific prior written permission. 2695b482a8SLen Brown * 2795b482a8SLen Brown * Alternatively, this software may be distributed under the terms of the 2895b482a8SLen Brown * GNU General Public License ("GPL") version 2 as published by the Free 2995b482a8SLen Brown * Software Foundation. 3095b482a8SLen Brown * 3195b482a8SLen Brown * NO WARRANTY 3295b482a8SLen Brown * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3395b482a8SLen Brown * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3495b482a8SLen Brown * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3595b482a8SLen Brown * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3695b482a8SLen Brown * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3795b482a8SLen Brown * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3895b482a8SLen Brown * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3995b482a8SLen Brown * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4095b482a8SLen Brown * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4195b482a8SLen Brown * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4295b482a8SLen Brown * POSSIBILITY OF SUCH DAMAGES. 4395b482a8SLen Brown */ 4495b482a8SLen Brown 4595b482a8SLen Brown #include <acpi/acpi.h> 46e2f7a777SLen Brown #include "accommon.h" 47e2f7a777SLen Brown #include "acnamesp.h" 48e2f7a777SLen Brown #include "acinterp.h" 4995b482a8SLen Brown 5095b482a8SLen Brown #define _COMPONENT ACPI_NAMESPACE 5195b482a8SLen Brown ACPI_MODULE_NAME("nsxfeval") 5295b482a8SLen Brown 5395b482a8SLen Brown /* Local prototypes */ 5495b482a8SLen Brown static void acpi_ns_resolve_references(struct acpi_evaluate_info *info); 5595b482a8SLen Brown 5695b482a8SLen Brown #ifdef ACPI_FUTURE_USAGE 5795b482a8SLen Brown /******************************************************************************* 5895b482a8SLen Brown * 5995b482a8SLen Brown * FUNCTION: acpi_evaluate_object_typed 6095b482a8SLen Brown * 6195b482a8SLen Brown * PARAMETERS: Handle - Object handle (optional) 6295b482a8SLen Brown * Pathname - Object pathname (optional) 6395b482a8SLen Brown * external_params - List of parameters to pass to method, 6495b482a8SLen Brown * terminated by NULL. May be NULL 6595b482a8SLen Brown * if no parameters are being passed. 6695b482a8SLen Brown * return_buffer - Where to put method's return value (if 6795b482a8SLen Brown * any). If NULL, no value is returned. 6895b482a8SLen Brown * return_type - Expected type of return object 6995b482a8SLen Brown * 7095b482a8SLen Brown * RETURN: Status 7195b482a8SLen Brown * 7295b482a8SLen Brown * DESCRIPTION: Find and evaluate the given object, passing the given 7395b482a8SLen Brown * parameters if necessary. One of "Handle" or "Pathname" must 7495b482a8SLen Brown * be valid (non-null) 7595b482a8SLen Brown * 7695b482a8SLen Brown ******************************************************************************/ 7795b482a8SLen Brown 7895b482a8SLen Brown acpi_status 7995b482a8SLen Brown acpi_evaluate_object_typed(acpi_handle handle, 8095b482a8SLen Brown acpi_string pathname, 8195b482a8SLen Brown struct acpi_object_list *external_params, 8295b482a8SLen Brown struct acpi_buffer *return_buffer, 8395b482a8SLen Brown acpi_object_type return_type) 8495b482a8SLen Brown { 8595b482a8SLen Brown acpi_status status; 8695b482a8SLen Brown u8 must_free = FALSE; 8795b482a8SLen Brown 8895b482a8SLen Brown ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed); 8995b482a8SLen Brown 9095b482a8SLen Brown /* Return buffer must be valid */ 9195b482a8SLen Brown 9295b482a8SLen Brown if (!return_buffer) { 9395b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 9495b482a8SLen Brown } 9595b482a8SLen Brown 9695b482a8SLen Brown if (return_buffer->length == ACPI_ALLOCATE_BUFFER) { 9795b482a8SLen Brown must_free = TRUE; 9895b482a8SLen Brown } 9995b482a8SLen Brown 10095b482a8SLen Brown /* Evaluate the object */ 10195b482a8SLen Brown 10295b482a8SLen Brown status = 10395b482a8SLen Brown acpi_evaluate_object(handle, pathname, external_params, 10495b482a8SLen Brown return_buffer); 10595b482a8SLen Brown if (ACPI_FAILURE(status)) { 10695b482a8SLen Brown return_ACPI_STATUS(status); 10795b482a8SLen Brown } 10895b482a8SLen Brown 10995b482a8SLen Brown /* Type ANY means "don't care" */ 11095b482a8SLen Brown 11195b482a8SLen Brown if (return_type == ACPI_TYPE_ANY) { 11295b482a8SLen Brown return_ACPI_STATUS(AE_OK); 11395b482a8SLen Brown } 11495b482a8SLen Brown 11595b482a8SLen Brown if (return_buffer->length == 0) { 11695b482a8SLen Brown 11795b482a8SLen Brown /* Error because caller specifically asked for a return value */ 11895b482a8SLen Brown 11995b482a8SLen Brown ACPI_ERROR((AE_INFO, "No return value")); 12095b482a8SLen Brown return_ACPI_STATUS(AE_NULL_OBJECT); 12195b482a8SLen Brown } 12295b482a8SLen Brown 12395b482a8SLen Brown /* Examine the object type returned from evaluate_object */ 12495b482a8SLen Brown 12595b482a8SLen Brown if (((union acpi_object *)return_buffer->pointer)->type == return_type) { 12695b482a8SLen Brown return_ACPI_STATUS(AE_OK); 12795b482a8SLen Brown } 12895b482a8SLen Brown 12995b482a8SLen Brown /* Return object type does not match requested type */ 13095b482a8SLen Brown 13195b482a8SLen Brown ACPI_ERROR((AE_INFO, 13295b482a8SLen Brown "Incorrect return type [%s] requested [%s]", 13395b482a8SLen Brown acpi_ut_get_type_name(((union acpi_object *)return_buffer-> 13495b482a8SLen Brown pointer)->type), 13595b482a8SLen Brown acpi_ut_get_type_name(return_type))); 13695b482a8SLen Brown 13795b482a8SLen Brown if (must_free) { 13895b482a8SLen Brown 13995b482a8SLen Brown /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ 14095b482a8SLen Brown 14195b482a8SLen Brown ACPI_FREE(return_buffer->pointer); 14295b482a8SLen Brown return_buffer->pointer = NULL; 14395b482a8SLen Brown } 14495b482a8SLen Brown 14595b482a8SLen Brown return_buffer->length = 0; 14695b482a8SLen Brown return_ACPI_STATUS(AE_TYPE); 14795b482a8SLen Brown } 14895b482a8SLen Brown 14995b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed) 15095b482a8SLen Brown #endif /* ACPI_FUTURE_USAGE */ 15195b482a8SLen Brown /******************************************************************************* 15295b482a8SLen Brown * 15395b482a8SLen Brown * FUNCTION: acpi_evaluate_object 15495b482a8SLen Brown * 15595b482a8SLen Brown * PARAMETERS: Handle - Object handle (optional) 15695b482a8SLen Brown * Pathname - Object pathname (optional) 15795b482a8SLen Brown * external_params - List of parameters to pass to method, 15895b482a8SLen Brown * terminated by NULL. May be NULL 15995b482a8SLen Brown * if no parameters are being passed. 16095b482a8SLen Brown * return_buffer - Where to put method's return value (if 16195b482a8SLen Brown * any). If NULL, no value is returned. 16295b482a8SLen Brown * 16395b482a8SLen Brown * RETURN: Status 16495b482a8SLen Brown * 16595b482a8SLen Brown * DESCRIPTION: Find and evaluate the given object, passing the given 16695b482a8SLen Brown * parameters if necessary. One of "Handle" or "Pathname" must 16795b482a8SLen Brown * be valid (non-null) 16895b482a8SLen Brown * 16995b482a8SLen Brown ******************************************************************************/ 17095b482a8SLen Brown acpi_status 17195b482a8SLen Brown acpi_evaluate_object(acpi_handle handle, 17295b482a8SLen Brown acpi_string pathname, 17395b482a8SLen Brown struct acpi_object_list *external_params, 17495b482a8SLen Brown struct acpi_buffer *return_buffer) 17595b482a8SLen Brown { 17695b482a8SLen Brown acpi_status status; 17795b482a8SLen Brown struct acpi_evaluate_info *info; 17895b482a8SLen Brown acpi_size buffer_space_needed; 17995b482a8SLen Brown u32 i; 18095b482a8SLen Brown 18195b482a8SLen Brown ACPI_FUNCTION_TRACE(acpi_evaluate_object); 18295b482a8SLen Brown 18395b482a8SLen Brown /* Allocate and initialize the evaluation information block */ 18495b482a8SLen Brown 18595b482a8SLen Brown info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); 18695b482a8SLen Brown if (!info) { 18795b482a8SLen Brown return_ACPI_STATUS(AE_NO_MEMORY); 18895b482a8SLen Brown } 18995b482a8SLen Brown 19095b482a8SLen Brown info->pathname = pathname; 19195b482a8SLen Brown 19295b482a8SLen Brown /* Convert and validate the device handle */ 19395b482a8SLen Brown 19495b482a8SLen Brown info->prefix_node = acpi_ns_map_handle_to_node(handle); 19595b482a8SLen Brown if (!info->prefix_node) { 19695b482a8SLen Brown status = AE_BAD_PARAMETER; 19795b482a8SLen Brown goto cleanup; 19895b482a8SLen Brown } 19995b482a8SLen Brown 20095b482a8SLen Brown /* 20195b482a8SLen Brown * If there are parameters to be passed to a control method, the external 20295b482a8SLen Brown * objects must all be converted to internal objects 20395b482a8SLen Brown */ 20495b482a8SLen Brown if (external_params && external_params->count) { 20595b482a8SLen Brown /* 20695b482a8SLen Brown * Allocate a new parameter block for the internal objects 20795b482a8SLen Brown * Add 1 to count to allow for null terminated internal list 20895b482a8SLen Brown */ 20995b482a8SLen Brown info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) 21095b482a8SLen Brown external_params-> 21195b482a8SLen Brown count + 21295b482a8SLen Brown 1) * sizeof(void *)); 21395b482a8SLen Brown if (!info->parameters) { 21495b482a8SLen Brown status = AE_NO_MEMORY; 21595b482a8SLen Brown goto cleanup; 21695b482a8SLen Brown } 21795b482a8SLen Brown 21895b482a8SLen Brown /* Convert each external object in the list to an internal object */ 21995b482a8SLen Brown 22095b482a8SLen Brown for (i = 0; i < external_params->count; i++) { 22195b482a8SLen Brown status = 22295b482a8SLen Brown acpi_ut_copy_eobject_to_iobject(&external_params-> 22395b482a8SLen Brown pointer[i], 22495b482a8SLen Brown &info-> 22595b482a8SLen Brown parameters[i]); 22695b482a8SLen Brown if (ACPI_FAILURE(status)) { 22795b482a8SLen Brown goto cleanup; 22895b482a8SLen Brown } 22995b482a8SLen Brown } 23095b482a8SLen Brown info->parameters[external_params->count] = NULL; 23195b482a8SLen Brown } 23295b482a8SLen Brown 23395b482a8SLen Brown /* 23495b482a8SLen Brown * Three major cases: 23595b482a8SLen Brown * 1) Fully qualified pathname 23695b482a8SLen Brown * 2) No handle, not fully qualified pathname (error) 23795b482a8SLen Brown * 3) Valid handle 23895b482a8SLen Brown */ 23995b482a8SLen Brown if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) { 24095b482a8SLen Brown 24195b482a8SLen Brown /* The path is fully qualified, just evaluate by name */ 24295b482a8SLen Brown 24395b482a8SLen Brown info->prefix_node = NULL; 24495b482a8SLen Brown status = acpi_ns_evaluate(info); 24595b482a8SLen Brown } else if (!handle) { 24695b482a8SLen Brown /* 24795b482a8SLen Brown * A handle is optional iff a fully qualified pathname is specified. 24895b482a8SLen Brown * Since we've already handled fully qualified names above, this is 24995b482a8SLen Brown * an error 25095b482a8SLen Brown */ 25195b482a8SLen Brown if (!pathname) { 25295b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, 25395b482a8SLen Brown "Both Handle and Pathname are NULL")); 25495b482a8SLen Brown } else { 25595b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, 25695b482a8SLen Brown "Null Handle with relative pathname [%s]", 25795b482a8SLen Brown pathname)); 25895b482a8SLen Brown } 25995b482a8SLen Brown 26095b482a8SLen Brown status = AE_BAD_PARAMETER; 26195b482a8SLen Brown } else { 26295b482a8SLen Brown /* We have a namespace a node and a possible relative path */ 26395b482a8SLen Brown 26495b482a8SLen Brown status = acpi_ns_evaluate(info); 26595b482a8SLen Brown } 26695b482a8SLen Brown 26795b482a8SLen Brown /* 26895b482a8SLen Brown * If we are expecting a return value, and all went well above, 26995b482a8SLen Brown * copy the return value to an external object. 27095b482a8SLen Brown */ 27195b482a8SLen Brown if (return_buffer) { 27295b482a8SLen Brown if (!info->return_object) { 27395b482a8SLen Brown return_buffer->length = 0; 27495b482a8SLen Brown } else { 27595b482a8SLen Brown if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) == 27695b482a8SLen Brown ACPI_DESC_TYPE_NAMED) { 27795b482a8SLen Brown /* 27895b482a8SLen Brown * If we received a NS Node as a return object, this means that 27995b482a8SLen Brown * the object we are evaluating has nothing interesting to 28095b482a8SLen Brown * return (such as a mutex, etc.) We return an error because 28195b482a8SLen Brown * these types are essentially unsupported by this interface. 28295b482a8SLen Brown * We don't check up front because this makes it easier to add 28395b482a8SLen Brown * support for various types at a later date if necessary. 28495b482a8SLen Brown */ 28595b482a8SLen Brown status = AE_TYPE; 28695b482a8SLen Brown info->return_object = NULL; /* No need to delete a NS Node */ 28795b482a8SLen Brown return_buffer->length = 0; 28895b482a8SLen Brown } 28995b482a8SLen Brown 29095b482a8SLen Brown if (ACPI_SUCCESS(status)) { 29195b482a8SLen Brown 29295b482a8SLen Brown /* Dereference Index and ref_of references */ 29395b482a8SLen Brown 29495b482a8SLen Brown acpi_ns_resolve_references(info); 29595b482a8SLen Brown 29695b482a8SLen Brown /* Get the size of the returned object */ 29795b482a8SLen Brown 29895b482a8SLen Brown status = 29995b482a8SLen Brown acpi_ut_get_object_size(info->return_object, 30095b482a8SLen Brown &buffer_space_needed); 30195b482a8SLen Brown if (ACPI_SUCCESS(status)) { 30295b482a8SLen Brown 30395b482a8SLen Brown /* Validate/Allocate/Clear caller buffer */ 30495b482a8SLen Brown 30595b482a8SLen Brown status = 30695b482a8SLen Brown acpi_ut_initialize_buffer 30795b482a8SLen Brown (return_buffer, 30895b482a8SLen Brown buffer_space_needed); 30995b482a8SLen Brown if (ACPI_FAILURE(status)) { 31095b482a8SLen Brown /* 31195b482a8SLen Brown * Caller's buffer is too small or a new one can't 31295b482a8SLen Brown * be allocated 31395b482a8SLen Brown */ 31495b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, 31595b482a8SLen Brown "Needed buffer size %X, %s\n", 31695b482a8SLen Brown (u32) 31795b482a8SLen Brown buffer_space_needed, 31895b482a8SLen Brown acpi_format_exception 31995b482a8SLen Brown (status))); 32095b482a8SLen Brown } else { 32195b482a8SLen Brown /* We have enough space for the object, build it */ 32295b482a8SLen Brown 32395b482a8SLen Brown status = 32495b482a8SLen Brown acpi_ut_copy_iobject_to_eobject 32595b482a8SLen Brown (info->return_object, 32695b482a8SLen Brown return_buffer); 32795b482a8SLen Brown } 32895b482a8SLen Brown } 32995b482a8SLen Brown } 33095b482a8SLen Brown } 33195b482a8SLen Brown } 33295b482a8SLen Brown 33395b482a8SLen Brown if (info->return_object) { 33495b482a8SLen Brown /* 33595b482a8SLen Brown * Delete the internal return object. NOTE: Interpreter must be 33695b482a8SLen Brown * locked to avoid race condition. 33795b482a8SLen Brown */ 33895b482a8SLen Brown acpi_ex_enter_interpreter(); 33995b482a8SLen Brown 34095b482a8SLen Brown /* Remove one reference on the return object (should delete it) */ 34195b482a8SLen Brown 34295b482a8SLen Brown acpi_ut_remove_reference(info->return_object); 34395b482a8SLen Brown acpi_ex_exit_interpreter(); 34495b482a8SLen Brown } 34595b482a8SLen Brown 34695b482a8SLen Brown cleanup: 34795b482a8SLen Brown 34895b482a8SLen Brown /* Free the input parameter list (if we created one) */ 34995b482a8SLen Brown 35095b482a8SLen Brown if (info->parameters) { 35195b482a8SLen Brown 35295b482a8SLen Brown /* Free the allocated parameter block */ 35395b482a8SLen Brown 35495b482a8SLen Brown acpi_ut_delete_internal_object_list(info->parameters); 35595b482a8SLen Brown } 35695b482a8SLen Brown 35795b482a8SLen Brown ACPI_FREE(info); 35895b482a8SLen Brown return_ACPI_STATUS(status); 35995b482a8SLen Brown } 36095b482a8SLen Brown 36195b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_evaluate_object) 36295b482a8SLen Brown 36395b482a8SLen Brown /******************************************************************************* 36495b482a8SLen Brown * 36595b482a8SLen Brown * FUNCTION: acpi_ns_resolve_references 36695b482a8SLen Brown * 36795b482a8SLen Brown * PARAMETERS: Info - Evaluation info block 36895b482a8SLen Brown * 36995b482a8SLen Brown * RETURN: Info->return_object is replaced with the dereferenced object 37095b482a8SLen Brown * 37195b482a8SLen Brown * DESCRIPTION: Dereference certain reference objects. Called before an 37295b482a8SLen Brown * internal return object is converted to an external union acpi_object. 37395b482a8SLen Brown * 37495b482a8SLen Brown * Performs an automatic dereference of Index and ref_of reference objects. 37595b482a8SLen Brown * These reference objects are not supported by the union acpi_object, so this is a 37695b482a8SLen Brown * last resort effort to return something useful. Also, provides compatibility 37795b482a8SLen Brown * with other ACPI implementations. 37895b482a8SLen Brown * 37995b482a8SLen Brown * NOTE: does not handle references within returned package objects or nested 38095b482a8SLen Brown * references, but this support could be added later if found to be necessary. 38195b482a8SLen Brown * 38295b482a8SLen Brown ******************************************************************************/ 38395b482a8SLen Brown static void acpi_ns_resolve_references(struct acpi_evaluate_info *info) 38495b482a8SLen Brown { 38595b482a8SLen Brown union acpi_operand_object *obj_desc = NULL; 38695b482a8SLen Brown struct acpi_namespace_node *node; 38795b482a8SLen Brown 38895b482a8SLen Brown /* We are interested in reference objects only */ 38995b482a8SLen Brown 3903371c19cSBob Moore if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) { 39195b482a8SLen Brown return; 39295b482a8SLen Brown } 39395b482a8SLen Brown 39495b482a8SLen Brown /* 39595b482a8SLen Brown * Two types of references are supported - those created by Index and 39695b482a8SLen Brown * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted 39795b482a8SLen Brown * to an union acpi_object, so it is not dereferenced here. A ddb_handle 39895b482a8SLen Brown * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to 39995b482a8SLen Brown * an union acpi_object. 40095b482a8SLen Brown */ 40195b482a8SLen Brown switch (info->return_object->reference.class) { 40295b482a8SLen Brown case ACPI_REFCLASS_INDEX: 40395b482a8SLen Brown 40495b482a8SLen Brown obj_desc = *(info->return_object->reference.where); 40595b482a8SLen Brown break; 40695b482a8SLen Brown 40795b482a8SLen Brown case ACPI_REFCLASS_REFOF: 40895b482a8SLen Brown 40995b482a8SLen Brown node = info->return_object->reference.object; 41095b482a8SLen Brown if (node) { 41195b482a8SLen Brown obj_desc = node->object; 41295b482a8SLen Brown } 41395b482a8SLen Brown break; 41495b482a8SLen Brown 41595b482a8SLen Brown default: 41695b482a8SLen Brown return; 41795b482a8SLen Brown } 41895b482a8SLen Brown 41995b482a8SLen Brown /* Replace the existing reference object */ 42095b482a8SLen Brown 42195b482a8SLen Brown if (obj_desc) { 42295b482a8SLen Brown acpi_ut_add_reference(obj_desc); 42395b482a8SLen Brown acpi_ut_remove_reference(info->return_object); 42495b482a8SLen Brown info->return_object = obj_desc; 42595b482a8SLen Brown } 42695b482a8SLen Brown 42795b482a8SLen Brown return; 42895b482a8SLen Brown } 42995b482a8SLen Brown 43095b482a8SLen Brown /******************************************************************************* 43195b482a8SLen Brown * 43295b482a8SLen Brown * FUNCTION: acpi_walk_namespace 43395b482a8SLen Brown * 43495b482a8SLen Brown * PARAMETERS: Type - acpi_object_type to search for 43595b482a8SLen Brown * start_object - Handle in namespace where search begins 43695b482a8SLen Brown * max_depth - Depth to which search is to reach 43795b482a8SLen Brown * user_function - Called when an object of "Type" is found 43895b482a8SLen Brown * Context - Passed to user function 43995b482a8SLen Brown * return_value - Location where return value of 44095b482a8SLen Brown * user_function is put if terminated early 44195b482a8SLen Brown * 44295b482a8SLen Brown * RETURNS Return value from the user_function if terminated early. 44395b482a8SLen Brown * Otherwise, returns NULL. 44495b482a8SLen Brown * 44595b482a8SLen Brown * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 44695b482a8SLen Brown * starting (and ending) at the object specified by start_handle. 44795b482a8SLen Brown * The user_function is called whenever an object that matches 44895b482a8SLen Brown * the type parameter is found. If the user function returns 44995b482a8SLen Brown * a non-zero value, the search is terminated immediately and this 45095b482a8SLen Brown * value is returned to the caller. 45195b482a8SLen Brown * 45295b482a8SLen Brown * The point of this procedure is to provide a generic namespace 45395b482a8SLen Brown * walk routine that can be called from multiple places to 45495b482a8SLen Brown * provide multiple services; the User Function can be tailored 45595b482a8SLen Brown * to each task, whether it is a print function, a compare 45695b482a8SLen Brown * function, etc. 45795b482a8SLen Brown * 45895b482a8SLen Brown ******************************************************************************/ 45995b482a8SLen Brown 46095b482a8SLen Brown acpi_status 46195b482a8SLen Brown acpi_walk_namespace(acpi_object_type type, 46295b482a8SLen Brown acpi_handle start_object, 46395b482a8SLen Brown u32 max_depth, 46495b482a8SLen Brown acpi_walk_callback user_function, 46595b482a8SLen Brown void *context, void **return_value) 46695b482a8SLen Brown { 46795b482a8SLen Brown acpi_status status; 46895b482a8SLen Brown 46995b482a8SLen Brown ACPI_FUNCTION_TRACE(acpi_walk_namespace); 47095b482a8SLen Brown 47195b482a8SLen Brown /* Parameter validation */ 47295b482a8SLen Brown 47395b482a8SLen Brown if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) { 47495b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 47595b482a8SLen Brown } 47695b482a8SLen Brown 47795b482a8SLen Brown /* 478*8a335a23SBob Moore * Need to acquire the namespace reader lock to prevent interference 479*8a335a23SBob Moore * with any concurrent table unloads (which causes the deletion of 480*8a335a23SBob Moore * namespace objects). We cannot allow the deletion of a namespace node 481*8a335a23SBob Moore * while the user function is using it. The exception to this are the 482*8a335a23SBob Moore * nodes created and deleted during control method execution -- these 483*8a335a23SBob Moore * nodes are marked as temporary nodes and are ignored by the namespace 484*8a335a23SBob Moore * walk. Thus, control methods can be executed while holding the 485*8a335a23SBob Moore * namespace deletion lock (and the user function can execute control 486*8a335a23SBob Moore * methods.) 487*8a335a23SBob Moore */ 488*8a335a23SBob Moore status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock); 489*8a335a23SBob Moore if (ACPI_FAILURE(status)) { 490*8a335a23SBob Moore return status; 491*8a335a23SBob Moore } 492*8a335a23SBob Moore 493*8a335a23SBob Moore /* 494*8a335a23SBob Moore * Lock the namespace around the walk. The namespace will be 495*8a335a23SBob Moore * unlocked/locked around each call to the user function - since the user 496*8a335a23SBob Moore * function must be allowed to make ACPICA calls itself (for example, it 497*8a335a23SBob Moore * will typically execute control methods during device enumeration.) 49895b482a8SLen Brown */ 49995b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 50095b482a8SLen Brown if (ACPI_FAILURE(status)) { 501*8a335a23SBob Moore goto unlock_and_exit; 50295b482a8SLen Brown } 50395b482a8SLen Brown 50495b482a8SLen Brown status = acpi_ns_walk_namespace(type, start_object, max_depth, 505*8a335a23SBob Moore ACPI_NS_WALK_UNLOCK, user_function, 506*8a335a23SBob Moore context, return_value); 50795b482a8SLen Brown 50895b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 509*8a335a23SBob Moore 510*8a335a23SBob Moore unlock_and_exit: 511*8a335a23SBob Moore (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock); 51295b482a8SLen Brown return_ACPI_STATUS(status); 51395b482a8SLen Brown } 51495b482a8SLen Brown 51595b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_walk_namespace) 51695b482a8SLen Brown 51795b482a8SLen Brown /******************************************************************************* 51895b482a8SLen Brown * 51995b482a8SLen Brown * FUNCTION: acpi_ns_get_device_callback 52095b482a8SLen Brown * 52195b482a8SLen Brown * PARAMETERS: Callback from acpi_get_device 52295b482a8SLen Brown * 52395b482a8SLen Brown * RETURN: Status 52495b482a8SLen Brown * 52595b482a8SLen Brown * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non- 52695b482a8SLen Brown * present devices, or if they specified a HID, it filters based 52795b482a8SLen Brown * on that. 52895b482a8SLen Brown * 52995b482a8SLen Brown ******************************************************************************/ 53095b482a8SLen Brown static acpi_status 53195b482a8SLen Brown acpi_ns_get_device_callback(acpi_handle obj_handle, 53295b482a8SLen Brown u32 nesting_level, 53395b482a8SLen Brown void *context, void **return_value) 53495b482a8SLen Brown { 53595b482a8SLen Brown struct acpi_get_devices_info *info = context; 53695b482a8SLen Brown acpi_status status; 53795b482a8SLen Brown struct acpi_namespace_node *node; 53895b482a8SLen Brown u32 flags; 53995b482a8SLen Brown struct acpica_device_id hid; 54095b482a8SLen Brown struct acpi_compatible_id_list *cid; 54195b482a8SLen Brown u32 i; 54295b482a8SLen Brown int found; 54395b482a8SLen Brown 54495b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 54595b482a8SLen Brown if (ACPI_FAILURE(status)) { 54695b482a8SLen Brown return (status); 54795b482a8SLen Brown } 54895b482a8SLen Brown 54995b482a8SLen Brown node = acpi_ns_map_handle_to_node(obj_handle); 55095b482a8SLen Brown status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 55195b482a8SLen Brown if (ACPI_FAILURE(status)) { 55295b482a8SLen Brown return (status); 55395b482a8SLen Brown } 55495b482a8SLen Brown 55595b482a8SLen Brown if (!node) { 55695b482a8SLen Brown return (AE_BAD_PARAMETER); 55795b482a8SLen Brown } 55895b482a8SLen Brown 55995b482a8SLen Brown /* Run _STA to determine if device is present */ 56095b482a8SLen Brown 56195b482a8SLen Brown status = acpi_ut_execute_STA(node, &flags); 56295b482a8SLen Brown if (ACPI_FAILURE(status)) { 56395b482a8SLen Brown return (AE_CTRL_DEPTH); 56495b482a8SLen Brown } 56595b482a8SLen Brown 56695b482a8SLen Brown if (!(flags & ACPI_STA_DEVICE_PRESENT) && 56795b482a8SLen Brown !(flags & ACPI_STA_DEVICE_FUNCTIONING)) { 56895b482a8SLen Brown /* 56995b482a8SLen Brown * Don't examine the children of the device only when the 57095b482a8SLen Brown * device is neither present nor functional. See ACPI spec, 57195b482a8SLen Brown * description of _STA for more information. 57295b482a8SLen Brown */ 57395b482a8SLen Brown return (AE_CTRL_DEPTH); 57495b482a8SLen Brown } 57595b482a8SLen Brown 57695b482a8SLen Brown /* Filter based on device HID & CID */ 57795b482a8SLen Brown 57895b482a8SLen Brown if (info->hid != NULL) { 57995b482a8SLen Brown status = acpi_ut_execute_HID(node, &hid); 58095b482a8SLen Brown if (status == AE_NOT_FOUND) { 58195b482a8SLen Brown return (AE_OK); 58295b482a8SLen Brown } else if (ACPI_FAILURE(status)) { 58395b482a8SLen Brown return (AE_CTRL_DEPTH); 58495b482a8SLen Brown } 58595b482a8SLen Brown 58695b482a8SLen Brown if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) { 58795b482a8SLen Brown 58895b482a8SLen Brown /* Get the list of Compatible IDs */ 58995b482a8SLen Brown 59095b482a8SLen Brown status = acpi_ut_execute_CID(node, &cid); 59195b482a8SLen Brown if (status == AE_NOT_FOUND) { 59295b482a8SLen Brown return (AE_OK); 59395b482a8SLen Brown } else if (ACPI_FAILURE(status)) { 59495b482a8SLen Brown return (AE_CTRL_DEPTH); 59595b482a8SLen Brown } 59695b482a8SLen Brown 59795b482a8SLen Brown /* Walk the CID list */ 59895b482a8SLen Brown 59995b482a8SLen Brown found = 0; 60095b482a8SLen Brown for (i = 0; i < cid->count; i++) { 60195b482a8SLen Brown if (ACPI_STRNCMP(cid->id[i].value, info->hid, 60295b482a8SLen Brown sizeof(struct 60395b482a8SLen Brown acpi_compatible_id)) == 60495b482a8SLen Brown 0) { 60595b482a8SLen Brown found = 1; 60695b482a8SLen Brown break; 60795b482a8SLen Brown } 60895b482a8SLen Brown } 60995b482a8SLen Brown ACPI_FREE(cid); 61095b482a8SLen Brown if (!found) 61195b482a8SLen Brown return (AE_OK); 61295b482a8SLen Brown } 61395b482a8SLen Brown } 61495b482a8SLen Brown 61595b482a8SLen Brown status = info->user_function(obj_handle, nesting_level, info->context, 61695b482a8SLen Brown return_value); 61795b482a8SLen Brown return (status); 61895b482a8SLen Brown } 61995b482a8SLen Brown 62095b482a8SLen Brown /******************************************************************************* 62195b482a8SLen Brown * 62295b482a8SLen Brown * FUNCTION: acpi_get_devices 62395b482a8SLen Brown * 62495b482a8SLen Brown * PARAMETERS: HID - HID to search for. Can be NULL. 62595b482a8SLen Brown * user_function - Called when a matching object is found 62695b482a8SLen Brown * Context - Passed to user function 62795b482a8SLen Brown * return_value - Location where return value of 62895b482a8SLen Brown * user_function is put if terminated early 62995b482a8SLen Brown * 63095b482a8SLen Brown * RETURNS Return value from the user_function if terminated early. 63195b482a8SLen Brown * Otherwise, returns NULL. 63295b482a8SLen Brown * 63395b482a8SLen Brown * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 63495b482a8SLen Brown * starting (and ending) at the object specified by start_handle. 63595b482a8SLen Brown * The user_function is called whenever an object of type 63695b482a8SLen Brown * Device is found. If the user function returns 63795b482a8SLen Brown * a non-zero value, the search is terminated immediately and this 63895b482a8SLen Brown * value is returned to the caller. 63995b482a8SLen Brown * 64095b482a8SLen Brown * This is a wrapper for walk_namespace, but the callback performs 64195b482a8SLen Brown * additional filtering. Please see acpi_ns_get_device_callback. 64295b482a8SLen Brown * 64395b482a8SLen Brown ******************************************************************************/ 64495b482a8SLen Brown 64595b482a8SLen Brown acpi_status 64695b482a8SLen Brown acpi_get_devices(const char *HID, 64795b482a8SLen Brown acpi_walk_callback user_function, 64895b482a8SLen Brown void *context, void **return_value) 64995b482a8SLen Brown { 65095b482a8SLen Brown acpi_status status; 65195b482a8SLen Brown struct acpi_get_devices_info info; 65295b482a8SLen Brown 65395b482a8SLen Brown ACPI_FUNCTION_TRACE(acpi_get_devices); 65495b482a8SLen Brown 65595b482a8SLen Brown /* Parameter validation */ 65695b482a8SLen Brown 65795b482a8SLen Brown if (!user_function) { 65895b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 65995b482a8SLen Brown } 66095b482a8SLen Brown 66195b482a8SLen Brown /* 66295b482a8SLen Brown * We're going to call their callback from OUR callback, so we need 66395b482a8SLen Brown * to know what it is, and their context parameter. 66495b482a8SLen Brown */ 66595b482a8SLen Brown info.hid = HID; 66695b482a8SLen Brown info.context = context; 66795b482a8SLen Brown info.user_function = user_function; 66895b482a8SLen Brown 66995b482a8SLen Brown /* 67095b482a8SLen Brown * Lock the namespace around the walk. 67195b482a8SLen Brown * The namespace will be unlocked/locked around each call 67295b482a8SLen Brown * to the user function - since this function 67395b482a8SLen Brown * must be allowed to make Acpi calls itself. 67495b482a8SLen Brown */ 67595b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 67695b482a8SLen Brown if (ACPI_FAILURE(status)) { 67795b482a8SLen Brown return_ACPI_STATUS(status); 67895b482a8SLen Brown } 67995b482a8SLen Brown 68095b482a8SLen Brown status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 68195b482a8SLen Brown ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, 68295b482a8SLen Brown acpi_ns_get_device_callback, &info, 68395b482a8SLen Brown return_value); 68495b482a8SLen Brown 68595b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 68695b482a8SLen Brown return_ACPI_STATUS(status); 68795b482a8SLen Brown } 68895b482a8SLen Brown 68995b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_devices) 69095b482a8SLen Brown 69195b482a8SLen Brown /******************************************************************************* 69295b482a8SLen Brown * 69395b482a8SLen Brown * FUNCTION: acpi_attach_data 69495b482a8SLen Brown * 69595b482a8SLen Brown * PARAMETERS: obj_handle - Namespace node 69695b482a8SLen Brown * Handler - Handler for this attachment 69795b482a8SLen Brown * Data - Pointer to data to be attached 69895b482a8SLen Brown * 69995b482a8SLen Brown * RETURN: Status 70095b482a8SLen Brown * 70195b482a8SLen Brown * DESCRIPTION: Attach arbitrary data and handler to a namespace node. 70295b482a8SLen Brown * 70395b482a8SLen Brown ******************************************************************************/ 70495b482a8SLen Brown acpi_status 70595b482a8SLen Brown acpi_attach_data(acpi_handle obj_handle, 70695b482a8SLen Brown acpi_object_handler handler, void *data) 70795b482a8SLen Brown { 70895b482a8SLen Brown struct acpi_namespace_node *node; 70995b482a8SLen Brown acpi_status status; 71095b482a8SLen Brown 71195b482a8SLen Brown /* Parameter validation */ 71295b482a8SLen Brown 71395b482a8SLen Brown if (!obj_handle || !handler || !data) { 71495b482a8SLen Brown return (AE_BAD_PARAMETER); 71595b482a8SLen Brown } 71695b482a8SLen Brown 71795b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 71895b482a8SLen Brown if (ACPI_FAILURE(status)) { 71995b482a8SLen Brown return (status); 72095b482a8SLen Brown } 72195b482a8SLen Brown 72295b482a8SLen Brown /* Convert and validate the handle */ 72395b482a8SLen Brown 72495b482a8SLen Brown node = acpi_ns_map_handle_to_node(obj_handle); 72595b482a8SLen Brown if (!node) { 72695b482a8SLen Brown status = AE_BAD_PARAMETER; 72795b482a8SLen Brown goto unlock_and_exit; 72895b482a8SLen Brown } 72995b482a8SLen Brown 73095b482a8SLen Brown status = acpi_ns_attach_data(node, handler, data); 73195b482a8SLen Brown 73295b482a8SLen Brown unlock_and_exit: 73395b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 73495b482a8SLen Brown return (status); 73595b482a8SLen Brown } 73695b482a8SLen Brown 73795b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_attach_data) 73895b482a8SLen Brown 73995b482a8SLen Brown /******************************************************************************* 74095b482a8SLen Brown * 74195b482a8SLen Brown * FUNCTION: acpi_detach_data 74295b482a8SLen Brown * 74395b482a8SLen Brown * PARAMETERS: obj_handle - Namespace node handle 74495b482a8SLen Brown * Handler - Handler used in call to acpi_attach_data 74595b482a8SLen Brown * 74695b482a8SLen Brown * RETURN: Status 74795b482a8SLen Brown * 74895b482a8SLen Brown * DESCRIPTION: Remove data that was previously attached to a node. 74995b482a8SLen Brown * 75095b482a8SLen Brown ******************************************************************************/ 75195b482a8SLen Brown acpi_status 75295b482a8SLen Brown acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler) 75395b482a8SLen Brown { 75495b482a8SLen Brown struct acpi_namespace_node *node; 75595b482a8SLen Brown acpi_status status; 75695b482a8SLen Brown 75795b482a8SLen Brown /* Parameter validation */ 75895b482a8SLen Brown 75995b482a8SLen Brown if (!obj_handle || !handler) { 76095b482a8SLen Brown return (AE_BAD_PARAMETER); 76195b482a8SLen Brown } 76295b482a8SLen Brown 76395b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 76495b482a8SLen Brown if (ACPI_FAILURE(status)) { 76595b482a8SLen Brown return (status); 76695b482a8SLen Brown } 76795b482a8SLen Brown 76895b482a8SLen Brown /* Convert and validate the handle */ 76995b482a8SLen Brown 77095b482a8SLen Brown node = acpi_ns_map_handle_to_node(obj_handle); 77195b482a8SLen Brown if (!node) { 77295b482a8SLen Brown status = AE_BAD_PARAMETER; 77395b482a8SLen Brown goto unlock_and_exit; 77495b482a8SLen Brown } 77595b482a8SLen Brown 77695b482a8SLen Brown status = acpi_ns_detach_data(node, handler); 77795b482a8SLen Brown 77895b482a8SLen Brown unlock_and_exit: 77995b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 78095b482a8SLen Brown return (status); 78195b482a8SLen Brown } 78295b482a8SLen Brown 78395b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_detach_data) 78495b482a8SLen Brown 78595b482a8SLen Brown /******************************************************************************* 78695b482a8SLen Brown * 78795b482a8SLen Brown * FUNCTION: acpi_get_data 78895b482a8SLen Brown * 78995b482a8SLen Brown * PARAMETERS: obj_handle - Namespace node 79095b482a8SLen Brown * Handler - Handler used in call to attach_data 79195b482a8SLen Brown * Data - Where the data is returned 79295b482a8SLen Brown * 79395b482a8SLen Brown * RETURN: Status 79495b482a8SLen Brown * 79595b482a8SLen Brown * DESCRIPTION: Retrieve data that was previously attached to a namespace node. 79695b482a8SLen Brown * 79795b482a8SLen Brown ******************************************************************************/ 79895b482a8SLen Brown acpi_status 79995b482a8SLen Brown acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data) 80095b482a8SLen Brown { 80195b482a8SLen Brown struct acpi_namespace_node *node; 80295b482a8SLen Brown acpi_status status; 80395b482a8SLen Brown 80495b482a8SLen Brown /* Parameter validation */ 80595b482a8SLen Brown 80695b482a8SLen Brown if (!obj_handle || !handler || !data) { 80795b482a8SLen Brown return (AE_BAD_PARAMETER); 80895b482a8SLen Brown } 80995b482a8SLen Brown 81095b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 81195b482a8SLen Brown if (ACPI_FAILURE(status)) { 81295b482a8SLen Brown return (status); 81395b482a8SLen Brown } 81495b482a8SLen Brown 81595b482a8SLen Brown /* Convert and validate the handle */ 81695b482a8SLen Brown 81795b482a8SLen Brown node = acpi_ns_map_handle_to_node(obj_handle); 81895b482a8SLen Brown if (!node) { 81995b482a8SLen Brown status = AE_BAD_PARAMETER; 82095b482a8SLen Brown goto unlock_and_exit; 82195b482a8SLen Brown } 82295b482a8SLen Brown 82395b482a8SLen Brown status = acpi_ns_get_attached_data(node, handler, data); 82495b482a8SLen Brown 82595b482a8SLen Brown unlock_and_exit: 82695b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 82795b482a8SLen Brown return (status); 82895b482a8SLen Brown } 82995b482a8SLen Brown 83095b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_data) 831