diff options
author | David Daney <ddaney@caviumnetworks.com> | 2009-01-08 19:46:40 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2009-01-11 04:57:21 -0500 |
commit | 5b3b16880f404ca54126210ca86141cceeafc0cf (patch) | |
tree | f69d30450a923782534d4ae257f20aace0a0be74 /arch/mips/mm | |
parent | 58f07778ce9d32c22cecb1d8ef348001f0e705c9 (diff) |
MIPS: Add Cavium OCTEON processor support files to arch/mips/cavium-octeon.
These are the rest of the new files needed to add OCTEON processor
support to the Linux kernel. Other than Makefile and Kconfig which
should be obvious, we have:
csrc-octeon.c -- Clock source driver for OCTEON.
dma-octeon.c -- Helper functions for mapping DMA memory.
flash_setup.c -- Register on-board flash with the MTD subsystem.
octeon-irq.c -- OCTEON interrupt controller managment.
octeon-memcpy.S -- Optimized memcpy() implementation.
serial.c -- Register 8250 platform driver and early console.
setup.c -- Early architecture initialization.
smp.c -- OCTEON SMP support.
octeon_switch.S -- Scheduler context switch for OCTEON.
c-octeon.c -- OCTEON cache controller support.
cex-oct.S -- OCTEON cache exception handler.
asm/mach-cavium-octeon/*.h -- Architecture include files.
Signed-off-by: Tomaso Paoletti <tpaoletti@caviumnetworks.com>
Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
create mode 100644 arch/mips/cavium-octeon/Kconfig
create mode 100644 arch/mips/cavium-octeon/Makefile
create mode 100644 arch/mips/cavium-octeon/csrc-octeon.c
create mode 100644 arch/mips/cavium-octeon/dma-octeon.c
create mode 100644 arch/mips/cavium-octeon/flash_setup.c
create mode 100644 arch/mips/cavium-octeon/octeon-irq.c
create mode 100644 arch/mips/cavium-octeon/octeon-memcpy.S
create mode 100644 arch/mips/cavium-octeon/serial.c
create mode 100644 arch/mips/cavium-octeon/setup.c
create mode 100644 arch/mips/cavium-octeon/smp.c
create mode 100644 arch/mips/include/asm/mach-cavium-octeon/cpu-feature-overrides.h
create mode 100644 arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
create mode 100644 arch/mips/include/asm/mach-cavium-octeon/irq.h
create mode 100644 arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h
create mode 100644 arch/mips/include/asm/mach-cavium-octeon/war.h
create mode 100644 arch/mips/include/asm/octeon/octeon.h
create mode 100644 arch/mips/kernel/octeon_switch.S
create mode 100644 arch/mips/mm/c-octeon.c
create mode 100644 arch/mips/mm/cex-oct.S
Diffstat (limited to 'arch/mips/mm')
-rw-r--r-- | arch/mips/mm/c-octeon.c | 307 | ||||
-rw-r--r-- | arch/mips/mm/cex-oct.S | 70 |
2 files changed, 377 insertions, 0 deletions
diff --git a/arch/mips/mm/c-octeon.c b/arch/mips/mm/c-octeon.c new file mode 100644 index 000000000000..44d01a0a8490 --- /dev/null +++ b/arch/mips/mm/c-octeon.c | |||
@@ -0,0 +1,307 @@ | |||
1 | /* | ||
2 | * This file is subject to the terms and conditions of the GNU General Public | ||
3 | * License. See the file "COPYING" in the main directory of this archive | ||
4 | * for more details. | ||
5 | * | ||
6 | * Copyright (C) 2005-2007 Cavium Networks | ||
7 | */ | ||
8 | #include <linux/init.h> | ||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/sched.h> | ||
11 | #include <linux/mm.h> | ||
12 | #include <linux/bitops.h> | ||
13 | #include <linux/cpu.h> | ||
14 | #include <linux/io.h> | ||
15 | |||
16 | #include <asm/bcache.h> | ||
17 | #include <asm/bootinfo.h> | ||
18 | #include <asm/cacheops.h> | ||
19 | #include <asm/cpu-features.h> | ||
20 | #include <asm/page.h> | ||
21 | #include <asm/pgtable.h> | ||
22 | #include <asm/r4kcache.h> | ||
23 | #include <asm/system.h> | ||
24 | #include <asm/mmu_context.h> | ||
25 | #include <asm/war.h> | ||
26 | |||
27 | #include <asm/octeon/octeon.h> | ||
28 | |||
29 | unsigned long long cache_err_dcache[NR_CPUS]; | ||
30 | |||
31 | /** | ||
32 | * Octeon automatically flushes the dcache on tlb changes, so | ||
33 | * from Linux's viewpoint it acts much like a physically | ||
34 | * tagged cache. No flushing is needed | ||
35 | * | ||
36 | */ | ||
37 | static void octeon_flush_data_cache_page(unsigned long addr) | ||
38 | { | ||
39 | /* Nothing to do */ | ||
40 | } | ||
41 | |||
42 | static inline void octeon_local_flush_icache(void) | ||
43 | { | ||
44 | asm volatile ("synci 0($0)"); | ||
45 | } | ||
46 | |||
47 | /* | ||
48 | * Flush local I-cache for the specified range. | ||
49 | */ | ||
50 | static void local_octeon_flush_icache_range(unsigned long start, | ||
51 | unsigned long end) | ||
52 | { | ||
53 | octeon_local_flush_icache(); | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * Flush caches as necessary for all cores affected by a | ||
58 | * vma. If no vma is supplied, all cores are flushed. | ||
59 | * | ||
60 | * @vma: VMA to flush or NULL to flush all icaches. | ||
61 | */ | ||
62 | static void octeon_flush_icache_all_cores(struct vm_area_struct *vma) | ||
63 | { | ||
64 | extern void octeon_send_ipi_single(int cpu, unsigned int action); | ||
65 | #ifdef CONFIG_SMP | ||
66 | int cpu; | ||
67 | cpumask_t mask; | ||
68 | #endif | ||
69 | |||
70 | mb(); | ||
71 | octeon_local_flush_icache(); | ||
72 | #ifdef CONFIG_SMP | ||
73 | preempt_disable(); | ||
74 | cpu = smp_processor_id(); | ||
75 | |||
76 | /* | ||
77 | * If we have a vma structure, we only need to worry about | ||
78 | * cores it has been used on | ||
79 | */ | ||
80 | if (vma) | ||
81 | mask = vma->vm_mm->cpu_vm_mask; | ||
82 | else | ||
83 | mask = cpu_online_map; | ||
84 | cpu_clear(cpu, mask); | ||
85 | for_each_cpu_mask(cpu, mask) | ||
86 | octeon_send_ipi_single(cpu, SMP_ICACHE_FLUSH); | ||
87 | |||
88 | preempt_enable(); | ||
89 | #endif | ||
90 | } | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Called to flush the icache on all cores | ||
95 | */ | ||
96 | static void octeon_flush_icache_all(void) | ||
97 | { | ||
98 | octeon_flush_icache_all_cores(NULL); | ||
99 | } | ||
100 | |||
101 | |||
102 | /** | ||
103 | * Called to flush all memory associated with a memory | ||
104 | * context. | ||
105 | * | ||
106 | * @mm: Memory context to flush | ||
107 | */ | ||
108 | static void octeon_flush_cache_mm(struct mm_struct *mm) | ||
109 | { | ||
110 | /* | ||
111 | * According to the R4K version of this file, CPUs without | ||
112 | * dcache aliases don't need to do anything here | ||
113 | */ | ||
114 | } | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Flush a range of kernel addresses out of the icache | ||
119 | * | ||
120 | */ | ||
121 | static void octeon_flush_icache_range(unsigned long start, unsigned long end) | ||
122 | { | ||
123 | octeon_flush_icache_all_cores(NULL); | ||
124 | } | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Flush the icache for a trampoline. These are used for interrupt | ||
129 | * and exception hooking. | ||
130 | * | ||
131 | * @addr: Address to flush | ||
132 | */ | ||
133 | static void octeon_flush_cache_sigtramp(unsigned long addr) | ||
134 | { | ||
135 | struct vm_area_struct *vma; | ||
136 | |||
137 | vma = find_vma(current->mm, addr); | ||
138 | octeon_flush_icache_all_cores(vma); | ||
139 | } | ||
140 | |||
141 | |||
142 | /** | ||
143 | * Flush a range out of a vma | ||
144 | * | ||
145 | * @vma: VMA to flush | ||
146 | * @start: | ||
147 | * @end: | ||
148 | */ | ||
149 | static void octeon_flush_cache_range(struct vm_area_struct *vma, | ||
150 | unsigned long start, unsigned long end) | ||
151 | { | ||
152 | if (vma->vm_flags & VM_EXEC) | ||
153 | octeon_flush_icache_all_cores(vma); | ||
154 | } | ||
155 | |||
156 | |||
157 | /** | ||
158 | * Flush a specific page of a vma | ||
159 | * | ||
160 | * @vma: VMA to flush page for | ||
161 | * @page: Page to flush | ||
162 | * @pfn: | ||
163 | */ | ||
164 | static void octeon_flush_cache_page(struct vm_area_struct *vma, | ||
165 | unsigned long page, unsigned long pfn) | ||
166 | { | ||
167 | if (vma->vm_flags & VM_EXEC) | ||
168 | octeon_flush_icache_all_cores(vma); | ||
169 | } | ||
170 | |||
171 | |||
172 | /** | ||
173 | * Probe Octeon's caches | ||
174 | * | ||
175 | */ | ||
176 | static void __devinit probe_octeon(void) | ||
177 | { | ||
178 | unsigned long icache_size; | ||
179 | unsigned long dcache_size; | ||
180 | unsigned int config1; | ||
181 | struct cpuinfo_mips *c = ¤t_cpu_data; | ||
182 | |||
183 | switch (c->cputype) { | ||
184 | case CPU_CAVIUM_OCTEON: | ||
185 | config1 = read_c0_config1(); | ||
186 | c->icache.linesz = 2 << ((config1 >> 19) & 7); | ||
187 | c->icache.sets = 64 << ((config1 >> 22) & 7); | ||
188 | c->icache.ways = 1 + ((config1 >> 16) & 7); | ||
189 | c->icache.flags |= MIPS_CACHE_VTAG; | ||
190 | icache_size = | ||
191 | c->icache.sets * c->icache.ways * c->icache.linesz; | ||
192 | c->icache.waybit = ffs(icache_size / c->icache.ways) - 1; | ||
193 | c->dcache.linesz = 128; | ||
194 | if (OCTEON_IS_MODEL(OCTEON_CN3XXX)) | ||
195 | c->dcache.sets = 1; /* CN3XXX has one Dcache set */ | ||
196 | else | ||
197 | c->dcache.sets = 2; /* CN5XXX has two Dcache sets */ | ||
198 | c->dcache.ways = 64; | ||
199 | dcache_size = | ||
200 | c->dcache.sets * c->dcache.ways * c->dcache.linesz; | ||
201 | c->dcache.waybit = ffs(dcache_size / c->dcache.ways) - 1; | ||
202 | c->options |= MIPS_CPU_PREFETCH; | ||
203 | break; | ||
204 | |||
205 | default: | ||
206 | panic("Unsupported Cavium Networks CPU type\n"); | ||
207 | break; | ||
208 | } | ||
209 | |||
210 | /* compute a couple of other cache variables */ | ||
211 | c->icache.waysize = icache_size / c->icache.ways; | ||
212 | c->dcache.waysize = dcache_size / c->dcache.ways; | ||
213 | |||
214 | c->icache.sets = icache_size / (c->icache.linesz * c->icache.ways); | ||
215 | c->dcache.sets = dcache_size / (c->dcache.linesz * c->dcache.ways); | ||
216 | |||
217 | if (smp_processor_id() == 0) { | ||
218 | pr_notice("Primary instruction cache %ldkB, %s, %d way, " | ||
219 | "%d sets, linesize %d bytes.\n", | ||
220 | icache_size >> 10, | ||
221 | cpu_has_vtag_icache ? | ||
222 | "virtually tagged" : "physically tagged", | ||
223 | c->icache.ways, c->icache.sets, c->icache.linesz); | ||
224 | |||
225 | pr_notice("Primary data cache %ldkB, %d-way, %d sets, " | ||
226 | "linesize %d bytes.\n", | ||
227 | dcache_size >> 10, c->dcache.ways, | ||
228 | c->dcache.sets, c->dcache.linesz); | ||
229 | } | ||
230 | } | ||
231 | |||
232 | |||
233 | /** | ||
234 | * Setup the Octeon cache flush routines | ||
235 | * | ||
236 | */ | ||
237 | void __devinit octeon_cache_init(void) | ||
238 | { | ||
239 | extern unsigned long ebase; | ||
240 | extern char except_vec2_octeon; | ||
241 | |||
242 | memcpy((void *)(ebase + 0x100), &except_vec2_octeon, 0x80); | ||
243 | octeon_flush_cache_sigtramp(ebase + 0x100); | ||
244 | |||
245 | probe_octeon(); | ||
246 | |||
247 | shm_align_mask = PAGE_SIZE - 1; | ||
248 | |||
249 | flush_cache_all = octeon_flush_icache_all; | ||
250 | __flush_cache_all = octeon_flush_icache_all; | ||
251 | flush_cache_mm = octeon_flush_cache_mm; | ||
252 | flush_cache_page = octeon_flush_cache_page; | ||
253 | flush_cache_range = octeon_flush_cache_range; | ||
254 | flush_cache_sigtramp = octeon_flush_cache_sigtramp; | ||
255 | flush_icache_all = octeon_flush_icache_all; | ||
256 | flush_data_cache_page = octeon_flush_data_cache_page; | ||
257 | flush_icache_range = octeon_flush_icache_range; | ||
258 | local_flush_icache_range = local_octeon_flush_icache_range; | ||
259 | |||
260 | build_clear_page(); | ||
261 | build_copy_page(); | ||
262 | } | ||
263 | |||
264 | /** | ||
265 | * Handle a cache error exception | ||
266 | */ | ||
267 | |||
268 | static void cache_parity_error_octeon(int non_recoverable) | ||
269 | { | ||
270 | unsigned long coreid = cvmx_get_core_num(); | ||
271 | uint64_t icache_err = read_octeon_c0_icacheerr(); | ||
272 | |||
273 | pr_err("Cache error exception:\n"); | ||
274 | pr_err("cp0_errorepc == %lx\n", read_c0_errorepc()); | ||
275 | if (icache_err & 1) { | ||
276 | pr_err("CacheErr (Icache) == %llx\n", | ||
277 | (unsigned long long)icache_err); | ||
278 | write_octeon_c0_icacheerr(0); | ||
279 | } | ||
280 | if (cache_err_dcache[coreid] & 1) { | ||
281 | pr_err("CacheErr (Dcache) == %llx\n", | ||
282 | (unsigned long long)cache_err_dcache[coreid]); | ||
283 | cache_err_dcache[coreid] = 0; | ||
284 | } | ||
285 | |||
286 | if (non_recoverable) | ||
287 | panic("Can't handle cache error: nested exception"); | ||
288 | } | ||
289 | |||
290 | /** | ||
291 | * Called when the the exception is not recoverable | ||
292 | */ | ||
293 | |||
294 | asmlinkage void cache_parity_error_octeon_recoverable(void) | ||
295 | { | ||
296 | cache_parity_error_octeon(0); | ||
297 | } | ||
298 | |||
299 | /** | ||
300 | * Called when the the exception is recoverable | ||
301 | */ | ||
302 | |||
303 | asmlinkage void cache_parity_error_octeon_non_recoverable(void) | ||
304 | { | ||
305 | cache_parity_error_octeon(1); | ||
306 | } | ||
307 | |||
diff --git a/arch/mips/mm/cex-oct.S b/arch/mips/mm/cex-oct.S new file mode 100644 index 000000000000..3db8553fcd34 --- /dev/null +++ b/arch/mips/mm/cex-oct.S | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * This file is subject to the terms and conditions of the GNU General Public | ||
3 | * License. See the file "COPYING" in the main directory of this archive | ||
4 | * for more details. | ||
5 | * | ||
6 | * Copyright (C) 2006 Cavium Networks | ||
7 | * Cache error handler | ||
8 | */ | ||
9 | |||
10 | #include <asm/asm.h> | ||
11 | #include <asm/regdef.h> | ||
12 | #include <asm/mipsregs.h> | ||
13 | #include <asm/stackframe.h> | ||
14 | |||
15 | /* | ||
16 | * Handle cache error. Indicate to the second level handler whether | ||
17 | * the exception is recoverable. | ||
18 | */ | ||
19 | LEAF(except_vec2_octeon) | ||
20 | |||
21 | .set push | ||
22 | .set mips64r2 | ||
23 | .set noreorder | ||
24 | .set noat | ||
25 | |||
26 | |||
27 | /* due to an errata we need to read the COP0 CacheErr (Dcache) | ||
28 | * before any cache/DRAM access */ | ||
29 | |||
30 | rdhwr k0, $0 /* get core_id */ | ||
31 | PTR_LA k1, cache_err_dcache | ||
32 | sll k0, k0, 3 | ||
33 | PTR_ADDU k1, k0, k1 /* k1 = &cache_err_dcache[core_id] */ | ||
34 | |||
35 | dmfc0 k0, CP0_CACHEERR, 1 | ||
36 | sd k0, (k1) | ||
37 | dmtc0 $0, CP0_CACHEERR, 1 | ||
38 | |||
39 | /* check whether this is a nested exception */ | ||
40 | mfc0 k1, CP0_STATUS | ||
41 | andi k1, k1, ST0_EXL | ||
42 | beqz k1, 1f | ||
43 | nop | ||
44 | j cache_parity_error_octeon_non_recoverable | ||
45 | nop | ||
46 | |||
47 | /* exception is recoverable */ | ||
48 | 1: j handle_cache_err | ||
49 | nop | ||
50 | |||
51 | .set pop | ||
52 | END(except_vec2_octeon) | ||
53 | |||
54 | /* We need to jump to handle_cache_err so that the previous handler | ||
55 | * can fit within 0x80 bytes. We also move from 0xFFFFFFFFAXXXXXXX | ||
56 | * space (uncached) to the 0xFFFFFFFF8XXXXXXX space (cached). */ | ||
57 | LEAF(handle_cache_err) | ||
58 | .set push | ||
59 | .set noreorder | ||
60 | .set noat | ||
61 | |||
62 | SAVE_ALL | ||
63 | KMODE | ||
64 | jal cache_parity_error_octeon_recoverable | ||
65 | nop | ||
66 | j ret_from_exception | ||
67 | nop | ||
68 | |||
69 | .set pop | ||
70 | END(handle_cache_err) | ||