aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/kernel/pm.c
diff options
context:
space:
mode:
authorJames Hogan <james.hogan@imgtec.com>2014-03-04 05:11:39 -0500
committerPaul Burton <paul.burton@imgtec.com>2014-04-24 10:15:54 -0400
commitb1d4c6cac02808b1d4e84d0187dc6014bffd2446 (patch)
tree6a3dcb67c7ea0b44616efa3a1b2fcb327551775f /arch/mips/kernel/pm.c
parenta798c10faf62a505d24e5f6213fbaf904a39623f (diff)
MIPS: PM: Add CPU PM callbacks for general CPU context
Add a CPU power management notifier callback for preserving general CPU context. The CPU PM callbacks will be triggered by the powering down of CPU cores, for example by cpuidle drivers & in the future by suspend to RAM implementations. The current state preserved is mostly related to the process context: - FPU - DSP - ASID - UserLocal - Watch registers Signed-off-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Diffstat (limited to 'arch/mips/kernel/pm.c')
-rw-r--r--arch/mips/kernel/pm.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/arch/mips/kernel/pm.c b/arch/mips/kernel/pm.c
new file mode 100644
index 000000000000..112903f36b89
--- /dev/null
+++ b/arch/mips/kernel/pm.c
@@ -0,0 +1,95 @@
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
12#include <linux/cpu_pm.h>
13#include <linux/init.h>
14
15#include <asm/dsp.h>
16#include <asm/fpu.h>
17#include <asm/mmu_context.h>
18#include <asm/watch.h>
19
20/**
21 * mips_cpu_save() - Save general CPU state.
22 * Ensures that general CPU context is saved, notably FPU and DSP.
23 */
24static int mips_cpu_save(void)
25{
26 /* Save FPU state */
27 lose_fpu(1);
28
29 /* Save DSP state */
30 save_dsp(current);
31
32 return 0;
33}
34
35/**
36 * mips_cpu_restore() - Restore general CPU state.
37 * Restores important CPU context.
38 */
39static void mips_cpu_restore(void)
40{
41 unsigned int cpu = smp_processor_id();
42
43 /* Restore ASID */
44 if (current->mm)
45 write_c0_entryhi(cpu_asid(cpu, current->mm));
46
47 /* Restore DSP state */
48 restore_dsp(current);
49
50 /* Restore UserLocal */
51 if (cpu_has_userlocal)
52 write_c0_userlocal(current_thread_info()->tp_value);
53
54 /* Restore watch registers */
55 __restore_watch();
56}
57
58/**
59 * mips_pm_notifier() - Notifier for preserving general CPU context.
60 * @self: Notifier block.
61 * @cmd: CPU PM event.
62 * @v: Private data (unused).
63 *
64 * This is called when a CPU power management event occurs, and is used to
65 * ensure that important CPU context is preserved across a CPU power down.
66 */
67static int mips_pm_notifier(struct notifier_block *self, unsigned long cmd,
68 void *v)
69{
70 int ret;
71
72 switch (cmd) {
73 case CPU_PM_ENTER:
74 ret = mips_cpu_save();
75 if (ret)
76 return NOTIFY_STOP;
77 break;
78 case CPU_PM_ENTER_FAILED:
79 case CPU_PM_EXIT:
80 mips_cpu_restore();
81 break;
82 }
83
84 return NOTIFY_OK;
85}
86
87static struct notifier_block mips_pm_notifier_block = {
88 .notifier_call = mips_pm_notifier,
89};
90
91static int __init mips_pm_init(void)
92{
93 return cpu_pm_register_notifier(&mips_pm_notifier_block);
94}
95arch_initcall(mips_pm_init);