blob: 25d42dfb0a92a0b0fb5e10982c03f067c4c0fac6 [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 */
75ENTRY(cpu_resume_mmu)
Russell Kingf6b0fa02011-02-06 15:48:39 +000076 ldr r3, =cpu_resume_after_mmu
Russell Kingf6b0fa02011-02-06 15:48:39 +000077 b cpu_resume_turn_mmu_on
78ENDPROC(cpu_resume_mmu)
79 .ltorg
80 .align 5
Russell Kinge8ce0eb2011-08-26 20:28:52 +010081ENTRY(cpu_resume_turn_mmu_on)
82 mcr p15, 0, r0, c1, c0, 0 @ turn on MMU, I-cache, etc
83 mrc p15, 0, r0, c0, c0, 0 @ read id reg
84 mov r0, r0
85 mov r0, r0
Russell Kingf6b0fa02011-02-06 15:48:39 +000086 mov pc, r3 @ jump to virtual address
87ENDPROC(cpu_resume_turn_mmu_on)
88cpu_resume_after_mmu:
Russell King14cd8fd2011-06-21 16:32:58 +010089 bl cpu_init @ restore the und/abt/irq banked regs
Russell King29cb3cd2011-07-02 09:54:01 +010090 mov r0, #0 @ return zero on success
Russell King5fa94c82011-06-13 15:04:14 +010091 ldmfd sp!, {r4 - r11, pc}
Russell Kingf6b0fa02011-02-06 15:48:39 +000092ENDPROC(cpu_resume_after_mmu)
93
94/*
95 * Note: Yes, part of the following code is located into the .data section.
96 * This is to allow sleep_save_sp to be accessed with a relative load
97 * while we can't rely on any MMU translation. We could have put
98 * sleep_save_sp in the .text section as well, but some setups might
99 * insist on it to be truly read-only.
100 */
101 .data
102 .align
103ENTRY(cpu_resume)
Russell King941aefa2011-02-11 11:32:19 +0000104#ifdef CONFIG_SMP
105 adr r0, sleep_save_sp
106 ALT_SMP(mrc p15, 0, r1, c0, c0, 5)
107 ALT_UP(mov r1, #0)
108 and r1, r1, #15
109 ldr r0, [r0, r1, lsl #2] @ stack phys addr
110#else
Russell Kingf6b0fa02011-02-06 15:48:39 +0000111 ldr r0, sleep_save_sp @ stack phys addr
Russell King941aefa2011-02-11 11:32:19 +0000112#endif
Nicolas Pitrefb4fe872011-03-22 19:09:14 +0100113 setmode PSR_I_BIT | PSR_F_BIT | SVC_MODE, r1 @ set SVC, irqs off
Russell Kingde8e71c2011-08-27 22:39:09 +0100114 @ load phys pgd, stack, resume fn
115 ARM( ldmia r0!, {r1, sp, pc} )
116THUMB( ldmia r0!, {r1, r2, r3} )
117THUMB( mov sp, r2 )
118THUMB( bx r3 )
Russell Kingf6b0fa02011-02-06 15:48:39 +0000119ENDPROC(cpu_resume)
120
121sleep_save_sp:
Russell King941aefa2011-02-11 11:32:19 +0000122 .rept CONFIG_NR_CPUS
123 .long 0 @ preserve stack phys ptr here
124 .endr