mmu_context.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #ifndef __ASM_POWERPC_MMU_CONTEXT_H
  2. #define __ASM_POWERPC_MMU_CONTEXT_H
  3. #ifdef __KERNEL__
  4. #include <linux/kernel.h>
  5. #include <linux/mm.h>
  6. #include <linux/sched.h>
  7. #include <linux/spinlock.h>
  8. #include <asm/mmu.h>
  9. #include <asm/cputable.h>
  10. #include <asm/cputhreads.h>
  11. /*
  12. * Most if the context management is out of line
  13. */
  14. extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  15. extern void destroy_context(struct mm_struct *mm);
  16. #ifdef CONFIG_SPAPR_TCE_IOMMU
  17. struct mm_iommu_table_group_mem_t;
  18. extern int isolate_lru_page(struct page *page); /* from internal.h */
  19. extern bool mm_iommu_preregistered(struct mm_struct *mm);
  20. extern long mm_iommu_get(struct mm_struct *mm,
  21. unsigned long ua, unsigned long entries,
  22. struct mm_iommu_table_group_mem_t **pmem);
  23. extern long mm_iommu_put(struct mm_struct *mm,
  24. struct mm_iommu_table_group_mem_t *mem);
  25. extern void mm_iommu_init(struct mm_struct *mm);
  26. extern void mm_iommu_cleanup(struct mm_struct *mm);
  27. extern struct mm_iommu_table_group_mem_t *mm_iommu_lookup(struct mm_struct *mm,
  28. unsigned long ua, unsigned long size);
  29. extern struct mm_iommu_table_group_mem_t *mm_iommu_find(struct mm_struct *mm,
  30. unsigned long ua, unsigned long entries);
  31. extern long mm_iommu_ua_to_hpa(struct mm_iommu_table_group_mem_t *mem,
  32. unsigned long ua, unsigned long *hpa);
  33. extern long mm_iommu_mapped_inc(struct mm_iommu_table_group_mem_t *mem);
  34. extern void mm_iommu_mapped_dec(struct mm_iommu_table_group_mem_t *mem);
  35. #endif
  36. extern void switch_slb(struct task_struct *tsk, struct mm_struct *mm);
  37. extern void set_context(unsigned long id, pgd_t *pgd);
  38. #ifdef CONFIG_PPC_BOOK3S_64
  39. extern void radix__switch_mmu_context(struct mm_struct *prev,
  40. struct mm_struct *next);
  41. static inline void switch_mmu_context(struct mm_struct *prev,
  42. struct mm_struct *next,
  43. struct task_struct *tsk)
  44. {
  45. if (radix_enabled())
  46. return radix__switch_mmu_context(prev, next);
  47. return switch_slb(tsk, next);
  48. }
  49. extern int __init_new_context(void);
  50. extern void __destroy_context(int context_id);
  51. static inline void mmu_context_init(void) { }
  52. #else
  53. extern void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next,
  54. struct task_struct *tsk);
  55. extern unsigned long __init_new_context(void);
  56. extern void __destroy_context(unsigned long context_id);
  57. extern void mmu_context_init(void);
  58. #endif
  59. extern void switch_cop(struct mm_struct *next);
  60. extern int use_cop(unsigned long acop, struct mm_struct *mm);
  61. extern void drop_cop(unsigned long acop, struct mm_struct *mm);
  62. /*
  63. * switch_mm is the entry point called from the architecture independent
  64. * code in kernel/sched/core.c
  65. */
  66. static inline void switch_mm_irqs_off(struct mm_struct *prev,
  67. struct mm_struct *next,
  68. struct task_struct *tsk)
  69. {
  70. /* Mark this context has been used on the new CPU */
  71. if (!cpumask_test_cpu(smp_processor_id(), mm_cpumask(next))) {
  72. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  73. /*
  74. * This full barrier orders the store to the cpumask above vs
  75. * a subsequent operation which allows this CPU to begin loading
  76. * translations for next.
  77. *
  78. * When using the radix MMU that operation is the load of the
  79. * MMU context id, which is then moved to SPRN_PID.
  80. *
  81. * For the hash MMU it is either the first load from slb_cache
  82. * in switch_slb(), and/or the store of paca->mm_ctx_id in
  83. * copy_mm_to_paca().
  84. *
  85. * On the read side the barrier is in pte_xchg(), which orders
  86. * the store to the PTE vs the load of mm_cpumask.
  87. */
  88. smp_mb();
  89. }
  90. /* 32-bit keeps track of the current PGDIR in the thread struct */
  91. #ifdef CONFIG_PPC32
  92. tsk->thread.pgdir = next->pgd;
  93. #endif /* CONFIG_PPC32 */
  94. /* 64-bit Book3E keeps track of current PGD in the PACA */
  95. #ifdef CONFIG_PPC_BOOK3E_64
  96. get_paca()->pgd = next->pgd;
  97. #endif
  98. /* Nothing else to do if we aren't actually switching */
  99. if (prev == next)
  100. return;
  101. #ifdef CONFIG_PPC_ICSWX
  102. /* Switch coprocessor context only if prev or next uses a coprocessor */
  103. if (prev->context.acop || next->context.acop)
  104. switch_cop(next);
  105. #endif /* CONFIG_PPC_ICSWX */
  106. /* We must stop all altivec streams before changing the HW
  107. * context
  108. */
  109. #ifdef CONFIG_ALTIVEC
  110. if (cpu_has_feature(CPU_FTR_ALTIVEC))
  111. asm volatile ("dssall");
  112. #endif /* CONFIG_ALTIVEC */
  113. /*
  114. * The actual HW switching method differs between the various
  115. * sub architectures. Out of line for now
  116. */
  117. switch_mmu_context(prev, next, tsk);
  118. }
  119. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  120. struct task_struct *tsk)
  121. {
  122. unsigned long flags;
  123. local_irq_save(flags);
  124. switch_mm_irqs_off(prev, next, tsk);
  125. local_irq_restore(flags);
  126. }
  127. #define switch_mm_irqs_off switch_mm_irqs_off
  128. #define deactivate_mm(tsk,mm) do { } while (0)
  129. /*
  130. * After we have set current->mm to a new value, this activates
  131. * the context for the new mm so we see the new mappings.
  132. */
  133. static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)
  134. {
  135. unsigned long flags;
  136. local_irq_save(flags);
  137. switch_mm(prev, next, current);
  138. local_irq_restore(flags);
  139. }
  140. /* We don't currently use enter_lazy_tlb() for anything */
  141. static inline void enter_lazy_tlb(struct mm_struct *mm,
  142. struct task_struct *tsk)
  143. {
  144. /* 64-bit Book3E keeps track of current PGD in the PACA */
  145. #ifdef CONFIG_PPC_BOOK3E_64
  146. get_paca()->pgd = NULL;
  147. #endif
  148. }
  149. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  150. struct mm_struct *mm)
  151. {
  152. }
  153. static inline void arch_exit_mmap(struct mm_struct *mm)
  154. {
  155. }
  156. static inline void arch_unmap(struct mm_struct *mm,
  157. struct vm_area_struct *vma,
  158. unsigned long start, unsigned long end)
  159. {
  160. if (start <= mm->context.vdso_base && mm->context.vdso_base < end)
  161. mm->context.vdso_base = 0;
  162. }
  163. static inline void arch_bprm_mm_init(struct mm_struct *mm,
  164. struct vm_area_struct *vma)
  165. {
  166. }
  167. static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
  168. bool write, bool execute, bool foreign)
  169. {
  170. /* by default, allow everything */
  171. return true;
  172. }
  173. static inline bool arch_pte_access_permitted(pte_t pte, bool write)
  174. {
  175. /* by default, allow everything */
  176. return true;
  177. }
  178. #endif /* __KERNEL__ */
  179. #endif /* __ASM_POWERPC_MMU_CONTEXT_H */