mmu_context_64.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * MMU context allocation for 64-bit kernels.
  3. *
  4. * Copyright (C) 2004 Anton Blanchard, IBM Corp. <anton@samba.org>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/string.h>
  16. #include <linux/types.h>
  17. #include <linux/mm.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/idr.h>
  20. #include <asm/mmu_context.h>
  21. static DEFINE_SPINLOCK(mmu_context_lock);
  22. static DEFINE_IDR(mmu_context_idr);
  23. int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  24. {
  25. int index;
  26. int err;
  27. int new_context = (mm->context.id == 0);
  28. again:
  29. if (!idr_pre_get(&mmu_context_idr, GFP_KERNEL))
  30. return -ENOMEM;
  31. spin_lock(&mmu_context_lock);
  32. err = idr_get_new_above(&mmu_context_idr, NULL, 1, &index);
  33. spin_unlock(&mmu_context_lock);
  34. if (err == -EAGAIN)
  35. goto again;
  36. else if (err)
  37. return err;
  38. if (index > MAX_CONTEXT) {
  39. spin_lock(&mmu_context_lock);
  40. idr_remove(&mmu_context_idr, index);
  41. spin_unlock(&mmu_context_lock);
  42. return -ENOMEM;
  43. }
  44. mm->context.id = index;
  45. #ifdef CONFIG_PPC_MM_SLICES
  46. /* The old code would re-promote on fork, we don't do that
  47. * when using slices as it could cause problem promoting slices
  48. * that have been forced down to 4K
  49. */
  50. if (new_context)
  51. slice_set_user_psize(mm, mmu_virtual_psize);
  52. #else
  53. mm->context.user_psize = mmu_virtual_psize;
  54. mm->context.sllp = SLB_VSID_USER |
  55. mmu_psize_defs[mmu_virtual_psize].sllp;
  56. #endif
  57. return 0;
  58. }
  59. void destroy_context(struct mm_struct *mm)
  60. {
  61. spin_lock(&mmu_context_lock);
  62. idr_remove(&mmu_context_idr, mm->context.id);
  63. spin_unlock(&mmu_context_lock);
  64. mm->context.id = NO_CONTEXT;
  65. }