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