util.S 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * arch/ppc/boot/common/util.S
  3. *
  4. * Useful bootup functions, which are more easily done in asm than C.
  5. *
  6. * NOTE: Be very very careful about the registers you use here.
  7. * We don't follow any ABI calling convention among the
  8. * assembler functions that call each other, especially early
  9. * in the initialization. Please preserve at least r3 and r4
  10. * for these early functions, as they often contain information
  11. * passed from boot roms into the C decompress function.
  12. *
  13. * Author: Tom Rini
  14. * trini@mvista.com
  15. * Derived from arch/ppc/boot/prep/head.S (Cort Dougan, many others).
  16. *
  17. * 2001-2004 (c) MontaVista, Software, Inc. This file is licensed under
  18. * the terms of the GNU General Public License version 2. This program
  19. * is licensed "as is" without any warranty of any kind, whether express
  20. * or implied.
  21. */
  22. #include <asm/processor.h>
  23. #include <asm/cache.h>
  24. #include <asm/ppc_asm.h>
  25. .text
  26. #ifdef CONFIG_6xx
  27. .globl disable_6xx_mmu
  28. disable_6xx_mmu:
  29. /* Establish default MSR value, exception prefix 0xFFF.
  30. * If necessary, this function must fix up the LR if we
  31. * return to a different address space once the MMU is
  32. * disabled.
  33. */
  34. li r8,MSR_IP|MSR_FP
  35. mtmsr r8
  36. isync
  37. /* Test for a 601 */
  38. mfpvr r10
  39. srwi r10,r10,16
  40. cmpwi 0,r10,1 /* 601 ? */
  41. beq .clearbats_601
  42. /* Clear BATs */
  43. li r8,0
  44. mtspr SPRN_DBAT0U,r8
  45. mtspr SPRN_DBAT0L,r8
  46. mtspr SPRN_DBAT1U,r8
  47. mtspr SPRN_DBAT1L,r8
  48. mtspr SPRN_DBAT2U,r8
  49. mtspr SPRN_DBAT2L,r8
  50. mtspr SPRN_DBAT3U,r8
  51. mtspr SPRN_DBAT3L,r8
  52. .clearbats_601:
  53. mtspr SPRN_IBAT0U,r8
  54. mtspr SPRN_IBAT0L,r8
  55. mtspr SPRN_IBAT1U,r8
  56. mtspr SPRN_IBAT1L,r8
  57. mtspr SPRN_IBAT2U,r8
  58. mtspr SPRN_IBAT2L,r8
  59. mtspr SPRN_IBAT3U,r8
  60. mtspr SPRN_IBAT3L,r8
  61. isync
  62. sync
  63. sync
  64. /* Set segment registers */
  65. li r8,16 /* load up segment register values */
  66. mtctr r8 /* for context 0 */
  67. lis r8,0x2000 /* Ku = 1, VSID = 0 */
  68. li r10,0
  69. 3: mtsrin r8,r10
  70. addi r8,r8,0x111 /* increment VSID */
  71. addis r10,r10,0x1000 /* address of next segment */
  72. bdnz 3b
  73. blr
  74. .globl disable_6xx_l1cache
  75. disable_6xx_l1cache:
  76. /* Enable, invalidate and then disable the L1 icache/dcache. */
  77. li r8,0
  78. ori r8,r8,(HID0_ICE|HID0_DCE|HID0_ICFI|HID0_DCI)
  79. mfspr r11,SPRN_HID0
  80. or r11,r11,r8
  81. andc r10,r11,r8
  82. isync
  83. mtspr SPRN_HID0,r8
  84. sync
  85. isync
  86. mtspr SPRN_HID0,r10
  87. sync
  88. isync
  89. blr
  90. #endif
  91. .globl _setup_L2CR
  92. _setup_L2CR:
  93. /*
  94. * We should be skipping this section on CPUs where this results in an
  95. * illegal instruction. If not, please send trini@kernel.crashing.org
  96. * the PVR of your CPU.
  97. */
  98. /* Invalidate/disable L2 cache */
  99. sync
  100. isync
  101. mfspr r8,SPRN_L2CR
  102. rlwinm r8,r8,0,1,31
  103. oris r8,r8,L2CR_L2I@h
  104. sync
  105. isync
  106. mtspr SPRN_L2CR,r8
  107. sync
  108. isync
  109. /* Wait for the invalidation to complete */
  110. mfspr r8,SPRN_PVR
  111. srwi r8,r8,16
  112. cmplwi cr0,r8,0x8000 /* 7450 */
  113. cmplwi cr1,r8,0x8001 /* 7455 */
  114. cmplwi cr2,r8,0x8002 /* 7457 */
  115. cror 4*cr0+eq,4*cr0+eq,4*cr1+eq /* Now test if any are true. */
  116. cror 4*cr0+eq,4*cr0+eq,4*cr2+eq
  117. bne 2f
  118. 1: mfspr r8,SPRN_L2CR /* On 745x, poll L2I bit (bit 10) */
  119. rlwinm. r9,r8,0,10,10
  120. bne 1b
  121. b 3f
  122. 2: mfspr r8,SPRN_L2CR /* On 75x & 74[01]0, poll L2IP bit (bit 31) */
  123. rlwinm. r9,r8,0,31,31
  124. bne 2b
  125. 3: rlwinm r8,r8,0,11,9 /* Turn off L2I bit */
  126. sync
  127. isync
  128. mtspr SPRN_L2CR,r8
  129. sync
  130. isync
  131. blr
  132. .globl _setup_L3CR
  133. _setup_L3CR:
  134. /* Invalidate/disable L3 cache */
  135. sync
  136. isync
  137. mfspr r8,SPRN_L3CR
  138. rlwinm r8,r8,0,1,31
  139. ori r8,r8,L3CR_L3I@l
  140. sync
  141. isync
  142. mtspr SPRN_L3CR,r8
  143. sync
  144. isync
  145. /* Wait for the invalidation to complete */
  146. 1: mfspr r8,SPRN_L3CR
  147. rlwinm. r9,r8,0,21,21
  148. bne 1b
  149. rlwinm r8,r8,0,22,20 /* Turn off L3I bit */
  150. sync
  151. isync
  152. mtspr SPRN_L3CR,r8
  153. sync
  154. isync
  155. blr
  156. /* udelay (on non-601 processors) needs to know the period of the
  157. * timebase in nanoseconds. This used to be hardcoded to be 60ns
  158. * (period of 66MHz/4). Now a variable is used that is initialized to
  159. * 60 for backward compatibility, but it can be overridden as necessary
  160. * with code something like this:
  161. * extern unsigned long timebase_period_ns;
  162. * timebase_period_ns = 1000000000 / bd->bi_tbfreq;
  163. */
  164. .data
  165. .globl timebase_period_ns
  166. timebase_period_ns:
  167. .long 60
  168. .text
  169. /*
  170. * Delay for a number of microseconds
  171. */
  172. .globl udelay
  173. udelay:
  174. mfspr r4,SPRN_PVR
  175. srwi r4,r4,16
  176. cmpwi 0,r4,1 /* 601 ? */
  177. bne .udelay_not_601
  178. 00: li r0,86 /* Instructions / microsecond? */
  179. mtctr r0
  180. 10: addi r0,r0,0 /* NOP */
  181. bdnz 10b
  182. subic. r3,r3,1
  183. bne 00b
  184. blr
  185. .udelay_not_601:
  186. mulli r4,r3,1000 /* nanoseconds */
  187. /* Change r4 to be the number of ticks using:
  188. * (nanoseconds + (timebase_period_ns - 1 )) / timebase_period_ns
  189. * timebase_period_ns defaults to 60 (16.6MHz) */
  190. lis r5,timebase_period_ns@ha
  191. lwz r5,timebase_period_ns@l(r5)
  192. add r4,r4,r5
  193. addi r4,r4,-1
  194. divw r4,r4,r5 /* BUS ticks */
  195. 1: mftbu r5
  196. mftb r6
  197. mftbu r7
  198. cmpw 0,r5,r7
  199. bne 1b /* Get [synced] base time */
  200. addc r9,r6,r4 /* Compute end time */
  201. addze r8,r5
  202. 2: mftbu r5
  203. cmpw 0,r5,r8
  204. blt 2b
  205. bgt 3f
  206. mftb r6
  207. cmpw 0,r6,r9
  208. blt 2b
  209. 3: blr
  210. .section ".relocate_code","xa"
  211. /*
  212. * Flush and enable instruction cache
  213. * First, flush the data cache in case it was enabled and may be
  214. * holding instructions for copy back.
  215. */
  216. _GLOBAL(flush_instruction_cache)
  217. mflr r6
  218. bl flush_data_cache
  219. #ifdef CONFIG_8xx
  220. lis r3, IDC_INVALL@h
  221. mtspr SPRN_IC_CST, r3
  222. lis r3, IDC_ENABLE@h
  223. mtspr SPRN_IC_CST, r3
  224. lis r3, IDC_DISABLE@h
  225. mtspr SPRN_DC_CST, r3
  226. #elif CONFIG_4xx
  227. lis r3,start@h # r9 = &_start
  228. lis r4,_etext@ha
  229. addi r4,r4,_etext@l # r8 = &_etext
  230. 1: dcbf r0,r3 # Flush the data cache
  231. icbi r0,r3 # Invalidate the instruction cache
  232. addi r3,r3,0x10 # Increment by one cache line
  233. cmplwi cr0,r3,r4 # Are we at the end yet?
  234. blt 1b # No, keep flushing and invalidating
  235. #else
  236. /* Enable, invalidate and then disable the L1 icache/dcache. */
  237. li r3,0
  238. ori r3,r3,(HID0_ICE|HID0_DCE|HID0_ICFI|HID0_DCI)
  239. mfspr r4,SPRN_HID0
  240. or r5,r4,r3
  241. isync
  242. mtspr SPRN_HID0,r5
  243. sync
  244. isync
  245. ori r5,r4,HID0_ICE /* Enable cache */
  246. mtspr SPRN_HID0,r5
  247. sync
  248. isync
  249. #endif
  250. mtlr r6
  251. blr
  252. #define NUM_CACHE_LINES 128*8
  253. #define cache_flush_buffer 0x1000
  254. /*
  255. * Flush data cache
  256. * Do this by just reading lots of stuff into the cache.
  257. */
  258. _GLOBAL(flush_data_cache)
  259. lis r3,cache_flush_buffer@h
  260. ori r3,r3,cache_flush_buffer@l
  261. li r4,NUM_CACHE_LINES
  262. mtctr r4
  263. 00: lwz r4,0(r3)
  264. addi r3,r3,L1_CACHE_BYTES /* Next line, please */
  265. bdnz 00b
  266. 10: blr
  267. .previous