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