bus.c 19 KB

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