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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/init.h> |
| 30 | #include <linux/types.h> |
Toshi Kani | fbfddae | 2012-11-21 01:36:28 +0000 | [diff] [blame] | 31 | #include <linux/hardirq.h> |
| 32 | #include <linux/acpi.h> |
Bjørn Mork | 45fef5b | 2014-05-22 12:47:47 +0200 | [diff] [blame] | 33 | #include <linux/dynamic_debug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 35 | #include "internal.h" |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define _COMPONENT ACPI_BUS_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 38 | ACPI_MODULE_NAME("utils"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* -------------------------------------------------------------------------- |
| 41 | Object Evaluation Helpers |
| 42 | -------------------------------------------------------------------------- */ |
Harvey Harrison | 4fd7f51 | 2008-02-15 17:07:19 -0800 | [diff] [blame] | 43 | static void |
| 44 | acpi_util_eval_error(acpi_handle h, acpi_string p, acpi_status s) |
| 45 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #ifdef ACPI_DEBUG_OUTPUT |
Harvey Harrison | 4fd7f51 | 2008-02-15 17:07:19 -0800 | [diff] [blame] | 47 | char prefix[80] = {'\0'}; |
| 48 | struct acpi_buffer buffer = {sizeof(prefix), prefix}; |
| 49 | acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer); |
| 50 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate [%s.%s]: %s\n", |
| 51 | (char *) prefix, p, acpi_format_exception(s))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #else |
Harvey Harrison | 4fd7f51 | 2008-02-15 17:07:19 -0800 | [diff] [blame] | 53 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #endif |
Harvey Harrison | 4fd7f51 | 2008-02-15 17:07:19 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 58 | acpi_extract_package(union acpi_object *package, |
| 59 | struct acpi_buffer *format, struct acpi_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 61 | u32 size_required = 0; |
| 62 | u32 tail_offset = 0; |
| 63 | char *format_string = NULL; |
| 64 | u32 format_count = 0; |
| 65 | u32 i = 0; |
| 66 | u8 *head = NULL; |
| 67 | u8 *tail = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | if (!package || (package->type != ACPI_TYPE_PACKAGE) |
| 71 | || (package->package.count < 1)) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 72 | printk(KERN_WARNING PREFIX "Invalid package argument\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 73 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | if (!format || !format->pointer || (format->length < 1)) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 77 | printk(KERN_WARNING PREFIX "Invalid format argument\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 78 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | if (!buffer) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 82 | printk(KERN_WARNING PREFIX "Invalid buffer argument\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 83 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | format_count = (format->length / sizeof(char)) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | if (format_count > package->package.count) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 88 | printk(KERN_WARNING PREFIX "Format specifies more objects [%d]" |
| 89 | " than exist in package [%d].\n", |
| 90 | format_count, package->package.count); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 91 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 94 | format_string = format->pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * Calculate size_required. |
| 98 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | for (i = 0; i < format_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | union acpi_object *element = &(package->package.elements[i]); |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | switch (element->type) { |
| 104 | |
| 105 | case ACPI_TYPE_INTEGER: |
| 106 | switch (format_string[i]) { |
| 107 | case 'N': |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 108 | size_required += sizeof(u64); |
| 109 | tail_offset += sizeof(u64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | break; |
| 111 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | size_required += |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 113 | sizeof(char *) + sizeof(u64) + |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | sizeof(char); |
| 115 | tail_offset += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | break; |
| 117 | default: |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 118 | printk(KERN_WARNING PREFIX "Invalid package element" |
Colin Ian King | e7e92ec9 | 2013-10-29 10:34:19 +0000 | [diff] [blame] | 119 | " [%d]: got number, expecting" |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 120 | " [%c]\n", |
| 121 | i, format_string[i]); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 122 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | break; |
| 124 | } |
| 125 | break; |
| 126 | |
| 127 | case ACPI_TYPE_STRING: |
| 128 | case ACPI_TYPE_BUFFER: |
| 129 | switch (format_string[i]) { |
| 130 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | size_required += |
| 132 | sizeof(char *) + |
| 133 | (element->string.length * sizeof(char)) + |
| 134 | sizeof(char); |
| 135 | tail_offset += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | break; |
| 137 | case 'B': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | size_required += |
| 139 | sizeof(u8 *) + |
| 140 | (element->buffer.length * sizeof(u8)); |
| 141 | tail_offset += sizeof(u8 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | break; |
| 143 | default: |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 144 | printk(KERN_WARNING PREFIX "Invalid package element" |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 145 | " [%d] got string/buffer," |
Colin Ian King | e7e92ec9 | 2013-10-29 10:34:19 +0000 | [diff] [blame] | 146 | " expecting [%c]\n", |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 147 | i, format_string[i]); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 148 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | break; |
Zhang Rui | e3ec483 | 2014-03-16 21:34:16 +0800 | [diff] [blame] | 152 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 153 | switch (format_string[i]) { |
| 154 | case 'R': |
| 155 | size_required += sizeof(void *); |
| 156 | tail_offset += sizeof(void *); |
| 157 | break; |
| 158 | default: |
| 159 | printk(KERN_WARNING PREFIX "Invalid package element" |
| 160 | " [%d] got reference," |
| 161 | " expecting [%c]\n", |
| 162 | i, format_string[i]); |
| 163 | return AE_BAD_DATA; |
| 164 | break; |
| 165 | } |
| 166 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | case ACPI_TYPE_PACKAGE: |
| 169 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 171 | "Found unsupported element at index=%d\n", |
| 172 | i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | /* TBD: handle nested packages... */ |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 174 | return AE_SUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | break; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Validate output buffer. |
| 181 | */ |
Al Stone | e83dda0 | 2013-10-09 14:21:10 -0600 | [diff] [blame] | 182 | if (buffer->length == ACPI_ALLOCATE_BUFFER) { |
jhbird.choi@samsung.com | 2d0acb4 | 2014-03-20 16:35:56 +0900 | [diff] [blame] | 183 | buffer->pointer = ACPI_ALLOCATE_ZEROED(size_required); |
Al Stone | e83dda0 | 2013-10-09 14:21:10 -0600 | [diff] [blame] | 184 | if (!buffer->pointer) |
| 185 | return AE_NO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | buffer->length = size_required; |
Al Stone | e83dda0 | 2013-10-09 14:21:10 -0600 | [diff] [blame] | 187 | } else { |
| 188 | if (buffer->length < size_required) { |
| 189 | buffer->length = size_required; |
| 190 | return AE_BUFFER_OVERFLOW; |
| 191 | } else if (buffer->length != size_required || |
| 192 | !buffer->pointer) { |
| 193 | return AE_BAD_PARAMETER; |
| 194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | head = buffer->pointer; |
| 198 | tail = buffer->pointer + tail_offset; |
| 199 | |
| 200 | /* |
| 201 | * Extract package data. |
| 202 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | for (i = 0; i < format_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | u8 **pointer = NULL; |
| 206 | union acpi_object *element = &(package->package.elements[i]); |
| 207 | |
| 208 | if (!element) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 209 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | switch (element->type) { |
| 213 | |
| 214 | case ACPI_TYPE_INTEGER: |
| 215 | switch (format_string[i]) { |
| 216 | case 'N': |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 217 | *((u64 *) head) = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | element->integer.value; |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 219 | head += sizeof(u64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | break; |
| 221 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | *pointer = tail; |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 224 | *((u64 *) tail) = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | element->integer.value; |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 226 | head += sizeof(u64 *); |
| 227 | tail += sizeof(u64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* NULL terminate string */ |
| 229 | *tail = (char)0; |
| 230 | tail += sizeof(char); |
| 231 | break; |
| 232 | default: |
| 233 | /* Should never get here */ |
| 234 | break; |
| 235 | } |
| 236 | break; |
| 237 | |
| 238 | case ACPI_TYPE_STRING: |
| 239 | case ACPI_TYPE_BUFFER: |
| 240 | switch (format_string[i]) { |
| 241 | case 'S': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | *pointer = tail; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | memcpy(tail, element->string.pointer, |
| 245 | element->string.length); |
| 246 | head += sizeof(char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | tail += element->string.length * sizeof(char); |
| 248 | /* NULL terminate string */ |
| 249 | *tail = (char)0; |
| 250 | tail += sizeof(char); |
| 251 | break; |
| 252 | case 'B': |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | pointer = (u8 **) head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | *pointer = tail; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | memcpy(tail, element->buffer.pointer, |
| 256 | element->buffer.length); |
| 257 | head += sizeof(u8 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | tail += element->buffer.length * sizeof(u8); |
| 259 | break; |
| 260 | default: |
| 261 | /* Should never get here */ |
| 262 | break; |
| 263 | } |
| 264 | break; |
Zhang Rui | e3ec483 | 2014-03-16 21:34:16 +0800 | [diff] [blame] | 265 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 266 | switch (format_string[i]) { |
| 267 | case 'R': |
| 268 | *(void **)head = |
| 269 | (void *)element->reference.handle; |
| 270 | head += sizeof(void *); |
| 271 | break; |
| 272 | default: |
| 273 | /* Should never get here */ |
| 274 | break; |
| 275 | } |
| 276 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | case ACPI_TYPE_PACKAGE: |
| 278 | /* TBD: handle nested packages... */ |
| 279 | default: |
| 280 | /* Should never get here */ |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 285 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | EXPORT_SYMBOL(acpi_extract_package); |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | acpi_evaluate_integer(acpi_handle handle, |
| 292 | acpi_string pathname, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 293 | struct acpi_object_list *arguments, unsigned long long *data) |
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 | acpi_status status = AE_OK; |
Pavel Machek | 4059907 | 2008-11-25 12:05:08 +0100 | [diff] [blame] | 296 | union acpi_object element; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | struct acpi_buffer buffer = { 0, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | if (!data) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 300 | return AE_BAD_PARAMETER; |
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 | buffer.length = sizeof(union acpi_object); |
Pavel Machek | 4059907 | 2008-11-25 12:05:08 +0100 | [diff] [blame] | 303 | buffer.pointer = &element; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | status = acpi_evaluate_object(handle, pathname, arguments, &buffer); |
| 305 | if (ACPI_FAILURE(status)) { |
| 306 | acpi_util_eval_error(handle, pathname, status); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 307 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Pavel Machek | 4059907 | 2008-11-25 12:05:08 +0100 | [diff] [blame] | 310 | if (element.type != ACPI_TYPE_INTEGER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | acpi_util_eval_error(handle, pathname, AE_BAD_DATA); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 312 | return AE_BAD_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Pavel Machek | 4059907 | 2008-11-25 12:05:08 +0100 | [diff] [blame] | 315 | *data = element.integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 317 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%llu]\n", *data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 319 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | EXPORT_SYMBOL(acpi_evaluate_integer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | acpi_evaluate_reference(acpi_handle handle, |
| 326 | acpi_string pathname, |
| 327 | struct acpi_object_list *arguments, |
| 328 | struct acpi_handle_list *list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | acpi_status status = AE_OK; |
| 331 | union acpi_object *package = NULL; |
| 332 | union acpi_object *element = NULL; |
| 333 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 334 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | if (!list) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 338 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /* Evaluate object. */ |
| 342 | |
| 343 | status = acpi_evaluate_object(handle, pathname, arguments, &buffer); |
| 344 | if (ACPI_FAILURE(status)) |
| 345 | goto end; |
| 346 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 347 | package = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | if ((buffer.length == 0) || !package) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 350 | printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n", |
| 351 | (unsigned)buffer.length, package); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | status = AE_BAD_DATA; |
| 353 | acpi_util_eval_error(handle, pathname, status); |
| 354 | goto end; |
| 355 | } |
| 356 | if (package->type != ACPI_TYPE_PACKAGE) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 357 | printk(KERN_ERR PREFIX "Expecting a [Package], found type %X\n", |
| 358 | package->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | status = AE_BAD_DATA; |
| 360 | acpi_util_eval_error(handle, pathname, status); |
| 361 | goto end; |
| 362 | } |
| 363 | if (!package->package.count) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 364 | printk(KERN_ERR PREFIX "[Package] has zero elements (%p)\n", |
| 365 | package); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | status = AE_BAD_DATA; |
| 367 | acpi_util_eval_error(handle, pathname, status); |
| 368 | goto end; |
| 369 | } |
| 370 | |
| 371 | if (package->package.count > ACPI_MAX_HANDLES) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 372 | return AE_NO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | list->count = package->package.count; |
| 375 | |
| 376 | /* Extract package data. */ |
| 377 | |
| 378 | for (i = 0; i < list->count; i++) { |
| 379 | |
| 380 | element = &(package->package.elements[i]); |
| 381 | |
Bob Moore | cd0b224 | 2008-04-10 19:06:43 +0400 | [diff] [blame] | 382 | if (element->type != ACPI_TYPE_LOCAL_REFERENCE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | status = AE_BAD_DATA; |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 384 | printk(KERN_ERR PREFIX |
| 385 | "Expecting a [Reference] package element, found type %X\n", |
| 386 | element->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | acpi_util_eval_error(handle, pathname, status); |
| 388 | break; |
| 389 | } |
| 390 | |
Thomas Renninger | b6a1638 | 2008-03-12 01:06:24 +0100 | [diff] [blame] | 391 | if (!element->reference.handle) { |
| 392 | printk(KERN_WARNING PREFIX "Invalid reference in" |
| 393 | " package %s\n", pathname); |
| 394 | status = AE_NULL_ENTRY; |
| 395 | break; |
| 396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | /* Get the acpi_handle. */ |
| 398 | |
| 399 | list->handles[i] = element->reference.handle; |
| 400 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 401 | list->handles[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | if (ACPI_FAILURE(status)) { |
| 406 | list->count = 0; |
| 407 | //kfree(list->handles); |
| 408 | } |
| 409 | |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 410 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 412 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 415 | EXPORT_SYMBOL(acpi_evaluate_reference); |
Matthew Garrett | 38ac0f1 | 2012-05-11 16:08:26 +0800 | [diff] [blame] | 416 | |
| 417 | acpi_status |
Feng Tang | 8ede06a | 2012-08-21 09:56:58 +0800 | [diff] [blame] | 418 | acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld) |
Matthew Garrett | 38ac0f1 | 2012-05-11 16:08:26 +0800 | [diff] [blame] | 419 | { |
| 420 | acpi_status status; |
| 421 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 422 | union acpi_object *output; |
| 423 | |
| 424 | status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer); |
| 425 | |
| 426 | if (ACPI_FAILURE(status)) |
| 427 | return status; |
| 428 | |
| 429 | output = buffer.pointer; |
| 430 | |
| 431 | if (!output || output->type != ACPI_TYPE_PACKAGE |
| 432 | || !output->package.count |
| 433 | || output->package.elements[0].type != ACPI_TYPE_BUFFER |
Feng Tang | 8ede06a | 2012-08-21 09:56:58 +0800 | [diff] [blame] | 434 | || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) { |
Matthew Garrett | 38ac0f1 | 2012-05-11 16:08:26 +0800 | [diff] [blame] | 435 | status = AE_TYPE; |
| 436 | goto out; |
| 437 | } |
| 438 | |
Feng Tang | 8ede06a | 2012-08-21 09:56:58 +0800 | [diff] [blame] | 439 | status = acpi_decode_pld_buffer( |
| 440 | output->package.elements[0].buffer.pointer, |
| 441 | output->package.elements[0].buffer.length, |
| 442 | pld); |
| 443 | |
Matthew Garrett | 38ac0f1 | 2012-05-11 16:08:26 +0800 | [diff] [blame] | 444 | out: |
| 445 | kfree(buffer.pointer); |
| 446 | return status; |
| 447 | } |
| 448 | EXPORT_SYMBOL(acpi_get_physical_device_location); |
Toshi Kani | 275c58d | 2012-05-23 20:25:19 -0600 | [diff] [blame] | 449 | |
| 450 | /** |
Rafael J. Wysocki | 700b842 | 2014-02-21 01:07:17 +0100 | [diff] [blame] | 451 | * acpi_evaluate_ost: Evaluate _OST for hotplug operations |
Toshi Kani | 275c58d | 2012-05-23 20:25:19 -0600 | [diff] [blame] | 452 | * @handle: ACPI device handle |
| 453 | * @source_event: source event code |
| 454 | * @status_code: status code |
| 455 | * @status_buf: optional detailed information (NULL if none) |
| 456 | * |
| 457 | * Evaluate _OST for hotplug operations. All ACPI hotplug handlers |
| 458 | * must call this function when evaluating _OST for hotplug operations. |
| 459 | * When the platform does not support _OST, this function has no effect. |
| 460 | */ |
| 461 | acpi_status |
Jiang Liu | 05730c1 | 2014-02-19 14:02:15 +0800 | [diff] [blame] | 462 | acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code, |
| 463 | struct acpi_buffer *status_buf) |
Toshi Kani | 275c58d | 2012-05-23 20:25:19 -0600 | [diff] [blame] | 464 | { |
Toshi Kani | 275c58d | 2012-05-23 20:25:19 -0600 | [diff] [blame] | 465 | union acpi_object params[3] = { |
| 466 | {.type = ACPI_TYPE_INTEGER,}, |
| 467 | {.type = ACPI_TYPE_INTEGER,}, |
| 468 | {.type = ACPI_TYPE_BUFFER,} |
| 469 | }; |
| 470 | struct acpi_object_list arg_list = {3, params}; |
Toshi Kani | 275c58d | 2012-05-23 20:25:19 -0600 | [diff] [blame] | 471 | |
| 472 | params[0].integer.value = source_event; |
| 473 | params[1].integer.value = status_code; |
| 474 | if (status_buf != NULL) { |
| 475 | params[2].buffer.pointer = status_buf->pointer; |
| 476 | params[2].buffer.length = status_buf->length; |
| 477 | } else { |
| 478 | params[2].buffer.pointer = NULL; |
| 479 | params[2].buffer.length = 0; |
| 480 | } |
| 481 | |
Jiang Liu | 05730c1 | 2014-02-19 14:02:15 +0800 | [diff] [blame] | 482 | return acpi_evaluate_object(handle, "_OST", &arg_list, NULL); |
Toshi Kani | 275c58d | 2012-05-23 20:25:19 -0600 | [diff] [blame] | 483 | } |
Jiang Liu | 05730c1 | 2014-02-19 14:02:15 +0800 | [diff] [blame] | 484 | EXPORT_SYMBOL(acpi_evaluate_ost); |
Toshi Kani | fbfddae | 2012-11-21 01:36:28 +0000 | [diff] [blame] | 485 | |
| 486 | /** |
Bjørn Mork | 45fef5b | 2014-05-22 12:47:47 +0200 | [diff] [blame] | 487 | * acpi_handle_path: Return the object path of handle |
| 488 | * |
| 489 | * Caller must free the returned buffer |
| 490 | */ |
| 491 | static char *acpi_handle_path(acpi_handle handle) |
| 492 | { |
| 493 | struct acpi_buffer buffer = { |
| 494 | .length = ACPI_ALLOCATE_BUFFER, |
| 495 | .pointer = NULL |
| 496 | }; |
| 497 | |
| 498 | if (in_interrupt() || |
| 499 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK) |
| 500 | return NULL; |
| 501 | return buffer.pointer; |
| 502 | } |
| 503 | |
| 504 | /** |
Toshi Kani | fbfddae | 2012-11-21 01:36:28 +0000 | [diff] [blame] | 505 | * acpi_handle_printk: Print message with ACPI prefix and object path |
| 506 | * |
| 507 | * This function is called through acpi_handle_<level> macros and prints |
| 508 | * a message with ACPI prefix and object path. This function acquires |
| 509 | * the global namespace mutex to obtain an object path. In interrupt |
| 510 | * context, it shows the object path as <n/a>. |
| 511 | */ |
| 512 | void |
| 513 | acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...) |
| 514 | { |
| 515 | struct va_format vaf; |
| 516 | va_list args; |
Toshi Kani | fbfddae | 2012-11-21 01:36:28 +0000 | [diff] [blame] | 517 | const char *path; |
| 518 | |
| 519 | va_start(args, fmt); |
| 520 | vaf.fmt = fmt; |
| 521 | vaf.va = &args; |
| 522 | |
Bjørn Mork | 45fef5b | 2014-05-22 12:47:47 +0200 | [diff] [blame] | 523 | path = acpi_handle_path(handle); |
| 524 | printk("%sACPI: %s: %pV", level, path ? path : "<n/a>" , &vaf); |
Toshi Kani | fbfddae | 2012-11-21 01:36:28 +0000 | [diff] [blame] | 525 | |
| 526 | va_end(args); |
Bjørn Mork | 45fef5b | 2014-05-22 12:47:47 +0200 | [diff] [blame] | 527 | kfree(path); |
Toshi Kani | fbfddae | 2012-11-21 01:36:28 +0000 | [diff] [blame] | 528 | } |
| 529 | EXPORT_SYMBOL(acpi_handle_printk); |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 530 | |
Bjørn Mork | 45fef5b | 2014-05-22 12:47:47 +0200 | [diff] [blame] | 531 | #if defined(CONFIG_DYNAMIC_DEBUG) |
| 532 | /** |
| 533 | * __acpi_handle_debug: pr_debug with ACPI prefix and object path |
| 534 | * |
| 535 | * This function is called through acpi_handle_debug macro and debug |
| 536 | * prints a message with ACPI prefix and object path. This function |
| 537 | * acquires the global namespace mutex to obtain an object path. In |
| 538 | * interrupt context, it shows the object path as <n/a>. |
| 539 | */ |
| 540 | void |
| 541 | __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, |
| 542 | const char *fmt, ...) |
| 543 | { |
| 544 | struct va_format vaf; |
| 545 | va_list args; |
| 546 | const char *path; |
| 547 | |
| 548 | va_start(args, fmt); |
| 549 | vaf.fmt = fmt; |
| 550 | vaf.va = &args; |
| 551 | |
| 552 | path = acpi_handle_path(handle); |
| 553 | __dynamic_pr_debug(descriptor, "ACPI: %s: %pV", path ? path : "<n/a>", &vaf); |
| 554 | |
| 555 | va_end(args); |
| 556 | kfree(path); |
| 557 | } |
| 558 | EXPORT_SYMBOL(__acpi_handle_debug); |
| 559 | #endif |
| 560 | |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 561 | /** |
| 562 | * acpi_has_method: Check whether @handle has a method named @name |
| 563 | * @handle: ACPI device handle |
| 564 | * @name: name of object or method |
| 565 | * |
| 566 | * Check whether @handle has a method named @name. |
| 567 | */ |
| 568 | bool acpi_has_method(acpi_handle handle, char *name) |
| 569 | { |
| 570 | acpi_handle tmp; |
| 571 | |
| 572 | return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp)); |
| 573 | } |
| 574 | EXPORT_SYMBOL(acpi_has_method); |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 575 | |
| 576 | acpi_status acpi_execute_simple_method(acpi_handle handle, char *method, |
| 577 | u64 arg) |
| 578 | { |
| 579 | union acpi_object obj = { .type = ACPI_TYPE_INTEGER }; |
| 580 | struct acpi_object_list arg_list = { .count = 1, .pointer = &obj, }; |
| 581 | |
| 582 | obj.integer.value = arg; |
| 583 | |
| 584 | return acpi_evaluate_object(handle, method, &arg_list, NULL); |
| 585 | } |
| 586 | EXPORT_SYMBOL(acpi_execute_simple_method); |
Jiang Liu | 7d2421f | 2013-06-29 00:24:40 +0800 | [diff] [blame] | 587 | |
| 588 | /** |
| 589 | * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations |
| 590 | * @handle: ACPI device handle |
| 591 | * |
| 592 | * Evaluate device's _EJ0 method for hotplug operations. |
| 593 | */ |
| 594 | acpi_status acpi_evaluate_ej0(acpi_handle handle) |
| 595 | { |
| 596 | acpi_status status; |
| 597 | |
| 598 | status = acpi_execute_simple_method(handle, "_EJ0", 1); |
| 599 | if (status == AE_NOT_FOUND) |
| 600 | acpi_handle_warn(handle, "No _EJ0 support for device\n"); |
| 601 | else if (ACPI_FAILURE(status)) |
| 602 | acpi_handle_warn(handle, "Eject failed (0x%x)\n", status); |
| 603 | |
| 604 | return status; |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device |
| 609 | * @handle: ACPI device handle |
| 610 | * @lock: lock device if non-zero, otherwise unlock device |
| 611 | * |
| 612 | * Evaluate device's _LCK method if present to lock/unlock device |
| 613 | */ |
| 614 | acpi_status acpi_evaluate_lck(acpi_handle handle, int lock) |
| 615 | { |
| 616 | acpi_status status; |
| 617 | |
| 618 | status = acpi_execute_simple_method(handle, "_LCK", !!lock); |
| 619 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 620 | if (lock) |
| 621 | acpi_handle_warn(handle, |
| 622 | "Locking device failed (0x%x)\n", status); |
| 623 | else |
| 624 | acpi_handle_warn(handle, |
| 625 | "Unlocking device failed (0x%x)\n", status); |
| 626 | } |
| 627 | |
| 628 | return status; |
| 629 | } |
Jiang Liu | a65ac52 | 2013-12-19 20:38:10 +0800 | [diff] [blame] | 630 | |
| 631 | /** |
| 632 | * acpi_evaluate_dsm - evaluate device's _DSM method |
| 633 | * @handle: ACPI device handle |
| 634 | * @uuid: UUID of requested functions, should be 16 bytes |
| 635 | * @rev: revision number of requested function |
| 636 | * @func: requested function number |
| 637 | * @argv4: the function specific parameter |
| 638 | * |
| 639 | * Evaluate device's _DSM method with specified UUID, revision id and |
| 640 | * function number. Caller needs to free the returned object. |
| 641 | * |
| 642 | * Though ACPI defines the fourth parameter for _DSM should be a package, |
| 643 | * some old BIOSes do expect a buffer or an integer etc. |
| 644 | */ |
| 645 | union acpi_object * |
| 646 | acpi_evaluate_dsm(acpi_handle handle, const u8 *uuid, int rev, int func, |
| 647 | union acpi_object *argv4) |
| 648 | { |
| 649 | acpi_status ret; |
| 650 | struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 651 | union acpi_object params[4]; |
| 652 | struct acpi_object_list input = { |
| 653 | .count = 4, |
| 654 | .pointer = params, |
| 655 | }; |
| 656 | |
| 657 | params[0].type = ACPI_TYPE_BUFFER; |
| 658 | params[0].buffer.length = 16; |
| 659 | params[0].buffer.pointer = (char *)uuid; |
| 660 | params[1].type = ACPI_TYPE_INTEGER; |
| 661 | params[1].integer.value = rev; |
| 662 | params[2].type = ACPI_TYPE_INTEGER; |
| 663 | params[2].integer.value = func; |
| 664 | if (argv4) { |
| 665 | params[3] = *argv4; |
| 666 | } else { |
| 667 | params[3].type = ACPI_TYPE_PACKAGE; |
| 668 | params[3].package.count = 0; |
| 669 | params[3].package.elements = NULL; |
| 670 | } |
| 671 | |
| 672 | ret = acpi_evaluate_object(handle, "_DSM", &input, &buf); |
| 673 | if (ACPI_SUCCESS(ret)) |
| 674 | return (union acpi_object *)buf.pointer; |
| 675 | |
| 676 | if (ret != AE_NOT_FOUND) |
| 677 | acpi_handle_warn(handle, |
| 678 | "failed to evaluate _DSM (0x%x)\n", ret); |
| 679 | |
| 680 | return NULL; |
| 681 | } |
| 682 | EXPORT_SYMBOL(acpi_evaluate_dsm); |
| 683 | |
| 684 | /** |
| 685 | * acpi_check_dsm - check if _DSM method supports requested functions. |
| 686 | * @handle: ACPI device handle |
| 687 | * @uuid: UUID of requested functions, should be 16 bytes at least |
| 688 | * @rev: revision number of requested functions |
| 689 | * @funcs: bitmap of requested functions |
Jiang Liu | a65ac52 | 2013-12-19 20:38:10 +0800 | [diff] [blame] | 690 | * |
| 691 | * Evaluate device's _DSM method to check whether it supports requested |
| 692 | * functions. Currently only support 64 functions at maximum, should be |
| 693 | * enough for now. |
| 694 | */ |
| 695 | bool acpi_check_dsm(acpi_handle handle, const u8 *uuid, int rev, u64 funcs) |
| 696 | { |
| 697 | int i; |
| 698 | u64 mask = 0; |
| 699 | union acpi_object *obj; |
| 700 | |
| 701 | if (funcs == 0) |
| 702 | return false; |
| 703 | |
| 704 | obj = acpi_evaluate_dsm(handle, uuid, rev, 0, NULL); |
| 705 | if (!obj) |
| 706 | return false; |
| 707 | |
| 708 | /* For compatibility, old BIOSes may return an integer */ |
| 709 | if (obj->type == ACPI_TYPE_INTEGER) |
| 710 | mask = obj->integer.value; |
| 711 | else if (obj->type == ACPI_TYPE_BUFFER) |
| 712 | for (i = 0; i < obj->buffer.length && i < 8; i++) |
| 713 | mask |= (((u8)obj->buffer.pointer[i]) << (i * 8)); |
| 714 | ACPI_FREE(obj); |
| 715 | |
| 716 | /* |
| 717 | * Bit 0 indicates whether there's support for any functions other than |
| 718 | * function 0 for the specified UUID and revision. |
| 719 | */ |
| 720 | if ((mask & 0x1) && (mask & funcs) == funcs) |
| 721 | return true; |
| 722 | |
| 723 | return false; |
| 724 | } |
| 725 | EXPORT_SYMBOL(acpi_check_dsm); |