util.S 6.3 KB

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