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