blob: c9a43caaea801fdabacf1c6f65562742eb26c094 [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
Russell Kingde8e71c2011-08-27 22:39:09 +010012 * r0 = phys addr of temporary page tables
Russell Kingf6b0fa02011-02-06 15:48:39 +000013 * r1 = v:p offset
Russell King3799bbe2011-06-13 15:28:40 +010014 * r2 = suspend function arg0
Russell Kinge8856a82011-06-13 15:58:34 +010015 * r3 = suspend function
Russell Kingf6b0fa02011-02-06 15:48:39 +000016 */
Russell King2c74a0c2011-06-22 17:41:48 +010017ENTRY(__cpu_suspend)
Russell Kinge8856a82011-06-13 15:58:34 +010018 stmfd sp!, {r4 - r11, lr}
Russell Kingde8e71c2011-08-27 22:39:09 +010019 mov r4, r0
Russell Kingf6b0fa02011-02-06 15:48:39 +000020#ifdef MULTI_CPU
21 ldr r10, =processor
Russell King8111eaa2011-06-13 15:25:11 +010022 ldr r5, [r10, #CPU_SLEEP_SIZE] @ size of CPU sleep state
Russell Kingf6b0fa02011-02-06 15:48:39 +000023 ldr ip, [r10, #CPU_DO_RESUME] @ virtual resume function
Russell King3fd431b2011-06-13 13:53:06 +010024#else
Russell King8111eaa2011-06-13 15:25:11 +010025 ldr r5, =cpu_suspend_size
Russell King3fd431b2011-06-13 13:53:06 +010026 ldr ip, =cpu_do_resume
27#endif
Russell King8111eaa2011-06-13 15:25:11 +010028 mov r6, sp @ current virtual SP
29 sub sp, sp, r5 @ allocate CPU state on stack
Russell King29cb3cd2011-07-02 09:54:01 +010030 mov r0, sp @ save pointer to CPU save block
Russell Kingf6b0fa02011-02-06 15:48:39 +000031 add ip, ip, r1 @ convert resume fn to phys
Russell Kingde8e71c2011-08-27 22:39:09 +010032 stmfd sp!, {r4, r6, ip} @ save phys pgd, virt SP, phys resume fn
Russell King8111eaa2011-06-13 15:25:11 +010033 ldr r5, =sleep_save_sp
34 add r6, sp, r1 @ convert SP to phys
Russell Kinge8856a82011-06-13 15:58:34 +010035 stmfd sp!, {r2, r3} @ save suspend func arg and pointer
Russell King941aefa2011-02-11 11:32:19 +000036#ifdef CONFIG_SMP
37 ALT_SMP(mrc p15, 0, lr, c0, c0, 5)
38 ALT_UP(mov lr, #0)
39 and lr, lr, #15
Russell King8111eaa2011-06-13 15:25:11 +010040 str r6, [r5, lr, lsl #2] @ save phys SP
Russell King941aefa2011-02-11 11:32:19 +000041#else
Russell King8111eaa2011-06-13 15:25:11 +010042 str r6, [r5] @ save phys SP
Russell King941aefa2011-02-11 11:32:19 +000043#endif
Russell King3fd431b2011-06-13 13:53:06 +010044#ifdef MULTI_CPU
Russell Kingf6b0fa02011-02-06 15:48:39 +000045 mov lr, pc
46 ldr pc, [r10, #CPU_DO_SUSPEND] @ save CPU state
47#else
Russell Kingf6b0fa02011-02-06 15:48:39 +000048 bl cpu_do_suspend
49#endif
50
51 @ flush data cache
52#ifdef MULTI_CACHE
53 ldr r10, =cpu_cache
Russell King3799bbe2011-06-13 15:28:40 +010054 mov lr, pc
Russell Kingf6b0fa02011-02-06 15:48:39 +000055 ldr pc, [r10, #CACHE_FLUSH_KERN_ALL]
56#else
Russell King3799bbe2011-06-13 15:28:40 +010057 bl __cpuc_flush_kern_all
Russell Kingf6b0fa02011-02-06 15:48:39 +000058#endif
Russell King29cb3cd2011-07-02 09:54:01 +010059 adr lr, BSYM(cpu_suspend_abort)
Russell King3799bbe2011-06-13 15:28:40 +010060 ldmfd sp!, {r0, pc} @ call suspend fn
Russell King2c74a0c2011-06-22 17:41:48 +010061ENDPROC(__cpu_suspend)
Russell Kingf6b0fa02011-02-06 15:48:39 +000062 .ltorg
63
Russell King29cb3cd2011-07-02 09:54:01 +010064cpu_suspend_abort:
Russell Kingde8e71c2011-08-27 22:39:09 +010065 ldmia sp!, {r1 - r3} @ pop phys pgd, virt SP, phys resume fn
Russell Kingf5fa68d2011-08-27 11:17:36 +010066 teq r0, #0
67 moveq r0, #1 @ force non-zero value
Russell King29cb3cd2011-07-02 09:54:01 +010068 mov sp, r2
69 ldmfd sp!, {r4 - r11, pc}
70ENDPROC(cpu_suspend_abort)
71
Russell Kingf6b0fa02011-02-06 15:48:39 +000072/*
73 * r0 = control register value
Russell Kingf6b0fa02011-02-06 15:48:39 +000074 */
Russell King62b2d072011-08-31 23:26:18 +010075 .align 5
Russell Kingf6b0fa02011-02-06 15:48:39 +000076ENTRY(cpu_resume_mmu)
Russell Kingf6b0fa02011-02-06 15:48:39 +000077 ldr r3, =cpu_resume_after_mmu
Russell Kinge8ce0eb2011-08-26 20:28:52 +010078 mcr p15, 0, r0, c1, c0, 0 @ turn on MMU, I-cache, etc
79 mrc p15, 0, r0, c0, c0, 0 @ read id reg
80 mov r0, r0
81 mov r0, r0
Russell Kingf6b0fa02011-02-06 15:48:39 +000082 mov pc, r3 @ jump to virtual address
Russell King62b2d072011-08-31 23:26:18 +010083ENDPROC(cpu_resume_mmu)
Russell Kingf6b0fa02011-02-06 15:48:39 +000084cpu_resume_after_mmu:
Russell King14cd8fd2011-06-21 16:32:58 +010085 bl cpu_init @ restore the und/abt/irq banked regs
Russell King29cb3cd2011-07-02 09:54:01 +010086 mov r0, #0 @ return zero on success
Russell King5fa94c82011-06-13 15:04:14 +010087 ldmfd sp!, {r4 - r11, pc}
Russell Kingf6b0fa02011-02-06 15:48:39 +000088ENDPROC(cpu_resume_after_mmu)
89
90/*
91 * Note: Yes, part of the following code is located into the .data section.
92 * This is to allow sleep_save_sp to be accessed with a relative load
93 * while we can't rely on any MMU translation. We could have put
94 * sleep_save_sp in the .text section as well, but some setups might
95 * insist on it to be truly read-only.
96 */
97 .data
98 .align
99ENTRY(cpu_resume)
Russell King941aefa2011-02-11 11:32:19 +0000100#ifdef CONFIG_SMP
101 adr r0, sleep_save_sp
102 ALT_SMP(mrc p15, 0, r1, c0, c0, 5)
103 ALT_UP(mov r1, #0)
104 and r1, r1, #15
105 ldr r0, [r0, r1, lsl #2] @ stack phys addr
106#else
Russell Kingf6b0fa02011-02-06 15:48:39 +0000107 ldr r0, sleep_save_sp @ stack phys addr
Russell King941aefa2011-02-11 11:32:19 +0000108#endif
Nicolas Pitrefb4fe872011-03-22 19:09:14 +0100109 setmode PSR_I_BIT | PSR_F_BIT | SVC_MODE, r1 @ set SVC, irqs off
Russell Kingde8e71c2011-08-27 22:39:09 +0100110 @ load phys pgd, stack, resume fn
111 ARM( ldmia r0!, {r1, sp, pc} )
112THUMB( ldmia r0!, {r1, r2, r3} )
113THUMB( mov sp, r2 )
114THUMB( bx r3 )
Russell Kingf6b0fa02011-02-06 15:48:39 +0000115ENDPROC(cpu_resume)
116
117sleep_save_sp:
Russell King941aefa2011-02-11 11:32:19 +0000118 .rept CONFIG_NR_CPUS
119 .long 0 @ preserve stack phys ptr here
120 .endr