bus.c 20 KB

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