tlb-urb.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. status = __raw_readl(MMUCR);
  25. urb = (status & MMUCR_URB) >> MMUCR_URB_SHIFT;
  26. status &= ~MMUCR_URC;
  27. /*
  28. * Make sure we're not trying to wire the last TLB entry slot.
  29. */
  30. BUG_ON(!--urb);
  31. urb = urb % MMUCR_URB_NENTRIES;
  32. /*
  33. * Insert this entry into the highest non-wired TLB slot (via
  34. * the URC field).
  35. */
  36. status |= (urb << MMUCR_URC_SHIFT);
  37. __raw_writel(status, MMUCR);
  38. ctrl_barrier();
  39. /* Load the entry into the TLB */
  40. __update_tlb(vma, addr, pte);
  41. /* ... and wire it up. */
  42. status = __raw_readl(MMUCR);
  43. status &= ~MMUCR_URB;
  44. status |= (urb << MMUCR_URB_SHIFT);
  45. __raw_writel(status, MMUCR);
  46. ctrl_barrier();
  47. local_irq_restore(flags);
  48. }
  49. /*
  50. * Unwire the last wired TLB entry.
  51. *
  52. * It should also be noted that it is not possible to wire and unwire
  53. * TLB entries in an arbitrary order. If you wire TLB entry N, followed
  54. * by entry N+1, you must unwire entry N+1 first, then entry N. In this
  55. * respect, it works like a stack or LIFO queue.
  56. */
  57. void tlb_unwire_entry(void)
  58. {
  59. unsigned long status, flags;
  60. int urb;
  61. local_irq_save(flags);
  62. status = __raw_readl(MMUCR);
  63. urb = (status & MMUCR_URB) >> MMUCR_URB_SHIFT;
  64. status &= ~MMUCR_URB;
  65. /*
  66. * Make sure we're not trying to unwire a TLB entry when none
  67. * have been wired.
  68. */
  69. BUG_ON(urb++ == MMUCR_URB_NENTRIES);
  70. urb = urb % MMUCR_URB_NENTRIES;
  71. status |= (urb << MMUCR_URB_SHIFT);
  72. __raw_writel(status, MMUCR);
  73. ctrl_barrier();
  74. local_irq_restore(flags);
  75. }