bus.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. */
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/kernel.h>
  28. #include <linux/list.h>
  29. #include <linux/sched.h>
  30. #include <linux/pm.h>
  31. #include <linux/device.h>
  32. #include <linux/proc_fs.h>
  33. #include <linux/acpi.h>
  34. #include <linux/slab.h>
  35. #ifdef CONFIG_X86
  36. #include <asm/mpspec.h>
  37. #endif
  38. #include <linux/pci.h>
  39. #include <acpi/acpi_bus.h>
  40. #include <acpi/acpi_drivers.h>
  41. #include <acpi/apei.h>
  42. #include <linux/dmi.h>
  43. #include <linux/suspend.h>
  44. #include "internal.h"
  45. #define _COMPONENT ACPI_BUS_COMPONENT
  46. ACPI_MODULE_NAME("bus");
  47. struct acpi_device *acpi_root;
  48. struct proc_dir_entry *acpi_root_dir;
  49. EXPORT_SYMBOL(acpi_root_dir);
  50. #define STRUCT_TO_INT(s) (*((int*)&s))
  51. #ifdef CONFIG_X86
  52. static int set_copy_dsdt(const struct dmi_system_id *id)
  53. {
  54. printk(KERN_NOTICE "%s detected - "
  55. "force copy of DSDT to local memory\n", id->ident);
  56. acpi_gbl_copy_dsdt_locally = 1;
  57. return 0;
  58. }
  59. static struct dmi_system_id dsdt_dmi_table[] __initdata = {
  60. /*
  61. * Invoke DSDT corruption work-around on all Toshiba Satellite.
  62. * https://bugzilla.kernel.org/show_bug.cgi?id=14679
  63. */
  64. {
  65. .callback = set_copy_dsdt,
  66. .ident = "TOSHIBA Satellite",
  67. .matches = {
  68. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  69. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
  70. },
  71. },
  72. {}
  73. };
  74. #else
  75. static struct dmi_system_id dsdt_dmi_table[] __initdata = {
  76. {}
  77. };
  78. #endif
  79. /* --------------------------------------------------------------------------
  80. Device Management
  81. -------------------------------------------------------------------------- */
  82. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
  83. {
  84. acpi_status status;
  85. if (!device)
  86. return -EINVAL;
  87. /* TBD: Support fixed-feature devices */
  88. status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
  89. if (ACPI_FAILURE(status) || !*device) {
  90. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  91. handle));
  92. return -ENODEV;
  93. }
  94. return 0;
  95. }
  96. EXPORT_SYMBOL(acpi_bus_get_device);
  97. acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  98. unsigned long long *sta)
  99. {
  100. acpi_status status;
  101. status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
  102. if (ACPI_SUCCESS(status))
  103. return AE_OK;
  104. if (status == AE_NOT_FOUND) {
  105. *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
  106. ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
  107. return AE_OK;
  108. }
  109. return status;
  110. }
  111. int acpi_bus_get_status(struct acpi_device *device)
  112. {
  113. acpi_status status;
  114. unsigned long long sta;
  115. status = acpi_bus_get_status_handle(device->handle, &sta);
  116. if (ACPI_FAILURE(status))
  117. return -ENODEV;
  118. STRUCT_TO_INT(device->status) = (int) sta;
  119. if (device->status.functional && !device->status.present) {
  120. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
  121. "functional but not present;\n",
  122. device->pnp.bus_id,
  123. (u32) STRUCT_TO_INT(device->status)));
  124. }
  125. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
  126. device->pnp.bus_id,
  127. (u32) STRUCT_TO_INT(device->status)));
  128. return 0;
  129. }
  130. EXPORT_SYMBOL(acpi_bus_get_status);
  131. void acpi_bus_private_data_handler(acpi_handle handle,
  132. void *context)
  133. {
  134. return;
  135. }
  136. EXPORT_SYMBOL(acpi_bus_private_data_handler);
  137. int acpi_bus_get_private_data(acpi_handle handle, void **data)
  138. {
  139. acpi_status status;
  140. if (!*data)
  141. return -EINVAL;
  142. status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
  143. if (ACPI_FAILURE(status) || !*data) {
  144. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  145. handle));
  146. return -ENODEV;
  147. }
  148. return 0;
  149. }
  150. EXPORT_SYMBOL(acpi_bus_get_private_data);
  151. static void acpi_print_osc_error(acpi_handle handle,
  152. struct acpi_osc_context *context, char *error)
  153. {
  154. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
  155. int i;
  156. if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
  157. printk(KERN_DEBUG "%s\n", error);
  158. else {
  159. printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
  160. kfree(buffer.pointer);
  161. }
  162. printk(KERN_DEBUG"_OSC request data:");
  163. for (i = 0; i < context->cap.length; i += sizeof(u32))
  164. printk("%x ", *((u32 *)(context->cap.pointer + i)));
  165. printk("\n");
  166. }
  167. static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
  168. {
  169. int i;
  170. static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
  171. 24, 26, 28, 30, 32, 34};
  172. if (strlen(str) != 36)
  173. return AE_BAD_PARAMETER;
  174. for (i = 0; i < 36; i++) {
  175. if (i == 8 || i == 13 || i == 18 || i == 23) {
  176. if (str[i] != '-')
  177. return AE_BAD_PARAMETER;
  178. } else if (!isxdigit(str[i]))
  179. return AE_BAD_PARAMETER;
  180. }
  181. for (i = 0; i < 16; i++) {
  182. uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4;
  183. uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]);
  184. }
  185. return AE_OK;
  186. }
  187. acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
  188. {
  189. acpi_status status;
  190. struct acpi_object_list input;
  191. union acpi_object in_params[4];
  192. union acpi_object *out_obj;
  193. u8 uuid[16];
  194. u32 errors;
  195. struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
  196. if (!context)
  197. return AE_ERROR;
  198. if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
  199. return AE_ERROR;
  200. context->ret.length = ACPI_ALLOCATE_BUFFER;
  201. context->ret.pointer = NULL;
  202. /* Setting up input parameters */
  203. input.count = 4;
  204. input.pointer = in_params;
  205. in_params[0].type = ACPI_TYPE_BUFFER;
  206. in_params[0].buffer.length = 16;
  207. in_params[0].buffer.pointer = uuid;
  208. in_params[1].type = ACPI_TYPE_INTEGER;
  209. in_params[1].integer.value = context->rev;
  210. in_params[2].type = ACPI_TYPE_INTEGER;
  211. in_params[2].integer.value = context->cap.length/sizeof(u32);
  212. in_params[3].type = ACPI_TYPE_BUFFER;
  213. in_params[3].buffer.length = context->cap.length;
  214. in_params[3].buffer.pointer = context->cap.pointer;
  215. status = acpi_evaluate_object(handle, "_OSC", &input, &output);
  216. if (ACPI_FAILURE(status))
  217. return status;
  218. if (!output.length)
  219. return AE_NULL_OBJECT;
  220. out_obj = output.pointer;
  221. if (out_obj->type != ACPI_TYPE_BUFFER
  222. || out_obj->buffer.length != context->cap.length) {
  223. acpi_print_osc_error(handle, context,
  224. "_OSC evaluation returned wrong type");
  225. status = AE_TYPE;
  226. goto out_kfree;
  227. }
  228. /* Need to ignore the bit0 in result code */
  229. errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
  230. if (errors) {
  231. if (errors & OSC_REQUEST_ERROR)
  232. acpi_print_osc_error(handle, context,
  233. "_OSC request failed");
  234. if (errors & OSC_INVALID_UUID_ERROR)
  235. acpi_print_osc_error(handle, context,
  236. "_OSC invalid UUID");
  237. if (errors & OSC_INVALID_REVISION_ERROR)
  238. acpi_print_osc_error(handle, context,
  239. "_OSC invalid revision");
  240. if (errors & OSC_CAPABILITIES_MASK_ERROR) {
  241. if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
  242. & OSC_QUERY_ENABLE)
  243. goto out_success;
  244. status = AE_SUPPORT;
  245. goto out_kfree;
  246. }
  247. status = AE_ERROR;
  248. goto out_kfree;
  249. }
  250. out_success:
  251. context->ret.length = out_obj->buffer.length;
  252. context->ret.pointer = kmemdup(out_obj->buffer.pointer,
  253. context->ret.length, GFP_KERNEL);
  254. if (!context->ret.pointer) {
  255. status = AE_NO_MEMORY;
  256. goto out_kfree;
  257. }
  258. status = AE_OK;
  259. out_kfree:
  260. kfree(output.pointer);
  261. if (status != AE_OK)
  262. context->ret.pointer = NULL;
  263. return status;
  264. }
  265. EXPORT_SYMBOL(acpi_run_osc);
  266. bool osc_sb_apei_support_acked;
  267. static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
  268. static void acpi_bus_osc_support(void)
  269. {
  270. u32 capbuf[2];
  271. struct acpi_osc_context context = {
  272. .uuid_str = sb_uuid_str,
  273. .rev = 1,
  274. .cap.length = 8,
  275. .cap.pointer = capbuf,
  276. };
  277. acpi_handle handle;
  278. capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
  279. capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
  280. #if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
  281. defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
  282. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
  283. #endif
  284. #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
  285. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PPC_OST_SUPPORT;
  286. #endif
  287. #ifdef ACPI_HOTPLUG_OST
  288. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_HOTPLUG_OST_SUPPORT;
  289. #endif
  290. if (!ghes_disable)
  291. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_APEI_SUPPORT;
  292. if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
  293. return;
  294. if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
  295. u32 *capbuf_ret = context.ret.pointer;
  296. if (context.ret.length > OSC_SUPPORT_TYPE)
  297. osc_sb_apei_support_acked =
  298. capbuf_ret[OSC_SUPPORT_TYPE] & OSC_SB_APEI_SUPPORT;
  299. kfree(context.ret.pointer);
  300. }
  301. /* do we need to check other returned cap? Sounds no */
  302. }
  303. /* --------------------------------------------------------------------------
  304. Event Management
  305. -------------------------------------------------------------------------- */
  306. #ifdef CONFIG_ACPI_PROC_EVENT
  307. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  308. LIST_HEAD(acpi_bus_event_list);
  309. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  310. extern int event_is_open;
  311. int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
  312. {
  313. struct acpi_bus_event *event;
  314. unsigned long flags;
  315. /* drop event on the floor if no one's listening */
  316. if (!event_is_open)
  317. return 0;
  318. event = kzalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
  319. if (!event)
  320. return -ENOMEM;
  321. strcpy(event->device_class, device_class);
  322. strcpy(event->bus_id, bus_id);
  323. event->type = type;
  324. event->data = data;
  325. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  326. list_add_tail(&event->node, &acpi_bus_event_list);
  327. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  328. wake_up_interruptible(&acpi_bus_event_queue);
  329. return 0;
  330. }
  331. EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
  332. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  333. {
  334. if (!device)
  335. return -EINVAL;
  336. return acpi_bus_generate_proc_event4(device->pnp.device_class,
  337. device->pnp.bus_id, type, data);
  338. }
  339. EXPORT_SYMBOL(acpi_bus_generate_proc_event);
  340. int acpi_bus_receive_event(struct acpi_bus_event *event)
  341. {
  342. unsigned long flags;
  343. struct acpi_bus_event *entry = NULL;
  344. DECLARE_WAITQUEUE(wait, current);
  345. if (!event)
  346. return -EINVAL;
  347. if (list_empty(&acpi_bus_event_list)) {
  348. set_current_state(TASK_INTERRUPTIBLE);
  349. add_wait_queue(&acpi_bus_event_queue, &wait);
  350. if (list_empty(&acpi_bus_event_list))
  351. schedule();
  352. remove_wait_queue(&acpi_bus_event_queue, &wait);
  353. set_current_state(TASK_RUNNING);
  354. if (signal_pending(current))
  355. return -ERESTARTSYS;
  356. }
  357. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  358. if (!list_empty(&acpi_bus_event_list)) {
  359. entry = list_entry(acpi_bus_event_list.next,
  360. struct acpi_bus_event, node);
  361. list_del(&entry->node);
  362. }
  363. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  364. if (!entry)
  365. return -ENODEV;
  366. memcpy(event, entry, sizeof(struct acpi_bus_event));
  367. kfree(entry);
  368. return 0;
  369. }
  370. #endif /* CONFIG_ACPI_PROC_EVENT */
  371. /* --------------------------------------------------------------------------
  372. Notification Handling
  373. -------------------------------------------------------------------------- */
  374. static void acpi_bus_check_device(acpi_handle handle)
  375. {
  376. struct acpi_device *device;
  377. acpi_status status;
  378. struct acpi_device_status old_status;
  379. if (acpi_bus_get_device(handle, &device))
  380. return;
  381. if (!device)
  382. return;
  383. old_status = device->status;
  384. /*
  385. * Make sure this device's parent is present before we go about
  386. * messing with the device.
  387. */
  388. if (device->parent && !device->parent->status.present) {
  389. device->status = device->parent->status;
  390. return;
  391. }
  392. status = acpi_bus_get_status(device);
  393. if (ACPI_FAILURE(status))
  394. return;
  395. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  396. return;
  397. /*
  398. * Device Insertion/Removal
  399. */
  400. if ((device->status.present) && !(old_status.present)) {
  401. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  402. /* TBD: Handle device insertion */
  403. } else if (!(device->status.present) && (old_status.present)) {
  404. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  405. /* TBD: Handle device removal */
  406. }
  407. }
  408. static void acpi_bus_check_scope(acpi_handle handle)
  409. {
  410. /* Status Change? */
  411. acpi_bus_check_device(handle);
  412. /*
  413. * TBD: Enumerate child devices within this device's scope and
  414. * run acpi_bus_check_device()'s on them.
  415. */
  416. }
  417. /**
  418. * acpi_bus_notify
  419. * ---------------
  420. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  421. */
  422. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  423. {
  424. struct acpi_device *device = NULL;
  425. struct acpi_driver *driver;
  426. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
  427. type, handle));
  428. switch (type) {
  429. case ACPI_NOTIFY_BUS_CHECK:
  430. acpi_bus_check_scope(handle);
  431. /*
  432. * TBD: We'll need to outsource certain events to non-ACPI
  433. * drivers via the device manager (device.c).
  434. */
  435. break;
  436. case ACPI_NOTIFY_DEVICE_CHECK:
  437. acpi_bus_check_device(handle);
  438. /*
  439. * TBD: We'll need to outsource certain events to non-ACPI
  440. * drivers via the device manager (device.c).
  441. */
  442. break;
  443. case ACPI_NOTIFY_DEVICE_WAKE:
  444. /* TBD */
  445. break;
  446. case ACPI_NOTIFY_EJECT_REQUEST:
  447. /* TBD */
  448. break;
  449. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  450. /* TBD: Exactly what does 'light' mean? */
  451. break;
  452. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  453. /* TBD */
  454. break;
  455. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  456. /* TBD */
  457. break;
  458. case ACPI_NOTIFY_POWER_FAULT:
  459. /* TBD */
  460. break;
  461. default:
  462. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  463. "Received unknown/unsupported notification [%08x]\n",
  464. type));
  465. break;
  466. }
  467. acpi_bus_get_device(handle, &device);
  468. if (device) {
  469. driver = device->driver;
  470. if (driver && driver->ops.notify &&
  471. (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
  472. driver->ops.notify(device, type);
  473. }
  474. }
  475. /* --------------------------------------------------------------------------
  476. Initialization/Cleanup
  477. -------------------------------------------------------------------------- */
  478. static int __init acpi_bus_init_irq(void)
  479. {
  480. acpi_status status;
  481. char *message = NULL;
  482. /*
  483. * Let the system know what interrupt model we are using by
  484. * evaluating the \_PIC object, if exists.
  485. */
  486. switch (acpi_irq_model) {
  487. case ACPI_IRQ_MODEL_PIC:
  488. message = "PIC";
  489. break;
  490. case ACPI_IRQ_MODEL_IOAPIC:
  491. message = "IOAPIC";
  492. break;
  493. case ACPI_IRQ_MODEL_IOSAPIC:
  494. message = "IOSAPIC";
  495. break;
  496. case ACPI_IRQ_MODEL_PLATFORM:
  497. message = "platform specific model";
  498. break;
  499. default:
  500. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  501. return -ENODEV;
  502. }
  503. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  504. status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model);
  505. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  506. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  507. return -ENODEV;
  508. }
  509. return 0;
  510. }
  511. u8 acpi_gbl_permanent_mmap;
  512. void __init acpi_early_init(void)
  513. {
  514. acpi_status status;
  515. if (acpi_disabled)
  516. return;
  517. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  518. /* enable workarounds, unless strict ACPI spec. compliance */
  519. if (!acpi_strict)
  520. acpi_gbl_enable_interpreter_slack = TRUE;
  521. acpi_gbl_permanent_mmap = 1;
  522. /*
  523. * If the machine falls into the DMI check table,
  524. * DSDT will be copied to memory
  525. */
  526. dmi_check_system(dsdt_dmi_table);
  527. status = acpi_reallocate_root_table();
  528. if (ACPI_FAILURE(status)) {
  529. printk(KERN_ERR PREFIX
  530. "Unable to reallocate ACPI tables\n");
  531. goto error0;
  532. }
  533. status = acpi_initialize_subsystem();
  534. if (ACPI_FAILURE(status)) {
  535. printk(KERN_ERR PREFIX
  536. "Unable to initialize the ACPI Interpreter\n");
  537. goto error0;
  538. }
  539. status = acpi_load_tables();
  540. if (ACPI_FAILURE(status)) {
  541. printk(KERN_ERR PREFIX
  542. "Unable to load the System Description Tables\n");
  543. goto error0;
  544. }
  545. #ifdef CONFIG_X86
  546. if (!acpi_ioapic) {
  547. /* compatible (0) means level (3) */
  548. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  549. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  550. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  551. }
  552. /* Set PIC-mode SCI trigger type */
  553. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  554. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  555. } else {
  556. /*
  557. * now that acpi_gbl_FADT is initialized,
  558. * update it with result from INT_SRC_OVR parsing
  559. */
  560. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  561. }
  562. #endif
  563. status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
  564. if (ACPI_FAILURE(status)) {
  565. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  566. goto error0;
  567. }
  568. return;
  569. error0:
  570. disable_acpi();
  571. return;
  572. }
  573. static int __init acpi_bus_init(void)
  574. {
  575. int result;
  576. acpi_status status;
  577. extern acpi_status acpi_os_initialize1(void);
  578. acpi_os_initialize1();
  579. status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
  580. if (ACPI_FAILURE(status)) {
  581. printk(KERN_ERR PREFIX
  582. "Unable to start the ACPI Interpreter\n");
  583. goto error1;
  584. }
  585. /*
  586. * ACPI 2.0 requires the EC driver to be loaded and work before
  587. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  588. * is called).
  589. *
  590. * This is accomplished by looking for the ECDT table, and getting
  591. * the EC parameters out of that.
  592. */
  593. status = acpi_ec_ecdt_probe();
  594. /* Ignore result. Not having an ECDT is not fatal. */
  595. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  596. if (ACPI_FAILURE(status)) {
  597. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  598. goto error1;
  599. }
  600. /*
  601. * _OSC method may exist in module level code,
  602. * so it must be run after ACPI_FULL_INITIALIZATION
  603. */
  604. acpi_bus_osc_support();
  605. /*
  606. * _PDC control method may load dynamic SSDT tables,
  607. * and we need to install the table handler before that.
  608. */
  609. acpi_sysfs_init();
  610. acpi_early_processor_set_pdc();
  611. /*
  612. * Maybe EC region is required at bus_scan/acpi_get_devices. So it
  613. * is necessary to enable it as early as possible.
  614. */
  615. acpi_boot_ec_enable();
  616. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  617. /* Initialize sleep structures */
  618. acpi_sleep_init();
  619. /*
  620. * Get the system interrupt model and evaluate \_PIC.
  621. */
  622. result = acpi_bus_init_irq();
  623. if (result)
  624. goto error1;
  625. /*
  626. * Register the for all standard device notifications.
  627. */
  628. status =
  629. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  630. &acpi_bus_notify, NULL);
  631. if (ACPI_FAILURE(status)) {
  632. printk(KERN_ERR PREFIX
  633. "Unable to register for device notifications\n");
  634. goto error1;
  635. }
  636. /*
  637. * Create the top ACPI proc directory
  638. */
  639. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  640. return 0;
  641. /* Mimic structured exception handling */
  642. error1:
  643. acpi_terminate();
  644. return -ENODEV;
  645. }
  646. struct kobject *acpi_kobj;
  647. EXPORT_SYMBOL_GPL(acpi_kobj);
  648. static int __init acpi_init(void)
  649. {
  650. int result;
  651. if (acpi_disabled) {
  652. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  653. return -ENODEV;
  654. }
  655. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  656. if (!acpi_kobj) {
  657. printk(KERN_WARNING "%s: kset create error\n", __func__);
  658. acpi_kobj = NULL;
  659. }
  660. init_acpi_device_notify();
  661. result = acpi_bus_init();
  662. if (result) {
  663. disable_acpi();
  664. return result;
  665. }
  666. pci_mmcfg_late_init();
  667. acpi_scan_init();
  668. acpi_ec_init();
  669. acpi_debugfs_init();
  670. acpi_sleep_proc_init();
  671. acpi_wakeup_device_init();
  672. return 0;
  673. }
  674. subsys_initcall(acpi_init);