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