mmu_context.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_MMU_CONTEXT_H
  15. #define _ASM_TILE_MMU_CONTEXT_H
  16. #include <linux/smp.h>
  17. #include <asm/setup.h>
  18. #include <asm/page.h>
  19. #include <asm/pgalloc.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/tlbflush.h>
  22. #include <asm/homecache.h>
  23. #include <asm-generic/mm_hooks.h>
  24. static inline int
  25. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  26. {
  27. return 0;
  28. }
  29. /*
  30. * Note that arch/tile/kernel/head_NN.S and arch/tile/mm/migrate_NN.S
  31. * also call hv_install_context().
  32. */
  33. static inline void __install_page_table(pgd_t *pgdir, int asid, pgprot_t prot)
  34. {
  35. /* FIXME: DIRECTIO should not always be set. FIXME. */
  36. int rc = hv_install_context(__pa(pgdir), prot, asid,
  37. HV_CTX_DIRECTIO | CTX_PAGE_FLAG);
  38. if (rc < 0)
  39. panic("hv_install_context failed: %d", rc);
  40. }
  41. static inline void install_page_table(pgd_t *pgdir, int asid)
  42. {
  43. pte_t *ptep = virt_to_kpte((unsigned long)pgdir);
  44. __install_page_table(pgdir, asid, *ptep);
  45. }
  46. /*
  47. * "Lazy" TLB mode is entered when we are switching to a kernel task,
  48. * which borrows the mm of the previous task. The goal of this
  49. * optimization is to avoid having to install a new page table. On
  50. * early x86 machines (where the concept originated) you couldn't do
  51. * anything short of a full page table install for invalidation, so
  52. * handling a remote TLB invalidate required doing a page table
  53. * re-install. Someone clearly decided that it was silly to keep
  54. * doing this while in "lazy" TLB mode, so the optimization involves
  55. * installing the swapper page table instead the first time one
  56. * occurs, and clearing the cpu out of cpu_vm_mask, so the cpu running
  57. * the kernel task doesn't need to take any more interrupts. At that
  58. * point it's then necessary to explicitly reinstall it when context
  59. * switching back to the original mm.
  60. *
  61. * On Tile, we have to do a page-table install whenever DMA is enabled,
  62. * so in that case lazy mode doesn't help anyway. And more generally,
  63. * we have efficient per-page TLB shootdown, and don't expect to spend
  64. * that much time in kernel tasks in general, so just leaving the
  65. * kernel task borrowing the old page table, but handling TLB
  66. * shootdowns, is a reasonable thing to do. And importantly, this
  67. * lets us use the hypervisor's internal APIs for TLB shootdown, which
  68. * means we don't have to worry about having TLB shootdowns blocked
  69. * when Linux is disabling interrupts; see the page migration code for
  70. * an example of where it's important for TLB shootdowns to complete
  71. * even when interrupts are disabled at the Linux level.
  72. */
  73. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *t)
  74. {
  75. #if CHIP_HAS_TILE_DMA()
  76. /*
  77. * We have to do an "identity" page table switch in order to
  78. * clear any pending DMA interrupts.
  79. */
  80. if (current->thread.tile_dma_state.enabled)
  81. install_page_table(mm->pgd, __this_cpu_read(current_asid));
  82. #endif
  83. }
  84. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  85. struct task_struct *tsk)
  86. {
  87. if (likely(prev != next)) {
  88. int cpu = smp_processor_id();
  89. /* Pick new ASID. */
  90. int asid = __this_cpu_read(current_asid) + 1;
  91. if (asid > max_asid) {
  92. asid = min_asid;
  93. local_flush_tlb();
  94. }
  95. __this_cpu_write(current_asid, asid);
  96. /* Clear cpu from the old mm, and set it in the new one. */
  97. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  98. cpumask_set_cpu(cpu, mm_cpumask(next));
  99. /* Re-load page tables */
  100. install_page_table(next->pgd, asid);
  101. /* See how we should set the red/black cache info */
  102. check_mm_caching(prev, next);
  103. /*
  104. * Since we're changing to a new mm, we have to flush
  105. * the icache in case some physical page now being mapped
  106. * has subsequently been repurposed and has new code.
  107. */
  108. __flush_icache();
  109. }
  110. }
  111. static inline void activate_mm(struct mm_struct *prev_mm,
  112. struct mm_struct *next_mm)
  113. {
  114. switch_mm(prev_mm, next_mm, NULL);
  115. }
  116. #define destroy_context(mm) do { } while (0)
  117. #define deactivate_mm(tsk, mm) do { } while (0)
  118. #endif /* _ASM_TILE_MMU_CONTEXT_H */