bus.c 19 KB

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