blob: f509019ee2c70294e9c37587151cc13ce0cb5f45 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#ifdef CONFIG_X86
37#include <asm/mpspec.h>
38#endif
Robert Hancock7752d5c2008-02-15 01:27:20 -080039#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <acpi/acpi_bus.h>
41#include <acpi/acpi_drivers.h>
Huang Yingeccddd32011-07-13 13:14:20 +080042#include <acpi/apei.h>
Len Browneb27cae2009-07-06 23:40:19 -040043#include <linux/dmi.h>
Rafael J. Wysockicd51e61c2011-02-11 00:04:52 +010044#include <linux/suspend.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060046#include "internal.h"
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050049ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Len Brown4be44fc2005-08-05 00:44:28 -040051struct acpi_device *acpi_root;
52struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053EXPORT_SYMBOL(acpi_root_dir);
54
Lin Mingcce4f632010-05-12 09:26:48 +080055#ifdef CONFIG_X86
Lin Mingaa2110c2010-04-08 14:34:27 +080056static int set_copy_dsdt(const struct dmi_system_id *id)
57{
58 printk(KERN_NOTICE "%s detected - "
59 "force copy of DSDT to local memory\n", id->ident);
60 acpi_gbl_copy_dsdt_locally = 1;
61 return 0;
62}
63
64static struct dmi_system_id dsdt_dmi_table[] __initdata = {
65 /*
Len Brown100cf872010-09-28 22:57:02 -040066 * Invoke DSDT corruption work-around on all Toshiba Satellite.
Lin Mingaa2110c2010-04-08 14:34:27 +080067 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
68 */
69 {
70 .callback = set_copy_dsdt,
Len Brown100cf872010-09-28 22:57:02 -040071 .ident = "TOSHIBA Satellite",
Lin Mingaa2110c2010-04-08 14:34:27 +080072 .matches = {
73 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Len Brown100cf872010-09-28 22:57:02 -040074 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
Lin Mingaa2110c2010-04-08 14:34:27 +080075 },
Lin Mingcce4f632010-05-12 09:26:48 +080076 },
77 {}
Lin Mingaa2110c2010-04-08 14:34:27 +080078};
Lin Mingcce4f632010-05-12 09:26:48 +080079#else
80static struct dmi_system_id dsdt_dmi_table[] __initdata = {
81 {}
82};
83#endif
Lin Mingaa2110c2010-04-08 14:34:27 +080084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* --------------------------------------------------------------------------
86 Device Management
87 -------------------------------------------------------------------------- */
88
Bjorn Helgaas402ac532009-09-21 19:30:01 +000089acpi_status acpi_bus_get_status_handle(acpi_handle handle,
90 unsigned long long *sta)
91{
92 acpi_status status;
93
94 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
95 if (ACPI_SUCCESS(status))
96 return AE_OK;
97
98 if (status == AE_NOT_FOUND) {
99 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
100 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
101 return AE_OK;
102 }
103 return status;
104}
105
Len Brown4be44fc2005-08-05 00:44:28 -0400106int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000108 acpi_status status;
109 unsigned long long sta;
Len Brown4be44fc2005-08-05 00:44:28 -0400110
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000111 status = acpi_bus_get_status_handle(device->handle, &sta);
112 if (ACPI_FAILURE(status))
113 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Rafael J. Wysocki25db1152013-11-22 21:56:06 +0100115 acpi_set_device_status(device, sta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800118 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
119 "functional but not present;\n",
Rafael J. Wysocki25db1152013-11-22 21:56:06 +0100120 device->pnp.bus_id, (u32)sta));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
Len Brown4be44fc2005-08-05 00:44:28 -0400123 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
Rafael J. Wysocki25db1152013-11-22 21:56:06 +0100124 device->pnp.bus_id, (u32)sta));
Patrick Mocheld550d982006-06-27 00:41:40 -0400125 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
Len Brown4be44fc2005-08-05 00:44:28 -0400127EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Zhang Rui20733932008-01-17 15:51:21 +0800129void acpi_bus_private_data_handler(acpi_handle handle,
Bob Moore8e4319c2009-06-29 13:43:27 +0800130 void *context)
Zhang Rui20733932008-01-17 15:51:21 +0800131{
132 return;
133}
134EXPORT_SYMBOL(acpi_bus_private_data_handler);
135
136int acpi_bus_get_private_data(acpi_handle handle, void **data)
137{
Bjorn Helgaas6a8c0af2013-06-03 18:20:24 +0000138 acpi_status status;
Zhang Rui20733932008-01-17 15:51:21 +0800139
140 if (!*data)
141 return -EINVAL;
142
143 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
144 if (ACPI_FAILURE(status) || !*data) {
145 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
146 handle));
147 return -ENODEV;
148 }
149
150 return 0;
151}
152EXPORT_SYMBOL(acpi_bus_get_private_data);
153
Shaohua Li70023de2009-10-29 11:04:28 +0800154static void acpi_print_osc_error(acpi_handle handle,
155 struct acpi_osc_context *context, char *error)
156{
157 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
158 int i;
159
160 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
161 printk(KERN_DEBUG "%s\n", error);
162 else {
163 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
164 kfree(buffer.pointer);
165 }
166 printk(KERN_DEBUG"_OSC request data:");
167 for (i = 0; i < context->cap.length; i += sizeof(u32))
168 printk("%x ", *((u32 *)(context->cap.pointer + i)));
169 printk("\n");
170}
171
Chen, Gong4b3db702013-10-21 14:29:25 -0700172acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
Shaohua Li70023de2009-10-29 11:04:28 +0800173{
174 int i;
175 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
176 24, 26, 28, 30, 32, 34};
177
178 if (strlen(str) != 36)
179 return AE_BAD_PARAMETER;
180 for (i = 0; i < 36; i++) {
181 if (i == 8 || i == 13 || i == 18 || i == 23) {
182 if (str[i] != '-')
183 return AE_BAD_PARAMETER;
184 } else if (!isxdigit(str[i]))
185 return AE_BAD_PARAMETER;
186 }
187 for (i = 0; i < 16; i++) {
Andy Shevchenko965fd9e2010-05-24 14:33:28 -0700188 uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
189 uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
Shaohua Li70023de2009-10-29 11:04:28 +0800190 }
191 return AE_OK;
192}
Chen, Gong4b3db702013-10-21 14:29:25 -0700193EXPORT_SYMBOL_GPL(acpi_str_to_uuid);
Shaohua Li70023de2009-10-29 11:04:28 +0800194
195acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
196{
197 acpi_status status;
198 struct acpi_object_list input;
199 union acpi_object in_params[4];
200 union acpi_object *out_obj;
201 u8 uuid[16];
202 u32 errors;
Shaohua Li9dc130f2009-12-23 17:04:11 +0800203 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
Shaohua Li70023de2009-10-29 11:04:28 +0800204
205 if (!context)
206 return AE_ERROR;
207 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
208 return AE_ERROR;
209 context->ret.length = ACPI_ALLOCATE_BUFFER;
210 context->ret.pointer = NULL;
211
212 /* Setting up input parameters */
213 input.count = 4;
214 input.pointer = in_params;
215 in_params[0].type = ACPI_TYPE_BUFFER;
216 in_params[0].buffer.length = 16;
217 in_params[0].buffer.pointer = uuid;
218 in_params[1].type = ACPI_TYPE_INTEGER;
219 in_params[1].integer.value = context->rev;
220 in_params[2].type = ACPI_TYPE_INTEGER;
221 in_params[2].integer.value = context->cap.length/sizeof(u32);
222 in_params[3].type = ACPI_TYPE_BUFFER;
223 in_params[3].buffer.length = context->cap.length;
224 in_params[3].buffer.pointer = context->cap.pointer;
225
Shaohua Li9dc130f2009-12-23 17:04:11 +0800226 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
Shaohua Li70023de2009-10-29 11:04:28 +0800227 if (ACPI_FAILURE(status))
228 return status;
229
Shaohua Li9dc130f2009-12-23 17:04:11 +0800230 if (!output.length)
Shaohua Li70023de2009-10-29 11:04:28 +0800231 return AE_NULL_OBJECT;
232
Shaohua Li9dc130f2009-12-23 17:04:11 +0800233 out_obj = output.pointer;
234 if (out_obj->type != ACPI_TYPE_BUFFER
235 || out_obj->buffer.length != context->cap.length) {
Shaohua Li70023de2009-10-29 11:04:28 +0800236 acpi_print_osc_error(handle, context,
237 "_OSC evaluation returned wrong type");
238 status = AE_TYPE;
239 goto out_kfree;
240 }
241 /* Need to ignore the bit0 in result code */
242 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
243 if (errors) {
244 if (errors & OSC_REQUEST_ERROR)
245 acpi_print_osc_error(handle, context,
246 "_OSC request failed");
247 if (errors & OSC_INVALID_UUID_ERROR)
248 acpi_print_osc_error(handle, context,
249 "_OSC invalid UUID");
250 if (errors & OSC_INVALID_REVISION_ERROR)
251 acpi_print_osc_error(handle, context,
252 "_OSC invalid revision");
253 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600254 if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD]
Shaohua Li70023de2009-10-29 11:04:28 +0800255 & OSC_QUERY_ENABLE)
256 goto out_success;
257 status = AE_SUPPORT;
258 goto out_kfree;
259 }
260 status = AE_ERROR;
261 goto out_kfree;
262 }
263out_success:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800264 context->ret.length = out_obj->buffer.length;
Andrei Epuree2cb5f02013-03-11 08:20:16 +0000265 context->ret.pointer = kmemdup(out_obj->buffer.pointer,
266 context->ret.length, GFP_KERNEL);
Shaohua Li9dc130f2009-12-23 17:04:11 +0800267 if (!context->ret.pointer) {
268 status = AE_NO_MEMORY;
269 goto out_kfree;
270 }
Shaohua Li9dc130f2009-12-23 17:04:11 +0800271 status = AE_OK;
Shaohua Li70023de2009-10-29 11:04:28 +0800272
273out_kfree:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800274 kfree(output.pointer);
275 if (status != AE_OK)
276 context->ret.pointer = NULL;
Shaohua Li70023de2009-10-29 11:04:28 +0800277 return status;
278}
279EXPORT_SYMBOL(acpi_run_osc);
280
Huang Yingeccddd32011-07-13 13:14:20 +0800281bool osc_sb_apei_support_acked;
Shaohua Li3563ff92009-10-29 11:05:05 +0800282static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
283static void acpi_bus_osc_support(void)
284{
285 u32 capbuf[2];
286 struct acpi_osc_context context = {
287 .uuid_str = sb_uuid_str,
288 .rev = 1,
289 .cap.length = 8,
290 .cap.pointer = capbuf,
291 };
292 acpi_handle handle;
293
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600294 capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
295 capbuf[OSC_SUPPORT_DWORD] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800296#if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
297 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600298 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PAD_SUPPORT;
Shaohua Li3563ff92009-10-29 11:05:05 +0800299#endif
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800300
301#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600302 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800303#endif
Huang Yingeccddd32011-07-13 13:14:20 +0800304
Toshi Kanic2f41912012-05-23 20:25:24 -0600305#ifdef ACPI_HOTPLUG_OST
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600306 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
Toshi Kanic2f41912012-05-23 20:25:24 -0600307#endif
308
Huang Yingeccddd32011-07-13 13:14:20 +0800309 if (!ghes_disable)
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600310 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
Shaohua Li3563ff92009-10-29 11:05:05 +0800311 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
312 return;
Huang Yingeccddd32011-07-13 13:14:20 +0800313 if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
314 u32 *capbuf_ret = context.ret.pointer;
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600315 if (context.ret.length > OSC_SUPPORT_DWORD)
Huang Yingeccddd32011-07-13 13:14:20 +0800316 osc_sb_apei_support_acked =
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600317 capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
Shaohua Li3563ff92009-10-29 11:05:05 +0800318 kfree(context.ret.pointer);
Huang Yingeccddd32011-07-13 13:14:20 +0800319 }
320 /* do we need to check other returned cap? Sounds no */
Shaohua Li3563ff92009-10-29 11:05:05 +0800321}
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/* --------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 Notification Handling
325 -------------------------------------------------------------------------- */
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/**
328 * acpi_bus_notify
329 * ---------------
330 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
331 */
Len Brown4be44fc2005-08-05 00:44:28 -0400332static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
Len Brown4be44fc2005-08-05 00:44:28 -0400334 struct acpi_device *device = NULL;
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600335 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Bjorn Helgaas02c37bd2009-05-22 11:43:41 -0600337 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
338 type, handle));
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 switch (type) {
341
342 case ACPI_NOTIFY_BUS_CHECK:
Rafael J. Wysockif4b734c2013-11-22 21:55:55 +0100343 /* TBD */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 break;
345
346 case ACPI_NOTIFY_DEVICE_CHECK:
Rafael J. Wysockif4b734c2013-11-22 21:55:55 +0100347 /* TBD */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 break;
349
350 case ACPI_NOTIFY_DEVICE_WAKE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 /* TBD */
352 break;
353
354 case ACPI_NOTIFY_EJECT_REQUEST:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 /* TBD */
356 break;
357
358 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 /* TBD: Exactly what does 'light' mean? */
360 break;
361
362 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* TBD */
364 break;
365
366 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /* TBD */
368 break;
369
370 case ACPI_NOTIFY_POWER_FAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* TBD */
372 break;
373
374 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400375 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
376 "Received unknown/unsupported notification [%08x]\n",
377 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 break;
379 }
380
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600381 acpi_bus_get_device(handle, &device);
382 if (device) {
383 driver = device->driver;
384 if (driver && driver->ops.notify &&
385 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
386 driver->ops.notify(device, type);
387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388}
389
390/* --------------------------------------------------------------------------
391 Initialization/Cleanup
392 -------------------------------------------------------------------------- */
393
Len Brown4be44fc2005-08-05 00:44:28 -0400394static int __init acpi_bus_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Bjorn Helgaas6a8c0af2013-06-03 18:20:24 +0000396 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400397 char *message = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500400 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 * Let the system know what interrupt model we are using by
402 * evaluating the \_PIC object, if exists.
403 */
404
405 switch (acpi_irq_model) {
406 case ACPI_IRQ_MODEL_PIC:
407 message = "PIC";
408 break;
409 case ACPI_IRQ_MODEL_IOAPIC:
410 message = "IOAPIC";
411 break;
412 case ACPI_IRQ_MODEL_IOSAPIC:
413 message = "IOSAPIC";
414 break;
John Keller3948ec92006-12-22 11:50:04 -0600415 case ACPI_IRQ_MODEL_PLATFORM:
416 message = "platform specific model";
417 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 default:
419 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400420 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
422
423 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
424
Jiang Liu0db98202013-06-29 00:24:39 +0800425 status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400427 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400428 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430
Patrick Mocheld550d982006-06-27 00:41:40 -0400431 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
Bob Moore67a119f2008-06-10 13:42:13 +0800434u8 acpi_gbl_permanent_mmap;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300435
436
Len Brown4be44fc2005-08-05 00:44:28 -0400437void __init acpi_early_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Bjorn Helgaas6a8c0af2013-06-03 18:20:24 +0000439 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400442 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Bob Moore616861242006-03-17 16:44:00 -0500444 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 /* enable workarounds, unless strict ACPI spec. compliance */
447 if (!acpi_strict)
448 acpi_gbl_enable_interpreter_slack = TRUE;
449
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300450 acpi_gbl_permanent_mmap = 1;
451
Lin Mingaa2110c2010-04-08 14:34:27 +0800452 /*
453 * If the machine falls into the DMI check table,
454 * DSDT will be copied to memory
455 */
456 dmi_check_system(dsdt_dmi_table);
457
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300458 status = acpi_reallocate_root_table();
459 if (ACPI_FAILURE(status)) {
460 printk(KERN_ERR PREFIX
461 "Unable to reallocate ACPI tables\n");
462 goto error0;
463 }
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 status = acpi_initialize_subsystem();
466 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400467 printk(KERN_ERR PREFIX
468 "Unable to initialize the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 goto error0;
470 }
471
472 status = acpi_load_tables();
473 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400474 printk(KERN_ERR PREFIX
475 "Unable to load the System Description Tables\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 goto error0;
477 }
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#ifdef CONFIG_X86
480 if (!acpi_ioapic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 /* compatible (0) means level (3) */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300482 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
483 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
484 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 /* Set PIC-mode SCI trigger type */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300487 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300488 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 /*
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300491 * now that acpi_gbl_FADT is initialized,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 * update it with result from INT_SRC_OVR parsing
493 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300494 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496#endif
497
Rafael J. Wysocki4505a202011-11-06 14:20:42 +0100498 status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 if (ACPI_FAILURE(status)) {
500 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
501 goto error0;
502 }
503
Patrick Mocheld550d982006-06-27 00:41:40 -0400504 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Len Brown4be44fc2005-08-05 00:44:28 -0400506 error0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 disable_acpi();
Patrick Mocheld550d982006-06-27 00:41:40 -0400508 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
Len Brown4be44fc2005-08-05 00:44:28 -0400511static int __init acpi_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Bjorn Helgaas6a8c0af2013-06-03 18:20:24 +0000513 int result;
514 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Jiri Slaby176f9c12009-03-04 11:55:27 -0800516 acpi_os_initialize1();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Rafael J. Wysocki4505a202011-11-06 14:20:42 +0100518 status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400520 printk(KERN_ERR PREFIX
521 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 goto error1;
523 }
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 /*
526 * ACPI 2.0 requires the EC driver to be loaded and work before
527 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
528 * is called).
529 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500530 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * the EC parameters out of that.
532 */
533 status = acpi_ec_ecdt_probe();
534 /* Ignore result. Not having an ECDT is not fatal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
537 if (ACPI_FAILURE(status)) {
538 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
539 goto error1;
540 }
541
Zhang Ruib1d248d2010-10-26 10:06:54 +0800542 /*
Lin Mingfc54ab72012-07-16 16:30:21 +0800543 * _OSC method may exist in module level code,
544 * so it must be run after ACPI_FULL_INITIALIZATION
545 */
546 acpi_bus_osc_support();
547
548 /*
Zhang Ruib1d248d2010-10-26 10:06:54 +0800549 * _PDC control method may load dynamic SSDT tables,
550 * and we need to install the table handler before that.
551 */
552 acpi_sysfs_init();
553
Alex Chiang78f16992009-12-20 12:19:09 -0700554 acpi_early_processor_set_pdc();
555
Zhao Yakui455c8792008-10-06 10:31:36 +0800556 /*
557 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
558 * is necessary to enable it as early as possible.
559 */
560 acpi_boot_ec_enable();
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 printk(KERN_INFO PREFIX "Interpreter enabled\n");
563
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500564 /* Initialize sleep structures */
565 acpi_sleep_init();
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 /*
568 * Get the system interrupt model and evaluate \_PIC.
569 */
570 result = acpi_bus_init_irq();
571 if (result)
572 goto error1;
573
574 /*
575 * Register the for all standard device notifications.
576 */
Len Brown4be44fc2005-08-05 00:44:28 -0400577 status =
578 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
579 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400581 printk(KERN_ERR PREFIX
582 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 goto error1;
584 }
585
586 /*
587 * Create the top ACPI proc directory
588 */
589 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
590
Patrick Mocheld550d982006-06-27 00:41:40 -0400591 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -0400594 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -0400596 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700599struct kobject *acpi_kobj;
Matthew Garrettf2d47532012-01-31 13:19:19 -0500600EXPORT_SYMBOL_GPL(acpi_kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Len Brown4be44fc2005-08-05 00:44:28 -0400602static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100604 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 if (acpi_disabled) {
607 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400608 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 }
610
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -0800611 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700612 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -0800613 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700614 acpi_kobj = NULL;
615 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Bjorn Helgaas0e465172009-03-24 16:50:09 -0600617 init_acpi_device_notify();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 result = acpi_bus_init();
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100619 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 disable_acpi();
Bjorn Helgaas81d02732009-03-24 16:49:38 -0600621 return result;
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100622 }
Bjorn Helgaas81d02732009-03-24 16:49:38 -0600623
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100624 pci_mmcfg_late_init();
Bjorn Helgaase747f272009-03-24 16:49:43 -0600625 acpi_scan_init();
Bjorn Helgaasa5f820f2009-03-24 16:49:48 -0600626 acpi_ec_init();
Zhang Ruia25ee922010-07-15 10:46:15 +0800627 acpi_debugfs_init();
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -0600628 acpi_sleep_proc_init();
Bjorn Helgaas201b8c62009-03-24 16:50:19 -0600629 acpi_wakeup_device_init();
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100630 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631}
632
633subsys_initcall(acpi_init);