blob: 07a20ee3e690b12d40855dc1c20dfaa5260bba85 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
3 *
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/ioport.h>
Randy Dunlapd568df82006-07-12 01:47:00 -040028#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/list.h>
30#include <linux/sched.h>
31#include <linux/pm.h>
32#include <linux/device.h>
33#include <linux/proc_fs.h>
Harvey Harrison6697c052008-02-09 23:24:08 +010034#include <linux/acpi.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#ifdef CONFIG_X86
37#include <asm/mpspec.h>
38#endif
Robert Hancock7752d5c2008-02-15 01:27:20 -080039#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <acpi/acpi_bus.h>
41#include <acpi/acpi_drivers.h>
Huang Yingeccddd32011-07-13 13:14:20 +080042#include <acpi/apei.h>
Len Browneb27cae2009-07-06 23:40:19 -040043#include <linux/dmi.h>
Rafael J. Wysockicd51e61c2011-02-11 00:04:52 +010044#include <linux/suspend.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060046#include "internal.h"
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050049ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Len Brown4be44fc2005-08-05 00:44:28 -040051struct acpi_device *acpi_root;
52struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053EXPORT_SYMBOL(acpi_root_dir);
54
55#define STRUCT_TO_INT(s) (*((int*)&s))
56
Zhao Yakui6415e122008-08-11 14:59:59 +080057
Lin Mingcce4f632010-05-12 09:26:48 +080058#ifdef CONFIG_X86
Lin Mingaa2110c2010-04-08 14:34:27 +080059static int set_copy_dsdt(const struct dmi_system_id *id)
60{
61 printk(KERN_NOTICE "%s detected - "
62 "force copy of DSDT to local memory\n", id->ident);
63 acpi_gbl_copy_dsdt_locally = 1;
64 return 0;
65}
66
67static struct dmi_system_id dsdt_dmi_table[] __initdata = {
68 /*
Len Brown100cf872010-09-28 22:57:02 -040069 * Invoke DSDT corruption work-around on all Toshiba Satellite.
Lin Mingaa2110c2010-04-08 14:34:27 +080070 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
71 */
72 {
73 .callback = set_copy_dsdt,
Len Brown100cf872010-09-28 22:57:02 -040074 .ident = "TOSHIBA Satellite",
Lin Mingaa2110c2010-04-08 14:34:27 +080075 .matches = {
76 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Len Brown100cf872010-09-28 22:57:02 -040077 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
Lin Mingaa2110c2010-04-08 14:34:27 +080078 },
Lin Mingcce4f632010-05-12 09:26:48 +080079 },
80 {}
Lin Mingaa2110c2010-04-08 14:34:27 +080081};
Lin Mingcce4f632010-05-12 09:26:48 +080082#else
83static struct dmi_system_id dsdt_dmi_table[] __initdata = {
84 {}
85};
86#endif
Lin Mingaa2110c2010-04-08 14:34:27 +080087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088/* --------------------------------------------------------------------------
89 Device Management
90 -------------------------------------------------------------------------- */
91
Len Brown4be44fc2005-08-05 00:44:28 -040092int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Len Brown4be44fc2005-08-05 00:44:28 -040094 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -040098 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 /* TBD: Support fixed-feature devices */
101
Len Brown4be44fc2005-08-05 00:44:28 -0400102 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (ACPI_FAILURE(status) || !*device) {
Len Brown9805cb72006-07-25 13:30:57 -0400104 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
105 handle));
Patrick Mocheld550d982006-06-27 00:41:40 -0400106 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108
Patrick Mocheld550d982006-06-27 00:41:40 -0400109 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
Len Brown4be44fc2005-08-05 00:44:28 -0400111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112EXPORT_SYMBOL(acpi_bus_get_device);
113
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000114acpi_status acpi_bus_get_status_handle(acpi_handle handle,
115 unsigned long long *sta)
116{
117 acpi_status status;
118
119 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
120 if (ACPI_SUCCESS(status))
121 return AE_OK;
122
123 if (status == AE_NOT_FOUND) {
124 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
125 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
126 return AE_OK;
127 }
128 return status;
129}
130
Len Brown4be44fc2005-08-05 00:44:28 -0400131int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000133 acpi_status status;
134 unsigned long long sta;
Len Brown4be44fc2005-08-05 00:44:28 -0400135
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000136 status = acpi_bus_get_status_handle(device->handle, &sta);
137 if (ACPI_FAILURE(status))
138 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000140 STRUCT_TO_INT(device->status) = (int) sta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800143 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
144 "functional but not present;\n",
145 device->pnp.bus_id,
146 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
150 device->pnp.bus_id,
151 (u32) STRUCT_TO_INT(device->status)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400152 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
Len Brown4be44fc2005-08-05 00:44:28 -0400154EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Zhang Rui20733932008-01-17 15:51:21 +0800156void acpi_bus_private_data_handler(acpi_handle handle,
Bob Moore8e4319c2009-06-29 13:43:27 +0800157 void *context)
Zhang Rui20733932008-01-17 15:51:21 +0800158{
159 return;
160}
161EXPORT_SYMBOL(acpi_bus_private_data_handler);
162
163int acpi_bus_get_private_data(acpi_handle handle, void **data)
164{
165 acpi_status status = AE_OK;
166
167 if (!*data)
168 return -EINVAL;
169
170 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
171 if (ACPI_FAILURE(status) || !*data) {
172 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
173 handle));
174 return -ENODEV;
175 }
176
177 return 0;
178}
179EXPORT_SYMBOL(acpi_bus_get_private_data);
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181/* --------------------------------------------------------------------------
182 Power Management
183 -------------------------------------------------------------------------- */
184
Rafael J. Wysocki63a1a762012-05-20 13:57:52 +0200185static const char *state_string(int state)
186{
187 switch (state) {
188 case ACPI_STATE_D0:
189 return "D0";
190 case ACPI_STATE_D1:
191 return "D1";
192 case ACPI_STATE_D2:
193 return "D2";
194 case ACPI_STATE_D3_HOT:
195 return "D3hot";
196 case ACPI_STATE_D3_COLD:
197 return "D3";
198 default:
199 return "(unknown)";
200 }
201}
202
Rafael J. Wysocki5e6d4fe2010-11-25 00:07:56 +0100203static int __acpi_bus_get_power(struct acpi_device *device, int *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Rafael J. Wysocki38c92ff2012-05-20 13:58:00 +0200205 int result = ACPI_STATE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Rafael J. Wysocki5e6d4fe2010-11-25 00:07:56 +0100207 if (!device || !state)
208 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Rafael J. Wysocki38c92ff2012-05-20 13:58:00 +0200210 if (!device->flags.power_manageable) {
Rafael J. Wysocki5e6d4fe2010-11-25 00:07:56 +0100211 /* TBD: Non-recursive algorithm for walking up hierarchy. */
212 *state = device->parent ?
213 device->parent->power.state : ACPI_STATE_D0;
Rafael J. Wysocki38c92ff2012-05-20 13:58:00 +0200214 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
Rafael J. Wysocki38c92ff2012-05-20 13:58:00 +0200217 /*
218 * Get the device's power state either directly (via _PSC) or
219 * indirectly (via power resources).
220 */
221 if (device->power.flags.explicit_get) {
222 unsigned long long psc;
223 acpi_status status = acpi_evaluate_integer(device->handle,
224 "_PSC", NULL, &psc);
225 if (ACPI_FAILURE(status))
226 return -ENODEV;
227
228 result = psc;
229 }
230 /* The test below covers ACPI_STATE_UNKNOWN too. */
231 if (result <= ACPI_STATE_D2) {
232 ; /* Do nothing. */
233 } else if (device->power.flags.power_resources) {
234 int error = acpi_power_get_inferred_state(device, &result);
235 if (error)
236 return error;
237 } else if (result == ACPI_STATE_D3_HOT) {
238 result = ACPI_STATE_D3;
239 }
Rafael J. Wysocki8f7412a2012-09-14 00:26:24 +0200240
241 /*
242 * If we were unsure about the device parent's power state up to this
243 * point, the fact that the device is in D0 implies that the parent has
244 * to be in D0 too.
245 */
246 if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN
247 && result == ACPI_STATE_D0)
248 device->parent->power.state = ACPI_STATE_D0;
249
Rafael J. Wysocki38c92ff2012-05-20 13:58:00 +0200250 *state = result;
251
252 out:
Rafael J. Wysocki63a1a762012-05-20 13:57:52 +0200253 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n",
254 device->pnp.bus_id, state_string(*state)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Patrick Mocheld550d982006-06-27 00:41:40 -0400256 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
Len Brown4be44fc2005-08-05 00:44:28 -0400258
Rafael J. Wysocki5e6d4fe2010-11-25 00:07:56 +0100259
Rafael J. Wysocki078eb122012-11-02 01:40:45 +0100260/**
261 * acpi_device_set_power - Set power state of an ACPI device.
262 * @device: Device to set the power state of.
263 * @state: New power state to set.
264 *
265 * Callers must ensure that the device is power manageable before using this
266 * function.
267 */
268int acpi_device_set_power(struct acpi_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Len Brown4be44fc2005-08-05 00:44:28 -0400270 int result = 0;
271 acpi_status status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400272 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Lin Ming28c21032011-05-04 22:56:43 +0800274 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
Patrick Mocheld550d982006-06-27 00:41:40 -0400275 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 /* Make sure this is a valid target state */
278
Rafael J. Wysocki488a76c2010-11-25 00:11:24 +0100279 if (state == device->power.state) {
Rafael J. Wysocki63a1a762012-05-20 13:57:52 +0200280 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at %s\n",
281 state_string(state)));
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500282 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (!device->power.states[state].flags.valid) {
Rafael J. Wysocki63a1a762012-05-20 13:57:52 +0200286 printk(KERN_WARNING PREFIX "Device does not support %s\n",
287 state_string(state));
Patrick Mocheld550d982006-06-27 00:41:40 -0400288 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290 if (device->parent && (state < device->parent->power.state)) {
Len Browncece9292006-06-26 23:04:31 -0400291 printk(KERN_WARNING PREFIX
Thomas Renningera6fc6722006-06-26 23:58:43 -0400292 "Cannot set device to a higher-powered"
Len Browncece9292006-06-26 23:04:31 -0400293 " state than parent\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400294 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296
Rafael J. Wysocki5c7dd712012-05-18 00:39:35 +0200297 /* For D3cold we should execute _PS3, not _PS4. */
298 if (state == ACPI_STATE_D3_COLD)
299 object_name[3] = '3';
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 /*
302 * Transition Power
303 * ----------------
304 * On transitions to a high-powered state we first apply power (via
305 * power resources) then evalute _PSx. Conversly for transitions to
306 * a lower-powered state.
David Shaohua Lib9131002005-03-19 00:16:18 -0500307 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 if (state < device->power.state) {
309 if (device->power.flags.power_resources) {
310 result = acpi_power_transition(device, state);
311 if (result)
312 goto end;
313 }
314 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400315 status = acpi_evaluate_object(device->handle,
316 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 if (ACPI_FAILURE(status)) {
318 result = -ENODEV;
319 goto end;
320 }
321 }
Len Brown4be44fc2005-08-05 00:44:28 -0400322 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400324 status = acpi_evaluate_object(device->handle,
325 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 if (ACPI_FAILURE(status)) {
327 result = -ENODEV;
328 goto end;
329 }
330 }
331 if (device->power.flags.power_resources) {
332 result = acpi_power_transition(device, state);
333 if (result)
334 goto end;
335 }
336 }
337
Len Brown4be44fc2005-08-05 00:44:28 -0400338 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 if (result)
Len Browncece9292006-06-26 23:04:31 -0400340 printk(KERN_WARNING PREFIX
Rafael J. Wysocki63a1a762012-05-20 13:57:52 +0200341 "Device [%s] failed to transition to %s\n",
342 device->pnp.bus_id, state_string(state));
Shaohua Li5e321322007-10-11 23:53:58 +0200343 else {
344 device->power.state = state;
Len Brown4be44fc2005-08-05 00:44:28 -0400345 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Rafael J. Wysocki63a1a762012-05-20 13:57:52 +0200346 "Device [%s] transitioned to %s\n",
347 device->pnp.bus_id, state_string(state)));
Shaohua Li5e321322007-10-11 23:53:58 +0200348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Patrick Mocheld550d982006-06-27 00:41:40 -0400350 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
Rafael J. Wysocki078eb122012-11-02 01:40:45 +0100352EXPORT_SYMBOL(acpi_device_set_power);
Len Brown4be44fc2005-08-05 00:44:28 -0400353
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100354
355int acpi_bus_set_power(acpi_handle handle, int state)
356{
357 struct acpi_device *device;
358 int result;
359
360 result = acpi_bus_get_device(handle, &device);
361 if (result)
362 return result;
363
364 if (!device->flags.power_manageable) {
365 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
366 "Device [%s] is not power manageable\n",
367 dev_name(&device->dev)));
368 return -ENODEV;
369 }
370
Rafael J. Wysocki078eb122012-11-02 01:40:45 +0100371 return acpi_device_set_power(device, state);
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100372}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373EXPORT_SYMBOL(acpi_bus_set_power);
374
Rafael J. Wysockiade3e7f2010-11-25 00:08:36 +0100375
376int acpi_bus_init_power(struct acpi_device *device)
377{
378 int state;
379 int result;
380
381 if (!device)
382 return -EINVAL;
383
384 device->power.state = ACPI_STATE_UNKNOWN;
385
386 result = __acpi_bus_get_power(device, &state);
387 if (result)
388 return result;
389
390 if (device->power.flags.power_resources)
391 result = acpi_power_on_resources(device, state);
392
393 if (!result)
394 device->power.state = state;
395
396 return result;
397}
398
399
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100400int acpi_bus_update_power(acpi_handle handle, int *state_p)
401{
402 struct acpi_device *device;
403 int state;
404 int result;
405
406 result = acpi_bus_get_device(handle, &device);
407 if (result)
408 return result;
409
410 result = __acpi_bus_get_power(device, &state);
411 if (result)
412 return result;
413
Rafael J. Wysocki078eb122012-11-02 01:40:45 +0100414 result = acpi_device_set_power(device, state);
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100415 if (!result && state_p)
416 *state_p = state;
417
418 return result;
419}
420EXPORT_SYMBOL_GPL(acpi_bus_update_power);
421
422
Rafael J. Wysocki3737b2b2008-07-07 03:30:55 +0200423bool acpi_bus_power_manageable(acpi_handle handle)
424{
425 struct acpi_device *device;
426 int result;
427
428 result = acpi_bus_get_device(handle, &device);
429 return result ? false : device->flags.power_manageable;
430}
431
432EXPORT_SYMBOL(acpi_bus_power_manageable);
433
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200434bool acpi_bus_can_wakeup(acpi_handle handle)
435{
436 struct acpi_device *device;
437 int result;
438
439 result = acpi_bus_get_device(handle, &device);
440 return result ? false : device->wakeup.flags.valid;
441}
442
443EXPORT_SYMBOL(acpi_bus_can_wakeup);
444
Shaohua Li70023de2009-10-29 11:04:28 +0800445static void acpi_print_osc_error(acpi_handle handle,
446 struct acpi_osc_context *context, char *error)
447{
448 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
449 int i;
450
451 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
452 printk(KERN_DEBUG "%s\n", error);
453 else {
454 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
455 kfree(buffer.pointer);
456 }
457 printk(KERN_DEBUG"_OSC request data:");
458 for (i = 0; i < context->cap.length; i += sizeof(u32))
459 printk("%x ", *((u32 *)(context->cap.pointer + i)));
460 printk("\n");
461}
462
Shaohua Li70023de2009-10-29 11:04:28 +0800463static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
464{
465 int i;
466 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
467 24, 26, 28, 30, 32, 34};
468
469 if (strlen(str) != 36)
470 return AE_BAD_PARAMETER;
471 for (i = 0; i < 36; i++) {
472 if (i == 8 || i == 13 || i == 18 || i == 23) {
473 if (str[i] != '-')
474 return AE_BAD_PARAMETER;
475 } else if (!isxdigit(str[i]))
476 return AE_BAD_PARAMETER;
477 }
478 for (i = 0; i < 16; i++) {
Andy Shevchenko965fd9e2010-05-24 14:33:28 -0700479 uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
480 uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
Shaohua Li70023de2009-10-29 11:04:28 +0800481 }
482 return AE_OK;
483}
484
485acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
486{
487 acpi_status status;
488 struct acpi_object_list input;
489 union acpi_object in_params[4];
490 union acpi_object *out_obj;
491 u8 uuid[16];
492 u32 errors;
Shaohua Li9dc130f2009-12-23 17:04:11 +0800493 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
Shaohua Li70023de2009-10-29 11:04:28 +0800494
495 if (!context)
496 return AE_ERROR;
497 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
498 return AE_ERROR;
499 context->ret.length = ACPI_ALLOCATE_BUFFER;
500 context->ret.pointer = NULL;
501
502 /* Setting up input parameters */
503 input.count = 4;
504 input.pointer = in_params;
505 in_params[0].type = ACPI_TYPE_BUFFER;
506 in_params[0].buffer.length = 16;
507 in_params[0].buffer.pointer = uuid;
508 in_params[1].type = ACPI_TYPE_INTEGER;
509 in_params[1].integer.value = context->rev;
510 in_params[2].type = ACPI_TYPE_INTEGER;
511 in_params[2].integer.value = context->cap.length/sizeof(u32);
512 in_params[3].type = ACPI_TYPE_BUFFER;
513 in_params[3].buffer.length = context->cap.length;
514 in_params[3].buffer.pointer = context->cap.pointer;
515
Shaohua Li9dc130f2009-12-23 17:04:11 +0800516 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
Shaohua Li70023de2009-10-29 11:04:28 +0800517 if (ACPI_FAILURE(status))
518 return status;
519
Shaohua Li9dc130f2009-12-23 17:04:11 +0800520 if (!output.length)
Shaohua Li70023de2009-10-29 11:04:28 +0800521 return AE_NULL_OBJECT;
522
Shaohua Li9dc130f2009-12-23 17:04:11 +0800523 out_obj = output.pointer;
524 if (out_obj->type != ACPI_TYPE_BUFFER
525 || out_obj->buffer.length != context->cap.length) {
Shaohua Li70023de2009-10-29 11:04:28 +0800526 acpi_print_osc_error(handle, context,
527 "_OSC evaluation returned wrong type");
528 status = AE_TYPE;
529 goto out_kfree;
530 }
531 /* Need to ignore the bit0 in result code */
532 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
533 if (errors) {
534 if (errors & OSC_REQUEST_ERROR)
535 acpi_print_osc_error(handle, context,
536 "_OSC request failed");
537 if (errors & OSC_INVALID_UUID_ERROR)
538 acpi_print_osc_error(handle, context,
539 "_OSC invalid UUID");
540 if (errors & OSC_INVALID_REVISION_ERROR)
541 acpi_print_osc_error(handle, context,
542 "_OSC invalid revision");
543 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
544 if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
545 & OSC_QUERY_ENABLE)
546 goto out_success;
547 status = AE_SUPPORT;
548 goto out_kfree;
549 }
550 status = AE_ERROR;
551 goto out_kfree;
552 }
553out_success:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800554 context->ret.length = out_obj->buffer.length;
555 context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
556 if (!context->ret.pointer) {
557 status = AE_NO_MEMORY;
558 goto out_kfree;
559 }
560 memcpy(context->ret.pointer, out_obj->buffer.pointer,
561 context->ret.length);
562 status = AE_OK;
Shaohua Li70023de2009-10-29 11:04:28 +0800563
564out_kfree:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800565 kfree(output.pointer);
566 if (status != AE_OK)
567 context->ret.pointer = NULL;
Shaohua Li70023de2009-10-29 11:04:28 +0800568 return status;
569}
570EXPORT_SYMBOL(acpi_run_osc);
571
Huang Yingeccddd32011-07-13 13:14:20 +0800572bool osc_sb_apei_support_acked;
Shaohua Li3563ff92009-10-29 11:05:05 +0800573static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
574static void acpi_bus_osc_support(void)
575{
576 u32 capbuf[2];
577 struct acpi_osc_context context = {
578 .uuid_str = sb_uuid_str,
579 .rev = 1,
580 .cap.length = 8,
581 .cap.pointer = capbuf,
582 };
583 acpi_handle handle;
584
585 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
586 capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800587#if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
588 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
Shaohua Li3563ff92009-10-29 11:05:05 +0800589 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
590#endif
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800591
592#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
593 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PPC_OST_SUPPORT;
594#endif
Huang Yingeccddd32011-07-13 13:14:20 +0800595
Toshi Kanic2f41912012-05-23 20:25:24 -0600596#ifdef ACPI_HOTPLUG_OST
597 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_HOTPLUG_OST_SUPPORT;
598#endif
599
Huang Yingeccddd32011-07-13 13:14:20 +0800600 if (!ghes_disable)
601 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_APEI_SUPPORT;
Shaohua Li3563ff92009-10-29 11:05:05 +0800602 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
603 return;
Huang Yingeccddd32011-07-13 13:14:20 +0800604 if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
605 u32 *capbuf_ret = context.ret.pointer;
606 if (context.ret.length > OSC_SUPPORT_TYPE)
607 osc_sb_apei_support_acked =
608 capbuf_ret[OSC_SUPPORT_TYPE] & OSC_SB_APEI_SUPPORT;
Shaohua Li3563ff92009-10-29 11:05:05 +0800609 kfree(context.ret.pointer);
Huang Yingeccddd32011-07-13 13:14:20 +0800610 }
611 /* do we need to check other returned cap? Sounds no */
Shaohua Li3563ff92009-10-29 11:05:05 +0800612}
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614/* --------------------------------------------------------------------------
615 Event Management
616 -------------------------------------------------------------------------- */
617
Len Brown14e04fb2007-08-23 15:20:26 -0400618#ifdef CONFIG_ACPI_PROC_EVENT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619static DEFINE_SPINLOCK(acpi_bus_event_lock);
620
621LIST_HEAD(acpi_bus_event_list);
622DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
623
Len Brown4be44fc2005-08-05 00:44:28 -0400624extern int event_is_open;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400626int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627{
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400628 struct acpi_bus_event *event;
Len Brown4be44fc2005-08-05 00:44:28 -0400629 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* drop event on the floor if no one's listening */
632 if (!event_is_open)
Patrick Mocheld550d982006-06-27 00:41:40 -0400633 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Dan Carpenter5cc4a0f2010-04-27 00:23:37 +0200635 event = kzalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400637 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400639 strcpy(event->device_class, device_class);
640 strcpy(event->bus_id, bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 event->type = type;
642 event->data = data;
643
644 spin_lock_irqsave(&acpi_bus_event_lock, flags);
645 list_add_tail(&event->node, &acpi_bus_event_list);
646 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
647
648 wake_up_interruptible(&acpi_bus_event_queue);
649
Patrick Mocheld550d982006-06-27 00:41:40 -0400650 return 0;
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400651
652}
653
654EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
655
656int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
657{
658 if (!device)
659 return -EINVAL;
660 return acpi_bus_generate_proc_event4(device->pnp.device_class,
661 device->pnp.bus_id, type, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
Len Brown4be44fc2005-08-05 00:44:28 -0400663
Len Brown14e04fb2007-08-23 15:20:26 -0400664EXPORT_SYMBOL(acpi_bus_generate_proc_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Len Brown4be44fc2005-08-05 00:44:28 -0400666int acpi_bus_receive_event(struct acpi_bus_event *event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
Len Brown4be44fc2005-08-05 00:44:28 -0400668 unsigned long flags = 0;
669 struct acpi_bus_event *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 DECLARE_WAITQUEUE(wait, current);
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400675 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 if (list_empty(&acpi_bus_event_list)) {
678
679 set_current_state(TASK_INTERRUPTIBLE);
680 add_wait_queue(&acpi_bus_event_queue, &wait);
681
682 if (list_empty(&acpi_bus_event_list))
683 schedule();
684
685 remove_wait_queue(&acpi_bus_event_queue, &wait);
686 set_current_state(TASK_RUNNING);
687
688 if (signal_pending(current))
Patrick Mocheld550d982006-06-27 00:41:40 -0400689 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 }
691
692 spin_lock_irqsave(&acpi_bus_event_lock, flags);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700693 if (!list_empty(&acpi_bus_event_list)) {
694 entry = list_entry(acpi_bus_event_list.next,
695 struct acpi_bus_event, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 list_del(&entry->node);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
699
700 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400701 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 memcpy(event, entry, sizeof(struct acpi_bus_event));
704
705 kfree(entry);
706
Patrick Mocheld550d982006-06-27 00:41:40 -0400707 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Len Brown14e04fb2007-08-23 15:20:26 -0400710#endif /* CONFIG_ACPI_PROC_EVENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712/* --------------------------------------------------------------------------
713 Notification Handling
714 -------------------------------------------------------------------------- */
715
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600716static void acpi_bus_check_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600718 struct acpi_device *device;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600719 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 struct acpi_device_status old_status;
721
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600722 if (acpi_bus_get_device(handle, &device))
723 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 if (!device)
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600725 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 old_status = device->status;
728
729 /*
730 * Make sure this device's parent is present before we go about
731 * messing with the device.
732 */
733 if (device->parent && !device->parent->status.present) {
734 device->status = device->parent->status;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600735 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737
738 status = acpi_bus_get_status(device);
739 if (ACPI_FAILURE(status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600740 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600743 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 /*
746 * Device Insertion/Removal
747 */
748 if ((device->status.present) && !(old_status.present)) {
749 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
750 /* TBD: Handle device insertion */
Len Brown4be44fc2005-08-05 00:44:28 -0400751 } else if (!(device->status.present) && (old_status.present)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
753 /* TBD: Handle device removal */
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600757static void acpi_bus_check_scope(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 /* Status Change? */
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600760 acpi_bus_check_device(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 /*
763 * TBD: Enumerate child devices within this device's scope and
764 * run acpi_bus_check_device()'s on them.
765 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766}
767
Shaohua Li6bd00a62008-08-28 10:04:29 +0800768static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
769int register_acpi_bus_notifier(struct notifier_block *nb)
770{
771 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
772}
773EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
774
775void unregister_acpi_bus_notifier(struct notifier_block *nb)
776{
777 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
778}
779EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781/**
782 * acpi_bus_notify
783 * ---------------
784 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
785 */
Len Brown4be44fc2005-08-05 00:44:28 -0400786static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
Len Brown4be44fc2005-08-05 00:44:28 -0400788 struct acpi_device *device = NULL;
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600789 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Bjorn Helgaas02c37bd2009-05-22 11:43:41 -0600791 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
792 type, handle));
793
Shaohua Li6bd00a62008-08-28 10:04:29 +0800794 blocking_notifier_call_chain(&acpi_bus_notify_list,
795 type, (void *)handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 switch (type) {
798
799 case ACPI_NOTIFY_BUS_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600800 acpi_bus_check_scope(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500801 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400803 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 */
805 break;
806
807 case ACPI_NOTIFY_DEVICE_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600808 acpi_bus_check_device(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500809 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400811 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 */
813 break;
814
815 case ACPI_NOTIFY_DEVICE_WAKE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 /* TBD */
817 break;
818
819 case ACPI_NOTIFY_EJECT_REQUEST:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 /* TBD */
821 break;
822
823 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 /* TBD: Exactly what does 'light' mean? */
825 break;
826
827 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 /* TBD */
829 break;
830
831 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 /* TBD */
833 break;
834
835 case ACPI_NOTIFY_POWER_FAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 /* TBD */
837 break;
838
839 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400840 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
841 "Received unknown/unsupported notification [%08x]\n",
842 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 break;
844 }
845
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600846 acpi_bus_get_device(handle, &device);
847 if (device) {
848 driver = device->driver;
849 if (driver && driver->ops.notify &&
850 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
851 driver->ops.notify(device, type);
852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854
855/* --------------------------------------------------------------------------
856 Initialization/Cleanup
857 -------------------------------------------------------------------------- */
858
Len Brown4be44fc2005-08-05 00:44:28 -0400859static int __init acpi_bus_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
Len Brown4be44fc2005-08-05 00:44:28 -0400861 acpi_status status = AE_OK;
862 union acpi_object arg = { ACPI_TYPE_INTEGER };
863 struct acpi_object_list arg_list = { 1, &arg };
864 char *message = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500867 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 * Let the system know what interrupt model we are using by
869 * evaluating the \_PIC object, if exists.
870 */
871
872 switch (acpi_irq_model) {
873 case ACPI_IRQ_MODEL_PIC:
874 message = "PIC";
875 break;
876 case ACPI_IRQ_MODEL_IOAPIC:
877 message = "IOAPIC";
878 break;
879 case ACPI_IRQ_MODEL_IOSAPIC:
880 message = "IOSAPIC";
881 break;
John Keller3948ec92006-12-22 11:50:04 -0600882 case ACPI_IRQ_MODEL_PLATFORM:
883 message = "platform specific model";
884 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 default:
886 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400887 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 }
889
890 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
891
892 arg.integer.value = acpi_irq_model;
893
894 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
895 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400896 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400897 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
Patrick Mocheld550d982006-06-27 00:41:40 -0400900 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
Bob Moore67a119f2008-06-10 13:42:13 +0800903u8 acpi_gbl_permanent_mmap;
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300904
905
Len Brown4be44fc2005-08-05 00:44:28 -0400906void __init acpi_early_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Len Brown4be44fc2005-08-05 00:44:28 -0400908 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400911 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Bob Moore616861242006-03-17 16:44:00 -0500913 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 /* enable workarounds, unless strict ACPI spec. compliance */
916 if (!acpi_strict)
917 acpi_gbl_enable_interpreter_slack = TRUE;
918
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300919 acpi_gbl_permanent_mmap = 1;
920
Lin Mingaa2110c2010-04-08 14:34:27 +0800921 /*
922 * If the machine falls into the DMI check table,
923 * DSDT will be copied to memory
924 */
925 dmi_check_system(dsdt_dmi_table);
926
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300927 status = acpi_reallocate_root_table();
928 if (ACPI_FAILURE(status)) {
929 printk(KERN_ERR PREFIX
930 "Unable to reallocate ACPI tables\n");
931 goto error0;
932 }
933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 status = acpi_initialize_subsystem();
935 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400936 printk(KERN_ERR PREFIX
937 "Unable to initialize the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 goto error0;
939 }
940
941 status = acpi_load_tables();
942 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400943 printk(KERN_ERR PREFIX
944 "Unable to load the System Description Tables\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 goto error0;
946 }
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948#ifdef CONFIG_X86
949 if (!acpi_ioapic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 /* compatible (0) means level (3) */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300951 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
952 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
953 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 /* Set PIC-mode SCI trigger type */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300956 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300957 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 /*
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300960 * now that acpi_gbl_FADT is initialized,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 * update it with result from INT_SRC_OVR parsing
962 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300963 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 }
965#endif
966
Rafael J. Wysocki4505a202011-11-06 14:20:42 +0100967 status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 if (ACPI_FAILURE(status)) {
969 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
970 goto error0;
971 }
972
Patrick Mocheld550d982006-06-27 00:41:40 -0400973 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Len Brown4be44fc2005-08-05 00:44:28 -0400975 error0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 disable_acpi();
Patrick Mocheld550d982006-06-27 00:41:40 -0400977 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978}
979
Len Brown4be44fc2005-08-05 00:44:28 -0400980static int __init acpi_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
Len Brown4be44fc2005-08-05 00:44:28 -0400982 int result = 0;
983 acpi_status status = AE_OK;
984 extern acpi_status acpi_os_initialize1(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Jiri Slaby176f9c12009-03-04 11:55:27 -0800986 acpi_os_initialize1();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Rafael J. Wysocki4505a202011-11-06 14:20:42 +0100988 status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400990 printk(KERN_ERR PREFIX
991 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 goto error1;
993 }
994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 /*
996 * ACPI 2.0 requires the EC driver to be loaded and work before
997 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
998 * is called).
999 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -05001000 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 * the EC parameters out of that.
1002 */
1003 status = acpi_ec_ecdt_probe();
1004 /* Ignore result. Not having an ECDT is not fatal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
1007 if (ACPI_FAILURE(status)) {
1008 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
1009 goto error1;
1010 }
1011
Zhang Ruib1d248d2010-10-26 10:06:54 +08001012 /*
Lin Mingfc54ab72012-07-16 16:30:21 +08001013 * _OSC method may exist in module level code,
1014 * so it must be run after ACPI_FULL_INITIALIZATION
1015 */
1016 acpi_bus_osc_support();
1017
1018 /*
Zhang Ruib1d248d2010-10-26 10:06:54 +08001019 * _PDC control method may load dynamic SSDT tables,
1020 * and we need to install the table handler before that.
1021 */
1022 acpi_sysfs_init();
1023
Alex Chiang78f16992009-12-20 12:19:09 -07001024 acpi_early_processor_set_pdc();
1025
Zhao Yakui455c8792008-10-06 10:31:36 +08001026 /*
1027 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
1028 * is necessary to enable it as early as possible.
1029 */
1030 acpi_boot_ec_enable();
1031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 printk(KERN_INFO PREFIX "Interpreter enabled\n");
1033
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -05001034 /* Initialize sleep structures */
1035 acpi_sleep_init();
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 /*
1038 * Get the system interrupt model and evaluate \_PIC.
1039 */
1040 result = acpi_bus_init_irq();
1041 if (result)
1042 goto error1;
1043
1044 /*
1045 * Register the for all standard device notifications.
1046 */
Len Brown4be44fc2005-08-05 00:44:28 -04001047 status =
1048 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
1049 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001051 printk(KERN_ERR PREFIX
1052 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 goto error1;
1054 }
1055
1056 /*
1057 * Create the top ACPI proc directory
1058 */
1059 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
1060
Patrick Mocheld550d982006-06-27 00:41:40 -04001061 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -04001064 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -04001066 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -07001069struct kobject *acpi_kobj;
Matthew Garrettf2d47532012-01-31 13:19:19 -05001070EXPORT_SYMBOL_GPL(acpi_kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Len Brown4be44fc2005-08-05 00:44:28 -04001072static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +01001074 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 if (acpi_disabled) {
1077 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001078 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 }
1080
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001081 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -07001082 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001083 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -07001084 acpi_kobj = NULL;
1085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Bjorn Helgaas0e465172009-03-24 16:50:09 -06001087 init_acpi_device_notify();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 result = acpi_bus_init();
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +01001089 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 disable_acpi();
Bjorn Helgaas81d02732009-03-24 16:49:38 -06001091 return result;
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +01001092 }
Bjorn Helgaas81d02732009-03-24 16:49:38 -06001093
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +01001094 pci_mmcfg_late_init();
Bjorn Helgaase747f272009-03-24 16:49:43 -06001095 acpi_scan_init();
Bjorn Helgaasa5f820f2009-03-24 16:49:48 -06001096 acpi_ec_init();
Zhang Ruia25ee922010-07-15 10:46:15 +08001097 acpi_debugfs_init();
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -06001098 acpi_sleep_proc_init();
Bjorn Helgaas201b8c62009-03-24 16:50:19 -06001099 acpi_wakeup_device_init();
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +01001100 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
1103subsys_initcall(acpi_init);