syscore.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * syscore.c - Execution of system core operations.
  3. *
  4. * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
  5. *
  6. * This file is released under the GPLv2.
  7. */
  8. #include <linux/syscore_ops.h>
  9. #include <linux/mutex.h>
  10. #include <linux/module.h>
  11. #include <linux/interrupt.h>
  12. #include <trace/events/power.h>
  13. static LIST_HEAD(syscore_ops_list);
  14. static DEFINE_MUTEX(syscore_ops_lock);
  15. /**
  16. * register_syscore_ops - Register a set of system core operations.
  17. * @ops: System core operations to register.
  18. */
  19. void register_syscore_ops(struct syscore_ops *ops)
  20. {
  21. mutex_lock(&syscore_ops_lock);
  22. list_add_tail(&ops->node, &syscore_ops_list);
  23. mutex_unlock(&syscore_ops_lock);
  24. }
  25. EXPORT_SYMBOL_GPL(register_syscore_ops);
  26. /**
  27. * unregister_syscore_ops - Unregister a set of system core operations.
  28. * @ops: System core operations to unregister.
  29. */
  30. void unregister_syscore_ops(struct syscore_ops *ops)
  31. {
  32. mutex_lock(&syscore_ops_lock);
  33. list_del(&ops->node);
  34. mutex_unlock(&syscore_ops_lock);
  35. }
  36. EXPORT_SYMBOL_GPL(unregister_syscore_ops);
  37. #ifdef CONFIG_PM_SLEEP
  38. /**
  39. * syscore_suspend - Execute all the registered system core suspend callbacks.
  40. *
  41. * This function is executed with one CPU on-line and disabled interrupts.
  42. */
  43. int syscore_suspend(void)
  44. {
  45. struct syscore_ops *ops;
  46. int ret = 0;
  47. trace_suspend_resume(TPS("syscore_suspend"), 0, true);
  48. pr_debug("Checking wakeup interrupts\n");
  49. /* Return error code if there are any wakeup interrupts pending. */
  50. ret = check_wakeup_irqs();
  51. if (ret)
  52. return ret;
  53. WARN_ONCE(!irqs_disabled(),
  54. "Interrupts enabled before system core suspend.\n");
  55. list_for_each_entry_reverse(ops, &syscore_ops_list, node)
  56. if (ops->suspend) {
  57. if (initcall_debug)
  58. pr_info("PM: Calling %pF\n", ops->suspend);
  59. ret = ops->suspend();
  60. if (ret)
  61. goto err_out;
  62. WARN_ONCE(!irqs_disabled(),
  63. "Interrupts enabled after %pF\n", ops->suspend);
  64. }
  65. trace_suspend_resume(TPS("syscore_suspend"), 0, false);
  66. return 0;
  67. err_out:
  68. pr_err("PM: System core suspend callback %pF failed.\n", ops->suspend);
  69. list_for_each_entry_continue(ops, &syscore_ops_list, node)
  70. if (ops->resume)
  71. ops->resume();
  72. return ret;
  73. }
  74. EXPORT_SYMBOL_GPL(syscore_suspend);
  75. /**
  76. * syscore_resume - Execute all the registered system core resume callbacks.
  77. *
  78. * This function is executed with one CPU on-line and disabled interrupts.
  79. */
  80. void syscore_resume(void)
  81. {
  82. struct syscore_ops *ops;
  83. trace_suspend_resume(TPS("syscore_resume"), 0, true);
  84. WARN_ONCE(!irqs_disabled(),
  85. "Interrupts enabled before system core resume.\n");
  86. list_for_each_entry(ops, &syscore_ops_list, node)
  87. if (ops->resume) {
  88. if (initcall_debug)
  89. pr_info("PM: Calling %pF\n", ops->resume);
  90. ops->resume();
  91. WARN_ONCE(!irqs_disabled(),
  92. "Interrupts enabled after %pF\n", ops->resume);
  93. }
  94. trace_suspend_resume(TPS("syscore_resume"), 0, false);
  95. }
  96. EXPORT_SYMBOL_GPL(syscore_resume);
  97. #endif /* CONFIG_PM_SLEEP */
  98. /**
  99. * syscore_shutdown - Execute all the registered system core shutdown callbacks.
  100. */
  101. void syscore_shutdown(void)
  102. {
  103. struct syscore_ops *ops;
  104. mutex_lock(&syscore_ops_lock);
  105. list_for_each_entry_reverse(ops, &syscore_ops_list, node)
  106. if (ops->shutdown) {
  107. if (initcall_debug)
  108. pr_info("PM: Calling %pF\n", ops->shutdown);
  109. ops->shutdown();
  110. }
  111. mutex_unlock(&syscore_ops_lock);
  112. }