4 * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org>
5 * Copyright (C) 2003 Richard Curnow <richard.curnow@superh.com>
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
13 #include <linux/init.h>
16 #include <asm/mmu_context.h>
21 * Perform initial setup for the DTLB and ITLB.
23 int __init sh64_tlb_init(void)
25 /* Assign some sane DTLB defaults */
26 cpu_data->dtlb.entries = 64;
27 cpu_data->dtlb.step = 0x10;
29 cpu_data->dtlb.first = DTLB_FIXED | cpu_data->dtlb.step;
30 cpu_data->dtlb.next = cpu_data->dtlb.first;
32 cpu_data->dtlb.last = DTLB_FIXED |
33 ((cpu_data->dtlb.entries - 1) *
36 /* And again for the ITLB */
37 cpu_data->itlb.entries = 64;
38 cpu_data->itlb.step = 0x10;
40 cpu_data->itlb.first = ITLB_FIXED | cpu_data->itlb.step;
41 cpu_data->itlb.next = cpu_data->itlb.first;
42 cpu_data->itlb.last = ITLB_FIXED |
43 ((cpu_data->itlb.entries - 1) *
50 * sh64_next_free_dtlb_entry
52 * Find the next available DTLB entry
54 unsigned long long sh64_next_free_dtlb_entry(void)
56 return cpu_data->dtlb.next;
60 * sh64_get_wired_dtlb_entry
62 * Allocate a wired (locked-in) entry in the DTLB
64 unsigned long long sh64_get_wired_dtlb_entry(void)
66 unsigned long long entry = sh64_next_free_dtlb_entry();
68 cpu_data->dtlb.first += cpu_data->dtlb.step;
69 cpu_data->dtlb.next += cpu_data->dtlb.step;
75 * sh64_put_wired_dtlb_entry
77 * @entry: Address of TLB slot.
79 * Free a wired (locked-in) entry in the DTLB.
81 * Works like a stack, last one to allocate must be first one to free.
83 int sh64_put_wired_dtlb_entry(unsigned long long entry)
85 __flush_tlb_slot(entry);
88 * We don't do any particularly useful tracking of wired entries,
89 * so this approach works like a stack .. last one to be allocated
90 * has to be the first one to be freed.
92 * We could potentially load wired entries into a list and work on
93 * rebalancing the list periodically (which also entails moving the
94 * contents of a TLB entry) .. though I have a feeling that this is
95 * more trouble than it's worth.
99 * Entry must be valid .. we don't want any ITLB addresses!
101 if (entry <= DTLB_FIXED)
105 * Next, check if we're within range to be freed. (ie, must be the
106 * entry beneath the first 'free' entry!
108 if (entry < (cpu_data->dtlb.first - cpu_data->dtlb.step))
111 /* If we are, then bring this entry back into the list */
112 cpu_data->dtlb.first -= cpu_data->dtlb.step;
113 cpu_data->dtlb.next = entry;
119 * sh64_setup_tlb_slot
121 * @config_addr: Address of TLB slot.
122 * @eaddr: Virtual address.
123 * @asid: Address Space Identifier.
124 * @paddr: Physical address.
126 * Load up a virtual<->physical translation for @eaddr<->@paddr in the
127 * pre-allocated TLB slot @config_addr (see sh64_get_wired_dtlb_entry).
129 inline void sh64_setup_tlb_slot(unsigned long long config_addr,
134 unsigned long long pteh, ptel;
138 pteh = (unsigned long long)(signed long long)(signed long) eaddr;
140 #error "Can't sign extend more than 32 bits yet"
143 pteh |= (asid << PTEH_ASID_SHIFT) | PTEH_VALID;
145 ptel = (unsigned long long)(signed long long)(signed long) paddr;
147 #error "Can't sign extend more than 32 bits yet"
150 ptel |= (_PAGE_CACHABLE | _PAGE_READ | _PAGE_WRITE);
152 asm volatile("putcfg %0, 1, %1\n\t"
154 : : "r" (config_addr), "r" (ptel), "r" (pteh));
158 * sh64_teardown_tlb_slot
160 * @config_addr: Address of TLB slot.
162 * Teardown any existing mapping in the TLB slot @config_addr.
164 inline void sh64_teardown_tlb_slot(unsigned long long config_addr)
165 __attribute__ ((alias("__flush_tlb_slot")));