blob: 0c1ad3105da137a6997a28b6602e6b417aba45e4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Dunlapd568df82006-07-12 01:47:00 -040028#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#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 Harrison6697c052008-02-09 23:24:08 +010034#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#ifdef CONFIG_X86
36#include <asm/mpspec.h>
37#endif
Robert Hancock7752d5c2008-02-15 01:27:20 -080038#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <acpi/acpi_bus.h>
40#include <acpi/acpi_drivers.h>
Len Browneb27cae2009-07-06 23:40:19 -040041#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060043#include "internal.h"
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050046ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Len Brown4be44fc2005-08-05 00:44:28 -040048struct acpi_device *acpi_root;
49struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050EXPORT_SYMBOL(acpi_root_dir);
51
52#define STRUCT_TO_INT(s) (*((int*)&s))
53
Zhao Yakui6415e122008-08-11 14:59:59 +080054static int set_power_nocheck(const struct dmi_system_id *id)
55{
56 printk(KERN_NOTICE PREFIX "%s detected - "
57 "disable power check in power transistion\n", id->ident);
58 acpi_power_nocheck = 1;
59 return 0;
60}
61static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
62 {
63 set_power_nocheck, "HP Pavilion 05", {
64 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
65 DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
66 DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
67 {},
68};
69
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* --------------------------------------------------------------------------
72 Device Management
73 -------------------------------------------------------------------------- */
74
Len Brown4be44fc2005-08-05 00:44:28 -040075int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Len Brown4be44fc2005-08-05 00:44:28 -040077 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -040081 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 /* TBD: Support fixed-feature devices */
84
Len Brown4be44fc2005-08-05 00:44:28 -040085 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if (ACPI_FAILURE(status) || !*device) {
Len Brown9805cb72006-07-25 13:30:57 -040087 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
88 handle));
Patrick Mocheld550d982006-06-27 00:41:40 -040089 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91
Patrick Mocheld550d982006-06-27 00:41:40 -040092 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
Len Brown4be44fc2005-08-05 00:44:28 -040094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095EXPORT_SYMBOL(acpi_bus_get_device);
96
Bjorn Helgaas402ac532009-09-21 19:30:01 +000097acpi_status acpi_bus_get_status_handle(acpi_handle handle,
98 unsigned long long *sta)
99{
100 acpi_status status;
101
102 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
103 if (ACPI_SUCCESS(status))
104 return AE_OK;
105
106 if (status == AE_NOT_FOUND) {
107 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
108 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
109 return AE_OK;
110 }
111 return status;
112}
113
Len Brown4be44fc2005-08-05 00:44:28 -0400114int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000116 acpi_status status;
117 unsigned long long sta;
Len Brown4be44fc2005-08-05 00:44:28 -0400118
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000119 status = acpi_bus_get_status_handle(device->handle, &sta);
120 if (ACPI_FAILURE(status))
121 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000123 STRUCT_TO_INT(device->status) = (int) sta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800126 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
127 "functional but not present;\n",
128 device->pnp.bus_id,
129 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
133 device->pnp.bus_id,
134 (u32) STRUCT_TO_INT(device->status)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400135 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
Len Brown4be44fc2005-08-05 00:44:28 -0400137EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Zhang Rui20733932008-01-17 15:51:21 +0800139void acpi_bus_private_data_handler(acpi_handle handle,
Bob Moore8e4319c2009-06-29 13:43:27 +0800140 void *context)
Zhang Rui20733932008-01-17 15:51:21 +0800141{
142 return;
143}
144EXPORT_SYMBOL(acpi_bus_private_data_handler);
145
146int acpi_bus_get_private_data(acpi_handle handle, void **data)
147{
148 acpi_status status = AE_OK;
149
150 if (!*data)
151 return -EINVAL;
152
153 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
154 if (ACPI_FAILURE(status) || !*data) {
155 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
156 handle));
157 return -ENODEV;
158 }
159
160 return 0;
161}
162EXPORT_SYMBOL(acpi_bus_get_private_data);
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/* --------------------------------------------------------------------------
165 Power Management
166 -------------------------------------------------------------------------- */
167
Len Brown4be44fc2005-08-05 00:44:28 -0400168int acpi_bus_get_power(acpi_handle handle, int *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Len Brown4be44fc2005-08-05 00:44:28 -0400170 int result = 0;
171 acpi_status status = 0;
172 struct acpi_device *device = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400173 unsigned long long psc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 result = acpi_bus_get_device(handle, &device);
177 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400178 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 *state = ACPI_STATE_UNKNOWN;
181
182 if (!device->flags.power_manageable) {
183 /* TBD: Non-recursive algorithm for walking up hierarchy */
184 if (device->parent)
185 *state = device->parent->power.state;
186 else
187 *state = ACPI_STATE_D0;
Len Brown4be44fc2005-08-05 00:44:28 -0400188 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /*
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500190 * Get the device's power state either directly (via _PSC) or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 * indirectly (via power resources).
192 */
193 if (device->power.flags.explicit_get) {
Len Brown4be44fc2005-08-05 00:44:28 -0400194 status = acpi_evaluate_integer(device->handle, "_PSC",
195 NULL, &psc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400197 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400198 device->power.state = (int)psc;
199 } else if (device->power.flags.power_resources) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 result = acpi_power_get_inferred_state(device);
201 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400202 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 }
204
205 *state = device->power.state;
206 }
207
208 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400209 device->pnp.bus_id, device->power.state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Patrick Mocheld550d982006-06-27 00:41:40 -0400211 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
Len Brown4be44fc2005-08-05 00:44:28 -0400213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214EXPORT_SYMBOL(acpi_bus_get_power);
215
Len Brown4be44fc2005-08-05 00:44:28 -0400216int acpi_bus_set_power(acpi_handle handle, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Len Brown4be44fc2005-08-05 00:44:28 -0400218 int result = 0;
219 acpi_status status = AE_OK;
220 struct acpi_device *device = NULL;
221 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 result = acpi_bus_get_device(handle, &device);
225 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400226 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
Patrick Mocheld550d982006-06-27 00:41:40 -0400229 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 /* Make sure this is a valid target state */
232
233 if (!device->flags.power_manageable) {
Len Brown9805cb72006-07-25 13:30:57 -0400234 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
Greg Kroah-Hartman19c38de2007-09-12 15:06:57 -0700235 kobject_name(&device->dev.kobj)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400236 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
David Shaohua Lib9131002005-03-19 00:16:18 -0500238 /*
Alexey Starikovskiyc35923b2007-10-22 14:19:09 +0400239 * Get device's current power state
David Shaohua Lib9131002005-03-19 00:16:18 -0500240 */
Zhao Yakuif5adfaa2008-08-11 14:57:50 +0800241 if (!acpi_power_nocheck) {
242 /*
243 * Maybe the incorrect power state is returned on the bogus
244 * bios, which is different with the real power state.
245 * For example: the bios returns D0 state and the real power
246 * state is D3. OS expects to set the device to D0 state. In
247 * such case if OS uses the power state returned by the BIOS,
248 * the device can't be transisted to the correct power state.
249 * So if the acpi_power_nocheck is set, it is unnecessary to
250 * get the power state by calling acpi_bus_get_power.
251 */
252 acpi_bus_get_power(device->handle, &device->power.state);
253 }
Len Brownec683732008-01-23 22:41:20 -0500254 if ((state == device->power.state) && !device->flags.force_power_state) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500255 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
256 state));
257 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -0500259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (!device->power.states[state].flags.valid) {
Len Browncece9292006-06-26 23:04:31 -0400261 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
Patrick Mocheld550d982006-06-27 00:41:40 -0400262 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
264 if (device->parent && (state < device->parent->power.state)) {
Len Browncece9292006-06-26 23:04:31 -0400265 printk(KERN_WARNING PREFIX
Thomas Renningera6fc6722006-06-26 23:58:43 -0400266 "Cannot set device to a higher-powered"
Len Browncece9292006-06-26 23:04:31 -0400267 " state than parent\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400268 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
270
271 /*
272 * Transition Power
273 * ----------------
274 * On transitions to a high-powered state we first apply power (via
275 * power resources) then evalute _PSx. Conversly for transitions to
276 * a lower-powered state.
David Shaohua Lib9131002005-03-19 00:16:18 -0500277 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (state < device->power.state) {
279 if (device->power.flags.power_resources) {
280 result = acpi_power_transition(device, state);
281 if (result)
282 goto end;
283 }
284 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400285 status = acpi_evaluate_object(device->handle,
286 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (ACPI_FAILURE(status)) {
288 result = -ENODEV;
289 goto end;
290 }
291 }
Len Brown4be44fc2005-08-05 00:44:28 -0400292 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (device->power.states[state].flags.explicit_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400294 status = acpi_evaluate_object(device->handle,
295 object_name, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (ACPI_FAILURE(status)) {
297 result = -ENODEV;
298 goto end;
299 }
300 }
301 if (device->power.flags.power_resources) {
302 result = acpi_power_transition(device, state);
303 if (result)
304 goto end;
305 }
306 }
307
Len Brown4be44fc2005-08-05 00:44:28 -0400308 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 if (result)
Len Browncece9292006-06-26 23:04:31 -0400310 printk(KERN_WARNING PREFIX
Len Brownddc50b62009-05-08 00:07:30 -0400311 "Device [%s] failed to transition to D%d\n",
Len Browncece9292006-06-26 23:04:31 -0400312 device->pnp.bus_id, state);
Shaohua Li5e321322007-10-11 23:53:58 +0200313 else {
314 device->power.state = state;
Len Brown4be44fc2005-08-05 00:44:28 -0400315 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
316 "Device [%s] transitioned to D%d\n",
317 device->pnp.bus_id, state));
Shaohua Li5e321322007-10-11 23:53:58 +0200318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Patrick Mocheld550d982006-06-27 00:41:40 -0400320 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
Len Brown4be44fc2005-08-05 00:44:28 -0400322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323EXPORT_SYMBOL(acpi_bus_set_power);
324
Rafael J. Wysocki3737b2b2008-07-07 03:30:55 +0200325bool acpi_bus_power_manageable(acpi_handle handle)
326{
327 struct acpi_device *device;
328 int result;
329
330 result = acpi_bus_get_device(handle, &device);
331 return result ? false : device->flags.power_manageable;
332}
333
334EXPORT_SYMBOL(acpi_bus_power_manageable);
335
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200336bool acpi_bus_can_wakeup(acpi_handle handle)
337{
338 struct acpi_device *device;
339 int result;
340
341 result = acpi_bus_get_device(handle, &device);
342 return result ? false : device->wakeup.flags.valid;
343}
344
345EXPORT_SYMBOL(acpi_bus_can_wakeup);
346
Shaohua Li70023de2009-10-29 11:04:28 +0800347static void acpi_print_osc_error(acpi_handle handle,
348 struct acpi_osc_context *context, char *error)
349{
350 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
351 int i;
352
353 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
354 printk(KERN_DEBUG "%s\n", error);
355 else {
356 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
357 kfree(buffer.pointer);
358 }
359 printk(KERN_DEBUG"_OSC request data:");
360 for (i = 0; i < context->cap.length; i += sizeof(u32))
361 printk("%x ", *((u32 *)(context->cap.pointer + i)));
362 printk("\n");
363}
364
365static u8 hex_val(unsigned char c)
366{
367 return isdigit(c) ? c - '0' : toupper(c) - 'A' + 10;
368}
369
370static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
371{
372 int i;
373 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
374 24, 26, 28, 30, 32, 34};
375
376 if (strlen(str) != 36)
377 return AE_BAD_PARAMETER;
378 for (i = 0; i < 36; i++) {
379 if (i == 8 || i == 13 || i == 18 || i == 23) {
380 if (str[i] != '-')
381 return AE_BAD_PARAMETER;
382 } else if (!isxdigit(str[i]))
383 return AE_BAD_PARAMETER;
384 }
385 for (i = 0; i < 16; i++) {
386 uuid[i] = hex_val(str[opc_map_to_uuid[i]]) << 4;
387 uuid[i] |= hex_val(str[opc_map_to_uuid[i] + 1]);
388 }
389 return AE_OK;
390}
391
392acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
393{
394 acpi_status status;
395 struct acpi_object_list input;
396 union acpi_object in_params[4];
397 union acpi_object *out_obj;
398 u8 uuid[16];
399 u32 errors;
Shaohua Li9dc130f2009-12-23 17:04:11 +0800400 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
Shaohua Li70023de2009-10-29 11:04:28 +0800401
402 if (!context)
403 return AE_ERROR;
404 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
405 return AE_ERROR;
406 context->ret.length = ACPI_ALLOCATE_BUFFER;
407 context->ret.pointer = NULL;
408
409 /* Setting up input parameters */
410 input.count = 4;
411 input.pointer = in_params;
412 in_params[0].type = ACPI_TYPE_BUFFER;
413 in_params[0].buffer.length = 16;
414 in_params[0].buffer.pointer = uuid;
415 in_params[1].type = ACPI_TYPE_INTEGER;
416 in_params[1].integer.value = context->rev;
417 in_params[2].type = ACPI_TYPE_INTEGER;
418 in_params[2].integer.value = context->cap.length/sizeof(u32);
419 in_params[3].type = ACPI_TYPE_BUFFER;
420 in_params[3].buffer.length = context->cap.length;
421 in_params[3].buffer.pointer = context->cap.pointer;
422
Shaohua Li9dc130f2009-12-23 17:04:11 +0800423 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
Shaohua Li70023de2009-10-29 11:04:28 +0800424 if (ACPI_FAILURE(status))
425 return status;
426
Shaohua Li9dc130f2009-12-23 17:04:11 +0800427 if (!output.length)
Shaohua Li70023de2009-10-29 11:04:28 +0800428 return AE_NULL_OBJECT;
429
Shaohua Li9dc130f2009-12-23 17:04:11 +0800430 out_obj = output.pointer;
431 if (out_obj->type != ACPI_TYPE_BUFFER
432 || out_obj->buffer.length != context->cap.length) {
Shaohua Li70023de2009-10-29 11:04:28 +0800433 acpi_print_osc_error(handle, context,
434 "_OSC evaluation returned wrong type");
435 status = AE_TYPE;
436 goto out_kfree;
437 }
438 /* Need to ignore the bit0 in result code */
439 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
440 if (errors) {
441 if (errors & OSC_REQUEST_ERROR)
442 acpi_print_osc_error(handle, context,
443 "_OSC request failed");
444 if (errors & OSC_INVALID_UUID_ERROR)
445 acpi_print_osc_error(handle, context,
446 "_OSC invalid UUID");
447 if (errors & OSC_INVALID_REVISION_ERROR)
448 acpi_print_osc_error(handle, context,
449 "_OSC invalid revision");
450 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
451 if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
452 & OSC_QUERY_ENABLE)
453 goto out_success;
454 status = AE_SUPPORT;
455 goto out_kfree;
456 }
457 status = AE_ERROR;
458 goto out_kfree;
459 }
460out_success:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800461 context->ret.length = out_obj->buffer.length;
462 context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
463 if (!context->ret.pointer) {
464 status = AE_NO_MEMORY;
465 goto out_kfree;
466 }
467 memcpy(context->ret.pointer, out_obj->buffer.pointer,
468 context->ret.length);
469 status = AE_OK;
Shaohua Li70023de2009-10-29 11:04:28 +0800470
471out_kfree:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800472 kfree(output.pointer);
473 if (status != AE_OK)
474 context->ret.pointer = NULL;
Shaohua Li70023de2009-10-29 11:04:28 +0800475 return status;
476}
477EXPORT_SYMBOL(acpi_run_osc);
478
Shaohua Li3563ff92009-10-29 11:05:05 +0800479static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
480static void acpi_bus_osc_support(void)
481{
482 u32 capbuf[2];
483 struct acpi_osc_context context = {
484 .uuid_str = sb_uuid_str,
485 .rev = 1,
486 .cap.length = 8,
487 .cap.pointer = capbuf,
488 };
489 acpi_handle handle;
490
491 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
492 capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
493#ifdef CONFIG_ACPI_PROCESSOR_AGGREGATOR
494 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
495#endif
496 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
497 return;
498 if (ACPI_SUCCESS(acpi_run_osc(handle, &context)))
499 kfree(context.ret.pointer);
500 /* do we need to check the returned cap? Sounds no */
501}
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503/* --------------------------------------------------------------------------
504 Event Management
505 -------------------------------------------------------------------------- */
506
Len Brown14e04fb2007-08-23 15:20:26 -0400507#ifdef CONFIG_ACPI_PROC_EVENT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508static DEFINE_SPINLOCK(acpi_bus_event_lock);
509
510LIST_HEAD(acpi_bus_event_list);
511DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
512
Len Brown4be44fc2005-08-05 00:44:28 -0400513extern int event_is_open;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400515int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400517 struct acpi_bus_event *event;
Len Brown4be44fc2005-08-05 00:44:28 -0400518 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 /* drop event on the floor if no one's listening */
521 if (!event_is_open)
Patrick Mocheld550d982006-06-27 00:41:40 -0400522 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
525 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400526 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400528 strcpy(event->device_class, device_class);
529 strcpy(event->bus_id, bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 event->type = type;
531 event->data = data;
532
533 spin_lock_irqsave(&acpi_bus_event_lock, flags);
534 list_add_tail(&event->node, &acpi_bus_event_list);
535 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
536
537 wake_up_interruptible(&acpi_bus_event_queue);
538
Patrick Mocheld550d982006-06-27 00:41:40 -0400539 return 0;
Alexey Starikovskiy8db85d42007-09-26 19:43:16 +0400540
541}
542
543EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
544
545int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
546{
547 if (!device)
548 return -EINVAL;
549 return acpi_bus_generate_proc_event4(device->pnp.device_class,
550 device->pnp.bus_id, type, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
Len Brown4be44fc2005-08-05 00:44:28 -0400552
Len Brown14e04fb2007-08-23 15:20:26 -0400553EXPORT_SYMBOL(acpi_bus_generate_proc_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Len Brown4be44fc2005-08-05 00:44:28 -0400555int acpi_bus_receive_event(struct acpi_bus_event *event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
Len Brown4be44fc2005-08-05 00:44:28 -0400557 unsigned long flags = 0;
558 struct acpi_bus_event *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 DECLARE_WAITQUEUE(wait, current);
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 if (!event)
Patrick Mocheld550d982006-06-27 00:41:40 -0400564 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 if (list_empty(&acpi_bus_event_list)) {
567
568 set_current_state(TASK_INTERRUPTIBLE);
569 add_wait_queue(&acpi_bus_event_queue, &wait);
570
571 if (list_empty(&acpi_bus_event_list))
572 schedule();
573
574 remove_wait_queue(&acpi_bus_event_queue, &wait);
575 set_current_state(TASK_RUNNING);
576
577 if (signal_pending(current))
Patrick Mocheld550d982006-06-27 00:41:40 -0400578 return -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
581 spin_lock_irqsave(&acpi_bus_event_lock, flags);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700582 if (!list_empty(&acpi_bus_event_list)) {
583 entry = list_entry(acpi_bus_event_list.next,
584 struct acpi_bus_event, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 list_del(&entry->node);
Chuck Ebbertf0a37e02008-04-15 14:34:47 -0700586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
588
589 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400590 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 memcpy(event, entry, sizeof(struct acpi_bus_event));
593
594 kfree(entry);
595
Patrick Mocheld550d982006-06-27 00:41:40 -0400596 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Len Brown14e04fb2007-08-23 15:20:26 -0400599#endif /* CONFIG_ACPI_PROC_EVENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601/* --------------------------------------------------------------------------
602 Notification Handling
603 -------------------------------------------------------------------------- */
604
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600605static void acpi_bus_check_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600607 struct acpi_device *device;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600608 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 struct acpi_device_status old_status;
610
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600611 if (acpi_bus_get_device(handle, &device))
612 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 if (!device)
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600614 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 old_status = device->status;
617
618 /*
619 * Make sure this device's parent is present before we go about
620 * messing with the device.
621 */
622 if (device->parent && !device->parent->status.present) {
623 device->status = device->parent->status;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600624 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626
627 status = acpi_bus_get_status(device);
628 if (ACPI_FAILURE(status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600629 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600632 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 /*
635 * Device Insertion/Removal
636 */
637 if ((device->status.present) && !(old_status.present)) {
638 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
639 /* TBD: Handle device insertion */
Len Brown4be44fc2005-08-05 00:44:28 -0400640 } else if (!(device->status.present) && (old_status.present)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
642 /* TBD: Handle device removal */
643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644}
645
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600646static void acpi_bus_check_scope(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 /* Status Change? */
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600649 acpi_bus_check_device(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /*
652 * TBD: Enumerate child devices within this device's scope and
653 * run acpi_bus_check_device()'s on them.
654 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
Shaohua Li6bd00a62008-08-28 10:04:29 +0800657static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
658int register_acpi_bus_notifier(struct notifier_block *nb)
659{
660 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
661}
662EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
663
664void unregister_acpi_bus_notifier(struct notifier_block *nb)
665{
666 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
667}
668EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670/**
671 * acpi_bus_notify
672 * ---------------
673 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
674 */
Len Brown4be44fc2005-08-05 00:44:28 -0400675static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Len Brown4be44fc2005-08-05 00:44:28 -0400677 struct acpi_device *device = NULL;
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600678 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Bjorn Helgaas02c37bd2009-05-22 11:43:41 -0600680 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
681 type, handle));
682
Shaohua Li6bd00a62008-08-28 10:04:29 +0800683 blocking_notifier_call_chain(&acpi_bus_notify_list,
684 type, (void *)handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 switch (type) {
687
688 case ACPI_NOTIFY_BUS_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600689 acpi_bus_check_scope(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500690 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400692 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 */
694 break;
695
696 case ACPI_NOTIFY_DEVICE_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600697 acpi_bus_check_device(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500698 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400700 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 */
702 break;
703
704 case ACPI_NOTIFY_DEVICE_WAKE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 /* TBD */
706 break;
707
708 case ACPI_NOTIFY_EJECT_REQUEST:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 /* TBD */
710 break;
711
712 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 /* TBD: Exactly what does 'light' mean? */
714 break;
715
716 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 /* TBD */
718 break;
719
720 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 /* TBD */
722 break;
723
724 case ACPI_NOTIFY_POWER_FAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 /* TBD */
726 break;
727
728 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400729 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
730 "Received unknown/unsupported notification [%08x]\n",
731 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 break;
733 }
734
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600735 acpi_bus_get_device(handle, &device);
736 if (device) {
737 driver = device->driver;
738 if (driver && driver->ops.notify &&
739 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
740 driver->ops.notify(device, type);
741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
744/* --------------------------------------------------------------------------
745 Initialization/Cleanup
746 -------------------------------------------------------------------------- */
747
Len Brown4be44fc2005-08-05 00:44:28 -0400748static int __init acpi_bus_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
Len Brown4be44fc2005-08-05 00:44:28 -0400750 acpi_status status = AE_OK;
751 union acpi_object arg = { ACPI_TYPE_INTEGER };
752 struct acpi_object_list arg_list = { 1, &arg };
753 char *message = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500756 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 * Let the system know what interrupt model we are using by
758 * evaluating the \_PIC object, if exists.
759 */
760
761 switch (acpi_irq_model) {
762 case ACPI_IRQ_MODEL_PIC:
763 message = "PIC";
764 break;
765 case ACPI_IRQ_MODEL_IOAPIC:
766 message = "IOAPIC";
767 break;
768 case ACPI_IRQ_MODEL_IOSAPIC:
769 message = "IOSAPIC";
770 break;
John Keller3948ec92006-12-22 11:50:04 -0600771 case ACPI_IRQ_MODEL_PLATFORM:
772 message = "platform specific model";
773 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 default:
775 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400776 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 }
778
779 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
780
781 arg.integer.value = acpi_irq_model;
782
783 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
784 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400785 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400786 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 }
788
Patrick Mocheld550d982006-06-27 00:41:40 -0400789 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
791
Bob Moore67a119f2008-06-10 13:42:13 +0800792u8 acpi_gbl_permanent_mmap;
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300793
794
Len Brown4be44fc2005-08-05 00:44:28 -0400795void __init acpi_early_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
Len Brown4be44fc2005-08-05 00:44:28 -0400797 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400800 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Bob Moore61686122006-03-17 16:44:00 -0500802 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 /* enable workarounds, unless strict ACPI spec. compliance */
805 if (!acpi_strict)
806 acpi_gbl_enable_interpreter_slack = TRUE;
807
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300808 acpi_gbl_permanent_mmap = 1;
809
810 status = acpi_reallocate_root_table();
811 if (ACPI_FAILURE(status)) {
812 printk(KERN_ERR PREFIX
813 "Unable to reallocate ACPI tables\n");
814 goto error0;
815 }
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 status = acpi_initialize_subsystem();
818 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400819 printk(KERN_ERR PREFIX
820 "Unable to initialize the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 goto error0;
822 }
823
824 status = acpi_load_tables();
825 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400826 printk(KERN_ERR PREFIX
827 "Unable to load the System Description Tables\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 goto error0;
829 }
830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831#ifdef CONFIG_X86
832 if (!acpi_ioapic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 /* compatible (0) means level (3) */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300834 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
835 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
836 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 /* Set PIC-mode SCI trigger type */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300839 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300840 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 /*
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300843 * now that acpi_gbl_FADT is initialized,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 * update it with result from INT_SRC_OVR parsing
845 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300846 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848#endif
849
Len Brown4be44fc2005-08-05 00:44:28 -0400850 status =
851 acpi_enable_subsystem(~
852 (ACPI_NO_HARDWARE_INIT |
853 ACPI_NO_ACPI_ENABLE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 if (ACPI_FAILURE(status)) {
855 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
856 goto error0;
857 }
858
Patrick Mocheld550d982006-06-27 00:41:40 -0400859 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Len Brown4be44fc2005-08-05 00:44:28 -0400861 error0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 disable_acpi();
Patrick Mocheld550d982006-06-27 00:41:40 -0400863 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864}
865
Len Brown4be44fc2005-08-05 00:44:28 -0400866static int __init acpi_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Len Brown4be44fc2005-08-05 00:44:28 -0400868 int result = 0;
869 acpi_status status = AE_OK;
870 extern acpi_status acpi_os_initialize1(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Jiri Slaby176f9c12009-03-04 11:55:27 -0800872 acpi_os_initialize1();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Len Brown4be44fc2005-08-05 00:44:28 -0400874 status =
875 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400877 printk(KERN_ERR PREFIX
878 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 goto error1;
880 }
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 /*
883 * ACPI 2.0 requires the EC driver to be loaded and work before
884 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
885 * is called).
886 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500887 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 * the EC parameters out of that.
889 */
890 status = acpi_ec_ecdt_probe();
891 /* Ignore result. Not having an ECDT is not fatal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Shaohua Li3563ff92009-10-29 11:05:05 +0800893 acpi_bus_osc_support();
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
896 if (ACPI_FAILURE(status)) {
897 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
898 goto error1;
899 }
900
Zhao Yakui455c8792008-10-06 10:31:36 +0800901 /*
902 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
903 * is necessary to enable it as early as possible.
904 */
905 acpi_boot_ec_enable();
906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 printk(KERN_INFO PREFIX "Interpreter enabled\n");
908
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500909 /* Initialize sleep structures */
910 acpi_sleep_init();
911
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 /*
913 * Get the system interrupt model and evaluate \_PIC.
914 */
915 result = acpi_bus_init_irq();
916 if (result)
917 goto error1;
918
919 /*
920 * Register the for all standard device notifications.
921 */
Len Brown4be44fc2005-08-05 00:44:28 -0400922 status =
923 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
924 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400926 printk(KERN_ERR PREFIX
927 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 goto error1;
929 }
930
931 /*
932 * Create the top ACPI proc directory
933 */
934 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
935
Patrick Mocheld550d982006-06-27 00:41:40 -0400936 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -0400939 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -0400941 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700944struct kobject *acpi_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Len Brown4be44fc2005-08-05 00:44:28 -0400946static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Len Brown4be44fc2005-08-05 00:44:28 -0400948 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 if (acpi_disabled) {
952 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400953 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
955
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -0800956 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700957 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -0800958 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700959 acpi_kobj = NULL;
960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Bjorn Helgaas0e465172009-03-24 16:50:09 -0600962 init_acpi_device_notify();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 result = acpi_bus_init();
964
965 if (!result) {
Robert Hancock7752d5c2008-02-15 01:27:20 -0800966 pci_mmcfg_late_init();
Len Brown9f9adec2007-12-13 17:38:03 -0500967 if (!(pm_flags & PM_APM))
968 pm_flags |= PM_ACPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400970 printk(KERN_INFO PREFIX
971 "APM is already active, exiting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 disable_acpi();
973 result = -ENODEV;
974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 } else
976 disable_acpi();
Bjorn Helgaas81d02732009-03-24 16:49:38 -0600977
978 if (acpi_disabled)
979 return result;
980
Zhao Yakui6415e122008-08-11 14:59:59 +0800981 /*
982 * If the laptop falls into the DMI check table, the power state check
983 * will be disabled in the course of device power transistion.
984 */
985 dmi_check_system(power_nocheck_dmi_table);
Bjorn Helgaase747f272009-03-24 16:49:43 -0600986
987 acpi_scan_init();
Bjorn Helgaasa5f820f2009-03-24 16:49:48 -0600988 acpi_ec_init();
Bjorn Helgaas44515372009-03-24 16:49:53 -0600989 acpi_power_init();
Bjorn Helgaas141a0af2009-03-24 16:49:58 -0600990 acpi_system_init();
Bjorn Helgaas84f810c2009-03-24 16:50:03 -0600991 acpi_debug_init();
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -0600992 acpi_sleep_proc_init();
Bjorn Helgaas201b8c62009-03-24 16:50:19 -0600993 acpi_wakeup_device_init();
Patrick Mocheld550d982006-06-27 00:41:40 -0400994 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
997subsys_initcall(acpi_init);