Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * acpi_utils.c - ACPI Utility Functions ($Revision: 10 $) |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 6 | * |
| 7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or (at |
| 12 | * your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 22 | * |
| 23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <acpi/acpi_bus.h> |
| 31 | #include <acpi/acpi_drivers.h> |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define _COMPONENT ACPI_BUS_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 34 | ACPI_MODULE_NAME("acpi_utils") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | /* -------------------------------------------------------------------------- |
| 37 | Object Evaluation Helpers |
| 38 | -------------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #ifdef ACPI_DEBUG_OUTPUT |
| 40 | #define acpi_util_eval_error(h,p,s) {\ |
| 41 | char prefix[80] = {'\0'};\ |
| 42 | struct acpi_buffer buffer = {sizeof(prefix), prefix};\ |
| 43 | acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\ |
| 44 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate [%s.%s]: %s\n",\ |
| 45 | (char *) prefix, p, acpi_format_exception(s))); } |
| 46 | #else |
| 47 | #define acpi_util_eval_error(h,p,s) |
| 48 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | acpi_extract_package(union acpi_object *package, |
| 51 | struct acpi_buffer *format, struct acpi_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | u32 size_required = 0; |
| 54 | u32 tail_offset = 0; |
| 55 | char *format_string = NULL; |
| 56 | u32 format_count = 0; |
| 57 | u32 i = 0; |
| 58 | u8 *head = NULL; |
| 59 | u8 *tail = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | ACPI_FUNCTION_TRACE("acpi_extract_package"); |
| 62 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | if (!package || (package->type != ACPI_TYPE_PACKAGE) |
| 64 | || (package->package.count < 1)) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 65 | printk(KERN_WARNING PREFIX "Invalid package argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 67 | } |
| 68 | |
| 69 | if (!format || !format->pointer || (format->length < 1)) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 70 | printk(KERN_WARNING PREFIX "Invalid format argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 72 | } |
| 73 | |
| 74 | if (!buffer) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 75 | printk(KERN_WARNING PREFIX "Invalid buffer argument\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 77 | } |
| 78 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | format_count = (format->length / sizeof(char)) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | if (format_count > package->package.count) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 81 | printk(KERN_WARNING PREFIX "Format specifies more objects [%d]" |
| 82 | " than exist in package [%d].\n", |
| 83 | format_count, package->package.count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return_ACPI_STATUS(AE_BAD_DATA); |
| 85 | } |
| 86 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | format_string = (char *)format->pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * Calculate size_required. |
| 91 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | for (i = 0; i < format_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | union acpi_object *element = &(package->package.elements[i]); |
| 95 | |
| 96 | if (!element) { |
| 97 | return_ACPI_STATUS(AE_BAD_DATA); |
| 98 | } |
| 99 | |
| 100 | switch (element->type) { |
| 101 | |
| 102 | case ACPI_TYPE_INTEGER: |
| 103 | switch (format_string[i]) { |
| 104 | case 'N': |
| 105 | size_required += sizeof(acpi_integer); |
| 106 | tail_offset += sizeof(acpi_integer); |
| 107 | break; |
| 108 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | size_required += |
| 110 | sizeof(char *) + sizeof(acpi_integer) + |
| 111 | sizeof(char); |
| 112 | tail_offset += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | break; |
| 114 | default: |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 115 | printk(KERN_WARNING PREFIX "Invalid package element" |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 116 | " [%d]: got number, expecing" |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 117 | " [%c]\n", |
| 118 | i, format_string[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return_ACPI_STATUS(AE_BAD_DATA); |
| 120 | break; |
| 121 | } |
| 122 | break; |
| 123 | |
| 124 | case ACPI_TYPE_STRING: |
| 125 | case ACPI_TYPE_BUFFER: |
| 126 | switch (format_string[i]) { |
| 127 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | size_required += |
| 129 | sizeof(char *) + |
| 130 | (element->string.length * sizeof(char)) + |
| 131 | sizeof(char); |
| 132 | tail_offset += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | break; |
| 134 | case 'B': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | size_required += |
| 136 | sizeof(u8 *) + |
| 137 | (element->buffer.length * sizeof(u8)); |
| 138 | tail_offset += sizeof(u8 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | break; |
| 140 | default: |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 141 | printk(KERN_WARNING PREFIX "Invalid package element" |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 142 | " [%d] got string/buffer," |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 143 | " expecing [%c]\n", |
| 144 | i, format_string[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | return_ACPI_STATUS(AE_BAD_DATA); |
| 146 | break; |
| 147 | } |
| 148 | break; |
| 149 | |
| 150 | case ACPI_TYPE_PACKAGE: |
| 151 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 153 | "Found unsupported element at index=%d\n", |
| 154 | i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* TBD: handle nested packages... */ |
| 156 | return_ACPI_STATUS(AE_SUPPORT); |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Validate output buffer. |
| 163 | */ |
| 164 | if (buffer->length < size_required) { |
| 165 | buffer->length = size_required; |
| 166 | return_ACPI_STATUS(AE_BUFFER_OVERFLOW); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | } else if (buffer->length != size_required || !buffer->pointer) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 169 | } |
| 170 | |
| 171 | head = buffer->pointer; |
| 172 | tail = buffer->pointer + tail_offset; |
| 173 | |
| 174 | /* |
| 175 | * Extract package data. |
| 176 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | for (i = 0; i < format_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | u8 **pointer = NULL; |
| 180 | union acpi_object *element = &(package->package.elements[i]); |
| 181 | |
| 182 | if (!element) { |
| 183 | return_ACPI_STATUS(AE_BAD_DATA); |
| 184 | } |
| 185 | |
| 186 | switch (element->type) { |
| 187 | |
| 188 | case ACPI_TYPE_INTEGER: |
| 189 | switch (format_string[i]) { |
| 190 | case 'N': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | *((acpi_integer *) head) = |
| 192 | element->integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | head += sizeof(acpi_integer); |
| 194 | break; |
| 195 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | *pointer = tail; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | *((acpi_integer *) tail) = |
| 199 | element->integer.value; |
| 200 | head += sizeof(acpi_integer *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | tail += sizeof(acpi_integer); |
| 202 | /* NULL terminate string */ |
| 203 | *tail = (char)0; |
| 204 | tail += sizeof(char); |
| 205 | break; |
| 206 | default: |
| 207 | /* Should never get here */ |
| 208 | break; |
| 209 | } |
| 210 | break; |
| 211 | |
| 212 | case ACPI_TYPE_STRING: |
| 213 | case ACPI_TYPE_BUFFER: |
| 214 | switch (format_string[i]) { |
| 215 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | *pointer = tail; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | memcpy(tail, element->string.pointer, |
| 219 | element->string.length); |
| 220 | head += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | tail += element->string.length * sizeof(char); |
| 222 | /* NULL terminate string */ |
| 223 | *tail = (char)0; |
| 224 | tail += sizeof(char); |
| 225 | break; |
| 226 | case 'B': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | *pointer = tail; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | memcpy(tail, element->buffer.pointer, |
| 230 | element->buffer.length); |
| 231 | head += sizeof(u8 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | tail += element->buffer.length * sizeof(u8); |
| 233 | break; |
| 234 | default: |
| 235 | /* Should never get here */ |
| 236 | break; |
| 237 | } |
| 238 | break; |
| 239 | |
| 240 | case ACPI_TYPE_PACKAGE: |
| 241 | /* TBD: handle nested packages... */ |
| 242 | default: |
| 243 | /* Should never get here */ |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return_ACPI_STATUS(AE_OK); |
| 249 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | EXPORT_SYMBOL(acpi_extract_package); |
| 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | acpi_evaluate_integer(acpi_handle handle, |
| 255 | acpi_string pathname, |
| 256 | struct acpi_object_list *arguments, unsigned long *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | acpi_status status = AE_OK; |
| 259 | union acpi_object *element; |
| 260 | struct acpi_buffer buffer = { 0, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | ACPI_FUNCTION_TRACE("acpi_evaluate_integer"); |
| 263 | |
| 264 | if (!data) |
| 265 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 266 | |
| 267 | element = kmalloc(sizeof(union acpi_object), GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 268 | if (!element) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 270 | |
| 271 | memset(element, 0, sizeof(union acpi_object)); |
| 272 | buffer.length = sizeof(union acpi_object); |
| 273 | buffer.pointer = element; |
| 274 | status = acpi_evaluate_object(handle, pathname, arguments, &buffer); |
| 275 | if (ACPI_FAILURE(status)) { |
| 276 | acpi_util_eval_error(handle, pathname, status); |
Vasily Averin | 64385f2 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 277 | kfree(element); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | return_ACPI_STATUS(status); |
| 279 | } |
| 280 | |
| 281 | if (element->type != ACPI_TYPE_INTEGER) { |
| 282 | acpi_util_eval_error(handle, pathname, AE_BAD_DATA); |
Vasily Averin | 64385f2 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 283 | kfree(element); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | return_ACPI_STATUS(AE_BAD_DATA); |
| 285 | } |
| 286 | |
| 287 | *data = element->integer.value; |
| 288 | kfree(element); |
| 289 | |
| 290 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%lu]\n", *data)); |
| 291 | |
| 292 | return_ACPI_STATUS(AE_OK); |
| 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 295 | EXPORT_SYMBOL(acpi_evaluate_integer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | #if 0 |
| 298 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | acpi_evaluate_string(acpi_handle handle, |
| 300 | acpi_string pathname, |
| 301 | acpi_object_list * arguments, acpi_string * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 303 | acpi_status status = AE_OK; |
| 304 | acpi_object *element = NULL; |
| 305 | acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 307 | ACPI_FUNCTION_TRACE("acpi_evaluate_string"); |
| 308 | |
| 309 | if (!data) |
| 310 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 311 | |
| 312 | status = acpi_evaluate_object(handle, pathname, arguments, &buffer); |
| 313 | if (ACPI_FAILURE(status)) { |
| 314 | acpi_util_eval_error(handle, pathname, status); |
| 315 | return_ACPI_STATUS(status); |
| 316 | } |
| 317 | |
| 318 | element = (acpi_object *) buffer.pointer; |
| 319 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | if ((element->type != ACPI_TYPE_STRING) |
| 321 | || (element->type != ACPI_TYPE_BUFFER) |
| 322 | || !element->string.length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | acpi_util_eval_error(handle, pathname, AE_BAD_DATA); |
| 324 | return_ACPI_STATUS(AE_BAD_DATA); |
| 325 | } |
| 326 | |
| 327 | *data = kmalloc(element->string.length + 1, GFP_KERNEL); |
| 328 | if (!data) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame^] | 329 | printk(KERN_ERR PREFIX "Memory allocation\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return_VALUE(-ENOMEM); |
| 331 | } |
| 332 | memset(*data, 0, element->string.length + 1); |
| 333 | |
| 334 | memcpy(*data, element->string.pointer, element->string.length); |
| 335 | |
| 336 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data)); |
| 337 | |
| 338 | acpi_os_free(buffer.pointer); |
| 339 | |
| 340 | return_ACPI_STATUS(AE_OK); |
| 341 | } |
| 342 | #endif |
| 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | acpi_evaluate_reference(acpi_handle handle, |
| 346 | acpi_string pathname, |
| 347 | struct acpi_object_list *arguments, |
| 348 | struct acpi_handle_list *list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | acpi_status status = AE_OK; |
| 351 | union acpi_object *package = NULL; |
| 352 | union acpi_object *element = NULL; |
| 353 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 354 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | ACPI_FUNCTION_TRACE("acpi_evaluate_reference"); |
| 357 | |
| 358 | if (!list) { |
| 359 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 360 | } |
| 361 | |
| 362 | /* Evaluate object. */ |
| 363 | |
| 364 | status = acpi_evaluate_object(handle, pathname, arguments, &buffer); |
| 365 | if (ACPI_FAILURE(status)) |
| 366 | goto end; |
| 367 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | package = (union acpi_object *)buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | if ((buffer.length == 0) || !package) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame^] | 371 | printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n", |
| 372 | (unsigned)buffer.length, package); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | status = AE_BAD_DATA; |
| 374 | acpi_util_eval_error(handle, pathname, status); |
| 375 | goto end; |
| 376 | } |
| 377 | if (package->type != ACPI_TYPE_PACKAGE) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame^] | 378 | printk(KERN_ERR PREFIX "Expecting a [Package], found type %X\n", |
| 379 | package->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | status = AE_BAD_DATA; |
| 381 | acpi_util_eval_error(handle, pathname, status); |
| 382 | goto end; |
| 383 | } |
| 384 | if (!package->package.count) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame^] | 385 | printk(KERN_ERR PREFIX "[Package] has zero elements (%p)\n", |
| 386 | package); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | status = AE_BAD_DATA; |
| 388 | acpi_util_eval_error(handle, pathname, status); |
| 389 | goto end; |
| 390 | } |
| 391 | |
| 392 | if (package->package.count > ACPI_MAX_HANDLES) { |
| 393 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 394 | } |
| 395 | list->count = package->package.count; |
| 396 | |
| 397 | /* Extract package data. */ |
| 398 | |
| 399 | for (i = 0; i < list->count; i++) { |
| 400 | |
| 401 | element = &(package->package.elements[i]); |
| 402 | |
| 403 | if (element->type != ACPI_TYPE_ANY) { |
| 404 | status = AE_BAD_DATA; |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame^] | 405 | printk(KERN_ERR PREFIX |
| 406 | "Expecting a [Reference] package element, found type %X\n", |
| 407 | element->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | acpi_util_eval_error(handle, pathname, status); |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | /* Get the acpi_handle. */ |
| 413 | |
| 414 | list->handles[i] = element->reference.handle; |
| 415 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | list->handles[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 419 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | if (ACPI_FAILURE(status)) { |
| 421 | list->count = 0; |
| 422 | //kfree(list->handles); |
| 423 | } |
| 424 | |
| 425 | acpi_os_free(buffer.pointer); |
| 426 | |
| 427 | return_ACPI_STATUS(status); |
| 428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 430 | EXPORT_SYMBOL(acpi_evaluate_reference); |