mmu.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * xtensa mmu stuff
  3. *
  4. * Extracted from init.c
  5. */
  6. #include <linux/bootmem.h>
  7. #include <linux/percpu.h>
  8. #include <linux/init.h>
  9. #include <linux/string.h>
  10. #include <linux/slab.h>
  11. #include <linux/cache.h>
  12. #include <asm/tlb.h>
  13. #include <asm/tlbflush.h>
  14. #include <asm/mmu_context.h>
  15. #include <asm/page.h>
  16. #include <asm/initialize_mmu.h>
  17. #include <asm/io.h>
  18. #if defined(CONFIG_HIGHMEM)
  19. static void * __init init_pmd(unsigned long vaddr, unsigned long n_pages)
  20. {
  21. pgd_t *pgd = pgd_offset_k(vaddr);
  22. pmd_t *pmd = pmd_offset(pgd, vaddr);
  23. pte_t *pte;
  24. unsigned long i;
  25. n_pages = ALIGN(n_pages, PTRS_PER_PTE);
  26. pr_debug("%s: vaddr: 0x%08lx, n_pages: %ld\n",
  27. __func__, vaddr, n_pages);
  28. pte = alloc_bootmem_low_pages(n_pages * sizeof(pte_t));
  29. for (i = 0; i < n_pages; ++i)
  30. pte_clear(NULL, 0, pte + i);
  31. for (i = 0; i < n_pages; i += PTRS_PER_PTE, ++pmd) {
  32. pte_t *cur_pte = pte + i;
  33. BUG_ON(!pmd_none(*pmd));
  34. set_pmd(pmd, __pmd(((unsigned long)cur_pte) & PAGE_MASK));
  35. BUG_ON(cur_pte != pte_offset_kernel(pmd, 0));
  36. pr_debug("%s: pmd: 0x%p, pte: 0x%p\n",
  37. __func__, pmd, cur_pte);
  38. }
  39. return pte;
  40. }
  41. static void __init fixedrange_init(void)
  42. {
  43. init_pmd(__fix_to_virt(0), __end_of_fixed_addresses);
  44. }
  45. #endif
  46. void __init paging_init(void)
  47. {
  48. memset(swapper_pg_dir, 0, PAGE_SIZE);
  49. #ifdef CONFIG_HIGHMEM
  50. fixedrange_init();
  51. pkmap_page_table = init_pmd(PKMAP_BASE, LAST_PKMAP);
  52. kmap_init();
  53. #endif
  54. }
  55. /*
  56. * Flush the mmu and reset associated register to default values.
  57. */
  58. void init_mmu(void)
  59. {
  60. #if !(XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY)
  61. /*
  62. * Writing zeros to the instruction and data TLBCFG special
  63. * registers ensure that valid values exist in the register.
  64. *
  65. * For existing PGSZID<w> fields, zero selects the first element
  66. * of the page-size array. For nonexistent PGSZID<w> fields,
  67. * zero is the best value to write. Also, when changing PGSZID<w>
  68. * fields, the corresponding TLB must be flushed.
  69. */
  70. set_itlbcfg_register(0);
  71. set_dtlbcfg_register(0);
  72. #endif
  73. #if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && defined(CONFIG_OF)
  74. /*
  75. * Update the IO area mapping in case xtensa_kio_paddr has changed
  76. */
  77. write_dtlb_entry(__pte(xtensa_kio_paddr + CA_WRITEBACK),
  78. XCHAL_KIO_CACHED_VADDR + 6);
  79. write_itlb_entry(__pte(xtensa_kio_paddr + CA_WRITEBACK),
  80. XCHAL_KIO_CACHED_VADDR + 6);
  81. write_dtlb_entry(__pte(xtensa_kio_paddr + CA_BYPASS),
  82. XCHAL_KIO_BYPASS_VADDR + 6);
  83. write_itlb_entry(__pte(xtensa_kio_paddr + CA_BYPASS),
  84. XCHAL_KIO_BYPASS_VADDR + 6);
  85. #endif
  86. local_flush_tlb_all();
  87. /* Set rasid register to a known value. */
  88. set_rasid_register(ASID_INSERT(ASID_USER_FIRST));
  89. /* Set PTEVADDR special register to the start of the page
  90. * table, which is in kernel mappable space (ie. not
  91. * statically mapped). This register's value is undefined on
  92. * reset.
  93. */
  94. set_ptevaddr_register(PGTABLE_START);
  95. }