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