mmu_context_64.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. again:
  28. if (!idr_pre_get(&mmu_context_idr, GFP_KERNEL))
  29. return -ENOMEM;
  30. spin_lock(&mmu_context_lock);
  31. err = idr_get_new_above(&mmu_context_idr, NULL, 1, &index);
  32. spin_unlock(&mmu_context_lock);
  33. if (err == -EAGAIN)
  34. goto again;
  35. else if (err)
  36. return err;
  37. if (index > MAX_CONTEXT) {
  38. spin_lock(&mmu_context_lock);
  39. idr_remove(&mmu_context_idr, index);
  40. spin_unlock(&mmu_context_lock);
  41. return -ENOMEM;
  42. }
  43. mm->context.id = index;
  44. mm->context.user_psize = mmu_virtual_psize;
  45. mm->context.sllp = SLB_VSID_USER |
  46. mmu_psize_defs[mmu_virtual_psize].sllp;
  47. return 0;
  48. }
  49. void destroy_context(struct mm_struct *mm)
  50. {
  51. spin_lock(&mmu_context_lock);
  52. idr_remove(&mmu_context_idr, mm->context.id);
  53. spin_unlock(&mmu_context_lock);
  54. mm->context.id = NO_CONTEXT;
  55. }