mmu_context_32.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. *
  15. * Derived from "arch/i386/mm/init.c"
  16. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. *
  23. */
  24. #include <linux/mm.h>
  25. #include <linux/init.h>
  26. #include <asm/mmu_context.h>
  27. #include <asm/tlbflush.h>
  28. unsigned long next_mmu_context;
  29. unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1];
  30. #ifdef FEW_CONTEXTS
  31. atomic_t nr_free_contexts;
  32. struct mm_struct *context_mm[LAST_CONTEXT+1];
  33. void steal_context(void);
  34. #endif /* FEW_CONTEXTS */
  35. /*
  36. * Initialize the context management stuff.
  37. */
  38. void __init
  39. mmu_context_init(void)
  40. {
  41. /*
  42. * Some processors have too few contexts to reserve one for
  43. * init_mm, and require using context 0 for a normal task.
  44. * Other processors reserve the use of context zero for the kernel.
  45. * This code assumes FIRST_CONTEXT < 32.
  46. */
  47. context_map[0] = (1 << FIRST_CONTEXT) - 1;
  48. next_mmu_context = FIRST_CONTEXT;
  49. #ifdef FEW_CONTEXTS
  50. atomic_set(&nr_free_contexts, LAST_CONTEXT - FIRST_CONTEXT + 1);
  51. #endif /* FEW_CONTEXTS */
  52. }
  53. #ifdef FEW_CONTEXTS
  54. /*
  55. * Steal a context from a task that has one at the moment.
  56. * This is only used on 8xx and 4xx and we presently assume that
  57. * they don't do SMP. If they do then this will have to check
  58. * whether the MM we steal is in use.
  59. * We also assume that this is only used on systems that don't
  60. * use an MMU hash table - this is true for 8xx and 4xx.
  61. * This isn't an LRU system, it just frees up each context in
  62. * turn (sort-of pseudo-random replacement :). This would be the
  63. * place to implement an LRU scheme if anyone was motivated to do it.
  64. * -- paulus
  65. */
  66. void
  67. steal_context(void)
  68. {
  69. struct mm_struct *mm;
  70. /* free up context `next_mmu_context' */
  71. /* if we shouldn't free context 0, don't... */
  72. if (next_mmu_context < FIRST_CONTEXT)
  73. next_mmu_context = FIRST_CONTEXT;
  74. mm = context_mm[next_mmu_context];
  75. flush_tlb_mm(mm);
  76. destroy_context(mm);
  77. }
  78. #endif /* FEW_CONTEXTS */