bus.c 19 KB

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