blob: e9b116d2b56dbc984e408286cf5af4dc0ef9a28e [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050043ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Len Brown4be44fc2005-08-05 00:44:28 -040045struct acpi_device *acpi_root;
46struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047EXPORT_SYMBOL(acpi_root_dir);
48
49#define STRUCT_TO_INT(s) (*((int*)&s))
50
Zhao Yakui6415e122008-08-11 14:59:59 +080051static int set_power_nocheck(const struct dmi_system_id *id)
52{
53 printk(KERN_NOTICE PREFIX "%s detected - "
54 "disable power check in power transistion\n", id->ident);
55 acpi_power_nocheck = 1;
56 return 0;
57}
58static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
59 {
60 set_power_nocheck, "HP Pavilion 05", {
61 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
62 DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
63 DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
64 {},
65};
66
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/* --------------------------------------------------------------------------
69 Device Management
70 -------------------------------------------------------------------------- */
71
Len Brown4be44fc2005-08-05 00:44:28 -040072int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Len Brown4be44fc2005-08-05 00:44:28 -040074 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -040078 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 /* TBD: Support fixed-feature devices */
81
Len Brown4be44fc2005-08-05 00:44:28 -040082 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if (ACPI_FAILURE(status) || !*device) {
Len Brown9805cb72006-07-25 13:30:57 -040084 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
85 handle));
Patrick Mocheld550d982006-06-27 00:41:40 -040086 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88
Patrick Mocheld550d982006-06-27 00:41:40 -040089 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
Len Brown4be44fc2005-08-05 00:44:28 -040091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092EXPORT_SYMBOL(acpi_bus_get_device);
93
Len Brown4be44fc2005-08-05 00:44:28 -040094int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Len Brown4be44fc2005-08-05 00:44:28 -040096 acpi_status status = AE_OK;
97 unsigned long sta = 0;
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400101 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 /*
104 * Evaluate _STA if present.
105 */
106 if (device->flags.dynamic_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400107 status =
108 acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400110 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400111 STRUCT_TO_INT(device->status) = (int)sta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113
114 /*
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800115 * According to ACPI spec some device can be present and functional
116 * even if the parent is not present but functional.
117 * In such conditions the child device should not inherit the status
118 * from the parent.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 else
Bjorn Helgaas0c0e8922007-04-25 14:20:58 -0400121 STRUCT_TO_INT(device->status) =
122 ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
123 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800126 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
127 "functional but not present;\n",
128 device->pnp.bus_id,
129 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
133 device->pnp.bus_id,
134 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Patrick Mocheld550d982006-06-27 00:41:40 -0400136 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Len Brown4be44fc2005-08-05 00:44:28 -0400139EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Zhang Rui20733932008-01-17 15:51:21 +0800141void acpi_bus_private_data_handler(acpi_handle handle,
142 u32 function, void *context)
143{
144 return;
145}
146EXPORT_SYMBOL(acpi_bus_private_data_handler);
147
148int acpi_bus_get_private_data(acpi_handle handle, void **data)
149{
150 acpi_status status = AE_OK;
151
152 if (!*data)
153 return -EINVAL;
154
155 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
156 if (ACPI_FAILURE(status) || !*data) {
157 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
158 handle));
159 return -ENODEV;
160 }
161
162 return 0;
163}
164EXPORT_SYMBOL(acpi_bus_get_private_data);
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/* --------------------------------------------------------------------------
167 Power Management
168 -------------------------------------------------------------------------- */
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170int acpi_bus_get_power(acpi_handle handle, int *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Len Brown4be44fc2005-08-05 00:44:28 -0400172 int result = 0;
173 acpi_status status = 0;
174 struct acpi_device *device = NULL;
175 unsigned long psc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 result = acpi_bus_get_device(handle, &device);
179 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400180 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 *state = ACPI_STATE_UNKNOWN;
183
184 if (!device->flags.power_manageable) {
185 /* TBD: Non-recursive algorithm for walking up hierarchy */
186 if (device->parent)
187 *state = device->parent->power.state;
188 else
189 *state = ACPI_STATE_D0;
Len Brown4be44fc2005-08-05 00:44:28 -0400190 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 /*
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500192 * Get the device's power state either directly (via _PSC) or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 * indirectly (via power resources).
194 */
195 if (device->power.flags.explicit_get) {
Len Brown4be44fc2005-08-05 00:44:28 -0400196 status = acpi_evaluate_integer(device->handle, "_PSC",
197 NULL, &psc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400199 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400200 device->power.state = (int)psc;
201 } else if (device->power.flags.power_resources) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 result = acpi_power_get_inferred_state(device);
203 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400204 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
207 *state = device->power.state;
208 }
209
210 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400211 device->pnp.bus_id, device->power.state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Patrick Mocheld550d982006-06-27 00:41:40 -0400213 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
Len Brown4be44fc2005-08-05 00:44:28 -0400215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216EXPORT_SYMBOL(acpi_bus_get_power);
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218int acpi_bus_set_power(acpi_handle handle, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Len Brown4be44fc2005-08-05 00:44:28 -0400220 int result = 0;
221 acpi_status status = AE_OK;
222 struct acpi_device *device = NULL;
223 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 result = acpi_bus_get_device(handle, &device);
227 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400228 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
Patrick Mocheld550d982006-06-27 00:41:40 -0400231 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 /* Make sure this is a valid target state */
234
235 if (!device->flags.power_manageable) {
Len Brown9805cb72006-07-25 13:30:57 -0400236 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
Greg Kroah-Hartman19c38de2007-09-12 15:06:57 -0700237 kobject_name(&device->dev.kobj)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400238 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
David Shaohua Lib9131002005-03-19 00:16:18 -0500240 /*
Alexey Starikovskiyc35923b2007-10-22 14:19:09 +0400241 * Get device's current power state
David Shaohua Lib9131002005-03-19 00:16:18 -0500242 */
Zhao Yakuif5adfaa2008-08-11 14:57:50 +0800243 if (!acpi_power_nocheck) {
244 /*
245 * Maybe the incorrect power state is returned on the bogus
246 * bios, which is different with the real power state.
247 * For example: the bios returns D0 state and the real power
248 * state is D3. OS expects to set the device to D0 state. In
249 * such case if OS uses the power state returned by the BIOS,
250 * the device can't be transisted to the correct power state.
251 * So if the acpi_power_nocheck is set, it is unnecessary to
252 * get the power state by calling acpi_bus_get_power.
253 */
254 acpi_bus_get_power(device->handle, &device->power.state);
255 }
Len Brownec683732008-01-23 22:41:20 -0500256 if ((state == device->power.state) && !device->flags.force_power_state) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500257 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
258 state));
259 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 if (!device->power.states[state].flags.valid) {
Len Browncece9292006-06-26 23:04:31 -0400263 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
Patrick Mocheld550d982006-06-27 00:41:40 -0400264 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
266 if (device->parent && (state < device->parent->power.state)) {
Len Browncece9292006-06-26 23:04:31 -0400267 printk(KERN_WARNING PREFIX
Thomas Renningera6fc6722006-06-26 23:58:43 -0400268 "Cannot set device to a higher-powered"
Len Browncece9292006-06-26 23:04:31 -0400269 " state than parent\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400270 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 }
272
273 /*
274 * Transition Power
275 * ----------------
276 * On transitions to a high-powered state we first apply power (via
277 * power resources) then evalute _PSx. Conversly for transitions to
278 * a lower-powered state.
David Shaohua Lib9131002005-03-19 00:16:18 -0500279 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 if (state < device->power.state) {
281 if (device->power.flags.power_resources) {
282 result = acpi_power_transition(device, state);
283 if (result)
284 goto end;
285 }
286 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400287 status = acpi_evaluate_object(device->handle,
288 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (ACPI_FAILURE(status)) {
290 result = -ENODEV;
291 goto end;
292 }
293 }
Len Brown4be44fc2005-08-05 00:44:28 -0400294 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400296 status = acpi_evaluate_object(device->handle,
297 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (ACPI_FAILURE(status)) {
299 result = -ENODEV;
300 goto end;
301 }
302 }
303 if (device->power.flags.power_resources) {
304 result = acpi_power_transition(device, state);
305 if (result)
306 goto end;
307 }
308 }
309
Len Brown4be44fc2005-08-05 00:44:28 -0400310 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (result)
Len Browncece9292006-06-26 23:04:31 -0400312 printk(KERN_WARNING PREFIX
313 "Transitioning device [%s] to D%d\n",
314 device->pnp.bus_id, state);
Shaohua Li5e321322007-10-11 23:53:58 +0200315 else {
316 device->power.state = state;
Len Brown4be44fc2005-08-05 00:44:28 -0400317 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
318 "Device [%s] transitioned to D%d\n",
319 device->pnp.bus_id, state));
Shaohua Li5e321322007-10-11 23:53:58 +0200320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Patrick Mocheld550d982006-06-27 00:41:40 -0400322 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323}
Len Brown4be44fc2005-08-05 00:44:28 -0400324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325EXPORT_SYMBOL(acpi_bus_set_power);
326
Rafael J. Wysocki3737b2b2008-07-07 03:30:55 +0200327bool acpi_bus_power_manageable(acpi_handle handle)
328{
329 struct acpi_device *device;
330 int result;
331
332 result = acpi_bus_get_device(handle, &device);
333 return result ? false : device->flags.power_manageable;
334}
335
336EXPORT_SYMBOL(acpi_bus_power_manageable);
337
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200338bool acpi_bus_can_wakeup(acpi_handle handle)
339{
340 struct acpi_device *device;
341 int result;
342
343 result = acpi_bus_get_device(handle, &device);
344 return result ? false : device->wakeup.flags.valid;
345}
346
347EXPORT_SYMBOL(acpi_bus_can_wakeup);
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349/* --------------------------------------------------------------------------
350 Event Management
351 -------------------------------------------------------------------------- */
352
Len Brown14e04fb2007-08-23 15:20:26 -0400353#ifdef CONFIG_ACPI_PROC_EVENT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354static DEFINE_SPINLOCK(acpi_bus_event_lock);
355
356LIST_HEAD(acpi_bus_event_list);
357DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
358
Len Brown4be44fc2005-08-05 00:44:28 -0400359extern int event_is_open;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400361int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400363 struct acpi_bus_event *event;
Len Brown4be44fc2005-08-05 00:44:28 -0400364 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 /* drop event on the floor if no one's listening */
367 if (!event_is_open)
Patrick Mocheld550d982006-06-27 00:41:40 -0400368 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
371 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400372 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400374 strcpy(event->device_class, device_class);
375 strcpy(event->bus_id, bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 event->type = type;
377 event->data = data;
378
379 spin_lock_irqsave(&acpi_bus_event_lock, flags);
380 list_add_tail(&event->node, &acpi_bus_event_list);
381 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
382
383 wake_up_interruptible(&acpi_bus_event_queue);
384
Patrick Mocheld550d982006-06-27 00:41:40 -0400385 return 0;
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400386
387}
388
389EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
390
391int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
392{
393 if (!device)
394 return -EINVAL;
395 return acpi_bus_generate_proc_event4(device->pnp.device_class,
396 device->pnp.bus_id, type, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
Len Brown4be44fc2005-08-05 00:44:28 -0400398
Len Brown14e04fb2007-08-23 15:20:26 -0400399EXPORT_SYMBOL(acpi_bus_generate_proc_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Len Brown4be44fc2005-08-05 00:44:28 -0400401int acpi_bus_receive_event(struct acpi_bus_event *event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Len Brown4be44fc2005-08-05 00:44:28 -0400403 unsigned long flags = 0;
404 struct acpi_bus_event *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 DECLARE_WAITQUEUE(wait, current);
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400410 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 if (list_empty(&acpi_bus_event_list)) {
413
414 set_current_state(TASK_INTERRUPTIBLE);
415 add_wait_queue(&acpi_bus_event_queue, &wait);
416
417 if (list_empty(&acpi_bus_event_list))
418 schedule();
419
420 remove_wait_queue(&acpi_bus_event_queue, &wait);
421 set_current_state(TASK_RUNNING);
422
423 if (signal_pending(current))
Patrick Mocheld550d982006-06-27 00:41:40 -0400424 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
426
427 spin_lock_irqsave(&acpi_bus_event_lock, flags);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700428 if (!list_empty(&acpi_bus_event_list)) {
429 entry = list_entry(acpi_bus_event_list.next,
430 struct acpi_bus_event, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 list_del(&entry->node);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
434
435 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400436 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 memcpy(event, entry, sizeof(struct acpi_bus_event));
439
440 kfree(entry);
441
Patrick Mocheld550d982006-06-27 00:41:40 -0400442 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Len Brown14e04fb2007-08-23 15:20:26 -0400445#endif /* CONFIG_ACPI_PROC_EVENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447/* --------------------------------------------------------------------------
448 Notification Handling
449 -------------------------------------------------------------------------- */
450
451static int
Len Brown4be44fc2005-08-05 00:44:28 -0400452acpi_bus_check_device(struct acpi_device *device, int *status_changed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
Len Brown4be44fc2005-08-05 00:44:28 -0400454 acpi_status status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 struct acpi_device_status old_status;
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400459 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 if (status_changed)
462 *status_changed = 0;
463
464 old_status = device->status;
465
466 /*
467 * Make sure this device's parent is present before we go about
468 * messing with the device.
469 */
470 if (device->parent && !device->parent->status.present) {
471 device->status = device->parent->status;
472 if (STRUCT_TO_INT(old_status) != STRUCT_TO_INT(device->status)) {
473 if (status_changed)
474 *status_changed = 1;
475 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400476 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478
479 status = acpi_bus_get_status(device);
480 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400481 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400484 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 if (status_changed)
487 *status_changed = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 /*
490 * Device Insertion/Removal
491 */
492 if ((device->status.present) && !(old_status.present)) {
493 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
494 /* TBD: Handle device insertion */
Len Brown4be44fc2005-08-05 00:44:28 -0400495 } else if (!(device->status.present) && (old_status.present)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
497 /* TBD: Handle device removal */
498 }
499
Patrick Mocheld550d982006-06-27 00:41:40 -0400500 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
Len Brown4be44fc2005-08-05 00:44:28 -0400503static int acpi_bus_check_scope(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Len Brown4be44fc2005-08-05 00:44:28 -0400505 int result = 0;
506 int status_changed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400510 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 /* Status Change? */
513 result = acpi_bus_check_device(device, &status_changed);
514 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400515 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 if (!status_changed)
Patrick Mocheld550d982006-06-27 00:41:40 -0400518 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 /*
521 * TBD: Enumerate child devices within this device's scope and
522 * run acpi_bus_check_device()'s on them.
523 */
524
Patrick Mocheld550d982006-06-27 00:41:40 -0400525 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526}
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528/**
529 * acpi_bus_notify
530 * ---------------
531 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
532 */
Len Brown4be44fc2005-08-05 00:44:28 -0400533static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
Len Brown4be44fc2005-08-05 00:44:28 -0400535 int result = 0;
536 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 if (acpi_bus_get_device(handle, &device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400540 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 switch (type) {
543
544 case ACPI_NOTIFY_BUS_CHECK:
Len Brown4be44fc2005-08-05 00:44:28 -0400545 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
546 "Received BUS CHECK notification for device [%s]\n",
547 device->pnp.bus_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 result = acpi_bus_check_scope(device);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500549 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400551 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 */
553 break;
554
555 case ACPI_NOTIFY_DEVICE_CHECK:
Len Brown4be44fc2005-08-05 00:44:28 -0400556 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
557 "Received DEVICE CHECK notification for device [%s]\n",
558 device->pnp.bus_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 result = acpi_bus_check_device(device, NULL);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500560 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400562 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 */
564 break;
565
566 case ACPI_NOTIFY_DEVICE_WAKE:
Len Brown4be44fc2005-08-05 00:44:28 -0400567 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
568 "Received DEVICE WAKE notification for device [%s]\n",
569 device->pnp.bus_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 /* TBD */
571 break;
572
573 case ACPI_NOTIFY_EJECT_REQUEST:
Len Brown4be44fc2005-08-05 00:44:28 -0400574 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
575 "Received EJECT REQUEST notification for device [%s]\n",
576 device->pnp.bus_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 /* TBD */
578 break;
579
580 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Len Brown4be44fc2005-08-05 00:44:28 -0400581 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
582 "Received DEVICE CHECK LIGHT notification for device [%s]\n",
583 device->pnp.bus_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 /* TBD: Exactly what does 'light' mean? */
585 break;
586
587 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Len Brown4be44fc2005-08-05 00:44:28 -0400588 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
589 "Received FREQUENCY MISMATCH notification for device [%s]\n",
590 device->pnp.bus_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 /* TBD */
592 break;
593
594 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Len Brown4be44fc2005-08-05 00:44:28 -0400595 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
596 "Received BUS MODE MISMATCH notification for device [%s]\n",
597 device->pnp.bus_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 /* TBD */
599 break;
600
601 case ACPI_NOTIFY_POWER_FAULT:
Len Brown4be44fc2005-08-05 00:44:28 -0400602 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
603 "Received POWER FAULT notification for device [%s]\n",
604 device->pnp.bus_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /* TBD */
606 break;
607
608 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400609 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
610 "Received unknown/unsupported notification [%08x]\n",
611 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 break;
613 }
614
Patrick Mocheld550d982006-06-27 00:41:40 -0400615 return;
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 Starikovskiyad71860a2007-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 Moore616861242006-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 Starikovskiyad71860a2007-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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 status = acpi_os_initialize1();
748
Len Brown4be44fc2005-08-05 00:44:28 -0400749 status =
750 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400752 printk(KERN_ERR PREFIX
753 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 goto error1;
755 }
756
757 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400758 printk(KERN_ERR PREFIX
759 "Unable to initialize ACPI OS objects\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 goto error1;
761 }
762#ifdef CONFIG_ACPI_EC
763 /*
764 * ACPI 2.0 requires the EC driver to be loaded and work before
765 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
766 * is called).
767 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500768 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 * the EC parameters out of that.
770 */
771 status = acpi_ec_ecdt_probe();
772 /* Ignore result. Not having an ECDT is not fatal. */
773#endif
774
775 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
776 if (ACPI_FAILURE(status)) {
777 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
778 goto error1;
779 }
780
781 printk(KERN_INFO PREFIX "Interpreter enabled\n");
782
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500783 /* Initialize sleep structures */
784 acpi_sleep_init();
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 /*
787 * Get the system interrupt model and evaluate \_PIC.
788 */
789 result = acpi_bus_init_irq();
790 if (result)
791 goto error1;
792
793 /*
794 * Register the for all standard device notifications.
795 */
Len Brown4be44fc2005-08-05 00:44:28 -0400796 status =
797 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
798 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400800 printk(KERN_ERR PREFIX
801 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 goto error1;
803 }
804
805 /*
806 * Create the top ACPI proc directory
807 */
808 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
809
Patrick Mocheld550d982006-06-27 00:41:40 -0400810 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -0400813 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -0400815 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
817
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700818struct kobject *acpi_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Len Brown4be44fc2005-08-05 00:44:28 -0400820static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Len Brown4be44fc2005-08-05 00:44:28 -0400822 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 if (acpi_disabled) {
826 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400827 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
829
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -0800830 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700831 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -0800832 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700833 acpi_kobj = NULL;
834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 result = acpi_bus_init();
837
838 if (!result) {
Robert Hancock7752d5c2008-02-15 01:27:20 -0800839 pci_mmcfg_late_init();
Len Brown9f9adec2007-12-13 17:38:03 -0500840 if (!(pm_flags & PM_APM))
841 pm_flags |= PM_ACPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400843 printk(KERN_INFO PREFIX
844 "APM is already active, exiting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 disable_acpi();
846 result = -ENODEV;
847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 } else
849 disable_acpi();
Zhao Yakui6415e122008-08-11 14:59:59 +0800850 /*
851 * If the laptop falls into the DMI check table, the power state check
852 * will be disabled in the course of device power transistion.
853 */
854 dmi_check_system(power_nocheck_dmi_table);
Patrick Mocheld550d982006-06-27 00:41:40 -0400855 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856}
857
858subsys_initcall(acpi_init);