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
12 #include <linux/init.h>
15 #include <asm/mmu_context.h>
20 * Perform initial setup for the DTLB and ITLB.
22 int __init
sh64_tlb_init(void)
24 /* Assign some sane DTLB defaults */
25 cpu_data
->dtlb
.entries
= 64;
26 cpu_data
->dtlb
.step
= 0x10;
28 cpu_data
->dtlb
.first
= DTLB_FIXED
| cpu_data
->dtlb
.step
;
29 cpu_data
->dtlb
.next
= cpu_data
->dtlb
.first
;
31 cpu_data
->dtlb
.last
= DTLB_FIXED
|
32 ((cpu_data
->dtlb
.entries
- 1) *
35 /* And again for the ITLB */
36 cpu_data
->itlb
.entries
= 64;
37 cpu_data
->itlb
.step
= 0x10;
39 cpu_data
->itlb
.first
= ITLB_FIXED
| cpu_data
->itlb
.step
;
40 cpu_data
->itlb
.next
= cpu_data
->itlb
.first
;
41 cpu_data
->itlb
.last
= ITLB_FIXED
|
42 ((cpu_data
->itlb
.entries
- 1) *
49 * sh64_next_free_dtlb_entry
51 * Find the next available DTLB entry
53 unsigned long long sh64_next_free_dtlb_entry(void)
55 return cpu_data
->dtlb
.next
;
59 * sh64_get_wired_dtlb_entry
61 * Allocate a wired (locked-in) entry in the DTLB
63 unsigned long long sh64_get_wired_dtlb_entry(void)
65 unsigned long long entry
= sh64_next_free_dtlb_entry();
67 cpu_data
->dtlb
.first
+= cpu_data
->dtlb
.step
;
68 cpu_data
->dtlb
.next
+= cpu_data
->dtlb
.step
;
74 * sh64_put_wired_dtlb_entry
76 * @entry: Address of TLB slot.
78 * Free a wired (locked-in) entry in the DTLB.
80 * Works like a stack, last one to allocate must be first one to free.
82 int sh64_put_wired_dtlb_entry(unsigned long long entry
)
84 __flush_tlb_slot(entry
);
87 * We don't do any particularly useful tracking of wired entries,
88 * so this approach works like a stack .. last one to be allocated
89 * has to be the first one to be freed.
91 * We could potentially load wired entries into a list and work on
92 * rebalancing the list periodically (which also entails moving the
93 * contents of a TLB entry) .. though I have a feeling that this is
94 * more trouble than it's worth.
98 * Entry must be valid .. we don't want any ITLB addresses!
100 if (entry
<= DTLB_FIXED
)
104 * Next, check if we're within range to be freed. (ie, must be the
105 * entry beneath the first 'free' entry!
107 if (entry
< (cpu_data
->dtlb
.first
- cpu_data
->dtlb
.step
))
110 /* If we are, then bring this entry back into the list */
111 cpu_data
->dtlb
.first
-= cpu_data
->dtlb
.step
;
112 cpu_data
->dtlb
.next
= entry
;
118 * sh64_setup_tlb_slot
120 * @config_addr: Address of TLB slot.
121 * @eaddr: Virtual address.
122 * @asid: Address Space Identifier.
123 * @paddr: Physical address.
125 * Load up a virtual<->physical translation for @eaddr<->@paddr in the
126 * pre-allocated TLB slot @config_addr (see sh64_get_wired_dtlb_entry).
128 inline void sh64_setup_tlb_slot(unsigned long long config_addr
,
133 unsigned long long pteh
, ptel
;
137 pteh
= (unsigned long long)(signed long long)(signed long) eaddr
;
139 #error "Can't sign extend more than 32 bits yet"
142 pteh
|= (asid
<< PTEH_ASID_SHIFT
) | PTEH_VALID
;
144 ptel
= (unsigned long long)(signed long long)(signed long) paddr
;
146 #error "Can't sign extend more than 32 bits yet"
149 ptel
|= (_PAGE_CACHABLE
| _PAGE_READ
| _PAGE_WRITE
);
151 asm volatile("putcfg %0, 1, %1\n\t"
153 : : "r" (config_addr
), "r" (ptel
), "r" (pteh
));
157 * sh64_teardown_tlb_slot
159 * @config_addr: Address of TLB slot.
161 * Teardown any existing mapping in the TLB slot @config_addr.
163 inline void sh64_teardown_tlb_slot(unsigned long long config_addr
)
164 __attribute__ ((alias("__flush_tlb_slot")));