Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / arch / sh / mm / tlb-urb.c
blobc92ce20db39bf478dd6db83a0c3ed6dc430ca027
1 /*
2 * arch/sh/mm/tlb-urb.c
4 * TLB entry wiring helpers for URB-equipped parts.
6 * Copyright (C) 2010 Matt Fleming
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.
12 #include <linux/mm.h>
13 #include <linux/io.h>
14 #include <asm/tlb.h>
15 #include <asm/mmu_context.h>
18 * Load the entry for 'addr' into the TLB and wire the entry.
20 void tlb_wire_entry(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
22 unsigned long status, flags;
23 int urb;
25 local_irq_save(flags);
27 status = __raw_readl(MMUCR);
28 urb = (status & MMUCR_URB) >> MMUCR_URB_SHIFT;
29 status &= ~MMUCR_URC;
32 * Make sure we're not trying to wire the last TLB entry slot.
34 BUG_ON(!--urb);
36 urb = urb % MMUCR_URB_NENTRIES;
39 * Insert this entry into the highest non-wired TLB slot (via
40 * the URC field).
42 status |= (urb << MMUCR_URC_SHIFT);
43 __raw_writel(status, MMUCR);
44 ctrl_barrier();
46 /* Load the entry into the TLB */
47 __update_tlb(vma, addr, pte);
49 /* ... and wire it up. */
50 status = __raw_readl(MMUCR);
52 status &= ~MMUCR_URB;
53 status |= (urb << MMUCR_URB_SHIFT);
55 __raw_writel(status, MMUCR);
56 ctrl_barrier();
58 local_irq_restore(flags);
62 * Unwire the last wired TLB entry.
64 * It should also be noted that it is not possible to wire and unwire
65 * TLB entries in an arbitrary order. If you wire TLB entry N, followed
66 * by entry N+1, you must unwire entry N+1 first, then entry N. In this
67 * respect, it works like a stack or LIFO queue.
69 void tlb_unwire_entry(void)
71 unsigned long status, flags;
72 int urb;
74 local_irq_save(flags);
76 status = __raw_readl(MMUCR);
77 urb = (status & MMUCR_URB) >> MMUCR_URB_SHIFT;
78 status &= ~MMUCR_URB;
81 * Make sure we're not trying to unwire a TLB entry when none
82 * have been wired.
84 BUG_ON(urb++ == MMUCR_URB_NENTRIES);
86 urb = urb % MMUCR_URB_NENTRIES;
88 status |= (urb << MMUCR_URB_SHIFT);
89 __raw_writel(status, MMUCR);
90 ctrl_barrier();
92 local_irq_restore(flags);