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