bus.c 19 KB

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