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 /* 97735ca0eSBob Moore * Copyright (C) 2000 - 2017, 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 45839e928fSLv Zheng #define EXPORT_ACPI_INTERFACES 46839e928fSLv Zheng 4795b482a8SLen Brown #include <acpi/acpi.h> 48e2f7a777SLen Brown #include "accommon.h" 49e2f7a777SLen Brown #include "acnamesp.h" 50e2f7a777SLen Brown #include "acinterp.h" 5195b482a8SLen Brown 5295b482a8SLen Brown #define _COMPONENT ACPI_NAMESPACE 5395b482a8SLen Brown ACPI_MODULE_NAME("nsxfeval") 5495b482a8SLen Brown 5595b482a8SLen Brown /* Local prototypes */ 5695b482a8SLen Brown static void acpi_ns_resolve_references(struct acpi_evaluate_info *info); 5795b482a8SLen Brown 5895b482a8SLen Brown /******************************************************************************* 5995b482a8SLen Brown * 6095b482a8SLen Brown * FUNCTION: acpi_evaluate_object_typed 6195b482a8SLen Brown * 62ba494beeSBob Moore * PARAMETERS: handle - Object handle (optional) 63ba494beeSBob Moore * pathname - Object pathname (optional) 6495b482a8SLen Brown * external_params - List of parameters to pass to method, 6595b482a8SLen Brown * terminated by NULL. May be NULL 6695b482a8SLen Brown * if no parameters are being passed. 6795b482a8SLen Brown * return_buffer - Where to put method's return value (if 6895b482a8SLen Brown * any). If NULL, no value is returned. 6995b482a8SLen Brown * return_type - Expected type of return object 7095b482a8SLen Brown * 7195b482a8SLen Brown * RETURN: Status 7295b482a8SLen Brown * 7395b482a8SLen Brown * DESCRIPTION: Find and evaluate the given object, passing the given 7495b482a8SLen Brown * parameters if necessary. One of "Handle" or "Pathname" must 7595b482a8SLen Brown * be valid (non-null) 7695b482a8SLen Brown * 7795b482a8SLen Brown ******************************************************************************/ 7895b482a8SLen Brown 7995b482a8SLen Brown acpi_status 8095b482a8SLen Brown acpi_evaluate_object_typed(acpi_handle handle, 8195b482a8SLen Brown acpi_string pathname, 8295b482a8SLen Brown struct acpi_object_list *external_params, 8395b482a8SLen Brown struct acpi_buffer *return_buffer, 8495b482a8SLen Brown acpi_object_type return_type) 8595b482a8SLen Brown { 8695b482a8SLen Brown acpi_status status; 87bb3fec14SLv Zheng u8 free_buffer_on_error = FALSE; 882d2a9543SBob Moore acpi_handle target_handle; 892d2a9543SBob Moore char *full_pathname; 9095b482a8SLen Brown 9195b482a8SLen Brown ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed); 9295b482a8SLen Brown 9395b482a8SLen Brown /* Return buffer must be valid */ 9495b482a8SLen Brown 9595b482a8SLen Brown if (!return_buffer) { 9695b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 9795b482a8SLen Brown } 9895b482a8SLen Brown 9995b482a8SLen Brown if (return_buffer->length == ACPI_ALLOCATE_BUFFER) { 100bb3fec14SLv Zheng free_buffer_on_error = TRUE; 10195b482a8SLen Brown } 10295b482a8SLen Brown 103*9b40eebcSRafael J. Wysocki if (pathname) { 1042d2a9543SBob Moore status = acpi_get_handle(handle, pathname, &target_handle); 10595b482a8SLen Brown if (ACPI_FAILURE(status)) { 10695b482a8SLen Brown return_ACPI_STATUS(status); 10795b482a8SLen Brown } 108*9b40eebcSRafael J. Wysocki } else { 109*9b40eebcSRafael J. Wysocki target_handle = handle; 110*9b40eebcSRafael J. Wysocki } 11195b482a8SLen Brown 1122d2a9543SBob Moore full_pathname = acpi_ns_get_external_pathname(target_handle); 1132d2a9543SBob Moore if (!full_pathname) { 1142d2a9543SBob Moore return_ACPI_STATUS(AE_NO_MEMORY); 1152d2a9543SBob Moore } 1162d2a9543SBob Moore 1172d2a9543SBob Moore /* Evaluate the object */ 1182d2a9543SBob Moore 1192d2a9543SBob Moore status = acpi_evaluate_object(target_handle, NULL, external_params, 1202d2a9543SBob Moore return_buffer); 1212d2a9543SBob Moore if (ACPI_FAILURE(status)) { 1222d2a9543SBob Moore goto exit; 1232d2a9543SBob Moore } 1242d2a9543SBob Moore 1252d2a9543SBob Moore /* Type ANY means "don't care about return value type" */ 12695b482a8SLen Brown 12795b482a8SLen Brown if (return_type == ACPI_TYPE_ANY) { 1282d2a9543SBob Moore goto exit; 12995b482a8SLen Brown } 13095b482a8SLen Brown 13195b482a8SLen Brown if (return_buffer->length == 0) { 13295b482a8SLen Brown 13395b482a8SLen Brown /* Error because caller specifically asked for a return value */ 13495b482a8SLen Brown 1352d2a9543SBob Moore ACPI_ERROR((AE_INFO, "%s did not return any object", 1362d2a9543SBob Moore full_pathname)); 1372d2a9543SBob Moore status = AE_NULL_OBJECT; 1382d2a9543SBob Moore goto exit; 13995b482a8SLen Brown } 14095b482a8SLen Brown 14195b482a8SLen Brown /* Examine the object type returned from evaluate_object */ 14295b482a8SLen Brown 14395b482a8SLen Brown if (((union acpi_object *)return_buffer->pointer)->type == return_type) { 1442d2a9543SBob Moore goto exit; 14595b482a8SLen Brown } 14695b482a8SLen Brown 14795b482a8SLen Brown /* Return object type does not match requested type */ 14895b482a8SLen Brown 14995b482a8SLen Brown ACPI_ERROR((AE_INFO, 1502d2a9543SBob Moore "Incorrect return type from %s - received [%s], requested [%s]", 1512d2a9543SBob Moore full_pathname, 15295b482a8SLen Brown acpi_ut_get_type_name(((union acpi_object *)return_buffer-> 15395b482a8SLen Brown pointer)->type), 15495b482a8SLen Brown acpi_ut_get_type_name(return_type))); 15595b482a8SLen Brown 156bb3fec14SLv Zheng if (free_buffer_on_error) { 157bb3fec14SLv Zheng /* 158bb3fec14SLv Zheng * Free a buffer created via ACPI_ALLOCATE_BUFFER. 159bb3fec14SLv Zheng * Note: We use acpi_os_free here because acpi_os_allocate was used 160bb3fec14SLv Zheng * to allocate the buffer. This purposefully bypasses the 161bb3fec14SLv Zheng * (optionally enabled) allocation tracking mechanism since we 162bb3fec14SLv Zheng * only want to track internal allocations. 163bb3fec14SLv Zheng */ 164bb3fec14SLv Zheng acpi_os_free(return_buffer->pointer); 16595b482a8SLen Brown return_buffer->pointer = NULL; 16695b482a8SLen Brown } 16795b482a8SLen Brown 16895b482a8SLen Brown return_buffer->length = 0; 1692d2a9543SBob Moore status = AE_TYPE; 1702d2a9543SBob Moore 1712d2a9543SBob Moore exit: 1722d2a9543SBob Moore ACPI_FREE(full_pathname); 1732d2a9543SBob Moore return_ACPI_STATUS(status); 17495b482a8SLen Brown } 17595b482a8SLen Brown 17695b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed) 1772c03d07aSLuca Tettamanti 17895b482a8SLen Brown /******************************************************************************* 17995b482a8SLen Brown * 18095b482a8SLen Brown * FUNCTION: acpi_evaluate_object 18195b482a8SLen Brown * 182ba494beeSBob Moore * PARAMETERS: handle - Object handle (optional) 183ba494beeSBob Moore * pathname - Object pathname (optional) 18495b482a8SLen Brown * external_params - List of parameters to pass to method, 18595b482a8SLen Brown * terminated by NULL. May be NULL 18695b482a8SLen Brown * if no parameters are being passed. 18795b482a8SLen Brown * return_buffer - Where to put method's return value (if 18895b482a8SLen Brown * any). If NULL, no value is returned. 18995b482a8SLen Brown * 19095b482a8SLen Brown * RETURN: Status 19195b482a8SLen Brown * 19295b482a8SLen Brown * DESCRIPTION: Find and evaluate the given object, passing the given 19395b482a8SLen Brown * parameters if necessary. One of "Handle" or "Pathname" must 19495b482a8SLen Brown * be valid (non-null) 19595b482a8SLen Brown * 19695b482a8SLen Brown ******************************************************************************/ 19795b482a8SLen Brown acpi_status 19895b482a8SLen Brown acpi_evaluate_object(acpi_handle handle, 19995b482a8SLen Brown acpi_string pathname, 20095b482a8SLen Brown struct acpi_object_list *external_params, 20195b482a8SLen Brown struct acpi_buffer *return_buffer) 20295b482a8SLen Brown { 20395b482a8SLen Brown acpi_status status; 20495b482a8SLen Brown struct acpi_evaluate_info *info; 20595b482a8SLen Brown acpi_size buffer_space_needed; 20695b482a8SLen Brown u32 i; 20795b482a8SLen Brown 20895b482a8SLen Brown ACPI_FUNCTION_TRACE(acpi_evaluate_object); 20995b482a8SLen Brown 21095b482a8SLen Brown /* Allocate and initialize the evaluation information block */ 21195b482a8SLen Brown 21295b482a8SLen Brown info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); 21395b482a8SLen Brown if (!info) { 21495b482a8SLen Brown return_ACPI_STATUS(AE_NO_MEMORY); 21595b482a8SLen Brown } 21695b482a8SLen Brown 21795b482a8SLen Brown /* Convert and validate the device handle */ 21895b482a8SLen Brown 219f24b664dSBob Moore info->prefix_node = acpi_ns_validate_handle(handle); 22095b482a8SLen Brown if (!info->prefix_node) { 22195b482a8SLen Brown status = AE_BAD_PARAMETER; 22295b482a8SLen Brown goto cleanup; 22395b482a8SLen Brown } 22495b482a8SLen Brown 22595b482a8SLen Brown /* 22629a241ccSBob Moore * Get the actual namespace node for the target object. 22729a241ccSBob Moore * Handles these cases: 22829a241ccSBob Moore * 22929a241ccSBob Moore * 1) Null node, valid pathname from root (absolute path) 23029a241ccSBob Moore * 2) Node and valid pathname (path relative to Node) 23129a241ccSBob Moore * 3) Node, Null pathname 23295b482a8SLen Brown */ 23304a81dceSBob Moore if ((pathname) && (ACPI_IS_ROOT_PREFIX(pathname[0]))) { 23495b482a8SLen Brown 23595b482a8SLen Brown /* The path is fully qualified, just evaluate by name */ 23695b482a8SLen Brown 23795b482a8SLen Brown info->prefix_node = NULL; 23895b482a8SLen Brown } else if (!handle) { 23995b482a8SLen Brown /* 24095b482a8SLen Brown * A handle is optional iff a fully qualified pathname is specified. 24195b482a8SLen Brown * Since we've already handled fully qualified names above, this is 24229a241ccSBob Moore * an error. 24395b482a8SLen Brown */ 24495b482a8SLen Brown if (!pathname) { 24595b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, 24695b482a8SLen Brown "Both Handle and Pathname are NULL")); 24795b482a8SLen Brown } else { 24895b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, 24995b482a8SLen Brown "Null Handle with relative pathname [%s]", 25095b482a8SLen Brown pathname)); 25195b482a8SLen Brown } 25295b482a8SLen Brown 25395b482a8SLen Brown status = AE_BAD_PARAMETER; 25429a241ccSBob Moore goto cleanup; 25529a241ccSBob Moore } 25629a241ccSBob Moore 25729a241ccSBob Moore info->relative_pathname = pathname; 25829a241ccSBob Moore 25929a241ccSBob Moore /* 26029a241ccSBob Moore * Convert all external objects passed as arguments to the 26129a241ccSBob Moore * internal version(s). 26229a241ccSBob Moore */ 26329a241ccSBob Moore if (external_params && external_params->count) { 26429a241ccSBob Moore info->param_count = (u16)external_params->count; 26529a241ccSBob Moore 26629a241ccSBob Moore /* Warn on impossible argument count */ 26729a241ccSBob Moore 26829a241ccSBob Moore if (info->param_count > ACPI_METHOD_NUM_ARGS) { 26929a241ccSBob Moore ACPI_WARN_PREDEFINED((AE_INFO, pathname, 27029a241ccSBob Moore ACPI_WARN_ALWAYS, 27129a241ccSBob Moore "Excess arguments (%u) - using only %u", 27229a241ccSBob Moore info->param_count, 27329a241ccSBob Moore ACPI_METHOD_NUM_ARGS)); 27429a241ccSBob Moore 27529a241ccSBob Moore info->param_count = ACPI_METHOD_NUM_ARGS; 27629a241ccSBob Moore } 27729a241ccSBob Moore 27829a241ccSBob Moore /* 27929a241ccSBob Moore * Allocate a new parameter block for the internal objects 28029a241ccSBob Moore * Add 1 to count to allow for null terminated internal list 28129a241ccSBob Moore */ 28229a241ccSBob Moore info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)info-> 28329a241ccSBob Moore param_count + 28429a241ccSBob Moore 1) * sizeof(void *)); 28529a241ccSBob Moore if (!info->parameters) { 28629a241ccSBob Moore status = AE_NO_MEMORY; 28729a241ccSBob Moore goto cleanup; 28829a241ccSBob Moore } 28929a241ccSBob Moore 29029a241ccSBob Moore /* Convert each external object in the list to an internal object */ 29129a241ccSBob Moore 29229a241ccSBob Moore for (i = 0; i < info->param_count; i++) { 29329a241ccSBob Moore status = 29429a241ccSBob Moore acpi_ut_copy_eobject_to_iobject(&external_params-> 29529a241ccSBob Moore pointer[i], 29629a241ccSBob Moore &info-> 29729a241ccSBob Moore parameters[i]); 29829a241ccSBob Moore if (ACPI_FAILURE(status)) { 29929a241ccSBob Moore goto cleanup; 30029a241ccSBob Moore } 30129a241ccSBob Moore } 30229a241ccSBob Moore 30329a241ccSBob Moore info->parameters[info->param_count] = NULL; 30429a241ccSBob Moore } 30529a241ccSBob Moore 3067dbec553SBob Moore #ifdef _FUTURE_FEATURE 30729a241ccSBob Moore 30829a241ccSBob Moore /* 30929a241ccSBob Moore * Begin incoming argument count analysis. Check for too few args 31029a241ccSBob Moore * and too many args. 31129a241ccSBob Moore */ 31229a241ccSBob Moore switch (acpi_ns_get_type(info->node)) { 31329a241ccSBob Moore case ACPI_TYPE_METHOD: 31429a241ccSBob Moore 31529a241ccSBob Moore /* Check incoming argument count against the method definition */ 31629a241ccSBob Moore 31729a241ccSBob Moore if (info->obj_desc->method.param_count > info->param_count) { 31829a241ccSBob Moore ACPI_ERROR((AE_INFO, 31929a241ccSBob Moore "Insufficient arguments (%u) - %u are required", 32029a241ccSBob Moore info->param_count, 32129a241ccSBob Moore info->obj_desc->method.param_count)); 32229a241ccSBob Moore 32329a241ccSBob Moore status = AE_MISSING_ARGUMENTS; 32429a241ccSBob Moore goto cleanup; 32529a241ccSBob Moore } 32629a241ccSBob Moore 32729a241ccSBob Moore else if (info->obj_desc->method.param_count < info->param_count) { 32829a241ccSBob Moore ACPI_WARNING((AE_INFO, 32929a241ccSBob Moore "Excess arguments (%u) - only %u are required", 33029a241ccSBob Moore info->param_count, 33129a241ccSBob Moore info->obj_desc->method.param_count)); 33229a241ccSBob Moore 33329a241ccSBob Moore /* Just pass the required number of arguments */ 33429a241ccSBob Moore 33529a241ccSBob Moore info->param_count = info->obj_desc->method.param_count; 33629a241ccSBob Moore } 33729a241ccSBob Moore 33829a241ccSBob Moore /* 33929a241ccSBob Moore * Any incoming external objects to be passed as arguments to the 34029a241ccSBob Moore * method must be converted to internal objects 34129a241ccSBob Moore */ 34229a241ccSBob Moore if (info->param_count) { 34329a241ccSBob Moore /* 34429a241ccSBob Moore * Allocate a new parameter block for the internal objects 34529a241ccSBob Moore * Add 1 to count to allow for null terminated internal list 34629a241ccSBob Moore */ 34729a241ccSBob Moore info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) 34829a241ccSBob Moore info-> 34929a241ccSBob Moore param_count + 35029a241ccSBob Moore 1) * 35129a241ccSBob Moore sizeof(void *)); 35229a241ccSBob Moore if (!info->parameters) { 35329a241ccSBob Moore status = AE_NO_MEMORY; 35429a241ccSBob Moore goto cleanup; 35529a241ccSBob Moore } 35629a241ccSBob Moore 35729a241ccSBob Moore /* Convert each external object in the list to an internal object */ 35829a241ccSBob Moore 35929a241ccSBob Moore for (i = 0; i < info->param_count; i++) { 36029a241ccSBob Moore status = 36129a241ccSBob Moore acpi_ut_copy_eobject_to_iobject 36229a241ccSBob Moore (&external_params->pointer[i], 36329a241ccSBob Moore &info->parameters[i]); 36429a241ccSBob Moore if (ACPI_FAILURE(status)) { 36529a241ccSBob Moore goto cleanup; 36629a241ccSBob Moore } 36729a241ccSBob Moore } 36829a241ccSBob Moore 36929a241ccSBob Moore info->parameters[info->param_count] = NULL; 37029a241ccSBob Moore } 37129a241ccSBob Moore break; 37229a241ccSBob Moore 37329a241ccSBob Moore default: 37429a241ccSBob Moore 37529a241ccSBob Moore /* Warn if arguments passed to an object that is not a method */ 37629a241ccSBob Moore 37729a241ccSBob Moore if (info->param_count) { 37829a241ccSBob Moore ACPI_WARNING((AE_INFO, 37929a241ccSBob Moore "%u arguments were passed to a non-method ACPI object", 38029a241ccSBob Moore info->param_count)); 38129a241ccSBob Moore } 38229a241ccSBob Moore break; 38329a241ccSBob Moore } 38429a241ccSBob Moore 38529a241ccSBob Moore #endif 38629a241ccSBob Moore 38729a241ccSBob Moore /* Now we can evaluate the object */ 38895b482a8SLen Brown 38995b482a8SLen Brown status = acpi_ns_evaluate(info); 39095b482a8SLen Brown 39195b482a8SLen Brown /* 39295b482a8SLen Brown * If we are expecting a return value, and all went well above, 39395b482a8SLen Brown * copy the return value to an external object. 39495b482a8SLen Brown */ 3957dbec553SBob Moore if (!return_buffer) { 3967dbec553SBob Moore goto cleanup_return_object; 3977dbec553SBob Moore } 3987dbec553SBob Moore 39995b482a8SLen Brown if (!info->return_object) { 40095b482a8SLen Brown return_buffer->length = 0; 4017dbec553SBob Moore goto cleanup; 4027dbec553SBob Moore } 4037dbec553SBob Moore 40495b482a8SLen Brown if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) == 40595b482a8SLen Brown ACPI_DESC_TYPE_NAMED) { 40695b482a8SLen Brown /* 40795b482a8SLen Brown * If we received a NS Node as a return object, this means that 40895b482a8SLen Brown * the object we are evaluating has nothing interesting to 40995b482a8SLen Brown * return (such as a mutex, etc.) We return an error because 41095b482a8SLen Brown * these types are essentially unsupported by this interface. 41195b482a8SLen Brown * We don't check up front because this makes it easier to add 41295b482a8SLen Brown * support for various types at a later date if necessary. 41395b482a8SLen Brown */ 41495b482a8SLen Brown status = AE_TYPE; 41595b482a8SLen Brown info->return_object = NULL; /* No need to delete a NS Node */ 41695b482a8SLen Brown return_buffer->length = 0; 41795b482a8SLen Brown } 41895b482a8SLen Brown 4197dbec553SBob Moore if (ACPI_FAILURE(status)) { 4207dbec553SBob Moore goto cleanup_return_object; 4217dbec553SBob Moore } 42295b482a8SLen Brown 42395b482a8SLen Brown /* Dereference Index and ref_of references */ 42495b482a8SLen Brown 42595b482a8SLen Brown acpi_ns_resolve_references(info); 42695b482a8SLen Brown 42795b482a8SLen Brown /* Get the size of the returned object */ 42895b482a8SLen Brown 4297dbec553SBob Moore status = acpi_ut_get_object_size(info->return_object, 43095b482a8SLen Brown &buffer_space_needed); 43195b482a8SLen Brown if (ACPI_SUCCESS(status)) { 43295b482a8SLen Brown 43395b482a8SLen Brown /* Validate/Allocate/Clear caller buffer */ 43495b482a8SLen Brown 4357dbec553SBob Moore status = acpi_ut_initialize_buffer(return_buffer, 43695b482a8SLen Brown buffer_space_needed); 43795b482a8SLen Brown if (ACPI_FAILURE(status)) { 43895b482a8SLen Brown /* 43995b482a8SLen Brown * Caller's buffer is too small or a new one can't 44095b482a8SLen Brown * be allocated 44195b482a8SLen Brown */ 44295b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, 44395b482a8SLen Brown "Needed buffer size %X, %s\n", 4447dbec553SBob Moore (u32)buffer_space_needed, 4457dbec553SBob Moore acpi_format_exception(status))); 44695b482a8SLen Brown } else { 44795b482a8SLen Brown /* We have enough space for the object, build it */ 44895b482a8SLen Brown 44995b482a8SLen Brown status = 4507dbec553SBob Moore acpi_ut_copy_iobject_to_eobject(info->return_object, 45195b482a8SLen Brown return_buffer); 45295b482a8SLen Brown } 45395b482a8SLen Brown } 4547dbec553SBob Moore 4557dbec553SBob Moore cleanup_return_object: 45695b482a8SLen Brown 45795b482a8SLen Brown if (info->return_object) { 45895b482a8SLen Brown /* 45995b482a8SLen Brown * Delete the internal return object. NOTE: Interpreter must be 46095b482a8SLen Brown * locked to avoid race condition. 46195b482a8SLen Brown */ 46295b482a8SLen Brown acpi_ex_enter_interpreter(); 46395b482a8SLen Brown 46495b482a8SLen Brown /* Remove one reference on the return object (should delete it) */ 46595b482a8SLen Brown 46695b482a8SLen Brown acpi_ut_remove_reference(info->return_object); 46795b482a8SLen Brown acpi_ex_exit_interpreter(); 46895b482a8SLen Brown } 46995b482a8SLen Brown 47095b482a8SLen Brown cleanup: 47195b482a8SLen Brown 47295b482a8SLen Brown /* Free the input parameter list (if we created one) */ 47395b482a8SLen Brown 47495b482a8SLen Brown if (info->parameters) { 47595b482a8SLen Brown 47695b482a8SLen Brown /* Free the allocated parameter block */ 47795b482a8SLen Brown 47895b482a8SLen Brown acpi_ut_delete_internal_object_list(info->parameters); 47995b482a8SLen Brown } 48095b482a8SLen Brown 48195b482a8SLen Brown ACPI_FREE(info); 48295b482a8SLen Brown return_ACPI_STATUS(status); 48395b482a8SLen Brown } 48495b482a8SLen Brown 48595b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_evaluate_object) 48695b482a8SLen Brown 48795b482a8SLen Brown /******************************************************************************* 48895b482a8SLen Brown * 48995b482a8SLen Brown * FUNCTION: acpi_ns_resolve_references 49095b482a8SLen Brown * 491ba494beeSBob Moore * PARAMETERS: info - Evaluation info block 49295b482a8SLen Brown * 49395b482a8SLen Brown * RETURN: Info->return_object is replaced with the dereferenced object 49495b482a8SLen Brown * 49595b482a8SLen Brown * DESCRIPTION: Dereference certain reference objects. Called before an 49695b482a8SLen Brown * internal return object is converted to an external union acpi_object. 49795b482a8SLen Brown * 49895b482a8SLen Brown * Performs an automatic dereference of Index and ref_of reference objects. 49995b482a8SLen Brown * These reference objects are not supported by the union acpi_object, so this is a 50095b482a8SLen Brown * last resort effort to return something useful. Also, provides compatibility 50195b482a8SLen Brown * with other ACPI implementations. 50295b482a8SLen Brown * 50395b482a8SLen Brown * NOTE: does not handle references within returned package objects or nested 50495b482a8SLen Brown * references, but this support could be added later if found to be necessary. 50595b482a8SLen Brown * 50695b482a8SLen Brown ******************************************************************************/ 50795b482a8SLen Brown static void acpi_ns_resolve_references(struct acpi_evaluate_info *info) 50895b482a8SLen Brown { 50995b482a8SLen Brown union acpi_operand_object *obj_desc = NULL; 51095b482a8SLen Brown struct acpi_namespace_node *node; 51195b482a8SLen Brown 51295b482a8SLen Brown /* We are interested in reference objects only */ 51395b482a8SLen Brown 5143371c19cSBob Moore if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) { 51595b482a8SLen Brown return; 51695b482a8SLen Brown } 51795b482a8SLen Brown 51895b482a8SLen Brown /* 51995b482a8SLen Brown * Two types of references are supported - those created by Index and 52095b482a8SLen Brown * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted 52103440c4eSMasahiro Yamada * to a union acpi_object, so it is not dereferenced here. A ddb_handle 52295b482a8SLen Brown * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to 52303440c4eSMasahiro Yamada * a union acpi_object. 52495b482a8SLen Brown */ 52595b482a8SLen Brown switch (info->return_object->reference.class) { 52695b482a8SLen Brown case ACPI_REFCLASS_INDEX: 52795b482a8SLen Brown 52895b482a8SLen Brown obj_desc = *(info->return_object->reference.where); 52995b482a8SLen Brown break; 53095b482a8SLen Brown 53195b482a8SLen Brown case ACPI_REFCLASS_REFOF: 53295b482a8SLen Brown 53395b482a8SLen Brown node = info->return_object->reference.object; 53495b482a8SLen Brown if (node) { 53595b482a8SLen Brown obj_desc = node->object; 53695b482a8SLen Brown } 53795b482a8SLen Brown break; 53895b482a8SLen Brown 53995b482a8SLen Brown default: 5401d1ea1b7SChao Guan 54195b482a8SLen Brown return; 54295b482a8SLen Brown } 54395b482a8SLen Brown 54495b482a8SLen Brown /* Replace the existing reference object */ 54595b482a8SLen Brown 54695b482a8SLen Brown if (obj_desc) { 54795b482a8SLen Brown acpi_ut_add_reference(obj_desc); 54895b482a8SLen Brown acpi_ut_remove_reference(info->return_object); 54995b482a8SLen Brown info->return_object = obj_desc; 55095b482a8SLen Brown } 55195b482a8SLen Brown 55295b482a8SLen Brown return; 55395b482a8SLen Brown } 55495b482a8SLen Brown 55595b482a8SLen Brown /******************************************************************************* 55695b482a8SLen Brown * 55795b482a8SLen Brown * FUNCTION: acpi_walk_namespace 55895b482a8SLen Brown * 559ba494beeSBob Moore * PARAMETERS: type - acpi_object_type to search for 56095b482a8SLen Brown * start_object - Handle in namespace where search begins 56195b482a8SLen Brown * max_depth - Depth to which search is to reach 5624ef17507SBob Moore * descending_callback - Called during tree descent 5632263576cSLin Ming * when an object of "Type" is found 5644ef17507SBob Moore * ascending_callback - Called during tree ascent 5652263576cSLin Ming * when an object of "Type" is found 566ba494beeSBob Moore * context - Passed to user function(s) above 56795b482a8SLen Brown * return_value - Location where return value of 56895b482a8SLen Brown * user_function is put if terminated early 56995b482a8SLen Brown * 57095b482a8SLen Brown * RETURNS Return value from the user_function if terminated early. 57195b482a8SLen Brown * Otherwise, returns NULL. 57295b482a8SLen Brown * 57395b482a8SLen Brown * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 57495b482a8SLen Brown * starting (and ending) at the object specified by start_handle. 5752263576cSLin Ming * The callback function is called whenever an object that matches 5762263576cSLin Ming * the type parameter is found. If the callback function returns 57795b482a8SLen Brown * a non-zero value, the search is terminated immediately and this 57895b482a8SLen Brown * value is returned to the caller. 57995b482a8SLen Brown * 58095b482a8SLen Brown * The point of this procedure is to provide a generic namespace 58195b482a8SLen Brown * walk routine that can be called from multiple places to 5822263576cSLin Ming * provide multiple services; the callback function(s) can be 5832263576cSLin Ming * tailored to each task, whether it is a print function, 5842263576cSLin Ming * a compare function, etc. 58595b482a8SLen Brown * 58695b482a8SLen Brown ******************************************************************************/ 58795b482a8SLen Brown 58895b482a8SLen Brown acpi_status 58995b482a8SLen Brown acpi_walk_namespace(acpi_object_type type, 59095b482a8SLen Brown acpi_handle start_object, 59195b482a8SLen Brown u32 max_depth, 5924ef17507SBob Moore acpi_walk_callback descending_callback, 5934ef17507SBob Moore acpi_walk_callback ascending_callback, 59495b482a8SLen Brown void *context, void **return_value) 59595b482a8SLen Brown { 59695b482a8SLen Brown acpi_status status; 59795b482a8SLen Brown 59895b482a8SLen Brown ACPI_FUNCTION_TRACE(acpi_walk_namespace); 59995b482a8SLen Brown 60095b482a8SLen Brown /* Parameter validation */ 60195b482a8SLen Brown 6022263576cSLin Ming if ((type > ACPI_TYPE_LOCAL_MAX) || 6034ef17507SBob Moore (!max_depth) || (!descending_callback && !ascending_callback)) { 60495b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 60595b482a8SLen Brown } 60695b482a8SLen Brown 60795b482a8SLen Brown /* 6088a335a23SBob Moore * Need to acquire the namespace reader lock to prevent interference 6098a335a23SBob Moore * with any concurrent table unloads (which causes the deletion of 6108a335a23SBob Moore * namespace objects). We cannot allow the deletion of a namespace node 6118a335a23SBob Moore * while the user function is using it. The exception to this are the 6128a335a23SBob Moore * nodes created and deleted during control method execution -- these 6138a335a23SBob Moore * nodes are marked as temporary nodes and are ignored by the namespace 6148a335a23SBob Moore * walk. Thus, control methods can be executed while holding the 6158a335a23SBob Moore * namespace deletion lock (and the user function can execute control 6168a335a23SBob Moore * methods.) 6178a335a23SBob Moore */ 6188a335a23SBob Moore status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock); 6198a335a23SBob Moore if (ACPI_FAILURE(status)) { 6207b6afb67SLv Zheng return_ACPI_STATUS(status); 6218a335a23SBob Moore } 6228a335a23SBob Moore 6238a335a23SBob Moore /* 6248a335a23SBob Moore * Lock the namespace around the walk. The namespace will be 6258a335a23SBob Moore * unlocked/locked around each call to the user function - since the user 6268a335a23SBob Moore * function must be allowed to make ACPICA calls itself (for example, it 6278a335a23SBob Moore * will typically execute control methods during device enumeration.) 62895b482a8SLen Brown */ 62995b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 63095b482a8SLen Brown if (ACPI_FAILURE(status)) { 6318a335a23SBob Moore goto unlock_and_exit; 63295b482a8SLen Brown } 63395b482a8SLen Brown 634d53d8207SBob Moore /* Now we can validate the starting node */ 635d53d8207SBob Moore 636d53d8207SBob Moore if (!acpi_ns_validate_handle(start_object)) { 637d53d8207SBob Moore status = AE_BAD_PARAMETER; 638d53d8207SBob Moore goto unlock_and_exit2; 639d53d8207SBob Moore } 640d53d8207SBob Moore 64195b482a8SLen Brown status = acpi_ns_walk_namespace(type, start_object, max_depth, 6424ef17507SBob Moore ACPI_NS_WALK_UNLOCK, 6434ef17507SBob Moore descending_callback, ascending_callback, 6444ef17507SBob Moore context, return_value); 64595b482a8SLen Brown 646d53d8207SBob Moore unlock_and_exit2: 64795b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 6488a335a23SBob Moore 6498a335a23SBob Moore unlock_and_exit: 6508a335a23SBob Moore (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock); 65195b482a8SLen Brown return_ACPI_STATUS(status); 65295b482a8SLen Brown } 65395b482a8SLen Brown 65495b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_walk_namespace) 65595b482a8SLen Brown 65695b482a8SLen Brown /******************************************************************************* 65795b482a8SLen Brown * 65895b482a8SLen Brown * FUNCTION: acpi_ns_get_device_callback 65995b482a8SLen Brown * 66095b482a8SLen Brown * PARAMETERS: Callback from acpi_get_device 66195b482a8SLen Brown * 66295b482a8SLen Brown * RETURN: Status 66395b482a8SLen Brown * 66495b482a8SLen Brown * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non- 66595b482a8SLen Brown * present devices, or if they specified a HID, it filters based 66695b482a8SLen Brown * on that. 66795b482a8SLen Brown * 66895b482a8SLen Brown ******************************************************************************/ 66995b482a8SLen Brown static acpi_status 67095b482a8SLen Brown acpi_ns_get_device_callback(acpi_handle obj_handle, 67195b482a8SLen Brown u32 nesting_level, 67295b482a8SLen Brown void *context, void **return_value) 67395b482a8SLen Brown { 67495b482a8SLen Brown struct acpi_get_devices_info *info = context; 67595b482a8SLen Brown acpi_status status; 67695b482a8SLen Brown struct acpi_namespace_node *node; 67795b482a8SLen Brown u32 flags; 67878e25fefSLv Zheng struct acpi_pnp_device_id *hid; 67978e25fefSLv Zheng struct acpi_pnp_device_id_list *cid; 68095b482a8SLen Brown u32 i; 68115b8dd53SBob Moore u8 found; 68215b8dd53SBob Moore int no_match; 68395b482a8SLen Brown 68495b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 68595b482a8SLen Brown if (ACPI_FAILURE(status)) { 6867b6afb67SLv Zheng return (status); 68795b482a8SLen Brown } 68895b482a8SLen Brown 689f24b664dSBob Moore node = acpi_ns_validate_handle(obj_handle); 69095b482a8SLen Brown status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 69195b482a8SLen Brown if (ACPI_FAILURE(status)) { 69295b482a8SLen Brown return (status); 69395b482a8SLen Brown } 69495b482a8SLen Brown 69595b482a8SLen Brown if (!node) { 69695b482a8SLen Brown return (AE_BAD_PARAMETER); 69795b482a8SLen Brown } 69895b482a8SLen Brown 69995b482a8SLen Brown /* 7005f8902acSLin Ming * First, filter based on the device HID and CID. 7015f8902acSLin Ming * 7025f8902acSLin Ming * 01/2010: For this case where a specific HID is requested, we don't 7035f8902acSLin Ming * want to run _STA until we have an actual HID match. Thus, we will 7045f8902acSLin Ming * not unnecessarily execute _STA on devices for which the caller 7055f8902acSLin Ming * doesn't care about. Previously, _STA was executed unconditionally 7065f8902acSLin Ming * on all devices found here. 7075f8902acSLin Ming * 7085f8902acSLin Ming * A side-effect of this change is that now we will continue to search 7095f8902acSLin Ming * for a matching HID even under device trees where the parent device 7105f8902acSLin Ming * would have returned a _STA that indicates it is not present or 7115f8902acSLin Ming * not functioning (thus aborting the search on that branch). 71295b482a8SLen Brown */ 71395b482a8SLen Brown if (info->hid != NULL) { 71495b482a8SLen Brown status = acpi_ut_execute_HID(node, &hid); 71595b482a8SLen Brown if (status == AE_NOT_FOUND) { 71695b482a8SLen Brown return (AE_OK); 71795b482a8SLen Brown } else if (ACPI_FAILURE(status)) { 71895b482a8SLen Brown return (AE_CTRL_DEPTH); 71995b482a8SLen Brown } 72095b482a8SLen Brown 7214fa4616eSBob Moore no_match = strcmp(hid->string, info->hid); 72215b8dd53SBob Moore ACPI_FREE(hid); 72395b482a8SLen Brown 72415b8dd53SBob Moore if (no_match) { 72515b8dd53SBob Moore /* 72615b8dd53SBob Moore * HID does not match, attempt match within the 72715b8dd53SBob Moore * list of Compatible IDs (CIDs) 72815b8dd53SBob Moore */ 72995b482a8SLen Brown status = acpi_ut_execute_CID(node, &cid); 73095b482a8SLen Brown if (status == AE_NOT_FOUND) { 73195b482a8SLen Brown return (AE_OK); 73295b482a8SLen Brown } else if (ACPI_FAILURE(status)) { 73395b482a8SLen Brown return (AE_CTRL_DEPTH); 73495b482a8SLen Brown } 73595b482a8SLen Brown 73695b482a8SLen Brown /* Walk the CID list */ 73795b482a8SLen Brown 738739dcbb9SLv Zheng found = FALSE; 73995b482a8SLen Brown for (i = 0; i < cid->count; i++) { 7404fa4616eSBob Moore if (strcmp(cid->ids[i].string, info->hid) == 0) { 7413e8214e5SLv Zheng 74275c8044fSLv Zheng /* Found a matching CID */ 7433e8214e5SLv Zheng 744739dcbb9SLv Zheng found = TRUE; 74595b482a8SLen Brown break; 74695b482a8SLen Brown } 74795b482a8SLen Brown } 748739dcbb9SLv Zheng 74995b482a8SLen Brown ACPI_FREE(cid); 750739dcbb9SLv Zheng if (!found) { 75195b482a8SLen Brown return (AE_OK); 75295b482a8SLen Brown } 75395b482a8SLen Brown } 754739dcbb9SLv Zheng } 75595b482a8SLen Brown 7565f8902acSLin Ming /* Run _STA to determine if device is present */ 7575f8902acSLin Ming 7585f8902acSLin Ming status = acpi_ut_execute_STA(node, &flags); 7595f8902acSLin Ming if (ACPI_FAILURE(status)) { 7605f8902acSLin Ming return (AE_CTRL_DEPTH); 7615f8902acSLin Ming } 7625f8902acSLin Ming 7635f8902acSLin Ming if (!(flags & ACPI_STA_DEVICE_PRESENT) && 7645f8902acSLin Ming !(flags & ACPI_STA_DEVICE_FUNCTIONING)) { 7655f8902acSLin Ming /* 7665f8902acSLin Ming * Don't examine the children of the device only when the 7675f8902acSLin Ming * device is neither present nor functional. See ACPI spec, 7685f8902acSLin Ming * description of _STA for more information. 7695f8902acSLin Ming */ 7705f8902acSLin Ming return (AE_CTRL_DEPTH); 7715f8902acSLin Ming } 7725f8902acSLin Ming 7735f8902acSLin Ming /* We have a valid device, invoke the user function */ 7745f8902acSLin Ming 7751fad8738SBob Moore status = info->user_function(obj_handle, nesting_level, 7761fad8738SBob Moore info->context, return_value); 77795b482a8SLen Brown return (status); 77895b482a8SLen Brown } 77995b482a8SLen Brown 78095b482a8SLen Brown /******************************************************************************* 78195b482a8SLen Brown * 78295b482a8SLen Brown * FUNCTION: acpi_get_devices 78395b482a8SLen Brown * 78495b482a8SLen Brown * PARAMETERS: HID - HID to search for. Can be NULL. 78595b482a8SLen Brown * user_function - Called when a matching object is found 786ba494beeSBob Moore * context - Passed to user function 78795b482a8SLen Brown * return_value - Location where return value of 78895b482a8SLen Brown * user_function is put if terminated early 78995b482a8SLen Brown * 79095b482a8SLen Brown * RETURNS Return value from the user_function if terminated early. 79195b482a8SLen Brown * Otherwise, returns NULL. 79295b482a8SLen Brown * 79395b482a8SLen Brown * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 79495b482a8SLen Brown * starting (and ending) at the object specified by start_handle. 79595b482a8SLen Brown * The user_function is called whenever an object of type 79695b482a8SLen Brown * Device is found. If the user function returns 79795b482a8SLen Brown * a non-zero value, the search is terminated immediately and this 79895b482a8SLen Brown * value is returned to the caller. 79995b482a8SLen Brown * 80095b482a8SLen Brown * This is a wrapper for walk_namespace, but the callback performs 80195b482a8SLen Brown * additional filtering. Please see acpi_ns_get_device_callback. 80295b482a8SLen Brown * 80395b482a8SLen Brown ******************************************************************************/ 80495b482a8SLen Brown 80595b482a8SLen Brown acpi_status 80695b482a8SLen Brown acpi_get_devices(const char *HID, 80795b482a8SLen Brown acpi_walk_callback user_function, 80895b482a8SLen Brown void *context, void **return_value) 80995b482a8SLen Brown { 81095b482a8SLen Brown acpi_status status; 81195b482a8SLen Brown struct acpi_get_devices_info info; 81295b482a8SLen Brown 81395b482a8SLen Brown ACPI_FUNCTION_TRACE(acpi_get_devices); 81495b482a8SLen Brown 81595b482a8SLen Brown /* Parameter validation */ 81695b482a8SLen Brown 81795b482a8SLen Brown if (!user_function) { 81895b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 81995b482a8SLen Brown } 82095b482a8SLen Brown 82195b482a8SLen Brown /* 82295b482a8SLen Brown * We're going to call their callback from OUR callback, so we need 82395b482a8SLen Brown * to know what it is, and their context parameter. 82495b482a8SLen Brown */ 82595b482a8SLen Brown info.hid = HID; 82695b482a8SLen Brown info.context = context; 82795b482a8SLen Brown info.user_function = user_function; 82895b482a8SLen Brown 82995b482a8SLen Brown /* 83095b482a8SLen Brown * Lock the namespace around the walk. 83195b482a8SLen Brown * The namespace will be unlocked/locked around each call 83295b482a8SLen Brown * to the user function - since this function 83395b482a8SLen Brown * must be allowed to make Acpi calls itself. 83495b482a8SLen Brown */ 83595b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 83695b482a8SLen Brown if (ACPI_FAILURE(status)) { 83795b482a8SLen Brown return_ACPI_STATUS(status); 83895b482a8SLen Brown } 83995b482a8SLen Brown 84095b482a8SLen Brown status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 84195b482a8SLen Brown ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, 8422263576cSLin Ming acpi_ns_get_device_callback, NULL, 8432263576cSLin Ming &info, return_value); 84495b482a8SLen Brown 84595b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 84695b482a8SLen Brown return_ACPI_STATUS(status); 84795b482a8SLen Brown } 84895b482a8SLen Brown 84995b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_devices) 85095b482a8SLen Brown 85195b482a8SLen Brown /******************************************************************************* 85295b482a8SLen Brown * 85395b482a8SLen Brown * FUNCTION: acpi_attach_data 85495b482a8SLen Brown * 85595b482a8SLen Brown * PARAMETERS: obj_handle - Namespace node 856ba494beeSBob Moore * handler - Handler for this attachment 857ba494beeSBob Moore * data - Pointer to data to be attached 85895b482a8SLen Brown * 85995b482a8SLen Brown * RETURN: Status 86095b482a8SLen Brown * 86195b482a8SLen Brown * DESCRIPTION: Attach arbitrary data and handler to a namespace node. 86295b482a8SLen Brown * 86395b482a8SLen Brown ******************************************************************************/ 86495b482a8SLen Brown acpi_status 86595b482a8SLen Brown acpi_attach_data(acpi_handle obj_handle, 86695b482a8SLen Brown acpi_object_handler handler, void *data) 86795b482a8SLen Brown { 86895b482a8SLen Brown struct acpi_namespace_node *node; 86995b482a8SLen Brown acpi_status status; 87095b482a8SLen Brown 87195b482a8SLen Brown /* Parameter validation */ 87295b482a8SLen Brown 87395b482a8SLen Brown if (!obj_handle || !handler || !data) { 87495b482a8SLen Brown return (AE_BAD_PARAMETER); 87595b482a8SLen Brown } 87695b482a8SLen Brown 87795b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 87895b482a8SLen Brown if (ACPI_FAILURE(status)) { 87995b482a8SLen Brown return (status); 88095b482a8SLen Brown } 88195b482a8SLen Brown 88295b482a8SLen Brown /* Convert and validate the handle */ 88395b482a8SLen Brown 884f24b664dSBob Moore node = acpi_ns_validate_handle(obj_handle); 88595b482a8SLen Brown if (!node) { 88695b482a8SLen Brown status = AE_BAD_PARAMETER; 88795b482a8SLen Brown goto unlock_and_exit; 88895b482a8SLen Brown } 88995b482a8SLen Brown 89095b482a8SLen Brown status = acpi_ns_attach_data(node, handler, data); 89195b482a8SLen Brown 89295b482a8SLen Brown unlock_and_exit: 89395b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 89495b482a8SLen Brown return (status); 89595b482a8SLen Brown } 89695b482a8SLen Brown 89795b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_attach_data) 89895b482a8SLen Brown 89995b482a8SLen Brown /******************************************************************************* 90095b482a8SLen Brown * 90195b482a8SLen Brown * FUNCTION: acpi_detach_data 90295b482a8SLen Brown * 90395b482a8SLen Brown * PARAMETERS: obj_handle - Namespace node handle 904ba494beeSBob Moore * handler - Handler used in call to acpi_attach_data 90595b482a8SLen Brown * 90695b482a8SLen Brown * RETURN: Status 90795b482a8SLen Brown * 90895b482a8SLen Brown * DESCRIPTION: Remove data that was previously attached to a node. 90995b482a8SLen Brown * 91095b482a8SLen Brown ******************************************************************************/ 91195b482a8SLen Brown acpi_status 91295b482a8SLen Brown acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler) 91395b482a8SLen Brown { 91495b482a8SLen Brown struct acpi_namespace_node *node; 91595b482a8SLen Brown acpi_status status; 91695b482a8SLen Brown 91795b482a8SLen Brown /* Parameter validation */ 91895b482a8SLen Brown 91995b482a8SLen Brown if (!obj_handle || !handler) { 92095b482a8SLen Brown return (AE_BAD_PARAMETER); 92195b482a8SLen Brown } 92295b482a8SLen Brown 92395b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 92495b482a8SLen Brown if (ACPI_FAILURE(status)) { 92595b482a8SLen Brown return (status); 92695b482a8SLen Brown } 92795b482a8SLen Brown 92895b482a8SLen Brown /* Convert and validate the handle */ 92995b482a8SLen Brown 930f24b664dSBob Moore node = acpi_ns_validate_handle(obj_handle); 93195b482a8SLen Brown if (!node) { 93295b482a8SLen Brown status = AE_BAD_PARAMETER; 93395b482a8SLen Brown goto unlock_and_exit; 93495b482a8SLen Brown } 93595b482a8SLen Brown 93695b482a8SLen Brown status = acpi_ns_detach_data(node, handler); 93795b482a8SLen Brown 93895b482a8SLen Brown unlock_and_exit: 93995b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 94095b482a8SLen Brown return (status); 94195b482a8SLen Brown } 94295b482a8SLen Brown 94395b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_detach_data) 94495b482a8SLen Brown 94595b482a8SLen Brown /******************************************************************************* 94695b482a8SLen Brown * 9477c2e1771SRafael J. Wysocki * FUNCTION: acpi_get_data_full 94895b482a8SLen Brown * 94995b482a8SLen Brown * PARAMETERS: obj_handle - Namespace node 950ba494beeSBob Moore * handler - Handler used in call to attach_data 951ba494beeSBob Moore * data - Where the data is returned 9527c2e1771SRafael J. Wysocki * callback - function to execute before returning 95395b482a8SLen Brown * 95495b482a8SLen Brown * RETURN: Status 95595b482a8SLen Brown * 9567c2e1771SRafael J. Wysocki * DESCRIPTION: Retrieve data that was previously attached to a namespace node 9577c2e1771SRafael J. Wysocki * and execute a callback before returning. 95895b482a8SLen Brown * 95995b482a8SLen Brown ******************************************************************************/ 96095b482a8SLen Brown acpi_status 9617c2e1771SRafael J. Wysocki acpi_get_data_full(acpi_handle obj_handle, acpi_object_handler handler, 9627c2e1771SRafael J. Wysocki void **data, void (*callback)(void *)) 96395b482a8SLen Brown { 96495b482a8SLen Brown struct acpi_namespace_node *node; 96595b482a8SLen Brown acpi_status status; 96695b482a8SLen Brown 96795b482a8SLen Brown /* Parameter validation */ 96895b482a8SLen Brown 96995b482a8SLen Brown if (!obj_handle || !handler || !data) { 97095b482a8SLen Brown return (AE_BAD_PARAMETER); 97195b482a8SLen Brown } 97295b482a8SLen Brown 97395b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 97495b482a8SLen Brown if (ACPI_FAILURE(status)) { 97595b482a8SLen Brown return (status); 97695b482a8SLen Brown } 97795b482a8SLen Brown 97895b482a8SLen Brown /* Convert and validate the handle */ 97995b482a8SLen Brown 980f24b664dSBob Moore node = acpi_ns_validate_handle(obj_handle); 98195b482a8SLen Brown if (!node) { 98295b482a8SLen Brown status = AE_BAD_PARAMETER; 98395b482a8SLen Brown goto unlock_and_exit; 98495b482a8SLen Brown } 98595b482a8SLen Brown 98695b482a8SLen Brown status = acpi_ns_get_attached_data(node, handler, data); 9877c2e1771SRafael J. Wysocki if (ACPI_SUCCESS(status) && callback) { 9887c2e1771SRafael J. Wysocki callback(*data); 9897c2e1771SRafael J. Wysocki } 99095b482a8SLen Brown 99195b482a8SLen Brown unlock_and_exit: 99295b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 99395b482a8SLen Brown return (status); 99495b482a8SLen Brown } 99595b482a8SLen Brown 9967c2e1771SRafael J. Wysocki ACPI_EXPORT_SYMBOL(acpi_get_data_full) 9977c2e1771SRafael J. Wysocki 9987c2e1771SRafael J. Wysocki /******************************************************************************* 9997c2e1771SRafael J. Wysocki * 10007c2e1771SRafael J. Wysocki * FUNCTION: acpi_get_data 10017c2e1771SRafael J. Wysocki * 10027c2e1771SRafael J. Wysocki * PARAMETERS: obj_handle - Namespace node 10037c2e1771SRafael J. Wysocki * handler - Handler used in call to attach_data 10047c2e1771SRafael J. Wysocki * data - Where the data is returned 10057c2e1771SRafael J. Wysocki * 10067c2e1771SRafael J. Wysocki * RETURN: Status 10077c2e1771SRafael J. Wysocki * 10087c2e1771SRafael J. Wysocki * DESCRIPTION: Retrieve data that was previously attached to a namespace node. 10097c2e1771SRafael J. Wysocki * 10107c2e1771SRafael J. Wysocki ******************************************************************************/ 10117c2e1771SRafael J. Wysocki acpi_status 10127c2e1771SRafael J. Wysocki acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data) 10137c2e1771SRafael J. Wysocki { 10147c2e1771SRafael J. Wysocki return acpi_get_data_full(obj_handle, handler, data, NULL); 10157c2e1771SRafael J. Wysocki } 10167c2e1771SRafael J. Wysocki 101795b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_data) 1018