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(struct acpi_device *device)
  366. {
  367. acpi_status status;
  368. struct acpi_device_status old_status;
  369. if (!device)
  370. return;
  371. old_status = device->status;
  372. /*
  373. * Make sure this device's parent is present before we go about
  374. * messing with the device.
  375. */
  376. if (device->parent && !device->parent->status.present) {
  377. device->status = device->parent->status;
  378. return;
  379. }
  380. status = acpi_bus_get_status(device);
  381. if (ACPI_FAILURE(status))
  382. return;
  383. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  384. return;
  385. /*
  386. * Device Insertion/Removal
  387. */
  388. if ((device->status.present) && !(old_status.present)) {
  389. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  390. /* TBD: Handle device insertion */
  391. } else if (!(device->status.present) && (old_status.present)) {
  392. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  393. /* TBD: Handle device removal */
  394. }
  395. }
  396. static void acpi_bus_check_scope(struct acpi_device *device)
  397. {
  398. if (!device)
  399. return;
  400. /* Status Change? */
  401. acpi_bus_check_device(device);
  402. /*
  403. * TBD: Enumerate child devices within this device's scope and
  404. * run acpi_bus_check_device()'s on them.
  405. */
  406. }
  407. static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
  408. int register_acpi_bus_notifier(struct notifier_block *nb)
  409. {
  410. return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
  411. }
  412. EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
  413. void unregister_acpi_bus_notifier(struct notifier_block *nb)
  414. {
  415. blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
  416. }
  417. EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
  418. /**
  419. * acpi_bus_notify
  420. * ---------------
  421. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  422. */
  423. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  424. {
  425. struct acpi_device *device = NULL;
  426. struct acpi_driver *driver;
  427. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
  428. type, handle));
  429. blocking_notifier_call_chain(&acpi_bus_notify_list,
  430. type, (void *)handle);
  431. if (acpi_bus_get_device(handle, &device))
  432. return;
  433. switch (type) {
  434. case ACPI_NOTIFY_BUS_CHECK:
  435. acpi_bus_check_scope(device);
  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(device);
  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. driver = device->driver;
  473. if (driver && driver->ops.notify &&
  474. (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
  475. driver->ops.notify(device, type);
  476. }
  477. /* --------------------------------------------------------------------------
  478. Initialization/Cleanup
  479. -------------------------------------------------------------------------- */
  480. static int __init acpi_bus_init_irq(void)
  481. {
  482. acpi_status status = AE_OK;
  483. union acpi_object arg = { ACPI_TYPE_INTEGER };
  484. struct acpi_object_list arg_list = { 1, &arg };
  485. char *message = NULL;
  486. /*
  487. * Let the system know what interrupt model we are using by
  488. * evaluating the \_PIC object, if exists.
  489. */
  490. switch (acpi_irq_model) {
  491. case ACPI_IRQ_MODEL_PIC:
  492. message = "PIC";
  493. break;
  494. case ACPI_IRQ_MODEL_IOAPIC:
  495. message = "IOAPIC";
  496. break;
  497. case ACPI_IRQ_MODEL_IOSAPIC:
  498. message = "IOSAPIC";
  499. break;
  500. case ACPI_IRQ_MODEL_PLATFORM:
  501. message = "platform specific model";
  502. break;
  503. default:
  504. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  505. return -ENODEV;
  506. }
  507. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  508. arg.integer.value = acpi_irq_model;
  509. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  510. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  511. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  512. return -ENODEV;
  513. }
  514. return 0;
  515. }
  516. u8 acpi_gbl_permanent_mmap;
  517. void __init acpi_early_init(void)
  518. {
  519. acpi_status status = AE_OK;
  520. if (acpi_disabled)
  521. return;
  522. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  523. /* enable workarounds, unless strict ACPI spec. compliance */
  524. if (!acpi_strict)
  525. acpi_gbl_enable_interpreter_slack = TRUE;
  526. acpi_gbl_permanent_mmap = 1;
  527. status = acpi_reallocate_root_table();
  528. if (ACPI_FAILURE(status)) {
  529. printk(KERN_ERR PREFIX
  530. "Unable to reallocate ACPI tables\n");
  531. goto error0;
  532. }
  533. status = acpi_initialize_subsystem();
  534. if (ACPI_FAILURE(status)) {
  535. printk(KERN_ERR PREFIX
  536. "Unable to initialize the ACPI Interpreter\n");
  537. goto error0;
  538. }
  539. status = acpi_load_tables();
  540. if (ACPI_FAILURE(status)) {
  541. printk(KERN_ERR PREFIX
  542. "Unable to load the System Description Tables\n");
  543. goto error0;
  544. }
  545. #ifdef CONFIG_X86
  546. if (!acpi_ioapic) {
  547. /* compatible (0) means level (3) */
  548. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  549. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  550. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  551. }
  552. /* Set PIC-mode SCI trigger type */
  553. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  554. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  555. } else {
  556. /*
  557. * now that acpi_gbl_FADT is initialized,
  558. * update it with result from INT_SRC_OVR parsing
  559. */
  560. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  561. }
  562. #endif
  563. status =
  564. acpi_enable_subsystem(~
  565. (ACPI_NO_HARDWARE_INIT |
  566. ACPI_NO_ACPI_ENABLE));
  567. if (ACPI_FAILURE(status)) {
  568. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  569. goto error0;
  570. }
  571. return;
  572. error0:
  573. disable_acpi();
  574. return;
  575. }
  576. static int __init acpi_bus_init(void)
  577. {
  578. int result = 0;
  579. acpi_status status = AE_OK;
  580. extern acpi_status acpi_os_initialize1(void);
  581. acpi_os_initialize1();
  582. status =
  583. acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  584. if (ACPI_FAILURE(status)) {
  585. printk(KERN_ERR PREFIX
  586. "Unable to start the ACPI Interpreter\n");
  587. goto error1;
  588. }
  589. /*
  590. * ACPI 2.0 requires the EC driver to be loaded and work before
  591. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  592. * is called).
  593. *
  594. * This is accomplished by looking for the ECDT table, and getting
  595. * the EC parameters out of that.
  596. */
  597. status = acpi_ec_ecdt_probe();
  598. /* Ignore result. Not having an ECDT is not fatal. */
  599. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  600. if (ACPI_FAILURE(status)) {
  601. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  602. goto error1;
  603. }
  604. /*
  605. * Maybe EC region is required at bus_scan/acpi_get_devices. So it
  606. * is necessary to enable it as early as possible.
  607. */
  608. acpi_boot_ec_enable();
  609. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  610. /* Initialize sleep structures */
  611. acpi_sleep_init();
  612. /*
  613. * Get the system interrupt model and evaluate \_PIC.
  614. */
  615. result = acpi_bus_init_irq();
  616. if (result)
  617. goto error1;
  618. /*
  619. * Register the for all standard device notifications.
  620. */
  621. status =
  622. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  623. &acpi_bus_notify, NULL);
  624. if (ACPI_FAILURE(status)) {
  625. printk(KERN_ERR PREFIX
  626. "Unable to register for device notifications\n");
  627. goto error1;
  628. }
  629. /*
  630. * Create the top ACPI proc directory
  631. */
  632. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  633. return 0;
  634. /* Mimic structured exception handling */
  635. error1:
  636. acpi_terminate();
  637. return -ENODEV;
  638. }
  639. struct kobject *acpi_kobj;
  640. static int __init acpi_init(void)
  641. {
  642. int result = 0;
  643. if (acpi_disabled) {
  644. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  645. return -ENODEV;
  646. }
  647. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  648. if (!acpi_kobj) {
  649. printk(KERN_WARNING "%s: kset create error\n", __func__);
  650. acpi_kobj = NULL;
  651. }
  652. init_acpi_device_notify();
  653. result = acpi_bus_init();
  654. if (!result) {
  655. pci_mmcfg_late_init();
  656. if (!(pm_flags & PM_APM))
  657. pm_flags |= PM_ACPI;
  658. else {
  659. printk(KERN_INFO PREFIX
  660. "APM is already active, exiting\n");
  661. disable_acpi();
  662. result = -ENODEV;
  663. }
  664. } else
  665. disable_acpi();
  666. if (acpi_disabled)
  667. return result;
  668. /*
  669. * If the laptop falls into the DMI check table, the power state check
  670. * will be disabled in the course of device power transistion.
  671. */
  672. dmi_check_system(power_nocheck_dmi_table);
  673. acpi_scan_init();
  674. acpi_ec_init();
  675. acpi_power_init();
  676. acpi_system_init();
  677. acpi_debug_init();
  678. acpi_sleep_proc_init();
  679. acpi_wakeup_device_init();
  680. return result;
  681. }
  682. subsys_initcall(acpi_init);