Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: nsxfeval - Public interfaces to the ACPI subsystem |
| 4 | * ACPI Object evaluation interfaces |
| 5 | * |
| 6 | ******************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 25f044e | 2013-01-25 05:38:56 +0000 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2013, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
Paul Gortmaker | 214f2c9 | 2011-10-26 16:22:14 -0400 | [diff] [blame] | 45 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 47 | #include "accommon.h" |
| 48 | #include "acnamesp.h" |
| 49 | #include "acinterp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("nsxfeval") |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 53 | |
| 54 | /* Local prototypes */ |
| 55 | static void acpi_ns_resolve_references(struct acpi_evaluate_info *info); |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /******************************************************************************* |
| 58 | * |
| 59 | * FUNCTION: acpi_evaluate_object_typed |
| 60 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 61 | * PARAMETERS: handle - Object handle (optional) |
| 62 | * pathname - Object pathname (optional) |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 63 | * external_params - List of parameters to pass to method, |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 64 | * terminated by NULL. May be NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | * if no parameters are being passed. |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 66 | * return_buffer - Where to put method's return value (if |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 67 | * any). If NULL, no value is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * return_type - Expected type of return object |
| 69 | * |
| 70 | * RETURN: Status |
| 71 | * |
| 72 | * DESCRIPTION: Find and evaluate the given object, passing the given |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 73 | * parameters if necessary. One of "Handle" or "Pathname" must |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | * be valid (non-null) |
| 75 | * |
| 76 | ******************************************************************************/ |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | acpi_evaluate_object_typed(acpi_handle handle, |
| 80 | acpi_string pathname, |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 81 | struct acpi_object_list *external_params, |
| 82 | struct acpi_buffer *return_buffer, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | acpi_object_type return_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | acpi_status status; |
| 86 | u8 must_free = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 88 | ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* Return buffer must be valid */ |
| 91 | |
| 92 | if (!return_buffer) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | if (return_buffer->length == ACPI_ALLOCATE_BUFFER) { |
| 97 | must_free = TRUE; |
| 98 | } |
| 99 | |
| 100 | /* Evaluate the object */ |
| 101 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | status = |
| 103 | acpi_evaluate_object(handle, pathname, external_params, |
| 104 | return_buffer); |
| 105 | if (ACPI_FAILURE(status)) { |
| 106 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* Type ANY means "don't care" */ |
| 110 | |
| 111 | if (return_type == ACPI_TYPE_ANY) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | if (return_buffer->length == 0) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* Error because caller specifically asked for a return value */ |
| 118 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 119 | ACPI_ERROR((AE_INFO, "No return value")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | return_ACPI_STATUS(AE_NULL_OBJECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /* Examine the object type returned from evaluate_object */ |
| 124 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | if (((union acpi_object *)return_buffer->pointer)->type == return_type) { |
| 126 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* Return object type does not match requested type */ |
| 130 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 131 | ACPI_ERROR((AE_INFO, |
| 132 | "Incorrect return type [%s] requested [%s]", |
| 133 | acpi_ut_get_type_name(((union acpi_object *)return_buffer-> |
| 134 | pointer)->type), |
| 135 | acpi_ut_get_type_name(return_type))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | if (must_free) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ |
| 140 | |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 141 | ACPI_FREE(return_buffer->pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | return_buffer->pointer = NULL; |
| 143 | } |
| 144 | |
| 145 | return_buffer->length = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 146 | return_ACPI_STATUS(AE_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 148 | |
| 149 | ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed) |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /******************************************************************************* |
| 152 | * |
| 153 | * FUNCTION: acpi_evaluate_object |
| 154 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 155 | * PARAMETERS: handle - Object handle (optional) |
| 156 | * pathname - Object pathname (optional) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | * external_params - List of parameters to pass to method, |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 158 | * terminated by NULL. May be NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | * if no parameters are being passed. |
| 160 | * return_buffer - Where to put method's return value (if |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 161 | * any). If NULL, no value is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | * |
| 163 | * RETURN: Status |
| 164 | * |
| 165 | * DESCRIPTION: Find and evaluate the given object, passing the given |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 166 | * parameters if necessary. One of "Handle" or "Pathname" must |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | * be valid (non-null) |
| 168 | * |
| 169 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | acpi_evaluate_object(acpi_handle handle, |
| 172 | acpi_string pathname, |
| 173 | struct acpi_object_list *external_params, |
| 174 | struct acpi_buffer *return_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | acpi_status status; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 177 | struct acpi_evaluate_info *info; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | acpi_size buffer_space_needed; |
| 179 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 181 | ACPI_FUNCTION_TRACE(acpi_evaluate_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 183 | /* Allocate and initialize the evaluation information block */ |
| 184 | |
| 185 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 186 | if (!info) { |
| 187 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 188 | } |
| 189 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 190 | /* Convert and validate the device handle */ |
| 191 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 192 | info->prefix_node = acpi_ns_validate_handle(handle); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 193 | if (!info->prefix_node) { |
| 194 | status = AE_BAD_PARAMETER; |
| 195 | goto cleanup; |
| 196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | /* |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 199 | * Get the actual namespace node for the target object. |
| 200 | * Handles these cases: |
| 201 | * |
| 202 | * 1) Null node, valid pathname from root (absolute path) |
| 203 | * 2) Node and valid pathname (path relative to Node) |
| 204 | * 3) Node, Null pathname |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | */ |
Bob Moore | 04a81dc | 2012-12-31 00:05:17 +0000 | [diff] [blame] | 206 | if ((pathname) && (ACPI_IS_ROOT_PREFIX(pathname[0]))) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 207 | |
| 208 | /* The path is fully qualified, just evaluate by name */ |
| 209 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 210 | info->prefix_node = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | } else if (!handle) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 213 | * A handle is optional iff a fully qualified pathname is specified. |
| 214 | * Since we've already handled fully qualified names above, this is |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 215 | * an error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | */ |
| 217 | if (!pathname) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 218 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 219 | "Both Handle and Pathname are NULL")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | } else { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 221 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 222 | "Null Handle with relative pathname [%s]", |
| 223 | pathname)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | status = AE_BAD_PARAMETER; |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 227 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 230 | info->relative_pathname = pathname; |
| 231 | |
| 232 | /* |
| 233 | * Convert all external objects passed as arguments to the |
| 234 | * internal version(s). |
| 235 | */ |
| 236 | if (external_params && external_params->count) { |
| 237 | info->param_count = (u16)external_params->count; |
| 238 | |
| 239 | /* Warn on impossible argument count */ |
| 240 | |
| 241 | if (info->param_count > ACPI_METHOD_NUM_ARGS) { |
| 242 | ACPI_WARN_PREDEFINED((AE_INFO, pathname, |
| 243 | ACPI_WARN_ALWAYS, |
| 244 | "Excess arguments (%u) - using only %u", |
| 245 | info->param_count, |
| 246 | ACPI_METHOD_NUM_ARGS)); |
| 247 | |
| 248 | info->param_count = ACPI_METHOD_NUM_ARGS; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Allocate a new parameter block for the internal objects |
| 253 | * Add 1 to count to allow for null terminated internal list |
| 254 | */ |
| 255 | info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) info-> |
| 256 | param_count + |
| 257 | 1) * sizeof(void *)); |
| 258 | if (!info->parameters) { |
| 259 | status = AE_NO_MEMORY; |
| 260 | goto cleanup; |
| 261 | } |
| 262 | |
| 263 | /* Convert each external object in the list to an internal object */ |
| 264 | |
| 265 | for (i = 0; i < info->param_count; i++) { |
| 266 | status = |
| 267 | acpi_ut_copy_eobject_to_iobject(&external_params-> |
| 268 | pointer[i], |
| 269 | &info-> |
| 270 | parameters[i]); |
| 271 | if (ACPI_FAILURE(status)) { |
| 272 | goto cleanup; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | info->parameters[info->param_count] = NULL; |
| 277 | } |
| 278 | |
| 279 | #if 0 |
| 280 | |
| 281 | /* |
| 282 | * Begin incoming argument count analysis. Check for too few args |
| 283 | * and too many args. |
| 284 | */ |
| 285 | |
| 286 | switch (acpi_ns_get_type(info->node)) { |
| 287 | case ACPI_TYPE_METHOD: |
| 288 | |
| 289 | /* Check incoming argument count against the method definition */ |
| 290 | |
| 291 | if (info->obj_desc->method.param_count > info->param_count) { |
| 292 | ACPI_ERROR((AE_INFO, |
| 293 | "Insufficient arguments (%u) - %u are required", |
| 294 | info->param_count, |
| 295 | info->obj_desc->method.param_count)); |
| 296 | |
| 297 | status = AE_MISSING_ARGUMENTS; |
| 298 | goto cleanup; |
| 299 | } |
| 300 | |
| 301 | else if (info->obj_desc->method.param_count < info->param_count) { |
| 302 | ACPI_WARNING((AE_INFO, |
| 303 | "Excess arguments (%u) - only %u are required", |
| 304 | info->param_count, |
| 305 | info->obj_desc->method.param_count)); |
| 306 | |
| 307 | /* Just pass the required number of arguments */ |
| 308 | |
| 309 | info->param_count = info->obj_desc->method.param_count; |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | * Any incoming external objects to be passed as arguments to the |
| 314 | * method must be converted to internal objects |
| 315 | */ |
| 316 | if (info->param_count) { |
| 317 | /* |
| 318 | * Allocate a new parameter block for the internal objects |
| 319 | * Add 1 to count to allow for null terminated internal list |
| 320 | */ |
| 321 | info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) |
| 322 | info-> |
| 323 | param_count + |
| 324 | 1) * |
| 325 | sizeof(void *)); |
| 326 | if (!info->parameters) { |
| 327 | status = AE_NO_MEMORY; |
| 328 | goto cleanup; |
| 329 | } |
| 330 | |
| 331 | /* Convert each external object in the list to an internal object */ |
| 332 | |
| 333 | for (i = 0; i < info->param_count; i++) { |
| 334 | status = |
| 335 | acpi_ut_copy_eobject_to_iobject |
| 336 | (&external_params->pointer[i], |
| 337 | &info->parameters[i]); |
| 338 | if (ACPI_FAILURE(status)) { |
| 339 | goto cleanup; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | info->parameters[info->param_count] = NULL; |
| 344 | } |
| 345 | break; |
| 346 | |
| 347 | default: |
| 348 | |
| 349 | /* Warn if arguments passed to an object that is not a method */ |
| 350 | |
| 351 | if (info->param_count) { |
| 352 | ACPI_WARNING((AE_INFO, |
| 353 | "%u arguments were passed to a non-method ACPI object", |
| 354 | info->param_count)); |
| 355 | } |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | #endif |
| 360 | |
| 361 | /* Now we can evaluate the object */ |
| 362 | |
| 363 | status = acpi_ns_evaluate(info); |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | /* |
| 366 | * If we are expecting a return value, and all went well above, |
| 367 | * copy the return value to an external object. |
| 368 | */ |
| 369 | if (return_buffer) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 370 | if (!info->return_object) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return_buffer->length = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | } else { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 373 | if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | ACPI_DESC_TYPE_NAMED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | /* |
| 376 | * If we received a NS Node as a return object, this means that |
| 377 | * the object we are evaluating has nothing interesting to |
| 378 | * return (such as a mutex, etc.) We return an error because |
| 379 | * these types are essentially unsupported by this interface. |
| 380 | * We don't check up front because this makes it easier to add |
| 381 | * support for various types at a later date if necessary. |
| 382 | */ |
| 383 | status = AE_TYPE; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 384 | info->return_object = NULL; /* No need to delete a NS Node */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return_buffer->length = 0; |
| 386 | } |
| 387 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 388 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 389 | |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 390 | /* Dereference Index and ref_of references */ |
| 391 | |
| 392 | acpi_ns_resolve_references(info); |
| 393 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 394 | /* Get the size of the returned object */ |
| 395 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | status = |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 397 | acpi_ut_get_object_size(info->return_object, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | &buffer_space_needed); |
| 399 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | /* Validate/Allocate/Clear caller buffer */ |
| 402 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | status = |
| 404 | acpi_ut_initialize_buffer |
| 405 | (return_buffer, |
| 406 | buffer_space_needed); |
| 407 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | /* |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 409 | * Caller's buffer is too small or a new one can't |
| 410 | * be allocated |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 413 | "Needed buffer size %X, %s\n", |
| 414 | (u32) |
| 415 | buffer_space_needed, |
| 416 | acpi_format_exception |
| 417 | (status))); |
| 418 | } else { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 419 | /* We have enough space for the object, build it */ |
| 420 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 421 | status = |
| 422 | acpi_ut_copy_iobject_to_eobject |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 423 | (info->return_object, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 424 | return_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 431 | if (info->return_object) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 433 | * Delete the internal return object. NOTE: Interpreter must be |
| 434 | * locked to avoid race condition. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | */ |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 436 | acpi_ex_enter_interpreter(); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 437 | |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 438 | /* Remove one reference on the return object (should delete it) */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 439 | |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 440 | acpi_ut_remove_reference(info->return_object); |
| 441 | acpi_ex_exit_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 444 | cleanup: |
| 445 | |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 446 | /* Free the input parameter list (if we created one) */ |
| 447 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 448 | if (info->parameters) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | /* Free the allocated parameter block */ |
| 451 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 452 | acpi_ut_delete_internal_object_list(info->parameters); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 455 | ACPI_FREE(info); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 459 | ACPI_EXPORT_SYMBOL(acpi_evaluate_object) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | /******************************************************************************* |
| 462 | * |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 463 | * FUNCTION: acpi_ns_resolve_references |
| 464 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 465 | * PARAMETERS: info - Evaluation info block |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 466 | * |
| 467 | * RETURN: Info->return_object is replaced with the dereferenced object |
| 468 | * |
| 469 | * DESCRIPTION: Dereference certain reference objects. Called before an |
| 470 | * internal return object is converted to an external union acpi_object. |
| 471 | * |
| 472 | * Performs an automatic dereference of Index and ref_of reference objects. |
| 473 | * These reference objects are not supported by the union acpi_object, so this is a |
| 474 | * last resort effort to return something useful. Also, provides compatibility |
| 475 | * with other ACPI implementations. |
| 476 | * |
| 477 | * NOTE: does not handle references within returned package objects or nested |
| 478 | * references, but this support could be added later if found to be necessary. |
| 479 | * |
| 480 | ******************************************************************************/ |
| 481 | static void acpi_ns_resolve_references(struct acpi_evaluate_info *info) |
| 482 | { |
| 483 | union acpi_operand_object *obj_desc = NULL; |
| 484 | struct acpi_namespace_node *node; |
| 485 | |
| 486 | /* We are interested in reference objects only */ |
| 487 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 488 | if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) { |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 489 | return; |
| 490 | } |
| 491 | |
| 492 | /* |
| 493 | * Two types of references are supported - those created by Index and |
| 494 | * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted |
| 495 | * to an union acpi_object, so it is not dereferenced here. A ddb_handle |
| 496 | * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to |
| 497 | * an union acpi_object. |
| 498 | */ |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 499 | switch (info->return_object->reference.class) { |
| 500 | case ACPI_REFCLASS_INDEX: |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 501 | |
| 502 | obj_desc = *(info->return_object->reference.where); |
| 503 | break; |
| 504 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 505 | case ACPI_REFCLASS_REFOF: |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 506 | |
| 507 | node = info->return_object->reference.object; |
| 508 | if (node) { |
| 509 | obj_desc = node->object; |
| 510 | } |
| 511 | break; |
| 512 | |
| 513 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 514 | |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 515 | return; |
| 516 | } |
| 517 | |
| 518 | /* Replace the existing reference object */ |
| 519 | |
| 520 | if (obj_desc) { |
| 521 | acpi_ut_add_reference(obj_desc); |
| 522 | acpi_ut_remove_reference(info->return_object); |
| 523 | info->return_object = obj_desc; |
| 524 | } |
| 525 | |
| 526 | return; |
| 527 | } |
| 528 | |
| 529 | /******************************************************************************* |
| 530 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | * FUNCTION: acpi_walk_namespace |
| 532 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 533 | * PARAMETERS: type - acpi_object_type to search for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | * start_object - Handle in namespace where search begins |
| 535 | * max_depth - Depth to which search is to reach |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 536 | * pre_order_visit - Called during tree pre-order visit |
| 537 | * when an object of "Type" is found |
| 538 | * post_order_visit - Called during tree post-order visit |
| 539 | * when an object of "Type" is found |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 540 | * context - Passed to user function(s) above |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | * return_value - Location where return value of |
| 542 | * user_function is put if terminated early |
| 543 | * |
| 544 | * RETURNS Return value from the user_function if terminated early. |
| 545 | * Otherwise, returns NULL. |
| 546 | * |
| 547 | * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, |
| 548 | * starting (and ending) at the object specified by start_handle. |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 549 | * The callback function is called whenever an object that matches |
| 550 | * the type parameter is found. If the callback function returns |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | * a non-zero value, the search is terminated immediately and this |
| 552 | * value is returned to the caller. |
| 553 | * |
| 554 | * The point of this procedure is to provide a generic namespace |
| 555 | * walk routine that can be called from multiple places to |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 556 | * provide multiple services; the callback function(s) can be |
| 557 | * tailored to each task, whether it is a print function, |
| 558 | * a compare function, etc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | * |
| 560 | ******************************************************************************/ |
Lin Ming | bbc2413 | 2008-08-04 13:22:10 +0800 | [diff] [blame] | 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 563 | acpi_walk_namespace(acpi_object_type type, |
| 564 | acpi_handle start_object, |
| 565 | u32 max_depth, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 566 | acpi_walk_callback pre_order_visit, |
| 567 | acpi_walk_callback post_order_visit, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 568 | void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 570 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 572 | ACPI_FUNCTION_TRACE(acpi_walk_namespace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
| 574 | /* Parameter validation */ |
| 575 | |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 576 | if ((type > ACPI_TYPE_LOCAL_MAX) || |
| 577 | (!max_depth) || (!pre_order_visit && !post_order_visit)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 578 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /* |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 582 | * Need to acquire the namespace reader lock to prevent interference |
| 583 | * with any concurrent table unloads (which causes the deletion of |
| 584 | * namespace objects). We cannot allow the deletion of a namespace node |
| 585 | * while the user function is using it. The exception to this are the |
| 586 | * nodes created and deleted during control method execution -- these |
| 587 | * nodes are marked as temporary nodes and are ignored by the namespace |
| 588 | * walk. Thus, control methods can be executed while holding the |
| 589 | * namespace deletion lock (and the user function can execute control |
| 590 | * methods.) |
| 591 | */ |
| 592 | status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock); |
| 593 | if (ACPI_FAILURE(status)) { |
Lv Zheng | 7b6afb6 | 2012-12-19 05:37:29 +0000 | [diff] [blame] | 594 | return_ACPI_STATUS(status); |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* |
| 598 | * Lock the namespace around the walk. The namespace will be |
| 599 | * unlocked/locked around each call to the user function - since the user |
| 600 | * function must be allowed to make ACPICA calls itself (for example, it |
| 601 | * will typically execute control methods during device enumeration.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 603 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 604 | if (ACPI_FAILURE(status)) { |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 605 | goto unlock_and_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 608 | status = acpi_ns_walk_namespace(type, start_object, max_depth, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 609 | ACPI_NS_WALK_UNLOCK, pre_order_visit, |
| 610 | post_order_visit, context, |
| 611 | return_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 613 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 614 | |
| 615 | unlock_and_exit: |
| 616 | (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 617 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 620 | ACPI_EXPORT_SYMBOL(acpi_walk_namespace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | /******************************************************************************* |
| 623 | * |
| 624 | * FUNCTION: acpi_ns_get_device_callback |
| 625 | * |
| 626 | * PARAMETERS: Callback from acpi_get_device |
| 627 | * |
| 628 | * RETURN: Status |
| 629 | * |
| 630 | * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non- |
| 631 | * present devices, or if they specified a HID, it filters based |
| 632 | * on that. |
| 633 | * |
| 634 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 636 | acpi_ns_get_device_callback(acpi_handle obj_handle, |
| 637 | u32 nesting_level, |
| 638 | void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | struct acpi_get_devices_info *info = context; |
| 641 | acpi_status status; |
| 642 | struct acpi_namespace_node *node; |
| 643 | u32 flags; |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 644 | struct acpi_pnp_device_id *hid; |
| 645 | struct acpi_pnp_device_id_list *cid; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 646 | u32 i; |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 647 | u8 found; |
| 648 | int no_match; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 650 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 651 | if (ACPI_FAILURE(status)) { |
Lv Zheng | 7b6afb6 | 2012-12-19 05:37:29 +0000 | [diff] [blame] | 652 | return (status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 655 | node = acpi_ns_validate_handle(obj_handle); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 656 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 657 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | return (status); |
| 659 | } |
| 660 | |
| 661 | if (!node) { |
| 662 | return (AE_BAD_PARAMETER); |
| 663 | } |
| 664 | |
Lin Ming | 5f8902ac | 2010-01-21 09:15:20 +0800 | [diff] [blame] | 665 | /* |
| 666 | * First, filter based on the device HID and CID. |
| 667 | * |
| 668 | * 01/2010: For this case where a specific HID is requested, we don't |
| 669 | * want to run _STA until we have an actual HID match. Thus, we will |
| 670 | * not unnecessarily execute _STA on devices for which the caller |
| 671 | * doesn't care about. Previously, _STA was executed unconditionally |
| 672 | * on all devices found here. |
| 673 | * |
| 674 | * A side-effect of this change is that now we will continue to search |
| 675 | * for a matching HID even under device trees where the parent device |
| 676 | * would have returned a _STA that indicates it is not present or |
| 677 | * not functioning (thus aborting the search on that branch). |
| 678 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | if (info->hid != NULL) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 680 | status = acpi_ut_execute_HID(node, &hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | if (status == AE_NOT_FOUND) { |
| 682 | return (AE_OK); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 683 | } else if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | return (AE_CTRL_DEPTH); |
| 685 | } |
| 686 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 687 | no_match = ACPI_STRCMP(hid->string, info->hid); |
| 688 | ACPI_FREE(hid); |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 689 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 690 | if (no_match) { |
| 691 | /* |
| 692 | * HID does not match, attempt match within the |
| 693 | * list of Compatible IDs (CIDs) |
| 694 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 695 | status = acpi_ut_execute_CID(node, &cid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | if (status == AE_NOT_FOUND) { |
| 697 | return (AE_OK); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 698 | } else if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return (AE_CTRL_DEPTH); |
| 700 | } |
| 701 | |
| 702 | /* Walk the CID list */ |
| 703 | |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 704 | found = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | for (i = 0; i < cid->count; i++) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 706 | if (ACPI_STRCMP(cid->ids[i].string, info->hid) |
| 707 | == 0) { |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 708 | |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 709 | /* Found a matching CID */ |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 710 | |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 711 | found = TRUE; |
Andrew Patterson | 02f8a85 | 2008-01-22 17:18:22 -0700 | [diff] [blame] | 712 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
| 714 | } |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 715 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 716 | ACPI_FREE(cid); |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 717 | if (!found) { |
Andrew Patterson | 02f8a85 | 2008-01-22 17:18:22 -0700 | [diff] [blame] | 718 | return (AE_OK); |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
Lin Ming | 5f8902ac | 2010-01-21 09:15:20 +0800 | [diff] [blame] | 723 | /* Run _STA to determine if device is present */ |
| 724 | |
| 725 | status = acpi_ut_execute_STA(node, &flags); |
| 726 | if (ACPI_FAILURE(status)) { |
| 727 | return (AE_CTRL_DEPTH); |
| 728 | } |
| 729 | |
| 730 | if (!(flags & ACPI_STA_DEVICE_PRESENT) && |
| 731 | !(flags & ACPI_STA_DEVICE_FUNCTIONING)) { |
| 732 | /* |
| 733 | * Don't examine the children of the device only when the |
| 734 | * device is neither present nor functional. See ACPI spec, |
| 735 | * description of _STA for more information. |
| 736 | */ |
| 737 | return (AE_CTRL_DEPTH); |
| 738 | } |
| 739 | |
| 740 | /* We have a valid device, invoke the user function */ |
| 741 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 742 | status = info->user_function(obj_handle, nesting_level, info->context, |
| 743 | return_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | return (status); |
| 745 | } |
| 746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | /******************************************************************************* |
| 748 | * |
| 749 | * FUNCTION: acpi_get_devices |
| 750 | * |
| 751 | * PARAMETERS: HID - HID to search for. Can be NULL. |
| 752 | * user_function - Called when a matching object is found |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 753 | * context - Passed to user function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | * return_value - Location where return value of |
| 755 | * user_function is put if terminated early |
| 756 | * |
| 757 | * RETURNS Return value from the user_function if terminated early. |
| 758 | * Otherwise, returns NULL. |
| 759 | * |
| 760 | * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, |
| 761 | * starting (and ending) at the object specified by start_handle. |
| 762 | * The user_function is called whenever an object of type |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 763 | * Device is found. If the user function returns |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | * a non-zero value, the search is terminated immediately and this |
| 765 | * value is returned to the caller. |
| 766 | * |
| 767 | * This is a wrapper for walk_namespace, but the callback performs |
Bob Moore | 549f460 | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 768 | * additional filtering. Please see acpi_ns_get_device_callback. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | * |
| 770 | ******************************************************************************/ |
| 771 | |
| 772 | acpi_status |
Al Viro | 70b30fb | 2007-08-21 16:18:20 +0100 | [diff] [blame] | 773 | acpi_get_devices(const char *HID, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 774 | acpi_walk_callback user_function, |
| 775 | void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 777 | acpi_status status; |
| 778 | struct acpi_get_devices_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 780 | ACPI_FUNCTION_TRACE(acpi_get_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | /* Parameter validation */ |
| 783 | |
| 784 | if (!user_function) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 785 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | /* |
| 789 | * We're going to call their callback from OUR callback, so we need |
| 790 | * to know what it is, and their context parameter. |
| 791 | */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 792 | info.hid = HID; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 793 | info.context = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | info.user_function = user_function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | /* |
| 797 | * Lock the namespace around the walk. |
| 798 | * The namespace will be unlocked/locked around each call |
| 799 | * to the user function - since this function |
| 800 | * must be allowed to make Acpi calls itself. |
| 801 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 802 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 803 | if (ACPI_FAILURE(status)) { |
| 804 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 807 | status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
| 808 | ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 809 | acpi_ns_get_device_callback, NULL, |
| 810 | &info, return_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 812 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 813 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 816 | ACPI_EXPORT_SYMBOL(acpi_get_devices) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | /******************************************************************************* |
| 819 | * |
| 820 | * FUNCTION: acpi_attach_data |
| 821 | * |
| 822 | * PARAMETERS: obj_handle - Namespace node |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 823 | * handler - Handler for this attachment |
| 824 | * data - Pointer to data to be attached |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | * |
| 826 | * RETURN: Status |
| 827 | * |
| 828 | * DESCRIPTION: Attach arbitrary data and handler to a namespace node. |
| 829 | * |
| 830 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 832 | acpi_attach_data(acpi_handle obj_handle, |
| 833 | acpi_object_handler handler, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 835 | struct acpi_namespace_node *node; |
| 836 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | /* Parameter validation */ |
| 839 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 840 | if (!obj_handle || !handler || !data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | return (AE_BAD_PARAMETER); |
| 842 | } |
| 843 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 844 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 845 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | return (status); |
| 847 | } |
| 848 | |
| 849 | /* Convert and validate the handle */ |
| 850 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 851 | node = acpi_ns_validate_handle(obj_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | if (!node) { |
| 853 | status = AE_BAD_PARAMETER; |
| 854 | goto unlock_and_exit; |
| 855 | } |
| 856 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 857 | status = acpi_ns_attach_data(node, handler, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 859 | unlock_and_exit: |
| 860 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | return (status); |
| 862 | } |
| 863 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 864 | ACPI_EXPORT_SYMBOL(acpi_attach_data) |
| 865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | /******************************************************************************* |
| 867 | * |
| 868 | * FUNCTION: acpi_detach_data |
| 869 | * |
| 870 | * PARAMETERS: obj_handle - Namespace node handle |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 871 | * handler - Handler used in call to acpi_attach_data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | * |
| 873 | * RETURN: Status |
| 874 | * |
| 875 | * DESCRIPTION: Remove data that was previously attached to a node. |
| 876 | * |
| 877 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 879 | acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 881 | struct acpi_namespace_node *node; |
| 882 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
| 884 | /* Parameter validation */ |
| 885 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 886 | if (!obj_handle || !handler) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | return (AE_BAD_PARAMETER); |
| 888 | } |
| 889 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 890 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 891 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | return (status); |
| 893 | } |
| 894 | |
| 895 | /* Convert and validate the handle */ |
| 896 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 897 | node = acpi_ns_validate_handle(obj_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | if (!node) { |
| 899 | status = AE_BAD_PARAMETER; |
| 900 | goto unlock_and_exit; |
| 901 | } |
| 902 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 903 | status = acpi_ns_detach_data(node, handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 905 | unlock_and_exit: |
| 906 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | return (status); |
| 908 | } |
| 909 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 910 | ACPI_EXPORT_SYMBOL(acpi_detach_data) |
| 911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | /******************************************************************************* |
| 913 | * |
| 914 | * FUNCTION: acpi_get_data |
| 915 | * |
| 916 | * PARAMETERS: obj_handle - Namespace node |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 917 | * handler - Handler used in call to attach_data |
| 918 | * data - Where the data is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | * |
| 920 | * RETURN: Status |
| 921 | * |
| 922 | * DESCRIPTION: Retrieve data that was previously attached to a namespace node. |
| 923 | * |
| 924 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 926 | acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 928 | struct acpi_namespace_node *node; |
| 929 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | /* Parameter validation */ |
| 932 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 933 | if (!obj_handle || !handler || !data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | return (AE_BAD_PARAMETER); |
| 935 | } |
| 936 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 937 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 938 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | return (status); |
| 940 | } |
| 941 | |
| 942 | /* Convert and validate the handle */ |
| 943 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 944 | node = acpi_ns_validate_handle(obj_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | if (!node) { |
| 946 | status = AE_BAD_PARAMETER; |
| 947 | goto unlock_and_exit; |
| 948 | } |
| 949 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 950 | status = acpi_ns_get_attached_data(node, handler, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 952 | unlock_and_exit: |
| 953 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | return (status); |
| 955 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 956 | |
| 957 | ACPI_EXPORT_SYMBOL(acpi_get_data) |