kernel-entry-init.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2005 Embedded Alley Solutions, Inc
  7. */
  8. #ifndef __ASM_MACH_KERNEL_ENTRY_INIT_H
  9. #define __ASM_MACH_KERNEL_ENTRY_INIT_H
  10. #include <asm/cacheops.h>
  11. #include <asm/addrspace.h>
  12. #define CO_CONFIGPR_VALID 0x3F1F41FF /* valid bits to write to ConfigPR */
  13. #define HAZARD_CP0 nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
  14. #define CACHE_OPC 0xBC000000 /* MIPS cache instruction opcode */
  15. #define ICACHE_LINE_SIZE 32 /* Instruction cache line size bytes */
  16. #define DCACHE_LINE_SIZE 32 /* Data cache line size in bytes */
  17. #define ICACHE_SET_COUNT 256 /* Instruction cache set count */
  18. #define DCACHE_SET_COUNT 128 /* Data cache set count */
  19. #define ICACHE_SET_SIZE (ICACHE_SET_COUNT * ICACHE_LINE_SIZE)
  20. #define DCACHE_SET_SIZE (DCACHE_SET_COUNT * DCACHE_LINE_SIZE)
  21. .macro kernel_entry_setup
  22. .set push
  23. .set noreorder
  24. /*
  25. * PNX8550 entry point, when running a non compressed
  26. * kernel. When loading a zImage, the head.S code in
  27. * arch/mips/zboot/pnx8550 will init the caches and,
  28. * decompress the kernel, and branch to kernel_entry.
  29. */
  30. cache_begin: li t0, (1<<28)
  31. mtc0 t0, CP0_STATUS /* cp0 usable */
  32. HAZARD_CP0
  33. mtc0 zero, CP0_CAUSE
  34. HAZARD_CP0
  35. /* Set static virtual to phys address translation and TLB disabled */
  36. mfc0 t0, CP0_CONFIG, 7
  37. HAZARD_CP0
  38. and t0, ~((1<<19) | (1<<20)) /* TLB/MAP cleared */
  39. mtc0 t0, CP0_CONFIG, 7
  40. HAZARD_CP0
  41. /* CPU boots with kseg0 cache algo set to 0x2 -- uncached */
  42. init_icache
  43. nop
  44. init_dcache
  45. nop
  46. cachePr4450ICReset
  47. nop
  48. cachePr4450DCReset
  49. nop
  50. /* read ConfigPR into t0 */
  51. mfc0 t0, CP0_CONFIG, 7
  52. HAZARD_CP0
  53. /* enable the TLB */
  54. or t0, (1<<19)
  55. /* disable the ICACHE: at least 10x slower */
  56. /* or t0, (1<<26) */
  57. /* disable the DCACHE; CONFIG_CPU_HAS_LLSC should not be set */
  58. /* or t0, (1<<27) */
  59. and t0, CO_CONFIGPR_VALID
  60. /* enable TLB. */
  61. mtc0 t0, CP0_CONFIG, 7
  62. HAZARD_CP0
  63. cache_end:
  64. /* Setup CMEM_0 to MMIO address space, 2MB */
  65. lui t0, 0x1BE0
  66. addi t0, t0, 0x3
  67. mtc0 $8, $22, 4
  68. nop
  69. /* Setup CMEM_1, 128MB */
  70. lui t0, 0x1000
  71. addi t0, t0, 0xf
  72. mtc0 $8, $22, 5
  73. nop
  74. /* Setup CMEM_2, 32MB */
  75. lui t0, 0x1C00
  76. addi t0, t0, 0xb
  77. mtc0 $8, $22, 6
  78. nop
  79. /* Setup CMEM_3, 0MB */
  80. lui t0, 0x0
  81. addi t0, t0, 0x0
  82. mtc0 $8, $22, 7
  83. nop
  84. /* Enable cache */
  85. mfc0 t0, CP0_CONFIG
  86. HAZARD_CP0
  87. and t0, t0, 0xFFFFFFF8
  88. or t0, t0, 3
  89. mtc0 t0, CP0_CONFIG
  90. HAZARD_CP0
  91. .set pop
  92. .endm
  93. .macro init_icache
  94. .set push
  95. .set noreorder
  96. /* Get Cache Configuration */
  97. mfc0 t3, CP0_CONFIG, 1
  98. HAZARD_CP0
  99. /* get cache Line size */
  100. srl t1, t3, 19 /* C0_CONFIGPR_IL_SHIFT */
  101. andi t1, t1, 0x7 /* C0_CONFIGPR_IL_MASK */
  102. beq t1, zero, pr4450_instr_cache_invalidated /* if zero instruction cache is absent */
  103. nop
  104. addiu t0, t1, 1
  105. ori t1, zero, 1
  106. sllv t1, t1, t0
  107. /* get max cache Index */
  108. srl t2, t3, 22 /* C0_CONFIGPR_IS_SHIFT */
  109. andi t2, t2, 0x7 /* C0_CONFIGPR_IS_MASK */
  110. addiu t0, t2, 6
  111. ori t2, zero, 1
  112. sllv t2, t2, t0
  113. /* get max cache way */
  114. srl t3, t3, 16 /* C0_CONFIGPR_IA_SHIFT */
  115. andi t3, t3, 0x7 /* C0_CONFIGPR_IA_MASK */
  116. addiu t3, t3, 1
  117. /* total no of cache lines */
  118. multu t2, t3 /* max index * max way */
  119. mflo t2
  120. addiu t2, t2, -1
  121. move t0, zero
  122. pr4450_next_instruction_cache_set:
  123. cache Index_Invalidate_I, 0(t0)
  124. addu t0, t0, t1 /* add bytes in a line */
  125. bne t2, zero, pr4450_next_instruction_cache_set
  126. addiu t2, t2, -1 /* reduce no of lines to invalidate by one */
  127. pr4450_instr_cache_invalidated:
  128. .set pop
  129. .endm
  130. .macro init_dcache
  131. .set push
  132. .set noreorder
  133. move t1, zero
  134. /* Store Tag Information */
  135. mtc0 zero, CP0_TAGLO, 0
  136. HAZARD_CP0
  137. mtc0 zero, CP0_TAGHI, 0
  138. HAZARD_CP0
  139. /* Cache size is 16384 = 512 lines x 32 bytes per line */
  140. or t2, zero, (128*4)-1 /* 512 lines */
  141. /* Invalidate all lines */
  142. 2:
  143. cache Index_Store_Tag_D, 0(t1)
  144. addiu t2, t2, -1
  145. bne t2, zero, 2b
  146. addiu t1, t1, 32 /* 32 bytes in a line */
  147. .set pop
  148. .endm
  149. .macro cachePr4450ICReset
  150. .set push
  151. .set noreorder
  152. /* Save CP0 status reg on entry; */
  153. /* disable interrupts during cache reset */
  154. mfc0 t0, CP0_STATUS /* T0 = interrupt status on entry */
  155. HAZARD_CP0
  156. mtc0 zero, CP0_STATUS /* disable CPU interrupts */
  157. HAZARD_CP0
  158. or t1, zero, zero /* T1 = starting cache index (0) */
  159. ori t2, zero, (256 - 1) /* T2 = inst cache set cnt - 1 */
  160. icache_invd_loop:
  161. /* 9 == register t1 */
  162. .word CACHE_OPC | (9 << 21) | (Index_Invalidate_I << 16) | \
  163. (0 * ICACHE_SET_SIZE) /* invalidate inst cache WAY0 */
  164. .word CACHE_OPC | (9 << 21) | (Index_Invalidate_I << 16) | \
  165. (1 * ICACHE_SET_SIZE) /* invalidate inst cache WAY1 */
  166. addiu t1, t1, ICACHE_LINE_SIZE /* T1 = next cache line index */
  167. bne t2, zero, icache_invd_loop /* T2 = 0 if all sets invalidated */
  168. addiu t2, t2, -1 /* decrement T2 set cnt (delay slot) */
  169. /* Initialize the latches in the instruction cache tag */
  170. /* that drive the way selection tri-state bus drivers, by doing a */
  171. /* dummy load while the instruction cache is still disabled. */
  172. /* TODO: Is this needed ? */
  173. la t1, KSEG0 /* T1 = cached memory base address */
  174. lw zero, 0x0000(t1) /* (dummy read of first memory word) */
  175. mtc0 t0, CP0_STATUS /* restore interrupt status on entry */
  176. HAZARD_CP0
  177. .set pop
  178. .endm
  179. .macro cachePr4450DCReset
  180. .set push
  181. .set noreorder
  182. mfc0 t0, CP0_STATUS /* T0 = interrupt status on entry */
  183. HAZARD_CP0
  184. mtc0 zero, CP0_STATUS /* disable CPU interrupts */
  185. HAZARD_CP0
  186. /* Writeback/invalidate entire data cache sets/ways/lines */
  187. or t1, zero, zero /* T1 = starting cache index (0) */
  188. ori t2, zero, (DCACHE_SET_COUNT - 1) /* T2 = data cache set cnt - 1 */
  189. dcache_wbinvd_loop:
  190. /* 9 == register t1 */
  191. .word CACHE_OPC | (9 << 21) | (Index_Writeback_Inv_D << 16) | \
  192. (0 * DCACHE_SET_SIZE) /* writeback/invalidate WAY0 */
  193. .word CACHE_OPC | (9 << 21) | (Index_Writeback_Inv_D << 16) | \
  194. (1 * DCACHE_SET_SIZE) /* writeback/invalidate WAY1 */
  195. .word CACHE_OPC | (9 << 21) | (Index_Writeback_Inv_D << 16) | \
  196. (2 * DCACHE_SET_SIZE) /* writeback/invalidate WAY2 */
  197. .word CACHE_OPC | (9 << 21) | (Index_Writeback_Inv_D << 16) | \
  198. (3 * DCACHE_SET_SIZE) /* writeback/invalidate WAY3 */
  199. addiu t1, t1, DCACHE_LINE_SIZE /* T1 = next data cache line index */
  200. bne t2, zero, dcache_wbinvd_loop /* T2 = 0 when wbinvd entire cache */
  201. addiu t2, t2, -1 /* decrement T2 set cnt (delay slot) */
  202. /* Initialize the latches in the data cache tag that drive the way
  203. selection tri-state bus drivers, by doing a dummy load while the
  204. data cache is still in the disabled mode. TODO: Is this needed ? */
  205. la t1, KSEG0 /* T1 = cached memory base address */
  206. lw zero, 0x0000(t1) /* (dummy read of first memory word) */
  207. mtc0 t0, CP0_STATUS /* restore interrupt status on entry */
  208. HAZARD_CP0
  209. .set pop
  210. .endm
  211. #endif /* __ASM_MACH_KERNEL_ENTRY_INIT_H */