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