bus.c 19 KB

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