bus.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. if (state == device->power.state) {
  177. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", state));
  178. return_VALUE(0);
  179. }
  180. if (!device->power.states[state].flags.valid) {
  181. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device does not support D%d\n", state));
  182. return_VALUE(-ENODEV);
  183. }
  184. if (device->parent && (state < device->parent->power.state)) {
  185. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Cannot set device to a higher-powered state than parent\n"));
  186. return_VALUE(-ENODEV);
  187. }
  188. /*
  189. * Transition Power
  190. * ----------------
  191. * On transitions to a high-powered state we first apply power (via
  192. * power resources) then evalute _PSx. Conversly for transitions to
  193. * a lower-powered state.
  194. */
  195. if (state < device->power.state) {
  196. if (device->power.flags.power_resources) {
  197. result = acpi_power_transition(device, state);
  198. if (result)
  199. goto end;
  200. }
  201. if (device->power.states[state].flags.explicit_set) {
  202. status = acpi_evaluate_object(device->handle,
  203. object_name, NULL, NULL);
  204. if (ACPI_FAILURE(status)) {
  205. result = -ENODEV;
  206. goto end;
  207. }
  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, "Error transitioning device [%s] to D%d\n",
  228. device->pnp.bus_id, state));
  229. else
  230. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] transitioned to D%d\n",
  231. device->pnp.bus_id, state));
  232. return_VALUE(result);
  233. }
  234. EXPORT_SYMBOL(acpi_bus_set_power);
  235. /* --------------------------------------------------------------------------
  236. Event Management
  237. -------------------------------------------------------------------------- */
  238. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  239. LIST_HEAD(acpi_bus_event_list);
  240. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  241. extern int event_is_open;
  242. int
  243. acpi_bus_generate_event (
  244. struct acpi_device *device,
  245. u8 type,
  246. int data)
  247. {
  248. struct acpi_bus_event *event = NULL;
  249. unsigned long flags = 0;
  250. ACPI_FUNCTION_TRACE("acpi_bus_generate_event");
  251. if (!device)
  252. return_VALUE(-EINVAL);
  253. /* drop event on the floor if no one's listening */
  254. if (!event_is_open)
  255. return_VALUE(0);
  256. event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
  257. if (!event)
  258. return_VALUE(-ENOMEM);
  259. strcpy(event->device_class, device->pnp.device_class);
  260. strcpy(event->bus_id, device->pnp.bus_id);
  261. event->type = type;
  262. event->data = data;
  263. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  264. list_add_tail(&event->node, &acpi_bus_event_list);
  265. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  266. wake_up_interruptible(&acpi_bus_event_queue);
  267. return_VALUE(0);
  268. }
  269. EXPORT_SYMBOL(acpi_bus_generate_event);
  270. int
  271. acpi_bus_receive_event (
  272. struct acpi_bus_event *event)
  273. {
  274. unsigned long flags = 0;
  275. struct acpi_bus_event *entry = NULL;
  276. DECLARE_WAITQUEUE(wait, current);
  277. ACPI_FUNCTION_TRACE("acpi_bus_receive_event");
  278. if (!event)
  279. return_VALUE(-EINVAL);
  280. if (list_empty(&acpi_bus_event_list)) {
  281. set_current_state(TASK_INTERRUPTIBLE);
  282. add_wait_queue(&acpi_bus_event_queue, &wait);
  283. if (list_empty(&acpi_bus_event_list))
  284. schedule();
  285. remove_wait_queue(&acpi_bus_event_queue, &wait);
  286. set_current_state(TASK_RUNNING);
  287. if (signal_pending(current))
  288. return_VALUE(-ERESTARTSYS);
  289. }
  290. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  291. entry = list_entry(acpi_bus_event_list.next, struct acpi_bus_event, node);
  292. if (entry)
  293. list_del(&entry->node);
  294. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  295. if (!entry)
  296. return_VALUE(-ENODEV);
  297. memcpy(event, entry, sizeof(struct acpi_bus_event));
  298. kfree(entry);
  299. return_VALUE(0);
  300. }
  301. EXPORT_SYMBOL(acpi_bus_receive_event);
  302. /* --------------------------------------------------------------------------
  303. Notification Handling
  304. -------------------------------------------------------------------------- */
  305. static int
  306. acpi_bus_check_device (
  307. struct acpi_device *device,
  308. int *status_changed)
  309. {
  310. acpi_status status = 0;
  311. struct acpi_device_status old_status;
  312. ACPI_FUNCTION_TRACE("acpi_bus_check_device");
  313. if (!device)
  314. return_VALUE(-EINVAL);
  315. if (status_changed)
  316. *status_changed = 0;
  317. old_status = device->status;
  318. /*
  319. * Make sure this device's parent is present before we go about
  320. * messing with the device.
  321. */
  322. if (device->parent && !device->parent->status.present) {
  323. device->status = device->parent->status;
  324. if (STRUCT_TO_INT(old_status) != STRUCT_TO_INT(device->status)) {
  325. if (status_changed)
  326. *status_changed = 1;
  327. }
  328. return_VALUE(0);
  329. }
  330. status = acpi_bus_get_status(device);
  331. if (ACPI_FAILURE(status))
  332. return_VALUE(-ENODEV);
  333. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  334. return_VALUE(0);
  335. if (status_changed)
  336. *status_changed = 1;
  337. /*
  338. * Device Insertion/Removal
  339. */
  340. if ((device->status.present) && !(old_status.present)) {
  341. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  342. /* TBD: Handle device insertion */
  343. }
  344. else if (!(device->status.present) && (old_status.present)) {
  345. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  346. /* TBD: Handle device removal */
  347. }
  348. return_VALUE(0);
  349. }
  350. static int
  351. acpi_bus_check_scope (
  352. struct acpi_device *device)
  353. {
  354. int result = 0;
  355. int status_changed = 0;
  356. ACPI_FUNCTION_TRACE("acpi_bus_check_scope");
  357. if (!device)
  358. return_VALUE(-EINVAL);
  359. /* Status Change? */
  360. result = acpi_bus_check_device(device, &status_changed);
  361. if (result)
  362. return_VALUE(result);
  363. if (!status_changed)
  364. return_VALUE(0);
  365. /*
  366. * TBD: Enumerate child devices within this device's scope and
  367. * run acpi_bus_check_device()'s on them.
  368. */
  369. return_VALUE(0);
  370. }
  371. /**
  372. * acpi_bus_notify
  373. * ---------------
  374. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  375. */
  376. static void
  377. acpi_bus_notify (
  378. acpi_handle handle,
  379. u32 type,
  380. void *data)
  381. {
  382. int result = 0;
  383. struct acpi_device *device = NULL;
  384. ACPI_FUNCTION_TRACE("acpi_bus_notify");
  385. if (acpi_bus_get_device(handle, &device))
  386. return_VOID;
  387. switch (type) {
  388. case ACPI_NOTIFY_BUS_CHECK:
  389. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received BUS CHECK notification for device [%s]\n",
  390. device->pnp.bus_id));
  391. result = acpi_bus_check_scope(device);
  392. /*
  393. * TBD: We'll need to outsource certain events to non-ACPI
  394. * drivers via the device manager (device.c).
  395. */
  396. break;
  397. case ACPI_NOTIFY_DEVICE_CHECK:
  398. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received DEVICE CHECK notification for device [%s]\n",
  399. device->pnp.bus_id));
  400. result = acpi_bus_check_device(device, NULL);
  401. /*
  402. * TBD: We'll need to outsource certain events to non-ACPI
  403. * drivers via the device manager (device.c).
  404. */
  405. break;
  406. case ACPI_NOTIFY_DEVICE_WAKE:
  407. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received DEVICE WAKE notification for device [%s]\n",
  408. device->pnp.bus_id));
  409. /* TBD */
  410. break;
  411. case ACPI_NOTIFY_EJECT_REQUEST:
  412. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received EJECT REQUEST notification for device [%s]\n",
  413. device->pnp.bus_id));
  414. /* TBD */
  415. break;
  416. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  417. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received DEVICE CHECK LIGHT notification for device [%s]\n",
  418. device->pnp.bus_id));
  419. /* TBD: Exactly what does 'light' mean? */
  420. break;
  421. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  422. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received FREQUENCY MISMATCH notification for device [%s]\n",
  423. device->pnp.bus_id));
  424. /* TBD */
  425. break;
  426. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  427. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received BUS MODE MISMATCH notification for device [%s]\n",
  428. device->pnp.bus_id));
  429. /* TBD */
  430. break;
  431. case ACPI_NOTIFY_POWER_FAULT:
  432. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received POWER FAULT notification for device [%s]\n",
  433. device->pnp.bus_id));
  434. /* TBD */
  435. break;
  436. default:
  437. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Received unknown/unsupported notification [%08x]\n",
  438. type));
  439. break;
  440. }
  441. return_VOID;
  442. }
  443. /* --------------------------------------------------------------------------
  444. Initialization/Cleanup
  445. -------------------------------------------------------------------------- */
  446. static int __init
  447. acpi_bus_init_irq (void)
  448. {
  449. acpi_status status = AE_OK;
  450. union acpi_object arg = {ACPI_TYPE_INTEGER};
  451. struct acpi_object_list arg_list = {1, &arg};
  452. char *message = NULL;
  453. ACPI_FUNCTION_TRACE("acpi_bus_init_irq");
  454. /*
  455. * Let the system know what interrupt model we are using by
  456. * evaluating the \_PIC object, if exists.
  457. */
  458. switch (acpi_irq_model) {
  459. case ACPI_IRQ_MODEL_PIC:
  460. message = "PIC";
  461. break;
  462. case ACPI_IRQ_MODEL_IOAPIC:
  463. message = "IOAPIC";
  464. break;
  465. case ACPI_IRQ_MODEL_IOSAPIC:
  466. message = "IOSAPIC";
  467. break;
  468. default:
  469. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  470. return_VALUE(-ENODEV);
  471. }
  472. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  473. arg.integer.value = acpi_irq_model;
  474. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  475. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  476. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PIC\n"));
  477. return_VALUE(-ENODEV);
  478. }
  479. return_VALUE(0);
  480. }
  481. void __init
  482. acpi_early_init (void)
  483. {
  484. acpi_status status = AE_OK;
  485. struct acpi_buffer buffer = {sizeof(acpi_fadt), &acpi_fadt};
  486. ACPI_FUNCTION_TRACE("acpi_early_init");
  487. if (acpi_disabled)
  488. return_VOID;
  489. /* enable workarounds, unless strict ACPI spec. compliance */
  490. if (!acpi_strict)
  491. acpi_gbl_enable_interpreter_slack = TRUE;
  492. status = acpi_initialize_subsystem();
  493. if (ACPI_FAILURE(status)) {
  494. printk(KERN_ERR PREFIX "Unable to initialize the ACPI Interpreter\n");
  495. goto error0;
  496. }
  497. status = acpi_load_tables();
  498. if (ACPI_FAILURE(status)) {
  499. printk(KERN_ERR PREFIX "Unable to load the System Description Tables\n");
  500. goto error0;
  501. }
  502. /*
  503. * Get a separate copy of the FADT for use by other drivers.
  504. */
  505. status = acpi_get_table(ACPI_TABLE_FADT, 1, &buffer);
  506. if (ACPI_FAILURE(status)) {
  507. printk(KERN_ERR PREFIX "Unable to get the FADT\n");
  508. goto error0;
  509. }
  510. #ifdef CONFIG_X86
  511. if (!acpi_ioapic) {
  512. extern acpi_interrupt_flags acpi_sci_flags;
  513. /* compatible (0) means level (3) */
  514. if (acpi_sci_flags.trigger == 0)
  515. acpi_sci_flags.trigger = 3;
  516. /* Set PIC-mode SCI trigger type */
  517. acpi_pic_sci_set_trigger(acpi_fadt.sci_int, acpi_sci_flags.trigger);
  518. } else {
  519. extern int acpi_sci_override_gsi;
  520. /*
  521. * now that acpi_fadt is initialized,
  522. * update it with result from INT_SRC_OVR parsing
  523. */
  524. acpi_fadt.sci_int = acpi_sci_override_gsi;
  525. }
  526. #endif
  527. status = acpi_enable_subsystem(~(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE));
  528. if (ACPI_FAILURE(status)) {
  529. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  530. goto error0;
  531. }
  532. return_VOID;
  533. error0:
  534. disable_acpi();
  535. return_VOID;
  536. }
  537. static int __init
  538. acpi_bus_init (void)
  539. {
  540. int result = 0;
  541. acpi_status status = AE_OK;
  542. extern acpi_status acpi_os_initialize1(void);
  543. ACPI_FUNCTION_TRACE("acpi_bus_init");
  544. status = acpi_os_initialize1();
  545. status = acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  546. if (ACPI_FAILURE(status)) {
  547. printk(KERN_ERR PREFIX "Unable to start the ACPI Interpreter\n");
  548. goto error1;
  549. }
  550. if (ACPI_FAILURE(status)) {
  551. printk(KERN_ERR PREFIX "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 = acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, &acpi_bus_notify, NULL);
  582. if (ACPI_FAILURE(status)) {
  583. printk(KERN_ERR PREFIX "Unable to register for device notifications\n");
  584. goto error1;
  585. }
  586. /*
  587. * Create the top ACPI proc directory
  588. */
  589. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  590. return_VALUE(0);
  591. /* Mimic structured exception handling */
  592. error1:
  593. acpi_terminate();
  594. return_VALUE(-ENODEV);
  595. }
  596. decl_subsys(acpi,NULL,NULL);
  597. static int __init acpi_init (void)
  598. {
  599. int result = 0;
  600. ACPI_FUNCTION_TRACE("acpi_init");
  601. printk(KERN_INFO PREFIX "Subsystem revision %08x\n",
  602. ACPI_CA_VERSION);
  603. if (acpi_disabled) {
  604. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  605. return_VALUE(-ENODEV);
  606. }
  607. firmware_register(&acpi_subsys);
  608. result = acpi_bus_init();
  609. if (!result) {
  610. #ifdef CONFIG_PM
  611. if (!PM_IS_ACTIVE())
  612. pm_active = 1;
  613. else {
  614. printk(KERN_INFO PREFIX "APM is already active, exiting\n");
  615. disable_acpi();
  616. result = -ENODEV;
  617. }
  618. #endif
  619. } else
  620. disable_acpi();
  621. return_VALUE(result);
  622. }
  623. subsys_initcall(acpi_init);