bus.c 34 KB

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