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> |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define _COMPONENT ACPI_BUS_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 43 | ACPI_MODULE_NAME("bus"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 45 | struct acpi_device *acpi_root; |
| 46 | struct proc_dir_entry *acpi_root_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | EXPORT_SYMBOL(acpi_root_dir); |
| 48 | |
| 49 | #define STRUCT_TO_INT(s) (*((int*)&s)) |
| 50 | |
Zhao Yakui | 6415e12 | 2008-08-11 14:59:59 +0800 | [diff] [blame] | 51 | static 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 | } |
| 58 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* -------------------------------------------------------------------------- |
| 69 | Device Management |
| 70 | -------------------------------------------------------------------------- */ |
| 71 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 78 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* TBD: Support fixed-feature devices */ |
| 81 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 82 | status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | if (ACPI_FAILURE(status) || !*device) { |
Len Brown | 9805cb7 | 2006-07-25 13:30:57 -0400 | [diff] [blame] | 84 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n", |
| 85 | handle)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 86 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 89 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | EXPORT_SYMBOL(acpi_bus_get_device); |
| 93 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | int acpi_bus_get_status(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 97 | unsigned long long sta = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 101 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * Evaluate _STA if present. |
| 105 | */ |
| 106 | if (device->flags.dynamic_status) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | status = |
| 108 | acpi_evaluate_integer(device->handle, "_STA", NULL, &sta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 110 | return -ENODEV; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | STRUCT_TO_INT(device->status) = (int)sta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* |
Zhao Yakui | 39a0ad8 | 2008-08-11 13:40:22 +0800 | [diff] [blame] | 115 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | else |
Bjorn Helgaas | 0c0e892 | 2007-04-25 14:20:58 -0400 | [diff] [blame] | 121 | STRUCT_TO_INT(device->status) = |
| 122 | ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | |
| 123 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; |
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))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 136 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | EXPORT_SYMBOL(acpi_bus_get_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 141 | void acpi_bus_private_data_handler(acpi_handle handle, |
| 142 | u32 function, void *context) |
| 143 | { |
| 144 | return; |
| 145 | } |
| 146 | EXPORT_SYMBOL(acpi_bus_private_data_handler); |
| 147 | |
| 148 | int 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 | } |
| 164 | EXPORT_SYMBOL(acpi_bus_get_private_data); |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | /* -------------------------------------------------------------------------- |
| 167 | Power Management |
| 168 | -------------------------------------------------------------------------- */ |
| 169 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | int acpi_bus_get_power(acpi_handle handle, int *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | int result = 0; |
| 173 | acpi_status status = 0; |
| 174 | struct acpi_device *device = NULL; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 175 | unsigned long long psc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | result = acpi_bus_get_device(handle, &device); |
| 179 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 180 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | /* |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 192 | * Get the device's power state either directly (via _PSC) or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | * indirectly (via power resources). |
| 194 | */ |
| 195 | if (device->power.flags.explicit_get) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | status = acpi_evaluate_integer(device->handle, "_PSC", |
| 197 | NULL, &psc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 199 | return -ENODEV; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | device->power.state = (int)psc; |
| 201 | } else if (device->power.flags.power_resources) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | result = acpi_power_get_inferred_state(device); |
| 203 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 204 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | *state = device->power.state; |
| 208 | } |
| 209 | |
| 210 | 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] | 211 | device->pnp.bus_id, device->power.state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 213 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | EXPORT_SYMBOL(acpi_bus_get_power); |
| 217 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | int acpi_bus_set_power(acpi_handle handle, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | result = acpi_bus_get_device(handle, &device); |
| 227 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 228 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 231 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | /* Make sure this is a valid target state */ |
| 234 | |
| 235 | if (!device->flags.power_manageable) { |
Len Brown | 9805cb7 | 2006-07-25 13:30:57 -0400 | [diff] [blame] | 236 | 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] | 237 | kobject_name(&device->dev.kobj))); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 238 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 240 | /* |
Alexey Starikovskiy | c35923b | 2007-10-22 14:19:09 +0400 | [diff] [blame] | 241 | * Get device's current power state |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 242 | */ |
Zhao Yakui | f5adfaa | 2008-08-11 14:57:50 +0800 | [diff] [blame] | 243 | 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 Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 256 | if ((state == device->power.state) && !device->flags.force_power_state) { |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 257 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", |
| 258 | state)); |
| 259 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if (!device->power.states[state].flags.valid) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 263 | printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 264 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | if (device->parent && (state < device->parent->power.state)) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 267 | printk(KERN_WARNING PREFIX |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 268 | "Cannot set device to a higher-powered" |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 269 | " state than parent\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 270 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 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 Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 279 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | status = acpi_evaluate_object(device->handle, |
| 288 | object_name, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (ACPI_FAILURE(status)) { |
| 290 | result = -ENODEV; |
| 291 | goto end; |
| 292 | } |
| 293 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | if (device->power.states[state].flags.explicit_set) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | status = acpi_evaluate_object(device->handle, |
| 297 | object_name, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (result) |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 312 | printk(KERN_WARNING PREFIX |
| 313 | "Transitioning device [%s] to D%d\n", |
| 314 | device->pnp.bus_id, state); |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 315 | else { |
| 316 | device->power.state = state; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 318 | "Device [%s] transitioned to D%d\n", |
| 319 | device->pnp.bus_id, state)); |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 322 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | EXPORT_SYMBOL(acpi_bus_set_power); |
| 326 | |
Rafael J. Wysocki | 3737b2b | 2008-07-07 03:30:55 +0200 | [diff] [blame] | 327 | bool 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 | |
| 336 | EXPORT_SYMBOL(acpi_bus_power_manageable); |
| 337 | |
Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 338 | bool 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 | |
| 347 | EXPORT_SYMBOL(acpi_bus_can_wakeup); |
| 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | /* -------------------------------------------------------------------------- |
| 350 | Event Management |
| 351 | -------------------------------------------------------------------------- */ |
| 352 | |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 353 | #ifdef CONFIG_ACPI_PROC_EVENT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | static DEFINE_SPINLOCK(acpi_bus_event_lock); |
| 355 | |
| 356 | LIST_HEAD(acpi_bus_event_list); |
| 357 | DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue); |
| 358 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 359 | extern int event_is_open; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Alexey Starikovskiy | 8db85d4 | 2007-09-26 19:43:16 +0400 | [diff] [blame] | 361 | 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] | 362 | { |
Alexey Starikovskiy | 8db85d4 | 2007-09-26 19:43:16 +0400 | [diff] [blame] | 363 | struct acpi_bus_event *event; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 364 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | /* drop event on the floor if no one's listening */ |
| 367 | if (!event_is_open) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 368 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC); |
| 371 | if (!event) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 372 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Alexey Starikovskiy | 8db85d4 | 2007-09-26 19:43:16 +0400 | [diff] [blame] | 374 | strcpy(event->device_class, device_class); |
| 375 | strcpy(event->bus_id, bus_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | 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 Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 385 | return 0; |
Alexey Starikovskiy | 8db85d4 | 2007-09-26 19:43:16 +0400 | [diff] [blame] | 386 | |
| 387 | } |
| 388 | |
| 389 | EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4); |
| 390 | |
| 391 | int 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 399 | EXPORT_SYMBOL(acpi_bus_generate_proc_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 401 | int acpi_bus_receive_event(struct acpi_bus_event *event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | unsigned long flags = 0; |
| 404 | struct acpi_bus_event *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | DECLARE_WAITQUEUE(wait, current); |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | if (!event) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 410 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 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 Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 424 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | spin_lock_irqsave(&acpi_bus_event_lock, flags); |
Chuck Ebbert | f0a37e0 | 2008-04-15 14:34:47 -0700 | [diff] [blame] | 428 | if (!list_empty(&acpi_bus_event_list)) { |
| 429 | entry = list_entry(acpi_bus_event_list.next, |
| 430 | struct acpi_bus_event, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | list_del(&entry->node); |
Chuck Ebbert | f0a37e0 | 2008-04-15 14:34:47 -0700 | [diff] [blame] | 432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | spin_unlock_irqrestore(&acpi_bus_event_lock, flags); |
| 434 | |
| 435 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 436 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | memcpy(event, entry, sizeof(struct acpi_bus_event)); |
| 439 | |
| 440 | kfree(entry); |
| 441 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 442 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 445 | #endif /* CONFIG_ACPI_PROC_EVENT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
| 447 | /* -------------------------------------------------------------------------- |
| 448 | Notification Handling |
| 449 | -------------------------------------------------------------------------- */ |
| 450 | |
| 451 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | acpi_bus_check_device(struct acpi_device *device, int *status_changed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | acpi_status status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | struct acpi_device_status old_status; |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 459 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 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 Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 476 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | status = acpi_bus_get_status(device); |
| 480 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 481 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 484 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
| 486 | if (status_changed) |
| 487 | *status_changed = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 495 | } else if (!(device->status.present) && (old_status.present)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n")); |
| 497 | /* TBD: Handle device removal */ |
| 498 | } |
| 499 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 500 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 503 | static int acpi_bus_check_scope(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | int result = 0; |
| 506 | int status_changed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 510 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | /* Status Change? */ |
| 513 | result = acpi_bus_check_device(device, &status_changed); |
| 514 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 515 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
| 517 | if (!status_changed) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 518 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| 520 | /* |
| 521 | * TBD: Enumerate child devices within this device's scope and |
| 522 | * run acpi_bus_check_device()'s on them. |
| 523 | */ |
| 524 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 525 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 528 | static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list); |
| 529 | int register_acpi_bus_notifier(struct notifier_block *nb) |
| 530 | { |
| 531 | return blocking_notifier_chain_register(&acpi_bus_notify_list, nb); |
| 532 | } |
| 533 | EXPORT_SYMBOL_GPL(register_acpi_bus_notifier); |
| 534 | |
| 535 | void unregister_acpi_bus_notifier(struct notifier_block *nb) |
| 536 | { |
| 537 | blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb); |
| 538 | } |
| 539 | EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier); |
| 540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | /** |
| 542 | * acpi_bus_notify |
| 543 | * --------------- |
| 544 | * Callback for all 'system-level' device notifications (values 0x00-0x7F). |
| 545 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 546 | static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 548 | int result = 0; |
| 549 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 551 | blocking_notifier_call_chain(&acpi_bus_notify_list, |
| 552 | type, (void *)handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | if (acpi_bus_get_device(handle, &device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 555 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | switch (type) { |
| 558 | |
| 559 | case ACPI_NOTIFY_BUS_CHECK: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 560 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 561 | "Received BUS CHECK notification for device [%s]\n", |
| 562 | device->pnp.bus_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | result = acpi_bus_check_scope(device); |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 564 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | * TBD: We'll need to outsource certain events to non-ACPI |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 566 | * drivers via the device manager (device.c). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | */ |
| 568 | break; |
| 569 | |
| 570 | case ACPI_NOTIFY_DEVICE_CHECK: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 571 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 572 | "Received DEVICE CHECK notification for device [%s]\n", |
| 573 | device->pnp.bus_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | result = acpi_bus_check_device(device, NULL); |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 575 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | * TBD: We'll need to outsource certain events to non-ACPI |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 577 | * drivers via the device manager (device.c). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | */ |
| 579 | break; |
| 580 | |
| 581 | case ACPI_NOTIFY_DEVICE_WAKE: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 582 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 583 | "Received DEVICE WAKE notification for device [%s]\n", |
| 584 | device->pnp.bus_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | /* TBD */ |
| 586 | break; |
| 587 | |
| 588 | case ACPI_NOTIFY_EJECT_REQUEST: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 589 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 590 | "Received EJECT REQUEST notification for device [%s]\n", |
| 591 | device->pnp.bus_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | /* TBD */ |
| 593 | break; |
| 594 | |
| 595 | case ACPI_NOTIFY_DEVICE_CHECK_LIGHT: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 596 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 597 | "Received DEVICE CHECK LIGHT notification for device [%s]\n", |
| 598 | device->pnp.bus_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* TBD: Exactly what does 'light' mean? */ |
| 600 | break; |
| 601 | |
| 602 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 603 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 604 | "Received FREQUENCY MISMATCH notification for device [%s]\n", |
| 605 | device->pnp.bus_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | /* TBD */ |
| 607 | break; |
| 608 | |
| 609 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 610 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 611 | "Received BUS MODE MISMATCH notification for device [%s]\n", |
| 612 | device->pnp.bus_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* TBD */ |
| 614 | break; |
| 615 | |
| 616 | case ACPI_NOTIFY_POWER_FAULT: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 617 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 618 | "Received POWER FAULT notification for device [%s]\n", |
| 619 | device->pnp.bus_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | /* TBD */ |
| 621 | break; |
| 622 | |
| 623 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 624 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 625 | "Received unknown/unsupported notification [%08x]\n", |
| 626 | type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | break; |
| 628 | } |
| 629 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 630 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* -------------------------------------------------------------------------- |
| 634 | Initialization/Cleanup |
| 635 | -------------------------------------------------------------------------- */ |
| 636 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 637 | static int __init acpi_bus_init_irq(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 639 | acpi_status status = AE_OK; |
| 640 | union acpi_object arg = { ACPI_TYPE_INTEGER }; |
| 641 | struct acpi_object_list arg_list = { 1, &arg }; |
| 642 | char *message = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 645 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | * Let the system know what interrupt model we are using by |
| 647 | * evaluating the \_PIC object, if exists. |
| 648 | */ |
| 649 | |
| 650 | switch (acpi_irq_model) { |
| 651 | case ACPI_IRQ_MODEL_PIC: |
| 652 | message = "PIC"; |
| 653 | break; |
| 654 | case ACPI_IRQ_MODEL_IOAPIC: |
| 655 | message = "IOAPIC"; |
| 656 | break; |
| 657 | case ACPI_IRQ_MODEL_IOSAPIC: |
| 658 | message = "IOSAPIC"; |
| 659 | break; |
John Keller | 3948ec9 | 2006-12-22 11:50:04 -0600 | [diff] [blame] | 660 | case ACPI_IRQ_MODEL_PLATFORM: |
| 661 | message = "platform specific model"; |
| 662 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | default: |
| 664 | printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 665 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message); |
| 669 | |
| 670 | arg.integer.value = acpi_irq_model; |
| 671 | |
| 672 | status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL); |
| 673 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 674 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 675 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 678 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 681 | u8 acpi_gbl_permanent_mmap; |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 682 | |
| 683 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 684 | void __init acpi_early_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 686 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
| 688 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 689 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 691 | printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); |
| 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | /* enable workarounds, unless strict ACPI spec. compliance */ |
| 694 | if (!acpi_strict) |
| 695 | acpi_gbl_enable_interpreter_slack = TRUE; |
| 696 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 697 | acpi_gbl_permanent_mmap = 1; |
| 698 | |
| 699 | status = acpi_reallocate_root_table(); |
| 700 | if (ACPI_FAILURE(status)) { |
| 701 | printk(KERN_ERR PREFIX |
| 702 | "Unable to reallocate ACPI tables\n"); |
| 703 | goto error0; |
| 704 | } |
| 705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | status = acpi_initialize_subsystem(); |
| 707 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 708 | printk(KERN_ERR PREFIX |
| 709 | "Unable to initialize the ACPI Interpreter\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | goto error0; |
| 711 | } |
| 712 | |
| 713 | status = acpi_load_tables(); |
| 714 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 715 | printk(KERN_ERR PREFIX |
| 716 | "Unable to load the System Description Tables\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | goto error0; |
| 718 | } |
| 719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | #ifdef CONFIG_X86 |
| 721 | if (!acpi_ioapic) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | /* compatible (0) means level (3) */ |
Alexey Starikovskiy | 5f3b1a8 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 723 | if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) { |
| 724 | acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK; |
| 725 | acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL; |
| 726 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | /* Set PIC-mode SCI trigger type */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 728 | acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt, |
Alexey Starikovskiy | 5f3b1a8 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 729 | (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | /* |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 732 | * now that acpi_gbl_FADT is initialized, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | * update it with result from INT_SRC_OVR parsing |
| 734 | */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 735 | acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | #endif |
| 738 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 739 | status = |
| 740 | acpi_enable_subsystem(~ |
| 741 | (ACPI_NO_HARDWARE_INIT | |
| 742 | ACPI_NO_ACPI_ENABLE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | if (ACPI_FAILURE(status)) { |
| 744 | printk(KERN_ERR PREFIX "Unable to enable ACPI\n"); |
| 745 | goto error0; |
| 746 | } |
| 747 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 748 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 750 | error0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | disable_acpi(); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 752 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 755 | static int __init acpi_bus_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 757 | int result = 0; |
| 758 | acpi_status status = AE_OK; |
| 759 | extern acpi_status acpi_os_initialize1(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | status = acpi_os_initialize1(); |
| 763 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 764 | status = |
| 765 | acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 767 | printk(KERN_ERR PREFIX |
| 768 | "Unable to start the ACPI Interpreter\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | goto error1; |
| 770 | } |
| 771 | |
| 772 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 773 | printk(KERN_ERR PREFIX |
| 774 | "Unable to initialize ACPI OS objects\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | goto error1; |
| 776 | } |
| 777 | #ifdef CONFIG_ACPI_EC |
| 778 | /* |
| 779 | * ACPI 2.0 requires the EC driver to be loaded and work before |
| 780 | * the EC device is found in the namespace (i.e. before acpi_initialize_objects() |
| 781 | * is called). |
| 782 | * |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 783 | * This is accomplished by looking for the ECDT table, and getting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | * the EC parameters out of that. |
| 785 | */ |
| 786 | status = acpi_ec_ecdt_probe(); |
| 787 | /* Ignore result. Not having an ECDT is not fatal. */ |
| 788 | #endif |
| 789 | |
| 790 | status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION); |
| 791 | if (ACPI_FAILURE(status)) { |
| 792 | printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n"); |
| 793 | goto error1; |
| 794 | } |
| 795 | |
Zhao Yakui | 455c879 | 2008-10-06 10:31:36 +0800 | [diff] [blame] | 796 | /* |
| 797 | * Maybe EC region is required at bus_scan/acpi_get_devices. So it |
| 798 | * is necessary to enable it as early as possible. |
| 799 | */ |
| 800 | acpi_boot_ec_enable(); |
| 801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | printk(KERN_INFO PREFIX "Interpreter enabled\n"); |
| 803 | |
Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 804 | /* Initialize sleep structures */ |
| 805 | acpi_sleep_init(); |
| 806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | /* |
| 808 | * Get the system interrupt model and evaluate \_PIC. |
| 809 | */ |
| 810 | result = acpi_bus_init_irq(); |
| 811 | if (result) |
| 812 | goto error1; |
| 813 | |
| 814 | /* |
| 815 | * Register the for all standard device notifications. |
| 816 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 817 | status = |
| 818 | acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, |
| 819 | &acpi_bus_notify, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 821 | printk(KERN_ERR PREFIX |
| 822 | "Unable to register for device notifications\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | goto error1; |
| 824 | } |
| 825 | |
| 826 | /* |
| 827 | * Create the top ACPI proc directory |
| 828 | */ |
| 829 | acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL); |
| 830 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 831 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
| 833 | /* Mimic structured exception handling */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 834 | error1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | acpi_terminate(); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 836 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Greg Kroah-Hartman | 99e0d2f | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 839 | struct kobject *acpi_kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 841 | static int __init acpi_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 843 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | if (acpi_disabled) { |
| 847 | printk(KERN_INFO PREFIX "Interpreter disabled.\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 848 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Greg Kroah-Hartman | f62ed9e | 2007-11-05 13:16:15 -0800 | [diff] [blame] | 851 | acpi_kobj = kobject_create_and_add("acpi", firmware_kobj); |
Greg Kroah-Hartman | 99e0d2f | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 852 | if (!acpi_kobj) { |
Harvey Harrison | 96b2dd1 | 2008-03-05 18:24:51 -0800 | [diff] [blame] | 853 | printk(KERN_WARNING "%s: kset create error\n", __func__); |
Greg Kroah-Hartman | 99e0d2f | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 854 | acpi_kobj = NULL; |
| 855 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
| 857 | result = acpi_bus_init(); |
| 858 | |
| 859 | if (!result) { |
Robert Hancock | 7752d5c | 2008-02-15 01:27:20 -0800 | [diff] [blame] | 860 | pci_mmcfg_late_init(); |
Len Brown | 9f9adec | 2007-12-13 17:38:03 -0500 | [diff] [blame] | 861 | if (!(pm_flags & PM_APM)) |
| 862 | pm_flags |= PM_ACPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 864 | printk(KERN_INFO PREFIX |
| 865 | "APM is already active, exiting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | disable_acpi(); |
| 867 | result = -ENODEV; |
| 868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } else |
| 870 | disable_acpi(); |
Zhao Yakui | 6415e12 | 2008-08-11 14:59:59 +0800 | [diff] [blame] | 871 | /* |
| 872 | * If the laptop falls into the DMI check table, the power state check |
| 873 | * will be disabled in the course of device power transistion. |
| 874 | */ |
| 875 | dmi_check_system(power_nocheck_dmi_table); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 876 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | subsys_initcall(acpi_init); |