mmu_context.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * include/asm-xtensa/mmu_context.h
  3. *
  4. * Switch an MMU context.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (C) 2001 - 2005 Tensilica Inc.
  11. */
  12. #ifndef _XTENSA_MMU_CONTEXT_H
  13. #define _XTENSA_MMU_CONTEXT_H
  14. #include <linux/stringify.h>
  15. #include <asm/pgtable.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/tlbflush.h>
  18. #define XCHAL_MMU_ASID_BITS 8
  19. #if (XCHAL_HAVE_TLBS != 1)
  20. # error "Linux must have an MMU!"
  21. #endif
  22. extern unsigned long asid_cache;
  23. /*
  24. * NO_CONTEXT is the invalid ASID value that we don't ever assign to
  25. * any user or kernel context.
  26. *
  27. * 0 invalid
  28. * 1 kernel
  29. * 2 reserved
  30. * 3 reserved
  31. * 4...255 available
  32. */
  33. #define NO_CONTEXT 0
  34. #define ASID_USER_FIRST 4
  35. #define ASID_MASK ((1 << XCHAL_MMU_ASID_BITS) - 1)
  36. #define ASID_INSERT(x) (0x03020001 | (((x) & ASID_MASK) << 8))
  37. static inline void set_rasid_register (unsigned long val)
  38. {
  39. __asm__ __volatile__ (" wsr %0, "__stringify(RASID)"\n\t"
  40. " isync\n" : : "a" (val));
  41. }
  42. static inline unsigned long get_rasid_register (void)
  43. {
  44. unsigned long tmp;
  45. __asm__ __volatile__ (" rsr %0,"__stringify(RASID)"\n\t" : "=a" (tmp));
  46. return tmp;
  47. }
  48. static inline void
  49. __get_new_mmu_context(struct mm_struct *mm)
  50. {
  51. extern void flush_tlb_all(void);
  52. if (! (++asid_cache & ASID_MASK) ) {
  53. flush_tlb_all(); /* start new asid cycle */
  54. asid_cache += ASID_USER_FIRST;
  55. }
  56. mm->context = asid_cache;
  57. }
  58. static inline void
  59. __load_mmu_context(struct mm_struct *mm)
  60. {
  61. set_rasid_register(ASID_INSERT(mm->context));
  62. invalidate_page_directory();
  63. }
  64. /*
  65. * Initialize the context related info for a new mm_struct
  66. * instance.
  67. */
  68. static inline int
  69. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  70. {
  71. mm->context = NO_CONTEXT;
  72. return 0;
  73. }
  74. /*
  75. * After we have set current->mm to a new value, this activates
  76. * the context for the new mm so we see the new mappings.
  77. */
  78. static inline void
  79. activate_mm(struct mm_struct *prev, struct mm_struct *next)
  80. {
  81. /* Unconditionally get a new ASID. */
  82. __get_new_mmu_context(next);
  83. __load_mmu_context(next);
  84. }
  85. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  86. struct task_struct *tsk)
  87. {
  88. unsigned long asid = asid_cache;
  89. /* Check if our ASID is of an older version and thus invalid */
  90. if (next->context == NO_CONTEXT || ((next->context^asid) & ~ASID_MASK))
  91. __get_new_mmu_context(next);
  92. __load_mmu_context(next);
  93. }
  94. #define deactivate_mm(tsk, mm) do { } while(0)
  95. /*
  96. * Destroy context related info for an mm_struct that is about
  97. * to be put to rest.
  98. */
  99. static inline void destroy_context(struct mm_struct *mm)
  100. {
  101. invalidate_page_directory();
  102. }
  103. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  104. {
  105. /* Nothing to do. */
  106. }
  107. #endif /* _XTENSA_MMU_CONTEXT_H */