bus.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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. entry =
  305. list_entry(acpi_bus_event_list.next, struct acpi_bus_event, node);
  306. if (entry)
  307. list_del(&entry->node);
  308. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  309. if (!entry)
  310. return -ENODEV;
  311. memcpy(event, entry, sizeof(struct acpi_bus_event));
  312. kfree(entry);
  313. return 0;
  314. }
  315. #endif /* CONFIG_ACPI_PROC_EVENT */
  316. /* --------------------------------------------------------------------------
  317. Notification Handling
  318. -------------------------------------------------------------------------- */
  319. static int
  320. acpi_bus_check_device(struct acpi_device *device, int *status_changed)
  321. {
  322. acpi_status status = 0;
  323. struct acpi_device_status old_status;
  324. if (!device)
  325. return -EINVAL;
  326. if (status_changed)
  327. *status_changed = 0;
  328. old_status = device->status;
  329. /*
  330. * Make sure this device's parent is present before we go about
  331. * messing with the device.
  332. */
  333. if (device->parent && !device->parent->status.present) {
  334. device->status = device->parent->status;
  335. if (STRUCT_TO_INT(old_status) != STRUCT_TO_INT(device->status)) {
  336. if (status_changed)
  337. *status_changed = 1;
  338. }
  339. return 0;
  340. }
  341. status = acpi_bus_get_status(device);
  342. if (ACPI_FAILURE(status))
  343. return -ENODEV;
  344. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  345. return 0;
  346. if (status_changed)
  347. *status_changed = 1;
  348. /*
  349. * Device Insertion/Removal
  350. */
  351. if ((device->status.present) && !(old_status.present)) {
  352. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  353. /* TBD: Handle device insertion */
  354. } else if (!(device->status.present) && (old_status.present)) {
  355. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  356. /* TBD: Handle device removal */
  357. }
  358. return 0;
  359. }
  360. static int acpi_bus_check_scope(struct acpi_device *device)
  361. {
  362. int result = 0;
  363. int status_changed = 0;
  364. if (!device)
  365. return -EINVAL;
  366. /* Status Change? */
  367. result = acpi_bus_check_device(device, &status_changed);
  368. if (result)
  369. return result;
  370. if (!status_changed)
  371. return 0;
  372. /*
  373. * TBD: Enumerate child devices within this device's scope and
  374. * run acpi_bus_check_device()'s on them.
  375. */
  376. return 0;
  377. }
  378. /**
  379. * acpi_bus_notify
  380. * ---------------
  381. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  382. */
  383. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  384. {
  385. int result = 0;
  386. struct acpi_device *device = NULL;
  387. if (acpi_bus_get_device(handle, &device))
  388. return;
  389. switch (type) {
  390. case ACPI_NOTIFY_BUS_CHECK:
  391. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  392. "Received BUS CHECK notification for device [%s]\n",
  393. device->pnp.bus_id));
  394. result = acpi_bus_check_scope(device);
  395. /*
  396. * TBD: We'll need to outsource certain events to non-ACPI
  397. * drivers via the device manager (device.c).
  398. */
  399. break;
  400. case ACPI_NOTIFY_DEVICE_CHECK:
  401. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  402. "Received DEVICE CHECK notification for device [%s]\n",
  403. device->pnp.bus_id));
  404. result = acpi_bus_check_device(device, NULL);
  405. /*
  406. * TBD: We'll need to outsource certain events to non-ACPI
  407. * drivers via the device manager (device.c).
  408. */
  409. break;
  410. case ACPI_NOTIFY_DEVICE_WAKE:
  411. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  412. "Received DEVICE WAKE notification for device [%s]\n",
  413. device->pnp.bus_id));
  414. /* TBD */
  415. break;
  416. case ACPI_NOTIFY_EJECT_REQUEST:
  417. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  418. "Received EJECT REQUEST notification for device [%s]\n",
  419. device->pnp.bus_id));
  420. /* TBD */
  421. break;
  422. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  423. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  424. "Received DEVICE CHECK LIGHT notification for device [%s]\n",
  425. device->pnp.bus_id));
  426. /* TBD: Exactly what does 'light' mean? */
  427. break;
  428. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  429. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  430. "Received FREQUENCY MISMATCH notification for device [%s]\n",
  431. device->pnp.bus_id));
  432. /* TBD */
  433. break;
  434. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  435. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  436. "Received BUS MODE MISMATCH notification for device [%s]\n",
  437. device->pnp.bus_id));
  438. /* TBD */
  439. break;
  440. case ACPI_NOTIFY_POWER_FAULT:
  441. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  442. "Received POWER FAULT notification for device [%s]\n",
  443. device->pnp.bus_id));
  444. /* TBD */
  445. break;
  446. default:
  447. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  448. "Received unknown/unsupported notification [%08x]\n",
  449. type));
  450. break;
  451. }
  452. return;
  453. }
  454. /* --------------------------------------------------------------------------
  455. Initialization/Cleanup
  456. -------------------------------------------------------------------------- */
  457. static int __init acpi_bus_init_irq(void)
  458. {
  459. acpi_status status = AE_OK;
  460. union acpi_object arg = { ACPI_TYPE_INTEGER };
  461. struct acpi_object_list arg_list = { 1, &arg };
  462. char *message = NULL;
  463. /*
  464. * Let the system know what interrupt model we are using by
  465. * evaluating the \_PIC object, if exists.
  466. */
  467. switch (acpi_irq_model) {
  468. case ACPI_IRQ_MODEL_PIC:
  469. message = "PIC";
  470. break;
  471. case ACPI_IRQ_MODEL_IOAPIC:
  472. message = "IOAPIC";
  473. break;
  474. case ACPI_IRQ_MODEL_IOSAPIC:
  475. message = "IOSAPIC";
  476. break;
  477. case ACPI_IRQ_MODEL_PLATFORM:
  478. message = "platform specific model";
  479. break;
  480. default:
  481. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  482. return -ENODEV;
  483. }
  484. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  485. arg.integer.value = acpi_irq_model;
  486. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  487. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  488. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  489. return -ENODEV;
  490. }
  491. return 0;
  492. }
  493. acpi_native_uint acpi_gbl_permanent_mmap;
  494. void __init acpi_early_init(void)
  495. {
  496. acpi_status status = AE_OK;
  497. if (acpi_disabled)
  498. return;
  499. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  500. /* enable workarounds, unless strict ACPI spec. compliance */
  501. if (!acpi_strict)
  502. acpi_gbl_enable_interpreter_slack = TRUE;
  503. acpi_gbl_permanent_mmap = 1;
  504. status = acpi_reallocate_root_table();
  505. if (ACPI_FAILURE(status)) {
  506. printk(KERN_ERR PREFIX
  507. "Unable to reallocate ACPI tables\n");
  508. goto error0;
  509. }
  510. status = acpi_initialize_subsystem();
  511. if (ACPI_FAILURE(status)) {
  512. printk(KERN_ERR PREFIX
  513. "Unable to initialize the ACPI Interpreter\n");
  514. goto error0;
  515. }
  516. status = acpi_load_tables();
  517. if (ACPI_FAILURE(status)) {
  518. printk(KERN_ERR PREFIX
  519. "Unable to load the System Description Tables\n");
  520. goto error0;
  521. }
  522. #ifdef CONFIG_X86
  523. if (!acpi_ioapic) {
  524. /* compatible (0) means level (3) */
  525. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  526. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  527. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  528. }
  529. /* Set PIC-mode SCI trigger type */
  530. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  531. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  532. } else {
  533. /*
  534. * now that acpi_gbl_FADT is initialized,
  535. * update it with result from INT_SRC_OVR parsing
  536. */
  537. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  538. }
  539. #endif
  540. status =
  541. acpi_enable_subsystem(~
  542. (ACPI_NO_HARDWARE_INIT |
  543. ACPI_NO_ACPI_ENABLE));
  544. if (ACPI_FAILURE(status)) {
  545. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  546. goto error0;
  547. }
  548. return;
  549. error0:
  550. disable_acpi();
  551. return;
  552. }
  553. static int __init acpi_bus_init(void)
  554. {
  555. int result = 0;
  556. acpi_status status = AE_OK;
  557. extern acpi_status acpi_os_initialize1(void);
  558. status = acpi_os_initialize1();
  559. status =
  560. acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  561. if (ACPI_FAILURE(status)) {
  562. printk(KERN_ERR PREFIX
  563. "Unable to start the ACPI Interpreter\n");
  564. goto error1;
  565. }
  566. if (ACPI_FAILURE(status)) {
  567. printk(KERN_ERR PREFIX
  568. "Unable to initialize ACPI OS objects\n");
  569. goto error1;
  570. }
  571. #ifdef CONFIG_ACPI_EC
  572. /*
  573. * ACPI 2.0 requires the EC driver to be loaded and work before
  574. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  575. * is called).
  576. *
  577. * This is accomplished by looking for the ECDT table, and getting
  578. * the EC parameters out of that.
  579. */
  580. status = acpi_ec_ecdt_probe();
  581. /* Ignore result. Not having an ECDT is not fatal. */
  582. #endif
  583. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  584. if (ACPI_FAILURE(status)) {
  585. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  586. goto error1;
  587. }
  588. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  589. /* Initialize sleep structures */
  590. acpi_sleep_init();
  591. /*
  592. * Get the system interrupt model and evaluate \_PIC.
  593. */
  594. result = acpi_bus_init_irq();
  595. if (result)
  596. goto error1;
  597. /*
  598. * Register the for all standard device notifications.
  599. */
  600. status =
  601. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  602. &acpi_bus_notify, NULL);
  603. if (ACPI_FAILURE(status)) {
  604. printk(KERN_ERR PREFIX
  605. "Unable to register for device notifications\n");
  606. goto error1;
  607. }
  608. /*
  609. * Create the top ACPI proc directory
  610. */
  611. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  612. return 0;
  613. /* Mimic structured exception handling */
  614. error1:
  615. acpi_terminate();
  616. return -ENODEV;
  617. }
  618. struct kobject *acpi_kobj;
  619. static int __init acpi_init(void)
  620. {
  621. int result = 0;
  622. if (acpi_disabled) {
  623. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  624. return -ENODEV;
  625. }
  626. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  627. if (!acpi_kobj) {
  628. printk(KERN_WARNING "%s: kset create error\n", __func__);
  629. acpi_kobj = NULL;
  630. }
  631. result = acpi_bus_init();
  632. if (!result) {
  633. if (!(pm_flags & PM_APM))
  634. pm_flags |= PM_ACPI;
  635. else {
  636. printk(KERN_INFO PREFIX
  637. "APM is already active, exiting\n");
  638. disable_acpi();
  639. result = -ENODEV;
  640. }
  641. } else
  642. disable_acpi();
  643. return result;
  644. }
  645. subsys_initcall(acpi_init);