mmu_context.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * This file contains the routines for handling the MMU.
  4. *
  5. * Copyright (C) 2007 Xilinx, Inc. All rights reserved.
  6. *
  7. * Derived from arch/ppc/mm/4xx_mmu.c:
  8. * -- paulus
  9. *
  10. * Derived from arch/ppc/mm/init.c:
  11. * Copyright (C) 1995-1996 Gary Thomas ([email protected])
  12. *
  13. * Modifications by Paul Mackerras (PowerMac) ([email protected])
  14. * and Cort Dougan (PReP) ([email protected])
  15. * Copyright (C) 1996 Paul Mackerras
  16. * Amiga/APUS changes by Jesper Skov ([email protected]).
  17. *
  18. * Derived from "arch/i386/mm/init.c"
  19. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  20. */
  21. #include <linux/mm.h>
  22. #include <linux/init.h>
  23. #include <asm/tlbflush.h>
  24. #include <asm/mmu_context.h>
  25. mm_context_t next_mmu_context;
  26. unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1];
  27. atomic_t nr_free_contexts;
  28. struct mm_struct *context_mm[LAST_CONTEXT+1];
  29. /*
  30. * Initialize the context management stuff.
  31. */
  32. void __init mmu_context_init(void)
  33. {
  34. /*
  35. * The use of context zero is reserved for the kernel.
  36. * This code assumes FIRST_CONTEXT < 32.
  37. */
  38. context_map[0] = (1 << FIRST_CONTEXT) - 1;
  39. next_mmu_context = FIRST_CONTEXT;
  40. atomic_set(&nr_free_contexts, LAST_CONTEXT - FIRST_CONTEXT + 1);
  41. }
  42. /*
  43. * Steal a context from a task that has one at the moment.
  44. *
  45. * This isn't an LRU system, it just frees up each context in
  46. * turn (sort-of pseudo-random replacement :). This would be the
  47. * place to implement an LRU scheme if anyone were motivated to do it.
  48. */
  49. void steal_context(void)
  50. {
  51. struct mm_struct *mm;
  52. /* free up context `next_mmu_context' */
  53. /* if we shouldn't free context 0, don't... */
  54. if (next_mmu_context < FIRST_CONTEXT)
  55. next_mmu_context = FIRST_CONTEXT;
  56. mm = context_mm[next_mmu_context];
  57. flush_tlb_mm(mm);
  58. destroy_context(mm);
  59. }