pm.c 2.0 KB

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