mmu_context.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef _ASM_SCORE_MMU_CONTEXT_H
  2. #define _ASM_SCORE_MMU_CONTEXT_H
  3. #include <linux/errno.h>
  4. #include <linux/sched.h>
  5. #include <linux/slab.h>
  6. #include <asm-generic/mm_hooks.h>
  7. #include <asm/cacheflush.h>
  8. #include <asm/tlbflush.h>
  9. #include <asm/scoreregs.h>
  10. /*
  11. * For the fast tlb miss handlers, we keep a per cpu array of pointers
  12. * to the current pgd for each processor. Also, the proc. id is stuffed
  13. * into the context register.
  14. */
  15. extern unsigned long asid_cache;
  16. extern unsigned long pgd_current;
  17. #define TLBMISS_HANDLER_SETUP_PGD(pgd) (pgd_current = (unsigned long)(pgd))
  18. #define TLBMISS_HANDLER_SETUP() \
  19. do { \
  20. write_c0_context(0); \
  21. TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir) \
  22. } while (0)
  23. /*
  24. * All unused by hardware upper bits will be considered
  25. * as a software asid extension.
  26. */
  27. #define ASID_VERSION_MASK 0xfffff000
  28. #define ASID_FIRST_VERSION 0x1000
  29. /* PEVN --------- VPN ---------- --ASID--- -NA- */
  30. /* binary: 0000 0000 0000 0000 0000 0000 0001 0000 */
  31. /* binary: 0000 0000 0000 0000 0000 1111 1111 0000 */
  32. #define ASID_INC 0x10
  33. #define ASID_MASK 0xff0
  34. static inline void enter_lazy_tlb(struct mm_struct *mm,
  35. struct task_struct *tsk)
  36. {}
  37. static inline void
  38. get_new_mmu_context(struct mm_struct *mm)
  39. {
  40. unsigned long asid = asid_cache + ASID_INC;
  41. if (!(asid & ASID_MASK)) {
  42. local_flush_tlb_all(); /* start new asid cycle */
  43. if (!asid) /* fix version if needed */
  44. asid = ASID_FIRST_VERSION;
  45. }
  46. mm->context = asid;
  47. asid_cache = asid;
  48. }
  49. /*
  50. * Initialize the context related info for a new mm_struct
  51. * instance.
  52. */
  53. static inline int
  54. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  55. {
  56. mm->context = 0;
  57. return 0;
  58. }
  59. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  60. struct task_struct *tsk)
  61. {
  62. unsigned long flags;
  63. local_irq_save(flags);
  64. if ((next->context ^ asid_cache) & ASID_VERSION_MASK)
  65. get_new_mmu_context(next);
  66. pevn_set(next->context);
  67. TLBMISS_HANDLER_SETUP_PGD(next->pgd);
  68. local_irq_restore(flags);
  69. }
  70. /*
  71. * Destroy context related info for an mm_struct that is about
  72. * to be put to rest.
  73. */
  74. static inline void destroy_context(struct mm_struct *mm)
  75. {}
  76. static inline void
  77. deactivate_mm(struct task_struct *task, struct mm_struct *mm)
  78. {}
  79. /*
  80. * After we have set current->mm to a new value, this activates
  81. * the context for the new mm so we see the new mappings.
  82. */
  83. static inline void
  84. activate_mm(struct mm_struct *prev, struct mm_struct *next)
  85. {
  86. unsigned long flags;
  87. local_irq_save(flags);
  88. get_new_mmu_context(next);
  89. pevn_set(next->context);
  90. TLBMISS_HANDLER_SETUP_PGD(next->pgd);
  91. local_irq_restore(flags);
  92. }
  93. #endif /* _ASM_SCORE_MMU_CONTEXT_H */