bus.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. #ifdef CONFIG_X86
  35. #include <asm/mpspec.h>
  36. #endif
  37. #include <linux/pci.h>
  38. #include <acpi/acpi_bus.h>
  39. #include <acpi/acpi_drivers.h>
  40. #define _COMPONENT ACPI_BUS_COMPONENT
  41. ACPI_MODULE_NAME("bus");
  42. struct acpi_device *acpi_root;
  43. struct proc_dir_entry *acpi_root_dir;
  44. EXPORT_SYMBOL(acpi_root_dir);
  45. #define STRUCT_TO_INT(s) (*((int*)&s))
  46. /* --------------------------------------------------------------------------
  47. Device Management
  48. -------------------------------------------------------------------------- */
  49. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
  50. {
  51. acpi_status status = AE_OK;
  52. if (!device)
  53. return -EINVAL;
  54. /* TBD: Support fixed-feature devices */
  55. status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
  56. if (ACPI_FAILURE(status) || !*device) {
  57. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  58. handle));
  59. return -ENODEV;
  60. }
  61. return 0;
  62. }
  63. EXPORT_SYMBOL(acpi_bus_get_device);
  64. int acpi_bus_get_status(struct acpi_device *device)
  65. {
  66. acpi_status status = AE_OK;
  67. unsigned long sta = 0;
  68. if (!device)
  69. return -EINVAL;
  70. /*
  71. * Evaluate _STA if present.
  72. */
  73. if (device->flags.dynamic_status) {
  74. status =
  75. acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
  76. if (ACPI_FAILURE(status))
  77. return -ENODEV;
  78. STRUCT_TO_INT(device->status) = (int)sta;
  79. }
  80. /*
  81. * Otherwise we assume the status of our parent (unless we don't
  82. * have one, in which case status is implied).
  83. */
  84. else if (device->parent)
  85. device->status = device->parent->status;
  86. else
  87. STRUCT_TO_INT(device->status) =
  88. ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
  89. ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
  90. if (device->status.functional && !device->status.present) {
  91. printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: "
  92. "functional but not present; setting present\n",
  93. device->pnp.bus_id, (u32) STRUCT_TO_INT(device->status));
  94. device->status.present = 1;
  95. }
  96. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
  97. device->pnp.bus_id,
  98. (u32) STRUCT_TO_INT(device->status)));
  99. return 0;
  100. }
  101. EXPORT_SYMBOL(acpi_bus_get_status);
  102. void acpi_bus_private_data_handler(acpi_handle handle,
  103. u32 function, void *context)
  104. {
  105. return;
  106. }
  107. EXPORT_SYMBOL(acpi_bus_private_data_handler);
  108. int acpi_bus_get_private_data(acpi_handle handle, void **data)
  109. {
  110. acpi_status status = AE_OK;
  111. if (!*data)
  112. return -EINVAL;
  113. status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
  114. if (ACPI_FAILURE(status) || !*data) {
  115. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  116. handle));
  117. return -ENODEV;
  118. }
  119. return 0;
  120. }
  121. EXPORT_SYMBOL(acpi_bus_get_private_data);
  122. /* --------------------------------------------------------------------------
  123. Power Management
  124. -------------------------------------------------------------------------- */
  125. int acpi_bus_get_power(acpi_handle handle, int *state)
  126. {
  127. int result = 0;
  128. acpi_status status = 0;
  129. struct acpi_device *device = NULL;
  130. unsigned long psc = 0;
  131. result = acpi_bus_get_device(handle, &device);
  132. if (result)
  133. return result;
  134. *state = ACPI_STATE_UNKNOWN;
  135. if (!device->flags.power_manageable) {
  136. /* TBD: Non-recursive algorithm for walking up hierarchy */
  137. if (device->parent)
  138. *state = device->parent->power.state;
  139. else
  140. *state = ACPI_STATE_D0;
  141. } else {
  142. /*
  143. * Get the device's power state either directly (via _PSC) or
  144. * indirectly (via power resources).
  145. */
  146. if (device->power.flags.explicit_get) {
  147. status = acpi_evaluate_integer(device->handle, "_PSC",
  148. NULL, &psc);
  149. if (ACPI_FAILURE(status))
  150. return -ENODEV;
  151. device->power.state = (int)psc;
  152. } else if (device->power.flags.power_resources) {
  153. result = acpi_power_get_inferred_state(device);
  154. if (result)
  155. return result;
  156. }
  157. *state = device->power.state;
  158. }
  159. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
  160. device->pnp.bus_id, device->power.state));
  161. return 0;
  162. }
  163. EXPORT_SYMBOL(acpi_bus_get_power);
  164. int acpi_bus_set_power(acpi_handle handle, int state)
  165. {
  166. int result = 0;
  167. acpi_status status = AE_OK;
  168. struct acpi_device *device = NULL;
  169. char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
  170. result = acpi_bus_get_device(handle, &device);
  171. if (result)
  172. return result;
  173. if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
  174. return -EINVAL;
  175. /* Make sure this is a valid target state */
  176. if (!device->flags.power_manageable) {
  177. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
  178. kobject_name(&device->dev.kobj)));
  179. return -ENODEV;
  180. }
  181. /*
  182. * Get device's current power state
  183. */
  184. acpi_bus_get_power(device->handle, &device->power.state);
  185. if ((state == device->power.state) && !device->flags.force_power_state) {
  186. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
  187. state));
  188. return 0;
  189. }
  190. if (!device->power.states[state].flags.valid) {
  191. printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
  192. return -ENODEV;
  193. }
  194. if (device->parent && (state < device->parent->power.state)) {
  195. printk(KERN_WARNING PREFIX
  196. "Cannot set device to a higher-powered"
  197. " state than parent\n");
  198. return -ENODEV;
  199. }
  200. /*
  201. * Transition Power
  202. * ----------------
  203. * On transitions to a high-powered state we first apply power (via
  204. * power resources) then evalute _PSx. Conversly for transitions to
  205. * a lower-powered state.
  206. */
  207. if (state < device->power.state) {
  208. if (device->power.flags.power_resources) {
  209. result = acpi_power_transition(device, state);
  210. if (result)
  211. goto end;
  212. }
  213. if (device->power.states[state].flags.explicit_set) {
  214. status = acpi_evaluate_object(device->handle,
  215. object_name, NULL, NULL);
  216. if (ACPI_FAILURE(status)) {
  217. result = -ENODEV;
  218. goto end;
  219. }
  220. }
  221. } else {
  222. if (device->power.states[state].flags.explicit_set) {
  223. status = acpi_evaluate_object(device->handle,
  224. object_name, NULL, NULL);
  225. if (ACPI_FAILURE(status)) {
  226. result = -ENODEV;
  227. goto end;
  228. }
  229. }
  230. if (device->power.flags.power_resources) {
  231. result = acpi_power_transition(device, state);
  232. if (result)
  233. goto end;
  234. }
  235. }
  236. end:
  237. if (result)
  238. printk(KERN_WARNING PREFIX
  239. "Transitioning device [%s] to D%d\n",
  240. device->pnp.bus_id, state);
  241. else {
  242. device->power.state = state;
  243. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  244. "Device [%s] transitioned to D%d\n",
  245. device->pnp.bus_id, state));
  246. }
  247. return result;
  248. }
  249. EXPORT_SYMBOL(acpi_bus_set_power);
  250. bool acpi_bus_power_manageable(acpi_handle handle)
  251. {
  252. struct acpi_device *device;
  253. int result;
  254. result = acpi_bus_get_device(handle, &device);
  255. return result ? false : device->flags.power_manageable;
  256. }
  257. EXPORT_SYMBOL(acpi_bus_power_manageable);
  258. bool acpi_bus_can_wakeup(acpi_handle handle)
  259. {
  260. struct acpi_device *device;
  261. int result;
  262. result = acpi_bus_get_device(handle, &device);
  263. return result ? false : device->wakeup.flags.valid;
  264. }
  265. EXPORT_SYMBOL(acpi_bus_can_wakeup);
  266. /* --------------------------------------------------------------------------
  267. Event Management
  268. -------------------------------------------------------------------------- */
  269. #ifdef CONFIG_ACPI_PROC_EVENT
  270. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  271. LIST_HEAD(acpi_bus_event_list);
  272. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  273. extern int event_is_open;
  274. int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
  275. {
  276. struct acpi_bus_event *event;
  277. unsigned long flags = 0;
  278. /* drop event on the floor if no one's listening */
  279. if (!event_is_open)
  280. return 0;
  281. event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
  282. if (!event)
  283. return -ENOMEM;
  284. strcpy(event->device_class, device_class);
  285. strcpy(event->bus_id, bus_id);
  286. event->type = type;
  287. event->data = data;
  288. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  289. list_add_tail(&event->node, &acpi_bus_event_list);
  290. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  291. wake_up_interruptible(&acpi_bus_event_queue);
  292. return 0;
  293. }
  294. EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
  295. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  296. {
  297. if (!device)
  298. return -EINVAL;
  299. return acpi_bus_generate_proc_event4(device->pnp.device_class,
  300. device->pnp.bus_id, type, data);
  301. }
  302. EXPORT_SYMBOL(acpi_bus_generate_proc_event);
  303. int acpi_bus_receive_event(struct acpi_bus_event *event)
  304. {
  305. unsigned long flags = 0;
  306. struct acpi_bus_event *entry = NULL;
  307. DECLARE_WAITQUEUE(wait, current);
  308. if (!event)
  309. return -EINVAL;
  310. if (list_empty(&acpi_bus_event_list)) {
  311. set_current_state(TASK_INTERRUPTIBLE);
  312. add_wait_queue(&acpi_bus_event_queue, &wait);
  313. if (list_empty(&acpi_bus_event_list))
  314. schedule();
  315. remove_wait_queue(&acpi_bus_event_queue, &wait);
  316. set_current_state(TASK_RUNNING);
  317. if (signal_pending(current))
  318. return -ERESTARTSYS;
  319. }
  320. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  321. if (!list_empty(&acpi_bus_event_list)) {
  322. entry = list_entry(acpi_bus_event_list.next,
  323. struct acpi_bus_event, node);
  324. list_del(&entry->node);
  325. }
  326. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  327. if (!entry)
  328. return -ENODEV;
  329. memcpy(event, entry, sizeof(struct acpi_bus_event));
  330. kfree(entry);
  331. return 0;
  332. }
  333. #endif /* CONFIG_ACPI_PROC_EVENT */
  334. /* --------------------------------------------------------------------------
  335. Notification Handling
  336. -------------------------------------------------------------------------- */
  337. static int
  338. acpi_bus_check_device(struct acpi_device *device, int *status_changed)
  339. {
  340. acpi_status status = 0;
  341. struct acpi_device_status old_status;
  342. if (!device)
  343. return -EINVAL;
  344. if (status_changed)
  345. *status_changed = 0;
  346. old_status = device->status;
  347. /*
  348. * Make sure this device's parent is present before we go about
  349. * messing with the device.
  350. */
  351. if (device->parent && !device->parent->status.present) {
  352. device->status = device->parent->status;
  353. if (STRUCT_TO_INT(old_status) != STRUCT_TO_INT(device->status)) {
  354. if (status_changed)
  355. *status_changed = 1;
  356. }
  357. return 0;
  358. }
  359. status = acpi_bus_get_status(device);
  360. if (ACPI_FAILURE(status))
  361. return -ENODEV;
  362. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  363. return 0;
  364. if (status_changed)
  365. *status_changed = 1;
  366. /*
  367. * Device Insertion/Removal
  368. */
  369. if ((device->status.present) && !(old_status.present)) {
  370. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  371. /* TBD: Handle device insertion */
  372. } else if (!(device->status.present) && (old_status.present)) {
  373. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  374. /* TBD: Handle device removal */
  375. }
  376. return 0;
  377. }
  378. static int acpi_bus_check_scope(struct acpi_device *device)
  379. {
  380. int result = 0;
  381. int status_changed = 0;
  382. if (!device)
  383. return -EINVAL;
  384. /* Status Change? */
  385. result = acpi_bus_check_device(device, &status_changed);
  386. if (result)
  387. return result;
  388. if (!status_changed)
  389. return 0;
  390. /*
  391. * TBD: Enumerate child devices within this device's scope and
  392. * run acpi_bus_check_device()'s on them.
  393. */
  394. return 0;
  395. }
  396. static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
  397. int register_acpi_bus_notifier(struct notifier_block *nb)
  398. {
  399. return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
  400. }
  401. EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
  402. void unregister_acpi_bus_notifier(struct notifier_block *nb)
  403. {
  404. blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
  405. }
  406. EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
  407. /**
  408. * acpi_bus_notify
  409. * ---------------
  410. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  411. */
  412. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  413. {
  414. int result = 0;
  415. struct acpi_device *device = NULL;
  416. blocking_notifier_call_chain(&acpi_bus_notify_list,
  417. type, (void *)handle);
  418. if (acpi_bus_get_device(handle, &device))
  419. return;
  420. switch (type) {
  421. case ACPI_NOTIFY_BUS_CHECK:
  422. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  423. "Received BUS CHECK notification for device [%s]\n",
  424. device->pnp.bus_id));
  425. result = acpi_bus_check_scope(device);
  426. /*
  427. * TBD: We'll need to outsource certain events to non-ACPI
  428. * drivers via the device manager (device.c).
  429. */
  430. break;
  431. case ACPI_NOTIFY_DEVICE_CHECK:
  432. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  433. "Received DEVICE CHECK notification for device [%s]\n",
  434. device->pnp.bus_id));
  435. result = acpi_bus_check_device(device, NULL);
  436. /*
  437. * TBD: We'll need to outsource certain events to non-ACPI
  438. * drivers via the device manager (device.c).
  439. */
  440. break;
  441. case ACPI_NOTIFY_DEVICE_WAKE:
  442. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  443. "Received DEVICE WAKE notification for device [%s]\n",
  444. device->pnp.bus_id));
  445. /* TBD */
  446. break;
  447. case ACPI_NOTIFY_EJECT_REQUEST:
  448. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  449. "Received EJECT REQUEST notification for device [%s]\n",
  450. device->pnp.bus_id));
  451. /* TBD */
  452. break;
  453. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  454. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  455. "Received DEVICE CHECK LIGHT notification for device [%s]\n",
  456. device->pnp.bus_id));
  457. /* TBD: Exactly what does 'light' mean? */
  458. break;
  459. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  460. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  461. "Received FREQUENCY MISMATCH notification for device [%s]\n",
  462. device->pnp.bus_id));
  463. /* TBD */
  464. break;
  465. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  466. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  467. "Received BUS MODE MISMATCH notification for device [%s]\n",
  468. device->pnp.bus_id));
  469. /* TBD */
  470. break;
  471. case ACPI_NOTIFY_POWER_FAULT:
  472. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  473. "Received POWER FAULT notification for device [%s]\n",
  474. device->pnp.bus_id));
  475. /* TBD */
  476. break;
  477. default:
  478. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  479. "Received unknown/unsupported notification [%08x]\n",
  480. type));
  481. break;
  482. }
  483. return;
  484. }
  485. /* --------------------------------------------------------------------------
  486. Initialization/Cleanup
  487. -------------------------------------------------------------------------- */
  488. static int __init acpi_bus_init_irq(void)
  489. {
  490. acpi_status status = AE_OK;
  491. union acpi_object arg = { ACPI_TYPE_INTEGER };
  492. struct acpi_object_list arg_list = { 1, &arg };
  493. char *message = NULL;
  494. /*
  495. * Let the system know what interrupt model we are using by
  496. * evaluating the \_PIC object, if exists.
  497. */
  498. switch (acpi_irq_model) {
  499. case ACPI_IRQ_MODEL_PIC:
  500. message = "PIC";
  501. break;
  502. case ACPI_IRQ_MODEL_IOAPIC:
  503. message = "IOAPIC";
  504. break;
  505. case ACPI_IRQ_MODEL_IOSAPIC:
  506. message = "IOSAPIC";
  507. break;
  508. case ACPI_IRQ_MODEL_PLATFORM:
  509. message = "platform specific model";
  510. break;
  511. default:
  512. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  513. return -ENODEV;
  514. }
  515. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  516. arg.integer.value = acpi_irq_model;
  517. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  518. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  519. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  520. return -ENODEV;
  521. }
  522. return 0;
  523. }
  524. u8 acpi_gbl_permanent_mmap;
  525. void __init acpi_early_init(void)
  526. {
  527. acpi_status status = AE_OK;
  528. if (acpi_disabled)
  529. return;
  530. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  531. /* enable workarounds, unless strict ACPI spec. compliance */
  532. if (!acpi_strict)
  533. acpi_gbl_enable_interpreter_slack = TRUE;
  534. acpi_gbl_permanent_mmap = 1;
  535. status = acpi_reallocate_root_table();
  536. if (ACPI_FAILURE(status)) {
  537. printk(KERN_ERR PREFIX
  538. "Unable to reallocate ACPI tables\n");
  539. goto error0;
  540. }
  541. status = acpi_initialize_subsystem();
  542. if (ACPI_FAILURE(status)) {
  543. printk(KERN_ERR PREFIX
  544. "Unable to initialize the ACPI Interpreter\n");
  545. goto error0;
  546. }
  547. status = acpi_load_tables();
  548. if (ACPI_FAILURE(status)) {
  549. printk(KERN_ERR PREFIX
  550. "Unable to load the System Description Tables\n");
  551. goto error0;
  552. }
  553. #ifdef CONFIG_X86
  554. if (!acpi_ioapic) {
  555. /* compatible (0) means level (3) */
  556. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  557. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  558. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  559. }
  560. /* Set PIC-mode SCI trigger type */
  561. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  562. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  563. } else {
  564. /*
  565. * now that acpi_gbl_FADT is initialized,
  566. * update it with result from INT_SRC_OVR parsing
  567. */
  568. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  569. }
  570. #endif
  571. status =
  572. acpi_enable_subsystem(~
  573. (ACPI_NO_HARDWARE_INIT |
  574. ACPI_NO_ACPI_ENABLE));
  575. if (ACPI_FAILURE(status)) {
  576. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  577. goto error0;
  578. }
  579. return;
  580. error0:
  581. disable_acpi();
  582. return;
  583. }
  584. static int __init acpi_bus_init(void)
  585. {
  586. int result = 0;
  587. acpi_status status = AE_OK;
  588. extern acpi_status acpi_os_initialize1(void);
  589. status = acpi_os_initialize1();
  590. status =
  591. acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  592. if (ACPI_FAILURE(status)) {
  593. printk(KERN_ERR PREFIX
  594. "Unable to start the ACPI Interpreter\n");
  595. goto error1;
  596. }
  597. if (ACPI_FAILURE(status)) {
  598. printk(KERN_ERR PREFIX
  599. "Unable to initialize ACPI OS objects\n");
  600. goto error1;
  601. }
  602. #ifdef CONFIG_ACPI_EC
  603. /*
  604. * ACPI 2.0 requires the EC driver to be loaded and work before
  605. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  606. * is called).
  607. *
  608. * This is accomplished by looking for the ECDT table, and getting
  609. * the EC parameters out of that.
  610. */
  611. status = acpi_ec_ecdt_probe();
  612. /* Ignore result. Not having an ECDT is not fatal. */
  613. #endif
  614. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  615. if (ACPI_FAILURE(status)) {
  616. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  617. goto error1;
  618. }
  619. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  620. /* Initialize sleep structures */
  621. acpi_sleep_init();
  622. /*
  623. * Get the system interrupt model and evaluate \_PIC.
  624. */
  625. result = acpi_bus_init_irq();
  626. if (result)
  627. goto error1;
  628. /*
  629. * Register the for all standard device notifications.
  630. */
  631. status =
  632. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  633. &acpi_bus_notify, NULL);
  634. if (ACPI_FAILURE(status)) {
  635. printk(KERN_ERR PREFIX
  636. "Unable to register for device notifications\n");
  637. goto error1;
  638. }
  639. /*
  640. * Create the top ACPI proc directory
  641. */
  642. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  643. return 0;
  644. /* Mimic structured exception handling */
  645. error1:
  646. acpi_terminate();
  647. return -ENODEV;
  648. }
  649. struct kobject *acpi_kobj;
  650. static int __init acpi_init(void)
  651. {
  652. int result = 0;
  653. if (acpi_disabled) {
  654. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  655. return -ENODEV;
  656. }
  657. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  658. if (!acpi_kobj) {
  659. printk(KERN_WARNING "%s: kset create error\n", __func__);
  660. acpi_kobj = NULL;
  661. }
  662. result = acpi_bus_init();
  663. if (!result) {
  664. pci_mmcfg_late_init();
  665. if (!(pm_flags & PM_APM))
  666. pm_flags |= PM_ACPI;
  667. else {
  668. printk(KERN_INFO PREFIX
  669. "APM is already active, exiting\n");
  670. disable_acpi();
  671. result = -ENODEV;
  672. }
  673. } else
  674. disable_acpi();
  675. return result;
  676. }
  677. subsys_initcall(acpi_init);