bus.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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 acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
  52. {
  53. acpi_status status = AE_OK;
  54. ACPI_FUNCTION_TRACE("acpi_bus_get_device");
  55. if (!device)
  56. return_VALUE(-EINVAL);
  57. /* TBD: Support fixed-feature devices */
  58. status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
  59. if (ACPI_FAILURE(status) || !*device) {
  60. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "No context for object [%p]\n",
  61. handle));
  62. return_VALUE(-ENODEV);
  63. }
  64. return_VALUE(0);
  65. }
  66. EXPORT_SYMBOL(acpi_bus_get_device);
  67. int acpi_bus_get_status(struct acpi_device *device)
  68. {
  69. acpi_status status = AE_OK;
  70. unsigned long sta = 0;
  71. ACPI_FUNCTION_TRACE("acpi_bus_get_status");
  72. if (!device)
  73. return_VALUE(-EINVAL);
  74. /*
  75. * Evaluate _STA if present.
  76. */
  77. if (device->flags.dynamic_status) {
  78. status =
  79. acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
  80. if (ACPI_FAILURE(status))
  81. return_VALUE(-ENODEV);
  82. STRUCT_TO_INT(device->status) = (int)sta;
  83. }
  84. /*
  85. * Otherwise we assume the status of our parent (unless we don't
  86. * have one, in which case status is implied).
  87. */
  88. else if (device->parent)
  89. device->status = device->parent->status;
  90. else
  91. STRUCT_TO_INT(device->status) = 0x0F;
  92. if (device->status.functional && !device->status.present) {
  93. printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: "
  94. "functional but not present; setting present\n",
  95. device->pnp.bus_id, (u32) STRUCT_TO_INT(device->status));
  96. device->status.present = 1;
  97. }
  98. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
  99. device->pnp.bus_id,
  100. (u32) STRUCT_TO_INT(device->status)));
  101. return_VALUE(0);
  102. }
  103. EXPORT_SYMBOL(acpi_bus_get_status);
  104. /* --------------------------------------------------------------------------
  105. Power Management
  106. -------------------------------------------------------------------------- */
  107. int acpi_bus_get_power(acpi_handle handle, int *state)
  108. {
  109. int result = 0;
  110. acpi_status status = 0;
  111. struct acpi_device *device = NULL;
  112. unsigned long psc = 0;
  113. ACPI_FUNCTION_TRACE("acpi_bus_get_power");
  114. result = acpi_bus_get_device(handle, &device);
  115. if (result)
  116. return_VALUE(result);
  117. *state = ACPI_STATE_UNKNOWN;
  118. if (!device->flags.power_manageable) {
  119. /* TBD: Non-recursive algorithm for walking up hierarchy */
  120. if (device->parent)
  121. *state = device->parent->power.state;
  122. else
  123. *state = ACPI_STATE_D0;
  124. } else {
  125. /*
  126. * Get the device's power state either directly (via _PSC) or
  127. * indirectly (via power resources).
  128. */
  129. if (device->power.flags.explicit_get) {
  130. status = acpi_evaluate_integer(device->handle, "_PSC",
  131. NULL, &psc);
  132. if (ACPI_FAILURE(status))
  133. return_VALUE(-ENODEV);
  134. device->power.state = (int)psc;
  135. } else if (device->power.flags.power_resources) {
  136. result = acpi_power_get_inferred_state(device);
  137. if (result)
  138. return_VALUE(result);
  139. }
  140. *state = device->power.state;
  141. }
  142. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
  143. device->pnp.bus_id, device->power.state));
  144. return_VALUE(0);
  145. }
  146. EXPORT_SYMBOL(acpi_bus_get_power);
  147. int acpi_bus_set_power(acpi_handle handle, int state)
  148. {
  149. int result = 0;
  150. acpi_status status = AE_OK;
  151. struct acpi_device *device = NULL;
  152. char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
  153. ACPI_FUNCTION_TRACE("acpi_bus_set_power");
  154. result = acpi_bus_get_device(handle, &device);
  155. if (result)
  156. return_VALUE(result);
  157. if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
  158. return_VALUE(-EINVAL);
  159. /* Make sure this is a valid target state */
  160. if (!device->flags.power_manageable) {
  161. ACPI_DEBUG_PRINT((ACPI_DB_WARN,
  162. "Device is not power manageable\n"));
  163. return_VALUE(-ENODEV);
  164. }
  165. /*
  166. * Get device's current power state if it's unknown
  167. * This means device power state isn't initialized or previous setting failed
  168. */
  169. if (device->power.state == ACPI_STATE_UNKNOWN)
  170. acpi_bus_get_power(device->handle, &device->power.state);
  171. if (state == device->power.state) {
  172. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
  173. state));
  174. return_VALUE(0);
  175. }
  176. if (!device->power.states[state].flags.valid) {
  177. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device does not support D%d\n",
  178. state));
  179. return_VALUE(-ENODEV);
  180. }
  181. if (device->parent && (state < device->parent->power.state)) {
  182. ACPI_DEBUG_PRINT((ACPI_DB_WARN,
  183. "Cannot set device to a higher-powered state than parent\n"));
  184. return_VALUE(-ENODEV);
  185. }
  186. /*
  187. * Transition Power
  188. * ----------------
  189. * On transitions to a high-powered state we first apply power (via
  190. * power resources) then evalute _PSx. Conversly for transitions to
  191. * a lower-powered state.
  192. */
  193. if (state < device->power.state) {
  194. if (device->power.flags.power_resources) {
  195. result = acpi_power_transition(device, state);
  196. if (result)
  197. goto end;
  198. }
  199. if (device->power.states[state].flags.explicit_set) {
  200. status = acpi_evaluate_object(device->handle,
  201. object_name, NULL, NULL);
  202. if (ACPI_FAILURE(status)) {
  203. result = -ENODEV;
  204. goto end;
  205. }
  206. }
  207. } else {
  208. if (device->power.states[state].flags.explicit_set) {
  209. status = acpi_evaluate_object(device->handle,
  210. object_name, NULL, NULL);
  211. if (ACPI_FAILURE(status)) {
  212. result = -ENODEV;
  213. goto end;
  214. }
  215. }
  216. if (device->power.flags.power_resources) {
  217. result = acpi_power_transition(device, state);
  218. if (result)
  219. goto end;
  220. }
  221. }
  222. end:
  223. if (result)
  224. ACPI_DEBUG_PRINT((ACPI_DB_WARN,
  225. "Error transitioning device [%s] to D%d\n",
  226. device->pnp.bus_id, state));
  227. else
  228. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  229. "Device [%s] transitioned to D%d\n",
  230. device->pnp.bus_id, state));
  231. return_VALUE(result);
  232. }
  233. EXPORT_SYMBOL(acpi_bus_set_power);
  234. /* --------------------------------------------------------------------------
  235. Event Management
  236. -------------------------------------------------------------------------- */
  237. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  238. LIST_HEAD(acpi_bus_event_list);
  239. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  240. extern int event_is_open;
  241. int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
  242. {
  243. struct acpi_bus_event *event = NULL;
  244. unsigned long flags = 0;
  245. ACPI_FUNCTION_TRACE("acpi_bus_generate_event");
  246. if (!device)
  247. return_VALUE(-EINVAL);
  248. /* drop event on the floor if no one's listening */
  249. if (!event_is_open)
  250. return_VALUE(0);
  251. event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
  252. if (!event)
  253. return_VALUE(-ENOMEM);
  254. strcpy(event->device_class, device->pnp.device_class);
  255. strcpy(event->bus_id, device->pnp.bus_id);
  256. event->type = type;
  257. event->data = data;
  258. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  259. list_add_tail(&event->node, &acpi_bus_event_list);
  260. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  261. wake_up_interruptible(&acpi_bus_event_queue);
  262. return_VALUE(0);
  263. }
  264. EXPORT_SYMBOL(acpi_bus_generate_event);
  265. int acpi_bus_receive_event(struct acpi_bus_event *event)
  266. {
  267. unsigned long flags = 0;
  268. struct acpi_bus_event *entry = NULL;
  269. DECLARE_WAITQUEUE(wait, current);
  270. ACPI_FUNCTION_TRACE("acpi_bus_receive_event");
  271. if (!event)
  272. return_VALUE(-EINVAL);
  273. if (list_empty(&acpi_bus_event_list)) {
  274. set_current_state(TASK_INTERRUPTIBLE);
  275. add_wait_queue(&acpi_bus_event_queue, &wait);
  276. if (list_empty(&acpi_bus_event_list))
  277. schedule();
  278. remove_wait_queue(&acpi_bus_event_queue, &wait);
  279. set_current_state(TASK_RUNNING);
  280. if (signal_pending(current))
  281. return_VALUE(-ERESTARTSYS);
  282. }
  283. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  284. entry =
  285. list_entry(acpi_bus_event_list.next, struct acpi_bus_event, node);
  286. if (entry)
  287. list_del(&entry->node);
  288. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  289. if (!entry)
  290. return_VALUE(-ENODEV);
  291. memcpy(event, entry, sizeof(struct acpi_bus_event));
  292. kfree(entry);
  293. return_VALUE(0);
  294. }
  295. EXPORT_SYMBOL(acpi_bus_receive_event);
  296. /* --------------------------------------------------------------------------
  297. Notification Handling
  298. -------------------------------------------------------------------------- */
  299. static int
  300. acpi_bus_check_device(struct acpi_device *device, int *status_changed)
  301. {
  302. acpi_status status = 0;
  303. struct acpi_device_status old_status;
  304. ACPI_FUNCTION_TRACE("acpi_bus_check_device");
  305. if (!device)
  306. return_VALUE(-EINVAL);
  307. if (status_changed)
  308. *status_changed = 0;
  309. old_status = device->status;
  310. /*
  311. * Make sure this device's parent is present before we go about
  312. * messing with the device.
  313. */
  314. if (device->parent && !device->parent->status.present) {
  315. device->status = device->parent->status;
  316. if (STRUCT_TO_INT(old_status) != STRUCT_TO_INT(device->status)) {
  317. if (status_changed)
  318. *status_changed = 1;
  319. }
  320. return_VALUE(0);
  321. }
  322. status = acpi_bus_get_status(device);
  323. if (ACPI_FAILURE(status))
  324. return_VALUE(-ENODEV);
  325. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  326. return_VALUE(0);
  327. if (status_changed)
  328. *status_changed = 1;
  329. /*
  330. * Device Insertion/Removal
  331. */
  332. if ((device->status.present) && !(old_status.present)) {
  333. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  334. /* TBD: Handle device insertion */
  335. } else if (!(device->status.present) && (old_status.present)) {
  336. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  337. /* TBD: Handle device removal */
  338. }
  339. return_VALUE(0);
  340. }
  341. static int acpi_bus_check_scope(struct acpi_device *device)
  342. {
  343. int result = 0;
  344. int status_changed = 0;
  345. ACPI_FUNCTION_TRACE("acpi_bus_check_scope");
  346. if (!device)
  347. return_VALUE(-EINVAL);
  348. /* Status Change? */
  349. result = acpi_bus_check_device(device, &status_changed);
  350. if (result)
  351. return_VALUE(result);
  352. if (!status_changed)
  353. return_VALUE(0);
  354. /*
  355. * TBD: Enumerate child devices within this device's scope and
  356. * run acpi_bus_check_device()'s on them.
  357. */
  358. return_VALUE(0);
  359. }
  360. /**
  361. * acpi_bus_notify
  362. * ---------------
  363. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  364. */
  365. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  366. {
  367. int result = 0;
  368. struct acpi_device *device = NULL;
  369. ACPI_FUNCTION_TRACE("acpi_bus_notify");
  370. if (acpi_bus_get_device(handle, &device))
  371. return_VOID;
  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_VOID;
  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. ACPI_FUNCTION_TRACE("acpi_bus_init_irq");
  447. /*
  448. * Let the system know what interrupt model we are using by
  449. * evaluating the \_PIC object, if exists.
  450. */
  451. switch (acpi_irq_model) {
  452. case ACPI_IRQ_MODEL_PIC:
  453. message = "PIC";
  454. break;
  455. case ACPI_IRQ_MODEL_IOAPIC:
  456. message = "IOAPIC";
  457. break;
  458. case ACPI_IRQ_MODEL_IOSAPIC:
  459. message = "IOSAPIC";
  460. break;
  461. default:
  462. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  463. return_VALUE(-ENODEV);
  464. }
  465. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  466. arg.integer.value = acpi_irq_model;
  467. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  468. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  469. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PIC\n"));
  470. return_VALUE(-ENODEV);
  471. }
  472. return_VALUE(0);
  473. }
  474. void __init acpi_early_init(void)
  475. {
  476. acpi_status status = AE_OK;
  477. struct acpi_buffer buffer = { sizeof(acpi_fadt), &acpi_fadt };
  478. ACPI_FUNCTION_TRACE("acpi_early_init");
  479. if (acpi_disabled)
  480. return_VOID;
  481. /* enable workarounds, unless strict ACPI spec. compliance */
  482. if (!acpi_strict)
  483. acpi_gbl_enable_interpreter_slack = TRUE;
  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. /*
  497. * Get a separate copy of the FADT for use by other drivers.
  498. */
  499. status = acpi_get_table(ACPI_TABLE_FADT, 1, &buffer);
  500. if (ACPI_FAILURE(status)) {
  501. printk(KERN_ERR PREFIX "Unable to get the FADT\n");
  502. goto error0;
  503. }
  504. #ifdef CONFIG_X86
  505. if (!acpi_ioapic) {
  506. extern acpi_interrupt_flags acpi_sci_flags;
  507. /* compatible (0) means level (3) */
  508. if (acpi_sci_flags.trigger == 0)
  509. acpi_sci_flags.trigger = 3;
  510. /* Set PIC-mode SCI trigger type */
  511. acpi_pic_sci_set_trigger(acpi_fadt.sci_int,
  512. acpi_sci_flags.trigger);
  513. } else {
  514. extern int acpi_sci_override_gsi;
  515. /*
  516. * now that acpi_fadt is initialized,
  517. * update it with result from INT_SRC_OVR parsing
  518. */
  519. acpi_fadt.sci_int = acpi_sci_override_gsi;
  520. }
  521. #endif
  522. status =
  523. acpi_enable_subsystem(~
  524. (ACPI_NO_HARDWARE_INIT |
  525. ACPI_NO_ACPI_ENABLE));
  526. if (ACPI_FAILURE(status)) {
  527. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  528. goto error0;
  529. }
  530. return_VOID;
  531. error0:
  532. disable_acpi();
  533. return_VOID;
  534. }
  535. static int __init acpi_bus_init(void)
  536. {
  537. int result = 0;
  538. acpi_status status = AE_OK;
  539. extern acpi_status acpi_os_initialize1(void);
  540. ACPI_FUNCTION_TRACE("acpi_bus_init");
  541. status = acpi_os_initialize1();
  542. status =
  543. acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  544. if (ACPI_FAILURE(status)) {
  545. printk(KERN_ERR PREFIX
  546. "Unable to start the ACPI Interpreter\n");
  547. goto error1;
  548. }
  549. if (ACPI_FAILURE(status)) {
  550. printk(KERN_ERR PREFIX
  551. "Unable to initialize ACPI OS objects\n");
  552. goto error1;
  553. }
  554. #ifdef CONFIG_ACPI_EC
  555. /*
  556. * ACPI 2.0 requires the EC driver to be loaded and work before
  557. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  558. * is called).
  559. *
  560. * This is accomplished by looking for the ECDT table, and getting
  561. * the EC parameters out of that.
  562. */
  563. status = acpi_ec_ecdt_probe();
  564. /* Ignore result. Not having an ECDT is not fatal. */
  565. #endif
  566. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  567. if (ACPI_FAILURE(status)) {
  568. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  569. goto error1;
  570. }
  571. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  572. /*
  573. * Get the system interrupt model and evaluate \_PIC.
  574. */
  575. result = acpi_bus_init_irq();
  576. if (result)
  577. goto error1;
  578. /*
  579. * Register the for all standard device notifications.
  580. */
  581. status =
  582. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  583. &acpi_bus_notify, NULL);
  584. if (ACPI_FAILURE(status)) {
  585. printk(KERN_ERR PREFIX
  586. "Unable to register for device notifications\n");
  587. goto error1;
  588. }
  589. /*
  590. * Create the top ACPI proc directory
  591. */
  592. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  593. return_VALUE(0);
  594. /* Mimic structured exception handling */
  595. error1:
  596. acpi_terminate();
  597. return_VALUE(-ENODEV);
  598. }
  599. decl_subsys(acpi, NULL, NULL);
  600. static int __init acpi_init(void)
  601. {
  602. int result = 0;
  603. ACPI_FUNCTION_TRACE("acpi_init");
  604. printk(KERN_INFO PREFIX "Subsystem revision %08x\n", ACPI_CA_VERSION);
  605. if (acpi_disabled) {
  606. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  607. return_VALUE(-ENODEV);
  608. }
  609. firmware_register(&acpi_subsys);
  610. result = acpi_bus_init();
  611. if (!result) {
  612. #ifdef CONFIG_PM
  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_VALUE(result);
  625. }
  626. subsys_initcall(acpi_init);