init.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Set up paging and the MMU.
  3. *
  4. * Copyright (C) 2000-2003, Axis Communications AB.
  5. *
  6. * Authors: Bjorn Wesen <bjornw@axis.com>
  7. * Tobias Anderberg <tobiasa@axis.com>, CRISv32 port.
  8. */
  9. #include <linux/mmzone.h>
  10. #include <linux/init.h>
  11. #include <linux/bootmem.h>
  12. #include <linux/mm.h>
  13. #include <asm/pgtable.h>
  14. #include <asm/page.h>
  15. #include <asm/types.h>
  16. #include <asm/mmu.h>
  17. #include <asm/io.h>
  18. #include <asm/mmu_context.h>
  19. #include <arch/hwregs/asm/mmu_defs_asm.h>
  20. #include <arch/hwregs/supp_reg.h>
  21. extern void tlb_init(void);
  22. /*
  23. * The kernel is already mapped with linear mapping at kseg_c so there's no
  24. * need to map it with a page table. However, head.S also temporarily mapped it
  25. * at kseg_4 thus the ksegs are set up again. Also clear the TLB and do various
  26. * other paging stuff.
  27. */
  28. void __init cris_mmu_init(void)
  29. {
  30. unsigned long mmu_config;
  31. unsigned long mmu_kbase_hi;
  32. unsigned long mmu_kbase_lo;
  33. unsigned short mmu_page_id;
  34. /*
  35. * Make sure the current pgd table points to something sane, even if it
  36. * is most probably not used until the next switch_mm.
  37. */
  38. per_cpu(current_pgd, smp_processor_id()) = init_mm.pgd;
  39. /* Initialise the TLB. Function found in tlb.c. */
  40. tlb_init();
  41. /*
  42. * Enable exceptions and initialize the kernel segments.
  43. * See head.S for differences between ARTPEC-3 and ETRAX FS.
  44. */
  45. mmu_config = ( REG_STATE(mmu, rw_mm_cfg, we, on) |
  46. REG_STATE(mmu, rw_mm_cfg, acc, on) |
  47. REG_STATE(mmu, rw_mm_cfg, ex, on) |
  48. REG_STATE(mmu, rw_mm_cfg, inv, on) |
  49. #ifdef CONFIG_CRIS_MACH_ARTPEC3
  50. REG_STATE(mmu, rw_mm_cfg, seg_f, page) |
  51. REG_STATE(mmu, rw_mm_cfg, seg_e, page) |
  52. REG_STATE(mmu, rw_mm_cfg, seg_d, linear) |
  53. #else
  54. REG_STATE(mmu, rw_mm_cfg, seg_f, linear) |
  55. REG_STATE(mmu, rw_mm_cfg, seg_e, linear) |
  56. REG_STATE(mmu, rw_mm_cfg, seg_d, page) |
  57. #endif
  58. REG_STATE(mmu, rw_mm_cfg, seg_c, linear) |
  59. REG_STATE(mmu, rw_mm_cfg, seg_b, linear) |
  60. REG_STATE(mmu, rw_mm_cfg, seg_a, page) |
  61. REG_STATE(mmu, rw_mm_cfg, seg_9, page) |
  62. REG_STATE(mmu, rw_mm_cfg, seg_8, page) |
  63. REG_STATE(mmu, rw_mm_cfg, seg_7, page) |
  64. REG_STATE(mmu, rw_mm_cfg, seg_6, page) |
  65. REG_STATE(mmu, rw_mm_cfg, seg_5, page) |
  66. REG_STATE(mmu, rw_mm_cfg, seg_4, page) |
  67. REG_STATE(mmu, rw_mm_cfg, seg_3, page) |
  68. REG_STATE(mmu, rw_mm_cfg, seg_2, page) |
  69. REG_STATE(mmu, rw_mm_cfg, seg_1, page) |
  70. REG_STATE(mmu, rw_mm_cfg, seg_0, page));
  71. /* See head.S for differences between ARTPEC-3 and ETRAX FS. */
  72. mmu_kbase_hi = ( REG_FIELD(mmu, rw_mm_kbase_hi, base_f, 0x0) |
  73. #ifdef CONFIG_CRIS_MACH_ARTPEC3
  74. REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 0x0) |
  75. REG_FIELD(mmu, rw_mm_kbase_hi, base_d, 0x5) |
  76. #else
  77. REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 0x8) |
  78. REG_FIELD(mmu, rw_mm_kbase_hi, base_d, 0x0) |
  79. #endif
  80. REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 0x4) |
  81. REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb) |
  82. REG_FIELD(mmu, rw_mm_kbase_hi, base_a, 0x0) |
  83. REG_FIELD(mmu, rw_mm_kbase_hi, base_9, 0x0) |
  84. REG_FIELD(mmu, rw_mm_kbase_hi, base_8, 0x0));
  85. mmu_kbase_lo = ( REG_FIELD(mmu, rw_mm_kbase_lo, base_7, 0x0) |
  86. REG_FIELD(mmu, rw_mm_kbase_lo, base_6, 0x0) |
  87. REG_FIELD(mmu, rw_mm_kbase_lo, base_5, 0x0) |
  88. REG_FIELD(mmu, rw_mm_kbase_lo, base_4, 0x0) |
  89. REG_FIELD(mmu, rw_mm_kbase_lo, base_3, 0x0) |
  90. REG_FIELD(mmu, rw_mm_kbase_lo, base_2, 0x0) |
  91. REG_FIELD(mmu, rw_mm_kbase_lo, base_1, 0x0) |
  92. REG_FIELD(mmu, rw_mm_kbase_lo, base_0, 0x0));
  93. mmu_page_id = REG_FIELD(mmu, rw_mm_tlb_hi, pid, 0);
  94. /* Update the instruction MMU. */
  95. SUPP_BANK_SEL(BANK_IM);
  96. SUPP_REG_WR(RW_MM_CFG, mmu_config);
  97. SUPP_REG_WR(RW_MM_KBASE_HI, mmu_kbase_hi);
  98. SUPP_REG_WR(RW_MM_KBASE_LO, mmu_kbase_lo);
  99. SUPP_REG_WR(RW_MM_TLB_HI, mmu_page_id);
  100. /* Update the data MMU. */
  101. SUPP_BANK_SEL(BANK_DM);
  102. SUPP_REG_WR(RW_MM_CFG, mmu_config);
  103. SUPP_REG_WR(RW_MM_KBASE_HI, mmu_kbase_hi);
  104. SUPP_REG_WR(RW_MM_KBASE_LO, mmu_kbase_lo);
  105. SUPP_REG_WR(RW_MM_TLB_HI, mmu_page_id);
  106. SPEC_REG_WR(SPEC_REG_PID, 0);
  107. /*
  108. * The MMU has been enabled ever since head.S but just to make it
  109. * totally obvious enable it here as well.
  110. */
  111. SUPP_BANK_SEL(BANK_GC);
  112. SUPP_REG_WR(RW_GC_CFG, 0xf); /* IMMU, DMMU, ICache, DCache on */
  113. }
  114. void __init paging_init(void)
  115. {
  116. int i;
  117. unsigned long zones_size[MAX_NR_ZONES];
  118. printk("Setting up paging and the MMU.\n");
  119. /* Clear out the init_mm.pgd that will contain the kernel's mappings. */
  120. for(i = 0; i < PTRS_PER_PGD; i++)
  121. swapper_pg_dir[i] = __pgd(0);
  122. cris_mmu_init();
  123. /*
  124. * Initialize the bad page table and bad page to point to a couple of
  125. * allocated pages.
  126. */
  127. empty_zero_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  128. memset((void *) empty_zero_page, 0, PAGE_SIZE);
  129. /* All pages are DMA'able in Etrax, so put all in the DMA'able zone. */
  130. zones_size[0] = ((unsigned long) high_memory - PAGE_OFFSET) >> PAGE_SHIFT;
  131. for (i = 1; i < MAX_NR_ZONES; i++)
  132. zones_size[i] = 0;
  133. /*
  134. * Use free_area_init_node instead of free_area_init, because it is
  135. * designed for systems where the DRAM starts at an address
  136. * substantially higher than 0, like us (we start at PAGE_OFFSET). This
  137. * saves space in the mem_map page array.
  138. */
  139. free_area_init_node(0, zones_size, PAGE_OFFSET >> PAGE_SHIFT, 0);
  140. mem_map = contig_page_data.node_mem_map;
  141. }