tlb-urb.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * arch/sh/mm/tlb-urb.c
  3. *
  4. * TLB entry wiring helpers for URB-equipped parts.
  5. *
  6. * Copyright (C) 2010 Matt Fleming
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/mm.h>
  13. #include <linux/io.h>
  14. #include <asm/tlb.h>
  15. #include <asm/mmu_context.h>
  16. /*
  17. * Load the entry for 'addr' into the TLB and wire the entry.
  18. */
  19. void tlb_wire_entry(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
  20. {
  21. unsigned long status, flags;
  22. int urb;
  23. local_irq_save(flags);
  24. /* Load the entry into the TLB */
  25. __update_tlb(vma, addr, pte);
  26. /* ... and wire it up. */
  27. status = __raw_readl(MMUCR);
  28. urb = (status & MMUCR_URB) >> MMUCR_URB_SHIFT;
  29. status &= ~MMUCR_URB;
  30. /*
  31. * Make sure we're not trying to wire the last TLB entry slot.
  32. */
  33. BUG_ON(!--urb);
  34. urb = urb % MMUCR_URB_NENTRIES;
  35. status |= (urb << MMUCR_URB_SHIFT);
  36. __raw_writel(status, MMUCR);
  37. ctrl_barrier();
  38. local_irq_restore(flags);
  39. }
  40. /*
  41. * Unwire the last wired TLB entry.
  42. *
  43. * It should also be noted that it is not possible to wire and unwire
  44. * TLB entries in an arbitrary order. If you wire TLB entry N, followed
  45. * by entry N+1, you must unwire entry N+1 first, then entry N. In this
  46. * respect, it works like a stack or LIFO queue.
  47. */
  48. void tlb_unwire_entry(void)
  49. {
  50. unsigned long status, flags;
  51. int urb;
  52. local_irq_save(flags);
  53. status = __raw_readl(MMUCR);
  54. urb = (status & MMUCR_URB) >> MMUCR_URB_SHIFT;
  55. status &= ~MMUCR_URB;
  56. /*
  57. * Make sure we're not trying to unwire a TLB entry when none
  58. * have been wired.
  59. */
  60. BUG_ON(urb++ == MMUCR_URB_NENTRIES);
  61. urb = urb % MMUCR_URB_NENTRIES;
  62. status |= (urb << MMUCR_URB_SHIFT);
  63. __raw_writel(status, MMUCR);
  64. ctrl_barrier();
  65. local_irq_restore(flags);
  66. }