blob: 1f268bda45528ebd0e52c88ddb9bdf40f5e12e03 [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/*
Russell Kingabda1bd2011-09-01 11:52:33 +010011 * Save CPU state for a suspend. This saves the CPU general purpose
12 * registers, and allocates space on the kernel stack to save the CPU
13 * specific registers and some other data for resume.
14 * r0 = suspend function arg0
15 * r1 = 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 Kingf6b0fa02011-02-06 15:48:39 +000019#ifdef MULTI_CPU
20 ldr r10, =processor
Russell Kingabda1bd2011-09-01 11:52:33 +010021 ldr r4, [r10, #CPU_SLEEP_SIZE] @ size of CPU sleep state
Russell King3fd431b2011-06-13 13:53:06 +010022#else
Russell Kingabda1bd2011-09-01 11:52:33 +010023 ldr r4, =cpu_suspend_size
Russell King3fd431b2011-06-13 13:53:06 +010024#endif
Russell Kingabda1bd2011-09-01 11:52:33 +010025 mov r5, sp @ current virtual SP
26 add r4, r4, #12 @ Space for pgd, virt sp, phys resume fn
27 sub sp, sp, r4 @ allocate CPU state on stack
28 stmfd sp!, {r0, r1} @ save suspend func arg and pointer
29 add r0, sp, #8 @ save pointer to save block
30 mov r1, r4 @ size of save block
31 mov r2, r5 @ virtual SP
32 ldr r3, =sleep_save_sp
Russell King941aefa2011-02-11 11:32:19 +000033#ifdef CONFIG_SMP
34 ALT_SMP(mrc p15, 0, lr, c0, c0, 5)
35 ALT_UP(mov lr, #0)
36 and lr, lr, #15
Russell Kingabda1bd2011-09-01 11:52:33 +010037 add r3, r3, lr, lsl #2
Russell King941aefa2011-02-11 11:32:19 +000038#endif
Russell Kingabda1bd2011-09-01 11:52:33 +010039 bl __cpu_suspend_save
Russell King29cb3cd2011-07-02 09:54:01 +010040 adr lr, BSYM(cpu_suspend_abort)
Russell King3799bbe2011-06-13 15:28:40 +010041 ldmfd sp!, {r0, pc} @ call suspend fn
Russell King2c74a0c2011-06-22 17:41:48 +010042ENDPROC(__cpu_suspend)
Russell Kingf6b0fa02011-02-06 15:48:39 +000043 .ltorg
44
Russell King29cb3cd2011-07-02 09:54:01 +010045cpu_suspend_abort:
Russell Kingde8e71c2011-08-27 22:39:09 +010046 ldmia sp!, {r1 - r3} @ pop phys pgd, virt SP, phys resume fn
Russell Kingf5fa68d2011-08-27 11:17:36 +010047 teq r0, #0
48 moveq r0, #1 @ force non-zero value
Russell King29cb3cd2011-07-02 09:54:01 +010049 mov sp, r2
50 ldmfd sp!, {r4 - r11, pc}
51ENDPROC(cpu_suspend_abort)
52
Russell Kingf6b0fa02011-02-06 15:48:39 +000053/*
54 * r0 = control register value
Russell Kingf6b0fa02011-02-06 15:48:39 +000055 */
Russell King62b2d072011-08-31 23:26:18 +010056 .align 5
Will Deacone6eadc62011-11-15 11:11:19 +000057 .pushsection .idmap.text,"ax"
Russell Kingf6b0fa02011-02-06 15:48:39 +000058ENTRY(cpu_resume_mmu)
Russell Kingf6b0fa02011-02-06 15:48:39 +000059 ldr r3, =cpu_resume_after_mmu
Will Deacond675d0b2011-11-22 17:30:28 +000060 instr_sync
Russell Kinge8ce0eb2011-08-26 20:28:52 +010061 mcr p15, 0, r0, c1, c0, 0 @ turn on MMU, I-cache, etc
62 mrc p15, 0, r0, c0, c0, 0 @ read id reg
Will Deacond675d0b2011-11-22 17:30:28 +000063 instr_sync
Russell Kinge8ce0eb2011-08-26 20:28:52 +010064 mov r0, r0
65 mov r0, r0
Russell Kingf6b0fa02011-02-06 15:48:39 +000066 mov pc, r3 @ jump to virtual address
Russell King62b2d072011-08-31 23:26:18 +010067ENDPROC(cpu_resume_mmu)
Will Deacone6eadc62011-11-15 11:11:19 +000068 .popsection
Russell Kingf6b0fa02011-02-06 15:48:39 +000069cpu_resume_after_mmu:
Russell King14cd8fd2011-06-21 16:32:58 +010070 bl cpu_init @ restore the und/abt/irq banked regs
Russell King29cb3cd2011-07-02 09:54:01 +010071 mov r0, #0 @ return zero on success
Russell King5fa94c82011-06-13 15:04:14 +010072 ldmfd sp!, {r4 - r11, pc}
Russell Kingf6b0fa02011-02-06 15:48:39 +000073ENDPROC(cpu_resume_after_mmu)
74
75/*
76 * Note: Yes, part of the following code is located into the .data section.
77 * This is to allow sleep_save_sp to be accessed with a relative load
78 * while we can't rely on any MMU translation. We could have put
79 * sleep_save_sp in the .text section as well, but some setups might
80 * insist on it to be truly read-only.
81 */
82 .data
83 .align
84ENTRY(cpu_resume)
Russell King941aefa2011-02-11 11:32:19 +000085#ifdef CONFIG_SMP
86 adr r0, sleep_save_sp
87 ALT_SMP(mrc p15, 0, r1, c0, c0, 5)
88 ALT_UP(mov r1, #0)
89 and r1, r1, #15
90 ldr r0, [r0, r1, lsl #2] @ stack phys addr
91#else
Russell Kingf6b0fa02011-02-06 15:48:39 +000092 ldr r0, sleep_save_sp @ stack phys addr
Russell King941aefa2011-02-11 11:32:19 +000093#endif
Nicolas Pitrefb4fe872011-03-22 19:09:14 +010094 setmode PSR_I_BIT | PSR_F_BIT | SVC_MODE, r1 @ set SVC, irqs off
Russell Kingde8e71c2011-08-27 22:39:09 +010095 @ load phys pgd, stack, resume fn
96 ARM( ldmia r0!, {r1, sp, pc} )
97THUMB( ldmia r0!, {r1, r2, r3} )
98THUMB( mov sp, r2 )
99THUMB( bx r3 )
Russell Kingf6b0fa02011-02-06 15:48:39 +0000100ENDPROC(cpu_resume)
101
102sleep_save_sp:
Russell King941aefa2011-02-11 11:32:19 +0000103 .rept CONFIG_NR_CPUS
104 .long 0 @ preserve stack phys ptr here
105 .endr