blob: f8e92513c1bd5a2255a11270779ec8baec930398 [file] [log] [blame]
Russell Kingf6b0fa02011-02-06 15:48:39 +00001#include <linux/linkage.h>
Russell King941aefa2011-02-11 11:32:19 +00002#include <linux/threads.h>
Russell Kingf6b0fa02011-02-06 15:48:39 +00003#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>
8 .text
9
10/*
11 * Save CPU state for a suspend
12 * r1 = v:p offset
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
16 */
17ENTRY(cpu_suspend)
Russell King2fefbcd2011-06-13 13:45:34 +010018 stmfd sp!, {r3}
Russell Kingf6b0fa02011-02-06 15:48:39 +000019 mov r9, lr
20#ifdef MULTI_CPU
21 ldr r10, =processor
22 mov r2, sp @ current virtual SP
23 ldr r0, [r10, #CPU_SLEEP_SIZE] @ size of CPU sleep state
24 ldr ip, [r10, #CPU_DO_RESUME] @ virtual resume function
25 sub sp, sp, r0 @ allocate CPU state on stack
26 mov r0, sp @ save pointer
27 add ip, ip, r1 @ convert resume fn to phys
Russell King2fefbcd2011-06-13 13:45:34 +010028 stmfd sp!, {r1, r2, ip} @ save v:p, virt SP, phys resume fn
Russell Kingf6b0fa02011-02-06 15:48:39 +000029 ldr r3, =sleep_save_sp
30 add r2, sp, r1 @ convert SP to phys
Russell King941aefa2011-02-11 11:32:19 +000031#ifdef CONFIG_SMP
32 ALT_SMP(mrc p15, 0, lr, c0, c0, 5)
33 ALT_UP(mov lr, #0)
34 and lr, lr, #15
35 str r2, [r3, lr, lsl #2] @ save phys SP
36#else
Russell Kingf6b0fa02011-02-06 15:48:39 +000037 str r2, [r3] @ save phys SP
Russell King941aefa2011-02-11 11:32:19 +000038#endif
Russell Kingf6b0fa02011-02-06 15:48:39 +000039 mov lr, pc
40 ldr pc, [r10, #CPU_DO_SUSPEND] @ save CPU state
41#else
42 mov r2, sp @ current virtual SP
43 ldr r0, =cpu_suspend_size
Russell King6b5f6ab2011-06-13 13:39:44 +010044 ldr ip, =cpu_do_resume
Russell Kingf6b0fa02011-02-06 15:48:39 +000045 sub sp, sp, r0 @ allocate CPU state on stack
46 mov r0, sp @ save pointer
Russell King6b5f6ab2011-06-13 13:39:44 +010047 add ip, ip, r1 @ convert resume fn to phys
Russell King2fefbcd2011-06-13 13:45:34 +010048 stmfd sp!, {r1, r2, ip} @ save v:p, virt SP, phys resume fn
Russell Kingf6b0fa02011-02-06 15:48:39 +000049 ldr r3, =sleep_save_sp
50 add r2, sp, r1 @ convert SP to phys
Russell King941aefa2011-02-11 11:32:19 +000051#ifdef CONFIG_SMP
52 ALT_SMP(mrc p15, 0, lr, c0, c0, 5)
53 ALT_UP(mov lr, #0)
54 and lr, lr, #15
55 str r2, [r3, lr, lsl #2] @ save phys SP
56#else
Russell Kingf6b0fa02011-02-06 15:48:39 +000057 str r2, [r3] @ save phys SP
Russell King941aefa2011-02-11 11:32:19 +000058#endif
Russell Kingf6b0fa02011-02-06 15:48:39 +000059 bl cpu_do_suspend
60#endif
61
62 @ flush data cache
63#ifdef MULTI_CACHE
64 ldr r10, =cpu_cache
65 mov lr, r9
66 ldr pc, [r10, #CACHE_FLUSH_KERN_ALL]
67#else
68 mov lr, r9
69 b __cpuc_flush_kern_all
70#endif
71ENDPROC(cpu_suspend)
72 .ltorg
73
74/*
75 * r0 = control register value
76 * r1 = v:p offset (preserved by cpu_do_resume)
77 * r2 = phys page table base
78 * r3 = L1 section flags
79 */
80ENTRY(cpu_resume_mmu)
81 adr r4, cpu_resume_turn_mmu_on
82 mov r4, r4, lsr #20
83 orr r3, r3, r4, lsl #20
84 ldr r5, [r2, r4, lsl #2] @ save old mapping
85 str r3, [r2, r4, lsl #2] @ setup 1:1 mapping for mmu code
86 sub r2, r2, r1
87 ldr r3, =cpu_resume_after_mmu
88 bic r1, r0, #CR_C @ ensure D-cache is disabled
89 b cpu_resume_turn_mmu_on
90ENDPROC(cpu_resume_mmu)
91 .ltorg
92 .align 5
93cpu_resume_turn_mmu_on:
94 mcr p15, 0, r1, c1, c0, 0 @ turn on MMU, I-cache, etc
95 mrc p15, 0, r1, c0, c0, 0 @ read id reg
96 mov r1, r1
97 mov r1, r1
98 mov pc, r3 @ jump to virtual address
99ENDPROC(cpu_resume_turn_mmu_on)
100cpu_resume_after_mmu:
101 str r5, [r2, r4, lsl #2] @ restore old mapping
102 mcr p15, 0, r0, c1, c0, 0 @ turn on D-cache
Russell King2fefbcd2011-06-13 13:45:34 +0100103 ldmfd sp!, {pc}
Russell Kingf6b0fa02011-02-06 15:48:39 +0000104ENDPROC(cpu_resume_after_mmu)
105
106/*
107 * Note: Yes, part of the following code is located into the .data section.
108 * This is to allow sleep_save_sp to be accessed with a relative load
109 * while we can't rely on any MMU translation. We could have put
110 * sleep_save_sp in the .text section as well, but some setups might
111 * insist on it to be truly read-only.
112 */
113 .data
114 .align
115ENTRY(cpu_resume)
Russell King941aefa2011-02-11 11:32:19 +0000116#ifdef CONFIG_SMP
117 adr r0, sleep_save_sp
118 ALT_SMP(mrc p15, 0, r1, c0, c0, 5)
119 ALT_UP(mov r1, #0)
120 and r1, r1, #15
121 ldr r0, [r0, r1, lsl #2] @ stack phys addr
122#else
Russell Kingf6b0fa02011-02-06 15:48:39 +0000123 ldr r0, sleep_save_sp @ stack phys addr
Russell King941aefa2011-02-11 11:32:19 +0000124#endif
Nicolas Pitrefb4fe872011-03-22 19:09:14 +0100125 setmode PSR_I_BIT | PSR_F_BIT | SVC_MODE, r1 @ set SVC, irqs off
Russell King2fefbcd2011-06-13 13:45:34 +0100126 @ load v:p, stack, resume fn
127 ARM( ldmia r0!, {r1, sp, pc} )
128THUMB( ldmia r0!, {r1, r2, r3} )
Nicolas Pitrefb4fe872011-03-22 19:09:14 +0100129THUMB( mov sp, r2 )
Russell King2fefbcd2011-06-13 13:45:34 +0100130THUMB( bx r3 )
Russell Kingf6b0fa02011-02-06 15:48:39 +0000131ENDPROC(cpu_resume)
132
133sleep_save_sp:
Russell King941aefa2011-02-11 11:32:19 +0000134 .rept CONFIG_NR_CPUS
135 .long 0 @ preserve stack phys ptr here
136 .endr