bus.c 19 KB

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