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