init.c 9.0 KB

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