mmu_context.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 bool mm_iommu_preregistered(void);
  19. extern long mm_iommu_get(unsigned long ua, unsigned long entries,
  20. struct mm_iommu_table_group_mem_t **pmem);
  21. extern long mm_iommu_put(struct mm_iommu_table_group_mem_t *mem);
  22. extern void mm_iommu_init(mm_context_t *ctx);
  23. extern void mm_iommu_cleanup(mm_context_t *ctx);
  24. extern struct mm_iommu_table_group_mem_t *mm_iommu_lookup(unsigned long ua,
  25. unsigned long size);
  26. extern struct mm_iommu_table_group_mem_t *mm_iommu_find(unsigned long ua,
  27. unsigned long entries);
  28. extern long mm_iommu_ua_to_hpa(struct mm_iommu_table_group_mem_t *mem,
  29. unsigned long ua, unsigned long *hpa);
  30. extern long mm_iommu_mapped_inc(struct mm_iommu_table_group_mem_t *mem);
  31. extern void mm_iommu_mapped_dec(struct mm_iommu_table_group_mem_t *mem);
  32. #endif
  33. extern void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next);
  34. extern void switch_slb(struct task_struct *tsk, struct mm_struct *mm);
  35. extern void set_context(unsigned long id, pgd_t *pgd);
  36. #ifdef CONFIG_PPC_BOOK3S_64
  37. extern int __init_new_context(void);
  38. extern void __destroy_context(int context_id);
  39. static inline void mmu_context_init(void) { }
  40. #else
  41. extern unsigned long __init_new_context(void);
  42. extern void __destroy_context(unsigned long context_id);
  43. extern void mmu_context_init(void);
  44. #endif
  45. extern void switch_cop(struct mm_struct *next);
  46. extern int use_cop(unsigned long acop, struct mm_struct *mm);
  47. extern void drop_cop(unsigned long acop, struct mm_struct *mm);
  48. /*
  49. * switch_mm is the entry point called from the architecture independent
  50. * code in kernel/sched/core.c
  51. */
  52. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  53. struct task_struct *tsk)
  54. {
  55. /* Mark this context has been used on the new CPU */
  56. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  57. /* 32-bit keeps track of the current PGDIR in the thread struct */
  58. #ifdef CONFIG_PPC32
  59. tsk->thread.pgdir = next->pgd;
  60. #endif /* CONFIG_PPC32 */
  61. /* 64-bit Book3E keeps track of current PGD in the PACA */
  62. #ifdef CONFIG_PPC_BOOK3E_64
  63. get_paca()->pgd = next->pgd;
  64. #endif
  65. /* Nothing else to do if we aren't actually switching */
  66. if (prev == next)
  67. return;
  68. #ifdef CONFIG_PPC_ICSWX
  69. /* Switch coprocessor context only if prev or next uses a coprocessor */
  70. if (prev->context.acop || next->context.acop)
  71. switch_cop(next);
  72. #endif /* CONFIG_PPC_ICSWX */
  73. /* We must stop all altivec streams before changing the HW
  74. * context
  75. */
  76. #ifdef CONFIG_ALTIVEC
  77. if (cpu_has_feature(CPU_FTR_ALTIVEC))
  78. asm volatile ("dssall");
  79. #endif /* CONFIG_ALTIVEC */
  80. /* The actual HW switching method differs between the various
  81. * sub architectures.
  82. */
  83. #ifdef CONFIG_PPC_STD_MMU_64
  84. switch_slb(tsk, next);
  85. #else
  86. /* Out of line for now */
  87. switch_mmu_context(prev, next);
  88. #endif
  89. }
  90. #define deactivate_mm(tsk,mm) do { } while (0)
  91. /*
  92. * After we have set current->mm to a new value, this activates
  93. * the context for the new mm so we see the new mappings.
  94. */
  95. static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)
  96. {
  97. unsigned long flags;
  98. local_irq_save(flags);
  99. switch_mm(prev, next, current);
  100. local_irq_restore(flags);
  101. }
  102. /* We don't currently use enter_lazy_tlb() for anything */
  103. static inline void enter_lazy_tlb(struct mm_struct *mm,
  104. struct task_struct *tsk)
  105. {
  106. /* 64-bit Book3E keeps track of current PGD in the PACA */
  107. #ifdef CONFIG_PPC_BOOK3E_64
  108. get_paca()->pgd = NULL;
  109. #endif
  110. }
  111. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  112. struct mm_struct *mm)
  113. {
  114. }
  115. static inline void arch_exit_mmap(struct mm_struct *mm)
  116. {
  117. }
  118. static inline void arch_unmap(struct mm_struct *mm,
  119. struct vm_area_struct *vma,
  120. unsigned long start, unsigned long end)
  121. {
  122. if (start <= mm->context.vdso_base && mm->context.vdso_base < end)
  123. mm->context.vdso_base = 0;
  124. }
  125. static inline void arch_bprm_mm_init(struct mm_struct *mm,
  126. struct vm_area_struct *vma)
  127. {
  128. }
  129. #endif /* __KERNEL__ */
  130. #endif /* __ASM_POWERPC_MMU_CONTEXT_H */