blob: eb986385c57ac680942c747b54c8ed74bf0d4374 [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>
41
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060042#include "internal.h"
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050045ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Len Brown4be44fc2005-08-05 00:44:28 -040047struct acpi_device *acpi_root;
48struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049EXPORT_SYMBOL(acpi_root_dir);
50
51#define STRUCT_TO_INT(s) (*((int*)&s))
52
Zhao Yakui6415e122008-08-11 14:59:59 +080053static int set_power_nocheck(const struct dmi_system_id *id)
54{
55 printk(KERN_NOTICE PREFIX "%s detected - "
56 "disable power check in power transistion\n", id->ident);
57 acpi_power_nocheck = 1;
58 return 0;
59}
60static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
61 {
62 set_power_nocheck, "HP Pavilion 05", {
63 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
64 DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
65 DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
66 {},
67};
68
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/* --------------------------------------------------------------------------
71 Device Management
72 -------------------------------------------------------------------------- */
73
Len Brown4be44fc2005-08-05 00:44:28 -040074int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Len Brown4be44fc2005-08-05 00:44:28 -040076 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -040080 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 /* TBD: Support fixed-feature devices */
83
Len Brown4be44fc2005-08-05 00:44:28 -040084 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 if (ACPI_FAILURE(status) || !*device) {
Len Brown9805cb72006-07-25 13:30:57 -040086 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
87 handle));
Patrick Mocheld550d982006-06-27 00:41:40 -040088 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90
Patrick Mocheld550d982006-06-27 00:41:40 -040091 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
Len Brown4be44fc2005-08-05 00:44:28 -040093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094EXPORT_SYMBOL(acpi_bus_get_device);
95
Len Brown4be44fc2005-08-05 00:44:28 -040096int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Len Brown4be44fc2005-08-05 00:44:28 -040098 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -040099 unsigned long long sta = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400103 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 /*
106 * Evaluate _STA if present.
107 */
108 if (device->flags.dynamic_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400109 status =
110 acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400112 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400113 STRUCT_TO_INT(device->status) = (int)sta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115
116 /*
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800117 * According to ACPI spec some device can be present and functional
118 * even if the parent is not present but functional.
119 * In such conditions the child device should not inherit the status
120 * from the parent.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 else
Bjorn Helgaas0c0e8922007-04-25 14:20:58 -0400123 STRUCT_TO_INT(device->status) =
124 ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
125 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800128 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
129 "functional but not present;\n",
130 device->pnp.bus_id,
131 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
133
Len Brown4be44fc2005-08-05 00:44:28 -0400134 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
135 device->pnp.bus_id,
136 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Patrick Mocheld550d982006-06-27 00:41:40 -0400138 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Len Brown4be44fc2005-08-05 00:44:28 -0400141EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Zhang Rui20733932008-01-17 15:51:21 +0800143void acpi_bus_private_data_handler(acpi_handle handle,
144 u32 function, void *context)
145{
146 return;
147}
148EXPORT_SYMBOL(acpi_bus_private_data_handler);
149
150int acpi_bus_get_private_data(acpi_handle handle, void **data)
151{
152 acpi_status status = AE_OK;
153
154 if (!*data)
155 return -EINVAL;
156
157 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
158 if (ACPI_FAILURE(status) || !*data) {
159 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
160 handle));
161 return -ENODEV;
162 }
163
164 return 0;
165}
166EXPORT_SYMBOL(acpi_bus_get_private_data);
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/* --------------------------------------------------------------------------
169 Power Management
170 -------------------------------------------------------------------------- */
171
Len Brown4be44fc2005-08-05 00:44:28 -0400172int acpi_bus_get_power(acpi_handle handle, int *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Len Brown4be44fc2005-08-05 00:44:28 -0400174 int result = 0;
175 acpi_status status = 0;
176 struct acpi_device *device = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400177 unsigned long long psc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 result = acpi_bus_get_device(handle, &device);
181 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400182 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 *state = ACPI_STATE_UNKNOWN;
185
186 if (!device->flags.power_manageable) {
187 /* TBD: Non-recursive algorithm for walking up hierarchy */
188 if (device->parent)
189 *state = device->parent->power.state;
190 else
191 *state = ACPI_STATE_D0;
Len Brown4be44fc2005-08-05 00:44:28 -0400192 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 /*
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500194 * Get the device's power state either directly (via _PSC) or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 * indirectly (via power resources).
196 */
197 if (device->power.flags.explicit_get) {
Len Brown4be44fc2005-08-05 00:44:28 -0400198 status = acpi_evaluate_integer(device->handle, "_PSC",
199 NULL, &psc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400201 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400202 device->power.state = (int)psc;
203 } else if (device->power.flags.power_resources) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 result = acpi_power_get_inferred_state(device);
205 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400206 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 }
208
209 *state = device->power.state;
210 }
211
212 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400213 device->pnp.bus_id, device->power.state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Patrick Mocheld550d982006-06-27 00:41:40 -0400215 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
Len Brown4be44fc2005-08-05 00:44:28 -0400217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218EXPORT_SYMBOL(acpi_bus_get_power);
219
Len Brown4be44fc2005-08-05 00:44:28 -0400220int acpi_bus_set_power(acpi_handle handle, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Len Brown4be44fc2005-08-05 00:44:28 -0400222 int result = 0;
223 acpi_status status = AE_OK;
224 struct acpi_device *device = NULL;
225 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 result = acpi_bus_get_device(handle, &device);
229 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400230 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
Patrick Mocheld550d982006-06-27 00:41:40 -0400233 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /* Make sure this is a valid target state */
236
237 if (!device->flags.power_manageable) {
Len Brown9805cb72006-07-25 13:30:57 -0400238 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
Greg Kroah-Hartman19c38de2007-09-12 15:06:57 -0700239 kobject_name(&device->dev.kobj)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400240 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
David Shaohua Lib9131002005-03-19 00:16:18 -0500242 /*
Alexey Starikovskiyc35923b2007-10-22 14:19:09 +0400243 * Get device's current power state
David Shaohua Lib9131002005-03-19 00:16:18 -0500244 */
Zhao Yakuif5adfaa2008-08-11 14:57:50 +0800245 if (!acpi_power_nocheck) {
246 /*
247 * Maybe the incorrect power state is returned on the bogus
248 * bios, which is different with the real power state.
249 * For example: the bios returns D0 state and the real power
250 * state is D3. OS expects to set the device to D0 state. In
251 * such case if OS uses the power state returned by the BIOS,
252 * the device can't be transisted to the correct power state.
253 * So if the acpi_power_nocheck is set, it is unnecessary to
254 * get the power state by calling acpi_bus_get_power.
255 */
256 acpi_bus_get_power(device->handle, &device->power.state);
257 }
Len Brownec683732008-01-23 22:41:20 -0500258 if ((state == device->power.state) && !device->flags.force_power_state) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500259 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
260 state));
261 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 if (!device->power.states[state].flags.valid) {
Len Browncece9292006-06-26 23:04:31 -0400265 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
Patrick Mocheld550d982006-06-27 00:41:40 -0400266 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268 if (device->parent && (state < device->parent->power.state)) {
Len Browncece9292006-06-26 23:04:31 -0400269 printk(KERN_WARNING PREFIX
Thomas Renningera6fc6722006-06-26 23:58:43 -0400270 "Cannot set device to a higher-powered"
Len Browncece9292006-06-26 23:04:31 -0400271 " state than parent\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400272 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
275 /*
276 * Transition Power
277 * ----------------
278 * On transitions to a high-powered state we first apply power (via
279 * power resources) then evalute _PSx. Conversly for transitions to
280 * a lower-powered state.
David Shaohua Lib9131002005-03-19 00:16:18 -0500281 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 if (state < device->power.state) {
283 if (device->power.flags.power_resources) {
284 result = acpi_power_transition(device, state);
285 if (result)
286 goto end;
287 }
288 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400289 status = acpi_evaluate_object(device->handle,
290 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (ACPI_FAILURE(status)) {
292 result = -ENODEV;
293 goto end;
294 }
295 }
Len Brown4be44fc2005-08-05 00:44:28 -0400296 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400298 status = acpi_evaluate_object(device->handle,
299 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (ACPI_FAILURE(status)) {
301 result = -ENODEV;
302 goto end;
303 }
304 }
305 if (device->power.flags.power_resources) {
306 result = acpi_power_transition(device, state);
307 if (result)
308 goto end;
309 }
310 }
311
Len Brown4be44fc2005-08-05 00:44:28 -0400312 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 if (result)
Len Browncece9292006-06-26 23:04:31 -0400314 printk(KERN_WARNING PREFIX
Len Brownddc50b62009-05-08 00:07:30 -0400315 "Device [%s] failed to transition to D%d\n",
Len Browncece9292006-06-26 23:04:31 -0400316 device->pnp.bus_id, state);
Shaohua Li5e321322007-10-11 23:53:58 +0200317 else {
318 device->power.state = state;
Len Brown4be44fc2005-08-05 00:44:28 -0400319 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
320 "Device [%s] transitioned to D%d\n",
321 device->pnp.bus_id, state));
Shaohua Li5e321322007-10-11 23:53:58 +0200322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Patrick Mocheld550d982006-06-27 00:41:40 -0400324 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
Len Brown4be44fc2005-08-05 00:44:28 -0400326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327EXPORT_SYMBOL(acpi_bus_set_power);
328
Rafael J. Wysocki3737b2b2008-07-07 03:30:55 +0200329bool acpi_bus_power_manageable(acpi_handle handle)
330{
331 struct acpi_device *device;
332 int result;
333
334 result = acpi_bus_get_device(handle, &device);
335 return result ? false : device->flags.power_manageable;
336}
337
338EXPORT_SYMBOL(acpi_bus_power_manageable);
339
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200340bool acpi_bus_can_wakeup(acpi_handle handle)
341{
342 struct acpi_device *device;
343 int result;
344
345 result = acpi_bus_get_device(handle, &device);
346 return result ? false : device->wakeup.flags.valid;
347}
348
349EXPORT_SYMBOL(acpi_bus_can_wakeup);
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/* --------------------------------------------------------------------------
352 Event Management
353 -------------------------------------------------------------------------- */
354
Len Brown14e04fb2007-08-23 15:20:26 -0400355#ifdef CONFIG_ACPI_PROC_EVENT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356static DEFINE_SPINLOCK(acpi_bus_event_lock);
357
358LIST_HEAD(acpi_bus_event_list);
359DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
360
Len Brown4be44fc2005-08-05 00:44:28 -0400361extern int event_is_open;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400363int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400365 struct acpi_bus_event *event;
Len Brown4be44fc2005-08-05 00:44:28 -0400366 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /* drop event on the floor if no one's listening */
369 if (!event_is_open)
Patrick Mocheld550d982006-06-27 00:41:40 -0400370 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
373 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400374 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400376 strcpy(event->device_class, device_class);
377 strcpy(event->bus_id, bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 event->type = type;
379 event->data = data;
380
381 spin_lock_irqsave(&acpi_bus_event_lock, flags);
382 list_add_tail(&event->node, &acpi_bus_event_list);
383 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
384
385 wake_up_interruptible(&acpi_bus_event_queue);
386
Patrick Mocheld550d982006-06-27 00:41:40 -0400387 return 0;
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400388
389}
390
391EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
392
393int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
394{
395 if (!device)
396 return -EINVAL;
397 return acpi_bus_generate_proc_event4(device->pnp.device_class,
398 device->pnp.bus_id, type, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
Len Brown4be44fc2005-08-05 00:44:28 -0400400
Len Brown14e04fb2007-08-23 15:20:26 -0400401EXPORT_SYMBOL(acpi_bus_generate_proc_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403int acpi_bus_receive_event(struct acpi_bus_event *event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Len Brown4be44fc2005-08-05 00:44:28 -0400405 unsigned long flags = 0;
406 struct acpi_bus_event *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 DECLARE_WAITQUEUE(wait, current);
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400412 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 if (list_empty(&acpi_bus_event_list)) {
415
416 set_current_state(TASK_INTERRUPTIBLE);
417 add_wait_queue(&acpi_bus_event_queue, &wait);
418
419 if (list_empty(&acpi_bus_event_list))
420 schedule();
421
422 remove_wait_queue(&acpi_bus_event_queue, &wait);
423 set_current_state(TASK_RUNNING);
424
425 if (signal_pending(current))
Patrick Mocheld550d982006-06-27 00:41:40 -0400426 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
428
429 spin_lock_irqsave(&acpi_bus_event_lock, flags);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700430 if (!list_empty(&acpi_bus_event_list)) {
431 entry = list_entry(acpi_bus_event_list.next,
432 struct acpi_bus_event, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 list_del(&entry->node);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
436
437 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400438 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 memcpy(event, entry, sizeof(struct acpi_bus_event));
441
442 kfree(entry);
443
Patrick Mocheld550d982006-06-27 00:41:40 -0400444 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Len Brown14e04fb2007-08-23 15:20:26 -0400447#endif /* CONFIG_ACPI_PROC_EVENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449/* --------------------------------------------------------------------------
450 Notification Handling
451 -------------------------------------------------------------------------- */
452
453static int
Len Brown4be44fc2005-08-05 00:44:28 -0400454acpi_bus_check_device(struct acpi_device *device, int *status_changed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Len Brown4be44fc2005-08-05 00:44:28 -0400456 acpi_status status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 struct acpi_device_status old_status;
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400461 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 if (status_changed)
464 *status_changed = 0;
465
466 old_status = device->status;
467
468 /*
469 * Make sure this device's parent is present before we go about
470 * messing with the device.
471 */
472 if (device->parent && !device->parent->status.present) {
473 device->status = device->parent->status;
474 if (STRUCT_TO_INT(old_status) != STRUCT_TO_INT(device->status)) {
475 if (status_changed)
476 *status_changed = 1;
477 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400478 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
480
481 status = acpi_bus_get_status(device);
482 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400483 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400486 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 if (status_changed)
489 *status_changed = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 /*
492 * Device Insertion/Removal
493 */
494 if ((device->status.present) && !(old_status.present)) {
495 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
496 /* TBD: Handle device insertion */
Len Brown4be44fc2005-08-05 00:44:28 -0400497 } else if (!(device->status.present) && (old_status.present)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
499 /* TBD: Handle device removal */
500 }
501
Patrick Mocheld550d982006-06-27 00:41:40 -0400502 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
Len Brown4be44fc2005-08-05 00:44:28 -0400505static int acpi_bus_check_scope(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Len Brown4be44fc2005-08-05 00:44:28 -0400507 int result = 0;
508 int status_changed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400512 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 /* Status Change? */
515 result = acpi_bus_check_device(device, &status_changed);
516 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400517 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 if (!status_changed)
Patrick Mocheld550d982006-06-27 00:41:40 -0400520 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 /*
523 * TBD: Enumerate child devices within this device's scope and
524 * run acpi_bus_check_device()'s on them.
525 */
526
Patrick Mocheld550d982006-06-27 00:41:40 -0400527 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528}
529
Shaohua Li6bd00a62008-08-28 10:04:29 +0800530static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
531int register_acpi_bus_notifier(struct notifier_block *nb)
532{
533 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
534}
535EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
536
537void unregister_acpi_bus_notifier(struct notifier_block *nb)
538{
539 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
540}
541EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543/**
544 * acpi_bus_notify
545 * ---------------
546 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
547 */
Len Brown4be44fc2005-08-05 00:44:28 -0400548static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Len Brown4be44fc2005-08-05 00:44:28 -0400550 int result = 0;
551 struct acpi_device *device = NULL;
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600552 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Bjorn Helgaas02c37bd2009-05-22 11:43:41 -0600554 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
555 type, handle));
556
Shaohua Li6bd00a62008-08-28 10:04:29 +0800557 blocking_notifier_call_chain(&acpi_bus_notify_list,
558 type, (void *)handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 if (acpi_bus_get_device(handle, &device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400561 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 switch (type) {
564
565 case ACPI_NOTIFY_BUS_CHECK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 result = acpi_bus_check_scope(device);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500567 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400569 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 */
571 break;
572
573 case ACPI_NOTIFY_DEVICE_CHECK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 result = acpi_bus_check_device(device, NULL);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500575 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400577 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 */
579 break;
580
581 case ACPI_NOTIFY_DEVICE_WAKE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 /* TBD */
583 break;
584
585 case ACPI_NOTIFY_EJECT_REQUEST:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /* TBD */
587 break;
588
589 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 /* TBD: Exactly what does 'light' mean? */
591 break;
592
593 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 /* TBD */
595 break;
596
597 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 /* TBD */
599 break;
600
601 case ACPI_NOTIFY_POWER_FAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /* TBD */
603 break;
604
605 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400606 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
607 "Received unknown/unsupported notification [%08x]\n",
608 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 break;
610 }
611
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600612 driver = device->driver;
613 if (driver && driver->ops.notify &&
614 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
615 driver->ops.notify(device, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616}
617
618/* --------------------------------------------------------------------------
619 Initialization/Cleanup
620 -------------------------------------------------------------------------- */
621
Len Brown4be44fc2005-08-05 00:44:28 -0400622static int __init acpi_bus_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Len Brown4be44fc2005-08-05 00:44:28 -0400624 acpi_status status = AE_OK;
625 union acpi_object arg = { ACPI_TYPE_INTEGER };
626 struct acpi_object_list arg_list = { 1, &arg };
627 char *message = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500630 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 * Let the system know what interrupt model we are using by
632 * evaluating the \_PIC object, if exists.
633 */
634
635 switch (acpi_irq_model) {
636 case ACPI_IRQ_MODEL_PIC:
637 message = "PIC";
638 break;
639 case ACPI_IRQ_MODEL_IOAPIC:
640 message = "IOAPIC";
641 break;
642 case ACPI_IRQ_MODEL_IOSAPIC:
643 message = "IOSAPIC";
644 break;
John Keller3948ec92006-12-22 11:50:04 -0600645 case ACPI_IRQ_MODEL_PLATFORM:
646 message = "platform specific model";
647 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 default:
649 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400650 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 }
652
653 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
654
655 arg.integer.value = acpi_irq_model;
656
657 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
658 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400659 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400660 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
662
Patrick Mocheld550d982006-06-27 00:41:40 -0400663 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664}
665
Bob Moore67a119f2008-06-10 13:42:13 +0800666u8 acpi_gbl_permanent_mmap;
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300667
668
Len Brown4be44fc2005-08-05 00:44:28 -0400669void __init acpi_early_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Len Brown4be44fc2005-08-05 00:44:28 -0400671 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400674 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Bob Moore61686122006-03-17 16:44:00 -0500676 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 /* enable workarounds, unless strict ACPI spec. compliance */
679 if (!acpi_strict)
680 acpi_gbl_enable_interpreter_slack = TRUE;
681
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300682 acpi_gbl_permanent_mmap = 1;
683
684 status = acpi_reallocate_root_table();
685 if (ACPI_FAILURE(status)) {
686 printk(KERN_ERR PREFIX
687 "Unable to reallocate ACPI tables\n");
688 goto error0;
689 }
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 status = acpi_initialize_subsystem();
692 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400693 printk(KERN_ERR PREFIX
694 "Unable to initialize the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 goto error0;
696 }
697
698 status = acpi_load_tables();
699 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400700 printk(KERN_ERR PREFIX
701 "Unable to load the System Description Tables\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 goto error0;
703 }
704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705#ifdef CONFIG_X86
706 if (!acpi_ioapic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 /* compatible (0) means level (3) */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300708 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
709 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
710 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /* Set PIC-mode SCI trigger type */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300713 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300714 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 /*
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300717 * now that acpi_gbl_FADT is initialized,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 * update it with result from INT_SRC_OVR parsing
719 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300720 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722#endif
723
Len Brown4be44fc2005-08-05 00:44:28 -0400724 status =
725 acpi_enable_subsystem(~
726 (ACPI_NO_HARDWARE_INIT |
727 ACPI_NO_ACPI_ENABLE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 if (ACPI_FAILURE(status)) {
729 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
730 goto error0;
731 }
732
Patrick Mocheld550d982006-06-27 00:41:40 -0400733 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Len Brown4be44fc2005-08-05 00:44:28 -0400735 error0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 disable_acpi();
Patrick Mocheld550d982006-06-27 00:41:40 -0400737 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
Len Brown4be44fc2005-08-05 00:44:28 -0400740static int __init acpi_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
Len Brown4be44fc2005-08-05 00:44:28 -0400742 int result = 0;
743 acpi_status status = AE_OK;
744 extern acpi_status acpi_os_initialize1(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Jiri Slaby176f9c12009-03-04 11:55:27 -0800746 acpi_os_initialize1();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Len Brown4be44fc2005-08-05 00:44:28 -0400748 status =
749 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400751 printk(KERN_ERR PREFIX
752 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 goto error1;
754 }
755
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 /*
757 * ACPI 2.0 requires the EC driver to be loaded and work before
758 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
759 * is called).
760 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500761 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 * the EC parameters out of that.
763 */
764 status = acpi_ec_ecdt_probe();
765 /* Ignore result. Not having an ECDT is not fatal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
767 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
768 if (ACPI_FAILURE(status)) {
769 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
770 goto error1;
771 }
772
Zhao Yakui455c8792008-10-06 10:31:36 +0800773 /*
774 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
775 * is necessary to enable it as early as possible.
776 */
777 acpi_boot_ec_enable();
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 printk(KERN_INFO PREFIX "Interpreter enabled\n");
780
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500781 /* Initialize sleep structures */
782 acpi_sleep_init();
783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 /*
785 * Get the system interrupt model and evaluate \_PIC.
786 */
787 result = acpi_bus_init_irq();
788 if (result)
789 goto error1;
790
791 /*
792 * Register the for all standard device notifications.
793 */
Len Brown4be44fc2005-08-05 00:44:28 -0400794 status =
795 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
796 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400798 printk(KERN_ERR PREFIX
799 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 goto error1;
801 }
802
803 /*
804 * Create the top ACPI proc directory
805 */
806 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
807
Patrick Mocheld550d982006-06-27 00:41:40 -0400808 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -0400811 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -0400813 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814}
815
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700816struct kobject *acpi_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Len Brown4be44fc2005-08-05 00:44:28 -0400818static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
Len Brown4be44fc2005-08-05 00:44:28 -0400820 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 if (acpi_disabled) {
824 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400825 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
827
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -0800828 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700829 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -0800830 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700831 acpi_kobj = NULL;
832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Bjorn Helgaas0e465172009-03-24 16:50:09 -0600834 init_acpi_device_notify();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 result = acpi_bus_init();
836
837 if (!result) {
Robert Hancock7752d5c2008-02-15 01:27:20 -0800838 pci_mmcfg_late_init();
Len Brown9f9adec2007-12-13 17:38:03 -0500839 if (!(pm_flags & PM_APM))
840 pm_flags |= PM_ACPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400842 printk(KERN_INFO PREFIX
843 "APM is already active, exiting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 disable_acpi();
845 result = -ENODEV;
846 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 } else
848 disable_acpi();
Bjorn Helgaas81d02732009-03-24 16:49:38 -0600849
850 if (acpi_disabled)
851 return result;
852
Zhao Yakui6415e122008-08-11 14:59:59 +0800853 /*
854 * If the laptop falls into the DMI check table, the power state check
855 * will be disabled in the course of device power transistion.
856 */
857 dmi_check_system(power_nocheck_dmi_table);
Bjorn Helgaase747f272009-03-24 16:49:43 -0600858
859 acpi_scan_init();
Bjorn Helgaasa5f820f2009-03-24 16:49:48 -0600860 acpi_ec_init();
Bjorn Helgaas44515372009-03-24 16:49:53 -0600861 acpi_power_init();
Bjorn Helgaas141a0af2009-03-24 16:49:58 -0600862 acpi_system_init();
Bjorn Helgaas84f810c2009-03-24 16:50:03 -0600863 acpi_debug_init();
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -0600864 acpi_sleep_proc_init();
Bjorn Helgaas201b8c62009-03-24 16:50:19 -0600865 acpi_wakeup_device_init();
Patrick Mocheld550d982006-06-27 00:41:40 -0400866 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}
868
869subsys_initcall(acpi_init);