poweroff.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * poweroff.c - ACPI handler for powering off the system.
  3. *
  4. * AKA S5, but it is independent of whether or not the kernel supports
  5. * any other sleep support in the system.
  6. *
  7. * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
  8. *
  9. * This file is released under the GPLv2.
  10. */
  11. #include <linux/pm.h>
  12. #include <linux/init.h>
  13. #include <acpi/acpi_bus.h>
  14. #include <linux/sched.h>
  15. #include <linux/sysdev.h>
  16. #include <asm/io.h>
  17. #include "sleep.h"
  18. int acpi_sleep_prepare(u32 acpi_state)
  19. {
  20. #ifdef CONFIG_ACPI_SLEEP
  21. /* do we have a wakeup address for S2 and S3? */
  22. /* Here, we support only S4BIOS, those we set the wakeup address */
  23. /* S4OS is only supported for now via swsusp.. */
  24. if (acpi_state == ACPI_STATE_S3 || acpi_state == ACPI_STATE_S4) {
  25. if (!acpi_wakeup_address) {
  26. return -EFAULT;
  27. }
  28. acpi_set_firmware_waking_vector((acpi_physical_address)
  29. virt_to_phys((void *)
  30. acpi_wakeup_address));
  31. }
  32. ACPI_FLUSH_CPU_CACHE();
  33. acpi_enable_wakeup_device_prep(acpi_state);
  34. #endif
  35. if (acpi_state == ACPI_STATE_S5) {
  36. acpi_wakeup_gpe_poweroff_prepare();
  37. }
  38. acpi_enter_sleep_state_prep(acpi_state);
  39. return 0;
  40. }
  41. #ifdef CONFIG_PM
  42. void acpi_power_off(void)
  43. {
  44. /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
  45. printk("%s called\n", __FUNCTION__);
  46. local_irq_disable();
  47. /* Some SMP machines only can poweroff in boot CPU */
  48. acpi_enter_sleep_state(ACPI_STATE_S5);
  49. }
  50. static int acpi_shutdown(struct sys_device *x)
  51. {
  52. return acpi_sleep_prepare(ACPI_STATE_S5);
  53. }
  54. static struct sysdev_class acpi_sysclass = {
  55. set_kset_name("acpi"),
  56. .shutdown = acpi_shutdown
  57. };
  58. static struct sys_device device_acpi = {
  59. .id = 0,
  60. .cls = &acpi_sysclass,
  61. };
  62. static int acpi_poweroff_init(void)
  63. {
  64. if (!acpi_disabled) {
  65. u8 type_a, type_b;
  66. acpi_status status;
  67. status =
  68. acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
  69. if (ACPI_SUCCESS(status)) {
  70. int error;
  71. error = sysdev_class_register(&acpi_sysclass);
  72. if (!error)
  73. error = sysdev_register(&device_acpi);
  74. if (!error)
  75. pm_power_off = acpi_power_off;
  76. return error;
  77. }
  78. }
  79. return 0;
  80. }
  81. late_initcall(acpi_poweroff_init);
  82. #endif /* CONFIG_PM */