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 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 33 | #include "internal.h" |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define _COMPONENT ACPI_BUS_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 36 | ACPI_MODULE_NAME("utils"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* -------------------------------------------------------------------------- |
| 39 | Object Evaluation Helpers |
| 40 | -------------------------------------------------------------------------- */ |
Harvey Harrison | 4fd7f51 | 2008-02-15 17:07:19 -0800 | [diff] [blame] | 41 | static void |
| 42 | acpi_util_eval_error(acpi_handle h, acpi_string p, acpi_status s) |
| 43 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #ifdef ACPI_DEBUG_OUTPUT |
Harvey Harrison | 4fd7f51 | 2008-02-15 17:07:19 -0800 | [diff] [blame] | 45 | char prefix[80] = {'\0'}; |
| 46 | struct acpi_buffer buffer = {sizeof(prefix), prefix}; |
| 47 | acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer); |
| 48 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate [%s.%s]: %s\n", |
| 49 | (char *) prefix, p, acpi_format_exception(s))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #else |
Harvey Harrison | 4fd7f51 | 2008-02-15 17:07:19 -0800 | [diff] [blame] | 51 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #endif |
Harvey Harrison | 4fd7f51 | 2008-02-15 17:07:19 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | acpi_extract_package(union acpi_object *package, |
| 57 | struct acpi_buffer *format, struct acpi_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 59 | u32 size_required = 0; |
| 60 | u32 tail_offset = 0; |
| 61 | char *format_string = NULL; |
| 62 | u32 format_count = 0; |
| 63 | u32 i = 0; |
| 64 | u8 *head = NULL; |
| 65 | u8 *tail = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 68 | if (!package || (package->type != ACPI_TYPE_PACKAGE) |
| 69 | || (package->package.count < 1)) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 70 | printk(KERN_WARNING PREFIX "Invalid package argument\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 71 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | if (!format || !format->pointer || (format->length < 1)) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 75 | printk(KERN_WARNING PREFIX "Invalid format argument\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 76 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | if (!buffer) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 80 | printk(KERN_WARNING PREFIX "Invalid buffer argument\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 81 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | format_count = (format->length / sizeof(char)) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if (format_count > package->package.count) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 86 | printk(KERN_WARNING PREFIX "Format specifies more objects [%d]" |
| 87 | " than exist in package [%d].\n", |
| 88 | format_count, package->package.count); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 89 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 92 | format_string = format->pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Calculate size_required. |
| 96 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | for (i = 0; i < format_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | union acpi_object *element = &(package->package.elements[i]); |
| 100 | |
| 101 | if (!element) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 102 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | switch (element->type) { |
| 106 | |
| 107 | case ACPI_TYPE_INTEGER: |
| 108 | switch (format_string[i]) { |
| 109 | case 'N': |
| 110 | size_required += sizeof(acpi_integer); |
| 111 | tail_offset += sizeof(acpi_integer); |
| 112 | break; |
| 113 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | size_required += |
| 115 | sizeof(char *) + sizeof(acpi_integer) + |
| 116 | sizeof(char); |
| 117 | tail_offset += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | break; |
| 119 | default: |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 120 | printk(KERN_WARNING PREFIX "Invalid package element" |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 121 | " [%d]: got number, expecing" |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 122 | " [%c]\n", |
| 123 | i, format_string[i]); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 124 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | break; |
| 126 | } |
| 127 | break; |
| 128 | |
| 129 | case ACPI_TYPE_STRING: |
| 130 | case ACPI_TYPE_BUFFER: |
| 131 | switch (format_string[i]) { |
| 132 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | size_required += |
| 134 | sizeof(char *) + |
| 135 | (element->string.length * sizeof(char)) + |
| 136 | sizeof(char); |
| 137 | tail_offset += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | break; |
| 139 | case 'B': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | size_required += |
| 141 | sizeof(u8 *) + |
| 142 | (element->buffer.length * sizeof(u8)); |
| 143 | tail_offset += sizeof(u8 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | break; |
| 145 | default: |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 146 | printk(KERN_WARNING PREFIX "Invalid package element" |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 147 | " [%d] got string/buffer," |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 148 | " expecing [%c]\n", |
| 149 | i, format_string[i]); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 150 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | break; |
| 152 | } |
| 153 | break; |
| 154 | |
| 155 | case ACPI_TYPE_PACKAGE: |
| 156 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 158 | "Found unsupported element at index=%d\n", |
| 159 | i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* TBD: handle nested packages... */ |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 161 | return AE_SUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Validate output buffer. |
| 168 | */ |
| 169 | if (buffer->length < size_required) { |
| 170 | buffer->length = size_required; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 171 | return AE_BUFFER_OVERFLOW; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | } else if (buffer->length != size_required || !buffer->pointer) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 173 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | head = buffer->pointer; |
| 177 | tail = buffer->pointer + tail_offset; |
| 178 | |
| 179 | /* |
| 180 | * Extract package data. |
| 181 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | for (i = 0; i < format_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | u8 **pointer = NULL; |
| 185 | union acpi_object *element = &(package->package.elements[i]); |
| 186 | |
| 187 | if (!element) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 188 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | switch (element->type) { |
| 192 | |
| 193 | case ACPI_TYPE_INTEGER: |
| 194 | switch (format_string[i]) { |
| 195 | case 'N': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | *((acpi_integer *) head) = |
| 197 | element->integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | head += sizeof(acpi_integer); |
| 199 | break; |
| 200 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | *pointer = tail; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | *((acpi_integer *) tail) = |
| 204 | element->integer.value; |
| 205 | head += sizeof(acpi_integer *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | tail += sizeof(acpi_integer); |
| 207 | /* NULL terminate string */ |
| 208 | *tail = (char)0; |
| 209 | tail += sizeof(char); |
| 210 | break; |
| 211 | default: |
| 212 | /* Should never get here */ |
| 213 | break; |
| 214 | } |
| 215 | break; |
| 216 | |
| 217 | case ACPI_TYPE_STRING: |
| 218 | case ACPI_TYPE_BUFFER: |
| 219 | switch (format_string[i]) { |
| 220 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | *pointer = tail; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | memcpy(tail, element->string.pointer, |
| 224 | element->string.length); |
| 225 | head += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | tail += element->string.length * sizeof(char); |
| 227 | /* NULL terminate string */ |
| 228 | *tail = (char)0; |
| 229 | tail += sizeof(char); |
| 230 | break; |
| 231 | case 'B': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | *pointer = tail; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 234 | memcpy(tail, element->buffer.pointer, |
| 235 | element->buffer.length); |
| 236 | head += sizeof(u8 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | tail += element->buffer.length * sizeof(u8); |
| 238 | break; |
| 239 | default: |
| 240 | /* Should never get here */ |
| 241 | break; |
| 242 | } |
| 243 | break; |
| 244 | |
| 245 | case ACPI_TYPE_PACKAGE: |
| 246 | /* TBD: handle nested packages... */ |
| 247 | default: |
| 248 | /* Should never get here */ |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 253 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | EXPORT_SYMBOL(acpi_extract_package); |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | acpi_evaluate_integer(acpi_handle handle, |
| 260 | acpi_string pathname, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 261 | struct acpi_object_list *arguments, unsigned long long *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | acpi_status status = AE_OK; |
Pavel Machek | 4059907 | 2008-11-25 12:05:08 +0100 | [diff] [blame] | 264 | union acpi_object element; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | struct acpi_buffer buffer = { 0, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | if (!data) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 268 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | buffer.length = sizeof(union acpi_object); |
Pavel Machek | 4059907 | 2008-11-25 12:05:08 +0100 | [diff] [blame] | 271 | buffer.pointer = &element; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | status = acpi_evaluate_object(handle, pathname, arguments, &buffer); |
| 273 | if (ACPI_FAILURE(status)) { |
| 274 | acpi_util_eval_error(handle, pathname, status); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 275 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Pavel Machek | 4059907 | 2008-11-25 12:05:08 +0100 | [diff] [blame] | 278 | if (element.type != ACPI_TYPE_INTEGER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | acpi_util_eval_error(handle, pathname, AE_BAD_DATA); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 280 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Pavel Machek | 4059907 | 2008-11-25 12:05:08 +0100 | [diff] [blame] | 283 | *data = element.integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 285 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%llu]\n", *data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 287 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 290 | EXPORT_SYMBOL(acpi_evaluate_integer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | #if 0 |
| 293 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | acpi_evaluate_string(acpi_handle handle, |
| 295 | acpi_string pathname, |
| 296 | acpi_object_list * arguments, acpi_string * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | acpi_status status = AE_OK; |
| 299 | acpi_object *element = NULL; |
| 300 | acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | if (!data) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 304 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | status = acpi_evaluate_object(handle, pathname, arguments, &buffer); |
| 307 | if (ACPI_FAILURE(status)) { |
| 308 | acpi_util_eval_error(handle, pathname, status); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 309 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | element = (acpi_object *) buffer.pointer; |
| 313 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | if ((element->type != ACPI_TYPE_STRING) |
| 315 | || (element->type != ACPI_TYPE_BUFFER) |
| 316 | || !element->string.length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | acpi_util_eval_error(handle, pathname, AE_BAD_DATA); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 318 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 321 | *data = kzalloc(element->string.length + 1, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (!data) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 323 | printk(KERN_ERR PREFIX "Memory allocation\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 324 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | memcpy(*data, element->string.pointer, element->string.length); |
| 328 | |
| 329 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data)); |
| 330 | |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 331 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 333 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | #endif |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | acpi_evaluate_reference(acpi_handle handle, |
| 339 | acpi_string pathname, |
| 340 | struct acpi_object_list *arguments, |
| 341 | struct acpi_handle_list *list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | acpi_status status = AE_OK; |
| 344 | union acpi_object *package = NULL; |
| 345 | union acpi_object *element = NULL; |
| 346 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 347 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | if (!list) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 351 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /* Evaluate object. */ |
| 355 | |
| 356 | status = acpi_evaluate_object(handle, pathname, arguments, &buffer); |
| 357 | if (ACPI_FAILURE(status)) |
| 358 | goto end; |
| 359 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 360 | package = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | if ((buffer.length == 0) || !package) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 363 | printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n", |
| 364 | (unsigned)buffer.length, package); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | status = AE_BAD_DATA; |
| 366 | acpi_util_eval_error(handle, pathname, status); |
| 367 | goto end; |
| 368 | } |
| 369 | if (package->type != ACPI_TYPE_PACKAGE) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 370 | printk(KERN_ERR PREFIX "Expecting a [Package], found type %X\n", |
| 371 | package->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | status = AE_BAD_DATA; |
| 373 | acpi_util_eval_error(handle, pathname, status); |
| 374 | goto end; |
| 375 | } |
| 376 | if (!package->package.count) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 377 | printk(KERN_ERR PREFIX "[Package] has zero elements (%p)\n", |
| 378 | package); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | status = AE_BAD_DATA; |
| 380 | acpi_util_eval_error(handle, pathname, status); |
| 381 | goto end; |
| 382 | } |
| 383 | |
| 384 | if (package->package.count > ACPI_MAX_HANDLES) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 385 | return AE_NO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | list->count = package->package.count; |
| 388 | |
| 389 | /* Extract package data. */ |
| 390 | |
| 391 | for (i = 0; i < list->count; i++) { |
| 392 | |
| 393 | element = &(package->package.elements[i]); |
| 394 | |
Bob Moore | cd0b224 | 2008-04-10 19:06:43 +0400 | [diff] [blame] | 395 | if (element->type != ACPI_TYPE_LOCAL_REFERENCE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | status = AE_BAD_DATA; |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 397 | printk(KERN_ERR PREFIX |
| 398 | "Expecting a [Reference] package element, found type %X\n", |
| 399 | element->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | acpi_util_eval_error(handle, pathname, status); |
| 401 | break; |
| 402 | } |
| 403 | |
Thomas Renninger | b6a1638 | 2008-03-12 01:06:24 +0100 | [diff] [blame] | 404 | if (!element->reference.handle) { |
| 405 | printk(KERN_WARNING PREFIX "Invalid reference in" |
| 406 | " package %s\n", pathname); |
| 407 | status = AE_NULL_ENTRY; |
| 408 | break; |
| 409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /* Get the acpi_handle. */ |
| 411 | |
| 412 | list->handles[i] = element->reference.handle; |
| 413 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | list->handles[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | if (ACPI_FAILURE(status)) { |
| 419 | list->count = 0; |
| 420 | //kfree(list->handles); |
| 421 | } |
| 422 | |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 423 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 425 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | EXPORT_SYMBOL(acpi_evaluate_reference); |