bus.c 22 KB

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