blob: 296bec89f4a1fb1cc1e213a30ccbdaf8c239ba49 [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>
Mark Brown49a12872014-01-27 00:32:14 +000036#include <linux/regulator/machine.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#ifdef CONFIG_X86
38#include <asm/mpspec.h>
39#endif
Robert Hancock7752d5c2008-02-15 01:27:20 -080040#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <acpi/acpi_bus.h>
42#include <acpi/acpi_drivers.h>
Huang Yingeccddd32011-07-13 13:14:20 +080043#include <acpi/apei.h>
Len Browneb27cae2009-07-06 23:40:19 -040044#include <linux/dmi.h>
Rafael J. Wysockicd51e61c2011-02-11 00:04:52 +010045#include <linux/suspend.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060047#include "internal.h"
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_BUS_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050050ACPI_MODULE_NAME("bus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Len Brown4be44fc2005-08-05 00:44:28 -040052struct acpi_device *acpi_root;
53struct proc_dir_entry *acpi_root_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054EXPORT_SYMBOL(acpi_root_dir);
55
56#define STRUCT_TO_INT(s) (*((int*)&s))
57
Zhao Yakui6415e122008-08-11 14:59:59 +080058
Lin Mingcce4f632010-05-12 09:26:48 +080059#ifdef CONFIG_X86
Lin Mingaa2110c2010-04-08 14:34:27 +080060static int set_copy_dsdt(const struct dmi_system_id *id)
61{
62 printk(KERN_NOTICE "%s detected - "
63 "force copy of DSDT to local memory\n", id->ident);
64 acpi_gbl_copy_dsdt_locally = 1;
65 return 0;
66}
67
68static struct dmi_system_id dsdt_dmi_table[] __initdata = {
69 /*
Len Brown100cf872010-09-28 22:57:02 -040070 * Invoke DSDT corruption work-around on all Toshiba Satellite.
Lin Mingaa2110c2010-04-08 14:34:27 +080071 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
72 */
73 {
74 .callback = set_copy_dsdt,
Len Brown100cf872010-09-28 22:57:02 -040075 .ident = "TOSHIBA Satellite",
Lin Mingaa2110c2010-04-08 14:34:27 +080076 .matches = {
77 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
Len Brown100cf872010-09-28 22:57:02 -040078 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
Lin Mingaa2110c2010-04-08 14:34:27 +080079 },
Lin Mingcce4f632010-05-12 09:26:48 +080080 },
81 {}
Lin Mingaa2110c2010-04-08 14:34:27 +080082};
Lin Mingcce4f632010-05-12 09:26:48 +080083#else
84static struct dmi_system_id dsdt_dmi_table[] __initdata = {
85 {}
86};
87#endif
Lin Mingaa2110c2010-04-08 14:34:27 +080088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/* --------------------------------------------------------------------------
90 Device Management
91 -------------------------------------------------------------------------- */
92
Bjorn Helgaas402ac532009-09-21 19:30:01 +000093acpi_status acpi_bus_get_status_handle(acpi_handle handle,
94 unsigned long long *sta)
95{
96 acpi_status status;
97
98 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
99 if (ACPI_SUCCESS(status))
100 return AE_OK;
101
102 if (status == AE_NOT_FOUND) {
103 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
104 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
105 return AE_OK;
106 }
107 return status;
108}
109
Len Brown4be44fc2005-08-05 00:44:28 -0400110int acpi_bus_get_status(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000112 acpi_status status;
113 unsigned long long sta;
Len Brown4be44fc2005-08-05 00:44:28 -0400114
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000115 status = acpi_bus_get_status_handle(device->handle, &sta);
116 if (ACPI_FAILURE(status))
117 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Bjorn Helgaas402ac532009-09-21 19:30:01 +0000119 STRUCT_TO_INT(device->status) = (int) sta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 if (device->status.functional && !device->status.present) {
Zhao Yakui39a0ad82008-08-11 13:40:22 +0800122 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
123 "functional but not present;\n",
124 device->pnp.bus_id,
125 (u32) STRUCT_TO_INT(device->status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
129 device->pnp.bus_id,
130 (u32) STRUCT_TO_INT(device->status)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400131 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
Len Brown4be44fc2005-08-05 00:44:28 -0400133EXPORT_SYMBOL(acpi_bus_get_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Zhang Rui20733932008-01-17 15:51:21 +0800135void acpi_bus_private_data_handler(acpi_handle handle,
Bob Moore8e4319c2009-06-29 13:43:27 +0800136 void *context)
Zhang Rui20733932008-01-17 15:51:21 +0800137{
138 return;
139}
140EXPORT_SYMBOL(acpi_bus_private_data_handler);
141
142int acpi_bus_get_private_data(acpi_handle handle, void **data)
143{
Bjorn Helgaas6a8c0af2013-06-03 18:20:24 +0000144 acpi_status status;
Zhang Rui20733932008-01-17 15:51:21 +0800145
146 if (!*data)
147 return -EINVAL;
148
149 status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
150 if (ACPI_FAILURE(status) || !*data) {
151 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
152 handle));
153 return -ENODEV;
154 }
155
156 return 0;
157}
158EXPORT_SYMBOL(acpi_bus_get_private_data);
159
Rafael J. Wysockif244d8b2013-12-31 13:39:42 +0100160void acpi_bus_no_hotplug(acpi_handle handle)
161{
162 struct acpi_device *adev = NULL;
163
164 acpi_bus_get_device(handle, &adev);
165 if (adev)
166 adev->flags.no_hotplug = true;
167}
168EXPORT_SYMBOL_GPL(acpi_bus_no_hotplug);
169
Shaohua Li70023de2009-10-29 11:04:28 +0800170static void acpi_print_osc_error(acpi_handle handle,
171 struct acpi_osc_context *context, char *error)
172{
173 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
174 int i;
175
176 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
177 printk(KERN_DEBUG "%s\n", error);
178 else {
179 printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
180 kfree(buffer.pointer);
181 }
182 printk(KERN_DEBUG"_OSC request data:");
183 for (i = 0; i < context->cap.length; i += sizeof(u32))
184 printk("%x ", *((u32 *)(context->cap.pointer + i)));
185 printk("\n");
186}
187
Chen, Gong4b3db702013-10-21 14:29:25 -0700188acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
Shaohua Li70023de2009-10-29 11:04:28 +0800189{
190 int i;
191 static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
192 24, 26, 28, 30, 32, 34};
193
194 if (strlen(str) != 36)
195 return AE_BAD_PARAMETER;
196 for (i = 0; i < 36; i++) {
197 if (i == 8 || i == 13 || i == 18 || i == 23) {
198 if (str[i] != '-')
199 return AE_BAD_PARAMETER;
200 } else if (!isxdigit(str[i]))
201 return AE_BAD_PARAMETER;
202 }
203 for (i = 0; i < 16; i++) {
Andy Shevchenko965fd9e2010-05-24 14:33:28 -0700204 uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
205 uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
Shaohua Li70023de2009-10-29 11:04:28 +0800206 }
207 return AE_OK;
208}
Chen, Gong4b3db702013-10-21 14:29:25 -0700209EXPORT_SYMBOL_GPL(acpi_str_to_uuid);
Shaohua Li70023de2009-10-29 11:04:28 +0800210
211acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
212{
213 acpi_status status;
214 struct acpi_object_list input;
215 union acpi_object in_params[4];
216 union acpi_object *out_obj;
217 u8 uuid[16];
218 u32 errors;
Shaohua Li9dc130f2009-12-23 17:04:11 +0800219 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
Shaohua Li70023de2009-10-29 11:04:28 +0800220
221 if (!context)
222 return AE_ERROR;
223 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
224 return AE_ERROR;
225 context->ret.length = ACPI_ALLOCATE_BUFFER;
226 context->ret.pointer = NULL;
227
228 /* Setting up input parameters */
229 input.count = 4;
230 input.pointer = in_params;
231 in_params[0].type = ACPI_TYPE_BUFFER;
232 in_params[0].buffer.length = 16;
233 in_params[0].buffer.pointer = uuid;
234 in_params[1].type = ACPI_TYPE_INTEGER;
235 in_params[1].integer.value = context->rev;
236 in_params[2].type = ACPI_TYPE_INTEGER;
237 in_params[2].integer.value = context->cap.length/sizeof(u32);
238 in_params[3].type = ACPI_TYPE_BUFFER;
239 in_params[3].buffer.length = context->cap.length;
240 in_params[3].buffer.pointer = context->cap.pointer;
241
Shaohua Li9dc130f2009-12-23 17:04:11 +0800242 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
Shaohua Li70023de2009-10-29 11:04:28 +0800243 if (ACPI_FAILURE(status))
244 return status;
245
Shaohua Li9dc130f2009-12-23 17:04:11 +0800246 if (!output.length)
Shaohua Li70023de2009-10-29 11:04:28 +0800247 return AE_NULL_OBJECT;
248
Shaohua Li9dc130f2009-12-23 17:04:11 +0800249 out_obj = output.pointer;
250 if (out_obj->type != ACPI_TYPE_BUFFER
251 || out_obj->buffer.length != context->cap.length) {
Shaohua Li70023de2009-10-29 11:04:28 +0800252 acpi_print_osc_error(handle, context,
253 "_OSC evaluation returned wrong type");
254 status = AE_TYPE;
255 goto out_kfree;
256 }
257 /* Need to ignore the bit0 in result code */
258 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
259 if (errors) {
260 if (errors & OSC_REQUEST_ERROR)
261 acpi_print_osc_error(handle, context,
262 "_OSC request failed");
263 if (errors & OSC_INVALID_UUID_ERROR)
264 acpi_print_osc_error(handle, context,
265 "_OSC invalid UUID");
266 if (errors & OSC_INVALID_REVISION_ERROR)
267 acpi_print_osc_error(handle, context,
268 "_OSC invalid revision");
269 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600270 if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD]
Shaohua Li70023de2009-10-29 11:04:28 +0800271 & OSC_QUERY_ENABLE)
272 goto out_success;
273 status = AE_SUPPORT;
274 goto out_kfree;
275 }
276 status = AE_ERROR;
277 goto out_kfree;
278 }
279out_success:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800280 context->ret.length = out_obj->buffer.length;
Andrei Epuree2cb5f02013-03-11 08:20:16 +0000281 context->ret.pointer = kmemdup(out_obj->buffer.pointer,
282 context->ret.length, GFP_KERNEL);
Shaohua Li9dc130f2009-12-23 17:04:11 +0800283 if (!context->ret.pointer) {
284 status = AE_NO_MEMORY;
285 goto out_kfree;
286 }
Shaohua Li9dc130f2009-12-23 17:04:11 +0800287 status = AE_OK;
Shaohua Li70023de2009-10-29 11:04:28 +0800288
289out_kfree:
Shaohua Li9dc130f2009-12-23 17:04:11 +0800290 kfree(output.pointer);
291 if (status != AE_OK)
292 context->ret.pointer = NULL;
Shaohua Li70023de2009-10-29 11:04:28 +0800293 return status;
294}
295EXPORT_SYMBOL(acpi_run_osc);
296
Huang Yingeccddd32011-07-13 13:14:20 +0800297bool osc_sb_apei_support_acked;
Shaohua Li3563ff92009-10-29 11:05:05 +0800298static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
299static void acpi_bus_osc_support(void)
300{
301 u32 capbuf[2];
302 struct acpi_osc_context context = {
303 .uuid_str = sb_uuid_str,
304 .rev = 1,
305 .cap.length = 8,
306 .cap.pointer = capbuf,
307 };
308 acpi_handle handle;
309
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600310 capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
311 capbuf[OSC_SUPPORT_DWORD] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800312#if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
313 defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600314 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PAD_SUPPORT;
Shaohua Li3563ff92009-10-29 11:05:05 +0800315#endif
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800316
317#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600318 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
Zhao Yakui6a4e2b72010-01-08 21:29:58 +0800319#endif
Huang Yingeccddd32011-07-13 13:14:20 +0800320
Toshi Kanic2f41912012-05-23 20:25:24 -0600321#ifdef ACPI_HOTPLUG_OST
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600322 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
Toshi Kanic2f41912012-05-23 20:25:24 -0600323#endif
324
Huang Yingeccddd32011-07-13 13:14:20 +0800325 if (!ghes_disable)
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600326 capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
Shaohua Li3563ff92009-10-29 11:05:05 +0800327 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
328 return;
Huang Yingeccddd32011-07-13 13:14:20 +0800329 if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
330 u32 *capbuf_ret = context.ret.pointer;
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600331 if (context.ret.length > OSC_SUPPORT_DWORD)
Huang Yingeccddd32011-07-13 13:14:20 +0800332 osc_sb_apei_support_acked =
Bjorn Helgaasb938a222013-09-05 15:05:54 -0600333 capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
Shaohua Li3563ff92009-10-29 11:05:05 +0800334 kfree(context.ret.pointer);
Huang Yingeccddd32011-07-13 13:14:20 +0800335 }
336 /* do we need to check other returned cap? Sounds no */
Shaohua Li3563ff92009-10-29 11:05:05 +0800337}
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/* --------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 Notification Handling
341 -------------------------------------------------------------------------- */
342
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600343static void acpi_bus_check_device(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600345 struct acpi_device *device;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600346 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 struct acpi_device_status old_status;
348
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600349 if (acpi_bus_get_device(handle, &device))
350 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if (!device)
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600352 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 old_status = device->status;
355
356 /*
357 * Make sure this device's parent is present before we go about
358 * messing with the device.
359 */
360 if (device->parent && !device->parent->status.present) {
361 device->status = device->parent->status;
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600362 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364
365 status = acpi_bus_get_status(device);
366 if (ACPI_FAILURE(status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600367 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
Bjorn Helgaascdd5b8c2009-05-22 11:43:51 -0600370 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 /*
373 * Device Insertion/Removal
374 */
375 if ((device->status.present) && !(old_status.present)) {
376 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
377 /* TBD: Handle device insertion */
Len Brown4be44fc2005-08-05 00:44:28 -0400378 } else if (!(device->status.present) && (old_status.present)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
380 /* TBD: Handle device removal */
381 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600384static void acpi_bus_check_scope(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 /* Status Change? */
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600387 acpi_bus_check_device(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 /*
390 * TBD: Enumerate child devices within this device's scope and
391 * run acpi_bus_check_device()'s on them.
392 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395/**
396 * acpi_bus_notify
397 * ---------------
398 * Callback for all 'system-level' device notifications (values 0x00-0x7F).
399 */
Len Brown4be44fc2005-08-05 00:44:28 -0400400static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Len Brown4be44fc2005-08-05 00:44:28 -0400402 struct acpi_device *device = NULL;
Bjorn Helgaas6d278132009-04-30 09:35:37 -0600403 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Bjorn Helgaas02c37bd2009-05-22 11:43:41 -0600405 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
406 type, handle));
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 switch (type) {
409
410 case ACPI_NOTIFY_BUS_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600411 acpi_bus_check_scope(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500412 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400414 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 */
416 break;
417
418 case ACPI_NOTIFY_DEVICE_CHECK:
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600419 acpi_bus_check_device(handle);
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500420 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 * TBD: We'll need to outsource certain events to non-ACPI
Len Brown4be44fc2005-08-05 00:44:28 -0400422 * drivers via the device manager (device.c).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 */
424 break;
425
426 case ACPI_NOTIFY_DEVICE_WAKE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 /* TBD */
428 break;
429
430 case ACPI_NOTIFY_EJECT_REQUEST:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 /* TBD */
432 break;
433
434 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 /* TBD: Exactly what does 'light' mean? */
436 break;
437
438 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 /* TBD */
440 break;
441
442 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 /* TBD */
444 break;
445
446 case ACPI_NOTIFY_POWER_FAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 /* TBD */
448 break;
449
450 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400451 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
452 "Received unknown/unsupported notification [%08x]\n",
453 type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 break;
455 }
456
Bjorn Helgaasff754e22009-05-22 11:43:56 -0600457 acpi_bus_get_device(handle, &device);
458 if (device) {
459 driver = device->driver;
460 if (driver && driver->ops.notify &&
461 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
462 driver->ops.notify(device, type);
463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
466/* --------------------------------------------------------------------------
467 Initialization/Cleanup
468 -------------------------------------------------------------------------- */
469
Len Brown4be44fc2005-08-05 00:44:28 -0400470static int __init acpi_bus_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Bjorn Helgaas6a8c0af2013-06-03 18:20:24 +0000472 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400473 char *message = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500476 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 * Let the system know what interrupt model we are using by
478 * evaluating the \_PIC object, if exists.
479 */
480
481 switch (acpi_irq_model) {
482 case ACPI_IRQ_MODEL_PIC:
483 message = "PIC";
484 break;
485 case ACPI_IRQ_MODEL_IOAPIC:
486 message = "IOAPIC";
487 break;
488 case ACPI_IRQ_MODEL_IOSAPIC:
489 message = "IOSAPIC";
490 break;
John Keller3948ec92006-12-22 11:50:04 -0600491 case ACPI_IRQ_MODEL_PLATFORM:
492 message = "platform specific model";
493 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 default:
495 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400496 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498
499 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
500
Jiang Liu0db98202013-06-29 00:24:39 +0800501 status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400503 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400504 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506
Patrick Mocheld550d982006-06-27 00:41:40 -0400507 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508}
509
Bob Moore67a119f2008-06-10 13:42:13 +0800510u8 acpi_gbl_permanent_mmap;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300511
512
Len Brown4be44fc2005-08-05 00:44:28 -0400513void __init acpi_early_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
Bjorn Helgaas6a8c0af2013-06-03 18:20:24 +0000515 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400518 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Bob Moore616861242006-03-17 16:44:00 -0500520 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 /* enable workarounds, unless strict ACPI spec. compliance */
523 if (!acpi_strict)
524 acpi_gbl_enable_interpreter_slack = TRUE;
525
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300526 acpi_gbl_permanent_mmap = 1;
527
Lin Mingaa2110c2010-04-08 14:34:27 +0800528 /*
529 * If the machine falls into the DMI check table,
530 * DSDT will be copied to memory
531 */
532 dmi_check_system(dsdt_dmi_table);
533
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300534 status = acpi_reallocate_root_table();
535 if (ACPI_FAILURE(status)) {
536 printk(KERN_ERR PREFIX
537 "Unable to reallocate ACPI tables\n");
538 goto error0;
539 }
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 status = acpi_initialize_subsystem();
542 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400543 printk(KERN_ERR PREFIX
544 "Unable to initialize the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 goto error0;
546 }
547
548 status = acpi_load_tables();
549 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400550 printk(KERN_ERR PREFIX
551 "Unable to load the System Description Tables\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 goto error0;
553 }
554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#ifdef CONFIG_X86
556 if (!acpi_ioapic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 /* compatible (0) means level (3) */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300558 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
559 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
560 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 /* Set PIC-mode SCI trigger type */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300563 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300564 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 /*
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300567 * now that acpi_gbl_FADT is initialized,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 * update it with result from INT_SRC_OVR parsing
569 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300570 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
572#endif
573
Rafael J. Wysocki4505a202011-11-06 14:20:42 +0100574 status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (ACPI_FAILURE(status)) {
576 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
577 goto error0;
578 }
579
Mark Brown49a12872014-01-27 00:32:14 +0000580 /*
581 * If the system is using ACPI then we can be reasonably
582 * confident that any regulators are managed by the firmware
583 * so tell the regulator core it has everything it needs to
584 * know.
585 */
586 regulator_has_full_constraints();
587
Patrick Mocheld550d982006-06-27 00:41:40 -0400588 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 error0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 disable_acpi();
Patrick Mocheld550d982006-06-27 00:41:40 -0400592 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
594
Len Brown4be44fc2005-08-05 00:44:28 -0400595static int __init acpi_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Bjorn Helgaas6a8c0af2013-06-03 18:20:24 +0000597 int result;
598 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Jiri Slaby176f9c12009-03-04 11:55:27 -0800600 acpi_os_initialize1();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Rafael J. Wysocki4505a202011-11-06 14:20:42 +0100602 status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400604 printk(KERN_ERR PREFIX
605 "Unable to start the ACPI Interpreter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 goto error1;
607 }
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 /*
610 * ACPI 2.0 requires the EC driver to be loaded and work before
611 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
612 * is called).
613 *
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500614 * This is accomplished by looking for the ECDT table, and getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 * the EC parameters out of that.
616 */
617 status = acpi_ec_ecdt_probe();
618 /* Ignore result. Not having an ECDT is not fatal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
621 if (ACPI_FAILURE(status)) {
622 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
623 goto error1;
624 }
625
Zhang Ruib1d248d2010-10-26 10:06:54 +0800626 /*
Lin Mingfc54ab72012-07-16 16:30:21 +0800627 * _OSC method may exist in module level code,
628 * so it must be run after ACPI_FULL_INITIALIZATION
629 */
630 acpi_bus_osc_support();
631
632 /*
Zhang Ruib1d248d2010-10-26 10:06:54 +0800633 * _PDC control method may load dynamic SSDT tables,
634 * and we need to install the table handler before that.
635 */
636 acpi_sysfs_init();
637
Alex Chiang78f16992009-12-20 12:19:09 -0700638 acpi_early_processor_set_pdc();
639
Zhao Yakui455c8792008-10-06 10:31:36 +0800640 /*
641 * Maybe EC region is required at bus_scan/acpi_get_devices. So it
642 * is necessary to enable it as early as possible.
643 */
644 acpi_boot_ec_enable();
645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 printk(KERN_INFO PREFIX "Interpreter enabled\n");
647
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500648 /* Initialize sleep structures */
649 acpi_sleep_init();
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /*
652 * Get the system interrupt model and evaluate \_PIC.
653 */
654 result = acpi_bus_init_irq();
655 if (result)
656 goto error1;
657
658 /*
659 * Register the for all standard device notifications.
660 */
Len Brown4be44fc2005-08-05 00:44:28 -0400661 status =
662 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
663 &acpi_bus_notify, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400665 printk(KERN_ERR PREFIX
666 "Unable to register for device notifications\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 goto error1;
668 }
669
670 /*
671 * Create the top ACPI proc directory
672 */
673 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
674
Patrick Mocheld550d982006-06-27 00:41:40 -0400675 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 /* Mimic structured exception handling */
Len Brown4be44fc2005-08-05 00:44:28 -0400678 error1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 acpi_terminate();
Patrick Mocheld550d982006-06-27 00:41:40 -0400680 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700683struct kobject *acpi_kobj;
Matthew Garrettf2d47532012-01-31 13:19:19 -0500684EXPORT_SYMBOL_GPL(acpi_kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Len Brown4be44fc2005-08-05 00:44:28 -0400686static int __init acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100688 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 if (acpi_disabled) {
691 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400692 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 }
694
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -0800695 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700696 if (!acpi_kobj) {
Harvey Harrison96b2dd12008-03-05 18:24:51 -0800697 printk(KERN_WARNING "%s: kset create error\n", __func__);
Greg Kroah-Hartman99e0d2f2007-11-02 16:19:59 -0700698 acpi_kobj = NULL;
699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Bjorn Helgaas0e465172009-03-24 16:50:09 -0600701 init_acpi_device_notify();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 result = acpi_bus_init();
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100703 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 disable_acpi();
Bjorn Helgaas81d02732009-03-24 16:49:38 -0600705 return result;
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100706 }
Bjorn Helgaas81d02732009-03-24 16:49:38 -0600707
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100708 pci_mmcfg_late_init();
Bjorn Helgaase747f272009-03-24 16:49:43 -0600709 acpi_scan_init();
Bjorn Helgaasa5f820f2009-03-24 16:49:48 -0600710 acpi_ec_init();
Zhang Ruia25ee922010-07-15 10:46:15 +0800711 acpi_debugfs_init();
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -0600712 acpi_sleep_proc_init();
Bjorn Helgaas201b8c62009-03-24 16:50:19 -0600713 acpi_wakeup_device_init();
Rafael J. Wysocki6831c6e2011-02-15 21:22:24 +0100714 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715}
716
717subsys_initcall(acpi_init);