bus.c 20 KB

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