bus.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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 = kmalloc(context->ret.length, GFP_KERNEL);
  253. if (!context->ret.pointer) {
  254. status = AE_NO_MEMORY;
  255. goto out_kfree;
  256. }
  257. memcpy(context->ret.pointer, out_obj->buffer.pointer,
  258. context->ret.length);
  259. status = AE_OK;
  260. out_kfree:
  261. kfree(output.pointer);
  262. if (status != AE_OK)
  263. context->ret.pointer = NULL;
  264. return status;
  265. }
  266. EXPORT_SYMBOL(acpi_run_osc);
  267. bool osc_sb_apei_support_acked;
  268. static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
  269. static void acpi_bus_osc_support(void)
  270. {
  271. u32 capbuf[2];
  272. struct acpi_osc_context context = {
  273. .uuid_str = sb_uuid_str,
  274. .rev = 1,
  275. .cap.length = 8,
  276. .cap.pointer = capbuf,
  277. };
  278. acpi_handle handle;
  279. capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
  280. capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
  281. #if defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) ||\
  282. defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
  283. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
  284. #endif
  285. #if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
  286. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PPC_OST_SUPPORT;
  287. #endif
  288. #ifdef ACPI_HOTPLUG_OST
  289. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_HOTPLUG_OST_SUPPORT;
  290. #endif
  291. if (!ghes_disable)
  292. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_APEI_SUPPORT;
  293. if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
  294. return;
  295. if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
  296. u32 *capbuf_ret = context.ret.pointer;
  297. if (context.ret.length > OSC_SUPPORT_TYPE)
  298. osc_sb_apei_support_acked =
  299. capbuf_ret[OSC_SUPPORT_TYPE] & OSC_SB_APEI_SUPPORT;
  300. kfree(context.ret.pointer);
  301. }
  302. /* do we need to check other returned cap? Sounds no */
  303. }
  304. /* --------------------------------------------------------------------------
  305. Event Management
  306. -------------------------------------------------------------------------- */
  307. #ifdef CONFIG_ACPI_PROC_EVENT
  308. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  309. LIST_HEAD(acpi_bus_event_list);
  310. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  311. extern int event_is_open;
  312. int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
  313. {
  314. struct acpi_bus_event *event;
  315. unsigned long flags = 0;
  316. /* drop event on the floor if no one's listening */
  317. if (!event_is_open)
  318. return 0;
  319. event = kzalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
  320. if (!event)
  321. return -ENOMEM;
  322. strcpy(event->device_class, device_class);
  323. strcpy(event->bus_id, bus_id);
  324. event->type = type;
  325. event->data = data;
  326. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  327. list_add_tail(&event->node, &acpi_bus_event_list);
  328. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  329. wake_up_interruptible(&acpi_bus_event_queue);
  330. return 0;
  331. }
  332. EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
  333. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  334. {
  335. if (!device)
  336. return -EINVAL;
  337. return acpi_bus_generate_proc_event4(device->pnp.device_class,
  338. device->pnp.bus_id, type, data);
  339. }
  340. EXPORT_SYMBOL(acpi_bus_generate_proc_event);
  341. int acpi_bus_receive_event(struct acpi_bus_event *event)
  342. {
  343. unsigned long flags = 0;
  344. struct acpi_bus_event *entry = NULL;
  345. DECLARE_WAITQUEUE(wait, current);
  346. if (!event)
  347. return -EINVAL;
  348. if (list_empty(&acpi_bus_event_list)) {
  349. set_current_state(TASK_INTERRUPTIBLE);
  350. add_wait_queue(&acpi_bus_event_queue, &wait);
  351. if (list_empty(&acpi_bus_event_list))
  352. schedule();
  353. remove_wait_queue(&acpi_bus_event_queue, &wait);
  354. set_current_state(TASK_RUNNING);
  355. if (signal_pending(current))
  356. return -ERESTARTSYS;
  357. }
  358. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  359. if (!list_empty(&acpi_bus_event_list)) {
  360. entry = list_entry(acpi_bus_event_list.next,
  361. struct acpi_bus_event, node);
  362. list_del(&entry->node);
  363. }
  364. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  365. if (!entry)
  366. return -ENODEV;
  367. memcpy(event, entry, sizeof(struct acpi_bus_event));
  368. kfree(entry);
  369. return 0;
  370. }
  371. #endif /* CONFIG_ACPI_PROC_EVENT */
  372. /* --------------------------------------------------------------------------
  373. Notification Handling
  374. -------------------------------------------------------------------------- */
  375. static void acpi_bus_check_device(acpi_handle handle)
  376. {
  377. struct acpi_device *device;
  378. acpi_status status;
  379. struct acpi_device_status old_status;
  380. if (acpi_bus_get_device(handle, &device))
  381. return;
  382. if (!device)
  383. return;
  384. old_status = device->status;
  385. /*
  386. * Make sure this device's parent is present before we go about
  387. * messing with the device.
  388. */
  389. if (device->parent && !device->parent->status.present) {
  390. device->status = device->parent->status;
  391. return;
  392. }
  393. status = acpi_bus_get_status(device);
  394. if (ACPI_FAILURE(status))
  395. return;
  396. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  397. return;
  398. /*
  399. * Device Insertion/Removal
  400. */
  401. if ((device->status.present) && !(old_status.present)) {
  402. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  403. /* TBD: Handle device insertion */
  404. } else if (!(device->status.present) && (old_status.present)) {
  405. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  406. /* TBD: Handle device removal */
  407. }
  408. }
  409. static void acpi_bus_check_scope(acpi_handle handle)
  410. {
  411. /* Status Change? */
  412. acpi_bus_check_device(handle);
  413. /*
  414. * TBD: Enumerate child devices within this device's scope and
  415. * run acpi_bus_check_device()'s on them.
  416. */
  417. }
  418. static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
  419. int register_acpi_bus_notifier(struct notifier_block *nb)
  420. {
  421. return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
  422. }
  423. EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
  424. void unregister_acpi_bus_notifier(struct notifier_block *nb)
  425. {
  426. blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
  427. }
  428. EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
  429. /**
  430. * acpi_bus_notify
  431. * ---------------
  432. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  433. */
  434. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  435. {
  436. struct acpi_device *device = NULL;
  437. struct acpi_driver *driver;
  438. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
  439. type, handle));
  440. blocking_notifier_call_chain(&acpi_bus_notify_list,
  441. type, (void *)handle);
  442. switch (type) {
  443. case ACPI_NOTIFY_BUS_CHECK:
  444. acpi_bus_check_scope(handle);
  445. /*
  446. * TBD: We'll need to outsource certain events to non-ACPI
  447. * drivers via the device manager (device.c).
  448. */
  449. break;
  450. case ACPI_NOTIFY_DEVICE_CHECK:
  451. acpi_bus_check_device(handle);
  452. /*
  453. * TBD: We'll need to outsource certain events to non-ACPI
  454. * drivers via the device manager (device.c).
  455. */
  456. break;
  457. case ACPI_NOTIFY_DEVICE_WAKE:
  458. /* TBD */
  459. break;
  460. case ACPI_NOTIFY_EJECT_REQUEST:
  461. /* TBD */
  462. break;
  463. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  464. /* TBD: Exactly what does 'light' mean? */
  465. break;
  466. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  467. /* TBD */
  468. break;
  469. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  470. /* TBD */
  471. break;
  472. case ACPI_NOTIFY_POWER_FAULT:
  473. /* TBD */
  474. break;
  475. default:
  476. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  477. "Received unknown/unsupported notification [%08x]\n",
  478. type));
  479. break;
  480. }
  481. acpi_bus_get_device(handle, &device);
  482. if (device) {
  483. driver = device->driver;
  484. if (driver && driver->ops.notify &&
  485. (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
  486. driver->ops.notify(device, type);
  487. }
  488. }
  489. /* --------------------------------------------------------------------------
  490. Initialization/Cleanup
  491. -------------------------------------------------------------------------- */
  492. static int __init acpi_bus_init_irq(void)
  493. {
  494. acpi_status status = AE_OK;
  495. union acpi_object arg = { ACPI_TYPE_INTEGER };
  496. struct acpi_object_list arg_list = { 1, &arg };
  497. char *message = NULL;
  498. /*
  499. * Let the system know what interrupt model we are using by
  500. * evaluating the \_PIC object, if exists.
  501. */
  502. switch (acpi_irq_model) {
  503. case ACPI_IRQ_MODEL_PIC:
  504. message = "PIC";
  505. break;
  506. case ACPI_IRQ_MODEL_IOAPIC:
  507. message = "IOAPIC";
  508. break;
  509. case ACPI_IRQ_MODEL_IOSAPIC:
  510. message = "IOSAPIC";
  511. break;
  512. case ACPI_IRQ_MODEL_PLATFORM:
  513. message = "platform specific model";
  514. break;
  515. default:
  516. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  517. return -ENODEV;
  518. }
  519. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  520. arg.integer.value = acpi_irq_model;
  521. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  522. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  523. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  524. return -ENODEV;
  525. }
  526. return 0;
  527. }
  528. u8 acpi_gbl_permanent_mmap;
  529. void __init acpi_early_init(void)
  530. {
  531. acpi_status status = AE_OK;
  532. if (acpi_disabled)
  533. return;
  534. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  535. /* enable workarounds, unless strict ACPI spec. compliance */
  536. if (!acpi_strict)
  537. acpi_gbl_enable_interpreter_slack = TRUE;
  538. acpi_gbl_permanent_mmap = 1;
  539. /*
  540. * If the machine falls into the DMI check table,
  541. * DSDT will be copied to memory
  542. */
  543. dmi_check_system(dsdt_dmi_table);
  544. status = acpi_reallocate_root_table();
  545. if (ACPI_FAILURE(status)) {
  546. printk(KERN_ERR PREFIX
  547. "Unable to reallocate ACPI tables\n");
  548. goto error0;
  549. }
  550. status = acpi_initialize_subsystem();
  551. if (ACPI_FAILURE(status)) {
  552. printk(KERN_ERR PREFIX
  553. "Unable to initialize the ACPI Interpreter\n");
  554. goto error0;
  555. }
  556. status = acpi_load_tables();
  557. if (ACPI_FAILURE(status)) {
  558. printk(KERN_ERR PREFIX
  559. "Unable to load the System Description Tables\n");
  560. goto error0;
  561. }
  562. #ifdef CONFIG_X86
  563. if (!acpi_ioapic) {
  564. /* compatible (0) means level (3) */
  565. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  566. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  567. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  568. }
  569. /* Set PIC-mode SCI trigger type */
  570. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  571. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  572. } else {
  573. /*
  574. * now that acpi_gbl_FADT is initialized,
  575. * update it with result from INT_SRC_OVR parsing
  576. */
  577. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  578. }
  579. #endif
  580. status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
  581. if (ACPI_FAILURE(status)) {
  582. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  583. goto error0;
  584. }
  585. return;
  586. error0:
  587. disable_acpi();
  588. return;
  589. }
  590. static int __init acpi_bus_init(void)
  591. {
  592. int result = 0;
  593. acpi_status status = AE_OK;
  594. extern acpi_status acpi_os_initialize1(void);
  595. acpi_os_initialize1();
  596. status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
  597. if (ACPI_FAILURE(status)) {
  598. printk(KERN_ERR PREFIX
  599. "Unable to start the ACPI Interpreter\n");
  600. goto error1;
  601. }
  602. /*
  603. * ACPI 2.0 requires the EC driver to be loaded and work before
  604. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  605. * is called).
  606. *
  607. * This is accomplished by looking for the ECDT table, and getting
  608. * the EC parameters out of that.
  609. */
  610. status = acpi_ec_ecdt_probe();
  611. /* Ignore result. Not having an ECDT is not fatal. */
  612. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  613. if (ACPI_FAILURE(status)) {
  614. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  615. goto error1;
  616. }
  617. /*
  618. * _OSC method may exist in module level code,
  619. * so it must be run after ACPI_FULL_INITIALIZATION
  620. */
  621. acpi_bus_osc_support();
  622. /*
  623. * _PDC control method may load dynamic SSDT tables,
  624. * and we need to install the table handler before that.
  625. */
  626. acpi_sysfs_init();
  627. acpi_early_processor_set_pdc();
  628. /*
  629. * Maybe EC region is required at bus_scan/acpi_get_devices. So it
  630. * is necessary to enable it as early as possible.
  631. */
  632. acpi_boot_ec_enable();
  633. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  634. /* Initialize sleep structures */
  635. acpi_sleep_init();
  636. /*
  637. * Get the system interrupt model and evaluate \_PIC.
  638. */
  639. result = acpi_bus_init_irq();
  640. if (result)
  641. goto error1;
  642. /*
  643. * Register the for all standard device notifications.
  644. */
  645. status =
  646. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  647. &acpi_bus_notify, NULL);
  648. if (ACPI_FAILURE(status)) {
  649. printk(KERN_ERR PREFIX
  650. "Unable to register for device notifications\n");
  651. goto error1;
  652. }
  653. /*
  654. * Create the top ACPI proc directory
  655. */
  656. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  657. return 0;
  658. /* Mimic structured exception handling */
  659. error1:
  660. acpi_terminate();
  661. return -ENODEV;
  662. }
  663. struct kobject *acpi_kobj;
  664. EXPORT_SYMBOL_GPL(acpi_kobj);
  665. static int __init acpi_init(void)
  666. {
  667. int result;
  668. if (acpi_disabled) {
  669. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  670. return -ENODEV;
  671. }
  672. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  673. if (!acpi_kobj) {
  674. printk(KERN_WARNING "%s: kset create error\n", __func__);
  675. acpi_kobj = NULL;
  676. }
  677. init_acpi_device_notify();
  678. result = acpi_bus_init();
  679. if (result) {
  680. disable_acpi();
  681. return result;
  682. }
  683. pci_mmcfg_late_init();
  684. acpi_scan_init();
  685. acpi_ec_init();
  686. acpi_debugfs_init();
  687. acpi_sleep_proc_init();
  688. acpi_wakeup_device_init();
  689. return 0;
  690. }
  691. subsys_initcall(acpi_init);