bus.c 19 KB

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