[prev in list] [next in list] [prev in thread] [next in thread] 

List:       uclinux-dev
Subject:    [uClinux-dev] [PATCHv2] m68knommu: Use symbolic constants for cache
From:       Philippe De Muyter <phdm () macqel ! be>
Date:       2010-09-25 15:28:41
Message-ID: 1285428521-15752-1-git-send-email-phdm () macqel ! be
[Download RAW message or body]

The MCF548x have the same cache control registers as the MCF5407.
Extract the bit definitions for the ACR and CACR registers from m5407sim.h
and move them to a new file m54xxacr.h.  Use them instead of hex
constants in cacheflush_no.h and mcfcache.h.

Signed-off-by: Philippe De Muyter <phdm@macqel.be>
---
 arch/m68k/include/asm/cacheflush_no.h |   29 +++++++++---
 arch/m68k/include/asm/m5407sim.h      |   34 ---------------
 arch/m68k/include/asm/m54xxacr.h      |   76 +++++++++++++++++++++++++++++++++
 arch/m68k/include/asm/mcfcache.h      |   22 +++++----
 4 files changed, 110 insertions(+), 51 deletions(-)
 create mode 100644 arch/m68k/include/asm/m54xxacr.h

diff --git a/arch/m68k/include/asm/cacheflush_no.h b/arch/m68k/include/asm/cacheflush_no.h
index 7085bd5..a8334f2 100644
--- a/arch/m68k/include/asm/cacheflush_no.h
+++ b/arch/m68k/include/asm/cacheflush_no.h
@@ -5,13 +5,21 @@
  * (C) Copyright 2000-2004, Greg Ungerer <gerg@snapgear.com>
  */
 #include <linux/mm.h>
+#if defined(CONFIG_M5407) || defined(CONFIG_M548x)
+#include <asm/m54xxacr.h>
+#if ((DATA_CACHE_MODE & ACR_CM) == ACR_CM_WT)
+#define flush_dcache_range(a, l) do { asm("nop"); } while (0)
+#endif
+#endif
 
 #define flush_cache_all()			__flush_cache_all()
 #define flush_cache_mm(mm)			do { } while (0)
 #define flush_cache_dup_mm(mm)			do { } while (0)
 #define flush_cache_range(vma, start, end)	__flush_cache_all()
 #define flush_cache_page(vma, vmaddr)		do { } while (0)
+#ifndef flush_dcache_range
 #define flush_dcache_range(start,len)		__flush_cache_all()
+#endif
 #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
 #define flush_dcache_page(page)			do { } while (0)
 #define flush_dcache_mmap_lock(mapping)		do { } while (0)
