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