Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Dunlap | d568df8 | 2006-07-12 01:47:00 -0400 | [diff] [blame] | 28 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #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 Harrison | 6697c05 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 34 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #ifdef CONFIG_X86 |
| 36 | #include <asm/mpspec.h> |
| 37 | #endif |
Robert Hancock | 7752d5c | 2008-02-15 01:27:20 -0800 | [diff] [blame] | 38 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <acpi/acpi_bus.h> |
| 40 | #include <acpi/acpi_drivers.h> |
Len Brown | eb27cae | 2009-07-06 23:40:19 -0400 | [diff] [blame] | 41 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Bjorn Helgaas | e60cc7a | 2009-03-13 12:08:26 -0600 | [diff] [blame] | 43 | #include "internal.h" |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define _COMPONENT ACPI_BUS_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 46 | ACPI_MODULE_NAME("bus"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | struct acpi_device *acpi_root; |
| 49 | struct proc_dir_entry *acpi_root_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | EXPORT_SYMBOL(acpi_root_dir); |
| 51 | |
| 52 | #define STRUCT_TO_INT(s) (*((int*)&s)) |
| 53 | |
Zhao Yakui | 6415e12 | 2008-08-11 14:59:59 +0800 | [diff] [blame] | 54 | static 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 | } |
| 61 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* -------------------------------------------------------------------------- |
| 72 | Device Management |
| 73 | -------------------------------------------------------------------------- */ |
| 74 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 81 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | /* TBD: Support fixed-feature devices */ |
| 84 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | if (ACPI_FAILURE(status) || !*device) { |
Len Brown | 9805cb7 | 2006-07-25 13:30:57 -0400 | [diff] [blame] | 87 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n", |
| 88 | handle)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 89 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 92 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | EXPORT_SYMBOL(acpi_bus_get_device); |
| 96 | |
Bjorn Helgaas | 402ac53 | 2009-09-21 19:30:01 +0000 | [diff] [blame] | 97 | acpi_status acpi_bus_get_status_handle(acpi_handle handle, |
| 98 | unsigned long long *sta) |
| 99 | { |
| 100 | acpi_status status; |
| 101 | |
| 102 | status = acpi_evaluate_integer(handle, "_STA", NULL, sta); |
| 103 | if (ACPI_SUCCESS(status)) |
| 104 | return AE_OK; |
| 105 | |
| 106 | if (status == AE_NOT_FOUND) { |
| 107 | *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | |
| 108 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; |
| 109 | return AE_OK; |
| 110 | } |
| 111 | return status; |
| 112 | } |
| 113 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | int acpi_bus_get_status(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
Bjorn Helgaas | 402ac53 | 2009-09-21 19:30:01 +0000 | [diff] [blame] | 116 | acpi_status status; |
| 117 | unsigned long long sta; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | |
Bjorn Helgaas | 402ac53 | 2009-09-21 19:30:01 +0000 | [diff] [blame] | 119 | status = acpi_bus_get_status_handle(device->handle, &sta); |
| 120 | if (ACPI_FAILURE(status)) |
| 121 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Bjorn Helgaas | 402ac53 | 2009-09-21 19:30:01 +0000 | [diff] [blame] | 123 | STRUCT_TO_INT(device->status) = (int) sta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | if (device->status.functional && !device->status.present) { |
Zhao Yakui | 39a0ad8 | 2008-08-11 13:40:22 +0800 | [diff] [blame] | 126 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n", |
| 133 | device->pnp.bus_id, |
| 134 | (u32) STRUCT_TO_INT(device->status))); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 135 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | EXPORT_SYMBOL(acpi_bus_get_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 139 | void acpi_bus_private_data_handler(acpi_handle handle, |
Bob Moore | 8e4319c | 2009-06-29 13:43:27 +0800 | [diff] [blame] | 140 | void *context) |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 141 | { |
| 142 | return; |
| 143 | } |
| 144 | EXPORT_SYMBOL(acpi_bus_private_data_handler); |
| 145 | |
| 146 | int acpi_bus_get_private_data(acpi_handle handle, void **data) |
| 147 | { |
| 148 | acpi_status status = AE_OK; |
| 149 | |
| 150 | if (!*data) |
| 151 | return -EINVAL; |
| 152 | |
| 153 | status = acpi_get_data(handle, acpi_bus_private_data_handler, data); |
| 154 | if (ACPI_FAILURE(status) || !*data) { |
| 155 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n", |
| 156 | handle)); |
| 157 | return -ENODEV; |
| 158 | } |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | EXPORT_SYMBOL(acpi_bus_get_private_data); |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* -------------------------------------------------------------------------- |
| 165 | Power Management |
| 166 | -------------------------------------------------------------------------- */ |
| 167 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | int acpi_bus_get_power(acpi_handle handle, int *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | int result = 0; |
| 171 | acpi_status status = 0; |
| 172 | struct acpi_device *device = NULL; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 173 | unsigned long long psc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | result = acpi_bus_get_device(handle, &device); |
| 177 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 178 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | *state = ACPI_STATE_UNKNOWN; |
| 181 | |
| 182 | if (!device->flags.power_manageable) { |
| 183 | /* TBD: Non-recursive algorithm for walking up hierarchy */ |
| 184 | if (device->parent) |
| 185 | *state = device->parent->power.state; |
| 186 | else |
| 187 | *state = ACPI_STATE_D0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 190 | * Get the device's power state either directly (via _PSC) or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | * indirectly (via power resources). |
| 192 | */ |
| 193 | if (device->power.flags.explicit_get) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | status = acpi_evaluate_integer(device->handle, "_PSC", |
| 195 | NULL, &psc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 197 | return -ENODEV; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | device->power.state = (int)psc; |
| 199 | } else if (device->power.flags.power_resources) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | result = acpi_power_get_inferred_state(device); |
| 201 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 202 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | *state = device->power.state; |
| 206 | } |
| 207 | |
| 208 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | device->pnp.bus_id, device->power.state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 211 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | EXPORT_SYMBOL(acpi_bus_get_power); |
| 215 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | int acpi_bus_set_power(acpi_handle handle, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | int result = 0; |
| 219 | acpi_status status = AE_OK; |
| 220 | struct acpi_device *device = NULL; |
| 221 | char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | result = acpi_bus_get_device(handle, &device); |
| 225 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 226 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 229 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
| 231 | /* Make sure this is a valid target state */ |
| 232 | |
| 233 | if (!device->flags.power_manageable) { |
Len Brown | 9805cb7 | 2006-07-25 13:30:57 -0400 | [diff] [blame] | 234 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n", |
Greg Kroah-Hartman | 19c38de | 2007-09-12 15:06:57 -0700 | [diff] [blame] | 235 | kobject_name(&device->dev.kobj))); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 236 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 238 | /* |
Alexey Starikovskiy | c35923b | 2007-10-22 14:19:09 +0400 | [diff] [blame] | 239 | * Get device's current power state |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 240 | */ |
Zhao Yakui | f5adfaa | 2008-08-11 14:57:50 +0800 | [diff] [blame] | 241 | if (!acpi_power_nocheck) { |
| 242 | /* |
| 243 | * Maybe the incorrect power state is returned on the bogus |
| 244 | * bios, which is different with the real power state. |
| 245 | * For example: the bios returns D0 state and the real power |
| 246 | * state is D3. OS expects to set the device to D0 state. In |
| 247 | * such case if OS uses the power state returned by the BIOS, |
| 248 | * the device can't be transisted to the correct power state. |
| 249 | * So if the acpi_power_nocheck is set, it is unnecessary to |
| 250 | * get the power state by calling acpi_bus_get_power. |
| 251 | */ |
| 252 | acpi_bus_get_power(device->handle, &device->power.state); |
| 253 | } |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 254 | if ((state == device->power.state) && !device->flags.force_power_state) { |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 255 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", |
| 256 | state)); |
| 257 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (!device->power.states[state].flags.valid) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 261 | printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 262 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | if (device->parent && (state < device->parent->power.state)) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 265 | printk(KERN_WARNING PREFIX |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 266 | "Cannot set device to a higher-powered" |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 267 | " state than parent\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 268 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Transition Power |
| 273 | * ---------------- |
| 274 | * On transitions to a high-powered state we first apply power (via |
| 275 | * power resources) then evalute _PSx. Conversly for transitions to |
| 276 | * a lower-powered state. |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 277 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | if (state < device->power.state) { |
| 279 | if (device->power.flags.power_resources) { |
| 280 | result = acpi_power_transition(device, state); |
| 281 | if (result) |
| 282 | goto end; |
| 283 | } |
| 284 | if (device->power.states[state].flags.explicit_set) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | status = acpi_evaluate_object(device->handle, |
| 286 | object_name, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | if (ACPI_FAILURE(status)) { |
| 288 | result = -ENODEV; |
| 289 | goto end; |
| 290 | } |
| 291 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 292 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | if (device->power.states[state].flags.explicit_set) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | status = acpi_evaluate_object(device->handle, |
| 295 | object_name, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | if (ACPI_FAILURE(status)) { |
| 297 | result = -ENODEV; |
| 298 | goto end; |
| 299 | } |
| 300 | } |
| 301 | if (device->power.flags.power_resources) { |
| 302 | result = acpi_power_transition(device, state); |
| 303 | if (result) |
| 304 | goto end; |
| 305 | } |
| 306 | } |
| 307 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | if (result) |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 310 | printk(KERN_WARNING PREFIX |
Len Brown | ddc50b6 | 2009-05-08 00:07:30 -0400 | [diff] [blame] | 311 | "Device [%s] failed to transition to D%d\n", |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 312 | device->pnp.bus_id, state); |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 313 | else { |
| 314 | device->power.state = state; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 316 | "Device [%s] transitioned to D%d\n", |
| 317 | device->pnp.bus_id, state)); |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 320 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | EXPORT_SYMBOL(acpi_bus_set_power); |
| 324 | |
Rafael J. Wysocki | 3737b2b | 2008-07-07 03:30:55 +0200 | [diff] [blame] | 325 | bool acpi_bus_power_manageable(acpi_handle handle) |
| 326 | { |
| 327 | struct acpi_device *device; |
| 328 | int result; |
| 329 | |
| 330 | result = acpi_bus_get_device(handle, &device); |
| 331 | return result ? false : device->flags.power_manageable; |
| 332 | } |
| 333 | |
| 334 | EXPORT_SYMBOL(acpi_bus_power_manageable); |
| 335 | |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 336 | bool acpi_bus_can_wakeup(acpi_handle handle) |
| 337 | { |
| 338 | struct acpi_device *device; |
| 339 | int result; |
| 340 | |
| 341 | result = acpi_bus_get_device(handle, &device); |
| 342 | return result ? false : device->wakeup.flags.valid; |
| 343 | } |
| 344 | |
| 345 | EXPORT_SYMBOL(acpi_bus_can_wakeup); |
| 346 | |
Shaohua Li | 70023de | 2009-10-29 11:04:28 +0800 | [diff] [blame^] | 347 | static void acpi_print_osc_error(acpi_handle handle, |
| 348 | struct acpi_osc_context *context, char *error) |
| 349 | { |
| 350 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER}; |
| 351 | int i; |
| 352 | |
| 353 | if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer))) |
| 354 | printk(KERN_DEBUG "%s\n", error); |
| 355 | else { |
| 356 | printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error); |
| 357 | kfree(buffer.pointer); |
| 358 | } |
| 359 | printk(KERN_DEBUG"_OSC request data:"); |
| 360 | for (i = 0; i < context->cap.length; i += sizeof(u32)) |
| 361 | printk("%x ", *((u32 *)(context->cap.pointer + i))); |
| 362 | printk("\n"); |
| 363 | } |
| 364 | |
| 365 | static u8 hex_val(unsigned char c) |
| 366 | { |
| 367 | return isdigit(c) ? c - '0' : toupper(c) - 'A' + 10; |
| 368 | } |
| 369 | |
| 370 | static acpi_status acpi_str_to_uuid(char *str, u8 *uuid) |
| 371 | { |
| 372 | int i; |
| 373 | static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21, |
| 374 | 24, 26, 28, 30, 32, 34}; |
| 375 | |
| 376 | if (strlen(str) != 36) |
| 377 | return AE_BAD_PARAMETER; |
| 378 | for (i = 0; i < 36; i++) { |
| 379 | if (i == 8 || i == 13 || i == 18 || i == 23) { |
| 380 | if (str[i] != '-') |
| 381 | return AE_BAD_PARAMETER; |
| 382 | } else if (!isxdigit(str[i])) |
| 383 | return AE_BAD_PARAMETER; |
| 384 | } |
| 385 | for (i = 0; i < 16; i++) { |
| 386 | uuid[i] = hex_val(str[opc_map_to_uuid[i]]) << 4; |
| 387 | uuid[i] |= hex_val(str[opc_map_to_uuid[i] + 1]); |
| 388 | } |
| 389 | return AE_OK; |
| 390 | } |
| 391 | |
| 392 | acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context) |
| 393 | { |
| 394 | acpi_status status; |
| 395 | struct acpi_object_list input; |
| 396 | union acpi_object in_params[4]; |
| 397 | union acpi_object *out_obj; |
| 398 | u8 uuid[16]; |
| 399 | u32 errors; |
| 400 | |
| 401 | if (!context) |
| 402 | return AE_ERROR; |
| 403 | if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid))) |
| 404 | return AE_ERROR; |
| 405 | context->ret.length = ACPI_ALLOCATE_BUFFER; |
| 406 | context->ret.pointer = NULL; |
| 407 | |
| 408 | /* Setting up input parameters */ |
| 409 | input.count = 4; |
| 410 | input.pointer = in_params; |
| 411 | in_params[0].type = ACPI_TYPE_BUFFER; |
| 412 | in_params[0].buffer.length = 16; |
| 413 | in_params[0].buffer.pointer = uuid; |
| 414 | in_params[1].type = ACPI_TYPE_INTEGER; |
| 415 | in_params[1].integer.value = context->rev; |
| 416 | in_params[2].type = ACPI_TYPE_INTEGER; |
| 417 | in_params[2].integer.value = context->cap.length/sizeof(u32); |
| 418 | in_params[3].type = ACPI_TYPE_BUFFER; |
| 419 | in_params[3].buffer.length = context->cap.length; |
| 420 | in_params[3].buffer.pointer = context->cap.pointer; |
| 421 | |
| 422 | status = acpi_evaluate_object(handle, "_OSC", &input, &context->ret); |
| 423 | if (ACPI_FAILURE(status)) |
| 424 | return status; |
| 425 | |
| 426 | /* return buffer should have the same length as cap buffer */ |
| 427 | if (context->ret.length != context->cap.length) |
| 428 | return AE_NULL_OBJECT; |
| 429 | |
| 430 | out_obj = context->ret.pointer; |
| 431 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
| 432 | acpi_print_osc_error(handle, context, |
| 433 | "_OSC evaluation returned wrong type"); |
| 434 | status = AE_TYPE; |
| 435 | goto out_kfree; |
| 436 | } |
| 437 | /* Need to ignore the bit0 in result code */ |
| 438 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); |
| 439 | if (errors) { |
| 440 | if (errors & OSC_REQUEST_ERROR) |
| 441 | acpi_print_osc_error(handle, context, |
| 442 | "_OSC request failed"); |
| 443 | if (errors & OSC_INVALID_UUID_ERROR) |
| 444 | acpi_print_osc_error(handle, context, |
| 445 | "_OSC invalid UUID"); |
| 446 | if (errors & OSC_INVALID_REVISION_ERROR) |
| 447 | acpi_print_osc_error(handle, context, |
| 448 | "_OSC invalid revision"); |
| 449 | if (errors & OSC_CAPABILITIES_MASK_ERROR) { |
| 450 | if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE] |
| 451 | & OSC_QUERY_ENABLE) |
| 452 | goto out_success; |
| 453 | status = AE_SUPPORT; |
| 454 | goto out_kfree; |
| 455 | } |
| 456 | status = AE_ERROR; |
| 457 | goto out_kfree; |
| 458 | } |
| 459 | out_success: |
| 460 | return AE_OK; |
| 461 | |
| 462 | out_kfree: |
| 463 | kfree(context->ret.pointer); |
| 464 | context->ret.pointer = NULL; |
| 465 | return status; |
| 466 | } |
| 467 | EXPORT_SYMBOL(acpi_run_osc); |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | /* -------------------------------------------------------------------------- |
| 470 | Event Management |
| 471 | -------------------------------------------------------------------------- */ |
| 472 | |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 473 | #ifdef CONFIG_ACPI_PROC_EVENT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | static DEFINE_SPINLOCK(acpi_bus_event_lock); |
| 475 | |
| 476 | LIST_HEAD(acpi_bus_event_list); |
| 477 | DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue); |
| 478 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 479 | extern int event_is_open; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Alexey Starikovskiy | 8db85d4 | 2007-09-26 19:43:16 +0400 | [diff] [blame] | 481 | int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Alexey Starikovskiy | 8db85d4 | 2007-09-26 19:43:16 +0400 | [diff] [blame] | 483 | struct acpi_bus_event *event; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 484 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | /* drop event on the floor if no one's listening */ |
| 487 | if (!event_is_open) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 488 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC); |
| 491 | if (!event) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 492 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Alexey Starikovskiy | 8db85d4 | 2007-09-26 19:43:16 +0400 | [diff] [blame] | 494 | strcpy(event->device_class, device_class); |
| 495 | strcpy(event->bus_id, bus_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | event->type = type; |
| 497 | event->data = data; |
| 498 | |
| 499 | spin_lock_irqsave(&acpi_bus_event_lock, flags); |
| 500 | list_add_tail(&event->node, &acpi_bus_event_list); |
| 501 | spin_unlock_irqrestore(&acpi_bus_event_lock, flags); |
| 502 | |
| 503 | wake_up_interruptible(&acpi_bus_event_queue); |
| 504 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 505 | return 0; |
Alexey Starikovskiy | 8db85d4 | 2007-09-26 19:43:16 +0400 | [diff] [blame] | 506 | |
| 507 | } |
| 508 | |
| 509 | EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4); |
| 510 | |
| 511 | int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data) |
| 512 | { |
| 513 | if (!device) |
| 514 | return -EINVAL; |
| 515 | return acpi_bus_generate_proc_event4(device->pnp.device_class, |
| 516 | device->pnp.bus_id, type, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 519 | EXPORT_SYMBOL(acpi_bus_generate_proc_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 521 | int acpi_bus_receive_event(struct acpi_bus_event *event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 523 | unsigned long flags = 0; |
| 524 | struct acpi_bus_event *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | DECLARE_WAITQUEUE(wait, current); |
| 527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | if (!event) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 530 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | if (list_empty(&acpi_bus_event_list)) { |
| 533 | |
| 534 | set_current_state(TASK_INTERRUPTIBLE); |
| 535 | add_wait_queue(&acpi_bus_event_queue, &wait); |
| 536 | |
| 537 | if (list_empty(&acpi_bus_event_list)) |
| 538 | schedule(); |
| 539 | |
| 540 | remove_wait_queue(&acpi_bus_event_queue, &wait); |
| 541 | set_current_state(TASK_RUNNING); |
| 542 | |
| 543 | if (signal_pending(current)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 544 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | spin_lock_irqsave(&acpi_bus_event_lock, flags); |
Chuck Ebbert | f0a37e0 | 2008-04-15 14:34:47 -0700 | [diff] [blame] | 548 | if (!list_empty(&acpi_bus_event_list)) { |
| 549 | entry = list_entry(acpi_bus_event_list.next, |
| 550 | struct acpi_bus_event, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | list_del(&entry->node); |
Chuck Ebbert | f0a37e0 | 2008-04-15 14:34:47 -0700 | [diff] [blame] | 552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | spin_unlock_irqrestore(&acpi_bus_event_lock, flags); |
| 554 | |
| 555 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 556 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
| 558 | memcpy(event, entry, sizeof(struct acpi_bus_event)); |
| 559 | |
| 560 | kfree(entry); |
| 561 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 562 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 565 | #endif /* CONFIG_ACPI_PROC_EVENT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
| 567 | /* -------------------------------------------------------------------------- |
| 568 | Notification Handling |
| 569 | -------------------------------------------------------------------------- */ |
| 570 | |
Bjorn Helgaas | ff754e2 | 2009-05-22 11:43:56 -0600 | [diff] [blame] | 571 | static void acpi_bus_check_device(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | { |
Bjorn Helgaas | ff754e2 | 2009-05-22 11:43:56 -0600 | [diff] [blame] | 573 | struct acpi_device *device; |
Bjorn Helgaas | cdd5b8c | 2009-05-22 11:43:51 -0600 | [diff] [blame] | 574 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | struct acpi_device_status old_status; |
| 576 | |
Bjorn Helgaas | ff754e2 | 2009-05-22 11:43:56 -0600 | [diff] [blame] | 577 | if (acpi_bus_get_device(handle, &device)) |
| 578 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | if (!device) |
Bjorn Helgaas | cdd5b8c | 2009-05-22 11:43:51 -0600 | [diff] [blame] | 580 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | old_status = device->status; |
| 583 | |
| 584 | /* |
| 585 | * Make sure this device's parent is present before we go about |
| 586 | * messing with the device. |
| 587 | */ |
| 588 | if (device->parent && !device->parent->status.present) { |
| 589 | device->status = device->parent->status; |
Bjorn Helgaas | cdd5b8c | 2009-05-22 11:43:51 -0600 | [diff] [blame] | 590 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | status = acpi_bus_get_status(device); |
| 594 | if (ACPI_FAILURE(status)) |
Bjorn Helgaas | cdd5b8c | 2009-05-22 11:43:51 -0600 | [diff] [blame] | 595 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
| 597 | if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status)) |
Bjorn Helgaas | cdd5b8c | 2009-05-22 11:43:51 -0600 | [diff] [blame] | 598 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | /* |
| 601 | * Device Insertion/Removal |
| 602 | */ |
| 603 | if ((device->status.present) && !(old_status.present)) { |
| 604 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n")); |
| 605 | /* TBD: Handle device insertion */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 606 | } else if (!(device->status.present) && (old_status.present)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n")); |
| 608 | /* TBD: Handle device removal */ |
| 609 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Bjorn Helgaas | ff754e2 | 2009-05-22 11:43:56 -0600 | [diff] [blame] | 612 | static void acpi_bus_check_scope(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | /* Status Change? */ |
Bjorn Helgaas | ff754e2 | 2009-05-22 11:43:56 -0600 | [diff] [blame] | 615 | acpi_bus_check_device(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* |
| 618 | * TBD: Enumerate child devices within this device's scope and |
| 619 | * run acpi_bus_check_device()'s on them. |
| 620 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 623 | static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list); |
| 624 | int register_acpi_bus_notifier(struct notifier_block *nb) |
| 625 | { |
| 626 | return blocking_notifier_chain_register(&acpi_bus_notify_list, nb); |
| 627 | } |
| 628 | EXPORT_SYMBOL_GPL(register_acpi_bus_notifier); |
| 629 | |
| 630 | void unregister_acpi_bus_notifier(struct notifier_block *nb) |
| 631 | { |
| 632 | blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb); |
| 633 | } |
| 634 | EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier); |
| 635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | /** |
| 637 | * acpi_bus_notify |
| 638 | * --------------- |
| 639 | * Callback for all 'system-level' device notifications (values 0x00-0x7F). |
| 640 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 641 | static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 643 | struct acpi_device *device = NULL; |
Bjorn Helgaas | 6d27813 | 2009-04-30 09:35:37 -0600 | [diff] [blame] | 644 | struct acpi_driver *driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Bjorn Helgaas | 02c37bd | 2009-05-22 11:43:41 -0600 | [diff] [blame] | 646 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n", |
| 647 | type, handle)); |
| 648 | |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 649 | blocking_notifier_call_chain(&acpi_bus_notify_list, |
| 650 | type, (void *)handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | switch (type) { |
| 653 | |
| 654 | case ACPI_NOTIFY_BUS_CHECK: |
Bjorn Helgaas | ff754e2 | 2009-05-22 11:43:56 -0600 | [diff] [blame] | 655 | acpi_bus_check_scope(handle); |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 656 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | * TBD: We'll need to outsource certain events to non-ACPI |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 658 | * drivers via the device manager (device.c). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | */ |
| 660 | break; |
| 661 | |
| 662 | case ACPI_NOTIFY_DEVICE_CHECK: |
Bjorn Helgaas | ff754e2 | 2009-05-22 11:43:56 -0600 | [diff] [blame] | 663 | acpi_bus_check_device(handle); |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 664 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | * TBD: We'll need to outsource certain events to non-ACPI |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 666 | * drivers via the device manager (device.c). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | */ |
| 668 | break; |
| 669 | |
| 670 | case ACPI_NOTIFY_DEVICE_WAKE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | /* TBD */ |
| 672 | break; |
| 673 | |
| 674 | case ACPI_NOTIFY_EJECT_REQUEST: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | /* TBD */ |
| 676 | break; |
| 677 | |
| 678 | case ACPI_NOTIFY_DEVICE_CHECK_LIGHT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | /* TBD: Exactly what does 'light' mean? */ |
| 680 | break; |
| 681 | |
| 682 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | /* TBD */ |
| 684 | break; |
| 685 | |
| 686 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | /* TBD */ |
| 688 | break; |
| 689 | |
| 690 | case ACPI_NOTIFY_POWER_FAULT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | /* TBD */ |
| 692 | break; |
| 693 | |
| 694 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 695 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 696 | "Received unknown/unsupported notification [%08x]\n", |
| 697 | type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | break; |
| 699 | } |
| 700 | |
Bjorn Helgaas | ff754e2 | 2009-05-22 11:43:56 -0600 | [diff] [blame] | 701 | acpi_bus_get_device(handle, &device); |
| 702 | if (device) { |
| 703 | driver = device->driver; |
| 704 | if (driver && driver->ops.notify && |
| 705 | (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS)) |
| 706 | driver->ops.notify(device, type); |
| 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /* -------------------------------------------------------------------------- |
| 711 | Initialization/Cleanup |
| 712 | -------------------------------------------------------------------------- */ |
| 713 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 714 | static int __init acpi_bus_init_irq(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 716 | acpi_status status = AE_OK; |
| 717 | union acpi_object arg = { ACPI_TYPE_INTEGER }; |
| 718 | struct acpi_object_list arg_list = { 1, &arg }; |
| 719 | char *message = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 722 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | * Let the system know what interrupt model we are using by |
| 724 | * evaluating the \_PIC object, if exists. |
| 725 | */ |
| 726 | |
| 727 | switch (acpi_irq_model) { |
| 728 | case ACPI_IRQ_MODEL_PIC: |
| 729 | message = "PIC"; |
| 730 | break; |
| 731 | case ACPI_IRQ_MODEL_IOAPIC: |
| 732 | message = "IOAPIC"; |
| 733 | break; |
| 734 | case ACPI_IRQ_MODEL_IOSAPIC: |
| 735 | message = "IOSAPIC"; |
| 736 | break; |
John Keller | 3948ec9 | 2006-12-22 11:50:04 -0600 | [diff] [blame] | 737 | case ACPI_IRQ_MODEL_PLATFORM: |
| 738 | message = "platform specific model"; |
| 739 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | default: |
| 741 | printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 742 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message); |
| 746 | |
| 747 | arg.integer.value = acpi_irq_model; |
| 748 | |
| 749 | status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL); |
| 750 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 751 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 752 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 755 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 758 | u8 acpi_gbl_permanent_mmap; |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 759 | |
| 760 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 761 | void __init acpi_early_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 763 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 766 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 768 | printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); |
| 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | /* enable workarounds, unless strict ACPI spec. compliance */ |
| 771 | if (!acpi_strict) |
| 772 | acpi_gbl_enable_interpreter_slack = TRUE; |
| 773 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 774 | acpi_gbl_permanent_mmap = 1; |
| 775 | |
| 776 | status = acpi_reallocate_root_table(); |
| 777 | if (ACPI_FAILURE(status)) { |
| 778 | printk(KERN_ERR PREFIX |
| 779 | "Unable to reallocate ACPI tables\n"); |
| 780 | goto error0; |
| 781 | } |
| 782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | status = acpi_initialize_subsystem(); |
| 784 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 785 | printk(KERN_ERR PREFIX |
| 786 | "Unable to initialize the ACPI Interpreter\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | goto error0; |
| 788 | } |
| 789 | |
| 790 | status = acpi_load_tables(); |
| 791 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 792 | printk(KERN_ERR PREFIX |
| 793 | "Unable to load the System Description Tables\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | goto error0; |
| 795 | } |
| 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | #ifdef CONFIG_X86 |
| 798 | if (!acpi_ioapic) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | /* compatible (0) means level (3) */ |
Alexey Starikovskiy | 5f3b1a8 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 800 | if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) { |
| 801 | acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK; |
| 802 | acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL; |
| 803 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | /* Set PIC-mode SCI trigger type */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 805 | acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt, |
Alexey Starikovskiy | 5f3b1a8 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 806 | (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | /* |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 809 | * now that acpi_gbl_FADT is initialized, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | * update it with result from INT_SRC_OVR parsing |
| 811 | */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 812 | acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | #endif |
| 815 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 816 | status = |
| 817 | acpi_enable_subsystem(~ |
| 818 | (ACPI_NO_HARDWARE_INIT | |
| 819 | ACPI_NO_ACPI_ENABLE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | if (ACPI_FAILURE(status)) { |
| 821 | printk(KERN_ERR PREFIX "Unable to enable ACPI\n"); |
| 822 | goto error0; |
| 823 | } |
| 824 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 825 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 827 | error0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | disable_acpi(); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 829 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 832 | static int __init acpi_bus_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 834 | int result = 0; |
| 835 | acpi_status status = AE_OK; |
| 836 | extern acpi_status acpi_os_initialize1(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
Jiri Slaby | 176f9c1 | 2009-03-04 11:55:27 -0800 | [diff] [blame] | 838 | acpi_os_initialize1(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 840 | status = |
| 841 | acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 843 | printk(KERN_ERR PREFIX |
| 844 | "Unable to start the ACPI Interpreter\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | goto error1; |
| 846 | } |
| 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | /* |
| 849 | * ACPI 2.0 requires the EC driver to be loaded and work before |
| 850 | * the EC device is found in the namespace (i.e. before acpi_initialize_objects() |
| 851 | * is called). |
| 852 | * |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 853 | * This is accomplished by looking for the ECDT table, and getting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | * the EC parameters out of that. |
| 855 | */ |
| 856 | status = acpi_ec_ecdt_probe(); |
| 857 | /* Ignore result. Not having an ECDT is not fatal. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
| 859 | status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION); |
| 860 | if (ACPI_FAILURE(status)) { |
| 861 | printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n"); |
| 862 | goto error1; |
| 863 | } |
| 864 | |
Zhao Yakui | 455c879 | 2008-10-06 10:31:36 +0800 | [diff] [blame] | 865 | /* |
| 866 | * Maybe EC region is required at bus_scan/acpi_get_devices. So it |
| 867 | * is necessary to enable it as early as possible. |
| 868 | */ |
| 869 | acpi_boot_ec_enable(); |
| 870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | printk(KERN_INFO PREFIX "Interpreter enabled\n"); |
| 872 | |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 873 | /* Initialize sleep structures */ |
| 874 | acpi_sleep_init(); |
| 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | /* |
| 877 | * Get the system interrupt model and evaluate \_PIC. |
| 878 | */ |
| 879 | result = acpi_bus_init_irq(); |
| 880 | if (result) |
| 881 | goto error1; |
| 882 | |
| 883 | /* |
| 884 | * Register the for all standard device notifications. |
| 885 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 886 | status = |
| 887 | acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, |
| 888 | &acpi_bus_notify, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 890 | printk(KERN_ERR PREFIX |
| 891 | "Unable to register for device notifications\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | goto error1; |
| 893 | } |
| 894 | |
| 895 | /* |
| 896 | * Create the top ACPI proc directory |
| 897 | */ |
| 898 | acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL); |
| 899 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 900 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
| 902 | /* Mimic structured exception handling */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 903 | error1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | acpi_terminate(); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 905 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Greg Kroah-Hartman | 99e0d2f | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 908 | struct kobject *acpi_kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 910 | static int __init acpi_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 912 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | if (acpi_disabled) { |
| 916 | printk(KERN_INFO PREFIX "Interpreter disabled.\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 917 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Greg Kroah-Hartman | f62ed9e | 2007-11-05 13:16:15 -0800 | [diff] [blame] | 920 | acpi_kobj = kobject_create_and_add("acpi", firmware_kobj); |
Greg Kroah-Hartman | 99e0d2f | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 921 | if (!acpi_kobj) { |
Harvey Harrison | 96b2dd1 | 2008-03-05 18:24:51 -0800 | [diff] [blame] | 922 | printk(KERN_WARNING "%s: kset create error\n", __func__); |
Greg Kroah-Hartman | 99e0d2f | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 923 | acpi_kobj = NULL; |
| 924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Bjorn Helgaas | 0e46517d | 2009-03-24 16:50:09 -0600 | [diff] [blame] | 926 | init_acpi_device_notify(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | result = acpi_bus_init(); |
| 928 | |
| 929 | if (!result) { |
Robert Hancock | 7752d5c | 2008-02-15 01:27:20 -0800 | [diff] [blame] | 930 | pci_mmcfg_late_init(); |
Len Brown | 9f9adec | 2007-12-13 17:38:03 -0500 | [diff] [blame] | 931 | if (!(pm_flags & PM_APM)) |
| 932 | pm_flags |= PM_ACPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 934 | printk(KERN_INFO PREFIX |
| 935 | "APM is already active, exiting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | disable_acpi(); |
| 937 | result = -ENODEV; |
| 938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | } else |
| 940 | disable_acpi(); |
Bjorn Helgaas | 81d0273 | 2009-03-24 16:49:38 -0600 | [diff] [blame] | 941 | |
| 942 | if (acpi_disabled) |
| 943 | return result; |
| 944 | |
Zhao Yakui | 6415e12 | 2008-08-11 14:59:59 +0800 | [diff] [blame] | 945 | /* |
| 946 | * If the laptop falls into the DMI check table, the power state check |
| 947 | * will be disabled in the course of device power transistion. |
| 948 | */ |
| 949 | dmi_check_system(power_nocheck_dmi_table); |
Bjorn Helgaas | e747f27 | 2009-03-24 16:49:43 -0600 | [diff] [blame] | 950 | |
| 951 | acpi_scan_init(); |
Bjorn Helgaas | a5f820f | 2009-03-24 16:49:48 -0600 | [diff] [blame] | 952 | acpi_ec_init(); |
Bjorn Helgaas | 4451537 | 2009-03-24 16:49:53 -0600 | [diff] [blame] | 953 | acpi_power_init(); |
Bjorn Helgaas | 141a0af | 2009-03-24 16:49:58 -0600 | [diff] [blame] | 954 | acpi_system_init(); |
Bjorn Helgaas | 84f810c | 2009-03-24 16:50:03 -0600 | [diff] [blame] | 955 | acpi_debug_init(); |
Bjorn Helgaas | 9cee43e | 2009-03-24 16:50:14 -0600 | [diff] [blame] | 956 | acpi_sleep_proc_init(); |
Bjorn Helgaas | 201b8c6 | 2009-03-24 16:50:19 -0600 | [diff] [blame] | 957 | acpi_wakeup_device_init(); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 958 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | subsys_initcall(acpi_init); |