mmu_context_mm.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2008-2009 PetaLogix
  4. * Copyright (C) 2006 Atmark Techno, Inc.
  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. #ifndef _ASM_MICROBLAZE_MMU_CONTEXT_H
  11. #define _ASM_MICROBLAZE_MMU_CONTEXT_H
  12. #include <linux/atomic.h>
  13. #include <asm/bitops.h>
  14. #include <asm/mmu.h>
  15. #include <asm-generic/mm_hooks.h>
  16. # ifdef __KERNEL__
  17. /*
  18. * This function defines the mapping from contexts to VSIDs (virtual
  19. * segment IDs). We use a skew on both the context and the high 4 bits
  20. * of the 32-bit virtual address (the "effective segment ID") in order
  21. * to spread out the entries in the MMU hash table.
  22. */
  23. # define CTX_TO_VSID(ctx, va) (((ctx) * (897 * 16) + ((va) >> 28) * 0x111) \
  24. & 0xffffff)
  25. /*
  26. MicroBlaze has 256 contexts, so we can just rotate through these
  27. as a way of "switching" contexts. If the TID of the TLB is zero,
  28. the PID/TID comparison is disabled, so we can use a TID of zero
  29. to represent all kernel pages as shared among all contexts.
  30. */
  31. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  32. {
  33. }
  34. # define NO_CONTEXT 256
  35. # define LAST_CONTEXT 255
  36. # define FIRST_CONTEXT 1
  37. /*
  38. * Set the current MMU context.
  39. * This is done byloading up the segment registers for the user part of the
  40. * address space.
  41. *
  42. * Since the PGD is immediately available, it is much faster to simply
  43. * pass this along as a second parameter, which is required for 8xx and
  44. * can be used for debugging on all processors (if you happen to have
  45. * an Abatron).
  46. */
  47. extern void set_context(mm_context_t context, pgd_t *pgd);
  48. /*
  49. * Bitmap of contexts in use.
  50. * The size of this bitmap is LAST_CONTEXT + 1 bits.
  51. */
  52. extern unsigned long context_map[];
  53. /*
  54. * This caches the next context number that we expect to be free.
  55. * Its use is an optimization only, we can't rely on this context
  56. * number to be free, but it usually will be.
  57. */
  58. extern mm_context_t next_mmu_context;
  59. /*
  60. * Since we don't have sufficient contexts to give one to every task
  61. * that could be in the system, we need to be able to steal contexts.
  62. * These variables support that.
  63. */
  64. extern atomic_t nr_free_contexts;
  65. extern struct mm_struct *context_mm[LAST_CONTEXT+1];
  66. extern void steal_context(void);
  67. /*
  68. * Get a new mmu context for the address space described by `mm'.
  69. */
  70. static inline void get_mmu_context(struct mm_struct *mm)
  71. {
  72. mm_context_t ctx;
  73. if (mm->context != NO_CONTEXT)
  74. return;
  75. while (atomic_dec_if_positive(&nr_free_contexts) < 0)
  76. steal_context();
  77. ctx = next_mmu_context;
  78. while (test_and_set_bit(ctx, context_map)) {
  79. ctx = find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx);
  80. if (ctx > LAST_CONTEXT)
  81. ctx = 0;
  82. }
  83. next_mmu_context = (ctx + 1) & LAST_CONTEXT;
  84. mm->context = ctx;
  85. context_mm[ctx] = mm;
  86. }
  87. /*
  88. * Set up the context for a new address space.
  89. */
  90. # define init_new_context(tsk, mm) (((mm)->context = NO_CONTEXT), 0)
  91. /*
  92. * We're finished using the context for an address space.
  93. */
  94. static inline void destroy_context(struct mm_struct *mm)
  95. {
  96. if (mm->context != NO_CONTEXT) {
  97. clear_bit(mm->context, context_map);
  98. mm->context = NO_CONTEXT;
  99. atomic_inc(&nr_free_contexts);
  100. }
  101. }
  102. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  103. struct task_struct *tsk)
  104. {
  105. tsk->thread.pgdir = next->pgd;
  106. get_mmu_context(next);
  107. set_context(next->context, next->pgd);
  108. }
  109. /*
  110. * After we have set current->mm to a new value, this activates
  111. * the context for the new mm so we see the new mappings.
  112. */
  113. static inline void activate_mm(struct mm_struct *active_mm,
  114. struct mm_struct *mm)
  115. {
  116. current->thread.pgdir = mm->pgd;
  117. get_mmu_context(mm);
  118. set_context(mm->context, mm->pgd);
  119. }
  120. extern void mmu_context_init(void);
  121. # endif /* __KERNEL__ */
  122. #endif /* _ASM_MICROBLAZE_MMU_CONTEXT_H */