@@ -30,27 +38,34 @@
 static inline void __flush_cache_all(void)
 {
 #if defined(CONFIG_M5407) || defined(CONFIG_M548x)
+	__asm__ __volatile__ (
+#if ((DATA_CACHE_MODE & ACR_CM) == ACR_CM_CP)
 	/*
 	 *	Use cpushl to push and invalidate all cache lines.
 	 *	Gas doesn't seem to know how to generate the ColdFire
 	 *	cpushl instruction... Oh well, bit stuff it for now.
 	 */
-	__asm__ __volatile__ (
-		"nop\n\t"
 		"clrl	%%d0\n\t"
 		"1:\n\t"
 		"movel	%%d0,%%a0\n\t"
 		"2:\n\t"
 		".word	0xf468\n\t"
-		"addl	#0x10,%%a0\n\t"
-		"cmpl	#0x00000800,%%a0\n\t"
+		"addl	%0,%%a0\n\t"
+		"cmpl	%1,%%a0\n\t"
 		"blt	2b\n\t"
 		"addql	#1,%%d0\n\t"
-		"cmpil	#4,%%d0\n\t"
+		"cmpil	%2,%%d0\n\t"
 		"bne	1b\n\t"
-		"movel	#0xb6088500,%%d0\n\t"
+#endif
+		"movel	%3,%%d0\n\t"
 		"movec	%%d0,%%CACR\n\t"
-		: : : "d0", "a0" );
+		"nop\n\t"	/* forces flush of Store Buffer */
+		: /* No output */
+		: "i" (CACHE_LINE_SIZE),
+		  "i" (DCACHE_SIZE / CACHE_WAYS),
+		  "i" (CACHE_WAYS),
+		  "i" (CACHE_MODE|CACR_DCINVA|CACR_BCINVA|CACR_ICINVA)
+		: "d0", "a0" );
 #endif /* CONFIG_M5407 */
 #if defined(CONFIG_M523x) || defined(CONFIG_M527x)
 	__asm__ __volatile__ (
diff --git a/arch/m68k/include/asm/m5407sim.h b/arch/m68k/include/asm/m5407sim.h
index c399abb..2099435 100644
--- a/arch/m68k/include/asm/m5407sim.h
+++ b/arch/m68k/include/asm/m5407sim.h
@@ -117,39 +117,5 @@
 #define	MCF_IRQ_TIMER		30		/* Timer0, Level 6 */
 #define	MCF_IRQ_PROFILER	31		/* Timer1, Level 7 */
 
-/*
- *	Define the Cache register flags.
- */
-#define	CACR_DEC		0x80000000	/* Enable data cache */
-#define	CACR_DWP		0x40000000	/* Data write protection */
-#define	CACR_DESB		0x20000000	/* Enable data store buffer */
-#define	CACR_DDPI		0x10000000	/* Disable CPUSHL */
-#define	CACR_DHCLK		0x08000000	/* Half data cache lock mode */
-#define	CACR_DDCM_WT		0x00000000	/* Write through cache*/
-#define	CACR_DDCM_CP		0x02000000	/* Copyback cache */
-#define	CACR_DDCM_P		0x04000000	/* No cache, precise */
-#define	CACR_DDCM_IMP		0x06000000	/* No cache, imprecise */
-#define	CACR_DCINVA		0x01000000	/* Invalidate data cache */
-#define	CACR_BEC		0x00080000	/* Enable branch cache */
-#define	CACR_BCINVA		0x00040000	/* Invalidate branch cache */
-#define	CACR_IEC		0x00008000	/* Enable instruction cache */
-#define	CACR_DNFB		0x00002000	/* Inhibited fill buffer */
-#define	CACR_IDPI		0x00001000	/* Disable CPUSHL */
-#define	CACR_IHLCK		0x00000800	/* Intruction cache half lock */
-#define	CACR_IDCM		0x00000400	/* Intruction cache inhibit */
-#define	CACR_ICINVA		0x00000100	/* Invalidate instr cache */
-
-#define	ACR_BASE_POS		24		/* Address Base */
-#define	ACR_MASK_POS		16		/* Address Mask */
-#define	ACR_ENABLE		0x00008000	/* Enable address */
-#define	ACR_USER		0x00000000	/* User mode access only */
-#define	ACR_SUPER		0x00002000	/* Supervisor mode only */
-#define	ACR_ANY			0x00004000	/* Match any access mode */
-#define	ACR_CM_WT		0x00000000	/* Write through mode */
-#define	ACR_CM_CP		0x00000020	/* Copyback mode */
-#define	ACR_CM_OFF_PRE		0x00000040	/* No cache, precise */
-#define	ACR_CM_OFF_IMP		0x00000060	/* No cache, imprecise */
-#define	ACR_WPROTECT		0x00000004	/* Write protect */
-
 /****************************************************************************/
 #endif	/* m5407sim_h */
diff --git a/arch/m68k/include/asm/m54xxacr.h b/arch/m68k/include/asm/m54xxacr.h
new file mode 100644
index 0000000..a6389b2
--- /dev/null
+++ b/arch/m68k/include/asm/m54xxacr.h
@@ -0,0 +1,76 @@
+/*
+ * Bit definitions for the MCF54xx ACR and CACR registers.
+ */
+
+#ifndef	m54xxacr_h
+#define	m54xxacr_h
+
+/*
+ *	Define the Cache register flags.
+ */
+#define	CACR_DEC	0x80000000	/* Enable data cache */
+#define	CACR_DWP	0x40000000	/* Data write protection */
+#define	CACR_DESB	0x20000000	/* Enable data store buffer */
+#define	CACR_DDPI	0x10000000	/* Disable invalidation by CPUSHL */
+#define	CACR_DHCLK	0x08000000	/* Half data cache lock mode */
+#define	CACR_DDCM_WT	0x00000000	/* Write through cache*/
+#define	CACR_DDCM_CP	0x02000000	/* Copyback cache */
+#define	CACR_DDCM_P	0x04000000	/* No cache, precise */
+#define	CACR_DDCM_IMP	0x06000000	/* No cache, imprecise */
+#define	CACR_DCINVA	0x01000000	/* Invalidate data cache */
+#define	CACR_BEC	0x00080000	/* Enable branch cache */
+#define	CACR_BCINVA	0x00040000	/* Invalidate branch cache */
+#define	CACR_IEC	0x00008000	/* Enable instruction cache */
+#define	CACR_DNFB	0x00002000	/* Inhibited fill buffer */
+#define	CACR_IDPI	0x00001000	/* Disable CPUSHL */
+#define	CACR_IHLCK	0x00000800	/* Intruction cache half lock */
+#define	CACR_IDCM	0x00000400	/* Intruction cache inhibit */
+#define	CACR_ICINVA	0x00000100	/* Invalidate instr cache */
+
+#define	ACR_BASE_POS	24		/* Address Base */
+#define	ACR_MASK_POS	16		/* Address Mask */
+#define	ACR_ENABLE	0x00008000	/* Enable address */
+#define	ACR_USER	0x00000000	/* User mode access only */
+#define	ACR_SUPER	0x00002000	/* Supervisor mode only */
+#define	ACR_ANY		0x00004000	/* Match any access mode */
+#define	ACR_CM_WT	0x00000000	/* Write through mode */
+#define	ACR_CM_CP	0x00000020	/* Copyback mode */
+#define	ACR_CM_OFF_PRE	0x00000040	/* No cache, precise */
+#define	ACR_CM_OFF_IMP	0x00000060	/* No cache, imprecise */
+#define	ACR_CM		0x00000060	/* Cache mode mask */
+#define	ACR_WPROTECT	0x00000004	/* Write protect */
+
+#if defined(CONFIG_M5407)
+
+#define ICACHE_SIZE 0x4000	/* instruction - 16k */
+#define DCACHE_SIZE 0x2000	/* data - 8k */
+
+#elif defined(CONFIG_M548x)
+
+#define ICACHE_SIZE 0x8000	/* instruction - 32k */
+#define DCACHE_SIZE 0x8000	/* data - 32k */
+
+#endif
+
+#define CACHE_LINE_SIZE 0x0010	/* 16 bytes */
+#define CACHE_WAYS 4		/* 4 ways */
+
+/*
+ *	Version 4 cores have a true harvard style separate instruction
+ *	and data cache. Enable data and instruction caches, also enable write
+ *	buffers and branch accelerator.
+ */
+/* attention : enabling CACR_DESB requires a "nop" to flush the store buffer */
+/* use '+' instead of '|' for assembler's sake */
+
+	/* Enable data cache */
+	/* Enable data store buffer */
+	/* outside ACRs : No cache, precise */
+	/* Enable instruction+branch caches */
+#define CACHE_MODE (CACR_DEC+CACR_DESB+CACR_DDCM_P+CACR_BEC+CACR_IEC)
+
+#define DATA_CACHE_MODE (ACR_ENABLE+ACR_ANY+ACR_CM_WT)
+
+#define INSN_CACHE_MODE (ACR_ENABLE+ACR_ANY)
+
+#endif	/* m54xxacr_h */
diff --git a/arch/m68k/include/asm/mcfcache.h b/arch/m68k/include/asm/mcfcache.h
index f49dfc0..7acb406 100644
--- a/arch/m68k/include/asm/mcfcache.h
+++ b/arch/m68k/include/asm/mcfcache.h
@@ -108,28 +108,30 @@
 #endif /* CONFIG_M532x */
 
 #if defined(CONFIG_M5407) || defined(CONFIG_M548x)
-/*
- *	Version 4 cores have a true harvard style separate instruction
- *	and data cache. Invalidate and enable cache, also enable write
- *	buffers and branch accelerator.
- */
+
+#include <asm/m54xxacr.h>
+
 .macro CACHE_ENABLE
-	movel	#0x01040100,%d0		/* invalidate whole cache */
+	/* invalidate whole cache */
+	movel	#(CACR_DCINVA+CACR_BCINVA+CACR_ICINVA),%d0
 	movec	%d0,%CACR
 	nop
-	movel	#0x000fc000,%d0		/* set SDRAM cached only */
+	/* addresses range for data cache : 0x00000000-0x0fffffff */
+	movel	#(0x000f0000+DATA_CACHE_MODE),%d0	/* set SDRAM cached */
 	movec	%d0, %ACR0
 	movel	#0x00000000,%d0		/* no other regions cached */
 	movec	%d0, %ACR1
-	movel	#0x000fc000,%d0		/* set SDRAM cached only */
+	/* addresses range for instruction cache : 0x00000000-0x0fffffff */
+	movel	#(0x000f0000+INSN_CACHE_MODE),%d0	/* set SDRAM cached */
 	movec	%d0, %ACR2
 	movel	#0x00000000,%d0		/* no other regions cached */
 	movec	%d0, %ACR3
-	movel	#0xb6088400,%d0		/* enable caches */
+	/* enable caches */
+	movel	#(CACHE_MODE),%d0
 	movec	%d0,%CACR
 	nop
 .endm
-#endif /* CONFIG_M5407 */
+#endif /* CONFIG_M5407 || CONFIG_M548x */
 
 #if defined(CONFIG_M520x)
 .macro CACHE_ENABLE
-- 
1.6.3.3

_______________________________________________
uClinux-dev mailing list
uClinux-dev@uclinux.org
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by uclinux-dev@uclinux.org
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic