bus.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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 = AE_OK;
  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 = AE_OK;
  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 = 0;
  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 = 0;
  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. static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
  418. int register_acpi_bus_notifier(struct notifier_block *nb)
  419. {
  420. return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
  421. }
  422. EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
  423. void unregister_acpi_bus_notifier(struct notifier_block *nb)
  424. {
  425. blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
  426. }
  427. EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
  428. /**
  429. * acpi_bus_notify
  430. * ---------------
  431. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  432. */
  433. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  434. {
  435. struct acpi_device *device = NULL;
  436. struct acpi_driver *driver;
  437. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
  438. type, handle));
  439. blocking_notifier_call_chain(&acpi_bus_notify_list,
  440. type, (void *)handle);
  441. switch (type) {
  442. case ACPI_NOTIFY_BUS_CHECK:
  443. acpi_bus_check_scope(handle);
  444. /*
  445. * TBD: We'll need to outsource certain events to non-ACPI
  446. * drivers via the device manager (device.c).
  447. */
  448. break;
  449. case ACPI_NOTIFY_DEVICE_CHECK:
  450. acpi_bus_check_device(handle);
  451. /*
  452. * TBD: We'll need to outsource certain events to non-ACPI
  453. * drivers via the device manager (device.c).
  454. */
  455. break;
  456. case ACPI_NOTIFY_DEVICE_WAKE:
  457. /* TBD */
  458. break;
  459. case ACPI_NOTIFY_EJECT_REQUEST:
  460. /* TBD */
  461. break;
  462. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  463. /* TBD: Exactly what does 'light' mean? */
  464. break;
  465. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  466. /* TBD */
  467. break;
  468. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  469. /* TBD */
  470. break;
  471. case ACPI_NOTIFY_POWER_FAULT:
  472. /* TBD */
  473. break;
  474. default:
  475. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  476. "Received unknown/unsupported notification [%08x]\n",
  477. type));
  478. break;
  479. }
  480. acpi_bus_get_device(handle, &device);
  481. if (device) {
  482. driver = device->driver;
  483. if (driver && driver->ops.notify &&
  484. (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
  485. driver->ops.notify(device, type);
  486. }
  487. }
  488. /* --------------------------------------------------------------------------
  489. Initialization/Cleanup
  490. -------------------------------------------------------------------------- */
  491. static int __init acpi_bus_init_irq(void)
  492. {
  493. acpi_status status = AE_OK;
  494. union acpi_object arg = { ACPI_TYPE_INTEGER };
  495. struct acpi_object_list arg_list = { 1, &arg };
  496. char *message = NULL;
  497. /*
  498. * Let the system know what interrupt model we are using by
  499. * evaluating the \_PIC object, if exists.
  500. */
  501. switch (acpi_irq_model) {
  502. case ACPI_IRQ_MODEL_PIC:
  503. message = "PIC";
  504. break;
  505. case ACPI_IRQ_MODEL_IOAPIC:
  506. message = "IOAPIC";
  507. break;
  508. case ACPI_IRQ_MODEL_IOSAPIC:
  509. message = "IOSAPIC";
  510. break;
  511. case ACPI_IRQ_MODEL_PLATFORM:
  512. message = "platform specific model";
  513. break;
  514. default:
  515. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  516. return -ENODEV;
  517. }
  518. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  519. arg.integer.value = acpi_irq_model;
  520. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  521. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  522. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  523. return -ENODEV;
  524. }
  525. return 0;
  526. }
  527. u8 acpi_gbl_permanent_mmap;
  528. void __init acpi_early_init(void)
  529. {
  530. acpi_status status = AE_OK;
  531. if (acpi_disabled)
  532. return;
  533. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  534. /* enable workarounds, unless strict ACPI spec. compliance */
  535. if (!acpi_strict)
  536. acpi_gbl_enable_interpreter_slack = TRUE;
  537. acpi_gbl_permanent_mmap = 1;
  538. /*
  539. * If the machine falls into the DMI check table,
  540. * DSDT will be copied to memory
  541. */
  542. dmi_check_system(dsdt_dmi_table);
  543. status = acpi_reallocate_root_table();
  544. if (ACPI_FAILURE(status)) {
  545. printk(KERN_ERR PREFIX
  546. "Unable to reallocate ACPI tables\n");
  547. goto error0;
  548. }
  549. status = acpi_initialize_subsystem();
  550. if (ACPI_FAILURE(status)) {
  551. printk(KERN_ERR PREFIX
  552. "Unable to initialize the ACPI Interpreter\n");
  553. goto error0;
  554. }
  555. status = acpi_load_tables();
  556. if (ACPI_FAILURE(status)) {
  557. printk(KERN_ERR PREFIX
  558. "Unable to load the System Description Tables\n");
  559. goto error0;
  560. }
  561. #ifdef CONFIG_X86
  562. if (!acpi_ioapic) {
  563. /* compatible (0) means level (3) */
  564. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  565. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  566. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  567. }
  568. /* Set PIC-mode SCI trigger type */
  569. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  570. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  571. } else {
  572. /*
  573. * now that acpi_gbl_FADT is initialized,
  574. * update it with result from INT_SRC_OVR parsing
  575. */
  576. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  577. }
  578. #endif
  579. status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
  580. if (ACPI_FAILURE(status)) {
  581. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  582. goto error0;
  583. }
  584. return;
  585. error0:
  586. disable_acpi();
  587. return;
  588. }
  589. static int __init acpi_bus_init(void)
  590. {
  591. int result = 0;
  592. acpi_status status = AE_OK;
  593. extern acpi_status acpi_os_initialize1(void);
  594. acpi_os_initialize1();
  595. status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
  596. if (ACPI_FAILURE(status)) {
  597. printk(KERN_ERR PREFIX
  598. "Unable to start the ACPI Interpreter\n");
  599. goto error1;
  600. }
  601. /*
  602. * ACPI 2.0 requires the EC driver to be loaded and work before
  603. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  604. * is called).
  605. *
  606. * This is accomplished by looking for the ECDT table, and getting
  607. * the EC parameters out of that.
  608. */
  609. status = acpi_ec_ecdt_probe();
  610. /* Ignore result. Not having an ECDT is not fatal. */
  611. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  612. if (ACPI_FAILURE(status)) {
  613. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  614. goto error1;
  615. }
  616. /*
  617. * _OSC method may exist in module level code,
  618. * so it must be run after ACPI_FULL_INITIALIZATION
  619. */
  620. acpi_bus_osc_support();
  621. /*
  622. * _PDC control method may load dynamic SSDT tables,
  623. * and we need to install the table handler before that.
  624. */
  625. acpi_sysfs_init();
  626. acpi_early_processor_set_pdc();
  627. /*
  628. * Maybe EC region is required at bus_scan/acpi_get_devices. So it
  629. * is necessary to enable it as early as possible.
  630. */
  631. acpi_boot_ec_enable();
  632. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  633. /* Initialize sleep structures */
  634. acpi_sleep_init();
  635. /*
  636. * Get the system interrupt model and evaluate \_PIC.
  637. */
  638. result = acpi_bus_init_irq();
  639. if (result)
  640. goto error1;
  641. /*
  642. * Register the for all standard device notifications.
  643. */
  644. status =
  645. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  646. &acpi_bus_notify, NULL);
  647. if (ACPI_FAILURE(status)) {
  648. printk(KERN_ERR PREFIX
  649. "Unable to register for device notifications\n");
  650. goto error1;
  651. }
  652. /*
  653. * Create the top ACPI proc directory
  654. */
  655. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  656. return 0;
  657. /* Mimic structured exception handling */
  658. error1:
  659. acpi_terminate();
  660. return -ENODEV;
  661. }
  662. struct kobject *acpi_kobj;
  663. EXPORT_SYMBOL_GPL(acpi_kobj);
  664. static int __init acpi_init(void)
  665. {
  666. int result;
  667. if (acpi_disabled) {
  668. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  669. return -ENODEV;
  670. }
  671. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  672. if (!acpi_kobj) {
  673. printk(KERN_WARNING "%s: kset create error\n", __func__);
  674. acpi_kobj = NULL;
  675. }
  676. init_acpi_device_notify();
  677. result = acpi_bus_init();
  678. if (result) {
  679. disable_acpi();
  680. return result;
  681. }
  682. pci_mmcfg_late_init();
  683. acpi_scan_init();
  684. acpi_ec_init();
  685. acpi_debugfs_init();
  686. acpi_sleep_proc_init();
  687. acpi_wakeup_device_init();
  688. return 0;
  689. }
  690. subsys_initcall(acpi_init);