]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $) | |
3 | * | |
4 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | |
5 | * | |
6 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or (at | |
11 | * your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
1da177e4 LT |
18 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
19 | */ | |
20 | ||
21 | #include <linux/module.h> | |
22 | #include <linux/init.h> | |
23 | #include <linux/ioport.h> | |
d568df84 | 24 | #include <linux/kernel.h> |
1da177e4 LT |
25 | #include <linux/list.h> |
26 | #include <linux/sched.h> | |
27 | #include <linux/pm.h> | |
28 | #include <linux/device.h> | |
29 | #include <linux/proc_fs.h> | |
6697c052 | 30 | #include <linux/acpi.h> |
5a0e3ad6 | 31 | #include <linux/slab.h> |
49a12877 | 32 | #include <linux/regulator/machine.h> |
baa0c019 PP |
33 | #include <linux/workqueue.h> |
34 | #include <linux/reboot.h> | |
35 | #include <linux/delay.h> | |
1da177e4 LT |
36 | #ifdef CONFIG_X86 |
37 | #include <asm/mpspec.h> | |
38 | #endif | |
88ef16d8 | 39 | #include <linux/acpi_iort.h> |
7752d5cf | 40 | #include <linux/pci.h> |
eccddd32 | 41 | #include <acpi/apei.h> |
eb27cae8 | 42 | #include <linux/dmi.h> |
cd51e61c | 43 | #include <linux/suspend.h> |
1da177e4 | 44 | |
e60cc7a6 BH |
45 | #include "internal.h" |
46 | ||
1da177e4 | 47 | #define _COMPONENT ACPI_BUS_COMPONENT |
f52fd66d | 48 | ACPI_MODULE_NAME("bus"); |
1da177e4 | 49 | |
4be44fcd LB |
50 | struct acpi_device *acpi_root; |
51 | struct proc_dir_entry *acpi_root_dir; | |
1da177e4 LT |
52 | EXPORT_SYMBOL(acpi_root_dir); |
53 | ||
cce4f632 | 54 | #ifdef CONFIG_X86 |
73577d1d LZ |
55 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
56 | static inline int set_copy_dsdt(const struct dmi_system_id *id) | |
57 | { | |
58 | return 0; | |
59 | } | |
60 | #else | |
aa2110cb LM |
61 | static int set_copy_dsdt(const struct dmi_system_id *id) |
62 | { | |
63 | printk(KERN_NOTICE "%s detected - " | |
64 | "force copy of DSDT to local memory\n", id->ident); | |
65 | acpi_gbl_copy_dsdt_locally = 1; | |
66 | return 0; | |
67 | } | |
73577d1d | 68 | #endif |
84d7b8fd KHF |
69 | static int set_gbl_term_list(const struct dmi_system_id *id) |
70 | { | |
71 | acpi_gbl_parse_table_as_term_list = 1; | |
72 | return 0; | |
73 | } | |
aa2110cb | 74 | |
84d7b8fd KHF |
75 | static const struct dmi_system_id acpi_quirks_dmi_table[] __initconst = { |
76 | /* | |
77 | * Touchpad on Dell XPS 9570/Precision M5530 doesn't work under I2C | |
78 | * mode. | |
79 | * https://bugzilla.kernel.org/show_bug.cgi?id=198515 | |
80 | */ | |
81 | { | |
82 | .callback = set_gbl_term_list, | |
83 | .ident = "Dell Precision M5530", | |
84 | .matches = { | |
85 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
86 | DMI_MATCH(DMI_PRODUCT_NAME, "Precision M5530"), | |
87 | }, | |
88 | }, | |
89 | { | |
90 | .callback = set_gbl_term_list, | |
91 | .ident = "Dell XPS 15 9570", | |
92 | .matches = { | |
93 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
94 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9570"), | |
95 | }, | |
96 | }, | |
aa2110cb | 97 | /* |
100cf877 | 98 | * Invoke DSDT corruption work-around on all Toshiba Satellite. |
84d7b8fd | 99 | * DSDT will be copied to memory. |
aa2110cb LM |
100 | * https://bugzilla.kernel.org/show_bug.cgi?id=14679 |
101 | */ | |
102 | { | |
103 | .callback = set_copy_dsdt, | |
100cf877 | 104 | .ident = "TOSHIBA Satellite", |
aa2110cb LM |
105 | .matches = { |
106 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), | |
100cf877 | 107 | DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"), |
aa2110cb | 108 | }, |
cce4f632 LM |
109 | }, |
110 | {} | |
aa2110cb | 111 | }; |
abd273f5 AM |
112 | |
113 | static const char * const acpi_quirk_lenovo_bios_ids[] = { | |
114 | "N2H", /* first 3 bytes of Lenovo BIOS version */ | |
115 | NULL | |
116 | }; | |
117 | ||
118 | bool acpi_quirk_matches_bios_ids(const char * const ids[]) | |
119 | { | |
120 | const char *bios_vendor = dmi_get_system_info(DMI_BIOS_VENDOR); | |
121 | const char *bios_ver = dmi_get_system_info(DMI_BIOS_VERSION); | |
122 | int i; | |
123 | ||
daad7030 KHF |
124 | if (!bios_vendor || !bios_ver) |
125 | return false; | |
126 | ||
127 | if (strncmp(bios_vendor, "LENOVO", 6)) | |
abd273f5 AM |
128 | return false; |
129 | ||
130 | for (i = 0; ids[i]; i++) | |
131 | if (!strncmp(bios_ver, ids[i], 3)) { | |
132 | acpi_gbl_parse_table_as_term_list = 1; | |
133 | return true; | |
134 | } | |
135 | ||
136 | return false; | |
137 | } | |
138 | ||
cce4f632 | 139 | #else |
84d7b8fd | 140 | static const struct dmi_system_id acpi_quirks_dmi_table[] __initconst = { |
cce4f632 LM |
141 | {} |
142 | }; | |
abd273f5 AM |
143 | |
144 | static const char * const acpi_quirk_lenovo_bios_ids[] = { | |
145 | NULL | |
146 | }; | |
147 | ||
148 | bool acpi_quirk_matches_bios_ids(const char * const ids[]) | |
149 | { | |
150 | return false; | |
151 | } | |
cce4f632 | 152 | #endif |
aa2110cb | 153 | |
1da177e4 LT |
154 | /* -------------------------------------------------------------------------- |
155 | Device Management | |
156 | -------------------------------------------------------------------------- */ | |
157 | ||
402ac536 BH |
158 | acpi_status acpi_bus_get_status_handle(acpi_handle handle, |
159 | unsigned long long *sta) | |
1da177e4 | 160 | { |
402ac536 | 161 | acpi_status status; |
4be44fcd | 162 | |
402ac536 BH |
163 | status = acpi_evaluate_integer(handle, "_STA", NULL, sta); |
164 | if (ACPI_SUCCESS(status)) | |
165 | return AE_OK; | |
1da177e4 | 166 | |
402ac536 BH |
167 | if (status == AE_NOT_FOUND) { |
168 | *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | | |
169 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; | |
170 | return AE_OK; | |
1da177e4 | 171 | } |
402ac536 BH |
172 | return status; |
173 | } | |
1da177e4 | 174 | |
402ac536 BH |
175 | int acpi_bus_get_status(struct acpi_device *device) |
176 | { | |
177 | acpi_status status; | |
178 | unsigned long long sta; | |
179 | ||
b7ecf663 HG |
180 | if (acpi_device_always_present(device)) { |
181 | acpi_set_device_status(device, ACPI_STA_DEFAULT); | |
182 | return 0; | |
183 | } | |
184 | ||
d32b102f HG |
185 | /* Battery devices must have their deps met before calling _STA */ |
186 | if (acpi_device_is_battery(device) && device->dep_unmet) { | |
187 | acpi_set_device_status(device, 0); | |
188 | return 0; | |
189 | } | |
190 | ||
402ac536 BH |
191 | status = acpi_bus_get_status_handle(device->handle, &sta); |
192 | if (ACPI_FAILURE(status)) | |
193 | return -ENODEV; | |
194 | ||
25db115b | 195 | acpi_set_device_status(device, sta); |
1da177e4 LT |
196 | |
197 | if (device->status.functional && !device->status.present) { | |
39a0ad87 ZY |
198 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: " |
199 | "functional but not present;\n", | |
25db115b | 200 | device->pnp.bus_id, (u32)sta)); |
1da177e4 LT |
201 | } |
202 | ||
4be44fcd | 203 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n", |
25db115b | 204 | device->pnp.bus_id, (u32)sta)); |
d550d98d | 205 | return 0; |
1da177e4 | 206 | } |
4be44fcd | 207 | EXPORT_SYMBOL(acpi_bus_get_status); |
1da177e4 | 208 | |
20733939 | 209 | void acpi_bus_private_data_handler(acpi_handle handle, |
8e4319c4 | 210 | void *context) |
20733939 ZR |
211 | { |
212 | return; | |
213 | } | |
214 | EXPORT_SYMBOL(acpi_bus_private_data_handler); | |
215 | ||
72013795 LT |
216 | int acpi_bus_attach_private_data(acpi_handle handle, void *data) |
217 | { | |
218 | acpi_status status; | |
219 | ||
220 | status = acpi_attach_data(handle, | |
221 | acpi_bus_private_data_handler, data); | |
222 | if (ACPI_FAILURE(status)) { | |
223 | acpi_handle_debug(handle, "Error attaching device data\n"); | |
224 | return -ENODEV; | |
225 | } | |
226 | ||
227 | return 0; | |
228 | } | |
229 | EXPORT_SYMBOL_GPL(acpi_bus_attach_private_data); | |
230 | ||
20733939 ZR |
231 | int acpi_bus_get_private_data(acpi_handle handle, void **data) |
232 | { | |
6a8c0af6 | 233 | acpi_status status; |
20733939 | 234 | |
edb2d764 | 235 | if (!data) |
20733939 ZR |
236 | return -EINVAL; |
237 | ||
238 | status = acpi_get_data(handle, acpi_bus_private_data_handler, data); | |
72013795 LT |
239 | if (ACPI_FAILURE(status)) { |
240 | acpi_handle_debug(handle, "No context for object\n"); | |
20733939 ZR |
241 | return -ENODEV; |
242 | } | |
243 | ||
244 | return 0; | |
245 | } | |
72013795 LT |
246 | EXPORT_SYMBOL_GPL(acpi_bus_get_private_data); |
247 | ||
248 | void acpi_bus_detach_private_data(acpi_handle handle) | |
249 | { | |
250 | acpi_detach_data(handle, acpi_bus_private_data_handler); | |
251 | } | |
252 | EXPORT_SYMBOL_GPL(acpi_bus_detach_private_data); | |
20733939 | 253 | |
70023de8 | 254 | static void acpi_print_osc_error(acpi_handle handle, |
f26f5c8b | 255 | struct acpi_osc_context *context, char *error) |
70023de8 | 256 | { |
70023de8 SL |
257 | int i; |
258 | ||
f26f5c8b RW |
259 | acpi_handle_debug(handle, "(%s): %s\n", context->uuid_str, error); |
260 | ||
261 | pr_debug("_OSC request data:"); | |
70023de8 | 262 | for (i = 0; i < context->cap.length; i += sizeof(u32)) |
f26f5c8b RW |
263 | pr_debug(" %x", *((u32 *)(context->cap.pointer + i))); |
264 | ||
265 | pr_debug("\n"); | |
70023de8 SL |
266 | } |
267 | ||
70023de8 SL |
268 | acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context) |
269 | { | |
270 | acpi_status status; | |
271 | struct acpi_object_list input; | |
272 | union acpi_object in_params[4]; | |
273 | union acpi_object *out_obj; | |
dfcaad8f | 274 | guid_t guid; |
70023de8 | 275 | u32 errors; |
9dc130fc | 276 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; |
70023de8 SL |
277 | |
278 | if (!context) | |
279 | return AE_ERROR; | |
dfcaad8f | 280 | if (guid_parse(context->uuid_str, &guid)) |
70023de8 SL |
281 | return AE_ERROR; |
282 | context->ret.length = ACPI_ALLOCATE_BUFFER; | |
283 | context->ret.pointer = NULL; | |
284 | ||
285 | /* Setting up input parameters */ | |
286 | input.count = 4; | |
287 | input.pointer = in_params; | |
288 | in_params[0].type = ACPI_TYPE_BUFFER; | |
289 | in_params[0].buffer.length = 16; | |
dfcaad8f | 290 | in_params[0].buffer.pointer = (u8 *)&guid; |
70023de8 SL |
291 | in_params[1].type = ACPI_TYPE_INTEGER; |
292 | in_params[1].integer.value = context->rev; | |
293 | in_params[2].type = ACPI_TYPE_INTEGER; | |
294 | in_params[2].integer.value = context->cap.length/sizeof(u32); | |
295 | in_params[3].type = ACPI_TYPE_BUFFER; | |
296 | in_params[3].buffer.length = context->cap.length; | |
297 | in_params[3].buffer.pointer = context->cap.pointer; | |
298 | ||
9dc130fc | 299 | status = acpi_evaluate_object(handle, "_OSC", &input, &output); |
70023de8 SL |
300 | if (ACPI_FAILURE(status)) |
301 | return status; | |
302 | ||
9dc130fc | 303 | if (!output.length) |
70023de8 SL |
304 | return AE_NULL_OBJECT; |
305 | ||
9dc130fc SL |
306 | out_obj = output.pointer; |
307 | if (out_obj->type != ACPI_TYPE_BUFFER | |
308 | || out_obj->buffer.length != context->cap.length) { | |
70023de8 SL |
309 | acpi_print_osc_error(handle, context, |
310 | "_OSC evaluation returned wrong type"); | |
311 | status = AE_TYPE; | |
312 | goto out_kfree; | |
313 | } | |
314 | /* Need to ignore the bit0 in result code */ | |
315 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); | |
316 | if (errors) { | |
317 | if (errors & OSC_REQUEST_ERROR) | |
318 | acpi_print_osc_error(handle, context, | |
319 | "_OSC request failed"); | |
320 | if (errors & OSC_INVALID_UUID_ERROR) | |
321 | acpi_print_osc_error(handle, context, | |
322 | "_OSC invalid UUID"); | |
323 | if (errors & OSC_INVALID_REVISION_ERROR) | |
324 | acpi_print_osc_error(handle, context, | |
325 | "_OSC invalid revision"); | |
326 | if (errors & OSC_CAPABILITIES_MASK_ERROR) { | |
b938a229 | 327 | if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD] |
70023de8 SL |
328 | & OSC_QUERY_ENABLE) |
329 | goto out_success; | |
330 | status = AE_SUPPORT; | |
331 | goto out_kfree; | |
332 | } | |
333 | status = AE_ERROR; | |
334 | goto out_kfree; | |
335 | } | |
336 | out_success: | |
9dc130fc | 337 | context->ret.length = out_obj->buffer.length; |
e2cb5f08 AE |
338 | context->ret.pointer = kmemdup(out_obj->buffer.pointer, |
339 | context->ret.length, GFP_KERNEL); | |
9dc130fc SL |
340 | if (!context->ret.pointer) { |
341 | status = AE_NO_MEMORY; | |
342 | goto out_kfree; | |
343 | } | |
9dc130fc | 344 | status = AE_OK; |
70023de8 SL |
345 | |
346 | out_kfree: | |
9dc130fc SL |
347 | kfree(output.pointer); |
348 | if (status != AE_OK) | |
349 | context->ret.pointer = NULL; | |
70023de8 SL |
350 | return status; |
351 | } | |
352 | EXPORT_SYMBOL(acpi_run_osc); | |
353 | ||
eccddd32 | 354 | bool osc_sb_apei_support_acked; |
a36a7fec SH |
355 | |
356 | /* | |
357 | * ACPI 6.0 Section 8.4.4.2 Idle State Coordination | |
358 | * OSPM supports platform coordinated low power idle(LPI) states | |
359 | */ | |
360 | bool osc_pc_lpi_support_confirmed; | |
361 | EXPORT_SYMBOL_GPL(osc_pc_lpi_support_confirmed); | |
362 | ||
3563ff96 SL |
363 | static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48"; |
364 | static void acpi_bus_osc_support(void) | |
365 | { | |
366 | u32 capbuf[2]; | |
367 | struct acpi_osc_context context = { | |
368 | .uuid_str = sb_uuid_str, | |
369 | .rev = 1, | |
370 | .cap.length = 8, | |
371 | .cap.pointer = capbuf, | |
372 | }; | |
373 | acpi_handle handle; | |
374 | ||
b938a229 BH |
375 | capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE; |
376 | capbuf[OSC_SUPPORT_DWORD] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */ | |
bcb2b0b2 SH |
377 | if (IS_ENABLED(CONFIG_ACPI_PROCESSOR_AGGREGATOR)) |
378 | capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PAD_SUPPORT; | |
379 | if (IS_ENABLED(CONFIG_ACPI_PROCESSOR)) | |
380 | capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT; | |
eccddd32 | 381 | |
b938a229 | 382 | capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT; |
a36a7fec | 383 | capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PCLPI_SUPPORT; |
c2f4191a | 384 | |
5c2832e9 SP |
385 | #ifdef CONFIG_X86 |
386 | if (boot_cpu_has(X86_FEATURE_HWP)) { | |
387 | capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_CPC_SUPPORT; | |
388 | capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_CPCV2_SUPPORT; | |
389 | } | |
390 | #endif | |
391 | ||
de966cf4 | 392 | if (IS_ENABLED(CONFIG_SCHED_MC_PRIO)) |
8b533a0e SP |
393 | capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_CPC_DIVERSE_HIGH_SUPPORT; |
394 | ||
eccddd32 | 395 | if (!ghes_disable) |
b938a229 | 396 | capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT; |
3563ff96 SL |
397 | if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle))) |
398 | return; | |
eccddd32 HY |
399 | if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) { |
400 | u32 *capbuf_ret = context.ret.pointer; | |
a36a7fec | 401 | if (context.ret.length > OSC_SUPPORT_DWORD) { |
eccddd32 | 402 | osc_sb_apei_support_acked = |
b938a229 | 403 | capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT; |
a36a7fec SH |
404 | osc_pc_lpi_support_confirmed = |
405 | capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_PCLPI_SUPPORT; | |
406 | } | |
3563ff96 | 407 | kfree(context.ret.pointer); |
eccddd32 HY |
408 | } |
409 | /* do we need to check other returned cap? Sounds no */ | |
3563ff96 SL |
410 | } |
411 | ||
1da177e4 LT |
412 | /* -------------------------------------------------------------------------- |
413 | Notification Handling | |
414 | -------------------------------------------------------------------------- */ | |
415 | ||
1da177e4 LT |
416 | /** |
417 | * acpi_bus_notify | |
418 | * --------------- | |
419 | * Callback for all 'system-level' device notifications (values 0x00-0x7F). | |
420 | */ | |
4be44fcd | 421 | static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) |
1da177e4 | 422 | { |
1a699476 | 423 | struct acpi_device *adev; |
6d278131 | 424 | struct acpi_driver *driver; |
1a699476 | 425 | u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; |
d0103387 | 426 | bool hotplug_event = false; |
02c37bd8 | 427 | |
1da177e4 | 428 | switch (type) { |
1da177e4 | 429 | case ACPI_NOTIFY_BUS_CHECK: |
1a699476 | 430 | acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); |
d0103387 | 431 | hotplug_event = true; |
1da177e4 LT |
432 | break; |
433 | ||
434 | case ACPI_NOTIFY_DEVICE_CHECK: | |
1a699476 | 435 | acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n"); |
d0103387 | 436 | hotplug_event = true; |
1da177e4 LT |
437 | break; |
438 | ||
439 | case ACPI_NOTIFY_DEVICE_WAKE: | |
1a699476 | 440 | acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_WAKE event\n"); |
1da177e4 LT |
441 | break; |
442 | ||
443 | case ACPI_NOTIFY_EJECT_REQUEST: | |
1a699476 | 444 | acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); |
d0103387 | 445 | hotplug_event = true; |
1da177e4 LT |
446 | break; |
447 | ||
448 | case ACPI_NOTIFY_DEVICE_CHECK_LIGHT: | |
1a699476 | 449 | acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK_LIGHT event\n"); |
1da177e4 LT |
450 | /* TBD: Exactly what does 'light' mean? */ |
451 | break; | |
452 | ||
453 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: | |
1a699476 RW |
454 | acpi_handle_err(handle, "Device cannot be configured due " |
455 | "to a frequency mismatch\n"); | |
1da177e4 LT |
456 | break; |
457 | ||
458 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: | |
1a699476 RW |
459 | acpi_handle_err(handle, "Device cannot be configured due " |
460 | "to a bus mode mismatch\n"); | |
1da177e4 LT |
461 | break; |
462 | ||
463 | case ACPI_NOTIFY_POWER_FAULT: | |
1a699476 | 464 | acpi_handle_err(handle, "Device has suffered a power fault\n"); |
1da177e4 LT |
465 | break; |
466 | ||
467 | default: | |
f66abe92 RW |
468 | acpi_handle_debug(handle, "Unknown event type 0x%x\n", type); |
469 | break; | |
1da177e4 LT |
470 | } |
471 | ||
1a699476 RW |
472 | adev = acpi_bus_get_acpi_device(handle); |
473 | if (!adev) | |
474 | goto err; | |
78ea4639 | 475 | |
1a699476 RW |
476 | driver = adev->driver; |
477 | if (driver && driver->ops.notify && | |
478 | (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS)) | |
479 | driver->ops.notify(adev, type); | |
480 | ||
9a4d8d60 LCY |
481 | if (!hotplug_event) { |
482 | acpi_bus_put_acpi_device(adev); | |
483 | return; | |
484 | } | |
485 | ||
486 | if (ACPI_SUCCESS(acpi_hotplug_schedule(adev, type))) | |
d0103387 RW |
487 | return; |
488 | ||
1a699476 | 489 | acpi_bus_put_acpi_device(adev); |
1a699476 RW |
490 | |
491 | err: | |
700b8422 | 492 | acpi_evaluate_ost(handle, type, ost_code, NULL); |
1da177e4 LT |
493 | } |
494 | ||
5894b0c4 RW |
495 | static void acpi_device_notify(acpi_handle handle, u32 event, void *data) |
496 | { | |
497 | struct acpi_device *device = data; | |
498 | ||
499 | device->driver->ops.notify(device, event); | |
500 | } | |
501 | ||
502 | static void acpi_device_notify_fixed(void *data) | |
503 | { | |
504 | struct acpi_device *device = data; | |
505 | ||
506 | /* Fixed hardware devices have no handles */ | |
507 | acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device); | |
508 | } | |
509 | ||
510 | static u32 acpi_device_fixed_event(void *data) | |
511 | { | |
512 | acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_device_notify_fixed, data); | |
513 | return ACPI_INTERRUPT_HANDLED; | |
514 | } | |
515 | ||
516 | static int acpi_device_install_notify_handler(struct acpi_device *device) | |
517 | { | |
518 | acpi_status status; | |
519 | ||
520 | if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) | |
521 | status = | |
522 | acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | |
523 | acpi_device_fixed_event, | |
524 | device); | |
525 | else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON) | |
526 | status = | |
527 | acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | |
528 | acpi_device_fixed_event, | |
529 | device); | |
530 | else | |
531 | status = acpi_install_notify_handler(device->handle, | |
532 | ACPI_DEVICE_NOTIFY, | |
533 | acpi_device_notify, | |
534 | device); | |
535 | ||
536 | if (ACPI_FAILURE(status)) | |
537 | return -EINVAL; | |
538 | return 0; | |
539 | } | |
540 | ||
541 | static void acpi_device_remove_notify_handler(struct acpi_device *device) | |
542 | { | |
543 | if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) | |
544 | acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | |
545 | acpi_device_fixed_event); | |
546 | else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON) | |
547 | acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | |
548 | acpi_device_fixed_event); | |
549 | else | |
550 | acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, | |
551 | acpi_device_notify); | |
552 | } | |
553 | ||
baa0c019 PP |
554 | /* Handle events targeting \_SB device (at present only graceful shutdown) */ |
555 | ||
556 | #define ACPI_SB_NOTIFY_SHUTDOWN_REQUEST 0x81 | |
557 | #define ACPI_SB_INDICATE_INTERVAL 10000 | |
558 | ||
559 | static void sb_notify_work(struct work_struct *dummy) | |
560 | { | |
561 | acpi_handle sb_handle; | |
562 | ||
563 | orderly_poweroff(true); | |
564 | ||
565 | /* | |
566 | * After initiating graceful shutdown, the ACPI spec requires OSPM | |
567 | * to evaluate _OST method once every 10seconds to indicate that | |
568 | * the shutdown is in progress | |
569 | */ | |
570 | acpi_get_handle(NULL, "\\_SB", &sb_handle); | |
571 | while (1) { | |
572 | pr_info("Graceful shutdown in progress.\n"); | |
573 | acpi_evaluate_ost(sb_handle, ACPI_OST_EC_OSPM_SHUTDOWN, | |
574 | ACPI_OST_SC_OS_SHUTDOWN_IN_PROGRESS, NULL); | |
575 | msleep(ACPI_SB_INDICATE_INTERVAL); | |
576 | } | |
577 | } | |
578 | ||
579 | static void acpi_sb_notify(acpi_handle handle, u32 event, void *data) | |
580 | { | |
581 | static DECLARE_WORK(acpi_sb_work, sb_notify_work); | |
582 | ||
583 | if (event == ACPI_SB_NOTIFY_SHUTDOWN_REQUEST) { | |
584 | if (!work_busy(&acpi_sb_work)) | |
585 | schedule_work(&acpi_sb_work); | |
586 | } else | |
587 | pr_warn("event %x is not supported by \\_SB device\n", event); | |
588 | } | |
589 | ||
590 | static int __init acpi_setup_sb_notify_handler(void) | |
591 | { | |
592 | acpi_handle sb_handle; | |
593 | ||
594 | if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &sb_handle))) | |
595 | return -ENXIO; | |
596 | ||
597 | if (ACPI_FAILURE(acpi_install_notify_handler(sb_handle, ACPI_DEVICE_NOTIFY, | |
598 | acpi_sb_notify, NULL))) | |
599 | return -EINVAL; | |
600 | ||
601 | return 0; | |
602 | } | |
603 | ||
68c6b148 RW |
604 | /* -------------------------------------------------------------------------- |
605 | Device Matching | |
606 | -------------------------------------------------------------------------- */ | |
607 | ||
3b95bd16 AM |
608 | /** |
609 | * acpi_get_first_physical_node - Get first physical node of an ACPI device | |
610 | * @adev: ACPI device in question | |
611 | * | |
612 | * Return: First physical node of ACPI device @adev | |
613 | */ | |
614 | struct device *acpi_get_first_physical_node(struct acpi_device *adev) | |
e91a398c RW |
615 | { |
616 | struct mutex *physical_node_lock = &adev->physical_node_lock; | |
3b95bd16 | 617 | struct device *phys_dev; |
e91a398c RW |
618 | |
619 | mutex_lock(physical_node_lock); | |
620 | if (list_empty(&adev->physical_node_list)) { | |
3b95bd16 | 621 | phys_dev = NULL; |
e91a398c RW |
622 | } else { |
623 | const struct acpi_device_physical_node *node; | |
624 | ||
625 | node = list_first_entry(&adev->physical_node_list, | |
626 | struct acpi_device_physical_node, node); | |
3b95bd16 AM |
627 | |
628 | phys_dev = node->dev; | |
e91a398c RW |
629 | } |
630 | mutex_unlock(physical_node_lock); | |
3b95bd16 AM |
631 | return phys_dev; |
632 | } | |
633 | ||
634 | static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev, | |
635 | const struct device *dev) | |
636 | { | |
637 | const struct device *phys_dev = acpi_get_first_physical_node(adev); | |
638 | ||
639 | return phys_dev && phys_dev == dev ? adev : NULL; | |
e91a398c RW |
640 | } |
641 | ||
3431e490 RW |
642 | /** |
643 | * acpi_device_is_first_physical_node - Is given dev first physical node | |
644 | * @adev: ACPI companion device | |
645 | * @dev: Physical device to check | |
646 | * | |
647 | * Function checks if given @dev is the first physical devices attached to | |
648 | * the ACPI companion device. This distinction is needed in some cases | |
649 | * where the same companion device is shared between many physical devices. | |
650 | * | |
651 | * Note that the caller have to provide valid @adev pointer. | |
652 | */ | |
653 | bool acpi_device_is_first_physical_node(struct acpi_device *adev, | |
654 | const struct device *dev) | |
655 | { | |
e91a398c | 656 | return !!acpi_primary_dev_companion(adev, dev); |
3431e490 RW |
657 | } |
658 | ||
68c6b148 RW |
659 | /* |
660 | * acpi_companion_match() - Can we match via ACPI companion device | |
661 | * @dev: Device in question | |
662 | * | |
663 | * Check if the given device has an ACPI companion and if that companion has | |
664 | * a valid list of PNP IDs, and if the device is the first (primary) physical | |
665 | * device associated with it. Return the companion pointer if that's the case | |
666 | * or NULL otherwise. | |
667 | * | |
668 | * If multiple physical devices are attached to a single ACPI companion, we need | |
669 | * to be careful. The usage scenario for this kind of relationship is that all | |
670 | * of the physical devices in question use resources provided by the ACPI | |
671 | * companion. A typical case is an MFD device where all the sub-devices share | |
672 | * the parent's ACPI companion. In such cases we can only allow the primary | |
673 | * (first) physical device to be matched with the help of the companion's PNP | |
674 | * IDs. | |
675 | * | |
676 | * Additional physical devices sharing the ACPI companion can still use | |
677 | * resources available from it but they will be matched normally using functions | |
678 | * provided by their bus types (and analogously for their modalias). | |
679 | */ | |
680 | struct acpi_device *acpi_companion_match(const struct device *dev) | |
681 | { | |
682 | struct acpi_device *adev; | |
68c6b148 RW |
683 | |
684 | adev = ACPI_COMPANION(dev); | |
685 | if (!adev) | |
686 | return NULL; | |
687 | ||
688 | if (list_empty(&adev->pnp.ids)) | |
689 | return NULL; | |
690 | ||
e91a398c | 691 | return acpi_primary_dev_companion(adev, dev); |
68c6b148 RW |
692 | } |
693 | ||
694 | /** | |
695 | * acpi_of_match_device - Match device object using the "compatible" property. | |
696 | * @adev: ACPI device object to match. | |
697 | * @of_match_table: List of device IDs to match against. | |
698 | * | |
699 | * If @dev has an ACPI companion which has ACPI_DT_NAMESPACE_HID in its list of | |
700 | * identifiers and a _DSD object with the "compatible" property, use that | |
701 | * property to match against the given list of identifiers. | |
702 | */ | |
703 | static bool acpi_of_match_device(struct acpi_device *adev, | |
704 | const struct of_device_id *of_match_table) | |
705 | { | |
706 | const union acpi_object *of_compatible, *obj; | |
707 | int i, nval; | |
708 | ||
709 | if (!adev) | |
710 | return false; | |
711 | ||
712 | of_compatible = adev->data.of_compatible; | |
713 | if (!of_match_table || !of_compatible) | |
714 | return false; | |
715 | ||
716 | if (of_compatible->type == ACPI_TYPE_PACKAGE) { | |
717 | nval = of_compatible->package.count; | |
718 | obj = of_compatible->package.elements; | |
719 | } else { /* Must be ACPI_TYPE_STRING. */ | |
720 | nval = 1; | |
721 | obj = of_compatible; | |
722 | } | |
723 | /* Now we can look for the driver DT compatible strings */ | |
724 | for (i = 0; i < nval; i++, obj++) { | |
725 | const struct of_device_id *id; | |
726 | ||
727 | for (id = of_match_table; id->compatible[0]; id++) | |
728 | if (!strcasecmp(obj->string.pointer, id->compatible)) | |
729 | return true; | |
730 | } | |
731 | ||
732 | return false; | |
733 | } | |
734 | ||
51ede5d9 DD |
735 | static bool acpi_of_modalias(struct acpi_device *adev, |
736 | char *modalias, size_t len) | |
737 | { | |
738 | const union acpi_object *of_compatible; | |
739 | const union acpi_object *obj; | |
740 | const char *str, *chr; | |
741 | ||
742 | of_compatible = adev->data.of_compatible; | |
743 | if (!of_compatible) | |
744 | return false; | |
745 | ||
746 | if (of_compatible->type == ACPI_TYPE_PACKAGE) | |
747 | obj = of_compatible->package.elements; | |
748 | else /* Must be ACPI_TYPE_STRING. */ | |
749 | obj = of_compatible; | |
750 | ||
751 | str = obj->string.pointer; | |
752 | chr = strchr(str, ','); | |
753 | strlcpy(modalias, chr ? chr + 1 : str, len); | |
754 | ||
755 | return true; | |
756 | } | |
757 | ||
758 | /** | |
759 | * acpi_set_modalias - Set modalias using "compatible" property or supplied ID | |
760 | * @adev: ACPI device object to match | |
761 | * @default_id: ID string to use as default if no compatible string found | |
762 | * @modalias: Pointer to buffer that modalias value will be copied into | |
763 | * @len: Length of modalias buffer | |
764 | * | |
765 | * This is a counterpart of of_modalias_node() for struct acpi_device objects. | |
766 | * If there is a compatible string for @adev, it will be copied to @modalias | |
767 | * with the vendor prefix stripped; otherwise, @default_id will be used. | |
768 | */ | |
769 | void acpi_set_modalias(struct acpi_device *adev, const char *default_id, | |
770 | char *modalias, size_t len) | |
771 | { | |
772 | if (!acpi_of_modalias(adev, modalias, len)) | |
773 | strlcpy(modalias, default_id, len); | |
774 | } | |
775 | EXPORT_SYMBOL_GPL(acpi_set_modalias); | |
776 | ||
68c6b148 RW |
777 | static bool __acpi_match_device_cls(const struct acpi_device_id *id, |
778 | struct acpi_hardware_id *hwid) | |
779 | { | |
780 | int i, msk, byte_shift; | |
781 | char buf[3]; | |
782 | ||
783 | if (!id->cls) | |
784 | return false; | |
785 | ||
786 | /* Apply class-code bitmask, before checking each class-code byte */ | |
787 | for (i = 1; i <= 3; i++) { | |
788 | byte_shift = 8 * (3 - i); | |
789 | msk = (id->cls_msk >> byte_shift) & 0xFF; | |
790 | if (!msk) | |
791 | continue; | |
792 | ||
793 | sprintf(buf, "%02x", (id->cls >> byte_shift) & msk); | |
794 | if (strncmp(buf, &hwid->id[(i - 1) * 2], 2)) | |
795 | return false; | |
796 | } | |
797 | return true; | |
798 | } | |
799 | ||
800 | static const struct acpi_device_id *__acpi_match_device( | |
801 | struct acpi_device *device, | |
802 | const struct acpi_device_id *ids, | |
803 | const struct of_device_id *of_ids) | |
804 | { | |
805 | const struct acpi_device_id *id; | |
806 | struct acpi_hardware_id *hwid; | |
807 | ||
808 | /* | |
809 | * If the device is not present, it is unnecessary to load device | |
810 | * driver for it. | |
811 | */ | |
812 | if (!device || !device->status.present) | |
813 | return NULL; | |
814 | ||
815 | list_for_each_entry(hwid, &device->pnp.ids, list) { | |
816 | /* First, check the ACPI/PNP IDs provided by the caller. */ | |
817 | for (id = ids; id->id[0] || id->cls; id++) { | |
818 | if (id->id[0] && !strcmp((char *) id->id, hwid->id)) | |
819 | return id; | |
820 | else if (id->cls && __acpi_match_device_cls(id, hwid)) | |
821 | return id; | |
822 | } | |
823 | ||
824 | /* | |
825 | * Next, check ACPI_DT_NAMESPACE_HID and try to match the | |
826 | * "compatible" property if found. | |
827 | * | |
828 | * The id returned by the below is not valid, but the only | |
829 | * caller passing non-NULL of_ids here is only interested in | |
830 | * whether or not the return value is NULL. | |
831 | */ | |
832 | if (!strcmp(ACPI_DT_NAMESPACE_HID, hwid->id) | |
833 | && acpi_of_match_device(device, of_ids)) | |
834 | return id; | |
835 | } | |
836 | return NULL; | |
837 | } | |
838 | ||
839 | /** | |
840 | * acpi_match_device - Match a struct device against a given list of ACPI IDs | |
841 | * @ids: Array of struct acpi_device_id object to match against. | |
842 | * @dev: The device structure to match. | |
843 | * | |
844 | * Check if @dev has a valid ACPI handle and if there is a struct acpi_device | |
845 | * object for that handle and use that object to match against a given list of | |
846 | * device IDs. | |
847 | * | |
848 | * Return a pointer to the first matching ID on success or %NULL on failure. | |
849 | */ | |
850 | const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids, | |
851 | const struct device *dev) | |
852 | { | |
853 | return __acpi_match_device(acpi_companion_match(dev), ids, NULL); | |
854 | } | |
855 | EXPORT_SYMBOL_GPL(acpi_match_device); | |
856 | ||
857 | int acpi_match_device_ids(struct acpi_device *device, | |
858 | const struct acpi_device_id *ids) | |
859 | { | |
860 | return __acpi_match_device(device, ids, NULL) ? 0 : -ENOENT; | |
861 | } | |
862 | EXPORT_SYMBOL(acpi_match_device_ids); | |
863 | ||
864 | bool acpi_driver_match_device(struct device *dev, | |
865 | const struct device_driver *drv) | |
866 | { | |
867 | if (!drv->acpi_match_table) | |
868 | return acpi_of_match_device(ACPI_COMPANION(dev), | |
869 | drv->of_match_table); | |
870 | ||
871 | return !!__acpi_match_device(acpi_companion_match(dev), | |
872 | drv->acpi_match_table, drv->of_match_table); | |
873 | } | |
874 | EXPORT_SYMBOL_GPL(acpi_driver_match_device); | |
875 | ||
5894b0c4 RW |
876 | /* -------------------------------------------------------------------------- |
877 | ACPI Driver Management | |
878 | -------------------------------------------------------------------------- */ | |
879 | ||
880 | /** | |
881 | * acpi_bus_register_driver - register a driver with the ACPI bus | |
882 | * @driver: driver being registered | |
883 | * | |
884 | * Registers a driver with the ACPI bus. Searches the namespace for all | |
885 | * devices that match the driver's criteria and binds. Returns zero for | |
886 | * success or a negative error status for failure. | |
887 | */ | |
888 | int acpi_bus_register_driver(struct acpi_driver *driver) | |
889 | { | |
890 | int ret; | |
891 | ||
892 | if (acpi_disabled) | |
893 | return -ENODEV; | |
894 | driver->drv.name = driver->name; | |
895 | driver->drv.bus = &acpi_bus_type; | |
896 | driver->drv.owner = driver->owner; | |
897 | ||
898 | ret = driver_register(&driver->drv); | |
899 | return ret; | |
900 | } | |
901 | ||
902 | EXPORT_SYMBOL(acpi_bus_register_driver); | |
903 | ||
904 | /** | |
905 | * acpi_bus_unregister_driver - unregisters a driver with the ACPI bus | |
906 | * @driver: driver to unregister | |
907 | * | |
908 | * Unregisters a driver with the ACPI bus. Searches the namespace for all | |
909 | * devices that match the driver's criteria and unbinds. | |
910 | */ | |
911 | void acpi_bus_unregister_driver(struct acpi_driver *driver) | |
912 | { | |
913 | driver_unregister(&driver->drv); | |
914 | } | |
915 | ||
916 | EXPORT_SYMBOL(acpi_bus_unregister_driver); | |
917 | ||
918 | /* -------------------------------------------------------------------------- | |
919 | ACPI Bus operations | |
920 | -------------------------------------------------------------------------- */ | |
921 | ||
922 | static int acpi_bus_match(struct device *dev, struct device_driver *drv) | |
923 | { | |
924 | struct acpi_device *acpi_dev = to_acpi_device(dev); | |
925 | struct acpi_driver *acpi_drv = to_acpi_driver(drv); | |
926 | ||
927 | return acpi_dev->flags.match_driver | |
928 | && !acpi_match_device_ids(acpi_dev, acpi_drv->ids); | |
929 | } | |
930 | ||
931 | static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) | |
932 | { | |
933 | return __acpi_device_uevent_modalias(to_acpi_device(dev), env); | |
934 | } | |
935 | ||
936 | static int acpi_device_probe(struct device *dev) | |
937 | { | |
938 | struct acpi_device *acpi_dev = to_acpi_device(dev); | |
939 | struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); | |
940 | int ret; | |
941 | ||
942 | if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev)) | |
943 | return -EINVAL; | |
944 | ||
945 | if (!acpi_drv->ops.add) | |
946 | return -ENOSYS; | |
947 | ||
948 | ret = acpi_drv->ops.add(acpi_dev); | |
949 | if (ret) | |
950 | return ret; | |
951 | ||
952 | acpi_dev->driver = acpi_drv; | |
953 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
954 | "Driver [%s] successfully bound to device [%s]\n", | |
955 | acpi_drv->name, acpi_dev->pnp.bus_id)); | |
956 | ||
957 | if (acpi_drv->ops.notify) { | |
958 | ret = acpi_device_install_notify_handler(acpi_dev); | |
959 | if (ret) { | |
960 | if (acpi_drv->ops.remove) | |
961 | acpi_drv->ops.remove(acpi_dev); | |
962 | ||
963 | acpi_dev->driver = NULL; | |
964 | acpi_dev->driver_data = NULL; | |
965 | return ret; | |
966 | } | |
967 | } | |
968 | ||
969 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n", | |
970 | acpi_drv->name, acpi_dev->pnp.bus_id)); | |
971 | get_device(dev); | |
972 | return 0; | |
973 | } | |
974 | ||
975 | static int acpi_device_remove(struct device * dev) | |
976 | { | |
977 | struct acpi_device *acpi_dev = to_acpi_device(dev); | |
978 | struct acpi_driver *acpi_drv = acpi_dev->driver; | |
979 | ||
980 | if (acpi_drv) { | |
981 | if (acpi_drv->ops.notify) | |
982 | acpi_device_remove_notify_handler(acpi_dev); | |
983 | if (acpi_drv->ops.remove) | |
984 | acpi_drv->ops.remove(acpi_dev); | |
985 | } | |
986 | acpi_dev->driver = NULL; | |
987 | acpi_dev->driver_data = NULL; | |
988 | ||
989 | put_device(dev); | |
990 | return 0; | |
991 | } | |
992 | ||
993 | struct bus_type acpi_bus_type = { | |
994 | .name = "acpi", | |
995 | .match = acpi_bus_match, | |
996 | .probe = acpi_device_probe, | |
997 | .remove = acpi_device_remove, | |
998 | .uevent = acpi_device_uevent, | |
999 | }; | |
1000 | ||
1da177e4 LT |
1001 | /* -------------------------------------------------------------------------- |
1002 | Initialization/Cleanup | |
1003 | -------------------------------------------------------------------------- */ | |
1004 | ||
4be44fcd | 1005 | static int __init acpi_bus_init_irq(void) |
1da177e4 | 1006 | { |
6a8c0af6 | 1007 | acpi_status status; |
4be44fcd | 1008 | char *message = NULL; |
1da177e4 | 1009 | |
1da177e4 | 1010 | |
aafbcd16 | 1011 | /* |
1da177e4 LT |
1012 | * Let the system know what interrupt model we are using by |
1013 | * evaluating the \_PIC object, if exists. | |
1014 | */ | |
1015 | ||
1016 | switch (acpi_irq_model) { | |
1017 | case ACPI_IRQ_MODEL_PIC: | |
1018 | message = "PIC"; | |
1019 | break; | |
1020 | case ACPI_IRQ_MODEL_IOAPIC: | |
1021 | message = "IOAPIC"; | |
1022 | break; | |
1023 | case ACPI_IRQ_MODEL_IOSAPIC: | |
1024 | message = "IOSAPIC"; | |
1025 | break; | |
fbe61ec7 HG |
1026 | case ACPI_IRQ_MODEL_GIC: |
1027 | message = "GIC"; | |
1028 | break; | |
3948ec94 JK |
1029 | case ACPI_IRQ_MODEL_PLATFORM: |
1030 | message = "platform specific model"; | |
1031 | break; | |
1da177e4 LT |
1032 | default: |
1033 | printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n"); | |
d550d98d | 1034 | return -ENODEV; |
1da177e4 LT |
1035 | } |
1036 | ||
1037 | printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message); | |
1038 | ||
0db98202 | 1039 | status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model); |
1da177e4 | 1040 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { |
a6fc6720 | 1041 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC")); |
d550d98d | 1042 | return -ENODEV; |
1da177e4 LT |
1043 | } |
1044 | ||
d550d98d | 1045 | return 0; |
1da177e4 LT |
1046 | } |
1047 | ||
b064a8fa RW |
1048 | /** |
1049 | * acpi_early_init - Initialize ACPICA and populate the ACPI namespace. | |
1050 | * | |
1051 | * The ACPI tables are accessible after this, but the handling of events has not | |
1052 | * been initialized and the global lock is not available yet, so AML should not | |
1053 | * be executed at this point. | |
1054 | * | |
1055 | * Doing this before switching the EFI runtime services to virtual mode allows | |
1056 | * the EfiBootServices memory to be freed slightly earlier on boot. | |
1057 | */ | |
4be44fcd | 1058 | void __init acpi_early_init(void) |
1da177e4 | 1059 | { |
6a8c0af6 | 1060 | acpi_status status; |
1da177e4 LT |
1061 | |
1062 | if (acpi_disabled) | |
d550d98d | 1063 | return; |
1da177e4 | 1064 | |
61686124 BM |
1065 | printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); |
1066 | ||
1da177e4 LT |
1067 | /* enable workarounds, unless strict ACPI spec. compliance */ |
1068 | if (!acpi_strict) | |
1069 | acpi_gbl_enable_interpreter_slack = TRUE; | |
1070 | ||
8d3523fb | 1071 | acpi_permanent_mmap = true; |
ad71860a | 1072 | |
84d7b8fd KHF |
1073 | /* Check machine-specific quirks */ |
1074 | dmi_check_system(acpi_quirks_dmi_table); | |
abd273f5 | 1075 | acpi_quirk_matches_bios_ids(acpi_quirk_lenovo_bios_ids); |
aa2110cb | 1076 | |
ad71860a AS |
1077 | status = acpi_reallocate_root_table(); |
1078 | if (ACPI_FAILURE(status)) { | |
1079 | printk(KERN_ERR PREFIX | |
1080 | "Unable to reallocate ACPI tables\n"); | |
1081 | goto error0; | |
1082 | } | |
1083 | ||
1da177e4 LT |
1084 | status = acpi_initialize_subsystem(); |
1085 | if (ACPI_FAILURE(status)) { | |
4be44fcd LB |
1086 | printk(KERN_ERR PREFIX |
1087 | "Unable to initialize the ACPI Interpreter\n"); | |
1da177e4 LT |
1088 | goto error0; |
1089 | } | |
1090 | ||
1ef35668 LZ |
1091 | if (!acpi_gbl_parse_table_as_term_list && |
1092 | acpi_gbl_group_module_level_code) { | |
fe6cbea0 LZ |
1093 | status = acpi_load_tables(); |
1094 | if (ACPI_FAILURE(status)) { | |
1095 | printk(KERN_ERR PREFIX | |
1096 | "Unable to load the System Description Tables\n"); | |
1097 | goto error0; | |
1098 | } | |
1da177e4 LT |
1099 | } |
1100 | ||
1da177e4 LT |
1101 | #ifdef CONFIG_X86 |
1102 | if (!acpi_ioapic) { | |
1da177e4 | 1103 | /* compatible (0) means level (3) */ |
5f3b1a8b AS |
1104 | if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) { |
1105 | acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK; | |
1106 | acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL; | |
1107 | } | |
1da177e4 | 1108 | /* Set PIC-mode SCI trigger type */ |
cee324b1 | 1109 | acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt, |
5f3b1a8b | 1110 | (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2); |
1da177e4 | 1111 | } else { |
1da177e4 | 1112 | /* |
cee324b1 | 1113 | * now that acpi_gbl_FADT is initialized, |
1da177e4 LT |
1114 | * update it with result from INT_SRC_OVR parsing |
1115 | */ | |
cee324b1 | 1116 | acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi; |
1da177e4 LT |
1117 | } |
1118 | #endif | |
b064a8fa RW |
1119 | return; |
1120 | ||
1121 | error0: | |
1122 | disable_acpi(); | |
1123 | } | |
1124 | ||
1125 | /** | |
1126 | * acpi_subsystem_init - Finalize the early initialization of ACPI. | |
1127 | * | |
3af03f77 | 1128 | * Switch over the platform to the ACPI mode (if possible). |
b064a8fa RW |
1129 | * |
1130 | * Doing this too early is generally unsafe, but at the same time it needs to be | |
1131 | * done before all things that really depend on ACPI. The right spot appears to | |
1132 | * be before finalizing the EFI initialization. | |
1133 | */ | |
1134 | void __init acpi_subsystem_init(void) | |
1135 | { | |
1136 | acpi_status status; | |
1137 | ||
1138 | if (acpi_disabled) | |
1139 | return; | |
1da177e4 | 1140 | |
4505a201 | 1141 | status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE); |
1da177e4 LT |
1142 | if (ACPI_FAILURE(status)) { |
1143 | printk(KERN_ERR PREFIX "Unable to enable ACPI\n"); | |
b064a8fa RW |
1144 | disable_acpi(); |
1145 | } else { | |
1146 | /* | |
1147 | * If the system is using ACPI then we can be reasonably | |
1148 | * confident that any regulators are managed by the firmware | |
1149 | * so tell the regulator core it has everything it needs to | |
1150 | * know. | |
1151 | */ | |
1152 | regulator_has_full_constraints(); | |
1da177e4 | 1153 | } |
1da177e4 LT |
1154 | } |
1155 | ||
68bdb677 OP |
1156 | static acpi_status acpi_bus_table_handler(u32 event, void *table, void *context) |
1157 | { | |
1158 | acpi_scan_table_handler(event, table, context); | |
1159 | ||
1160 | return acpi_sysfs_table_handler(event, table, context); | |
1161 | } | |
1162 | ||
4be44fcd | 1163 | static int __init acpi_bus_init(void) |
1da177e4 | 1164 | { |
6a8c0af6 BH |
1165 | int result; |
1166 | acpi_status status; | |
1da177e4 | 1167 | |
176f9c18 | 1168 | acpi_os_initialize1(); |
1da177e4 | 1169 | |
1da177e4 LT |
1170 | /* |
1171 | * ACPI 2.0 requires the EC driver to be loaded and work before | |
fe6cbea0 LZ |
1172 | * the EC device is found in the namespace (i.e. before |
1173 | * acpi_load_tables() is called). | |
1da177e4 | 1174 | * |
aafbcd16 | 1175 | * This is accomplished by looking for the ECDT table, and getting |
1da177e4 LT |
1176 | * the EC parameters out of that. |
1177 | */ | |
1178 | status = acpi_ec_ecdt_probe(); | |
1179 | /* Ignore result. Not having an ECDT is not fatal. */ | |
1da177e4 | 1180 | |
1ef35668 LZ |
1181 | if (acpi_gbl_parse_table_as_term_list || |
1182 | !acpi_gbl_group_module_level_code) { | |
fe6cbea0 LZ |
1183 | status = acpi_load_tables(); |
1184 | if (ACPI_FAILURE(status)) { | |
1185 | printk(KERN_ERR PREFIX | |
1186 | "Unable to load the System Description Tables\n"); | |
1187 | goto error1; | |
1188 | } | |
1189 | } | |
1190 | ||
1191 | status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE); | |
1192 | if (ACPI_FAILURE(status)) { | |
1193 | printk(KERN_ERR PREFIX | |
1194 | "Unable to start the ACPI Interpreter\n"); | |
1195 | goto error1; | |
1196 | } | |
1197 | ||
1da177e4 LT |
1198 | status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION); |
1199 | if (ACPI_FAILURE(status)) { | |
1200 | printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n"); | |
1201 | goto error1; | |
1202 | } | |
1203 | ||
a2121167 SP |
1204 | /* Set capability bits for _OSC under processor scope */ |
1205 | acpi_early_processor_osc(); | |
1206 | ||
fc54ab72 LM |
1207 | /* |
1208 | * _OSC method may exist in module level code, | |
1209 | * so it must be run after ACPI_FULL_INITIALIZATION | |
1210 | */ | |
1211 | acpi_bus_osc_support(); | |
1212 | ||
b1d248d9 ZR |
1213 | /* |
1214 | * _PDC control method may load dynamic SSDT tables, | |
1215 | * and we need to install the table handler before that. | |
1216 | */ | |
68bdb677 OP |
1217 | status = acpi_install_table_handler(acpi_bus_table_handler, NULL); |
1218 | ||
b1d248d9 ZR |
1219 | acpi_sysfs_init(); |
1220 | ||
78f16996 AC |
1221 | acpi_early_processor_set_pdc(); |
1222 | ||
455c8793 ZY |
1223 | /* |
1224 | * Maybe EC region is required at bus_scan/acpi_get_devices. So it | |
1225 | * is necessary to enable it as early as possible. | |
1226 | */ | |
dcf15cbd | 1227 | acpi_ec_dsdt_probe(); |
455c8793 | 1228 | |
1da177e4 LT |
1229 | printk(KERN_INFO PREFIX "Interpreter enabled\n"); |
1230 | ||
aafbcd16 AS |
1231 | /* Initialize sleep structures */ |
1232 | acpi_sleep_init(); | |
1233 | ||
1da177e4 LT |
1234 | /* |
1235 | * Get the system interrupt model and evaluate \_PIC. | |
1236 | */ | |
1237 | result = acpi_bus_init_irq(); | |
1238 | if (result) | |
1239 | goto error1; | |
1240 | ||
1241 | /* | |
1242 | * Register the for all standard device notifications. | |
1243 | */ | |
4be44fcd LB |
1244 | status = |
1245 | acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, | |
1246 | &acpi_bus_notify, NULL); | |
1da177e4 | 1247 | if (ACPI_FAILURE(status)) { |
4be44fcd LB |
1248 | printk(KERN_ERR PREFIX |
1249 | "Unable to register for device notifications\n"); | |
1da177e4 LT |
1250 | goto error1; |
1251 | } | |
1252 | ||
1253 | /* | |
1254 | * Create the top ACPI proc directory | |
1255 | */ | |
1256 | acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL); | |
1257 | ||
1dcc3d33 RW |
1258 | result = bus_register(&acpi_bus_type); |
1259 | if (!result) | |
1260 | return 0; | |
1da177e4 LT |
1261 | |
1262 | /* Mimic structured exception handling */ | |
4be44fcd | 1263 | error1: |
1da177e4 | 1264 | acpi_terminate(); |
d550d98d | 1265 | return -ENODEV; |
1da177e4 LT |
1266 | } |
1267 | ||
99e0d2fc | 1268 | struct kobject *acpi_kobj; |
f2d4753f | 1269 | EXPORT_SYMBOL_GPL(acpi_kobj); |
1da177e4 | 1270 | |
4be44fcd | 1271 | static int __init acpi_init(void) |
1da177e4 | 1272 | { |
6831c6ed | 1273 | int result; |
1da177e4 | 1274 | |
1da177e4 LT |
1275 | if (acpi_disabled) { |
1276 | printk(KERN_INFO PREFIX "Interpreter disabled.\n"); | |
d550d98d | 1277 | return -ENODEV; |
1da177e4 LT |
1278 | } |
1279 | ||
f62ed9e3 | 1280 | acpi_kobj = kobject_create_and_add("acpi", firmware_kobj); |
99e0d2fc | 1281 | if (!acpi_kobj) { |
96b2dd1f | 1282 | printk(KERN_WARNING "%s: kset create error\n", __func__); |
99e0d2fc GKH |
1283 | acpi_kobj = NULL; |
1284 | } | |
1da177e4 | 1285 | |
0e46517d | 1286 | init_acpi_device_notify(); |
1da177e4 | 1287 | result = acpi_bus_init(); |
6831c6ed | 1288 | if (result) { |
1da177e4 | 1289 | disable_acpi(); |
81d0273d | 1290 | return result; |
6831c6ed | 1291 | } |
81d0273d | 1292 | |
6831c6ed | 1293 | pci_mmcfg_late_init(); |
88ef16d8 | 1294 | acpi_iort_init(); |
e747f274 | 1295 | acpi_scan_init(); |
a5f820fe | 1296 | acpi_ec_init(); |
a25ee920 | 1297 | acpi_debugfs_init(); |
9cee43e0 | 1298 | acpi_sleep_proc_init(); |
201b8c65 | 1299 | acpi_wakeup_device_init(); |
836d0830 | 1300 | acpi_debugger_init(); |
baa0c019 | 1301 | acpi_setup_sb_notify_handler(); |
6831c6ed | 1302 | return 0; |
1da177e4 LT |
1303 | } |
1304 | ||
1305 | subsys_initcall(acpi_init); |