pm.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2014 Imagination Technologies Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * CPU PM notifiers for saving/restoring general CPU state.
  10. */
  11. #include <linux/cpu_pm.h>
  12. #include <linux/init.h>
  13. #include <asm/dsp.h>
  14. #include <asm/fpu.h>
  15. #include <asm/mmu_context.h>
  16. #include <asm/pm.h>
  17. #include <asm/watch.h>
  18. /* Used by PM helper macros in asm/pm.h */
  19. struct mips_static_suspend_state mips_static_suspend_state;
  20. /**
  21. * mips_cpu_save() - Save general CPU state.
  22. * Ensures that general CPU context is saved, notably FPU and DSP.
  23. */
  24. static int mips_cpu_save(void)
  25. {
  26. /* Save FPU state */
  27. lose_fpu(1);
  28. /* Save DSP state */
  29. save_dsp(current);
  30. return 0;
  31. }
  32. /**
  33. * mips_cpu_restore() - Restore general CPU state.
  34. * Restores important CPU context.
  35. */
  36. static void mips_cpu_restore(void)
  37. {
  38. unsigned int cpu = smp_processor_id();
  39. /* Restore ASID */
  40. if (current->mm)
  41. write_c0_entryhi(cpu_asid(cpu, current->mm));
  42. /* Restore DSP state */
  43. restore_dsp(current);
  44. /* Restore UserLocal */
  45. if (cpu_has_userlocal)
  46. write_c0_userlocal(current_thread_info()->tp_value);
  47. /* Restore watch registers */
  48. __restore_watch();
  49. }
  50. /**
  51. * mips_pm_notifier() - Notifier for preserving general CPU context.
  52. * @self: Notifier block.
  53. * @cmd: CPU PM event.
  54. * @v: Private data (unused).
  55. *
  56. * This is called when a CPU power management event occurs, and is used to
  57. * ensure that important CPU context is preserved across a CPU power down.
  58. */
  59. static int mips_pm_notifier(struct notifier_block *self, unsigned long cmd,
  60. void *v)
  61. {
  62. int ret;
  63. switch (cmd) {
  64. case CPU_PM_ENTER:
  65. ret = mips_cpu_save();
  66. if (ret)
  67. return NOTIFY_STOP;
  68. break;
  69. case CPU_PM_ENTER_FAILED:
  70. case CPU_PM_EXIT:
  71. mips_cpu_restore();
  72. break;
  73. }
  74. return NOTIFY_OK;
  75. }
  76. static struct notifier_block mips_pm_notifier_block = {
  77. .notifier_call = mips_pm_notifier,
  78. };
  79. static int __init mips_pm_init(void)
  80. {
  81. return cpu_pm_register_notifier(&mips_pm_notifier_block);
  82. }
  83. arch_initcall(mips_pm_init);