bus.c 19 KB

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