blob: 135fbfe1825c94a5052fef82c0970e6e1f20fdcc [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#ifdef CONFIG_X86
36#include <asm/mpspec.h>
37#endif
Robert Hancock7752d5c2008-02-15 01:27:20 -080038#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <acpi/acpi_bus.h>
40#include <acpi/acpi_drivers.h>
Len Browneb27cae2009-07-06 23:40:19 -040041#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060043#include "internal.h"
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050046ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Len Brown4be44fc2005-08-05 00:44:28 -040048struct acpi_device *acpi_root;
49struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050EXPORT_SYMBOL(acpi_root_dir);
51
52#define STRUCT_TO_INT(s) (*((int*)&s))
53
Zhao Yakui6415e122008-08-11 14:59:59 +080054static int set_power_nocheck(const struct dmi_system_id *id)
55{
56 printk(KERN_NOTICE PREFIX "%s detected - "
57 "disable power check in power transistion\n", id->ident);
58 acpi_power_nocheck = 1;
59 return 0;
60}
61static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
62 {
63 set_power_nocheck, "HP Pavilion 05", {
64 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
65 DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
66 DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
67 {},
68};
69
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* --------------------------------------------------------------------------
72 Device Management
73 -------------------------------------------------------------------------- */
74
Len Brown4be44fc2005-08-05 00:44:28 -040075int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Len Brown4be44fc2005-08-05 00:44:28 -040077 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -040081 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 /* TBD: Support fixed-feature devices */
84
Len Brown4be44fc2005-08-05 00:44:28 -040085 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if (ACPI_FAILURE(status) || !*device) {
Len Brown9805cb72006-07-25 13:30:57 -040087 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
88 handle));
Patrick Mocheld550d982006-06-27 00:41:40 -040089 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91
Patrick Mocheld550d982006-06-27 00:41:40 -040092 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
Len Brown4be44fc2005-08-05 00:44:28 -040094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095EXPORT_SYMBOL(acpi_bus_get_device);
96
Len Brown4be44fc2005-08-05 00:44:28 -040097int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Len Brown4be44fc2005-08-05 00:44:28 -040099 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400100 unsigned long long sta = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400104 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 /*
107 * Evaluate _STA if present.
108 */
109 if (device->flags.dynamic_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400110 status =
111 acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400113 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400114 STRUCT_TO_INT(device->status) = (int)sta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
116
117 /*
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800118 * According to ACPI spec some device can be present and functional
119 * even if the parent is not present but functional.
120 * In such conditions the child device should not inherit the status
121 * from the parent.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 else
Bjorn Helgaas0c0e8922007-04-25 14:20:58 -0400124 STRUCT_TO_INT(device->status) =
125 ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
126 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800129 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
130 "functional but not present;\n",
131 device->pnp.bus_id,
132 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134
Len Brown4be44fc2005-08-05 00:44:28 -0400135 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
136 device->pnp.bus_id,
137 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Patrick Mocheld550d982006-06-27 00:41:40 -0400139 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Len Brown4be44fc2005-08-05 00:44:28 -0400142EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Zhang Rui20733932008-01-17 15:51:21 +0800144void acpi_bus_private_data_handler(acpi_handle handle,
Bob Moore8e4319c2009-06-29 13:43:27 +0800145 void *context)
Zhang Rui20733932008-01-17 15:51:21 +0800146{
147 return;
148}
149EXPORT_SYMBOL(acpi_bus_private_data_handler);
150
151int acpi_bus_get_private_data(acpi_handle handle, void **data)
152{
153 acpi_status status = AE_OK;
154
155 if (!*data)
156 return -EINVAL;
157
158 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
159 if (ACPI_FAILURE(status) || !*data) {
160 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
161 handle));
162 return -ENODEV;
163 }
164
165 return 0;
166}
167EXPORT_SYMBOL(acpi_bus_get_private_data);
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/* --------------------------------------------------------------------------
170 Power Management
171 -------------------------------------------------------------------------- */
172
Len Brown4be44fc2005-08-05 00:44:28 -0400173int acpi_bus_get_power(acpi_handle handle, int *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Len Brown4be44fc2005-08-05 00:44:28 -0400175 int result = 0;
176 acpi_status status = 0;
177 struct acpi_device *device = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400178 unsigned long long psc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 result = acpi_bus_get_device(handle, &device);
182 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400183 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 *state = ACPI_STATE_UNKNOWN;
186
187 if (!device->flags.power_manageable) {
188 /* TBD: Non-recursive algorithm for walking up hierarchy */
189 if (device->parent)
190 *state = device->parent->power.state;
191 else
192 *state = ACPI_STATE_D0;
Len Brown4be44fc2005-08-05 00:44:28 -0400193 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 /*
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500195 * Get the device's power state either directly (via _PSC) or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 * indirectly (via power resources).
197 */
198 if (device->power.flags.explicit_get) {
Len Brown4be44fc2005-08-05 00:44:28 -0400199 status = acpi_evaluate_integer(device->handle, "_PSC",
200 NULL, &psc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400202 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400203 device->power.state = (int)psc;
204 } else if (device->power.flags.power_resources) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 result = acpi_power_get_inferred_state(device);
206 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400207 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 }
209
210 *state = device->power.state;
211 }
212
213 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400214 device->pnp.bus_id, device->power.state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Patrick Mocheld550d982006-06-27 00:41:40 -0400216 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
Len Brown4be44fc2005-08-05 00:44:28 -0400218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219EXPORT_SYMBOL(acpi_bus_get_power);
220
Len Brown4be44fc2005-08-05 00:44:28 -0400221int acpi_bus_set_power(acpi_handle handle, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Len Brown4be44fc2005-08-05 00:44:28 -0400223 int result = 0;
224 acpi_status status = AE_OK;
225 struct acpi_device *device = NULL;
226 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 result = acpi_bus_get_device(handle, &device);
230 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400231 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
Patrick Mocheld550d982006-06-27 00:41:40 -0400234 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 /* Make sure this is a valid target state */
237
238 if (!device->flags.power_manageable) {
Len Brown9805cb72006-07-25 13:30:57 -0400239 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
Greg Kroah-Hartman19c38de2007-09-12 15:06:57 -0700240 kobject_name(&device->dev.kobj)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400241 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
David Shaohua Lib9131002005-03-19 00:16:18 -0500243 /*
Alexey Starikovskiyc35923b2007-10-22 14:19:09 +0400244 * Get device's current power state
David Shaohua Lib9131002005-03-19 00:16:18 -0500245 */
Zhao Yakuif5adfaa2008-08-11 14:57:50 +0800246 if (!acpi_power_nocheck) {
247 /*
248 * Maybe the incorrect power state is returned on the bogus
249 * bios, which is different with the real power state.
250 * For example: the bios returns D0 state and the real power
251 * state is D3. OS expects to set the device to D0 state. In
252 * such case if OS uses the power state returned by the BIOS,
253 * the device can't be transisted to the correct power state.
254 * So if the acpi_power_nocheck is set, it is unnecessary to
255 * get the power state by calling acpi_bus_get_power.
256 */
257 acpi_bus_get_power(device->handle, &device->power.state);
258 }
Len Brownec683732008-01-23 22:41:20 -0500259 if ((state == device->power.state) && !device->flags.force_power_state) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500260 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
261 state));
262 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (!device->power.states[state].flags.valid) {
Len Browncece9292006-06-26 23:04:31 -0400266 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
Patrick Mocheld550d982006-06-27 00:41:40 -0400267 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269 if (device->parent && (state < device->parent->power.state)) {
Len Browncece9292006-06-26 23:04:31 -0400270 printk(KERN_WARNING PREFIX
Thomas Renningera6fc6722006-06-26 23:58:43 -0400271 "Cannot set device to a higher-powered"
Len Browncece9292006-06-26 23:04:31 -0400272 " state than parent\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400273 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
275
276 /*
277 * Transition Power
278 * ----------------
279 * On transitions to a high-powered state we first apply power (via
280 * power resources) then evalute _PSx. Conversly for transitions to
281 * a lower-powered state.
David Shaohua Lib9131002005-03-19 00:16:18 -0500282 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (state < device->power.state) {
284 if (device->power.flags.power_resources) {
285 result = acpi_power_transition(device, state);
286 if (result)
287 goto end;
288 }
289 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400290 status = acpi_evaluate_object(device->handle,
291 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 if (ACPI_FAILURE(status)) {
293 result = -ENODEV;
294 goto end;
295 }
296 }
Len Brown4be44fc2005-08-05 00:44:28 -0400297 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400299 status = acpi_evaluate_object(device->handle,
300 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 if (ACPI_FAILURE(status)) {
302 result = -ENODEV;
303 goto end;
304 }
305 }
306 if (device->power.flags.power_resources) {
307 result = acpi_power_transition(device, state);
308 if (result)
309 goto end;
310 }
311 }
312
Len Brown4be44fc2005-08-05 00:44:28 -0400313 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 if (result)
Len Browncece9292006-06-26 23:04:31 -0400315 printk(KERN_WARNING PREFIX
Len Brownddc50b62009-05-08 00:07:30 -0400316 "Device [%s] failed to transition to D%d\n",
Len Browncece9292006-06-26 23:04:31 -0400317 device->pnp.bus_id, state);
Shaohua Li5e321322007-10-11 23:53:58 +0200318 else {
319 device->power.state = state;
Len Brown4be44fc2005-08-05 00:44:28 -0400320 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
321 "Device [%s] transitioned to D%d\n",
322 device->pnp.bus_id, state));
Shaohua Li5e321322007-10-11 23:53:58 +0200323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Patrick Mocheld550d982006-06-27 00:41:40 -0400325 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}
Len Brown4be44fc2005-08-05 00:44:28 -0400327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328EXPORT_SYMBOL(acpi_bus_set_power);
329
Rafael J. Wysocki3737b2b2008-07-07 03:30:55 +0200330bool acpi_bus_power_manageable(acpi_handle handle)
331{
332 struct acpi_device *device;
333 int result;
334
335 result = acpi_bus_get_device(handle, &device);
336 return result ? false : device->flags.power_manageable;
337}
338
339EXPORT_SYMBOL(acpi_bus_power_manageable);
340
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200341bool acpi_bus_can_wakeup(acpi_handle handle)
342{
343 struct acpi_device *device;
344 int result;
345
346 result = acpi_bus_get_device(handle, &device);
347 return result ? false : device->wakeup.flags.valid;
348}
349
350EXPORT_SYMBOL(acpi_bus_can_wakeup);
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352/* --------------------------------------------------------------------------
353 Event Management
354 -------------------------------------------------------------------------- */
355
Len Brown14e04fb2007-08-23 15:20:26 -0400356#ifdef CONFIG_ACPI_PROC_EVENT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357static DEFINE_SPINLOCK(acpi_bus_event_lock);
358
359LIST_HEAD(acpi_bus_event_list);
360DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
361
Len Brown4be44fc2005-08-05 00:44:28 -0400362extern int event_is_open;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400364int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400366 struct acpi_bus_event *event;
Len Brown4be44fc2005-08-05 00:44:28 -0400367 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /* drop event on the floor if no one's listening */
370 if (!event_is_open)
Patrick Mocheld550d982006-06-27 00:41:40 -0400371 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
374 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400375 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400377 strcpy(event->device_class, device_class);
378 strcpy(event->bus_id, bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 event->type = type;
380 event->data = data;
381
382 spin_lock_irqsave(&acpi_bus_event_lock, flags);
383 list_add_tail(&event->node, &acpi_bus_event_list);
384 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
385
386 wake_up_interruptible(&acpi_bus_event_queue);
387
Patrick Mocheld550d982006-06-27 00:41:40 -0400388 return 0;
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400389
390}
391
392EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
393
394int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
395{
396 if (!device)
397 return -EINVAL;
398 return acpi_bus_generate_proc_event4(device->pnp.device_class,
399 device->pnp.bus_id, type, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
Len Brown4be44fc2005-08-05 00:44:28 -0400401
Len Brown14e04fb2007-08-23 15:20:26 -0400402EXPORT_SYMBOL(acpi_bus_generate_proc_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Len Brown4be44fc2005-08-05 00:44:28 -0400404int acpi_bus_receive_event(struct acpi_bus_event *event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
Len Brown4be44fc2005-08-05 00:44:28 -0400406 unsigned long flags = 0;
407 struct acpi_bus_event *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 DECLARE_WAITQUEUE(wait, current);
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400413 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 if (list_empty(&acpi_bus_event_list)) {
416
417 set_current_state(TASK_INTERRUPTIBLE);
418 add_wait_queue(&acpi_bus_event_queue, &wait);
419
420 if (list_empty(&acpi_bus_event_list))
421 schedule();
422
423 remove_wait_queue(&acpi_bus_event_queue, &wait);
424 set_current_state(TASK_RUNNING);
425
426 if (signal_pending(current))
Patrick Mocheld550d982006-06-27 00:41:40 -0400427 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
430 spin_lock_irqsave(&acpi_bus_event_lock, flags);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700431 if (!list_empty(&acpi_bus_event_list)) {
432 entry = list_entry(acpi_bus_event_list.next,
433 struct acpi_bus_event, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 list_del(&entry->node);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
437
438 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400439 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 memcpy(event, entry, sizeof(struct acpi_bus_event));
442
443 kfree(entry);
444
Patrick Mocheld550d982006-06-27 00:41:40 -0400445 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Len Brown14e04fb2007-08-23 15:20:26 -0400448#endif /* CONFIG_ACPI_PROC_EVENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450/* --------------------------------------------------------------------------
451 Notification Handling
452 -------------------------------------------------------------------------- */
453
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600454static void acpi_bus_check_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600456 struct acpi_device *device;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600457 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 struct acpi_device_status old_status;
459
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600460 if (acpi_bus_get_device(handle, &device))
461 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 if (!device)
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600463 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 old_status = device->status;
466
467 /*
468 * Make sure this device's parent is present before we go about
469 * messing with the device.
470 */
471 if (device->parent && !device->parent->status.present) {
472 device->status = device->parent->status;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600473 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475
476 status = acpi_bus_get_status(device);
477 if (ACPI_FAILURE(status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600478 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600481 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /*
484 * Device Insertion/Removal
485 */
486 if ((device->status.present) && !(old_status.present)) {
487 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
488 /* TBD: Handle device insertion */
Len Brown4be44fc2005-08-05 00:44:28 -0400489 } else if (!(device->status.present) && (old_status.present)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
491 /* TBD: Handle device removal */
492 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493}
494
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600495static void acpi_bus_check_scope(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 /* Status Change? */
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600498 acpi_bus_check_device(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /*
501 * TBD: Enumerate child devices within this device's scope and
502 * run acpi_bus_check_device()'s on them.
503 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504}
505
Shaohua Li6bd00a62008-08-28 10:04:29 +0800506static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
507int register_acpi_bus_notifier(struct notifier_block *nb)
508{
509 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
510}
511EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
512
513void unregister_acpi_bus_notifier(struct notifier_block *nb)
514{
515 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
516}
517EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519/**
520 * acpi_bus_notify
521 * ---------------
522 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
523 */
Len Brown4be44fc2005-08-05 00:44:28 -0400524static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Len Brown4be44fc2005-08-05 00:44:28 -0400526 struct acpi_device *device = NULL;
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600527 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Bjorn Helgaas02c37bd2009-05-22 11:43:41 -0600529 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
530 type, handle));
531
Shaohua Li6bd00a62008-08-28 10:04:29 +0800532 blocking_notifier_call_chain(&acpi_bus_notify_list,
533 type, (void *)handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 switch (type) {
536
537 case ACPI_NOTIFY_BUS_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600538 acpi_bus_check_scope(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500539 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400541 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 */
543 break;
544
545 case ACPI_NOTIFY_DEVICE_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600546 acpi_bus_check_device(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500547 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400549 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 */
551 break;
552
553 case ACPI_NOTIFY_DEVICE_WAKE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 /* TBD */
555 break;
556
557 case ACPI_NOTIFY_EJECT_REQUEST:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 /* TBD */
559 break;
560
561 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 /* TBD: Exactly what does 'light' mean? */
563 break;
564
565 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 /* TBD */
567 break;
568
569 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 /* TBD */
571 break;
572
573 case ACPI_NOTIFY_POWER_FAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /* TBD */
575 break;
576
577 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400578 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
579 "Received unknown/unsupported notification [%08x]\n",
580 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 break;
582 }
583
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600584 acpi_bus_get_device(handle, &device);
585 if (device) {
586 driver = device->driver;
587 if (driver && driver->ops.notify &&
588 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
589 driver->ops.notify(device, type);
590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
593/* --------------------------------------------------------------------------
594 Initialization/Cleanup
595 -------------------------------------------------------------------------- */
596
Len Brown4be44fc2005-08-05 00:44:28 -0400597static int __init acpi_bus_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Len Brown4be44fc2005-08-05 00:44:28 -0400599 acpi_status status = AE_OK;
600 union acpi_object arg = { ACPI_TYPE_INTEGER };
601 struct acpi_object_list arg_list = { 1, &arg };
602 char *message = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500605 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 * Let the system know what interrupt model we are using by
607 * evaluating the \_PIC object, if exists.
608 */
609
610 switch (acpi_irq_model) {
611 case ACPI_IRQ_MODEL_PIC:
612 message = "PIC";
613 break;
614 case ACPI_IRQ_MODEL_IOAPIC:
615 message = "IOAPIC";
616 break;
617 case ACPI_IRQ_MODEL_IOSAPIC:
618 message = "IOSAPIC";
619 break;
John Keller3948ec92006-12-22 11:50:04 -0600620 case ACPI_IRQ_MODEL_PLATFORM:
621 message = "platform specific model";
622 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 default:
624 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400625 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 }
627
628 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
629
630 arg.integer.value = acpi_irq_model;
631
632 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
633 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400634 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400635 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637
Patrick Mocheld550d982006-06-27 00:41:40 -0400638 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639}
640
Bob Moore67a119f2008-06-10 13:42:13 +0800641u8 acpi_gbl_permanent_mmap;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300642
643
Len Brown4be44fc2005-08-05 00:44:28 -0400644void __init acpi_early_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Len Brown4be44fc2005-08-05 00:44:28 -0400646 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400649 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Bob Moore616861242006-03-17 16:44:00 -0500651 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /* enable workarounds, unless strict ACPI spec. compliance */
654 if (!acpi_strict)
655 acpi_gbl_enable_interpreter_slack = TRUE;
656
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300657 acpi_gbl_permanent_mmap = 1;
658
659 status = acpi_reallocate_root_table();
660 if (ACPI_FAILURE(status)) {
661 printk(KERN_ERR PREFIX
662 "Unable to reallocate ACPI tables\n");
663 goto error0;
664 }
665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 status = acpi_initialize_subsystem();
667 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400668 printk(KERN_ERR PREFIX
669 "Unable to initialize the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 goto error0;
671 }
672
673 status = acpi_load_tables();
674 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400675 printk(KERN_ERR PREFIX
676 "Unable to load the System Description Tables\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 goto error0;
678 }
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680#ifdef CONFIG_X86
681 if (!acpi_ioapic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* compatible (0) means level (3) */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300683 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
684 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
685 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /* Set PIC-mode SCI trigger type */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300688 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300689 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 /*
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300692 * now that acpi_gbl_FADT is initialized,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 * update it with result from INT_SRC_OVR parsing
694 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300695 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 }
697#endif
698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 status =
700 acpi_enable_subsystem(~
701 (ACPI_NO_HARDWARE_INIT |
702 ACPI_NO_ACPI_ENABLE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (ACPI_FAILURE(status)) {
704 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
705 goto error0;
706 }
707
Patrick Mocheld550d982006-06-27 00:41:40 -0400708 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Len Brown4be44fc2005-08-05 00:44:28 -0400710 error0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 disable_acpi();
Patrick Mocheld550d982006-06-27 00:41:40 -0400712 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715static int __init acpi_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716{
Len Brown4be44fc2005-08-05 00:44:28 -0400717 int result = 0;
718 acpi_status status = AE_OK;
719 extern acpi_status acpi_os_initialize1(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Jiri Slaby176f9c12009-03-04 11:55:27 -0800721 acpi_os_initialize1();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Len Brown4be44fc2005-08-05 00:44:28 -0400723 status =
724 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400726 printk(KERN_ERR PREFIX
727 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 goto error1;
729 }
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 /*
732 * ACPI 2.0 requires the EC driver to be loaded and work before
733 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
734 * is called).
735 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500736 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 * the EC parameters out of that.
738 */
739 status = acpi_ec_ecdt_probe();
740 /* Ignore result. Not having an ECDT is not fatal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
743 if (ACPI_FAILURE(status)) {
744 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
745 goto error1;
746 }
747
Zhao Yakui455c8792008-10-06 10:31:36 +0800748 /*
749 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
750 * is necessary to enable it as early as possible.
751 */
752 acpi_boot_ec_enable();
753
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 printk(KERN_INFO PREFIX "Interpreter enabled\n");
755
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500756 /* Initialize sleep structures */
757 acpi_sleep_init();
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 /*
760 * Get the system interrupt model and evaluate \_PIC.
761 */
762 result = acpi_bus_init_irq();
763 if (result)
764 goto error1;
765
766 /*
767 * Register the for all standard device notifications.
768 */
Len Brown4be44fc2005-08-05 00:44:28 -0400769 status =
770 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
771 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400773 printk(KERN_ERR PREFIX
774 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 goto error1;
776 }
777
778 /*
779 * Create the top ACPI proc directory
780 */
781 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
782
Patrick Mocheld550d982006-06-27 00:41:40 -0400783 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -0400786 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -0400788 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789}
790
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700791struct kobject *acpi_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Len Brown4be44fc2005-08-05 00:44:28 -0400793static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
Len Brown4be44fc2005-08-05 00:44:28 -0400795 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 if (acpi_disabled) {
799 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400800 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 }
802
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -0800803 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700804 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -0800805 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700806 acpi_kobj = NULL;
807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Bjorn Helgaas0e465172009-03-24 16:50:09 -0600809 init_acpi_device_notify();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 result = acpi_bus_init();
811
812 if (!result) {
Robert Hancock7752d5c2008-02-15 01:27:20 -0800813 pci_mmcfg_late_init();
Len Brown9f9adec2007-12-13 17:38:03 -0500814 if (!(pm_flags & PM_APM))
815 pm_flags |= PM_ACPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400817 printk(KERN_INFO PREFIX
818 "APM is already active, exiting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 disable_acpi();
820 result = -ENODEV;
821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 } else
823 disable_acpi();
Bjorn Helgaas81d02732009-03-24 16:49:38 -0600824
825 if (acpi_disabled)
826 return result;
827
Zhao Yakui6415e122008-08-11 14:59:59 +0800828 /*
829 * If the laptop falls into the DMI check table, the power state check
830 * will be disabled in the course of device power transistion.
831 */
832 dmi_check_system(power_nocheck_dmi_table);
Bjorn Helgaase747f272009-03-24 16:49:43 -0600833
834 acpi_scan_init();
Bjorn Helgaasa5f820f2009-03-24 16:49:48 -0600835 acpi_ec_init();
Bjorn Helgaas44515372009-03-24 16:49:53 -0600836 acpi_power_init();
Bjorn Helgaas141a0af2009-03-24 16:49:58 -0600837 acpi_system_init();
Bjorn Helgaas84f810c2009-03-24 16:50:03 -0600838 acpi_debug_init();
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -0600839 acpi_sleep_proc_init();
Bjorn Helgaas201b8c62009-03-24 16:50:19 -0600840 acpi_wakeup_device_init();
Patrick Mocheld550d982006-06-27 00:41:40 -0400841 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842}
843
844subsys_initcall(acpi_init);