0001
0002 #include <linux/ftrace.h>
0003 #include <linux/init.h>
0004 #include <linux/slab.h>
0005 #include <linux/mm_types.h>
0006 #include <linux/pgtable.h>
0007
0008 #include <asm/bugs.h>
0009 #include <asm/cacheflush.h>
0010 #include <asm/idmap.h>
0011 #include <asm/memory.h>
0012 #include <asm/smp_plat.h>
0013 #include <asm/suspend.h>
0014 #include <asm/tlbflush.h>
0015
0016 extern int __cpu_suspend(unsigned long, int (*)(unsigned long), u32 cpuid);
0017 extern void cpu_resume_mmu(void);
0018
0019 #ifdef CONFIG_MMU
0020 int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
0021 {
0022 struct mm_struct *mm = current->active_mm;
0023 u32 __mpidr = cpu_logical_map(smp_processor_id());
0024 int ret;
0025
0026 if (!idmap_pgd)
0027 return -EINVAL;
0028
0029
0030
0031
0032
0033
0034 pause_graph_tracing();
0035
0036
0037
0038
0039
0040
0041
0042 ret = __cpu_suspend(arg, fn, __mpidr);
0043
0044 unpause_graph_tracing();
0045
0046 if (ret == 0) {
0047 cpu_switch_mm(mm->pgd, mm);
0048 local_flush_bp_all();
0049 local_flush_tlb_all();
0050 check_other_bugs();
0051 }
0052
0053 return ret;
0054 }
0055 #else
0056 int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
0057 {
0058 u32 __mpidr = cpu_logical_map(smp_processor_id());
0059 int ret;
0060
0061 pause_graph_tracing();
0062 ret = __cpu_suspend(arg, fn, __mpidr);
0063 unpause_graph_tracing();
0064
0065 return ret;
0066 }
0067 #define idmap_pgd NULL
0068 #endif
0069
0070
0071
0072
0073
0074
0075 void __cpu_suspend_save(u32 *ptr, u32 ptrsz, u32 sp, u32 *save_ptr)
0076 {
0077 u32 *ctx = ptr;
0078
0079 *save_ptr = virt_to_phys(ptr);
0080
0081
0082 *ptr++ = virt_to_phys(idmap_pgd);
0083 *ptr++ = sp;
0084 *ptr++ = virt_to_phys(cpu_do_resume);
0085
0086 cpu_do_suspend(ptr);
0087
0088 flush_cache_louis();
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 __cpuc_flush_dcache_area(ctx, ptrsz);
0100 __cpuc_flush_dcache_area(save_ptr, sizeof(*save_ptr));
0101
0102 outer_clean_range(*save_ptr, *save_ptr + ptrsz);
0103 outer_clean_range(virt_to_phys(save_ptr),
0104 virt_to_phys(save_ptr) + sizeof(*save_ptr));
0105 }
0106
0107 extern struct sleep_save_sp sleep_save_sp;
0108
0109 static int cpu_suspend_alloc_sp(void)
0110 {
0111 void *ctx_ptr;
0112
0113 ctx_ptr = kcalloc(mpidr_hash_size(), sizeof(u32), GFP_KERNEL);
0114
0115 if (WARN_ON(!ctx_ptr))
0116 return -ENOMEM;
0117 sleep_save_sp.save_ptr_stash = ctx_ptr;
0118 sleep_save_sp.save_ptr_stash_phys = virt_to_phys(ctx_ptr);
0119 sync_cache_w(&sleep_save_sp);
0120 return 0;
0121 }
0122 early_initcall(cpu_suspend_alloc_sp);