m68k: fix ColdFire clear cache operation
PATCH v2 1/1 m68k: fix ColdFire clear cache operation
From: Greg Ungerer <[email protected]>
The code for clearing (invalidating) the ColdFire cache is actually performing a push operation. Add functions to clear the cache, and fix cache_clear() to call the appropriate clear cache function.
--- arch/m68k/include/asm/cacheflush_mm.h | 35 +++++++++++++++++++++++++++++++++ arch/m68k/mm/memory.c | 2 +- 2 files changed, 36 insertions(+), 1 deletions(-)
arch/m68k/include/asm/cacheflush_mm.h +35 -0
@@ -17,6 +17,41 @@#define DCACHE_SETMASK 0#endif +/* +* ColdFire architecture has no way to clear individual cache lines, so we +* are stuck invalidating all the cache entries when we want a clear operation. +*/ +static inline void clear_cf_icache (unsigned long start,unsigned long end) +{ + __asm__ __volatile__ ( +"movec %0,%%cacr\n\t" +"nop\n\t" + : + :"r" (CACHE_MODE |CACR_ICINVA |CACR_BCINVA )); +} + +static inline void clear_cf_dcache (unsigned long start,unsigned long end) +{ + __asm__ __volatile__ ( +"movec %0,%%cacr\n\t" +"nop\n\t" + : + :"r" (CACHE_MODE |CACR_DCINVA )); +} + +static inline void clear_cf_bcache (unsigned long start,unsigned long end) +{ + __asm__ __volatile__ ( +"movec %0,%%cacr\n\t" +"nop\n\t" + : + :"r" (CACHE_MODE |CACR_ICINVA |CACR_BCINVA |CACR_DCINVA )); +} + +/* +* Use the ColdFire cpushl instruction to push (and invalidate) cache lines. +* The start and end addresses are cache line numbers not memory addresses. +*/ static inline void flush_cf_icache (unsigned long start,unsigned long end) {unsigned long set;
arch/m68k/mm/memory.c +1 -1
@@ -203,7 +203,7 @@ static inline void pushcl040(unsigned long paddr)void cache_clear (unsigned long paddr,int len) {if (CPU_IS_COLDFIRE ) { -flush_cf_bcache (0 ,DCACHE_MAX_ADDR ); +clear_cf_bcache (0 ,DCACHE_MAX_ADDR ); }else if (CPU_IS_040_OR_060 ) {int tmp;
Signature · 1 line
1.7.0.4
arch/m68k/include/asm/cacheflush_mm.h line 28
Quoted 3 lines · On Wed, Jul 11, 2012 at 10:37:16AM +1000, [email protected] wrote:
arch/m68k/include/asm/cacheflush_mm.h +3
-0+ __asm__ __volatile__ ( +"movec %0,%%cacr\n\t" + "nop\n\t"
This could be written as
"movec %0,%%cacr; nop"
i.e. :
final "\n\t" is useless
other "\n\t" may be replaced by ";"
Philippe
Hi Philippe,
Quoted 9 lines · Philippe De Muyter
arch/m68k/include/asm/cacheflush_mm.h line 28
Quoted 3 lines · On Wed, Jul 11, 2012 at 10:37:16AM +1000, [email protected] wrote:
arch/m68k/include/asm/cacheflush_mm.h +3
-0+ __asm__ __volatile__ ( +"movec %0,%%cacr\n\t" + "nop\n\t"This could be written as
"movec %0,%%cacr; nop"
It could, but IMHO that is not as clear. One instruction per line is easier to read.
Quoted 2 lines
i.e. :
final "\n\t" is useless
Yep, I will remove that.
Thanks
Greg
------------------------------------------------------------------------
Greg Ungerer -- Principal Engineer EMAIL: [email protected] SnapGear Group, McAfee PHONE: +61 7 3435 2888 8 Gardner Close FAX: +61 7 3217 5323 Milton, QLD, 4064, Australia WEB: http://www.SnapGear.com
Geert Uytterhoeven
maintainerQuoted 7 lines · On Wed, Jul 11, 2012 at 2:37 AM, <[email protected]> wrote:
arch/m68k/include/asm/cacheflush_mm.h +1
-0@@ -17,6 +17,41 @@#define DCACHE_SETMASK 0#endif +/*
arch/m68k/include/asm/cacheflush_mm.h line 30
Quoted 10 lines
arch/m68k/include/asm/cacheflush_mm.h +10
-0+* ColdFire architecture has no way to clear individual cache lines, so we +* are stuck invalidating all the cache entries when we want a clear operation. +*/ +static inline void clear_cf_icache (unsigned long start,unsigned long end) +{ + __asm__ __volatile__ ( +"movec %0,%%cacr\n\t" +"nop\n\t" + : + :"r" (CACHE_MODE |CACR_ICINVA |CACR_BCINVA ));
These new functions should be moved inside the #ifdef CONFIG_COLDFIRE at the top of the file:
arch/m68k/include/asm/cacheflush_mm.h:30:10: error: 'CACHE_MODE' undeclared (first use in this function) arch/m68k/include/asm/cacheflush_mm.h:30:23: error: 'CACR_ICINVA' undeclared (first use in this function) arch/m68k/include/asm/cacheflush_mm.h:30:37: error: 'CACR_BCINVA' undeclared (first use in this function) arch/m68k/include/asm/cacheflush_mm.h:39:10: error: 'CACHE_MODE' undeclared (first use in this function) arch/m68k/include/asm/cacheflush_mm.h:39:23: error: 'CACR_DCINVA' undeclared (first use in this function) arch/m68k/include/asm/cacheflush_mm.h:48:10: error: 'CACHE_MODE' undeclared (first use in this function) arch/m68k/include/asm/cacheflush_mm.h:48:23: error: 'CACR_ICINVA' undeclared (first use in this function) arch/m68k/include/asm/cacheflush_mm.h:48:37: error: 'CACR_BCINVA' undeclared (first use in this function) arch/m68k/include/asm/cacheflush_mm.h:48:51: error: 'CACR_DCINVA' undeclared (first use in this function)
http://kisskb.ellerman.id.au/kisskb/buildresult/6720541/
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hi Geert,
Quoted 41 lines · Geert Uytterhoeven
Quoted 7 lines · On Wed, Jul 11, 2012 at 2:37 AM, <[email protected]> wrote:
arch/m68k/include/asm/cacheflush_mm.h +1
-0@@ -17,6 +17,41 @@#define DCACHE_SETMASK 0#endif +/* arch/m68k/include/asm/cacheflush_mm.h line 30
Quoted 10 lines
arch/m68k/include/asm/cacheflush_mm.h +10
-0+* ColdFire architecture has no way to clear individual cache lines, so we +* are stuck invalidating all the cache entries when we want a clear operation. +*/ +static inline void clear_cf_icache (unsigned long start,unsigned long end) +{ + __asm__ __volatile__ ( +"movec %0,%%cacr\n\t" +"nop\n\t" + : + :"r" (CACHE_MODE |CACR_ICINVA |CACR_BCINVA ));These new functions should be moved inside the #ifdef
CONFIG_COLDFIREat the top of the file:
arch/m68k/include/asm/cacheflush_mm.h:30:10: error: 'CACHE_MODE' undeclared (first use in this function)arch/m68k/include/asm/cacheflush_mm.h:30:23: error: 'CACR_ICINVA' undeclared (first use in this function)arch/m68k/include/asm/cacheflush_mm.h:30:37: error: 'CACR_BCINVA' undeclared (first use in this function)arch/m68k/include/asm/cacheflush_mm.h:39:10: error: 'CACHE_MODE' undeclared (first use in this function)arch/m68k/include/asm/cacheflush_mm.h:39:23: error: 'CACR_DCINVA' undeclared (first use in this function)arch/m68k/include/asm/cacheflush_mm.h:48:10: error: 'CACHE_MODE' undeclared (first use in this function)arch/m68k/include/asm/cacheflush_mm.h:48:23: error: 'CACR_ICINVA' undeclared (first use in this function)arch/m68k/include/asm/cacheflush_mm.h:48:37: error: 'CACR_BCINVA' undeclared (first use in this function)arch/m68k/include/asm/cacheflush_mm.h:48:51: error: 'CACR_DCINVA' undeclared (first use in this function)
Ah yes. Just moving those functions into a CONFIG_COLDFIRE region is not enough though. That will fail with:
CC arch/m68k/mm/memory.oarch/m68k/mm/memory.c: In function ‘cache_clear’:arch/m68k/mm/memory.c:206:2: error: implicit declaration of function ‘clear_cf_bcache’
I hit the same problem with the other ColdFire flush functions too. To fix those I locally defined the required definitions if they are not set. I can do the same here with:
#ifndef CACHE_MODE #define CACHE_MODE 0 #define CACR_ICINVA 0 #define CACR_DCINVA 0 #define CACR_BCINVA 0 #endif
This pollutes the code less than littering the code with #ifdefs on the use COFIG_COLDFIRE, and doesn't seem any worse than defining empty cache clear and push functions when not CONFIG_COLDFIRE.
Regards
Greg
------------------------------------------------------------------------
Greg Ungerer -- Principal Engineer EMAIL: [email protected] SnapGear Group, McAfee PHONE: +61 7 3435 2888 8 Gardner Close FAX: +61 7 3217 5323 Milton, QLD, 4064, Australia WEB: http://www.SnapGear.com