bus.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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/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("bus");
  40. #ifdef CONFIG_X86
  41. extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger);
  42. #endif
  43. struct acpi_device *acpi_root;
  44. struct proc_dir_entry *acpi_root_dir;
  45. EXPORT_SYMBOL(acpi_root_dir);
  46. #define STRUCT_TO_INT(s) (*((int*)&s))
  47. /* --------------------------------------------------------------------------
  48. Device Management
  49. -------------------------------------------------------------------------- */
  50. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
  51. {
  52. acpi_status status = AE_OK;
  53. if (!device)
  54. return -EINVAL;
  55. /* TBD: Support fixed-feature devices */
  56. status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
  57. if (ACPI_FAILURE(status) || !*device) {
  58. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  59. handle));
  60. return -ENODEV;
  61. }
  62. return 0;
  63. }
  64. EXPORT_SYMBOL(acpi_bus_get_device);
  65. int acpi_bus_get_status(struct acpi_device *device)
  66. {
  67. acpi_status status = AE_OK;
  68. unsigned long sta = 0;
  69. if (!device)
  70. return -EINVAL;
  71. /*
  72. * Evaluate _STA if present.
  73. */
  74. if (device->flags.dynamic_status) {
  75. status =
  76. acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
  77. if (ACPI_FAILURE(status))
  78. return -ENODEV;
  79. STRUCT_TO_INT(device->status) = (int)sta;
  80. }
  81. /*
  82. * Otherwise we assume the status of our parent (unless we don't
  83. * have one, in which case status is implied).
  84. */
  85. else if (device->parent)
  86. device->status = device->parent->status;
  87. else
  88. STRUCT_TO_INT(device->status) =
  89. ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
  90. ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
  91. if (device->status.functional && !device->status.present) {
  92. printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: "
  93. "functional but not present; setting present\n",
  94. device->pnp.bus_id, (u32) STRUCT_TO_INT(device->status));
  95. device->status.present = 1;
  96. }
  97. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
  98. device->pnp.bus_id,
  99. (u32) STRUCT_TO_INT(device->status)));
  100. return 0;
  101. }
  102. EXPORT_SYMBOL(acpi_bus_get_status);
  103. /* --------------------------------------------------------------------------
  104. Power Management
  105. -------------------------------------------------------------------------- */
  106. int acpi_bus_get_power(acpi_handle handle, int *state)
  107. {
  108. int result = 0;
  109. acpi_status status = 0;
  110. struct acpi_device *device = NULL;
  111. unsigned long psc = 0;
  112. result = acpi_bus_get_device(handle, &device);
  113. if (result)
  114. return result;
  115. *state = ACPI_STATE_UNKNOWN;
  116. if (!device->flags.power_manageable) {
  117. /* TBD: Non-recursive algorithm for walking up hierarchy */
  118. if (device->parent)
  119. *state = device->parent->power.state;
  120. else
  121. *state = ACPI_STATE_D0;
  122. } else {
  123. /*
  124. * Get the device's power state either directly (via _PSC) or
  125. * indirectly (via power resources).
  126. */
  127. if (device->power.flags.explicit_get) {
  128. status = acpi_evaluate_integer(device->handle, "_PSC",
  129. NULL, &psc);
  130. if (ACPI_FAILURE(status))
  131. return -ENODEV;
  132. device->power.state = (int)psc;
  133. } else if (device->power.flags.power_resources) {
  134. result = acpi_power_get_inferred_state(device);
  135. if (result)
  136. return result;
  137. }
  138. *state = device->power.state;
  139. }
  140. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
  141. device->pnp.bus_id, device->power.state));
  142. return 0;
  143. }
  144. EXPORT_SYMBOL(acpi_bus_get_power);
  145. int acpi_bus_set_power(acpi_handle handle, int state)
  146. {
  147. int result = 0;
  148. acpi_status status = AE_OK;
  149. struct acpi_device *device = NULL;
  150. char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
  151. result = acpi_bus_get_device(handle, &device);
  152. if (result)
  153. return result;
  154. if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
  155. return -EINVAL;
  156. /* Make sure this is a valid target state */
  157. if (!device->flags.power_manageable) {
  158. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
  159. kobject_name(&device->dev.kobj)));
  160. return -ENODEV;
  161. }
  162. /*
  163. * Get device's current power state
  164. */
  165. acpi_bus_get_power(device->handle, &device->power.state);
  166. if ((state == device->power.state) && !device->flags.force_power_state) {
  167. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
  168. state));
  169. return 0;
  170. }
  171. if (!device->power.states[state].flags.valid) {
  172. printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
  173. return -ENODEV;
  174. }
  175. if (device->parent && (state < device->parent->power.state)) {
  176. printk(KERN_WARNING PREFIX
  177. "Cannot set device to a higher-powered"
  178. " state than parent\n");
  179. return -ENODEV;
  180. }
  181. /*
  182. * Transition Power
  183. * ----------------
  184. * On transitions to a high-powered state we first apply power (via
  185. * power resources) then evalute _PSx. Conversly for transitions to
  186. * a lower-powered state.
  187. */
  188. if (state < device->power.state) {
  189. if (device->power.flags.power_resources) {
  190. result = acpi_power_transition(device, state);
  191. if (result)
  192. goto end;
  193. }
  194. if (device->power.states[state].flags.explicit_set) {
  195. status = acpi_evaluate_object(device->handle,
  196. object_name, NULL, NULL);
  197. if (ACPI_FAILURE(status)) {
  198. result = -ENODEV;
  199. goto end;
  200. }
  201. }
  202. } else {
  203. if (device->power.states[state].flags.explicit_set) {
  204. status = acpi_evaluate_object(device->handle,
  205. object_name, NULL, NULL);
  206. if (ACPI_FAILURE(status)) {
  207. result = -ENODEV;
  208. goto end;
  209. }
  210. }
  211. if (device->power.flags.power_resources) {
  212. result = acpi_power_transition(device, state);
  213. if (result)
  214. goto end;
  215. }
  216. }
  217. end:
  218. if (result)
  219. printk(KERN_WARNING PREFIX
  220. "Transitioning device [%s] to D%d\n",
  221. device->pnp.bus_id, state);
  222. else {
  223. device->power.state = state;
  224. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  225. "Device [%s] transitioned to D%d\n",
  226. device->pnp.bus_id, state));
  227. }
  228. return result;
  229. }
  230. EXPORT_SYMBOL(acpi_bus_set_power);
  231. /* --------------------------------------------------------------------------
  232. Event Management
  233. -------------------------------------------------------------------------- */
  234. #ifdef CONFIG_ACPI_PROC_EVENT
  235. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  236. LIST_HEAD(acpi_bus_event_list);
  237. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  238. extern int event_is_open;
  239. int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
  240. {
  241. struct acpi_bus_event *event;
  242. unsigned long flags = 0;
  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_class);
  250. strcpy(event->bus_id, 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_GPL(acpi_bus_generate_proc_event4);
  260. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  261. {
  262. if (!device)
  263. return -EINVAL;
  264. return acpi_bus_generate_proc_event4(device->pnp.device_class,
  265. device->pnp.bus_id, type, data);
  266. }
  267. EXPORT_SYMBOL(acpi_bus_generate_proc_event);
  268. int acpi_bus_receive_event(struct acpi_bus_event *event)
  269. {
  270. unsigned long flags = 0;
  271. struct acpi_bus_event *entry = NULL;
  272. DECLARE_WAITQUEUE(wait, current);
  273. if (!event)
  274. return -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 -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 -ENODEV;
  293. memcpy(event, entry, sizeof(struct acpi_bus_event));
  294. kfree(entry);
  295. return 0;
  296. }
  297. EXPORT_SYMBOL(acpi_bus_receive_event);
  298. #endif /* CONFIG_ACPI_PROC_EVENT */
  299. /* --------------------------------------------------------------------------
  300. Notification Handling
  301. -------------------------------------------------------------------------- */
  302. static int
  303. acpi_bus_check_device(struct acpi_device *device, int *status_changed)
  304. {
  305. acpi_status status = 0;
  306. struct acpi_device_status old_status;
  307. if (!device)
  308. return -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 0;
  323. }
  324. status = acpi_bus_get_status(device);
  325. if (ACPI_FAILURE(status))
  326. return -ENODEV;
  327. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  328. return 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 0;
  342. }
  343. static int acpi_bus_check_scope(struct acpi_device *device)
  344. {
  345. int result = 0;
  346. int status_changed = 0;
  347. if (!device)
  348. return -EINVAL;
  349. /* Status Change? */
  350. result = acpi_bus_check_device(device, &status_changed);
  351. if (result)
  352. return result;
  353. if (!status_changed)
  354. return 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 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. if (acpi_bus_get_device(handle, &device))
  371. return;
  372. switch (type) {
  373. case ACPI_NOTIFY_BUS_CHECK:
  374. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  375. "Received BUS CHECK notification for device [%s]\n",
  376. device->pnp.bus_id));
  377. result = acpi_bus_check_scope(device);
  378. /*
  379. * TBD: We'll need to outsource certain events to non-ACPI
  380. * drivers via the device manager (device.c).
  381. */
  382. break;
  383. case ACPI_NOTIFY_DEVICE_CHECK:
  384. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  385. "Received DEVICE CHECK notification for device [%s]\n",
  386. device->pnp.bus_id));
  387. result = acpi_bus_check_device(device, NULL);
  388. /*
  389. * TBD: We'll need to outsource certain events to non-ACPI
  390. * drivers via the device manager (device.c).
  391. */
  392. break;
  393. case ACPI_NOTIFY_DEVICE_WAKE:
  394. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  395. "Received DEVICE WAKE notification for device [%s]\n",
  396. device->pnp.bus_id));
  397. /* TBD */
  398. break;
  399. case ACPI_NOTIFY_EJECT_REQUEST:
  400. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  401. "Received EJECT REQUEST notification for device [%s]\n",
  402. device->pnp.bus_id));
  403. /* TBD */
  404. break;
  405. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  406. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  407. "Received DEVICE CHECK LIGHT notification for device [%s]\n",
  408. device->pnp.bus_id));
  409. /* TBD: Exactly what does 'light' mean? */
  410. break;
  411. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  412. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  413. "Received FREQUENCY MISMATCH notification for device [%s]\n",
  414. device->pnp.bus_id));
  415. /* TBD */
  416. break;
  417. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  418. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  419. "Received BUS MODE MISMATCH notification for device [%s]\n",
  420. device->pnp.bus_id));
  421. /* TBD */
  422. break;
  423. case ACPI_NOTIFY_POWER_FAULT:
  424. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  425. "Received POWER FAULT notification for device [%s]\n",
  426. device->pnp.bus_id));
  427. /* TBD */
  428. break;
  429. default:
  430. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  431. "Received unknown/unsupported notification [%08x]\n",
  432. type));
  433. break;
  434. }
  435. return;
  436. }
  437. /* --------------------------------------------------------------------------
  438. Initialization/Cleanup
  439. -------------------------------------------------------------------------- */
  440. static int __init acpi_bus_init_irq(void)
  441. {
  442. acpi_status status = AE_OK;
  443. union acpi_object arg = { ACPI_TYPE_INTEGER };
  444. struct acpi_object_list arg_list = { 1, &arg };
  445. char *message = NULL;
  446. /*
  447. * Let the system know what interrupt model we are using by
  448. * evaluating the \_PIC object, if exists.
  449. */
  450. switch (acpi_irq_model) {
  451. case ACPI_IRQ_MODEL_PIC:
  452. message = "PIC";
  453. break;
  454. case ACPI_IRQ_MODEL_IOAPIC:
  455. message = "IOAPIC";
  456. break;
  457. case ACPI_IRQ_MODEL_IOSAPIC:
  458. message = "IOSAPIC";
  459. break;
  460. case ACPI_IRQ_MODEL_PLATFORM:
  461. message = "platform specific model";
  462. break;
  463. default:
  464. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  465. return -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 -ENODEV;
  473. }
  474. return 0;
  475. }
  476. acpi_native_uint acpi_gbl_permanent_mmap;
  477. void __init acpi_early_init(void)
  478. {
  479. acpi_status status = AE_OK;
  480. if (acpi_disabled)
  481. return;
  482. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  483. /* enable workarounds, unless strict ACPI spec. compliance */
  484. if (!acpi_strict)
  485. acpi_gbl_enable_interpreter_slack = TRUE;
  486. acpi_gbl_permanent_mmap = 1;
  487. status = acpi_reallocate_root_table();
  488. if (ACPI_FAILURE(status)) {
  489. printk(KERN_ERR PREFIX
  490. "Unable to reallocate ACPI tables\n");
  491. goto error0;
  492. }
  493. status = acpi_initialize_subsystem();
  494. if (ACPI_FAILURE(status)) {
  495. printk(KERN_ERR PREFIX
  496. "Unable to initialize the ACPI Interpreter\n");
  497. goto error0;
  498. }
  499. status = acpi_load_tables();
  500. if (ACPI_FAILURE(status)) {
  501. printk(KERN_ERR PREFIX
  502. "Unable to load the System Description Tables\n");
  503. goto error0;
  504. }
  505. #ifdef CONFIG_X86
  506. if (!acpi_ioapic) {
  507. extern u8 acpi_sci_flags;
  508. /* compatible (0) means level (3) */
  509. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  510. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  511. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  512. }
  513. /* Set PIC-mode SCI trigger type */
  514. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  515. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  516. } else {
  517. extern int acpi_sci_override_gsi;
  518. /*
  519. * now that acpi_gbl_FADT is initialized,
  520. * update it with result from INT_SRC_OVR parsing
  521. */
  522. acpi_gbl_FADT.sci_interrupt = 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;
  534. error0:
  535. disable_acpi();
  536. return;
  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. status = acpi_os_initialize1();
  544. status =
  545. acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  546. if (ACPI_FAILURE(status)) {
  547. printk(KERN_ERR PREFIX
  548. "Unable to start the ACPI Interpreter\n");
  549. goto error1;
  550. }
  551. if (ACPI_FAILURE(status)) {
  552. printk(KERN_ERR PREFIX
  553. "Unable to initialize ACPI OS objects\n");
  554. goto error1;
  555. }
  556. #ifdef CONFIG_ACPI_EC
  557. /*
  558. * ACPI 2.0 requires the EC driver to be loaded and work before
  559. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  560. * is called).
  561. *
  562. * This is accomplished by looking for the ECDT table, and getting
  563. * the EC parameters out of that.
  564. */
  565. status = acpi_ec_ecdt_probe();
  566. /* Ignore result. Not having an ECDT is not fatal. */
  567. #endif
  568. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  569. if (ACPI_FAILURE(status)) {
  570. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  571. goto error1;
  572. }
  573. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  574. /* Initialize sleep structures */
  575. acpi_sleep_init();
  576. /*
  577. * Get the system interrupt model and evaluate \_PIC.
  578. */
  579. result = acpi_bus_init_irq();
  580. if (result)
  581. goto error1;
  582. /*
  583. * Register the for all standard device notifications.
  584. */
  585. status =
  586. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  587. &acpi_bus_notify, NULL);
  588. if (ACPI_FAILURE(status)) {
  589. printk(KERN_ERR PREFIX
  590. "Unable to register for device notifications\n");
  591. goto error1;
  592. }
  593. /*
  594. * Create the top ACPI proc directory
  595. */
  596. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  597. return 0;
  598. /* Mimic structured exception handling */
  599. error1:
  600. acpi_terminate();
  601. return -ENODEV;
  602. }
  603. struct kobject *acpi_kobj;
  604. static int __init acpi_init(void)
  605. {
  606. int result = 0;
  607. if (acpi_disabled) {
  608. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  609. return -ENODEV;
  610. }
  611. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  612. if (!acpi_kobj) {
  613. printk(KERN_WARNING "%s: kset create error\n", __FUNCTION__);
  614. acpi_kobj = NULL;
  615. }
  616. result = acpi_bus_init();
  617. if (!result) {
  618. if (!(pm_flags & PM_APM))
  619. pm_flags |= PM_ACPI;
  620. else {
  621. printk(KERN_INFO PREFIX
  622. "APM is already active, exiting\n");
  623. disable_acpi();
  624. result = -ENODEV;
  625. }
  626. } else
  627. disable_acpi();
  628. return result;
  629. }
  630. subsys_initcall(acpi_init);