sleep.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. .text
  8. /*
  9. * Implementation of MPIDR hash algorithm through shifting
  10. * and OR'ing.
  11. *
  12. * @dst: register containing hash result
  13. * @rs0: register containing affinity level 0 bit shift
  14. * @rs1: register containing affinity level 1 bit shift
  15. * @rs2: register containing affinity level 2 bit shift
  16. * @mpidr: register containing MPIDR value
  17. * @mask: register containing MPIDR mask
  18. *
  19. * Pseudo C-code:
  20. *
  21. *u32 dst;
  22. *
  23. *compute_mpidr_hash(u32 rs0, u32 rs1, u32 rs2, u32 mpidr, u32 mask) {
  24. * u32 aff0, aff1, aff2;
  25. * u32 mpidr_masked = mpidr & mask;
  26. * aff0 = mpidr_masked & 0xff;
  27. * aff1 = mpidr_masked & 0xff00;
  28. * aff2 = mpidr_masked & 0xff0000;
  29. * dst = (aff0 >> rs0 | aff1 >> rs1 | aff2 >> rs2);
  30. *}
  31. * Input registers: rs0, rs1, rs2, mpidr, mask
  32. * Output register: dst
  33. * Note: input and output registers must be disjoint register sets
  34. (eg: a macro instance with mpidr = r1 and dst = r1 is invalid)
  35. */
  36. .macro compute_mpidr_hash dst, rs0, rs1, rs2, mpidr, mask
  37. and \mpidr, \mpidr, \mask @ mask out MPIDR bits
  38. and \dst, \mpidr, #0xff @ mask=aff0
  39. ARM( mov \dst, \dst, lsr \rs0 ) @ dst=aff0>>rs0
  40. THUMB( lsr \dst, \dst, \rs0 )
  41. and \mask, \mpidr, #0xff00 @ mask = aff1
  42. ARM( orr \dst, \dst, \mask, lsr \rs1 ) @ dst|=(aff1>>rs1)
  43. THUMB( lsr \mask, \mask, \rs1 )
  44. THUMB( orr \dst, \dst, \mask )
  45. and \mask, \mpidr, #0xff0000 @ mask = aff2
  46. ARM( orr \dst, \dst, \mask, lsr \rs2 ) @ dst|=(aff2>>rs2)
  47. THUMB( lsr \mask, \mask, \rs2 )
  48. THUMB( orr \dst, \dst, \mask )
  49. .endm
  50. /*
  51. * Save CPU state for a suspend. This saves the CPU general purpose
  52. * registers, and allocates space on the kernel stack to save the CPU
  53. * specific registers and some other data for resume.
  54. * r0 = suspend function arg0
  55. * r1 = suspend function
  56. * r2 = MPIDR value the resuming CPU will use
  57. */
  58. ENTRY(__cpu_suspend)
  59. stmfd sp!, {r4 - r11, lr}
  60. #ifdef MULTI_CPU
  61. ldr r10, =processor
  62. ldr r4, [r10, #CPU_SLEEP_SIZE] @ size of CPU sleep state
  63. #else
  64. ldr r4, =cpu_suspend_size
  65. #endif
  66. mov r5, sp @ current virtual SP
  67. add r4, r4, #12 @ Space for pgd, virt sp, phys resume fn
  68. sub sp, sp, r4 @ allocate CPU state on stack
  69. ldr r3, =sleep_save_sp
  70. stmfd sp!, {r0, r1} @ save suspend func arg and pointer
  71. ldr r3, [r3, #SLEEP_SAVE_SP_VIRT]
  72. ALT_SMP(ldr r0, =mpidr_hash)
  73. ALT_UP_B(1f)
  74. /* This ldmia relies on the memory layout of the mpidr_hash struct */
  75. ldmia r0, {r1, r6-r8} @ r1 = mpidr mask (r6,r7,r8) = l[0,1,2] shifts
  76. compute_mpidr_hash r0, r6, r7, r8, r2, r1
  77. add r3, r3, r0, lsl #2
  78. 1: mov r2, r5 @ virtual SP
  79. mov r1, r4 @ size of save block
  80. add r0, sp, #8 @ pointer to save block
  81. bl __cpu_suspend_save
  82. badr lr, cpu_suspend_abort
  83. ldmfd sp!, {r0, pc} @ call suspend fn
  84. ENDPROC(__cpu_suspend)
  85. .ltorg
  86. cpu_suspend_abort:
  87. ldmia sp!, {r1 - r3} @ pop phys pgd, virt SP, phys resume fn
  88. teq r0, #0
  89. moveq r0, #1 @ force non-zero value
  90. mov sp, r2
  91. ldmfd sp!, {r4 - r11, pc}
  92. ENDPROC(cpu_suspend_abort)
  93. /*
  94. * r0 = control register value
  95. */
  96. .align 5
  97. .pushsection .idmap.text,"ax"
  98. ENTRY(cpu_resume_mmu)
  99. ldr r3, =cpu_resume_after_mmu
  100. instr_sync
  101. mcr p15, 0, r0, c1, c0, 0 @ turn on MMU, I-cache, etc
  102. mrc p15, 0, r0, c0, c0, 0 @ read id reg
  103. instr_sync
  104. mov r0, r0
  105. mov r0, r0
  106. ret r3 @ jump to virtual address
  107. ENDPROC(cpu_resume_mmu)
  108. .popsection
  109. cpu_resume_after_mmu:
  110. bl cpu_init @ restore the und/abt/irq banked regs
  111. mov r0, #0 @ return zero on success
  112. ldmfd sp!, {r4 - r11, pc}
  113. ENDPROC(cpu_resume_after_mmu)
  114. .text
  115. .align
  116. #ifdef CONFIG_MMU
  117. .arm
  118. ENTRY(cpu_resume_arm)
  119. THUMB( badr r9, 1f ) @ Kernel is entered in ARM.
  120. THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
  121. THUMB( .thumb ) @ switch to Thumb now.
  122. THUMB(1: )
  123. #endif
  124. ENTRY(cpu_resume)
  125. ARM_BE8(setend be) @ ensure we are in BE mode
  126. #ifdef CONFIG_ARM_VIRT_EXT
  127. bl __hyp_stub_install_secondary
  128. #endif
  129. safe_svcmode_maskall r1
  130. mov r1, #0
  131. ALT_SMP(mrc p15, 0, r0, c0, c0, 5)
  132. ALT_UP_B(1f)
  133. adr r2, mpidr_hash_ptr
  134. ldr r3, [r2]
  135. add r2, r2, r3 @ r2 = struct mpidr_hash phys address
  136. /*
  137. * This ldmia relies on the memory layout of the mpidr_hash
  138. * struct mpidr_hash.
  139. */
  140. ldmia r2, { r3-r6 } @ r3 = mpidr mask (r4,r5,r6) = l[0,1,2] shifts
  141. compute_mpidr_hash r1, r4, r5, r6, r0, r3
  142. 1:
  143. adr r0, _sleep_save_sp
  144. ldr r2, [r0]
  145. add r0, r0, r2
  146. ldr r0, [r0, #SLEEP_SAVE_SP_PHYS]
  147. ldr r0, [r0, r1, lsl #2]
  148. @ load phys pgd, stack, resume fn
  149. ARM( ldmia r0!, {r1, sp, pc} )
  150. THUMB( ldmia r0!, {r1, r2, r3} )
  151. THUMB( mov sp, r2 )
  152. THUMB( bx r3 )
  153. ENDPROC(cpu_resume)
  154. #ifdef CONFIG_MMU
  155. ENDPROC(cpu_resume_arm)
  156. #endif
  157. .align 2
  158. _sleep_save_sp:
  159. .long sleep_save_sp - .
  160. mpidr_hash_ptr:
  161. .long mpidr_hash - . @ mpidr_hash struct offset
  162. .data
  163. .type sleep_save_sp, #object
  164. ENTRY(sleep_save_sp)
  165. .space SLEEP_SAVE_SP_SZ @ struct sleep_save_sp