blob: cc17b352d1c53689555532af70937e9b8df37809 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060044#include "internal.h"
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050047ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Len Brown4be44fc2005-08-05 00:44:28 -040049struct acpi_device *acpi_root;
50struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051EXPORT_SYMBOL(acpi_root_dir);
52
53#define STRUCT_TO_INT(s) (*((int*)&s))
54
Zhao Yakui6415e122008-08-11 14:59:59 +080055static int set_power_nocheck(const struct dmi_system_id *id)
56{
57 printk(KERN_NOTICE PREFIX "%s detected - "
Lucas De Marchi58f87ed2010-09-07 12:49:45 -040058 "disable power check in power transition\n", id->ident);
Zhao Yakui6415e122008-08-11 14:59:59 +080059 acpi_power_nocheck = 1;
60 return 0;
61}
62static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
63 {
64 set_power_nocheck, "HP Pavilion 05", {
65 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
66 DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
67 DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
68 {},
69};
70
71
Lin Mingcce4f632010-05-12 09:26:48 +080072#ifdef CONFIG_X86
Lin Mingaa2110c2010-04-08 14:34:27 +080073static int set_copy_dsdt(const struct dmi_system_id *id)
74{
75 printk(KERN_NOTICE "%s detected - "
76 "force copy of DSDT to local memory\n", id->ident);
77 acpi_gbl_copy_dsdt_locally = 1;
78 return 0;
79}
80
81static struct dmi_system_id dsdt_dmi_table[] __initdata = {
82 /*
83 * Insyde BIOS on some TOSHIBA machines corrupt the DSDT.
84 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
85 */
86 {
87 .callback = set_copy_dsdt,
88 .ident = "TOSHIBA Satellite A505",
89 .matches = {
90 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
91 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite A505"),
92 },
93 },
94 {
95 .callback = set_copy_dsdt,
96 .ident = "TOSHIBA Satellite L505D",
97 .matches = {
98 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
99 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite L505D"),
100 },
Lin Mingcce4f632010-05-12 09:26:48 +0800101 },
102 {}
Lin Mingaa2110c2010-04-08 14:34:27 +0800103};
Lin Mingcce4f632010-05-12 09:26:48 +0800104#else
105static struct dmi_system_id dsdt_dmi_table[] __initdata = {
106 {}
107};
108#endif
Lin Mingaa2110c2010-04-08 14:34:27 +0800109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/* --------------------------------------------------------------------------
111 Device Management
112 -------------------------------------------------------------------------- */
113
Len Brown4be44fc2005-08-05 00:44:28 -0400114int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Len Brown4be44fc2005-08-05 00:44:28 -0400116 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400120 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 /* TBD: Support fixed-feature devices */
123
Len Brown4be44fc2005-08-05 00:44:28 -0400124 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (ACPI_FAILURE(status) || !*device) {
Len Brown9805cb72006-07-25 13:30:57 -0400126 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
127 handle));
Patrick Mocheld550d982006-06-27 00:41:40 -0400128 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130
Patrick Mocheld550d982006-06-27 00:41:40 -0400131 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
Len Brown4be44fc2005-08-05 00:44:28 -0400133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134EXPORT_SYMBOL(acpi_bus_get_device);
135
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000136acpi_status acpi_bus_get_status_handle(acpi_handle handle,
137 unsigned long long *sta)
138{
139 acpi_status status;
140
141 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
142 if (ACPI_SUCCESS(status))
143 return AE_OK;
144
145 if (status == AE_NOT_FOUND) {
146 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
147 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
148 return AE_OK;
149 }
150 return status;
151}
152
Len Brown4be44fc2005-08-05 00:44:28 -0400153int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000155 acpi_status status;
156 unsigned long long sta;
Len Brown4be44fc2005-08-05 00:44:28 -0400157
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000158 status = acpi_bus_get_status_handle(device->handle, &sta);
159 if (ACPI_FAILURE(status))
160 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000162 STRUCT_TO_INT(device->status) = (int) sta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800165 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
166 "functional but not present;\n",
167 device->pnp.bus_id,
168 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 }
170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
172 device->pnp.bus_id,
173 (u32) STRUCT_TO_INT(device->status)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400174 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
Len Brown4be44fc2005-08-05 00:44:28 -0400176EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Zhang Rui20733932008-01-17 15:51:21 +0800178void acpi_bus_private_data_handler(acpi_handle handle,
Bob Moore8e4319c2009-06-29 13:43:27 +0800179 void *context)
Zhang Rui20733932008-01-17 15:51:21 +0800180{
181 return;
182}
183EXPORT_SYMBOL(acpi_bus_private_data_handler);
184
185int acpi_bus_get_private_data(acpi_handle handle, void **data)
186{
187 acpi_status status = AE_OK;
188
189 if (!*data)
190 return -EINVAL;
191
192 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
193 if (ACPI_FAILURE(status) || !*data) {
194 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
195 handle));
196 return -ENODEV;
197 }
198
199 return 0;
200}
201EXPORT_SYMBOL(acpi_bus_get_private_data);
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203/* --------------------------------------------------------------------------
204 Power Management
205 -------------------------------------------------------------------------- */
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207int acpi_bus_get_power(acpi_handle handle, int *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Len Brown4be44fc2005-08-05 00:44:28 -0400209 int result = 0;
210 acpi_status status = 0;
211 struct acpi_device *device = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400212 unsigned long long psc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 result = acpi_bus_get_device(handle, &device);
216 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400217 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 *state = ACPI_STATE_UNKNOWN;
220
221 if (!device->flags.power_manageable) {
222 /* TBD: Non-recursive algorithm for walking up hierarchy */
223 if (device->parent)
224 *state = device->parent->power.state;
225 else
226 *state = ACPI_STATE_D0;
Len Brown4be44fc2005-08-05 00:44:28 -0400227 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /*
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500229 * Get the device's power state either directly (via _PSC) or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 * indirectly (via power resources).
231 */
Zhang Rui0c99c522009-12-17 16:02:08 +0800232 if (device->power.flags.power_resources) {
233 result = acpi_power_get_inferred_state(device);
234 if (result)
235 return result;
236 } else if (device->power.flags.explicit_get) {
Len Brown4be44fc2005-08-05 00:44:28 -0400237 status = acpi_evaluate_integer(device->handle, "_PSC",
238 NULL, &psc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400240 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400241 device->power.state = (int)psc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
243
244 *state = device->power.state;
245 }
246
247 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400248 device->pnp.bus_id, device->power.state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Patrick Mocheld550d982006-06-27 00:41:40 -0400250 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
Len Brown4be44fc2005-08-05 00:44:28 -0400252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253EXPORT_SYMBOL(acpi_bus_get_power);
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255int acpi_bus_set_power(acpi_handle handle, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Len Brown4be44fc2005-08-05 00:44:28 -0400257 int result = 0;
258 acpi_status status = AE_OK;
259 struct acpi_device *device = NULL;
260 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 result = acpi_bus_get_device(handle, &device);
264 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400265 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
Patrick Mocheld550d982006-06-27 00:41:40 -0400268 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Make sure this is a valid target state */
271
272 if (!device->flags.power_manageable) {
Len Brown9805cb72006-07-25 13:30:57 -0400273 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
Greg Kroah-Hartman19c38de2007-09-12 15:06:57 -0700274 kobject_name(&device->dev.kobj)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400275 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
David Shaohua Lib9131002005-03-19 00:16:18 -0500277 /*
Alexey Starikovskiyc35923b2007-10-22 14:19:09 +0400278 * Get device's current power state
David Shaohua Lib9131002005-03-19 00:16:18 -0500279 */
Zhao Yakuif5adfaa2008-08-11 14:57:50 +0800280 if (!acpi_power_nocheck) {
281 /*
282 * Maybe the incorrect power state is returned on the bogus
283 * bios, which is different with the real power state.
284 * For example: the bios returns D0 state and the real power
285 * state is D3. OS expects to set the device to D0 state. In
286 * such case if OS uses the power state returned by the BIOS,
287 * the device can't be transisted to the correct power state.
288 * So if the acpi_power_nocheck is set, it is unnecessary to
289 * get the power state by calling acpi_bus_get_power.
290 */
291 acpi_bus_get_power(device->handle, &device->power.state);
292 }
Len Brownec683732008-01-23 22:41:20 -0500293 if ((state == device->power.state) && !device->flags.force_power_state) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500294 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
295 state));
296 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (!device->power.states[state].flags.valid) {
Len Browncece9292006-06-26 23:04:31 -0400300 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
Patrick Mocheld550d982006-06-27 00:41:40 -0400301 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303 if (device->parent && (state < device->parent->power.state)) {
Len Browncece9292006-06-26 23:04:31 -0400304 printk(KERN_WARNING PREFIX
Thomas Renningera6fc6722006-06-26 23:58:43 -0400305 "Cannot set device to a higher-powered"
Len Browncece9292006-06-26 23:04:31 -0400306 " state than parent\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400307 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
309
310 /*
311 * Transition Power
312 * ----------------
313 * On transitions to a high-powered state we first apply power (via
314 * power resources) then evalute _PSx. Conversly for transitions to
315 * a lower-powered state.
David Shaohua Lib9131002005-03-19 00:16:18 -0500316 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 if (state < device->power.state) {
318 if (device->power.flags.power_resources) {
319 result = acpi_power_transition(device, state);
320 if (result)
321 goto end;
322 }
323 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 }
Len Brown4be44fc2005-08-05 00:44:28 -0400331 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400333 status = acpi_evaluate_object(device->handle,
334 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (ACPI_FAILURE(status)) {
336 result = -ENODEV;
337 goto end;
338 }
339 }
340 if (device->power.flags.power_resources) {
341 result = acpi_power_transition(device, state);
342 if (result)
343 goto end;
344 }
345 }
346
Len Brown4be44fc2005-08-05 00:44:28 -0400347 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (result)
Len Browncece9292006-06-26 23:04:31 -0400349 printk(KERN_WARNING PREFIX
Len Brownddc50b62009-05-08 00:07:30 -0400350 "Device [%s] failed to transition to D%d\n",
Len Browncece9292006-06-26 23:04:31 -0400351 device->pnp.bus_id, state);
Shaohua Li5e321322007-10-11 23:53:58 +0200352 else {
353 device->power.state = state;
Len Brown4be44fc2005-08-05 00:44:28 -0400354 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
355 "Device [%s] transitioned to D%d\n",
356 device->pnp.bus_id, state));
Shaohua Li5e321322007-10-11 23:53:58 +0200357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Patrick Mocheld550d982006-06-27 00:41:40 -0400359 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
Len Brown4be44fc2005-08-05 00:44:28 -0400361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362EXPORT_SYMBOL(acpi_bus_set_power);
363
Rafael J. Wysocki3737b2b2008-07-07 03:30:55 +0200364bool acpi_bus_power_manageable(acpi_handle handle)
365{
366 struct acpi_device *device;
367 int result;
368
369 result = acpi_bus_get_device(handle, &device);
370 return result ? false : device->flags.power_manageable;
371}
372
373EXPORT_SYMBOL(acpi_bus_power_manageable);
374
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200375bool acpi_bus_can_wakeup(acpi_handle handle)
376{
377 struct acpi_device *device;
378 int result;
379
380 result = acpi_bus_get_device(handle, &device);
381 return result ? false : device->wakeup.flags.valid;
382}
383
384EXPORT_SYMBOL(acpi_bus_can_wakeup);
385
Shaohua Li70023de2009-10-29 11:04:28 +0800386static void acpi_print_osc_error(acpi_handle handle,
387 struct acpi_osc_context *context, char *error)
388{
389 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
390 int i;
391
392 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
393 printk(KERN_DEBUG "%s\n", error);
394 else {
395 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
396 kfree(buffer.pointer);
397 }
398 printk(KERN_DEBUG"_OSC request data:");
399 for (i = 0; i < context->cap.length; i += sizeof(u32))
400 printk("%x ", *((u32 *)(context->cap.pointer + i)));
401 printk("\n");
402}
403
Shaohua Li70023de2009-10-29 11:04:28 +0800404static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
405{
406 int i;
407 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
408 24, 26, 28, 30, 32, 34};
409
410 if (strlen(str) != 36)
411 return AE_BAD_PARAMETER;
412 for (i = 0; i < 36; i++) {
413 if (i == 8 || i == 13 || i == 18 || i == 23) {
414 if (str[i] != '-')
415 return AE_BAD_PARAMETER;
416 } else if (!isxdigit(str[i]))
417 return AE_BAD_PARAMETER;
418 }
419 for (i = 0; i < 16; i++) {
Andy Shevchenko965fd9e2010-05-24 14:33:28 -0700420 uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
421 uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
Shaohua Li70023de2009-10-29 11:04:28 +0800422 }
423 return AE_OK;
424}
425
426acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
427{
428 acpi_status status;
429 struct acpi_object_list input;
430 union acpi_object in_params[4];
431 union acpi_object *out_obj;
432 u8 uuid[16];
433 u32 errors;
Shaohua Li9dc130f2009-12-23 17:04:11 +0800434 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
Shaohua Li70023de2009-10-29 11:04:28 +0800435
436 if (!context)
437 return AE_ERROR;
438 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
439 return AE_ERROR;
440 context->ret.length = ACPI_ALLOCATE_BUFFER;
441 context->ret.pointer = NULL;
442
443 /* Setting up input parameters */
444 input.count = 4;
445 input.pointer = in_params;
446 in_params[0].type = ACPI_TYPE_BUFFER;
447 in_params[0].buffer.length = 16;
448 in_params[0].buffer.pointer = uuid;
449 in_params[1].type = ACPI_TYPE_INTEGER;
450 in_params[1].integer.value = context->rev;
451 in_params[2].type = ACPI_TYPE_INTEGER;
452 in_params[2].integer.value = context->cap.length/sizeof(u32);
453 in_params[3].type = ACPI_TYPE_BUFFER;
454 in_params[3].buffer.length = context->cap.length;
455 in_params[3].buffer.pointer = context->cap.pointer;
456
Shaohua Li9dc130f2009-12-23 17:04:11 +0800457 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
Shaohua Li70023de2009-10-29 11:04:28 +0800458 if (ACPI_FAILURE(status))
459 return status;
460
Shaohua Li9dc130f2009-12-23 17:04:11 +0800461 if (!output.length)
Shaohua Li70023de2009-10-29 11:04:28 +0800462 return AE_NULL_OBJECT;
463
Shaohua Li9dc130f2009-12-23 17:04:11 +0800464 out_obj = output.pointer;
465 if (out_obj->type != ACPI_TYPE_BUFFER
466 || out_obj->buffer.length != context->cap.length) {
Shaohua Li70023de2009-10-29 11:04:28 +0800467 acpi_print_osc_error(handle, context,
468 "_OSC evaluation returned wrong type");
469 status = AE_TYPE;
470 goto out_kfree;
471 }
472 /* Need to ignore the bit0 in result code */
473 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
474 if (errors) {
475 if (errors & OSC_REQUEST_ERROR)
476 acpi_print_osc_error(handle, context,
477 "_OSC request failed");
478 if (errors & OSC_INVALID_UUID_ERROR)
479 acpi_print_osc_error(handle, context,
480 "_OSC invalid UUID");
481 if (errors & OSC_INVALID_REVISION_ERROR)
482 acpi_print_osc_error(handle, context,
483 "_OSC invalid revision");
484 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
485 if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
486 & OSC_QUERY_ENABLE)
487 goto out_success;
488 status = AE_SUPPORT;
489 goto out_kfree;
490 }
491 status = AE_ERROR;
492 goto out_kfree;
493 }
494out_success:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800495 context->ret.length = out_obj->buffer.length;
496 context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
497 if (!context->ret.pointer) {
498 status = AE_NO_MEMORY;
499 goto out_kfree;
500 }
501 memcpy(context->ret.pointer, out_obj->buffer.pointer,
502 context->ret.length);
503 status = AE_OK;
Shaohua Li70023de2009-10-29 11:04:28 +0800504
505out_kfree:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800506 kfree(output.pointer);
507 if (status != AE_OK)
508 context->ret.pointer = NULL;
Shaohua Li70023de2009-10-29 11:04:28 +0800509 return status;
510}
511EXPORT_SYMBOL(acpi_run_osc);
512
Shaohua Li3563ff92009-10-29 11:05:05 +0800513static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
514static void acpi_bus_osc_support(void)
515{
516 u32 capbuf[2];
517 struct acpi_osc_context context = {
518 .uuid_str = sb_uuid_str,
519 .rev = 1,
520 .cap.length = 8,
521 .cap.pointer = capbuf,
522 };
523 acpi_handle handle;
524
525 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
526 capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800527#if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
528 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
Shaohua Li3563ff92009-10-29 11:05:05 +0800529 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
530#endif
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800531
532#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
533 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PPC_OST_SUPPORT;
534#endif
Shaohua Li3563ff92009-10-29 11:05:05 +0800535 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
536 return;
537 if (ACPI_SUCCESS(acpi_run_osc(handle, &context)))
538 kfree(context.ret.pointer);
539 /* do we need to check the returned cap? Sounds no */
540}
541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542/* --------------------------------------------------------------------------
543 Event Management
544 -------------------------------------------------------------------------- */
545
Len Brown14e04fb2007-08-23 15:20:26 -0400546#ifdef CONFIG_ACPI_PROC_EVENT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547static DEFINE_SPINLOCK(acpi_bus_event_lock);
548
549LIST_HEAD(acpi_bus_event_list);
550DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
551
Len Brown4be44fc2005-08-05 00:44:28 -0400552extern int event_is_open;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400554int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400556 struct acpi_bus_event *event;
Len Brown4be44fc2005-08-05 00:44:28 -0400557 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 /* drop event on the floor if no one's listening */
560 if (!event_is_open)
Patrick Mocheld550d982006-06-27 00:41:40 -0400561 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Dan Carpenter5cc4a0f2010-04-27 00:23:37 +0200563 event = kzalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400565 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400567 strcpy(event->device_class, device_class);
568 strcpy(event->bus_id, bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 event->type = type;
570 event->data = data;
571
572 spin_lock_irqsave(&acpi_bus_event_lock, flags);
573 list_add_tail(&event->node, &acpi_bus_event_list);
574 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
575
576 wake_up_interruptible(&acpi_bus_event_queue);
577
Patrick Mocheld550d982006-06-27 00:41:40 -0400578 return 0;
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400579
580}
581
582EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
583
584int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
585{
586 if (!device)
587 return -EINVAL;
588 return acpi_bus_generate_proc_event4(device->pnp.device_class,
589 device->pnp.bus_id, type, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
Len Brown4be44fc2005-08-05 00:44:28 -0400591
Len Brown14e04fb2007-08-23 15:20:26 -0400592EXPORT_SYMBOL(acpi_bus_generate_proc_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Len Brown4be44fc2005-08-05 00:44:28 -0400594int acpi_bus_receive_event(struct acpi_bus_event *event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Len Brown4be44fc2005-08-05 00:44:28 -0400596 unsigned long flags = 0;
597 struct acpi_bus_event *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 DECLARE_WAITQUEUE(wait, current);
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400603 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 if (list_empty(&acpi_bus_event_list)) {
606
607 set_current_state(TASK_INTERRUPTIBLE);
608 add_wait_queue(&acpi_bus_event_queue, &wait);
609
610 if (list_empty(&acpi_bus_event_list))
611 schedule();
612
613 remove_wait_queue(&acpi_bus_event_queue, &wait);
614 set_current_state(TASK_RUNNING);
615
616 if (signal_pending(current))
Patrick Mocheld550d982006-06-27 00:41:40 -0400617 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 }
619
620 spin_lock_irqsave(&acpi_bus_event_lock, flags);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700621 if (!list_empty(&acpi_bus_event_list)) {
622 entry = list_entry(acpi_bus_event_list.next,
623 struct acpi_bus_event, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 list_del(&entry->node);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
627
628 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400629 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 memcpy(event, entry, sizeof(struct acpi_bus_event));
632
633 kfree(entry);
634
Patrick Mocheld550d982006-06-27 00:41:40 -0400635 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Len Brown14e04fb2007-08-23 15:20:26 -0400638#endif /* CONFIG_ACPI_PROC_EVENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640/* --------------------------------------------------------------------------
641 Notification Handling
642 -------------------------------------------------------------------------- */
643
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600644static void acpi_bus_check_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600646 struct acpi_device *device;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600647 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 struct acpi_device_status old_status;
649
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600650 if (acpi_bus_get_device(handle, &device))
651 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (!device)
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600653 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 old_status = device->status;
656
657 /*
658 * Make sure this device's parent is present before we go about
659 * messing with the device.
660 */
661 if (device->parent && !device->parent->status.present) {
662 device->status = device->parent->status;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600663 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
665
666 status = acpi_bus_get_status(device);
667 if (ACPI_FAILURE(status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600668 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600671 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 /*
674 * Device Insertion/Removal
675 */
676 if ((device->status.present) && !(old_status.present)) {
677 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
678 /* TBD: Handle device insertion */
Len Brown4be44fc2005-08-05 00:44:28 -0400679 } else if (!(device->status.present) && (old_status.present)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
681 /* TBD: Handle device removal */
682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600685static void acpi_bus_check_scope(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /* Status Change? */
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600688 acpi_bus_check_device(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 /*
691 * TBD: Enumerate child devices within this device's scope and
692 * run acpi_bus_check_device()'s on them.
693 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
695
Shaohua Li6bd00a62008-08-28 10:04:29 +0800696static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
697int register_acpi_bus_notifier(struct notifier_block *nb)
698{
699 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
700}
701EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
702
703void unregister_acpi_bus_notifier(struct notifier_block *nb)
704{
705 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
706}
707EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709/**
710 * acpi_bus_notify
711 * ---------------
712 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
713 */
Len Brown4be44fc2005-08-05 00:44:28 -0400714static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
Len Brown4be44fc2005-08-05 00:44:28 -0400716 struct acpi_device *device = NULL;
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600717 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Bjorn Helgaas02c37bd2009-05-22 11:43:41 -0600719 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
720 type, handle));
721
Shaohua Li6bd00a62008-08-28 10:04:29 +0800722 blocking_notifier_call_chain(&acpi_bus_notify_list,
723 type, (void *)handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 switch (type) {
726
727 case ACPI_NOTIFY_BUS_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600728 acpi_bus_check_scope(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500729 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400731 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 */
733 break;
734
735 case ACPI_NOTIFY_DEVICE_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600736 acpi_bus_check_device(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500737 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400739 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 */
741 break;
742
743 case ACPI_NOTIFY_DEVICE_WAKE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 /* TBD */
745 break;
746
747 case ACPI_NOTIFY_EJECT_REQUEST:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 /* TBD */
749 break;
750
751 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 /* TBD: Exactly what does 'light' mean? */
753 break;
754
755 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 /* TBD */
757 break;
758
759 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 /* TBD */
761 break;
762
763 case ACPI_NOTIFY_POWER_FAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 /* TBD */
765 break;
766
767 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400768 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
769 "Received unknown/unsupported notification [%08x]\n",
770 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 break;
772 }
773
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600774 acpi_bus_get_device(handle, &device);
775 if (device) {
776 driver = device->driver;
777 if (driver && driver->ops.notify &&
778 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
779 driver->ops.notify(device, type);
780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
783/* --------------------------------------------------------------------------
784 Initialization/Cleanup
785 -------------------------------------------------------------------------- */
786
Len Brown4be44fc2005-08-05 00:44:28 -0400787static int __init acpi_bus_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
Len Brown4be44fc2005-08-05 00:44:28 -0400789 acpi_status status = AE_OK;
790 union acpi_object arg = { ACPI_TYPE_INTEGER };
791 struct acpi_object_list arg_list = { 1, &arg };
792 char *message = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500795 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 * Let the system know what interrupt model we are using by
797 * evaluating the \_PIC object, if exists.
798 */
799
800 switch (acpi_irq_model) {
801 case ACPI_IRQ_MODEL_PIC:
802 message = "PIC";
803 break;
804 case ACPI_IRQ_MODEL_IOAPIC:
805 message = "IOAPIC";
806 break;
807 case ACPI_IRQ_MODEL_IOSAPIC:
808 message = "IOSAPIC";
809 break;
John Keller3948ec92006-12-22 11:50:04 -0600810 case ACPI_IRQ_MODEL_PLATFORM:
811 message = "platform specific model";
812 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 default:
814 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400815 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817
818 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
819
820 arg.integer.value = acpi_irq_model;
821
822 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
823 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400824 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400825 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
827
Patrick Mocheld550d982006-06-27 00:41:40 -0400828 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
830
Bob Moore67a119f2008-06-10 13:42:13 +0800831u8 acpi_gbl_permanent_mmap;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300832
833
Len Brown4be44fc2005-08-05 00:44:28 -0400834void __init acpi_early_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
Len Brown4be44fc2005-08-05 00:44:28 -0400836 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400839 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Bob Moore616861242006-03-17 16:44:00 -0500841 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 /* enable workarounds, unless strict ACPI spec. compliance */
844 if (!acpi_strict)
845 acpi_gbl_enable_interpreter_slack = TRUE;
846
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300847 acpi_gbl_permanent_mmap = 1;
848
Lin Mingaa2110c2010-04-08 14:34:27 +0800849 /*
850 * If the machine falls into the DMI check table,
851 * DSDT will be copied to memory
852 */
853 dmi_check_system(dsdt_dmi_table);
854
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300855 status = acpi_reallocate_root_table();
856 if (ACPI_FAILURE(status)) {
857 printk(KERN_ERR PREFIX
858 "Unable to reallocate ACPI tables\n");
859 goto error0;
860 }
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 status = acpi_initialize_subsystem();
863 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400864 printk(KERN_ERR PREFIX
865 "Unable to initialize the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 goto error0;
867 }
868
869 status = acpi_load_tables();
870 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400871 printk(KERN_ERR PREFIX
872 "Unable to load the System Description Tables\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 goto error0;
874 }
875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876#ifdef CONFIG_X86
877 if (!acpi_ioapic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 /* compatible (0) means level (3) */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300879 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
880 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
881 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 /* Set PIC-mode SCI trigger type */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300884 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300885 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 /*
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300888 * now that acpi_gbl_FADT is initialized,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 * update it with result from INT_SRC_OVR parsing
890 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300891 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893#endif
894
Len Brown4be44fc2005-08-05 00:44:28 -0400895 status =
896 acpi_enable_subsystem(~
897 (ACPI_NO_HARDWARE_INIT |
898 ACPI_NO_ACPI_ENABLE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 if (ACPI_FAILURE(status)) {
900 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
901 goto error0;
902 }
903
Patrick Mocheld550d982006-06-27 00:41:40 -0400904 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Len Brown4be44fc2005-08-05 00:44:28 -0400906 error0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 disable_acpi();
Patrick Mocheld550d982006-06-27 00:41:40 -0400908 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909}
910
Len Brown4be44fc2005-08-05 00:44:28 -0400911static int __init acpi_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
Len Brown4be44fc2005-08-05 00:44:28 -0400913 int result = 0;
914 acpi_status status = AE_OK;
915 extern acpi_status acpi_os_initialize1(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Jiri Slaby176f9c182009-03-04 11:55:27 -0800917 acpi_os_initialize1();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Len Brown4be44fc2005-08-05 00:44:28 -0400919 status =
920 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400922 printk(KERN_ERR PREFIX
923 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 goto error1;
925 }
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 /*
928 * ACPI 2.0 requires the EC driver to be loaded and work before
929 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
930 * is called).
931 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500932 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 * the EC parameters out of that.
934 */
935 status = acpi_ec_ecdt_probe();
936 /* Ignore result. Not having an ECDT is not fatal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Shaohua Li3563ff92009-10-29 11:05:05 +0800938 acpi_bus_osc_support();
939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
941 if (ACPI_FAILURE(status)) {
942 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
943 goto error1;
944 }
945
Alex Chiang78f16992009-12-20 12:19:09 -0700946 acpi_early_processor_set_pdc();
947
Zhao Yakui455c8792008-10-06 10:31:36 +0800948 /*
949 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
950 * is necessary to enable it as early as possible.
951 */
952 acpi_boot_ec_enable();
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 printk(KERN_INFO PREFIX "Interpreter enabled\n");
955
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500956 /* Initialize sleep structures */
957 acpi_sleep_init();
958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 /*
960 * Get the system interrupt model and evaluate \_PIC.
961 */
962 result = acpi_bus_init_irq();
963 if (result)
964 goto error1;
965
966 /*
967 * Register the for all standard device notifications.
968 */
Len Brown4be44fc2005-08-05 00:44:28 -0400969 status =
970 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
971 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400973 printk(KERN_ERR PREFIX
974 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 goto error1;
976 }
977
978 /*
979 * Create the top ACPI proc directory
980 */
981 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
982
Patrick Mocheld550d982006-06-27 00:41:40 -0400983 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -0400986 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -0400988 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700991struct kobject *acpi_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
Len Brown4be44fc2005-08-05 00:44:28 -0400993static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
Len Brown4be44fc2005-08-05 00:44:28 -0400995 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 if (acpi_disabled) {
999 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001000 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001003 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -07001004 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001005 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -07001006 acpi_kobj = NULL;
1007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Bjorn Helgaas0e465172009-03-24 16:50:09 -06001009 init_acpi_device_notify();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 result = acpi_bus_init();
1011
1012 if (!result) {
Robert Hancock7752d5c2008-02-15 01:27:20 -08001013 pci_mmcfg_late_init();
Len Brown9f9adec2007-12-13 17:38:03 -05001014 if (!(pm_flags & PM_APM))
1015 pm_flags |= PM_ACPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 else {
Len Brown4be44fc2005-08-05 00:44:28 -04001017 printk(KERN_INFO PREFIX
1018 "APM is already active, exiting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 disable_acpi();
1020 result = -ENODEV;
1021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 } else
1023 disable_acpi();
Bjorn Helgaas81d02732009-03-24 16:49:38 -06001024
1025 if (acpi_disabled)
1026 return result;
1027
Zhao Yakui6415e122008-08-11 14:59:59 +08001028 /*
1029 * If the laptop falls into the DMI check table, the power state check
Lucas De Marchi58f87ed2010-09-07 12:49:45 -04001030 * will be disabled in the course of device power transition.
Zhao Yakui6415e122008-08-11 14:59:59 +08001031 */
1032 dmi_check_system(power_nocheck_dmi_table);
Bjorn Helgaase747f272009-03-24 16:49:43 -06001033
1034 acpi_scan_init();
Bjorn Helgaasa5f820f2009-03-24 16:49:48 -06001035 acpi_ec_init();
Bjorn Helgaas44515372009-03-24 16:49:53 -06001036 acpi_power_init();
Zhang Rui1c8fce22010-07-15 10:46:30 +08001037 acpi_sysfs_init();
Zhang Ruia25ee922010-07-15 10:46:15 +08001038 acpi_debugfs_init();
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -06001039 acpi_sleep_proc_init();
Bjorn Helgaas201b8c62009-03-24 16:50:19 -06001040 acpi_wakeup_device_init();
Patrick Mocheld550d982006-06-27 00:41:40 -04001041 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042}
1043
1044subsys_initcall(acpi_init);