diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/cris/arch-v10/mm |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/cris/arch-v10/mm')
-rw-r--r-- | arch/cris/arch-v10/mm/Makefile | 6 | ||||
-rw-r--r-- | arch/cris/arch-v10/mm/fault.c | 117 | ||||
-rw-r--r-- | arch/cris/arch-v10/mm/init.c | 264 | ||||
-rw-r--r-- | arch/cris/arch-v10/mm/tlb.c | 248 |
4 files changed, 635 insertions, 0 deletions
diff --git a/arch/cris/arch-v10/mm/Makefile b/arch/cris/arch-v10/mm/Makefile new file mode 100644 index 000000000000..588b4baee85e --- /dev/null +++ b/arch/cris/arch-v10/mm/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | # | ||
2 | # Makefile for the linux cris-specific parts of the memory manager. | ||
3 | # | ||
4 | |||
5 | obj-y := fault.o init.o tlb.o | ||
6 | |||
diff --git a/arch/cris/arch-v10/mm/fault.c b/arch/cris/arch-v10/mm/fault.c new file mode 100644 index 000000000000..6805cdb25a53 --- /dev/null +++ b/arch/cris/arch-v10/mm/fault.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * linux/arch/cris/mm/fault.c | ||
3 | * | ||
4 | * Low level bus fault handler | ||
5 | * | ||
6 | * | ||
7 | * Copyright (C) 2000, 2001 Axis Communications AB | ||
8 | * | ||
9 | * Authors: Bjorn Wesen | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/mm.h> | ||
14 | #include <asm/uaccess.h> | ||
15 | #include <asm/pgtable.h> | ||
16 | #include <asm/arch/svinto.h> | ||
17 | |||
18 | /* debug of low-level TLB reload */ | ||
19 | #undef DEBUG | ||
20 | |||
21 | #ifdef DEBUG | ||
22 | #define D(x) x | ||
23 | #else | ||
24 | #define D(x) | ||
25 | #endif | ||
26 | |||
27 | extern volatile pgd_t *current_pgd; | ||
28 | |||
29 | extern const struct exception_table_entry | ||
30 | *search_exception_tables(unsigned long addr); | ||
31 | |||
32 | asmlinkage void do_page_fault(unsigned long address, struct pt_regs *regs, | ||
33 | int protection, int writeaccess); | ||
34 | |||
35 | /* fast TLB-fill fault handler | ||
36 | * this is called from entry.S with interrupts disabled | ||
37 | */ | ||
38 | |||
39 | void | ||
40 | handle_mmu_bus_fault(struct pt_regs *regs) | ||
41 | { | ||
42 | int cause; | ||
43 | int select; | ||
44 | #ifdef DEBUG | ||
45 | int index; | ||
46 | int page_id; | ||
47 | int acc, inv; | ||
48 | #endif | ||
49 | pgd_t* pgd = (pgd_t*)current_pgd; | ||
50 | pmd_t *pmd; | ||
51 | pte_t pte; | ||
52 | int miss, we, writeac; | ||
53 | unsigned long address; | ||
54 | unsigned long flags; | ||
55 | |||
56 | cause = *R_MMU_CAUSE; | ||
57 | |||
58 | address = cause & PAGE_MASK; /* get faulting address */ | ||
59 | select = *R_TLB_SELECT; | ||
60 | |||
61 | #ifdef DEBUG | ||
62 | page_id = IO_EXTRACT(R_MMU_CAUSE, page_id, cause); | ||
63 | acc = IO_EXTRACT(R_MMU_CAUSE, acc_excp, cause); | ||
64 | inv = IO_EXTRACT(R_MMU_CAUSE, inv_excp, cause); | ||
65 | index = IO_EXTRACT(R_TLB_SELECT, index, select); | ||
66 | #endif | ||
67 | miss = IO_EXTRACT(R_MMU_CAUSE, miss_excp, cause); | ||
68 | we = IO_EXTRACT(R_MMU_CAUSE, we_excp, cause); | ||
69 | writeac = IO_EXTRACT(R_MMU_CAUSE, wr_rd, cause); | ||
70 | |||
71 | D(printk("bus_fault from IRP 0x%lx: addr 0x%lx, miss %d, inv %d, we %d, acc %d, dx %d pid %d\n", | ||
72 | regs->irp, address, miss, inv, we, acc, index, page_id)); | ||
73 | |||
74 | /* leave it to the MM system fault handler */ | ||
75 | if (miss) | ||
76 | do_page_fault(address, regs, 0, writeac); | ||
77 | else | ||
78 | do_page_fault(address, regs, 1, we); | ||
79 | |||
80 | /* Reload TLB with new entry to avoid an extra miss exception. | ||
81 | * do_page_fault may have flushed the TLB so we have to restore | ||
82 | * the MMU registers. | ||
83 | */ | ||
84 | local_save_flags(flags); | ||
85 | local_irq_disable(); | ||
86 | pmd = (pmd_t *)(pgd + pgd_index(address)); | ||
87 | if (pmd_none(*pmd)) | ||
88 | return; | ||
89 | pte = *pte_offset_kernel(pmd, address); | ||
90 | if (!pte_present(pte)) | ||
91 | return; | ||
92 | *R_TLB_SELECT = select; | ||
93 | *R_TLB_HI = cause; | ||
94 | *R_TLB_LO = pte_val(pte); | ||
95 | local_irq_restore(flags); | ||
96 | } | ||
97 | |||
98 | /* Called from arch/cris/mm/fault.c to find fixup code. */ | ||
99 | int | ||
100 | find_fixup_code(struct pt_regs *regs) | ||
101 | { | ||
102 | const struct exception_table_entry *fixup; | ||
103 | |||
104 | if ((fixup = search_exception_tables(regs->irp)) != 0) { | ||
105 | /* Adjust the instruction pointer in the stackframe. */ | ||
106 | regs->irp = fixup->fixup; | ||
107 | |||
108 | /* | ||
109 | * Don't return by restoring the CPU state, so switch | ||
110 | * frame-type. | ||
111 | */ | ||
112 | regs->frametype = CRIS_FRAME_NORMAL; | ||
113 | return 1; | ||
114 | } | ||
115 | |||
116 | return 0; | ||
117 | } | ||
diff --git a/arch/cris/arch-v10/mm/init.c b/arch/cris/arch-v10/mm/init.c new file mode 100644 index 000000000000..a9f975a9cfb5 --- /dev/null +++ b/arch/cris/arch-v10/mm/init.c | |||
@@ -0,0 +1,264 @@ | |||
1 | /* | ||
2 | * linux/arch/cris/arch-v10/mm/init.c | ||
3 | * | ||
4 | */ | ||
5 | #include <linux/config.h> | ||
6 | #include <linux/mmzone.h> | ||
7 | #include <linux/init.h> | ||
8 | #include <linux/bootmem.h> | ||
9 | #include <linux/mm.h> | ||
10 | #include <asm/pgtable.h> | ||
11 | #include <asm/page.h> | ||
12 | #include <asm/types.h> | ||
13 | #include <asm/mmu.h> | ||
14 | #include <asm/io.h> | ||
15 | #include <asm/mmu_context.h> | ||
16 | #include <asm/arch/svinto.h> | ||
17 | |||
18 | extern void tlb_init(void); | ||
19 | |||
20 | /* | ||
21 | * The kernel is already mapped with a kernel segment at kseg_c so | ||
22 | * we don't need to map it with a page table. However head.S also | ||
23 | * temporarily mapped it at kseg_4 so we should set up the ksegs again, | ||
24 | * clear the TLB and do some other paging setup stuff. | ||
25 | */ | ||
26 | |||
27 | void __init | ||
28 | paging_init(void) | ||
29 | { | ||
30 | int i; | ||
31 | unsigned long zones_size[MAX_NR_ZONES]; | ||
32 | |||
33 | printk("Setting up paging and the MMU.\n"); | ||
34 | |||
35 | /* clear out the init_mm.pgd that will contain the kernel's mappings */ | ||
36 | |||
37 | for(i = 0; i < PTRS_PER_PGD; i++) | ||
38 | swapper_pg_dir[i] = __pgd(0); | ||
39 | |||
40 | /* make sure the current pgd table points to something sane | ||
41 | * (even if it is most probably not used until the next | ||
42 | * switch_mm) | ||
43 | */ | ||
44 | |||
45 | current_pgd = init_mm.pgd; | ||
46 | |||
47 | /* initialise the TLB (tlb.c) */ | ||
48 | |||
49 | tlb_init(); | ||
50 | |||
51 | /* see README.mm for details on the KSEG setup */ | ||
52 | |||
53 | #ifdef CONFIG_CRIS_LOW_MAP | ||
54 | /* Etrax-100 LX version 1 has a bug so that we cannot map anything | ||
55 | * across the 0x80000000 boundary, so we need to shrink the user-virtual | ||
56 | * area to 0x50000000 instead of 0xb0000000 and map things slightly | ||
57 | * different. The unused areas are marked as paged so that we can catch | ||
58 | * freak kernel accesses there. | ||
59 | * | ||
60 | * The ARTPEC chip is mapped at 0xa so we pass that segment straight | ||
61 | * through. We cannot vremap it because the vmalloc area is below 0x8 | ||
62 | * and Juliette needs an uncached area above 0x8. | ||
63 | * | ||
64 | * Same thing with 0xc and 0x9, which is memory-mapped I/O on some boards. | ||
65 | * We map them straight over in LOW_MAP, but use vremap in LX version 2. | ||
66 | */ | ||
67 | |||
68 | #define CACHED_BOOTROM (KSEG_F | 0x08000000UL) | ||
69 | |||
70 | *R_MMU_KSEG = ( IO_STATE(R_MMU_KSEG, seg_f, seg ) | /* bootrom */ | ||
71 | IO_STATE(R_MMU_KSEG, seg_e, page ) | | ||
72 | IO_STATE(R_MMU_KSEG, seg_d, page ) | | ||
73 | IO_STATE(R_MMU_KSEG, seg_c, page ) | | ||
74 | IO_STATE(R_MMU_KSEG, seg_b, seg ) | /* kernel reg area */ | ||
75 | #ifdef CONFIG_JULIETTE | ||
76 | IO_STATE(R_MMU_KSEG, seg_a, seg ) | /* ARTPEC etc. */ | ||
77 | #else | ||
78 | IO_STATE(R_MMU_KSEG, seg_a, page ) | | ||
79 | #endif | ||
80 | IO_STATE(R_MMU_KSEG, seg_9, seg ) | /* LED's on some boards */ | ||
81 | IO_STATE(R_MMU_KSEG, seg_8, seg ) | /* CSE0/1, flash and I/O */ | ||
82 | IO_STATE(R_MMU_KSEG, seg_7, page ) | /* kernel vmalloc area */ | ||
83 | IO_STATE(R_MMU_KSEG, seg_6, seg ) | /* kernel DRAM area */ | ||
84 | IO_STATE(R_MMU_KSEG, seg_5, seg ) | /* cached flash */ | ||
85 | IO_STATE(R_MMU_KSEG, seg_4, page ) | /* user area */ | ||
86 | IO_STATE(R_MMU_KSEG, seg_3, page ) | /* user area */ | ||
87 | IO_STATE(R_MMU_KSEG, seg_2, page ) | /* user area */ | ||
88 | IO_STATE(R_MMU_KSEG, seg_1, page ) | /* user area */ | ||
89 | IO_STATE(R_MMU_KSEG, seg_0, page ) ); /* user area */ | ||
90 | |||
91 | *R_MMU_KBASE_HI = ( IO_FIELD(R_MMU_KBASE_HI, base_f, 0x3 ) | | ||
92 | IO_FIELD(R_MMU_KBASE_HI, base_e, 0x0 ) | | ||
93 | IO_FIELD(R_MMU_KBASE_HI, base_d, 0x0 ) | | ||
94 | IO_FIELD(R_MMU_KBASE_HI, base_c, 0x0 ) | | ||
95 | IO_FIELD(R_MMU_KBASE_HI, base_b, 0xb ) | | ||
96 | #ifdef CONFIG_JULIETTE | ||
97 | IO_FIELD(R_MMU_KBASE_HI, base_a, 0xa ) | | ||
98 | #else | ||
99 | IO_FIELD(R_MMU_KBASE_HI, base_a, 0x0 ) | | ||
100 | #endif | ||
101 | IO_FIELD(R_MMU_KBASE_HI, base_9, 0x9 ) | | ||
102 | IO_FIELD(R_MMU_KBASE_HI, base_8, 0x8 ) ); | ||
103 | |||
104 | *R_MMU_KBASE_LO = ( IO_FIELD(R_MMU_KBASE_LO, base_7, 0x0 ) | | ||
105 | IO_FIELD(R_MMU_KBASE_LO, base_6, 0x4 ) | | ||
106 | IO_FIELD(R_MMU_KBASE_LO, base_5, 0x0 ) | | ||
107 | IO_FIELD(R_MMU_KBASE_LO, base_4, 0x0 ) | | ||
108 | IO_FIELD(R_MMU_KBASE_LO, base_3, 0x0 ) | | ||
109 | IO_FIELD(R_MMU_KBASE_LO, base_2, 0x0 ) | | ||
110 | IO_FIELD(R_MMU_KBASE_LO, base_1, 0x0 ) | | ||
111 | IO_FIELD(R_MMU_KBASE_LO, base_0, 0x0 ) ); | ||
112 | #else | ||
113 | /* This code is for the corrected Etrax-100 LX version 2... */ | ||
114 | |||
115 | #define CACHED_BOOTROM (KSEG_A | 0x08000000UL) | ||
116 | |||
117 | *R_MMU_KSEG = ( IO_STATE(R_MMU_KSEG, seg_f, seg ) | /* cached flash */ | ||
118 | IO_STATE(R_MMU_KSEG, seg_e, seg ) | /* uncached flash */ | ||
119 | IO_STATE(R_MMU_KSEG, seg_d, page ) | /* vmalloc area */ | ||
120 | IO_STATE(R_MMU_KSEG, seg_c, seg ) | /* kernel area */ | ||
121 | IO_STATE(R_MMU_KSEG, seg_b, seg ) | /* kernel reg area */ | ||
122 | IO_STATE(R_MMU_KSEG, seg_a, seg ) | /* bootrom */ | ||
123 | IO_STATE(R_MMU_KSEG, seg_9, page ) | /* user area */ | ||
124 | IO_STATE(R_MMU_KSEG, seg_8, page ) | | ||
125 | IO_STATE(R_MMU_KSEG, seg_7, page ) | | ||
126 | IO_STATE(R_MMU_KSEG, seg_6, page ) | | ||
127 | IO_STATE(R_MMU_KSEG, seg_5, page ) | | ||
128 | IO_STATE(R_MMU_KSEG, seg_4, page ) | | ||
129 | IO_STATE(R_MMU_KSEG, seg_3, page ) | | ||
130 | IO_STATE(R_MMU_KSEG, seg_2, page ) | | ||
131 | IO_STATE(R_MMU_KSEG, seg_1, page ) | | ||
132 | IO_STATE(R_MMU_KSEG, seg_0, page ) ); | ||
133 | |||
134 | *R_MMU_KBASE_HI = ( IO_FIELD(R_MMU_KBASE_HI, base_f, 0x0 ) | | ||
135 | IO_FIELD(R_MMU_KBASE_HI, base_e, 0x8 ) | | ||
136 | IO_FIELD(R_MMU_KBASE_HI, base_d, 0x0 ) | | ||
137 | IO_FIELD(R_MMU_KBASE_HI, base_c, 0x4 ) | | ||
138 | IO_FIELD(R_MMU_KBASE_HI, base_b, 0xb ) | | ||
139 | IO_FIELD(R_MMU_KBASE_HI, base_a, 0x3 ) | | ||
140 | IO_FIELD(R_MMU_KBASE_HI, base_9, 0x0 ) | | ||
141 | IO_FIELD(R_MMU_KBASE_HI, base_8, 0x0 ) ); | ||
142 | |||
143 | *R_MMU_KBASE_LO = ( IO_FIELD(R_MMU_KBASE_LO, base_7, 0x0 ) | | ||
144 | IO_FIELD(R_MMU_KBASE_LO, base_6, 0x0 ) | | ||
145 | IO_FIELD(R_MMU_KBASE_LO, base_5, 0x0 ) | | ||
146 | IO_FIELD(R_MMU_KBASE_LO, base_4, 0x0 ) | | ||
147 | IO_FIELD(R_MMU_KBASE_LO, base_3, 0x0 ) | | ||
148 | IO_FIELD(R_MMU_KBASE_LO, base_2, 0x0 ) | | ||
149 | IO_FIELD(R_MMU_KBASE_LO, base_1, 0x0 ) | | ||
150 | IO_FIELD(R_MMU_KBASE_LO, base_0, 0x0 ) ); | ||
151 | #endif | ||
152 | |||
153 | *R_MMU_CONTEXT = ( IO_FIELD(R_MMU_CONTEXT, page_id, 0 ) ); | ||
154 | |||
155 | /* The MMU has been enabled ever since head.S but just to make | ||
156 | * it totally obvious we do it here as well. | ||
157 | */ | ||
158 | |||
159 | *R_MMU_CTRL = ( IO_STATE(R_MMU_CTRL, inv_excp, enable ) | | ||
160 | IO_STATE(R_MMU_CTRL, acc_excp, enable ) | | ||
161 | IO_STATE(R_MMU_CTRL, we_excp, enable ) ); | ||
162 | |||
163 | *R_MMU_ENABLE = IO_STATE(R_MMU_ENABLE, mmu_enable, enable); | ||
164 | |||
165 | /* | ||
166 | * initialize the bad page table and bad page to point | ||
167 | * to a couple of allocated pages | ||
168 | */ | ||
169 | |||
170 | empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE); | ||
171 | memset((void *)empty_zero_page, 0, PAGE_SIZE); | ||
172 | |||
173 | /* All pages are DMA'able in Etrax, so put all in the DMA'able zone */ | ||
174 | |||
175 | zones_size[0] = ((unsigned long)high_memory - PAGE_OFFSET) >> PAGE_SHIFT; | ||
176 | |||
177 | for (i = 1; i < MAX_NR_ZONES; i++) | ||
178 | zones_size[i] = 0; | ||
179 | |||
180 | /* Use free_area_init_node instead of free_area_init, because the former | ||
181 | * is designed for systems where the DRAM starts at an address substantially | ||
182 | * higher than 0, like us (we start at PAGE_OFFSET). This saves space in the | ||
183 | * mem_map page array. | ||
184 | */ | ||
185 | |||
186 | free_area_init_node(0, &contig_page_data, zones_size, PAGE_OFFSET >> PAGE_SHIFT, 0); | ||
187 | } | ||
188 | |||
189 | /* Initialize remaps of some I/O-ports. It is important that this | ||
190 | * is called before any driver is initialized. | ||
191 | */ | ||
192 | |||
193 | static int | ||
194 | __init init_ioremap(void) | ||
195 | { | ||
196 | |||
197 | /* Give the external I/O-port addresses their values */ | ||
198 | |||
199 | #ifdef CONFIG_CRIS_LOW_MAP | ||
200 | /* Simply a linear map (see the KSEG map above in paging_init) */ | ||
201 | port_cse1_addr = (volatile unsigned long *)(MEM_CSE1_START | | ||
202 | MEM_NON_CACHEABLE); | ||
203 | port_csp0_addr = (volatile unsigned long *)(MEM_CSP0_START | | ||
204 | MEM_NON_CACHEABLE); | ||
205 | port_csp4_addr = (volatile unsigned long *)(MEM_CSP4_START | | ||
206 | MEM_NON_CACHEABLE); | ||
207 | #else | ||
208 | /* Note that nothing blows up just because we do this remapping | ||
209 | * it's ok even if the ports are not used or connected | ||
210 | * to anything (or connected to a non-I/O thing) */ | ||
211 | port_cse1_addr = (volatile unsigned long *) | ||
212 | ioremap((unsigned long)(MEM_CSE1_START | MEM_NON_CACHEABLE), 16); | ||
213 | port_csp0_addr = (volatile unsigned long *) | ||
214 | ioremap((unsigned long)(MEM_CSP0_START | MEM_NON_CACHEABLE), 16); | ||
215 | port_csp4_addr = (volatile unsigned long *) | ||
216 | ioremap((unsigned long)(MEM_CSP4_START | MEM_NON_CACHEABLE), 16); | ||
217 | #endif | ||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | __initcall(init_ioremap); | ||
222 | |||
223 | /* Helper function for the two below */ | ||
224 | |||
225 | static inline void | ||
226 | flush_etrax_cacherange(void *startadr, int length) | ||
227 | { | ||
228 | /* CACHED_BOOTROM is mapped to the boot-rom area (cached) which | ||
229 | * we can use to get fast dummy-reads of cachelines | ||
230 | */ | ||
231 | |||
232 | volatile short *flushadr = (volatile short *)(((unsigned long)startadr & ~PAGE_MASK) | | ||
233 | CACHED_BOOTROM); | ||
234 | |||
235 | length = length > 8192 ? 8192 : length; /* No need to flush more than cache size */ | ||
236 | |||
237 | while(length > 0) { | ||
238 | *flushadr; /* dummy read to flush */ | ||
239 | flushadr += (32/sizeof(short)); /* a cacheline is 32 bytes */ | ||
240 | length -= 32; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | /* Due to a bug in Etrax100(LX) all versions, receiving DMA buffers | ||
245 | * will occationally corrupt certain CPU writes if the DMA buffers | ||
246 | * happen to be hot in the cache. | ||
247 | * | ||
248 | * As a workaround, we have to flush the relevant parts of the cache | ||
249 | * before (re) inserting any receiving descriptor into the DMA HW. | ||
250 | */ | ||
251 | |||
252 | void | ||
253 | prepare_rx_descriptor(struct etrax_dma_descr *desc) | ||
254 | { | ||
255 | flush_etrax_cacherange((void *)desc->buf, desc->sw_len ? desc->sw_len : 65536); | ||
256 | } | ||
257 | |||
258 | /* Do the same thing but flush the entire cache */ | ||
259 | |||
260 | void | ||
261 | flush_etrax_cache(void) | ||
262 | { | ||
263 | flush_etrax_cacherange(0, 8192); | ||
264 | } | ||
diff --git a/arch/cris/arch-v10/mm/tlb.c b/arch/cris/arch-v10/mm/tlb.c new file mode 100644 index 000000000000..9d06125ff5a2 --- /dev/null +++ b/arch/cris/arch-v10/mm/tlb.c | |||
@@ -0,0 +1,248 @@ | |||
1 | /* | ||
2 | * linux/arch/cris/arch-v10/mm/tlb.c | ||
3 | * | ||
4 | * Low level TLB handling | ||
5 | * | ||
6 | * | ||
7 | * Copyright (C) 2000-2002 Axis Communications AB | ||
8 | * | ||
9 | * Authors: Bjorn Wesen (bjornw@axis.com) | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <asm/tlb.h> | ||
14 | #include <asm/mmu_context.h> | ||
15 | #include <asm/arch/svinto.h> | ||
16 | |||
17 | #define D(x) | ||
18 | |||
19 | /* The TLB can host up to 64 different mm contexts at the same time. | ||
20 | * The running context is R_MMU_CONTEXT, and each TLB entry contains a | ||
21 | * page_id that has to match to give a hit. In page_id_map, we keep track | ||
22 | * of which mm's we have assigned which page_id's, so that we know when | ||
23 | * to invalidate TLB entries. | ||
24 | * | ||
25 | * The last page_id is never running - it is used as an invalid page_id | ||
26 | * so we can make TLB entries that will never match. | ||
27 | * | ||
28 | * Notice that we need to make the flushes atomic, otherwise an interrupt | ||
29 | * handler that uses vmalloced memory might cause a TLB load in the middle | ||
30 | * of a flush causing. | ||
31 | */ | ||
32 | |||
33 | /* invalidate all TLB entries */ | ||
34 | |||
35 | void | ||
36 | flush_tlb_all(void) | ||
37 | { | ||
38 | int i; | ||
39 | unsigned long flags; | ||
40 | |||
41 | /* the vpn of i & 0xf is so we dont write similar TLB entries | ||
42 | * in the same 4-way entry group. details.. | ||
43 | */ | ||
44 | |||
45 | local_save_flags(flags); | ||
46 | local_irq_disable(); | ||
47 | for(i = 0; i < NUM_TLB_ENTRIES; i++) { | ||
48 | *R_TLB_SELECT = ( IO_FIELD(R_TLB_SELECT, index, i) ); | ||
49 | *R_TLB_HI = ( IO_FIELD(R_TLB_HI, page_id, INVALID_PAGEID ) | | ||
50 | IO_FIELD(R_TLB_HI, vpn, i & 0xf ) ); | ||
51 | |||
52 | *R_TLB_LO = ( IO_STATE(R_TLB_LO, global,no ) | | ||
53 | IO_STATE(R_TLB_LO, valid, no ) | | ||
54 | IO_STATE(R_TLB_LO, kernel,no ) | | ||
55 | IO_STATE(R_TLB_LO, we, no ) | | ||
56 | IO_FIELD(R_TLB_LO, pfn, 0 ) ); | ||
57 | } | ||
58 | local_irq_restore(flags); | ||
59 | D(printk("tlb: flushed all\n")); | ||
60 | } | ||
61 | |||
62 | /* invalidate the selected mm context only */ | ||
63 | |||
64 | void | ||
65 | flush_tlb_mm(struct mm_struct *mm) | ||
66 | { | ||
67 | int i; | ||
68 | int page_id = mm->context.page_id; | ||
69 | unsigned long flags; | ||
70 | |||
71 | D(printk("tlb: flush mm context %d (%p)\n", page_id, mm)); | ||
72 | |||
73 | if(page_id == NO_CONTEXT) | ||
74 | return; | ||
75 | |||
76 | /* mark the TLB entries that match the page_id as invalid. | ||
77 | * here we could also check the _PAGE_GLOBAL bit and NOT flush | ||
78 | * global pages. is it worth the extra I/O ? | ||
79 | */ | ||
80 | |||
81 | local_save_flags(flags); | ||
82 | local_irq_disable(); | ||
83 | for(i = 0; i < NUM_TLB_ENTRIES; i++) { | ||
84 | *R_TLB_SELECT = IO_FIELD(R_TLB_SELECT, index, i); | ||
85 | if (IO_EXTRACT(R_TLB_HI, page_id, *R_TLB_HI) == page_id) { | ||
86 | *R_TLB_HI = ( IO_FIELD(R_TLB_HI, page_id, INVALID_PAGEID ) | | ||
87 | IO_FIELD(R_TLB_HI, vpn, i & 0xf ) ); | ||
88 | |||
89 | *R_TLB_LO = ( IO_STATE(R_TLB_LO, global,no ) | | ||
90 | IO_STATE(R_TLB_LO, valid, no ) | | ||
91 | IO_STATE(R_TLB_LO, kernel,no ) | | ||
92 | IO_STATE(R_TLB_LO, we, no ) | | ||
93 | IO_FIELD(R_TLB_LO, pfn, 0 ) ); | ||
94 | } | ||
95 | } | ||
96 | local_irq_restore(flags); | ||
97 | } | ||
98 | |||
99 | /* invalidate a single page */ | ||
100 | |||
101 | void | ||
102 | flush_tlb_page(struct vm_area_struct *vma, | ||
103 | unsigned long addr) | ||
104 | { | ||
105 | struct mm_struct *mm = vma->vm_mm; | ||
106 | int page_id = mm->context.page_id; | ||
107 | int i; | ||
108 | unsigned long flags; | ||
109 | |||
110 | D(printk("tlb: flush page %p in context %d (%p)\n", addr, page_id, mm)); | ||
111 | |||
112 | if(page_id == NO_CONTEXT) | ||
113 | return; | ||
114 | |||
115 | addr &= PAGE_MASK; /* perhaps not necessary */ | ||
116 | |||
117 | /* invalidate those TLB entries that match both the mm context | ||
118 | * and the virtual address requested | ||
119 | */ | ||
120 | |||
121 | local_save_flags(flags); | ||
122 | local_irq_disable(); | ||
123 | for(i = 0; i < NUM_TLB_ENTRIES; i++) { | ||
124 | unsigned long tlb_hi; | ||
125 | *R_TLB_SELECT = IO_FIELD(R_TLB_SELECT, index, i); | ||
126 | tlb_hi = *R_TLB_HI; | ||
127 | if (IO_EXTRACT(R_TLB_HI, page_id, tlb_hi) == page_id && | ||
128 | (tlb_hi & PAGE_MASK) == addr) { | ||
129 | *R_TLB_HI = IO_FIELD(R_TLB_HI, page_id, INVALID_PAGEID ) | | ||
130 | addr; /* same addr as before works. */ | ||
131 | |||
132 | *R_TLB_LO = ( IO_STATE(R_TLB_LO, global,no ) | | ||
133 | IO_STATE(R_TLB_LO, valid, no ) | | ||
134 | IO_STATE(R_TLB_LO, kernel,no ) | | ||
135 | IO_STATE(R_TLB_LO, we, no ) | | ||
136 | IO_FIELD(R_TLB_LO, pfn, 0 ) ); | ||
137 | } | ||
138 | } | ||
139 | local_irq_restore(flags); | ||
140 | } | ||
141 | |||
142 | /* invalidate a page range */ | ||
143 | |||
144 | void | ||
145 | flush_tlb_range(struct vm_area_struct *vma, | ||
146 | unsigned long start, | ||
147 | unsigned long end) | ||
148 | { | ||
149 | struct mm_struct *mm = vma->vm_mm; | ||
150 | int page_id = mm->context.page_id; | ||
151 | int i; | ||
152 | unsigned long flags; | ||
153 | |||
154 | D(printk("tlb: flush range %p<->%p in context %d (%p)\n", | ||
155 | start, end, page_id, mm)); | ||
156 | |||
157 | if(page_id == NO_CONTEXT) | ||
158 | return; | ||
159 | |||
160 | start &= PAGE_MASK; /* probably not necessary */ | ||
161 | end &= PAGE_MASK; /* dito */ | ||
162 | |||
163 | /* invalidate those TLB entries that match both the mm context | ||
164 | * and the virtual address range | ||
165 | */ | ||
166 | |||
167 | local_save_flags(flags); | ||
168 | local_irq_disable(); | ||
169 | for(i = 0; i < NUM_TLB_ENTRIES; i++) { | ||
170 | unsigned long tlb_hi, vpn; | ||
171 | *R_TLB_SELECT = IO_FIELD(R_TLB_SELECT, index, i); | ||
172 | tlb_hi = *R_TLB_HI; | ||
173 | vpn = tlb_hi & PAGE_MASK; | ||
174 | if (IO_EXTRACT(R_TLB_HI, page_id, tlb_hi) == page_id && | ||
175 | vpn >= start && vpn < end) { | ||
176 | *R_TLB_HI = ( IO_FIELD(R_TLB_HI, page_id, INVALID_PAGEID ) | | ||
177 | IO_FIELD(R_TLB_HI, vpn, i & 0xf ) ); | ||
178 | |||
179 | *R_TLB_LO = ( IO_STATE(R_TLB_LO, global,no ) | | ||
180 | IO_STATE(R_TLB_LO, valid, no ) | | ||
181 | IO_STATE(R_TLB_LO, kernel,no ) | | ||
182 | IO_STATE(R_TLB_LO, we, no ) | | ||
183 | IO_FIELD(R_TLB_LO, pfn, 0 ) ); | ||
184 | } | ||
185 | } | ||
186 | local_irq_restore(flags); | ||
187 | } | ||
188 | |||
189 | /* dump the entire TLB for debug purposes */ | ||
190 | |||
191 | #if 0 | ||
192 | void | ||
193 | dump_tlb_all(void) | ||
194 | { | ||
195 | int i; | ||
196 | unsigned long flags; | ||
197 | |||
198 | printk("TLB dump. LO is: pfn | reserved | global | valid | kernel | we |\n"); | ||
199 | |||
200 | local_save_flags(flags); | ||
201 | local_irq_disable(); | ||
202 | for(i = 0; i < NUM_TLB_ENTRIES; i++) { | ||
203 | *R_TLB_SELECT = ( IO_FIELD(R_TLB_SELECT, index, i) ); | ||
204 | printk("Entry %d: HI 0x%08lx, LO 0x%08lx\n", | ||
205 | i, *R_TLB_HI, *R_TLB_LO); | ||
206 | } | ||
207 | local_irq_restore(flags); | ||
208 | } | ||
209 | #endif | ||
210 | |||
211 | /* | ||
212 | * Initialize the context related info for a new mm_struct | ||
213 | * instance. | ||
214 | */ | ||
215 | |||
216 | int | ||
217 | init_new_context(struct task_struct *tsk, struct mm_struct *mm) | ||
218 | { | ||
219 | mm->context.page_id = NO_CONTEXT; | ||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | /* called in schedule() just before actually doing the switch_to */ | ||
224 | |||
225 | void | ||
226 | switch_mm(struct mm_struct *prev, struct mm_struct *next, | ||
227 | struct task_struct *tsk) | ||
228 | { | ||
229 | /* make sure we have a context */ | ||
230 | |||
231 | get_mmu_context(next); | ||
232 | |||
233 | /* remember the pgd for the fault handlers | ||
234 | * this is similar to the pgd register in some other CPU's. | ||
235 | * we need our own copy of it because current and active_mm | ||
236 | * might be invalid at points where we still need to derefer | ||
237 | * the pgd. | ||
238 | */ | ||
239 | |||
240 | current_pgd = next->pgd; | ||
241 | |||
242 | /* switch context in the MMU */ | ||
243 | |||
244 | D(printk("switching mmu_context to %d (%p)\n", next->context, next)); | ||
245 | |||
246 | *R_MMU_CONTEXT = IO_FIELD(R_MMU_CONTEXT, page_id, next->context.page_id); | ||
247 | } | ||
248 | |||