tlb-sh4.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * arch/sh/mm/tlb-sh4.c
  3. *
  4. * SH-4 specific TLB operations
  5. *
  6. * Copyright (C) 1999 Niibe Yutaka
  7. * Copyright (C) 2002 - 2007 Paul Mundt
  8. *
  9. * Released under the terms of the GNU GPL v2.0.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/io.h>
  14. #include <asm/system.h>
  15. #include <asm/mmu_context.h>
  16. #include <asm/cacheflush.h>
  17. void update_mmu_cache(struct vm_area_struct * vma,
  18. unsigned long address, pte_t pte)
  19. {
  20. unsigned long flags;
  21. unsigned long pteval;
  22. unsigned long vpn;
  23. unsigned long pfn = pte_pfn(pte);
  24. struct page *page;
  25. /* Ptrace may call this routine. */
  26. if (vma && current->active_mm != vma->vm_mm)
  27. return;
  28. page = pfn_to_page(pfn);
  29. if (pfn_valid(pfn) && page_mapping(page)) {
  30. #ifndef CONFIG_SMP
  31. int dirty = test_and_clear_bit(PG_dcache_dirty, &page->flags);
  32. if (dirty) {
  33. unsigned long addr = (unsigned long)page_address(page);
  34. if (pages_do_alias(addr, address & PAGE_MASK))
  35. __flush_wback_region((void *)addr, PAGE_SIZE);
  36. }
  37. #endif
  38. }
  39. local_irq_save(flags);
  40. /* Set PTEH register */
  41. vpn = (address & MMU_VPN_MASK) | get_asid();
  42. ctrl_outl(vpn, MMU_PTEH);
  43. pteval = pte.pte_low;
  44. /* Set PTEA register */
  45. #ifdef CONFIG_X2TLB
  46. /*
  47. * For the extended mode TLB this is trivial, only the ESZ and
  48. * EPR bits need to be written out to PTEA, with the remainder of
  49. * the protection bits (with the exception of the compat-mode SZ
  50. * and PR bits, which are cleared) being written out in PTEL.
  51. */
  52. ctrl_outl(pte.pte_high, MMU_PTEA);
  53. #else
  54. if (cpu_data->flags & CPU_HAS_PTEA)
  55. /* TODO: make this look less hacky */
  56. ctrl_outl(((pteval >> 28) & 0xe) | (pteval & 0x1), MMU_PTEA);
  57. #endif
  58. /* Set PTEL register */
  59. pteval &= _PAGE_FLAGS_HARDWARE_MASK; /* drop software flags */
  60. #ifdef CONFIG_CACHE_WRITETHROUGH
  61. pteval |= _PAGE_WT;
  62. #endif
  63. /* conveniently, we want all the software flags to be 0 anyway */
  64. ctrl_outl(pteval, MMU_PTEL);
  65. /* Load the TLB */
  66. asm volatile("ldtlb": /* no output */ : /* no input */ : "memory");
  67. local_irq_restore(flags);
  68. }
  69. void __uses_jump_to_uncached local_flush_tlb_one(unsigned long asid,
  70. unsigned long page)
  71. {
  72. unsigned long addr, data;
  73. /*
  74. * NOTE: PTEH.ASID should be set to this MM
  75. * _AND_ we need to write ASID to the array.
  76. *
  77. * It would be simple if we didn't need to set PTEH.ASID...
  78. */
  79. addr = MMU_UTLB_ADDRESS_ARRAY | MMU_PAGE_ASSOC_BIT;
  80. data = page | asid; /* VALID bit is off */
  81. jump_to_uncached();
  82. ctrl_outl(data, addr);
  83. back_to_cached();
  84. }