bus.c 20 KB

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