sleep.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <linux/linkage.h>
  2. #include <linux/threads.h>
  3. #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. * Save CPU state for a suspend
  11. * r1 = v:p offset
  12. * r2 = suspend function arg0
  13. * r3 = suspend function
  14. */
  15. ENTRY(__cpu_suspend)
  16. stmfd sp!, {r4 - r11, lr}
  17. #ifdef MULTI_CPU
  18. ldr r10, =processor
  19. ldr r5, [r10, #CPU_SLEEP_SIZE] @ size of CPU sleep state
  20. ldr ip, [r10, #CPU_DO_RESUME] @ virtual resume function
  21. #else
  22. ldr r5, =cpu_suspend_size
  23. ldr ip, =cpu_do_resume
  24. #endif
  25. mov r6, sp @ current virtual SP
  26. sub sp, sp, r5 @ allocate CPU state on stack
  27. mov r0, sp @ save pointer to CPU save block
  28. add ip, ip, r1 @ convert resume fn to phys
  29. stmfd sp!, {r1, r6, ip} @ save v:p, virt SP, phys resume fn
  30. ldr r5, =sleep_save_sp
  31. add r6, sp, r1 @ convert SP to phys
  32. stmfd sp!, {r2, r3} @ save suspend func arg and pointer
  33. #ifdef CONFIG_SMP
  34. ALT_SMP(mrc p15, 0, lr, c0, c0, 5)
  35. ALT_UP(mov lr, #0)
  36. and lr, lr, #15
  37. str r6, [r5, lr, lsl #2] @ save phys SP
  38. #else
  39. str r6, [r5] @ save phys SP
  40. #endif
  41. #ifdef MULTI_CPU
  42. mov lr, pc
  43. ldr pc, [r10, #CPU_DO_SUSPEND] @ save CPU state
  44. #else
  45. bl cpu_do_suspend
  46. #endif
  47. @ flush data cache
  48. #ifdef MULTI_CACHE
  49. ldr r10, =cpu_cache
  50. mov lr, pc
  51. ldr pc, [r10, #CACHE_FLUSH_KERN_ALL]
  52. #else
  53. bl __cpuc_flush_kern_all
  54. #endif
  55. adr lr, BSYM(cpu_suspend_abort)
  56. ldmfd sp!, {r0, pc} @ call suspend fn
  57. ENDPROC(__cpu_suspend)
  58. .ltorg
  59. cpu_suspend_abort:
  60. ldmia sp!, {r1 - r3} @ pop v:p, virt SP, phys resume fn
  61. teq r0, #0
  62. moveq r0, #1 @ force non-zero value
  63. mov sp, r2
  64. ldmfd sp!, {r4 - r11, pc}
  65. ENDPROC(cpu_suspend_abort)
  66. /*
  67. * r0 = control register value
  68. * r1 = v:p offset (preserved by cpu_do_resume)
  69. * r2 = phys page table base
  70. * r3 = L1 section flags
  71. */
  72. ENTRY(cpu_resume_mmu)
  73. adr r4, cpu_resume_turn_mmu_on
  74. mov r4, r4, lsr #20
  75. orr r3, r3, r4, lsl #20
  76. ldr r5, [r2, r4, lsl #2] @ save old mapping
  77. str r3, [r2, r4, lsl #2] @ setup 1:1 mapping for mmu code
  78. sub r2, r2, r1
  79. ldr r3, =cpu_resume_after_mmu
  80. bic r1, r0, #CR_C @ ensure D-cache is disabled
  81. b cpu_resume_turn_mmu_on
  82. ENDPROC(cpu_resume_mmu)
  83. .ltorg
  84. .align 5
  85. cpu_resume_turn_mmu_on:
  86. mcr p15, 0, r1, c1, c0, 0 @ turn on MMU, I-cache, etc
  87. mrc p15, 0, r1, c0, c0, 0 @ read id reg
  88. mov r1, r1
  89. mov r1, r1
  90. mov pc, r3 @ jump to virtual address
  91. ENDPROC(cpu_resume_turn_mmu_on)
  92. cpu_resume_after_mmu:
  93. str r5, [r2, r4, lsl #2] @ restore old mapping
  94. mcr p15, 0, r0, c1, c0, 0 @ turn on D-cache
  95. bl cpu_init @ restore the und/abt/irq banked regs
  96. mov r0, #0 @ return zero on success
  97. ldmfd sp!, {r4 - r11, pc}
  98. ENDPROC(cpu_resume_after_mmu)
  99. /*
  100. * Note: Yes, part of the following code is located into the .data section.
  101. * This is to allow sleep_save_sp to be accessed with a relative load
  102. * while we can't rely on any MMU translation. We could have put
  103. * sleep_save_sp in the .text section as well, but some setups might
  104. * insist on it to be truly read-only.
  105. */
  106. .data
  107. .align
  108. ENTRY(cpu_resume)
  109. #ifdef CONFIG_SMP
  110. adr r0, sleep_save_sp
  111. ALT_SMP(mrc p15, 0, r1, c0, c0, 5)
  112. ALT_UP(mov r1, #0)
  113. and r1, r1, #15
  114. ldr r0, [r0, r1, lsl #2] @ stack phys addr
  115. #else
  116. ldr r0, sleep_save_sp @ stack phys addr
  117. #endif
  118. setmode PSR_I_BIT | PSR_F_BIT | SVC_MODE, r1 @ set SVC, irqs off
  119. @ load v:p, stack, resume fn
  120. ARM( ldmia r0!, {r1, sp, pc} )
  121. THUMB( ldmia r0!, {r1, r2, r3} )
  122. THUMB( mov sp, r2 )
  123. THUMB( bx r3 )
  124. ENDPROC(cpu_resume)
  125. sleep_save_sp:
  126. .rept CONFIG_NR_CPUS
  127. .long 0 @ preserve stack phys ptr here
  128. .endr