1 From 3592cd3db82e5b010df590079f1e310b5d317248 Mon Sep 17 00:00:00 2001
2 From: Kurt Mahan <kmahan@freescale.com>
3 Date: Mon, 3 Dec 2007 23:03:07 -0700
4 Subject: [PATCH] Rewrite Coldfire cache code.
6 LTIBName: mcfv4e-cache-base-update
7 Signed-off-by: Kurt Mahan <kmahan@freescale.com>
9 arch/m68k/coldfire/cache.c | 196 +-------------
10 arch/m68k/coldfire/head.S | 6 +-
11 arch/m68k/coldfire/signal.c | 4 +-
12 arch/m68k/kernel/sys_m68k.c | 16 ++
13 arch/m68k/mm/cache.c | 31 +---
14 arch/m68k/mm/memory.c | 76 +-----
15 include/asm-m68k/cf_cacheflush.h | 525 +++++++++++++++++++++++++++++---------
16 include/asm-m68k/cfcache.h | 95 ++++----
17 8 files changed, 495 insertions(+), 454 deletions(-)
19 --- a/arch/m68k/coldfire/cache.c
20 +++ b/arch/m68k/coldfire/cache.c
23 - * linux/arch/m68k/coldifre/cache.c
24 + * linux/arch/m68k/coldfire/cache.c
26 * Matt Waddel Matt.Waddel@freescale.com
27 + * Kurt Mahan kmahan@freescale.com
28 * Copyright Freescale Semiconductor, Inc. 2007
30 * This program is free software; you can redistribute it and/or modify
32 #include <asm/coldfire.h>
33 #include <asm/system.h>
35 -#define _DCACHE_SIZE (2*16384)
36 -#define _ICACHE_SIZE (2*16384)
41 - * Masks for cache sizes. Programming note: because the set size is a
42 - * power of two, the mask is also the last address in the set.
45 -#define _DCACHE_SET_MASK ((_DCACHE_SIZE/64-1)<<_SET_SHIFT)
46 -#define _ICACHE_SET_MASK ((_ICACHE_SIZE/64-1)<<_SET_SHIFT)
47 -#define LAST_DCACHE_ADDR _DCACHE_SET_MASK
48 -#define LAST_ICACHE_ADDR _ICACHE_SET_MASK
50 -/************************************************************
51 - * Routine to cleanly flush the cache, pushing all lines and
52 - * invalidating them.
54 - * The is the flash-resident version, used after copying the .text
55 - * segment from flash to ram.
56 - *************************************************************/
57 -void FLASHDcacheFlushInvalidate(void)
58 - __attribute__ ((section (".text_loader")));
60 -void FLASHDcacheFlushInvalidate()
63 - unsigned long start_set;
64 - unsigned long end_set;
67 - end_set = (unsigned long)LAST_DCACHE_ADDR;
69 - for (set = start_set; set < end_set; set += (0x10 - 3))
70 - asm volatile("cpushl %%dc,(%0)\n"
72 - "\tcpushl %%dc,(%0)\n"
74 - "\tcpushl %%dc,(%0)\n"
76 - "\tcpushl %%dc,(%0)" : : "a" (set));
79 -/************************************************************
80 - * Routine to cleanly flush the cache, pushing all lines and
81 - * invalidating them.
83 - *************************************************************/
84 -void DcacheFlushInvalidate()
87 - unsigned long start_set;
88 - unsigned long end_set;
91 - end_set = (unsigned long)LAST_DCACHE_ADDR;
93 - for (set = start_set; set < end_set; set += (0x10 - 3))
94 - asm volatile("cpushl %%dc,(%0)\n"
96 - "\tcpushl %%dc,(%0)\n"
98 - "\tcpushl %%dc,(%0)\n"
100 - "\tcpushl %%dc,(%0)" : : "a" (set));
105 -/******************************************************************************
106 - * Routine to cleanly flush the a block of cache, pushing all relevant lines
107 - * and invalidating them.
109 - ******************************************************************************/
110 -void DcacheFlushInvalidateCacheBlock(void *start, unsigned long size)
113 - unsigned long start_set;
114 - unsigned long end_set;
116 - /* if size is bigger than the cache can store
117 - * set the size to the maximum amount
120 - if (size > LAST_DCACHE_ADDR)
121 - size = LAST_DCACHE_ADDR;
123 - start_set = ((unsigned long)start) & _DCACHE_SET_MASK;
124 - end_set = ((unsigned long)(start+size-1)) & _DCACHE_SET_MASK;
126 - if (start_set > end_set) {
127 - /* from the begining to the lowest address */
128 - for (set = 0; set <= end_set; set += (0x10 - 3))
129 - asm volatile("cpushl %%dc,(%0)\n"
130 - "\taddq%.l #1,%0\n"
131 - "\tcpushl %%dc,(%0)\n"
132 - "\taddq%.l #1,%0\n"
133 - "\tcpushl %%dc,(%0)\n"
134 - "\taddq%.l #1,%0\n"
135 - "\tcpushl %%dc,(%0)" : : "a" (set));
137 - /* next loop will finish the cache ie pass the hole */
138 - end_set = LAST_DCACHE_ADDR;
140 - for (set = start_set; set <= end_set; set += (0x10 - 3))
141 - asm volatile("cpushl %%dc,(%0)\n"
142 - "\taddq%.l #1,%0\n"
143 - "\tcpushl %%dc,(%0)\n"
144 - "\taddq%.l #1,%0\n"
145 - "\tcpushl %%dc,(%0)\n"
146 - "\taddq%.l #1,%0\n"
147 - "\tcpushl %%dc,(%0)" : : "a" (set));
151 -void IcacheInvalidateCacheBlock(void *start, unsigned long size)
154 - unsigned long start_set;
155 - unsigned long end_set;
157 - /* if size is bigger than the cache can store
158 - * set the size to the maximum ammount
161 - if (size > LAST_ICACHE_ADDR)
162 - size = LAST_ICACHE_ADDR;
164 - start_set = ((unsigned long)start) & _ICACHE_SET_MASK;
165 - end_set = ((unsigned long)(start+size-1)) & _ICACHE_SET_MASK;
167 - if (start_set > end_set) {
168 - /* from the begining to the lowest address */
169 - for (set = 0; set <= end_set; set += (0x10 - 3))
170 - asm volatile("cpushl %%ic,(%0)\n"
171 - "\taddq%.l #1,%0\n"
172 - "\tcpushl %%ic,(%0)\n"
173 - "\taddq%.l #1,%0\n"
174 - "\tcpushl %%ic,(%0)\n"
175 - "\taddq%.l #1,%0\n"
176 - "\tcpushl %%ic,(%0)" : : "a" (set));
178 - /* next loop will finish the cache ie pass the hole */
179 - end_set = LAST_ICACHE_ADDR;
181 - for (set = start_set; set <= end_set; set += (0x10 - 3))
182 - asm volatile("cpushl %%ic,(%0)\n"
183 - "\taddq%.l #1,%0\n"
184 - "\tcpushl %%ic,(%0)\n"
185 - "\taddq%.l #1,%0\n"
186 - "\tcpushl %%ic,(%0)\n"
187 - "\taddq%.l #1,%0\n"
188 - "\tcpushl %%ic,(%0)" : : "a" (set));
192 -/********************************************************************
193 - * Disable the data cache completely
194 - ********************************************************************/
195 -void DcacheDisable(void)
198 - unsigned long flags;
200 - local_save_flags(flags);
201 - local_irq_disable();
203 - DcacheFlushInvalidate(); /* begin by flushing the cache */
204 - newValue = CACHE_DISABLE_MODE; /* disable it */
205 - cacr_set(newValue);
206 - local_irq_restore(flags);
209 -/********************************************************************
210 - * Unconditionally enable the data cache
211 - ********************************************************************/
212 -void DcacheEnable(void)
214 - cacr_set(CACHE_INITIAL_MODE);
218 +/* Cache Control Reg shadow reg */
219 unsigned long shadow_cacr;
222 + * cacr_set - Set the Cache Control Register
225 void cacr_set(unsigned long x)
228 @@ -209,6 +32,11 @@ void cacr_set(unsigned long x)
229 : "r" (shadow_cacr));
233 + * cacr_get - Get the current value of the Cache Control Register
235 + * @return CACR value
237 unsigned long cacr_get(void)
240 --- a/arch/m68k/coldfire/head.S
241 +++ b/arch/m68k/coldfire/head.S
242 @@ -244,7 +244,7 @@ ENTRY(__start)
243 /* Setup initial stack pointer */
244 movel #0x40001000,%sp
251 @@ -252,6 +252,10 @@ ENTRY(__start)
256 + movel #(CF_CACR_ICINVA + CF_CACR_DCINVA),%d0
259 movel #(MMU_BASE+1),%d0
261 movel #MMUOR_CA,%a0 /* Clear tlb entries */
262 --- a/arch/m68k/coldfire/signal.c
263 +++ b/arch/m68k/coldfire/signal.c
265 #include <asm/cf_pgtable.h>
266 #include <asm/traps.h>
267 #include <asm/ucontext.h>
268 +#include <asm/cacheflush.h>
270 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
272 @@ -605,10 +606,9 @@ static inline int rt_setup_ucontext(stru
276 -extern void IcacheInvalidateCacheBlock(void *, unsigned long);
277 static inline void push_cache(unsigned long vaddr)
279 - IcacheInvalidateCacheBlock((void *)vaddr, 8);
280 + cf_cache_push(__pa(vaddr), 8);
283 static inline void __user *
284 --- a/arch/m68k/kernel/sys_m68k.c
285 +++ b/arch/m68k/kernel/sys_m68k.c
287 #include <asm/traps.h>
288 #include <asm/page.h>
289 #include <asm/unistd.h>
290 +#ifdef CONFIG_COLDFIRE
291 +#include <asm/cacheflush.h>
295 * sys_pipe() is the normal C calling standard for creating
296 @@ -257,6 +260,7 @@ asmlinkage int sys_ipc (uint call, int f
300 +#ifndef CONFIG_COLDFIRE
301 /* Convert virtual (user) address VADDR to physical address PADDR */
302 #define virt_to_phys_040(vaddr) \
304 @@ -580,6 +584,7 @@ cache_flush_060 (unsigned long addr, int
308 +#endif /* CONFIG_COLDFIRE */
310 /* sys_cacheflush -- flush (part of) the processor cache. */
312 @@ -612,6 +617,7 @@ sys_cacheflush (unsigned long addr, int
316 +#ifndef CONFIG_COLDFIRE
317 if (CPU_IS_020_OR_030) {
318 if (scope == FLUSH_SCOPE_LINE && len < 256) {
320 @@ -656,6 +662,16 @@ sys_cacheflush (unsigned long addr, int
321 ret = cache_flush_060 (addr, scope, cache, len);
324 +#else /* CONFIG_COLDFIRE */
325 + if ((cache & FLUSH_CACHE_INSN) && (cache & FLUSH_CACHE_DATA))
327 + else if (cache & FLUSH_CACHE_INSN)
333 +#endif /* CONFIG_COLDFIRE */
337 --- a/arch/m68k/mm/cache.c
338 +++ b/arch/m68k/mm/cache.c
339 @@ -81,36 +81,7 @@ static unsigned long virt_to_phys_slow(u
340 void flush_icache_range(unsigned long address, unsigned long endaddr)
342 #ifdef CONFIG_COLDFIRE
344 - unsigned long start_set;
345 - unsigned long end_set;
347 - start_set = address & _ICACHE_SET_MASK;
348 - end_set = endaddr & _ICACHE_SET_MASK;
350 - if (start_set > end_set) {
351 - /* from the begining to the lowest address */
352 - for (set = 0; set <= end_set; set += (0x10 - 3))
353 - asm volatile ("cpushl %%ic,(%0)\n"
354 - "\taddq%.l #1,%0\n"
355 - "\tcpushl %%ic,(%0)\n"
356 - "\taddq%.l #1,%0\n"
357 - "\tcpushl %%ic,(%0)\n"
358 - "\taddq%.l #1,%0\n"
359 - "\tcpushl %%ic,(%0)" : : "a" (set));
361 - /* next loop will finish the cache ie pass the hole */
362 - end_set = LAST_ICACHE_ADDR;
364 - for (set = start_set; set <= end_set; set += (0x10 - 3))
365 - asm volatile ("cpushl %%ic,(%0)\n"
366 - "\taddq%.l #1,%0\n"
367 - "\tcpushl %%ic,(%0)\n"
368 - "\taddq%.l #1,%0\n"
369 - "\tcpushl %%ic,(%0)\n"
370 - "\taddq%.l #1,%0\n"
371 - "\tcpushl %%ic,(%0)" : : "a" (set));
373 + cf_icache_flush_range(address, endaddr);
374 #else /* !CONFIG_COLDFIRE */
376 if (CPU_IS_040_OR_060) {
377 --- a/arch/m68k/mm/memory.c
378 +++ b/arch/m68k/mm/memory.c
379 @@ -127,6 +127,7 @@ int free_pointer_table (pmd_t *ptable)
383 +#ifndef CONFIG_COLDFIRE
384 /* invalidate page in both caches */
385 static inline void clear040(unsigned long paddr)
387 @@ -173,6 +174,7 @@ static inline void pushcl040(unsigned lo
389 local_irq_restore(flags);
391 +#endif /* CONFIG_COLDFIRE */
394 * 040: Hit every page containing an address in the range paddr..paddr+len-1.
395 @@ -203,38 +205,10 @@ static inline void pushcl040(unsigned lo
397 void cache_clear (unsigned long paddr, int len)
399 - if (CPU_IS_CFV4E) {
401 - unsigned long start_set;
402 - unsigned long end_set;
404 - start_set = paddr & _ICACHE_SET_MASK;
405 - end_set = (paddr+len-1) & _ICACHE_SET_MASK;
407 - if (start_set > end_set) {
408 - /* from the begining to the lowest address */
409 - for (set = 0; set <= end_set; set += (0x10 - 3))
410 - asm volatile("cpushl %%bc,(%0)\n"
411 - "\taddq%.l #1,%0\n"
412 - "\tcpushl %%bc,(%0)\n"
413 - "\taddq%.l #1,%0\n"
414 - "\tcpushl %%bc,(%0)\n"
415 - "\taddq%.l #1,%0\n"
416 - "\tcpushl %%bc,(%0)" : : "a" (set));
418 - /* next loop will finish the cache ie pass the hole */
419 - end_set = LAST_ICACHE_ADDR;
421 - for (set = start_set; set <= end_set; set += (0x10 - 3))
422 - asm volatile("cpushl %%bc,(%0)\n"
423 - "\taddq%.l #1,%0\n"
424 - "\tcpushl %%bc,(%0)\n"
425 - "\taddq%.l #1,%0\n"
426 - "\tcpushl %%bc,(%0)\n"
427 - "\taddq%.l #1,%0\n"
428 - "\tcpushl %%bc,(%0)" : : "a" (set));
430 - } else if (CPU_IS_040_OR_060) {
431 +#ifdef CONFIG_COLDFIRE
432 + cf_cache_clear(paddr, len);
434 + if (CPU_IS_040_OR_060) {
438 @@ -268,6 +242,7 @@ void cache_clear (unsigned long paddr, i
442 +#endif /* CONFIG_COLDFIRE */
444 EXPORT_SYMBOL(cache_clear);
446 @@ -281,38 +256,10 @@ EXPORT_SYMBOL(cache_clear);
448 void cache_push (unsigned long paddr, int len)
450 - if (CPU_IS_CFV4E) {
452 - unsigned long start_set;
453 - unsigned long end_set;
455 - start_set = paddr & _ICACHE_SET_MASK;
456 - end_set = (paddr+len-1) & _ICACHE_SET_MASK;
458 - if (start_set > end_set) {
459 - /* from the begining to the lowest address */
460 - for (set = 0; set <= end_set; set += (0x10 - 3))
461 - asm volatile("cpushl %%bc,(%0)\n"
462 - "\taddq%.l #1,%0\n"
463 - "\tcpushl %%bc,(%0)\n"
464 - "\taddq%.l #1,%0\n"
465 - "\tcpushl %%bc,(%0)\n"
466 - "\taddq%.l #1,%0\n"
467 - "\tcpushl %%bc,(%0)" : : "a" (set));
469 - /* next loop will finish the cache ie pass the hole */
470 - end_set = LAST_ICACHE_ADDR;
472 - for (set = start_set; set <= end_set; set += (0x10 - 3))
473 - asm volatile("cpushl %%bc,(%0)\n"
474 - "\taddq%.l #1,%0\n"
475 - "\tcpushl %%bc,(%0)\n"
476 - "\taddq%.l #1,%0\n"
477 - "\tcpushl %%bc,(%0)\n"
478 - "\taddq%.l #1,%0\n"
479 - "\tcpushl %%bc,(%0)" : : "a" (set));
481 - } else if (CPU_IS_040_OR_060) {
482 +#ifdef CONFIG_COLDFIRE
483 + cf_cache_push(paddr, len);
485 + if (CPU_IS_040_OR_060) {
489 @@ -352,6 +299,7 @@ void cache_push (unsigned long paddr, in
493 +#endif /* CONFIG_COLDFIRE */
495 EXPORT_SYMBOL(cache_push);
497 --- a/include/asm-m68k/cf_cacheflush.h
498 +++ b/include/asm-m68k/cf_cacheflush.h
501 + * include/asm-m68k/cf_cacheflush.h - Coldfire Cache
503 + * Based on include/asm-m68k/cacheflush.h
505 + * Coldfire pieces by:
506 + * Kurt Mahan kmahan@freescale.com
508 + * Copyright Freescale Semiconductor, Inc. 2007
510 + * This program is free software; you can redistribute it and/or modify it
511 + * under the terms of the GNU General Public License as published by the
512 + * Free Software Foundation; either version 2 of the License, or (at your
513 + * option) any later version.
515 #ifndef M68K_CF_CACHEFLUSH_H
516 #define M68K_CF_CACHEFLUSH_H
518 #include <asm/cfcache.h>
521 - * Cache handling functions
522 + * Coldfire Cache Model
524 + * The Coldfire processors use a Harvard architecture cache configured
525 + * as four-way set associative. The cache does not implement bus snooping
526 + * so cache coherency with other masters must be maintained in software.
528 + * The cache is managed via the CPUSHL instruction in conjunction with
529 + * bits set in the CACR (cache control register). Currently the code
530 + * uses the CPUSHL enhancement which adds the ability to
531 + * invalidate/clear/push a cacheline by physical address. This feature
532 + * is designated in the Hardware Configuration Register [D1-CPES].
535 + * DPI[28] cpushl invalidate disable for d-cache
536 + * IDPI[12] cpushl invalidate disable for i-cache
537 + * SPA[14] cpushl search by physical address
538 + * IVO[20] cpushl invalidate only
540 + * Random Terminology:
541 + * * invalidate = reset the cache line's valid bit
542 + * * push = generate a line-sized store of the data if its contents are marked
543 + * as modifed (the modified flag is cleared after the store)
544 + * * clear = push + invalidate
547 -#define flush_icache() \
549 - unsigned long set; \
550 - unsigned long start_set; \
551 - unsigned long end_set; \
554 - end_set = (unsigned long)LAST_DCACHE_ADDR; \
556 - for (set = start_set; set <= end_set; set += (0x10 - 3)) \
557 - asm volatile("cpushl %%ic,(%0)\n" \
558 - "\taddq%.l #1,%0\n" \
559 - "\tcpushl %%ic,(%0)\n" \
560 - "\taddq%.l #1,%0\n" \
561 - "\tcpushl %%ic,(%0)\n" \
562 - "\taddq%.l #1,%0\n" \
563 - "\tcpushl %%ic,(%0)" : : "a" (set)); \
566 + * flush_icache - Flush all of the instruction cache
568 +static inline void flush_icache(void)
570 + asm volatile("nop\n"
571 + "moveq%.l #0,%%d0\n"
572 + "moveq%.l #0,%%d1\n"
573 + "move%.l %%d0,%%a0\n"
575 + "cpushl %%ic,(%%a0)\n"
576 + "add%.l #0x0010,%%a0\n"
577 + "addq%.l #1,%%d1\n"
578 + "cmpi%.l %0,%%d1\n"
580 + "moveq%.l #0,%%d1\n"
581 + "addq%.l #1,%%d0\n"
582 + "move%.l %%d0,%%a0\n"
583 + "cmpi%.l #4,%%d0\n"
585 + : : "i" (CACHE_SETS)
586 + : "a0", "d0", "d1");
590 - * invalidate the cache for the specified memory range.
591 - * It starts at the physical address specified for
592 - * the given number of bytes.
594 + * flush_dcache - Flush all of the data cache
596 -extern void cache_clear(unsigned long paddr, int len);
598 - * push any dirty cache in the specified memory range.
599 - * It starts at the physical address specified for
600 - * the given number of bytes.
601 +static inline void flush_dcache(void)
603 + asm volatile("nop\n"
604 + "moveq%.l #0,%%d0\n"
605 + "moveq%.l #0,%%d1\n"
606 + "move%.l %%d0,%%a0\n"
608 + "cpushl %%dc,(%%a0)\n"
609 + "add%.l #0x0010,%%a0\n"
610 + "addq%.l #1,%%d1\n"
611 + "cmpi%.l %0,%%d1\n"
613 + "moveq%.l #0,%%d1\n"
614 + "addq%.l #1,%%d0\n"
615 + "move%.l %%d0,%%a0\n"
616 + "cmpi%.l #4,%%d0\n"
618 + : : "i" (CACHE_SETS)
619 + : "a0", "d0", "d1");
623 + * flush_bcache - Flush all of both caches
625 -extern void cache_push(unsigned long paddr, int len);
626 +static inline void flush_bcache(void)
628 + asm volatile("nop\n"
629 + "moveq%.l #0,%%d0\n"
630 + "moveq%.l #0,%%d1\n"
631 + "move%.l %%d0,%%a0\n"
633 + "cpushl %%bc,(%%a0)\n"
634 + "add%.l #0x0010,%%a0\n"
635 + "addq%.l #1,%%d1\n"
636 + "cmpi%.l %0,%%d1\n"
638 + "moveq%.l #0,%%d1\n"
639 + "addq%.l #1,%%d0\n"
640 + "move%.l %%d0,%%a0\n"
641 + "cmpi%.l #4,%%d0\n"
643 + : : "i" (CACHE_SETS)
644 + : "a0", "d0", "d1");
648 - * push and invalidate pages in the specified user virtual
651 + * cf_cache_clear - invalidate cache
652 + * @paddr: starting physical address
653 + * @len: number of bytes
655 + * Invalidate cache lines starting at paddr for len bytes.
656 + * Those lines are not pushed.
658 +static inline void cf_cache_clear(unsigned long paddr, int len)
660 + /* number of lines */
661 + len = (len + (CACHE_LINE_SIZE-1)) / CACHE_LINE_SIZE;
663 + /* align on set boundary */
664 + paddr &= 0xfffffff0;
666 + asm volatile("nop\n"
667 + "move%.l %2,%%d0\n"
669 + "movec %%d0,%%cacr\n"
670 + "move%.l %0,%%a0\n"
671 + "move%.l %1,%%d0\n"
673 + "cpushl %%bc,(%%a0)\n"
674 + "lea 0x10(%%a0),%%a0\n"
675 + "subq%.l #1,%%d0\n"
677 + "movec %2,%%cacr\n"
678 + : : "a" (paddr), "r" (len),
680 + "i" (CF_CACR_SPA+CF_CACR_IVO)
685 + * cf_cache_push - Push dirty cache out with no invalidate
686 + * @paddr: starting physical address
687 + * @len: number of bytes
689 + * Push the any dirty lines starting at paddr for len bytes.
690 + * Those lines are not invalidated.
692 +static inline void cf_cache_push(unsigned long paddr, int len)
694 + /* number of lines */
695 + len = (len + (CACHE_LINE_SIZE-1)) / CACHE_LINE_SIZE;
697 + /* align on set boundary */
698 + paddr &= 0xfffffff0;
700 + asm volatile("nop\n"
701 + "move%.l %2,%%d0\n"
703 + "movec %%d0,%%cacr\n"
704 + "move%.l %0,%%a0\n"
705 + "move%.l %1,%%d0\n"
707 + "cpushl %%bc,(%%a0)\n"
708 + "lea 0x10(%%a0),%%a0\n"
709 + "subq%.l #1,%%d0\n"
711 + "movec %2,%%cacr\n"
712 + : : "a" (paddr), "r" (len),
714 + "i" (CF_CACR_SPA+CF_CACR_DPI+CF_CACR_IDPI)
719 + * cf_cache_flush - Push dirty cache out and invalidate
720 + * @paddr: starting physical address
721 + * @len: number of bytes
723 + * Push the any dirty lines starting at paddr for len bytes and
724 + * invalidate those lines.
726 +static inline void cf_cache_flush(unsigned long paddr, int len)
728 + /* number of lines */
729 + len = (len + (CACHE_LINE_SIZE-1)) / CACHE_LINE_SIZE;
731 + /* align on set boundary */
732 + paddr &= 0xfffffff0;
734 + asm volatile("nop\n"
735 + "move%.l %2,%%d0\n"
737 + "movec %%d0,%%cacr\n"
738 + "move%.l %0,%%a0\n"
739 + "move%.l %1,%%d0\n"
741 + "cpushl %%bc,(%%a0)\n"
742 + "lea 0x10(%%a0),%%a0\n"
743 + "subq%.l #1,%%d0\n"
745 + "movec %2,%%cacr\n"
746 + : : "a" (paddr), "r" (len),
753 + * cf_cache_flush_range - Push dirty data/inst cache in range out and invalidate
754 + * @vstart - starting virtual address
755 + * @vend: ending virtual address
757 + * Push the any dirty data/instr lines starting at paddr for len bytes and
758 + * invalidate those lines.
760 +static inline void cf_cache_flush_range(unsigned long vstart, unsigned long vend)
764 + /* align on set boundary */
765 + vstart &= 0xfffffff0;
766 + vend = PAGE_ALIGN((vend + (CACHE_LINE_SIZE-1))) & 0xfffffff0;
767 + len = vend - vstart;
768 + vstart = __pa(vstart);
769 + vend = vstart + len;
771 + asm volatile("nop\n"
772 + "move%.l %2,%%d0\n"
774 + "movec %%d0,%%cacr\n"
775 + "move%.l %0,%%a0\n"
776 + "move%.l %1,%%a1\n"
778 + "cpushl %%bc,(%%a0)\n"
779 + "lea 0x10(%%a0),%%a0\n"
780 + "cmpa%.l %%a0,%%a1\n"
782 + "movec %2,%%cacr\n"
784 + : "a" (vstart), "a" (vend),
787 + : "a0", "a1", "d0");
791 + * cf_dcache_flush_range - Push dirty data cache in range out and invalidate
792 + * @vstart - starting virtual address
793 + * @vend: ending virtual address
795 + * Push the any dirty data lines starting at paddr for len bytes and
796 + * invalidate those lines.
798 +static inline void cf_dcache_flush_range(unsigned long vstart, unsigned long vend)
800 + /* align on set boundary */
801 + vstart &= 0xfffffff0;
802 + vend = (vend + (CACHE_LINE_SIZE-1)) & 0xfffffff0;
804 + asm volatile("nop\n"
805 + "move%.l %2,%%d0\n"
807 + "movec %%d0,%%cacr\n"
808 + "move%.l %0,%%a0\n"
809 + "move%.l %1,%%a1\n"
811 + "cpushl %%dc,(%%a0)\n"
812 + "lea 0x10(%%a0),%%a0\n"
813 + "cmpa%.l %%a0,%%a1\n"
815 + "movec %2,%%cacr\n"
817 + : "a" (__pa(vstart)), "a" (__pa(vend)),
820 + : "a0", "a1", "d0");
824 + * cf_icache_flush_range - Push dirty inst cache in range out and invalidate
825 + * @vstart - starting virtual address
826 + * @vend: ending virtual address
828 + * Push the any dirty instr lines starting at paddr for len bytes and
829 + * invalidate those lines. This should just be an invalidate since you
830 + * shouldn't be able to have dirty instruction cache.
832 -extern void cache_push_v(unsigned long vaddr, int len);
833 +static inline void cf_icache_flush_range(unsigned long vstart, unsigned long vend)
835 + /* align on set boundary */
836 + vstart &= 0xfffffff0;
837 + vend = (vend + (CACHE_LINE_SIZE-1)) & 0xfffffff0;
839 + asm volatile("nop\n"
840 + "move%.l %2,%%d0\n"
842 + "movec %%d0,%%cacr\n"
843 + "move%.l %0,%%a0\n"
844 + "move%.l %1,%%a1\n"
846 + "cpushl %%ic,(%%a0)\n"
847 + "lea 0x10(%%a0),%%a0\n"
848 + "cmpa%.l %%a0,%%a1\n"
850 + "movec %2,%%cacr\n"
852 + : "a" (__pa(vstart)), "a" (__pa(vend)),
855 + : "a0", "a1", "d0");
858 -/* This is needed whenever the virtual mapping of the current
859 - process changes. */
861 + * flush_cache_mm - Flush an mm_struct
862 + * @mm: mm_struct to flush
864 +static inline void flush_cache_mm(struct mm_struct *mm)
866 + if (mm == current->mm)
870 +#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
872 -#define flush_cache_all() do { } while (0)
873 -#define flush_cache_mm(mm) do { } while (0)
874 -#define flush_cache_range(mm, a, b) do { } while (0)
875 -#define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
877 -#define flush_dcache_range(paddr, len) do { } while (0)
879 -/* Push the page at kernel virtual address and clear the icache */
880 -/* use cpush %bc instead of cpush %dc, cinv %ic */
881 -#define flush_page_to_ram(page) __flush_page_to_ram((void *) page_address(page))
882 -extern inline void __flush_page_to_ram(void *address)
885 - unsigned long start_set;
886 - unsigned long end_set;
887 - unsigned long addr = (unsigned long) address;
889 - addr &= ~(PAGE_SIZE - 1); /* round down to page start address */
891 - start_set = addr & _ICACHE_SET_MASK;
892 - end_set = (addr + PAGE_SIZE-1) & _ICACHE_SET_MASK;
894 - if (start_set > end_set) {
895 - /* from the begining to the lowest address */
896 - for (set = 0; set <= end_set; set += (0x10 - 3))
897 - asm volatile("cpushl %%bc,(%0)\n"
898 - "\taddq%.l #1,%0\n"
899 - "\tcpushl %%bc,(%0)\n"
900 - "\taddq%.l #1,%0\n"
901 - "\tcpushl %%bc,(%0)\n"
902 - "\taddq%.l #1,%0\n"
903 - "\tcpushl %%bc,(%0)" : : "a" (set));
905 - /* next loop will finish the cache ie pass the hole */
906 - end_set = LAST_ICACHE_ADDR;
908 - for (set = start_set; set <= end_set; set += (0x10 - 3))
909 - asm volatile("cpushl %%bc,(%0)\n"
910 - "\taddq%.l #1,%0\n"
911 - "\tcpushl %%bc,(%0)\n"
912 - "\taddq%.l #1,%0\n"
913 - "\tcpushl %%bc,(%0)\n"
914 - "\taddq%.l #1,%0\n"
915 - "\tcpushl %%bc,(%0)" : : "a" (set));
918 -#define flush_dcache_page(page) do { } while (0)
919 -#define flush_icache_page(vma, pg) do { } while (0)
920 -#define flush_icache_user_range(adr, len) do { } while (0)
922 -#define flush_icache_user_page(vma, page, addr, len) do { } while (0)
924 -/* Push n pages at kernel virtual address and clear the icache */
925 -/* use cpush %bc instead of cpush %dc, cinv %ic */
926 -extern inline void flush_icache_range(unsigned long address,
927 - unsigned long endaddr)
930 - unsigned long start_set;
931 - unsigned long end_set;
933 - start_set = address & _ICACHE_SET_MASK;
934 - end_set = endaddr & _ICACHE_SET_MASK;
936 - if (start_set > end_set) {
937 - /* from the begining to the lowest address */
938 - for (set = 0; set <= end_set; set += (0x10 - 3))
939 - asm volatile("cpushl %%ic,(%0)\n"
940 - "\taddq%.l #1,%0\n"
941 - "\tcpushl %%ic,(%0)\n"
942 - "\taddq%.l #1,%0\n"
943 - "\tcpushl %%ic,(%0)\n"
944 - "\taddq%.l #1,%0\n"
945 - "\tcpushl %%ic,(%0)" : : "a" (set));
947 - /* next loop will finish the cache ie pass the hole */
948 - end_set = LAST_ICACHE_ADDR;
950 - for (set = start_set; set <= end_set; set += (0x10 - 3))
951 - asm volatile("cpushl %%ic,(%0)\n"
952 - "\taddq%.l #1,%0\n"
953 - "\tcpushl %%ic,(%0)\n"
954 - "\taddq%.l #1,%0\n"
955 - "\tcpushl %%ic,(%0)\n"
956 - "\taddq%.l #1,%0\n"
957 - "\tcpushl %%ic,(%0)" : : "a" (set));
959 + * flush_cache_range - Flush a cache range
961 + * @start: Starting address
962 + * @end: Ending address
964 + * flush_cache_range must be a macro to avoid a dependency on
965 + * linux/mm.h which includes this file.
967 +static inline void flush_cache_range(struct vm_area_struct *vma,
968 + unsigned long start, unsigned long end)
970 + if (vma->vm_mm == current->mm)
971 + cf_cache_flush_range(start, end);
975 + * flush_cache_page - Flush a page of the cache
980 + * flush_cache_page must be a macro to avoid a dependency on
981 + * linux/mm.h which includes this file.
983 +static inline void flush_cache_page(struct vm_area_struct *vma,
984 + unsigned long vmaddr, unsigned long pfn)
986 + if (vma->vm_mm == current->mm)
987 + cf_cache_flush_range(vmaddr, vmaddr+PAGE_SIZE);
991 + * __flush_page_to_ram - Push a page out of the cache
992 + * @vaddr: Virtual address at start of page
994 + * Push the page at kernel virtual address *vaddr* and clear
997 +static inline void __flush_page_to_ram(void *vaddr)
999 + asm volatile("nop\n"
1000 + "move%.l %2,%%d0\n"
1002 + "movec %%d0,%%cacr\n"
1003 + "move%.l %0,%%d0\n"
1004 + "and%.l #0xfffffff0,%%d0\n"
1005 + "move%.l %%d0,%%a0\n"
1006 + "move%.l %1,%%d0\n"
1008 + "cpushl %%bc,(%%a0)\n"
1009 + "lea 0x10(%%a0),%%a0\n"
1010 + "subq%.l #1,%%d0\n"
1012 + "movec %2,%%cacr\n"
1013 + : : "a" (__pa(vaddr)), "i" (PAGE_SIZE / CACHE_LINE_SIZE),
1014 + "r" (shadow_cacr), "i" (CF_CACR_SPA)
1019 + * Various defines for the kernel.
1022 +extern void cache_clear(unsigned long paddr, int len);
1023 +extern void cache_push(unsigned long paddr, int len);
1024 +extern void flush_icache_range(unsigned long address, unsigned long endaddr);
1026 +#define flush_cache_all() flush_bcache()
1027 +#define flush_cache_vmap(start, end) flush_bcache()
1028 +#define flush_cache_vunmap(start, end) flush_bcache()
1030 +#define flush_dcache_range(vstart, vend) cf_dcache_flush_range(vstart, vend)
1031 +#define flush_dcache_page(page) __flush_page_to_ram(page_address(page))
1032 +#define flush_dcache_mmap_lock(mapping) do { } while (0)
1033 +#define flush_dcache_mmap_unlock(mapping) do { } while (0)
1035 +#define flush_icache_page(vma, page) __flush_page_to_ram(page_address(page))
1038 + * copy_to_user_page - Copy memory to user page
1040 static inline void copy_to_user_page(struct vm_area_struct *vma,
1041 struct page *page, unsigned long vaddr,
1042 void *dst, void *src, int len)
1044 memcpy(dst, src, len);
1045 - flush_icache_user_page(vma, page, vaddr, len);
1046 + cf_cache_flush(page_to_phys(page), PAGE_SIZE);
1050 + * copy_from_user_page - Copy memory from user page
1052 static inline void copy_from_user_page(struct vm_area_struct *vma,
1053 struct page *page, unsigned long vaddr,
1054 void *dst, void *src, int len)
1056 + cf_cache_flush(page_to_phys(page), PAGE_SIZE);
1057 memcpy(dst, src, len);
1060 -#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
1061 -#define flush_cache_vmap(start, end) flush_cache_all()
1062 -#define flush_cache_vunmap(start, end) flush_cache_all()
1063 -#define flush_dcache_mmap_lock(mapping) do { } while (0)
1064 -#define flush_dcache_mmap_unlock(mapping) do { } while (0)
1066 #endif /* M68K_CF_CACHEFLUSH_H */
1067 --- a/include/asm-m68k/cfcache.h
1068 +++ b/include/asm-m68k/cfcache.h
1071 - * include/asm-m68k/cfcache.h
1072 + * include/asm-m68k/cfcache.h - Coldfire Cache Controller
1074 + * Kurt Mahan kmahan@freescale.com
1076 + * Copyright Freescale Semiconductor, Inc. 2007
1078 + * This program is free software; you can redistribute it and/or modify it
1079 + * under the terms of the GNU General Public License as published by the
1080 + * Free Software Foundation; either version 2 of the License, or (at your
1081 + * option) any later version.
1083 #ifndef CF_CFCACHE_H
1084 #define CF_CFCACHE_H
1087 + * CACR Cache Control Register
1089 #define CF_CACR_DEC (0x80000000) /* Data Cache Enable */
1090 #define CF_CACR_DW (0x40000000) /* Data default Write-protect */
1091 #define CF_CACR_DESB (0x20000000) /* Data Enable Store Buffer */
1092 -#define CF_CACR_DDPI (0x10000000) /* Data Disable CPUSHL Invalidate */
1093 +#define CF_CACR_DPI (0x10000000) /* Data Disable CPUSHL Invalidate */
1094 #define CF_CACR_DHLCK (0x08000000) /* 1/2 Data Cache Lock Mode */
1095 #define CF_CACR_DDCM_00 (0x00000000) /* Cacheable writethrough imprecise */
1096 #define CF_CACR_DDCM_01 (0x02000000) /* Cacheable copyback */
1097 #define CF_CACR_DDCM_10 (0x04000000) /* Noncacheable precise */
1098 #define CF_CACR_DDCM_11 (0x06000000) /* Noncacheable imprecise */
1099 #define CF_CACR_DCINVA (0x01000000) /* Data Cache Invalidate All */
1100 +#define CF_CACR_DDSP (0x00800000) /* Data default supervisor-protect */
1101 #define CF_CACR_IVO (0x00100000) /* Invalidate only */
1102 #define CF_CACR_BEC (0x00080000) /* Branch Cache Enable */
1103 #define CF_CACR_BCINVA (0x00040000) /* Branch Cache Invalidate All */
1105 #define CF_CACR_IHLCK (0x00000800) /* 1/2 Instruction Cache Lock Mode */
1106 #define CF_CACR_IDCM (0x00000400) /* Noncacheable Instr default mode */
1107 #define CF_CACR_ICINVA (0x00000100) /* Instr Cache Invalidate All */
1108 +#define CF_CACR_IDSP (0x00000080) /* Ins default supervisor-protect */
1109 #define CF_CACR_EUSP (0x00000020) /* Switch stacks in user mode */
1111 -#define DCACHE_LINE_SIZE 0x0010 /* bytes per line */
1112 -#define DCACHE_WAY_SIZE 0x2000 /* words per cache block */
1113 -#define CACHE_DISABLE_MODE (CF_CACR_DCINVA+CF_CACR_BCINVA+CF_CACR_ICINVA)
1114 -#ifdef CONFIG_M5445X_DISABLE_CACHE
1115 -/* disable cache for testing rev0 silicon */
1116 -#define CACHE_INITIAL_MODE (CF_CACR_EUSP)
1118 -#define CACHE_INITIAL_MODE (CF_CACR_DEC+CF_CACR_BEC+CF_CACR_IEC+CF_CACR_EUSP)
1121 -#define _DCACHE_SIZE (2*16384)
1122 -#define _ICACHE_SIZE (2*16384)
1124 -#define _SET_SHIFT 4
1126 +#ifdef CONFIG_M54455
1128 - * Masks for cache sizes. Programming note: because the set size is a
1129 - * power of two, the mask is also the last address in the set.
1130 - * This may need to be #ifdef for other Coldfire processors.
1131 + * M5445x Cache Configuration
1132 + * - cache line size is 16 bytes
1133 + * - cache is 4-way set associative
1134 + * - each cache has 256 sets (64k / 16bytes / 4way)
1135 + * - I-Cache size is 16KB
1136 + * - D-Cache size is 16KB
1138 +#define ICACHE_SIZE 0x4000 /* instruction - 16k */
1139 +#define DCACHE_SIZE 0x4000 /* data - 16k */
1141 -#define _DCACHE_SET_MASK ((_DCACHE_SIZE/64-1)<<_SET_SHIFT)
1142 -#define _ICACHE_SET_MASK ((_ICACHE_SIZE/64-1)<<_SET_SHIFT)
1143 -#define LAST_DCACHE_ADDR _DCACHE_SET_MASK
1144 -#define LAST_ICACHE_ADDR _ICACHE_SET_MASK
1146 +#define CACHE_LINE_SIZE 0x0010 /* 16 bytes */
1147 +#define CACHE_SETS 0x0100 /* 256 sets */
1148 +#define CACHE_WAYS 0x0004 /* 4 way */
1150 +#define CACHE_DISABLE_MODE (CF_CACR_DCINVA+ \
1154 +#ifndef CONFIG_M5445X_DISABLE_CACHE
1155 +#define CACHE_INITIAL_MODE (CF_CACR_DEC+ \
1160 +/* cache disabled for testing */
1161 +#define CACHE_INITIAL_MODE (CF_CACR_EUSP)
1162 +#endif /* CONFIG_M5445X_DISABLE_CACHE */
1163 +#endif /* CONFIG_M54455 */
1165 #ifndef __ASSEMBLY__
1167 -extern void DcacheFlushInvalidate(void);
1169 -extern void DcacheDisable(void);
1170 -extern void DcacheEnable(void);
1172 -/******************************************************************************/
1173 -/*** Unimplemented Cache functionality ***/
1174 -/******************************************************************************/
1175 -#define preDcacheInvalidateBlockMark()
1176 -#define postDcacheInvalidateBlockMark()
1177 -#define DcacheZeroBlock(p, l) fast_bzero((char *)(p), (long)(l))
1178 -#define loadDcacheInvalidateBlock() ASSERT(!"Not Implemented on V4e")
1179 -#define IcacheInvalidateBlock() ASSERT(!"Not Implemented on V4e")
1181 -/******************************************************************************/
1182 -/*** Redundant Cache functionality on ColdFire ***/
1183 -/******************************************************************************/
1184 -#define DcacheInvalidateBlock(p, l) DcacheFlushInvalidateCacheBlock(p, l)
1185 -#define DcacheFlushCacheBlock(p, l) DcacheFlushInvalidateCacheBlock(p, l)
1186 -#define DcacheFlushBlock(p, l) DcacheFlushInvalidateCacheBlock(p, l)
1188 -extern void DcacheFlushInvalidateCacheBlock(void *start, unsigned long size);
1189 -extern void FLASHDcacheFlushInvalidate(void);
1191 +extern unsigned long shadow_cacr;
1192 extern void cacr_set(unsigned long x);
1194 #endif /* !__ASSEMBLY__ */