blob: 8cf13de1e36844322a6c047eac3742b3eda2786f [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
Russell King3799bbe2011-06-13 15:28:40 +010013 * r2 = suspend function arg0
Russell Kinge8856a82011-06-13 15:58:34 +010014 * r3 = suspend function
Russell Kingf6b0fa02011-02-06 15:48:39 +000015 */
Russell King2c74a0c2011-06-22 17:41:48 +010016ENTRY(__cpu_suspend)
Russell Kinge8856a82011-06-13 15:58:34 +010017 stmfd sp!, {r4 - r11, lr}
Russell Kingf6b0fa02011-02-06 15:48:39 +000018#ifdef MULTI_CPU
19 ldr r10, =processor
Russell King8111eaa2011-06-13 15:25:11 +010020 ldr r5, [r10, #CPU_SLEEP_SIZE] @ size of CPU sleep state
Russell Kingf6b0fa02011-02-06 15:48:39 +000021 ldr ip, [r10, #CPU_DO_RESUME] @ virtual resume function
Russell King3fd431b2011-06-13 13:53:06 +010022#else
Russell King8111eaa2011-06-13 15:25:11 +010023 ldr r5, =cpu_suspend_size
Russell King3fd431b2011-06-13 13:53:06 +010024 ldr ip, =cpu_do_resume
25#endif
Russell King8111eaa2011-06-13 15:25:11 +010026 mov r6, sp @ current virtual SP
27 sub sp, sp, r5 @ allocate CPU state on stack
Russell King29cb3cd2011-07-02 09:54:01 +010028 mov r0, sp @ save pointer to CPU save block
Russell Kingf6b0fa02011-02-06 15:48:39 +000029 add ip, ip, r1 @ convert resume fn to phys
Russell Kinge8ce0eb2011-08-26 20:28:52 +010030 stmfd sp!, {r6, ip} @ save virt SP, phys resume fn
Russell King8111eaa2011-06-13 15:25:11 +010031 ldr r5, =sleep_save_sp
32 add r6, sp, r1 @ convert SP to phys
Russell Kinge8856a82011-06-13 15:58:34 +010033 stmfd sp!, {r2, r3} @ save suspend func arg and pointer
Russell King941aefa2011-02-11 11:32:19 +000034#ifdef CONFIG_SMP
35 ALT_SMP(mrc p15, 0, lr, c0, c0, 5)
36 ALT_UP(mov lr, #0)
37 and lr, lr, #15
Russell King8111eaa2011-06-13 15:25:11 +010038 str r6, [r5, lr, lsl #2] @ save phys SP
Russell King941aefa2011-02-11 11:32:19 +000039#else
Russell King8111eaa2011-06-13 15:25:11 +010040 str r6, [r5] @ save phys SP
Russell King941aefa2011-02-11 11:32:19 +000041#endif
Russell King3fd431b2011-06-13 13:53:06 +010042#ifdef MULTI_CPU
Russell Kingf6b0fa02011-02-06 15:48:39 +000043 mov lr, pc
44 ldr pc, [r10, #CPU_DO_SUSPEND] @ save CPU state
45#else
Russell Kingf6b0fa02011-02-06 15:48:39 +000046 bl cpu_do_suspend
47#endif
48
49 @ flush data cache
50#ifdef MULTI_CACHE
51 ldr r10, =cpu_cache
Russell King3799bbe2011-06-13 15:28:40 +010052 mov lr, pc
Russell Kingf6b0fa02011-02-06 15:48:39 +000053 ldr pc, [r10, #CACHE_FLUSH_KERN_ALL]
54#else
Russell King3799bbe2011-06-13 15:28:40 +010055 bl __cpuc_flush_kern_all
Russell Kingf6b0fa02011-02-06 15:48:39 +000056#endif
Russell King29cb3cd2011-07-02 09:54:01 +010057 adr lr, BSYM(cpu_suspend_abort)
Russell King3799bbe2011-06-13 15:28:40 +010058 ldmfd sp!, {r0, pc} @ call suspend fn
Russell King2c74a0c2011-06-22 17:41:48 +010059ENDPROC(__cpu_suspend)
Russell Kingf6b0fa02011-02-06 15:48:39 +000060 .ltorg
61
Russell King29cb3cd2011-07-02 09:54:01 +010062cpu_suspend_abort:
Russell Kinge8ce0eb2011-08-26 20:28:52 +010063 ldmia sp!, {r2 - r3} @ pop virt SP, phys resume fn
Russell Kingf5fa68d2011-08-27 11:17:36 +010064 teq r0, #0
65 moveq r0, #1 @ force non-zero value
Russell King29cb3cd2011-07-02 09:54:01 +010066 mov sp, r2
67 ldmfd sp!, {r4 - r11, pc}
68ENDPROC(cpu_suspend_abort)
69
Russell Kingf6b0fa02011-02-06 15:48:39 +000070/*
71 * r0 = control register value
72 * r1 = v:p offset (preserved by cpu_do_resume)
73 * r2 = phys page table base
74 * r3 = L1 section flags
75 */
76ENTRY(cpu_resume_mmu)
Russell Kingf6b0fa02011-02-06 15:48:39 +000077 ldr r3, =cpu_resume_after_mmu
Russell Kingf6b0fa02011-02-06 15:48:39 +000078 b cpu_resume_turn_mmu_on
79ENDPROC(cpu_resume_mmu)
80 .ltorg
81 .align 5
Russell Kinge8ce0eb2011-08-26 20:28:52 +010082ENTRY(cpu_resume_turn_mmu_on)
83 mcr p15, 0, r0, c1, c0, 0 @ turn on MMU, I-cache, etc
84 mrc p15, 0, r0, c0, c0, 0 @ read id reg
85 mov r0, r0
86 mov r0, r0
Russell Kingf6b0fa02011-02-06 15:48:39 +000087 mov pc, r3 @ jump to virtual address
88ENDPROC(cpu_resume_turn_mmu_on)
89cpu_resume_after_mmu:
Russell King14cd8fd2011-06-21 16:32:58 +010090 bl cpu_init @ restore the und/abt/irq banked regs
Russell King29cb3cd2011-07-02 09:54:01 +010091 mov r0, #0 @ return zero on success
Russell King5fa94c82011-06-13 15:04:14 +010092 ldmfd sp!, {r4 - r11, pc}
Russell Kingf6b0fa02011-02-06 15:48:39 +000093ENDPROC(cpu_resume_after_mmu)
94
95/*
96 * Note: Yes, part of the following code is located into the .data section.
97 * This is to allow sleep_save_sp to be accessed with a relative load
98 * while we can't rely on any MMU translation. We could have put
99 * sleep_save_sp in the .text section as well, but some setups might
100 * insist on it to be truly read-only.
101 */
102 .data
103 .align
104ENTRY(cpu_resume)
Russell King941aefa2011-02-11 11:32:19 +0000105#ifdef CONFIG_SMP
106 adr r0, sleep_save_sp
107 ALT_SMP(mrc p15, 0, r1, c0, c0, 5)
108 ALT_UP(mov r1, #0)
109 and r1, r1, #15
110 ldr r0, [r0, r1, lsl #2] @ stack phys addr
111#else
Russell Kingf6b0fa02011-02-06 15:48:39 +0000112 ldr r0, sleep_save_sp @ stack phys addr
Russell King941aefa2011-02-11 11:32:19 +0000113#endif
Nicolas Pitrefb4fe872011-03-22 19:09:14 +0100114 setmode PSR_I_BIT | PSR_F_BIT | SVC_MODE, r1 @ set SVC, irqs off
Russell Kinge8ce0eb2011-08-26 20:28:52 +0100115 @ load stack, resume fn
116 ARM( ldmia r0!, {sp, pc} )
117THUMB( ldmia r0!, {r2, r3} )
118THUMB( mov sp, r2 )
119THUMB( bx r3 )
Russell Kingf6b0fa02011-02-06 15:48:39 +0000120ENDPROC(cpu_resume)
121
122sleep_save_sp:
Russell King941aefa2011-02-11 11:32:19 +0000123 .rept CONFIG_NR_CPUS
124 .long 0 @ preserve stack phys ptr here
125 .endr