1 #include <linux/linkage.h>
2 #include <linux/threads.h>
3 #include <asm/asm-offsets.h>
4 #include <asm/assembler.h>
5 #include <asm/glue-cache.h>
6 #include <asm/glue-proc.h>
7 #include <asm/system.h>
11 * Save CPU state for a suspend
13 * r3 = virtual return function
14 * Note: sp is decremented to allocate space for CPU state on stack
15 * r0-r3,r9,r10,lr corrupted
21 mov r2, sp @ current virtual SP
22 ldr r0, [r10, #CPU_SLEEP_SIZE] @ size of CPU sleep state
23 ldr ip, [r10, #CPU_DO_RESUME] @ virtual resume function
24 sub sp, sp, r0 @ allocate CPU state on stack
25 mov r0, sp @ save pointer
26 add ip, ip, r1 @ convert resume fn to phys
27 stmfd sp!, {r1, r2, r3, ip} @ save v:p, virt SP, retfn, phys resume fn
28 ldr r3, =sleep_save_sp
29 add r2, sp, r1 @ convert SP to phys
31 ALT_SMP(mrc p15, 0, lr, c0, c0, 5)
34 str r2, [r3, lr, lsl #2] @ save phys SP
36 str r2, [r3] @ save phys SP
39 ldr pc, [r10, #CPU_DO_SUSPEND] @ save CPU state
41 mov r2, sp @ current virtual SP
42 ldr r0, =cpu_suspend_size
43 sub sp, sp, r0 @ allocate CPU state on stack
44 mov r0, sp @ save pointer
45 stmfd sp!, {r1, r2, r3} @ save v:p, virt SP, return fn
46 ldr r3, =sleep_save_sp
47 add r2, sp, r1 @ convert SP to phys
49 ALT_SMP(mrc p15, 0, lr, c0, c0, 5)
52 str r2, [r3, lr, lsl #2] @ save phys SP
54 str r2, [r3] @ save phys SP
63 ldr pc, [r10, #CACHE_FLUSH_KERN_ALL]
66 b __cpuc_flush_kern_all
72 * r0 = control register value
73 * r1 = v:p offset (preserved by cpu_do_resume)
74 * r2 = phys page table base
75 * r3 = L1 section flags
78 adr r4, cpu_resume_turn_mmu_on
80 orr r3, r3, r4, lsl #20
81 ldr r5, [r2, r4, lsl #2] @ save old mapping
82 str r3, [r2, r4, lsl #2] @ setup 1:1 mapping for mmu code
84 ldr r3, =cpu_resume_after_mmu
85 bic r1, r0, #CR_C @ ensure D-cache is disabled
86 b cpu_resume_turn_mmu_on
87 ENDPROC(cpu_resume_mmu)
90 cpu_resume_turn_mmu_on:
91 mcr p15, 0, r1, c1, c0, 0 @ turn on MMU, I-cache, etc
92 mrc p15, 0, r1, c0, c0, 0 @ read id reg
95 mov pc, r3 @ jump to virtual address
96 ENDPROC(cpu_resume_turn_mmu_on)
98 str r5, [r2, r4, lsl #2] @ restore old mapping
99 mcr p15, 0, r0, c1, c0, 0 @ turn on D-cache
101 ENDPROC(cpu_resume_after_mmu)
104 * Note: Yes, part of the following code is located into the .data section.
105 * This is to allow sleep_save_sp to be accessed with a relative load
106 * while we can't rely on any MMU translation. We could have put
107 * sleep_save_sp in the .text section as well, but some setups might
108 * insist on it to be truly read-only.
114 adr r0, sleep_save_sp
115 ALT_SMP(mrc p15, 0, r1, c0, c0, 5)
118 ldr r0, [r0, r1, lsl #2] @ stack phys addr
120 ldr r0, sleep_save_sp @ stack phys addr
122 setmode PSR_I_BIT | PSR_F_BIT | SVC_MODE, r1 @ set SVC, irqs off
124 @ load v:p, stack, return fn, resume fn
125 ARM( ldmia r0!, {r1, sp, lr, pc} )
126 THUMB( ldmia r0!, {r1, r2, r3, r4} )
131 @ load v:p, stack, return fn
132 ARM( ldmia r0!, {r1, sp, lr} )
133 THUMB( ldmia r0!, {r1, r2, lr} )
141 .long 0 @ preserve stack phys ptr here