bus.c 19 KB

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