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. 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_DEBUG_PRINT((ACPI_DB_WARN, "No context for object [%p]\n",
  62. handle));
  63. return_VALUE(-ENODEV);
  64. }
  65. return_VALUE(0);
  66. }
  67. EXPORT_SYMBOL(acpi_bus_get_device);
  68. int acpi_bus_get_status(struct acpi_device *device)
  69. {
  70. acpi_status status = AE_OK;
  71. unsigned long sta = 0;
  72. ACPI_FUNCTION_TRACE("acpi_bus_get_status");
  73. if (!device)
  74. return_VALUE(-EINVAL);
  75. /*
  76. * Evaluate _STA if present.
  77. */
  78. if (device->flags.dynamic_status) {
  79. status =
  80. acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
  81. if (ACPI_FAILURE(status))
  82. return_VALUE(-ENODEV);
  83. STRUCT_TO_INT(device->status) = (int)sta;
  84. }
  85. /*
  86. * Otherwise we assume the status of our parent (unless we don't
  87. * have one, in which case status is implied).
  88. */
  89. else if (device->parent)
  90. device->status = device->parent->status;
  91. else
  92. STRUCT_TO_INT(device->status) = 0x0F;
  93. if (device->status.functional && !device->status.present) {
  94. printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: "
  95. "functional but not present; setting present\n",
  96. device->pnp.bus_id, (u32) STRUCT_TO_INT(device->status));
  97. device->status.present = 1;
  98. }
  99. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
  100. device->pnp.bus_id,
  101. (u32) STRUCT_TO_INT(device->status)));
  102. return_VALUE(0);
  103. }
  104. EXPORT_SYMBOL(acpi_bus_get_status);
  105. /* --------------------------------------------------------------------------
  106. Power Management
  107. -------------------------------------------------------------------------- */
  108. int acpi_bus_get_power(acpi_handle handle, int *state)
  109. {
  110. int result = 0;
  111. acpi_status status = 0;
  112. struct acpi_device *device = NULL;
  113. unsigned long psc = 0;
  114. ACPI_FUNCTION_TRACE("acpi_bus_get_power");
  115. result = acpi_bus_get_device(handle, &device);
  116. if (result)
  117. return_VALUE(result);
  118. *state = ACPI_STATE_UNKNOWN;
  119. if (!device->flags.power_manageable) {
  120. /* TBD: Non-recursive algorithm for walking up hierarchy */
  121. if (device->parent)
  122. *state = device->parent->power.state;
  123. else
  124. *state = ACPI_STATE_D0;
  125. } else {
  126. /*
  127. * Get the device's power state either directly (via _PSC) or
  128. * indirectly (via power resources).
  129. */
  130. if (device->power.flags.explicit_get) {
  131. status = acpi_evaluate_integer(device->handle, "_PSC",
  132. NULL, &psc);
  133. if (ACPI_FAILURE(status))
  134. return_VALUE(-ENODEV);
  135. device->power.state = (int)psc;
  136. } else if (device->power.flags.power_resources) {
  137. result = acpi_power_get_inferred_state(device);
  138. if (result)
  139. return_VALUE(result);
  140. }
  141. *state = device->power.state;
  142. }
  143. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
  144. device->pnp.bus_id, device->power.state));
  145. return_VALUE(0);
  146. }
  147. EXPORT_SYMBOL(acpi_bus_get_power);
  148. int acpi_bus_set_power(acpi_handle handle, int state)
  149. {
  150. int result = 0;
  151. acpi_status status = AE_OK;
  152. struct acpi_device *device = NULL;
  153. char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
  154. ACPI_FUNCTION_TRACE("acpi_bus_set_power");
  155. result = acpi_bus_get_device(handle, &device);
  156. if (result)
  157. return_VALUE(result);
  158. if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
  159. return_VALUE(-EINVAL);
  160. /* Make sure this is a valid target state */
  161. if (!device->flags.power_manageable) {
  162. ACPI_DEBUG_PRINT((ACPI_DB_WARN,
  163. "Device is not power manageable\n"));
  164. return_VALUE(-ENODEV);
  165. }
  166. /*
  167. * Get device's current power state if it's unknown
  168. * This means device power state isn't initialized or previous setting failed
  169. */
  170. if (device->power.state == ACPI_STATE_UNKNOWN)
  171. acpi_bus_get_power(device->handle, &device->power.state);
  172. if (state == device->power.state) {
  173. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
  174. state));
  175. return_VALUE(0);
  176. }
  177. if (!device->power.states[state].flags.valid) {
  178. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device does not support D%d\n",
  179. state));
  180. return_VALUE(-ENODEV);
  181. }
  182. if (device->parent && (state < device->parent->power.state)) {
  183. ACPI_DEBUG_PRINT((ACPI_DB_WARN,
  184. "Cannot set device to a higher-powered state than parent\n"));
  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_DEBUG_PRINT((ACPI_DB_WARN,
  226. "Error transitioning device [%s] to D%d\n",
  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_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PIC\n"));
  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. /* enable workarounds, unless strict ACPI spec. compliance */
  483. if (!acpi_strict)
  484. acpi_gbl_enable_interpreter_slack = TRUE;
  485. status = acpi_initialize_subsystem();
  486. if (ACPI_FAILURE(status)) {
  487. printk(KERN_ERR PREFIX
  488. "Unable to initialize the ACPI Interpreter\n");
  489. goto error0;
  490. }
  491. status = acpi_load_tables();
  492. if (ACPI_FAILURE(status)) {
  493. printk(KERN_ERR PREFIX
  494. "Unable to load the System Description Tables\n");
  495. goto error0;
  496. }
  497. /*
  498. * Get a separate copy of the FADT for use by other drivers.
  499. */
  500. status = acpi_get_table(ACPI_TABLE_FADT, 1, &buffer);
  501. if (ACPI_FAILURE(status)) {
  502. printk(KERN_ERR PREFIX "Unable to get the FADT\n");
  503. goto error0;
  504. }
  505. #ifdef CONFIG_X86
  506. if (!acpi_ioapic) {
  507. extern acpi_interrupt_flags acpi_sci_flags;
  508. /* compatible (0) means level (3) */
  509. if (acpi_sci_flags.trigger == 0)
  510. acpi_sci_flags.trigger = 3;
  511. /* Set PIC-mode SCI trigger type */
  512. acpi_pic_sci_set_trigger(acpi_fadt.sci_int,
  513. acpi_sci_flags.trigger);
  514. } else {
  515. extern int acpi_sci_override_gsi;
  516. /*
  517. * now that acpi_fadt is initialized,
  518. * update it with result from INT_SRC_OVR parsing
  519. */
  520. acpi_fadt.sci_int = acpi_sci_override_gsi;
  521. }
  522. #endif
  523. status =
  524. acpi_enable_subsystem(~
  525. (ACPI_NO_HARDWARE_INIT |
  526. ACPI_NO_ACPI_ENABLE));
  527. if (ACPI_FAILURE(status)) {
  528. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  529. goto error0;
  530. }
  531. return_VOID;
  532. error0:
  533. disable_acpi();
  534. return_VOID;
  535. }
  536. static int __init acpi_bus_init(void)
  537. {
  538. int result = 0;
  539. acpi_status status = AE_OK;
  540. extern acpi_status acpi_os_initialize1(void);
  541. ACPI_FUNCTION_TRACE("acpi_bus_init");
  542. status = acpi_os_initialize1();
  543. status =
  544. acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  545. if (ACPI_FAILURE(status)) {
  546. printk(KERN_ERR PREFIX
  547. "Unable to start the ACPI Interpreter\n");
  548. goto error1;
  549. }
  550. if (ACPI_FAILURE(status)) {
  551. printk(KERN_ERR PREFIX
  552. "Unable to initialize ACPI OS objects\n");
  553. goto error1;
  554. }
  555. #ifdef CONFIG_ACPI_EC
  556. /*
  557. * ACPI 2.0 requires the EC driver to be loaded and work before
  558. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  559. * is called).
  560. *
  561. * This is accomplished by looking for the ECDT table, and getting
  562. * the EC parameters out of that.
  563. */
  564. status = acpi_ec_ecdt_probe();
  565. /* Ignore result. Not having an ECDT is not fatal. */
  566. #endif
  567. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  568. if (ACPI_FAILURE(status)) {
  569. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  570. goto error1;
  571. }
  572. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  573. /*
  574. * Get the system interrupt model and evaluate \_PIC.
  575. */
  576. result = acpi_bus_init_irq();
  577. if (result)
  578. goto error1;
  579. /*
  580. * Register the for all standard device notifications.
  581. */
  582. status =
  583. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  584. &acpi_bus_notify, NULL);
  585. if (ACPI_FAILURE(status)) {
  586. printk(KERN_ERR PREFIX
  587. "Unable to register for device notifications\n");
  588. goto error1;
  589. }
  590. /*
  591. * Create the top ACPI proc directory
  592. */
  593. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  594. return_VALUE(0);
  595. /* Mimic structured exception handling */
  596. error1:
  597. acpi_terminate();
  598. return_VALUE(-ENODEV);
  599. }
  600. decl_subsys(acpi, NULL, NULL);
  601. static int __init acpi_init(void)
  602. {
  603. int result = 0;
  604. ACPI_FUNCTION_TRACE("acpi_init");
  605. printk(KERN_INFO PREFIX "Subsystem revision %08x\n", ACPI_CA_VERSION);
  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);