bus.c 21 KB

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