blob: 74437130431359005374a44529bab0c801918f3a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/init.h>
30#include <linux/types.h>
Toshi Kanifbfddae2012-11-21 01:36:28 +000031#include <linux/hardirq.h>
32#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <acpi/acpi_bus.h>
34#include <acpi/acpi_drivers.h>
35
Len Browna192a952009-07-28 16:45:54 -040036#include "internal.h"
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050039ACPI_MODULE_NAME("utils");
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/* --------------------------------------------------------------------------
42 Object Evaluation Helpers
43 -------------------------------------------------------------------------- */
Harvey Harrison4fd7f512008-02-15 17:07:19 -080044static void
45acpi_util_eval_error(acpi_handle h, acpi_string p, acpi_status s)
46{
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#ifdef ACPI_DEBUG_OUTPUT
Harvey Harrison4fd7f512008-02-15 17:07:19 -080048 char prefix[80] = {'\0'};
49 struct acpi_buffer buffer = {sizeof(prefix), prefix};
50 acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);
51 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate [%s.%s]: %s\n",
52 (char *) prefix, p, acpi_format_exception(s)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#else
Harvey Harrison4fd7f512008-02-15 17:07:19 -080054 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#endif
Harvey Harrison4fd7f512008-02-15 17:07:19 -080056}
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040059acpi_extract_package(union acpi_object *package,
60 struct acpi_buffer *format, struct acpi_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Len Brown4be44fc2005-08-05 00:44:28 -040062 u32 size_required = 0;
63 u32 tail_offset = 0;
64 char *format_string = NULL;
65 u32 format_count = 0;
66 u32 i = 0;
67 u8 *head = NULL;
68 u8 *tail = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Len Brown4be44fc2005-08-05 00:44:28 -040071 if (!package || (package->type != ACPI_TYPE_PACKAGE)
72 || (package->package.count < 1)) {
Len Browncece9292006-06-26 23:04:31 -040073 printk(KERN_WARNING PREFIX "Invalid package argument\n");
Patrick Mocheld550d982006-06-27 00:41:40 -040074 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
76
77 if (!format || !format->pointer || (format->length < 1)) {
Len Browncece9292006-06-26 23:04:31 -040078 printk(KERN_WARNING PREFIX "Invalid format argument\n");
Patrick Mocheld550d982006-06-27 00:41:40 -040079 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
81
82 if (!buffer) {
Len Browncece9292006-06-26 23:04:31 -040083 printk(KERN_WARNING PREFIX "Invalid buffer argument\n");
Patrick Mocheld550d982006-06-27 00:41:40 -040084 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
86
Len Brown4be44fc2005-08-05 00:44:28 -040087 format_count = (format->length / sizeof(char)) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 if (format_count > package->package.count) {
Len Browncece9292006-06-26 23:04:31 -040089 printk(KERN_WARNING PREFIX "Format specifies more objects [%d]"
90 " than exist in package [%d].\n",
91 format_count, package->package.count);
Patrick Mocheld550d982006-06-27 00:41:40 -040092 return AE_BAD_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
94
Jan Engelhardt50dd0962006-10-01 00:28:50 +020095 format_string = format->pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 /*
98 * Calculate size_required.
99 */
Len Brown4be44fc2005-08-05 00:44:28 -0400100 for (i = 0; i < format_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 union acpi_object *element = &(package->package.elements[i]);
103
104 if (!element) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400105 return AE_BAD_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 }
107
108 switch (element->type) {
109
110 case ACPI_TYPE_INTEGER:
111 switch (format_string[i]) {
112 case 'N':
Lin Ming439913f2010-01-28 10:53:19 +0800113 size_required += sizeof(u64);
114 tail_offset += sizeof(u64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 break;
116 case 'S':
Len Brown4be44fc2005-08-05 00:44:28 -0400117 size_required +=
Lin Ming439913f2010-01-28 10:53:19 +0800118 sizeof(char *) + sizeof(u64) +
Len Brown4be44fc2005-08-05 00:44:28 -0400119 sizeof(char);
120 tail_offset += sizeof(char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 break;
122 default:
Len Browncece9292006-06-26 23:04:31 -0400123 printk(KERN_WARNING PREFIX "Invalid package element"
Thomas Renningera6fc6722006-06-26 23:58:43 -0400124 " [%d]: got number, expecing"
Len Browncece9292006-06-26 23:04:31 -0400125 " [%c]\n",
126 i, format_string[i]);
Patrick Mocheld550d982006-06-27 00:41:40 -0400127 return AE_BAD_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 break;
129 }
130 break;
131
132 case ACPI_TYPE_STRING:
133 case ACPI_TYPE_BUFFER:
134 switch (format_string[i]) {
135 case 'S':
Len Brown4be44fc2005-08-05 00:44:28 -0400136 size_required +=
137 sizeof(char *) +
138 (element->string.length * sizeof(char)) +
139 sizeof(char);
140 tail_offset += sizeof(char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 break;
142 case 'B':
Len Brown4be44fc2005-08-05 00:44:28 -0400143 size_required +=
144 sizeof(u8 *) +
145 (element->buffer.length * sizeof(u8));
146 tail_offset += sizeof(u8 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 break;
148 default:
Len Browncece9292006-06-26 23:04:31 -0400149 printk(KERN_WARNING PREFIX "Invalid package element"
Thomas Renningera6fc6722006-06-26 23:58:43 -0400150 " [%d] got string/buffer,"
Len Browncece9292006-06-26 23:04:31 -0400151 " expecing [%c]\n",
152 i, format_string[i]);
Patrick Mocheld550d982006-06-27 00:41:40 -0400153 return AE_BAD_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 break;
155 }
156 break;
157
158 case ACPI_TYPE_PACKAGE:
159 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400160 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
161 "Found unsupported element at index=%d\n",
162 i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* TBD: handle nested packages... */
Patrick Mocheld550d982006-06-27 00:41:40 -0400164 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 break;
166 }
167 }
168
169 /*
170 * Validate output buffer.
171 */
172 if (buffer->length < size_required) {
173 buffer->length = size_required;
Patrick Mocheld550d982006-06-27 00:41:40 -0400174 return AE_BUFFER_OVERFLOW;
Len Brown4be44fc2005-08-05 00:44:28 -0400175 } else if (buffer->length != size_required || !buffer->pointer) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400176 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178
179 head = buffer->pointer;
180 tail = buffer->pointer + tail_offset;
181
182 /*
183 * Extract package data.
184 */
Len Brown4be44fc2005-08-05 00:44:28 -0400185 for (i = 0; i < format_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 u8 **pointer = NULL;
188 union acpi_object *element = &(package->package.elements[i]);
189
190 if (!element) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400191 return AE_BAD_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193
194 switch (element->type) {
195
196 case ACPI_TYPE_INTEGER:
197 switch (format_string[i]) {
198 case 'N':
Lin Ming439913f2010-01-28 10:53:19 +0800199 *((u64 *) head) =
Len Brown4be44fc2005-08-05 00:44:28 -0400200 element->integer.value;
Lin Ming439913f2010-01-28 10:53:19 +0800201 head += sizeof(u64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 break;
203 case 'S':
Len Brown4be44fc2005-08-05 00:44:28 -0400204 pointer = (u8 **) head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 *pointer = tail;
Lin Ming439913f2010-01-28 10:53:19 +0800206 *((u64 *) tail) =
Len Brown4be44fc2005-08-05 00:44:28 -0400207 element->integer.value;
Lin Ming439913f2010-01-28 10:53:19 +0800208 head += sizeof(u64 *);
209 tail += sizeof(u64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 /* NULL terminate string */
211 *tail = (char)0;
212 tail += sizeof(char);
213 break;
214 default:
215 /* Should never get here */
216 break;
217 }
218 break;
219
220 case ACPI_TYPE_STRING:
221 case ACPI_TYPE_BUFFER:
222 switch (format_string[i]) {
223 case 'S':
Len Brown4be44fc2005-08-05 00:44:28 -0400224 pointer = (u8 **) head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 *pointer = tail;
Len Brown4be44fc2005-08-05 00:44:28 -0400226 memcpy(tail, element->string.pointer,
227 element->string.length);
228 head += sizeof(char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 tail += element->string.length * sizeof(char);
230 /* NULL terminate string */
231 *tail = (char)0;
232 tail += sizeof(char);
233 break;
234 case 'B':
Len Brown4be44fc2005-08-05 00:44:28 -0400235 pointer = (u8 **) head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 *pointer = tail;
Len Brown4be44fc2005-08-05 00:44:28 -0400237 memcpy(tail, element->buffer.pointer,
238 element->buffer.length);
239 head += sizeof(u8 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 tail += element->buffer.length * sizeof(u8);
241 break;
242 default:
243 /* Should never get here */
244 break;
245 }
246 break;
247
248 case ACPI_TYPE_PACKAGE:
249 /* TBD: handle nested packages... */
250 default:
251 /* Should never get here */
252 break;
253 }
254 }
255
Patrick Mocheld550d982006-06-27 00:41:40 -0400256 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
Len Brown4be44fc2005-08-05 00:44:28 -0400258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259EXPORT_SYMBOL(acpi_extract_package);
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400262acpi_evaluate_integer(acpi_handle handle,
263 acpi_string pathname,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400264 struct acpi_object_list *arguments, unsigned long long *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Len Brown4be44fc2005-08-05 00:44:28 -0400266 acpi_status status = AE_OK;
Pavel Machek40599072008-11-25 12:05:08 +0100267 union acpi_object element;
Len Brown4be44fc2005-08-05 00:44:28 -0400268 struct acpi_buffer buffer = { 0, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -0400271 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 buffer.length = sizeof(union acpi_object);
Pavel Machek40599072008-11-25 12:05:08 +0100274 buffer.pointer = &element;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
276 if (ACPI_FAILURE(status)) {
277 acpi_util_eval_error(handle, pathname, status);
Patrick Mocheld550d982006-06-27 00:41:40 -0400278 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280
Pavel Machek40599072008-11-25 12:05:08 +0100281 if (element.type != ACPI_TYPE_INTEGER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 acpi_util_eval_error(handle, pathname, AE_BAD_DATA);
Patrick Mocheld550d982006-06-27 00:41:40 -0400283 return AE_BAD_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
Pavel Machek40599072008-11-25 12:05:08 +0100286 *data = element.integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Matthew Wilcox27663c52008-10-10 02:22:59 -0400288 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%llu]\n", *data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Patrick Mocheld550d982006-06-27 00:41:40 -0400290 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Len Brown4be44fc2005-08-05 00:44:28 -0400293EXPORT_SYMBOL(acpi_evaluate_integer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400296acpi_evaluate_reference(acpi_handle handle,
297 acpi_string pathname,
298 struct acpi_object_list *arguments,
299 struct acpi_handle_list *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Len Brown4be44fc2005-08-05 00:44:28 -0400301 acpi_status status = AE_OK;
302 union acpi_object *package = NULL;
303 union acpi_object *element = NULL;
304 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
305 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (!list) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400309 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
312 /* Evaluate object. */
313
314 status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
315 if (ACPI_FAILURE(status))
316 goto end;
317
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200318 package = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 if ((buffer.length == 0) || !package) {
Len Brown64684632006-06-26 23:41:38 -0400321 printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n",
322 (unsigned)buffer.length, package);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 status = AE_BAD_DATA;
324 acpi_util_eval_error(handle, pathname, status);
325 goto end;
326 }
327 if (package->type != ACPI_TYPE_PACKAGE) {
Len Brown64684632006-06-26 23:41:38 -0400328 printk(KERN_ERR PREFIX "Expecting a [Package], found type %X\n",
329 package->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 status = AE_BAD_DATA;
331 acpi_util_eval_error(handle, pathname, status);
332 goto end;
333 }
334 if (!package->package.count) {
Len Brown64684632006-06-26 23:41:38 -0400335 printk(KERN_ERR PREFIX "[Package] has zero elements (%p)\n",
336 package);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 status = AE_BAD_DATA;
338 acpi_util_eval_error(handle, pathname, status);
339 goto end;
340 }
341
342 if (package->package.count > ACPI_MAX_HANDLES) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400343 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345 list->count = package->package.count;
346
347 /* Extract package data. */
348
349 for (i = 0; i < list->count; i++) {
350
351 element = &(package->package.elements[i]);
352
Bob Moorecd0b2242008-04-10 19:06:43 +0400353 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 status = AE_BAD_DATA;
Len Brown64684632006-06-26 23:41:38 -0400355 printk(KERN_ERR PREFIX
356 "Expecting a [Reference] package element, found type %X\n",
357 element->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 acpi_util_eval_error(handle, pathname, status);
359 break;
360 }
361
Thomas Renningerb6a16382008-03-12 01:06:24 +0100362 if (!element->reference.handle) {
363 printk(KERN_WARNING PREFIX "Invalid reference in"
364 " package %s\n", pathname);
365 status = AE_NULL_ENTRY;
366 break;
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /* Get the acpi_handle. */
369
370 list->handles[i] = element->reference.handle;
371 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400372 list->handles[i]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 if (ACPI_FAILURE(status)) {
377 list->count = 0;
378 //kfree(list->handles);
379 }
380
Len Brown02438d82006-06-30 03:19:10 -0400381 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Patrick Mocheld550d982006-06-27 00:41:40 -0400383 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Len Brown4be44fc2005-08-05 00:44:28 -0400386EXPORT_SYMBOL(acpi_evaluate_reference);
Matthew Garrett38ac0f12012-05-11 16:08:26 +0800387
388acpi_status
Feng Tang8ede06a2012-08-21 09:56:58 +0800389acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
Matthew Garrett38ac0f12012-05-11 16:08:26 +0800390{
391 acpi_status status;
392 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
393 union acpi_object *output;
394
395 status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer);
396
397 if (ACPI_FAILURE(status))
398 return status;
399
400 output = buffer.pointer;
401
402 if (!output || output->type != ACPI_TYPE_PACKAGE
403 || !output->package.count
404 || output->package.elements[0].type != ACPI_TYPE_BUFFER
Feng Tang8ede06a2012-08-21 09:56:58 +0800405 || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) {
Matthew Garrett38ac0f12012-05-11 16:08:26 +0800406 status = AE_TYPE;
407 goto out;
408 }
409
Feng Tang8ede06a2012-08-21 09:56:58 +0800410 status = acpi_decode_pld_buffer(
411 output->package.elements[0].buffer.pointer,
412 output->package.elements[0].buffer.length,
413 pld);
414
Matthew Garrett38ac0f12012-05-11 16:08:26 +0800415out:
416 kfree(buffer.pointer);
417 return status;
418}
419EXPORT_SYMBOL(acpi_get_physical_device_location);
Toshi Kani275c58d2012-05-23 20:25:19 -0600420
421/**
422 * acpi_evaluate_hotplug_ost: Evaluate _OST for hotplug operations
423 * @handle: ACPI device handle
424 * @source_event: source event code
425 * @status_code: status code
426 * @status_buf: optional detailed information (NULL if none)
427 *
428 * Evaluate _OST for hotplug operations. All ACPI hotplug handlers
429 * must call this function when evaluating _OST for hotplug operations.
430 * When the platform does not support _OST, this function has no effect.
431 */
432acpi_status
433acpi_evaluate_hotplug_ost(acpi_handle handle, u32 source_event,
434 u32 status_code, struct acpi_buffer *status_buf)
435{
436#ifdef ACPI_HOTPLUG_OST
437 union acpi_object params[3] = {
438 {.type = ACPI_TYPE_INTEGER,},
439 {.type = ACPI_TYPE_INTEGER,},
440 {.type = ACPI_TYPE_BUFFER,}
441 };
442 struct acpi_object_list arg_list = {3, params};
443 acpi_status status;
444
445 params[0].integer.value = source_event;
446 params[1].integer.value = status_code;
447 if (status_buf != NULL) {
448 params[2].buffer.pointer = status_buf->pointer;
449 params[2].buffer.length = status_buf->length;
450 } else {
451 params[2].buffer.pointer = NULL;
452 params[2].buffer.length = 0;
453 }
454
455 status = acpi_evaluate_object(handle, "_OST", &arg_list, NULL);
456 return status;
457#else
458 return AE_OK;
459#endif
460}
461EXPORT_SYMBOL(acpi_evaluate_hotplug_ost);
Toshi Kanifbfddae2012-11-21 01:36:28 +0000462
463/**
464 * acpi_handle_printk: Print message with ACPI prefix and object path
465 *
466 * This function is called through acpi_handle_<level> macros and prints
467 * a message with ACPI prefix and object path. This function acquires
468 * the global namespace mutex to obtain an object path. In interrupt
469 * context, it shows the object path as <n/a>.
470 */
471void
472acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
473{
474 struct va_format vaf;
475 va_list args;
476 struct acpi_buffer buffer = {
477 .length = ACPI_ALLOCATE_BUFFER,
478 .pointer = NULL
479 };
480 const char *path;
481
482 va_start(args, fmt);
483 vaf.fmt = fmt;
484 vaf.va = &args;
485
486 if (in_interrupt() ||
487 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK)
488 path = "<n/a>";
489 else
490 path = buffer.pointer;
491
492 printk("%sACPI: %s: %pV", level, path, &vaf);
493
494 va_end(args);
495 kfree(buffer.pointer);
496}
497EXPORT_SYMBOL(acpi_handle_printk);