blob: 973b0709972c8ad3fddfe4ffaf56e046d47e643b [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>
Len Browneb27cae2009-07-06 23:40:19 -040042#include <linux/dmi.h>
Rafael J. Wysockicd51e61c2011-02-11 00:04:52 +010043#include <linux/suspend.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060045#include "internal.h"
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050048ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Len Brown4be44fc2005-08-05 00:44:28 -040050struct acpi_device *acpi_root;
51struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052EXPORT_SYMBOL(acpi_root_dir);
53
54#define STRUCT_TO_INT(s) (*((int*)&s))
55
Zhao Yakui6415e122008-08-11 14:59:59 +080056
Lin Mingcce4f632010-05-12 09:26:48 +080057#ifdef CONFIG_X86
Lin Mingaa2110c2010-04-08 14:34:27 +080058static int set_copy_dsdt(const struct dmi_system_id *id)
59{
60 printk(KERN_NOTICE "%s detected - "
61 "force copy of DSDT to local memory\n", id->ident);
62 acpi_gbl_copy_dsdt_locally = 1;
63 return 0;
64}
65
66static struct dmi_system_id dsdt_dmi_table[] __initdata = {
67 /*
Len Brown100cf872010-09-28 22:57:02 -040068 * Invoke DSDT corruption work-around on all Toshiba Satellite.
Lin Mingaa2110c2010-04-08 14:34:27 +080069 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
70 */
71 {
72 .callback = set_copy_dsdt,
Len Brown100cf872010-09-28 22:57:02 -040073 .ident = "TOSHIBA Satellite",
Lin Mingaa2110c2010-04-08 14:34:27 +080074 .matches = {
75 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Len Brown100cf872010-09-28 22:57:02 -040076 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
Lin Mingaa2110c2010-04-08 14:34:27 +080077 },
Lin Mingcce4f632010-05-12 09:26:48 +080078 },
79 {}
Lin Mingaa2110c2010-04-08 14:34:27 +080080};
Lin Mingcce4f632010-05-12 09:26:48 +080081#else
82static struct dmi_system_id dsdt_dmi_table[] __initdata = {
83 {}
84};
85#endif
Lin Mingaa2110c2010-04-08 14:34:27 +080086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087/* --------------------------------------------------------------------------
88 Device Management
89 -------------------------------------------------------------------------- */
90
Len Brown4be44fc2005-08-05 00:44:28 -040091int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Len Brown4be44fc2005-08-05 00:44:28 -040093 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -040097 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 /* TBD: Support fixed-feature devices */
100
Len Brown4be44fc2005-08-05 00:44:28 -0400101 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (ACPI_FAILURE(status) || !*device) {
Len Brown9805cb72006-07-25 13:30:57 -0400103 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
104 handle));
Patrick Mocheld550d982006-06-27 00:41:40 -0400105 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 }
107
Patrick Mocheld550d982006-06-27 00:41:40 -0400108 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
Len Brown4be44fc2005-08-05 00:44:28 -0400110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111EXPORT_SYMBOL(acpi_bus_get_device);
112
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000113acpi_status acpi_bus_get_status_handle(acpi_handle handle,
114 unsigned long long *sta)
115{
116 acpi_status status;
117
118 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
119 if (ACPI_SUCCESS(status))
120 return AE_OK;
121
122 if (status == AE_NOT_FOUND) {
123 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
124 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
125 return AE_OK;
126 }
127 return status;
128}
129
Len Brown4be44fc2005-08-05 00:44:28 -0400130int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000132 acpi_status status;
133 unsigned long long sta;
Len Brown4be44fc2005-08-05 00:44:28 -0400134
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000135 status = acpi_bus_get_status_handle(device->handle, &sta);
136 if (ACPI_FAILURE(status))
137 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000139 STRUCT_TO_INT(device->status) = (int) sta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800142 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
143 "functional but not present;\n",
144 device->pnp.bus_id,
145 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147
Len Brown4be44fc2005-08-05 00:44:28 -0400148 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
149 device->pnp.bus_id,
150 (u32) STRUCT_TO_INT(device->status)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400151 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
Len Brown4be44fc2005-08-05 00:44:28 -0400153EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Zhang Rui20733932008-01-17 15:51:21 +0800155void acpi_bus_private_data_handler(acpi_handle handle,
Bob Moore8e4319c2009-06-29 13:43:27 +0800156 void *context)
Zhang Rui20733932008-01-17 15:51:21 +0800157{
158 return;
159}
160EXPORT_SYMBOL(acpi_bus_private_data_handler);
161
162int acpi_bus_get_private_data(acpi_handle handle, void **data)
163{
164 acpi_status status = AE_OK;
165
166 if (!*data)
167 return -EINVAL;
168
169 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
170 if (ACPI_FAILURE(status) || !*data) {
171 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
172 handle));
173 return -ENODEV;
174 }
175
176 return 0;
177}
178EXPORT_SYMBOL(acpi_bus_get_private_data);
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/* --------------------------------------------------------------------------
181 Power Management
182 -------------------------------------------------------------------------- */
183
Rafael J. Wysocki5e6d4fe42010-11-25 00:07:56 +0100184static int __acpi_bus_get_power(struct acpi_device *device, int *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Len Brown4be44fc2005-08-05 00:44:28 -0400186 int result = 0;
187 acpi_status status = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400188 unsigned long long psc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Rafael J. Wysocki5e6d4fe42010-11-25 00:07:56 +0100190 if (!device || !state)
191 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 *state = ACPI_STATE_UNKNOWN;
194
Rafael J. Wysocki5e6d4fe42010-11-25 00:07:56 +0100195 if (device->flags.power_manageable) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 /*
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500197 * Get the device's power state either directly (via _PSC) or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 * indirectly (via power resources).
199 */
Zhang Rui0c99c522009-12-17 16:02:08 +0800200 if (device->power.flags.power_resources) {
Rafael J. Wysocki5e6d4fe42010-11-25 00:07:56 +0100201 result = acpi_power_get_inferred_state(device, state);
Zhang Rui0c99c522009-12-17 16:02:08 +0800202 if (result)
203 return result;
204 } else if (device->power.flags.explicit_get) {
Len Brown4be44fc2005-08-05 00:44:28 -0400205 status = acpi_evaluate_integer(device->handle, "_PSC",
206 NULL, &psc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400208 return -ENODEV;
Rafael J. Wysocki5e6d4fe42010-11-25 00:07:56 +0100209 *state = (int)psc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
Rafael J. Wysocki5e6d4fe42010-11-25 00:07:56 +0100211 } else {
212 /* TBD: Non-recursive algorithm for walking up hierarchy. */
213 *state = device->parent ?
214 device->parent->power.state : ACPI_STATE_D0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
217 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
Rafael J. Wysocki5e6d4fe42010-11-25 00:07:56 +0100218 device->pnp.bus_id, *state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Patrick Mocheld550d982006-06-27 00:41:40 -0400220 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
Len Brown4be44fc2005-08-05 00:44:28 -0400222
Rafael J. Wysocki5e6d4fe42010-11-25 00:07:56 +0100223
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100224static int __acpi_bus_set_power(struct acpi_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Len Brown4be44fc2005-08-05 00:44:28 -0400226 int result = 0;
227 acpi_status status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400228 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100230 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
Patrick Mocheld550d982006-06-27 00:41:40 -0400231 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 /* Make sure this is a valid target state */
234
Rafael J. Wysocki488a76c2010-11-25 00:11:24 +0100235 if (state == device->power.state) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500236 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
237 state));
238 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (!device->power.states[state].flags.valid) {
Len Browncece9292006-06-26 23:04:31 -0400242 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
Patrick Mocheld550d982006-06-27 00:41:40 -0400243 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245 if (device->parent && (state < device->parent->power.state)) {
Len Browncece9292006-06-26 23:04:31 -0400246 printk(KERN_WARNING PREFIX
Thomas Renningera6fc6722006-06-26 23:58:43 -0400247 "Cannot set device to a higher-powered"
Len Browncece9292006-06-26 23:04:31 -0400248 " state than parent\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400249 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251
252 /*
253 * Transition Power
254 * ----------------
255 * On transitions to a high-powered state we first apply power (via
256 * power resources) then evalute _PSx. Conversly for transitions to
257 * a lower-powered state.
David Shaohua Lib9131002005-03-19 00:16:18 -0500258 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 if (state < device->power.state) {
260 if (device->power.flags.power_resources) {
261 result = acpi_power_transition(device, state);
262 if (result)
263 goto end;
264 }
265 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400266 status = acpi_evaluate_object(device->handle,
267 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 if (ACPI_FAILURE(status)) {
269 result = -ENODEV;
270 goto end;
271 }
272 }
Len Brown4be44fc2005-08-05 00:44:28 -0400273 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400275 status = acpi_evaluate_object(device->handle,
276 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (ACPI_FAILURE(status)) {
278 result = -ENODEV;
279 goto end;
280 }
281 }
282 if (device->power.flags.power_resources) {
283 result = acpi_power_transition(device, state);
284 if (result)
285 goto end;
286 }
287 }
288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 if (result)
Len Browncece9292006-06-26 23:04:31 -0400291 printk(KERN_WARNING PREFIX
Len Brownddc50b62009-05-08 00:07:30 -0400292 "Device [%s] failed to transition to D%d\n",
Len Browncece9292006-06-26 23:04:31 -0400293 device->pnp.bus_id, state);
Shaohua Li5e321322007-10-11 23:53:58 +0200294 else {
295 device->power.state = state;
Len Brown4be44fc2005-08-05 00:44:28 -0400296 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
297 "Device [%s] transitioned to D%d\n",
298 device->pnp.bus_id, state));
Shaohua Li5e321322007-10-11 23:53:58 +0200299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Patrick Mocheld550d982006-06-27 00:41:40 -0400301 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
Len Brown4be44fc2005-08-05 00:44:28 -0400303
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100304
305int acpi_bus_set_power(acpi_handle handle, int state)
306{
307 struct acpi_device *device;
308 int result;
309
310 result = acpi_bus_get_device(handle, &device);
311 if (result)
312 return result;
313
314 if (!device->flags.power_manageable) {
315 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
316 "Device [%s] is not power manageable\n",
317 dev_name(&device->dev)));
318 return -ENODEV;
319 }
320
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100321 return __acpi_bus_set_power(device, state);
322}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323EXPORT_SYMBOL(acpi_bus_set_power);
324
Rafael J. Wysockiade3e7f2010-11-25 00:08:36 +0100325
326int acpi_bus_init_power(struct acpi_device *device)
327{
328 int state;
329 int result;
330
331 if (!device)
332 return -EINVAL;
333
334 device->power.state = ACPI_STATE_UNKNOWN;
335
336 result = __acpi_bus_get_power(device, &state);
337 if (result)
338 return result;
339
340 if (device->power.flags.power_resources)
341 result = acpi_power_on_resources(device, state);
342
343 if (!result)
344 device->power.state = state;
345
346 return result;
347}
348
349
Rafael J. Wysocki25eed402010-11-25 00:09:15 +0100350int acpi_bus_update_power(acpi_handle handle, int *state_p)
351{
352 struct acpi_device *device;
353 int state;
354 int result;
355
356 result = acpi_bus_get_device(handle, &device);
357 if (result)
358 return result;
359
360 result = __acpi_bus_get_power(device, &state);
361 if (result)
362 return result;
363
364 result = __acpi_bus_set_power(device, state);
365 if (!result && state_p)
366 *state_p = state;
367
368 return result;
369}
370EXPORT_SYMBOL_GPL(acpi_bus_update_power);
371
372
Rafael J. Wysocki3737b2b2008-07-07 03:30:55 +0200373bool acpi_bus_power_manageable(acpi_handle handle)
374{
375 struct acpi_device *device;
376 int result;
377
378 result = acpi_bus_get_device(handle, &device);
379 return result ? false : device->flags.power_manageable;
380}
381
382EXPORT_SYMBOL(acpi_bus_power_manageable);
383
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200384bool acpi_bus_can_wakeup(acpi_handle handle)
385{
386 struct acpi_device *device;
387 int result;
388
389 result = acpi_bus_get_device(handle, &device);
390 return result ? false : device->wakeup.flags.valid;
391}
392
393EXPORT_SYMBOL(acpi_bus_can_wakeup);
394
Shaohua Li70023de2009-10-29 11:04:28 +0800395static void acpi_print_osc_error(acpi_handle handle,
396 struct acpi_osc_context *context, char *error)
397{
398 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
399 int i;
400
401 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
402 printk(KERN_DEBUG "%s\n", error);
403 else {
404 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
405 kfree(buffer.pointer);
406 }
407 printk(KERN_DEBUG"_OSC request data:");
408 for (i = 0; i < context->cap.length; i += sizeof(u32))
409 printk("%x ", *((u32 *)(context->cap.pointer + i)));
410 printk("\n");
411}
412
Shaohua Li70023de2009-10-29 11:04:28 +0800413static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
414{
415 int i;
416 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
417 24, 26, 28, 30, 32, 34};
418
419 if (strlen(str) != 36)
420 return AE_BAD_PARAMETER;
421 for (i = 0; i < 36; i++) {
422 if (i == 8 || i == 13 || i == 18 || i == 23) {
423 if (str[i] != '-')
424 return AE_BAD_PARAMETER;
425 } else if (!isxdigit(str[i]))
426 return AE_BAD_PARAMETER;
427 }
428 for (i = 0; i < 16; i++) {
Andy Shevchenko965fd9e2010-05-24 14:33:28 -0700429 uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
430 uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
Shaohua Li70023de2009-10-29 11:04:28 +0800431 }
432 return AE_OK;
433}
434
435acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
436{
437 acpi_status status;
438 struct acpi_object_list input;
439 union acpi_object in_params[4];
440 union acpi_object *out_obj;
441 u8 uuid[16];
442 u32 errors;
Shaohua Li9dc130f2009-12-23 17:04:11 +0800443 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
Shaohua Li70023de2009-10-29 11:04:28 +0800444
445 if (!context)
446 return AE_ERROR;
447 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
448 return AE_ERROR;
449 context->ret.length = ACPI_ALLOCATE_BUFFER;
450 context->ret.pointer = NULL;
451
452 /* Setting up input parameters */
453 input.count = 4;
454 input.pointer = in_params;
455 in_params[0].type = ACPI_TYPE_BUFFER;
456 in_params[0].buffer.length = 16;
457 in_params[0].buffer.pointer = uuid;
458 in_params[1].type = ACPI_TYPE_INTEGER;
459 in_params[1].integer.value = context->rev;
460 in_params[2].type = ACPI_TYPE_INTEGER;
461 in_params[2].integer.value = context->cap.length/sizeof(u32);
462 in_params[3].type = ACPI_TYPE_BUFFER;
463 in_params[3].buffer.length = context->cap.length;
464 in_params[3].buffer.pointer = context->cap.pointer;
465
Shaohua Li9dc130f2009-12-23 17:04:11 +0800466 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
Shaohua Li70023de2009-10-29 11:04:28 +0800467 if (ACPI_FAILURE(status))
468 return status;
469
Shaohua Li9dc130f2009-12-23 17:04:11 +0800470 if (!output.length)
Shaohua Li70023de2009-10-29 11:04:28 +0800471 return AE_NULL_OBJECT;
472
Shaohua Li9dc130f2009-12-23 17:04:11 +0800473 out_obj = output.pointer;
474 if (out_obj->type != ACPI_TYPE_BUFFER
475 || out_obj->buffer.length != context->cap.length) {
Shaohua Li70023de2009-10-29 11:04:28 +0800476 acpi_print_osc_error(handle, context,
477 "_OSC evaluation returned wrong type");
478 status = AE_TYPE;
479 goto out_kfree;
480 }
481 /* Need to ignore the bit0 in result code */
482 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
483 if (errors) {
484 if (errors & OSC_REQUEST_ERROR)
485 acpi_print_osc_error(handle, context,
486 "_OSC request failed");
487 if (errors & OSC_INVALID_UUID_ERROR)
488 acpi_print_osc_error(handle, context,
489 "_OSC invalid UUID");
490 if (errors & OSC_INVALID_REVISION_ERROR)
491 acpi_print_osc_error(handle, context,
492 "_OSC invalid revision");
493 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
494 if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
495 & OSC_QUERY_ENABLE)
496 goto out_success;
497 status = AE_SUPPORT;
498 goto out_kfree;
499 }
500 status = AE_ERROR;
501 goto out_kfree;
502 }
503out_success:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800504 context->ret.length = out_obj->buffer.length;
505 context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
506 if (!context->ret.pointer) {
507 status = AE_NO_MEMORY;
508 goto out_kfree;
509 }
510 memcpy(context->ret.pointer, out_obj->buffer.pointer,
511 context->ret.length);
512 status = AE_OK;
Shaohua Li70023de2009-10-29 11:04:28 +0800513
514out_kfree:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800515 kfree(output.pointer);
516 if (status != AE_OK)
517 context->ret.pointer = NULL;
Shaohua Li70023de2009-10-29 11:04:28 +0800518 return status;
519}
520EXPORT_SYMBOL(acpi_run_osc);
521
Shaohua Li3563ff92009-10-29 11:05:05 +0800522static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
523static void acpi_bus_osc_support(void)
524{
525 u32 capbuf[2];
526 struct acpi_osc_context context = {
527 .uuid_str = sb_uuid_str,
528 .rev = 1,
529 .cap.length = 8,
530 .cap.pointer = capbuf,
531 };
532 acpi_handle handle;
533
534 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
535 capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800536#if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
537 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
Shaohua Li3563ff92009-10-29 11:05:05 +0800538 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
539#endif
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800540
541#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
542 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PPC_OST_SUPPORT;
543#endif
Shaohua Li3563ff92009-10-29 11:05:05 +0800544 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
545 return;
546 if (ACPI_SUCCESS(acpi_run_osc(handle, &context)))
547 kfree(context.ret.pointer);
548 /* do we need to check the returned cap? Sounds no */
549}
550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551/* --------------------------------------------------------------------------
552 Event Management
553 -------------------------------------------------------------------------- */
554
Len Brown14e04fb32007-08-23 15:20:26 -0400555#ifdef CONFIG_ACPI_PROC_EVENT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556static DEFINE_SPINLOCK(acpi_bus_event_lock);
557
558LIST_HEAD(acpi_bus_event_list);
559DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561extern int event_is_open;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400563int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400565 struct acpi_bus_event *event;
Len Brown4be44fc2005-08-05 00:44:28 -0400566 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 /* drop event on the floor if no one's listening */
569 if (!event_is_open)
Patrick Mocheld550d982006-06-27 00:41:40 -0400570 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Dan Carpenter5cc4a0f2010-04-27 00:23:37 +0200572 event = kzalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400574 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400576 strcpy(event->device_class, device_class);
577 strcpy(event->bus_id, bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 event->type = type;
579 event->data = data;
580
581 spin_lock_irqsave(&acpi_bus_event_lock, flags);
582 list_add_tail(&event->node, &acpi_bus_event_list);
583 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
584
585 wake_up_interruptible(&acpi_bus_event_queue);
586
Patrick Mocheld550d982006-06-27 00:41:40 -0400587 return 0;
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400588
589}
590
591EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
592
593int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
594{
595 if (!device)
596 return -EINVAL;
597 return acpi_bus_generate_proc_event4(device->pnp.device_class,
598 device->pnp.bus_id, type, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
Len Brown4be44fc2005-08-05 00:44:28 -0400600
Len Brown14e04fb32007-08-23 15:20:26 -0400601EXPORT_SYMBOL(acpi_bus_generate_proc_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Len Brown4be44fc2005-08-05 00:44:28 -0400603int acpi_bus_receive_event(struct acpi_bus_event *event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Len Brown4be44fc2005-08-05 00:44:28 -0400605 unsigned long flags = 0;
606 struct acpi_bus_event *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608 DECLARE_WAITQUEUE(wait, current);
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400612 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 if (list_empty(&acpi_bus_event_list)) {
615
616 set_current_state(TASK_INTERRUPTIBLE);
617 add_wait_queue(&acpi_bus_event_queue, &wait);
618
619 if (list_empty(&acpi_bus_event_list))
620 schedule();
621
622 remove_wait_queue(&acpi_bus_event_queue, &wait);
623 set_current_state(TASK_RUNNING);
624
625 if (signal_pending(current))
Patrick Mocheld550d982006-06-27 00:41:40 -0400626 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 }
628
629 spin_lock_irqsave(&acpi_bus_event_lock, flags);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700630 if (!list_empty(&acpi_bus_event_list)) {
631 entry = list_entry(acpi_bus_event_list.next,
632 struct acpi_bus_event, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 list_del(&entry->node);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
636
637 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400638 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 memcpy(event, entry, sizeof(struct acpi_bus_event));
641
642 kfree(entry);
643
Patrick Mocheld550d982006-06-27 00:41:40 -0400644 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Len Brown14e04fb32007-08-23 15:20:26 -0400647#endif /* CONFIG_ACPI_PROC_EVENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649/* --------------------------------------------------------------------------
650 Notification Handling
651 -------------------------------------------------------------------------- */
652
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600653static void acpi_bus_check_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600655 struct acpi_device *device;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600656 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 struct acpi_device_status old_status;
658
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600659 if (acpi_bus_get_device(handle, &device))
660 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 if (!device)
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600662 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 old_status = device->status;
665
666 /*
667 * Make sure this device's parent is present before we go about
668 * messing with the device.
669 */
670 if (device->parent && !device->parent->status.present) {
671 device->status = device->parent->status;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600672 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674
675 status = acpi_bus_get_status(device);
676 if (ACPI_FAILURE(status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600677 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600680 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /*
683 * Device Insertion/Removal
684 */
685 if ((device->status.present) && !(old_status.present)) {
686 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
687 /* TBD: Handle device insertion */
Len Brown4be44fc2005-08-05 00:44:28 -0400688 } else if (!(device->status.present) && (old_status.present)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
690 /* TBD: Handle device removal */
691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600694static void acpi_bus_check_scope(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 /* Status Change? */
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600697 acpi_bus_check_device(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 /*
700 * TBD: Enumerate child devices within this device's scope and
701 * run acpi_bus_check_device()'s on them.
702 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
Shaohua Li6bd00a62008-08-28 10:04:29 +0800705static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
706int register_acpi_bus_notifier(struct notifier_block *nb)
707{
708 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
709}
710EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
711
712void unregister_acpi_bus_notifier(struct notifier_block *nb)
713{
714 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
715}
716EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718/**
719 * acpi_bus_notify
720 * ---------------
721 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
722 */
Len Brown4be44fc2005-08-05 00:44:28 -0400723static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
Len Brown4be44fc2005-08-05 00:44:28 -0400725 struct acpi_device *device = NULL;
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600726 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Bjorn Helgaas02c37bd2009-05-22 11:43:41 -0600728 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
729 type, handle));
730
Shaohua Li6bd00a62008-08-28 10:04:29 +0800731 blocking_notifier_call_chain(&acpi_bus_notify_list,
732 type, (void *)handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 switch (type) {
735
736 case ACPI_NOTIFY_BUS_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600737 acpi_bus_check_scope(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500738 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400740 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 */
742 break;
743
744 case ACPI_NOTIFY_DEVICE_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600745 acpi_bus_check_device(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500746 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400748 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 */
750 break;
751
752 case ACPI_NOTIFY_DEVICE_WAKE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 /* TBD */
754 break;
755
756 case ACPI_NOTIFY_EJECT_REQUEST:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 /* TBD */
758 break;
759
760 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 /* TBD: Exactly what does 'light' mean? */
762 break;
763
764 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 /* TBD */
766 break;
767
768 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 /* TBD */
770 break;
771
772 case ACPI_NOTIFY_POWER_FAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 /* TBD */
774 break;
775
776 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400777 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
778 "Received unknown/unsupported notification [%08x]\n",
779 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 break;
781 }
782
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600783 acpi_bus_get_device(handle, &device);
784 if (device) {
785 driver = device->driver;
786 if (driver && driver->ops.notify &&
787 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
788 driver->ops.notify(device, type);
789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
791
792/* --------------------------------------------------------------------------
793 Initialization/Cleanup
794 -------------------------------------------------------------------------- */
795
Len Brown4be44fc2005-08-05 00:44:28 -0400796static int __init acpi_bus_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
Len Brown4be44fc2005-08-05 00:44:28 -0400798 acpi_status status = AE_OK;
799 union acpi_object arg = { ACPI_TYPE_INTEGER };
800 struct acpi_object_list arg_list = { 1, &arg };
801 char *message = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500804 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 * Let the system know what interrupt model we are using by
806 * evaluating the \_PIC object, if exists.
807 */
808
809 switch (acpi_irq_model) {
810 case ACPI_IRQ_MODEL_PIC:
811 message = "PIC";
812 break;
813 case ACPI_IRQ_MODEL_IOAPIC:
814 message = "IOAPIC";
815 break;
816 case ACPI_IRQ_MODEL_IOSAPIC:
817 message = "IOSAPIC";
818 break;
John Keller3948ec92006-12-22 11:50:04 -0600819 case ACPI_IRQ_MODEL_PLATFORM:
820 message = "platform specific model";
821 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 default:
823 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400824 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 }
826
827 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
828
829 arg.integer.value = acpi_irq_model;
830
831 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
832 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400833 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400834 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836
Patrick Mocheld550d982006-06-27 00:41:40 -0400837 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838}
839
Bob Moore67a119f2008-06-10 13:42:13 +0800840u8 acpi_gbl_permanent_mmap;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300841
842
Len Brown4be44fc2005-08-05 00:44:28 -0400843void __init acpi_early_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
Len Brown4be44fc2005-08-05 00:44:28 -0400845 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400848 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Bob Moore616861242006-03-17 16:44:00 -0500850 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 /* enable workarounds, unless strict ACPI spec. compliance */
853 if (!acpi_strict)
854 acpi_gbl_enable_interpreter_slack = TRUE;
855
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300856 acpi_gbl_permanent_mmap = 1;
857
Lin Mingaa2110c2010-04-08 14:34:27 +0800858 /*
859 * If the machine falls into the DMI check table,
860 * DSDT will be copied to memory
861 */
862 dmi_check_system(dsdt_dmi_table);
863
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300864 status = acpi_reallocate_root_table();
865 if (ACPI_FAILURE(status)) {
866 printk(KERN_ERR PREFIX
867 "Unable to reallocate ACPI tables\n");
868 goto error0;
869 }
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 status = acpi_initialize_subsystem();
872 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400873 printk(KERN_ERR PREFIX
874 "Unable to initialize the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 goto error0;
876 }
877
878 status = acpi_load_tables();
879 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400880 printk(KERN_ERR PREFIX
881 "Unable to load the System Description Tables\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 goto error0;
883 }
884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885#ifdef CONFIG_X86
886 if (!acpi_ioapic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 /* compatible (0) means level (3) */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300888 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
889 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
890 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 /* Set PIC-mode SCI trigger type */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300893 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300894 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 /*
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300897 * now that acpi_gbl_FADT is initialized,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 * update it with result from INT_SRC_OVR parsing
899 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300900 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
902#endif
903
Len Brown4be44fc2005-08-05 00:44:28 -0400904 status =
905 acpi_enable_subsystem(~
906 (ACPI_NO_HARDWARE_INIT |
907 ACPI_NO_ACPI_ENABLE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 if (ACPI_FAILURE(status)) {
909 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
910 goto error0;
911 }
912
Patrick Mocheld550d982006-06-27 00:41:40 -0400913 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Len Brown4be44fc2005-08-05 00:44:28 -0400915 error0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 disable_acpi();
Patrick Mocheld550d982006-06-27 00:41:40 -0400917 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
Len Brown4be44fc2005-08-05 00:44:28 -0400920static int __init acpi_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Len Brown4be44fc2005-08-05 00:44:28 -0400922 int result = 0;
923 acpi_status status = AE_OK;
924 extern acpi_status acpi_os_initialize1(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Jiri Slaby176f9c12009-03-04 11:55:27 -0800926 acpi_os_initialize1();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Len Brown4be44fc2005-08-05 00:44:28 -0400928 status =
929 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400931 printk(KERN_ERR PREFIX
932 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 goto error1;
934 }
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 /*
937 * ACPI 2.0 requires the EC driver to be loaded and work before
938 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
939 * is called).
940 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500941 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 * the EC parameters out of that.
943 */
944 status = acpi_ec_ecdt_probe();
945 /* Ignore result. Not having an ECDT is not fatal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Shaohua Li3563ff92009-10-29 11:05:05 +0800947 acpi_bus_osc_support();
948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
950 if (ACPI_FAILURE(status)) {
951 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
952 goto error1;
953 }
954
Zhang Ruib1d248d2010-10-26 10:06:54 +0800955 /*
956 * _PDC control method may load dynamic SSDT tables,
957 * and we need to install the table handler before that.
958 */
959 acpi_sysfs_init();
960
Alex Chiang78f16992009-12-20 12:19:09 -0700961 acpi_early_processor_set_pdc();
962
Zhao Yakui455c8792008-10-06 10:31:36 +0800963 /*
964 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
965 * is necessary to enable it as early as possible.
966 */
967 acpi_boot_ec_enable();
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 printk(KERN_INFO PREFIX "Interpreter enabled\n");
970
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500971 /* Initialize sleep structures */
972 acpi_sleep_init();
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 /*
975 * Get the system interrupt model and evaluate \_PIC.
976 */
977 result = acpi_bus_init_irq();
978 if (result)
979 goto error1;
980
981 /*
982 * Register the for all standard device notifications.
983 */
Len Brown4be44fc2005-08-05 00:44:28 -0400984 status =
985 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
986 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400988 printk(KERN_ERR PREFIX
989 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 goto error1;
991 }
992
993 /*
994 * Create the top ACPI proc directory
995 */
996 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
997
Patrick Mocheld550d982006-06-27 00:41:40 -0400998 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -04001001 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -04001003 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -07001006struct kobject *acpi_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Len Brown4be44fc2005-08-05 00:44:28 -04001008static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
Len Brown4be44fc2005-08-05 00:44:28 -04001010 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if (acpi_disabled) {
1014 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001015 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 }
1017
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001018 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -07001019 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001020 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -07001021 acpi_kobj = NULL;
1022 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Bjorn Helgaas0e46517d2009-03-24 16:50:09 -06001024 init_acpi_device_notify();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 result = acpi_bus_init();
1026
1027 if (!result) {
Robert Hancock7752d5c2008-02-15 01:27:20 -08001028 pci_mmcfg_late_init();
Rafael J. Wysockicd51e61c2011-02-11 00:04:52 +01001029 if (pm_apm_enabled()) {
Len Brown4be44fc2005-08-05 00:44:28 -04001030 printk(KERN_INFO PREFIX
1031 "APM is already active, exiting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 disable_acpi();
1033 result = -ENODEV;
Rafael J. Wysockicd51e61c2011-02-11 00:04:52 +01001034 } else {
1035 pm_set_acpi_flag();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 } else
1038 disable_acpi();
Bjorn Helgaas81d02732009-03-24 16:49:38 -06001039
1040 if (acpi_disabled)
1041 return result;
1042
Bjorn Helgaase747f272009-03-24 16:49:43 -06001043 acpi_scan_init();
Bjorn Helgaasa5f820f2009-03-24 16:49:48 -06001044 acpi_ec_init();
Zhang Ruia25ee922010-07-15 10:46:15 +08001045 acpi_debugfs_init();
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -06001046 acpi_sleep_proc_init();
Bjorn Helgaas201b8c62009-03-24 16:50:19 -06001047 acpi_wakeup_device_init();
Patrick Mocheld550d982006-06-27 00:41:40 -04001048 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
1051subsys_initcall(acpi_init);