mmu_context.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This file contains the routines for handling the MMU on those
  3. * PowerPC implementations where the MMU substantially follows the
  4. * architecture specification. This includes the 6xx, 7xx, 7xxx,
  5. * 8260, and POWER3 implementations but excludes the 8xx and 4xx.
  6. * -- paulus
  7. *
  8. * Derived from arch/ppc/mm/init.c:
  9. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  10. *
  11. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  12. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  13. * Copyright (C) 1996 Paul Mackerras
  14. * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
  15. *
  16. * Derived from "arch/i386/mm/init.c"
  17. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License
  21. * as published by the Free Software Foundation; either version
  22. * 2 of the License, or (at your option) any later version.
  23. *
  24. */
  25. #include <linux/config.h>
  26. #include <linux/mm.h>
  27. #include <linux/init.h>
  28. #include <asm/mmu_context.h>
  29. #include <asm/tlbflush.h>
  30. mm_context_t next_mmu_context;
  31. unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1];
  32. #ifdef FEW_CONTEXTS
  33. atomic_t nr_free_contexts;
  34. struct mm_struct *context_mm[LAST_CONTEXT+1];
  35. void steal_context(void);
  36. #endif /* FEW_CONTEXTS */
  37. /*
  38. * Initialize the context management stuff.
  39. */
  40. void __init
  41. mmu_context_init(void)
  42. {
  43. /*
  44. * Some processors have too few contexts to reserve one for
  45. * init_mm, and require using context 0 for a normal task.
  46. * Other processors reserve the use of context zero for the kernel.
  47. * This code assumes FIRST_CONTEXT < 32.
  48. */
  49. context_map[0] = (1 << FIRST_CONTEXT) - 1;
  50. next_mmu_context = FIRST_CONTEXT;
  51. #ifdef FEW_CONTEXTS
  52. atomic_set(&nr_free_contexts, LAST_CONTEXT - FIRST_CONTEXT + 1);
  53. #endif /* FEW_CONTEXTS */
  54. }
  55. #ifdef FEW_CONTEXTS
  56. /*
  57. * Steal a context from a task that has one at the moment.
  58. * This is only used on 8xx and 4xx and we presently assume that
  59. * they don't do SMP. If they do then this will have to check
  60. * whether the MM we steal is in use.
  61. * We also assume that this is only used on systems that don't
  62. * use an MMU hash table - this is true for 8xx and 4xx.
  63. * This isn't an LRU system, it just frees up each context in
  64. * turn (sort-of pseudo-random replacement :). This would be the
  65. * place to implement an LRU scheme if anyone was motivated to do it.
  66. * -- paulus
  67. */
  68. void
  69. steal_context(void)
  70. {
  71. struct mm_struct *mm;
  72. /* free up context `next_mmu_context' */
  73. /* if we shouldn't free context 0, don't... */
  74. if (next_mmu_context < FIRST_CONTEXT)
  75. next_mmu_context = FIRST_CONTEXT;
  76. mm = context_mm[next_mmu_context];
  77. flush_tlb_mm(mm);
  78. destroy_context(mm);
  79. }
  80. #endif /* FEW_CONTEXTS */