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