init.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * linux/arch/cris/arch-v10/mm/init.c
  3. *
  4. */
  5. #include <linux/mmzone.h>
  6. #include <linux/init.h>
  7. #include <linux/bootmem.h>
  8. #include <linux/mm.h>
  9. #include <asm/pgtable.h>
  10. #include <asm/page.h>
  11. #include <asm/types.h>
  12. #include <asm/mmu.h>
  13. #include <asm/io.h>
  14. #include <asm/mmu_context.h>
  15. #include <arch/svinto.h>
  16. extern void tlb_init(void);
  17. /*
  18. * The kernel is already mapped with a kernel segment at kseg_c so
  19. * we don't need to map it with a page table. However head.S also
  20. * temporarily mapped it at kseg_4 so we should set up the ksegs again,
  21. * clear the TLB and do some other paging setup stuff.
  22. */
  23. void __init
  24. paging_init(void)
  25. {
  26. int i;
  27. unsigned long zones_size[MAX_NR_ZONES];
  28. printk("Setting up paging and the MMU.\n");
  29. /* clear out the init_mm.pgd that will contain the kernel's mappings */
  30. for(i = 0; i < PTRS_PER_PGD; i++)
  31. swapper_pg_dir[i] = __pgd(0);
  32. /* make sure the current pgd table points to something sane
  33. * (even if it is most probably not used until the next
  34. * switch_mm)
  35. */
  36. per_cpu(current_pgd, smp_processor_id()) = init_mm.pgd;
  37. /* initialise the TLB (tlb.c) */
  38. tlb_init();
  39. /* see README.mm for details on the KSEG setup */
  40. #ifdef CONFIG_CRIS_LOW_MAP
  41. /* Etrax-100 LX version 1 has a bug so that we cannot map anything
  42. * across the 0x80000000 boundary, so we need to shrink the user-virtual
  43. * area to 0x50000000 instead of 0xb0000000 and map things slightly
  44. * different. The unused areas are marked as paged so that we can catch
  45. * freak kernel accesses there.
  46. *
  47. * The ARTPEC chip is mapped at 0xa so we pass that segment straight
  48. * through. We cannot vremap it because the vmalloc area is below 0x8
  49. * and Juliette needs an uncached area above 0x8.
  50. *
  51. * Same thing with 0xc and 0x9, which is memory-mapped I/O on some boards.
  52. * We map them straight over in LOW_MAP, but use vremap in LX version 2.
  53. */
  54. #define CACHED_BOOTROM (KSEG_F | 0x08000000UL)
  55. *R_MMU_KSEG = ( IO_STATE(R_MMU_KSEG, seg_f, seg ) | /* bootrom */
  56. IO_STATE(R_MMU_KSEG, seg_e, page ) |
  57. IO_STATE(R_MMU_KSEG, seg_d, page ) |
  58. IO_STATE(R_MMU_KSEG, seg_c, page ) |
  59. IO_STATE(R_MMU_KSEG, seg_b, seg ) | /* kernel reg area */
  60. #ifdef CONFIG_JULIETTE
  61. IO_STATE(R_MMU_KSEG, seg_a, seg ) | /* ARTPEC etc. */
  62. #else
  63. IO_STATE(R_MMU_KSEG, seg_a, page ) |
  64. #endif
  65. IO_STATE(R_MMU_KSEG, seg_9, seg ) | /* LED's on some boards */
  66. IO_STATE(R_MMU_KSEG, seg_8, seg ) | /* CSE0/1, flash and I/O */
  67. IO_STATE(R_MMU_KSEG, seg_7, page ) | /* kernel vmalloc area */
  68. IO_STATE(R_MMU_KSEG, seg_6, seg ) | /* kernel DRAM area */
  69. IO_STATE(R_MMU_KSEG, seg_5, seg ) | /* cached flash */
  70. IO_STATE(R_MMU_KSEG, seg_4, page ) | /* user area */
  71. IO_STATE(R_MMU_KSEG, seg_3, page ) | /* user area */
  72. IO_STATE(R_MMU_KSEG, seg_2, page ) | /* user area */
  73. IO_STATE(R_MMU_KSEG, seg_1, page ) | /* user area */
  74. IO_STATE(R_MMU_KSEG, seg_0, page ) ); /* user area */
  75. *R_MMU_KBASE_HI = ( IO_FIELD(R_MMU_KBASE_HI, base_f, 0x3 ) |
  76. IO_FIELD(R_MMU_KBASE_HI, base_e, 0x0 ) |
  77. IO_FIELD(R_MMU_KBASE_HI, base_d, 0x0 ) |
  78. IO_FIELD(R_MMU_KBASE_HI, base_c, 0x0 ) |
  79. IO_FIELD(R_MMU_KBASE_HI, base_b, 0xb ) |
  80. #ifdef CONFIG_JULIETTE
  81. IO_FIELD(R_MMU_KBASE_HI, base_a, 0xa ) |
  82. #else
  83. IO_FIELD(R_MMU_KBASE_HI, base_a, 0x0 ) |
  84. #endif
  85. IO_FIELD(R_MMU_KBASE_HI, base_9, 0x9 ) |
  86. IO_FIELD(R_MMU_KBASE_HI, base_8, 0x8 ) );
  87. *R_MMU_KBASE_LO = ( IO_FIELD(R_MMU_KBASE_LO, base_7, 0x0 ) |
  88. IO_FIELD(R_MMU_KBASE_LO, base_6, 0x4 ) |
  89. IO_FIELD(R_MMU_KBASE_LO, base_5, 0x0 ) |
  90. IO_FIELD(R_MMU_KBASE_LO, base_4, 0x0 ) |
  91. IO_FIELD(R_MMU_KBASE_LO, base_3, 0x0 ) |
  92. IO_FIELD(R_MMU_KBASE_LO, base_2, 0x0 ) |
  93. IO_FIELD(R_MMU_KBASE_LO, base_1, 0x0 ) |
  94. IO_FIELD(R_MMU_KBASE_LO, base_0, 0x0 ) );
  95. #else
  96. /* This code is for the corrected Etrax-100 LX version 2... */
  97. #define CACHED_BOOTROM (KSEG_A | 0x08000000UL)
  98. *R_MMU_KSEG = ( IO_STATE(R_MMU_KSEG, seg_f, seg ) | /* cached flash */
  99. IO_STATE(R_MMU_KSEG, seg_e, seg ) | /* uncached flash */
  100. IO_STATE(R_MMU_KSEG, seg_d, page ) | /* vmalloc area */
  101. IO_STATE(R_MMU_KSEG, seg_c, seg ) | /* kernel area */
  102. IO_STATE(R_MMU_KSEG, seg_b, seg ) | /* kernel reg area */
  103. IO_STATE(R_MMU_KSEG, seg_a, seg ) | /* bootrom */
  104. IO_STATE(R_MMU_KSEG, seg_9, page ) | /* user area */
  105. IO_STATE(R_MMU_KSEG, seg_8, page ) |
  106. IO_STATE(R_MMU_KSEG, seg_7, page ) |
  107. IO_STATE(R_MMU_KSEG, seg_6, page ) |
  108. IO_STATE(R_MMU_KSEG, seg_5, page ) |
  109. IO_STATE(R_MMU_KSEG, seg_4, page ) |
  110. IO_STATE(R_MMU_KSEG, seg_3, page ) |
  111. IO_STATE(R_MMU_KSEG, seg_2, page ) |
  112. IO_STATE(R_MMU_KSEG, seg_1, page ) |
  113. IO_STATE(R_MMU_KSEG, seg_0, page ) );
  114. *R_MMU_KBASE_HI = ( IO_FIELD(R_MMU_KBASE_HI, base_f, 0x0 ) |
  115. IO_FIELD(R_MMU_KBASE_HI, base_e, 0x8 ) |
  116. IO_FIELD(R_MMU_KBASE_HI, base_d, 0x0 ) |
  117. IO_FIELD(R_MMU_KBASE_HI, base_c, 0x4 ) |
  118. IO_FIELD(R_MMU_KBASE_HI, base_b, 0xb ) |
  119. IO_FIELD(R_MMU_KBASE_HI, base_a, 0x3 ) |
  120. IO_FIELD(R_MMU_KBASE_HI, base_9, 0x0 ) |
  121. IO_FIELD(R_MMU_KBASE_HI, base_8, 0x0 ) );
  122. *R_MMU_KBASE_LO = ( IO_FIELD(R_MMU_KBASE_LO, base_7, 0x0 ) |
  123. IO_FIELD(R_MMU_KBASE_LO, base_6, 0x0 ) |
  124. IO_FIELD(R_MMU_KBASE_LO, base_5, 0x0 ) |
  125. IO_FIELD(R_MMU_KBASE_LO, base_4, 0x0 ) |
  126. IO_FIELD(R_MMU_KBASE_LO, base_3, 0x0 ) |
  127. IO_FIELD(R_MMU_KBASE_LO, base_2, 0x0 ) |
  128. IO_FIELD(R_MMU_KBASE_LO, base_1, 0x0 ) |
  129. IO_FIELD(R_MMU_KBASE_LO, base_0, 0x0 ) );
  130. #endif
  131. *R_MMU_CONTEXT = ( IO_FIELD(R_MMU_CONTEXT, page_id, 0 ) );
  132. /* The MMU has been enabled ever since head.S but just to make
  133. * it totally obvious we do it here as well.
  134. */
  135. *R_MMU_CTRL = ( IO_STATE(R_MMU_CTRL, inv_excp, enable ) |
  136. IO_STATE(R_MMU_CTRL, acc_excp, enable ) |
  137. IO_STATE(R_MMU_CTRL, we_excp, enable ) );
  138. *R_MMU_ENABLE = IO_STATE(R_MMU_ENABLE, mmu_enable, enable);
  139. /*
  140. * initialize the bad page table and bad page to point
  141. * to a couple of allocated pages
  142. */
  143. empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  144. memset((void *)empty_zero_page, 0, PAGE_SIZE);
  145. /* All pages are DMA'able in Etrax, so put all in the DMA'able zone */
  146. zones_size[0] = ((unsigned long)high_memory - PAGE_OFFSET) >> PAGE_SHIFT;
  147. for (i = 1; i < MAX_NR_ZONES; i++)
  148. zones_size[i] = 0;
  149. /* Use free_area_init_node instead of free_area_init, because the former
  150. * is designed for systems where the DRAM starts at an address substantially
  151. * higher than 0, like us (we start at PAGE_OFFSET). This saves space in the
  152. * mem_map page array.
  153. */
  154. free_area_init_node(0, zones_size, PAGE_OFFSET >> PAGE_SHIFT, 0);
  155. }
  156. /* Initialize remaps of some I/O-ports. It is important that this
  157. * is called before any driver is initialized.
  158. */
  159. static int
  160. __init init_ioremap(void)
  161. {
  162. /* Give the external I/O-port addresses their values */
  163. #ifdef CONFIG_CRIS_LOW_MAP
  164. /* Simply a linear map (see the KSEG map above in paging_init) */
  165. port_cse1_addr = (volatile unsigned long *)(MEM_CSE1_START |
  166. MEM_NON_CACHEABLE);
  167. port_csp0_addr = (volatile unsigned long *)(MEM_CSP0_START |
  168. MEM_NON_CACHEABLE);
  169. port_csp4_addr = (volatile unsigned long *)(MEM_CSP4_START |
  170. MEM_NON_CACHEABLE);
  171. #else
  172. /* Note that nothing blows up just because we do this remapping
  173. * it's ok even if the ports are not used or connected
  174. * to anything (or connected to a non-I/O thing) */
  175. port_cse1_addr = (volatile unsigned long *)
  176. ioremap((unsigned long)(MEM_CSE1_START | MEM_NON_CACHEABLE), 16);
  177. port_csp0_addr = (volatile unsigned long *)
  178. ioremap((unsigned long)(MEM_CSP0_START | MEM_NON_CACHEABLE), 16);
  179. port_csp4_addr = (volatile unsigned long *)
  180. ioremap((unsigned long)(MEM_CSP4_START | MEM_NON_CACHEABLE), 16);
  181. #endif
  182. return 0;
  183. }
  184. __initcall(init_ioremap);
  185. /* Helper function for the two below */
  186. static inline void
  187. flush_etrax_cacherange(void *startadr, int length)
  188. {
  189. /* CACHED_BOOTROM is mapped to the boot-rom area (cached) which
  190. * we can use to get fast dummy-reads of cachelines
  191. */
  192. volatile short *flushadr = (volatile short *)(((unsigned long)startadr & ~PAGE_MASK) |
  193. CACHED_BOOTROM);
  194. length = length > 8192 ? 8192 : length; /* No need to flush more than cache size */
  195. while(length > 0) {
  196. *flushadr; /* dummy read to flush */
  197. flushadr += (32/sizeof(short)); /* a cacheline is 32 bytes */
  198. length -= 32;
  199. }
  200. }
  201. /* Due to a bug in Etrax100(LX) all versions, receiving DMA buffers
  202. * will occasionally corrupt certain CPU writes if the DMA buffers
  203. * happen to be hot in the cache.
  204. *
  205. * As a workaround, we have to flush the relevant parts of the cache
  206. * before (re) inserting any receiving descriptor into the DMA HW.
  207. */
  208. void
  209. prepare_rx_descriptor(struct etrax_dma_descr *desc)
  210. {
  211. flush_etrax_cacherange((void *)desc->buf, desc->sw_len ? desc->sw_len : 65536);
  212. }
  213. /* Do the same thing but flush the entire cache */
  214. void
  215. flush_etrax_cache(void)
  216. {
  217. flush_etrax_cacherange(0, 8192);
  218. }