Skip to content

Commit

Permalink
m68knommu: clean up ColdFire cache control code
Browse files Browse the repository at this point in the history
The cache control code for the ColdFire CPU's is a big ugly mess
of "#ifdef"ery liberally coated with bit constants. Clean it up.

The cache controllers in the various ColdFire parts are actually quite
similar. Just differing in some bit flags and options supported. Using
the header defines now in place it is pretty easy to factor out the
small differences and use common setup and flush/invalidate code.

I have preserved the cache setups as they where in the old code
(except where obviously wrong - like in the case of the 5249). Following
from this it should be easy now to extend the possible setups used on
the CACHE controllers that support split cacheing or copy-back or
write through options.

Signed-off-by: Greg Ungerer <gerg@uclinux.org>
  • Loading branch information
Greg Ungerer committed Jan 5, 2011
1 parent 3d46140 commit 8ce877a
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 192 deletions.
40 changes: 6 additions & 34 deletions arch/m68k/include/asm/cacheflush_no.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#define _M68KNOMMU_CACHEFLUSH_H

/*
* (C) Copyright 2000-2004, Greg Ungerer <gerg@snapgear.com>
* (C) Copyright 2000-2010, Greg Ungerer <gerg@snapgear.com>
*/
#include <linux/mm.h>
#include <asm/mcfsim.h>

#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_range(vma, start, end) do { } while (0)
#define flush_cache_page(vma, vmaddr) do { } while (0)
#ifndef flush_dcache_range
#define flush_dcache_range(start,len) __flush_cache_all()
Expand All @@ -33,41 +33,13 @@
#ifndef __flush_cache_all
static inline void __flush_cache_all(void)
{
#if defined(CONFIG_M523x) || defined(CONFIG_M527x)
#ifdef CACHE_INVALIDATE
__asm__ __volatile__ (
"movel #0x81400110, %%d0\n\t"
"movel %0, %%d0\n\t"
"movec %%d0, %%CACR\n\t"
"nop\n\t"
: : : "d0" );
#endif /* CONFIG_M523x || CONFIG_M527x */
#if defined(CONFIG_M528x)
__asm__ __volatile__ (
"movel #0x81000200, %%d0\n\t"
"movec %%d0, %%CACR\n\t"
"nop\n\t"
: : : "d0" );
#endif /* CONFIG_M528x */
#if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || defined(CONFIG_M5272)
__asm__ __volatile__ (
"movel #0x81000100, %%d0\n\t"
"movec %%d0, %%CACR\n\t"
"nop\n\t"
: : : "d0" );
#endif /* CONFIG_M5206 || CONFIG_M5206e || CONFIG_M5272 */
#ifdef CONFIG_M5249
__asm__ __volatile__ (
"movel #0xa1000200, %%d0\n\t"
"movec %%d0, %%CACR\n\t"
"nop\n\t"
: : : "d0" );
#endif /* CONFIG_M5249 */
#ifdef CONFIG_M532x
__asm__ __volatile__ (
"movel #0x81000210, %%d0\n\t"
"movec %%d0, %%CACR\n\t"
"nop\n\t"
: : : "d0" );
#endif /* CONFIG_M532x */
: : "i" (CACHE_INVALIDATE) : "d0" );
#endif
}
#endif /* __flush_cache_all */

Expand Down
27 changes: 27 additions & 0 deletions arch/m68k/include/asm/m52xxacr.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,32 @@
#define ACR_BWE 0x00000020 /* Write buffer enabled */
#define ACR_WPROTECT 0x00000004 /* Write protect region */

/*
* Set the cache controller settings we will use. This code is set to
* only use the instruction cache, even on the controllers that support
* split cache. (This setup is trying to preserve the existing behavior
* for now, in the furture I hope to actually use the split cache mode).
*/
#if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
defined(CONFIG_M5249) || defined(CONFIG_M5272)
#define CACHE_INIT (CACR_CINV)
#define CACHE_MODE (CACR_CENB + CACR_DCM)
#else
#ifdef CONFIG_COLDFIRE_SW_A7
#define CACHE_INIT (CACR_CINV + CACR_DISD)
#define CACHE_MODE (CACR_CENB + CACR_DISD + CACR_DCM)
#else
#define CACHE_INIT (CACR_CINV + CACR_DISD + CACR_EUSP)
#define CACHE_MODE (CACR_CENB + CACR_DISD + CACR_DCM + CACR_EUSP)
#endif
#endif

#define CACHE_INVALIDATE (CACHE_MODE + CACR_CINV)

#define ACR0_MODE ((CONFIG_RAMBASE & 0xff000000) + \
(0x000f0000) + \
(ACR_ENABLE + ACR_ANY + ACR_CENB + ACR_BWE))
#define ACR1_MODE 0

/****************************************************************************/
#endif /* m52xxsim_h */
18 changes: 18 additions & 0 deletions arch/m68k/include/asm/m53xxacr.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,23 @@
#define ACR_CM_IMPRE 0x00000060 /* Cache inhibited, imprecise */
#define ACR_WPROTECT 0x00000004 /* Write protect region */

/*
* Set the cache controller settings we will use. This default in the
* CACR is cache inhibited, we use the ACR register to set cacheing
* enabled on the regions we want (eg RAM).
*/
#ifdef CONFIG_COLDFIRE_SW_A7
#define CACHE_MODE (CACR_EC + CACR_ESB + CACR_DCM_PRE)
#else
#define CACHE_MODE (CACR_EC + CACR_ESB + CACR_DCM_PRE + CACR_EUSP)
#endif

#define CACHE_INIT CACR_CINVA

#define ACR0_MODE ((CONFIG_RAMBASE & 0xff000000) + \
(0x000f0000) + \
(ACR_ENABLE + ACR_ANY + ACR_CM_CB))
#define ACR1_MODE 0

/****************************************************************************/
#endif /* m53xxsim_h */
11 changes: 8 additions & 3 deletions arch/m68k/include/asm/m54xxacr.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@
#else
#define CACHE_MODE (CACR_DEC+CACR_DESB+CACR_DDCM_P+CACR_BEC+CACR_IEC+CACR_EUSP)
#endif

#define DATA_CACHE_MODE (ACR_ENABLE+ACR_ANY+ACR_CM_WT)

#define INSN_CACHE_MODE (ACR_ENABLE+ACR_ANY)

#define CACHE_INIT (CACR_DCINVA+CACR_BCINVA+CACR_ICINVA)
#define CACHE_INVALIDATE (CACHE_MODE+CACR_DCINVA+CACR_BCINVA+CACR_ICINVA)
#define ACR0_MODE (0x000f0000+DATA_CACHE_MODE)
#define ACR1_MODE 0
#define ACR2_MODE (0x000f0000+INSN_CACHE_MODE)
#define ACR3_MODE 0

#ifndef __ASSEMBLY__

#if ((DATA_CACHE_MODE & ACR_CM) == ACR_CM_WT)
Expand Down Expand Up @@ -112,7 +117,7 @@ static inline void __m54xx_flush_cache_all(void)
: "i" (CACHE_LINE_SIZE),
"i" (DCACHE_SIZE / CACHE_WAYS),
"i" (CACHE_WAYS),
"i" (CACHE_MODE|CACR_DCINVA|CACR_BCINVA|CACR_ICINVA)
"i" (CACHE_INVALIDATE)
: "d0", "a0" );
}

Expand Down
150 changes: 0 additions & 150 deletions arch/m68k/include/asm/mcfcache.h

This file was deleted.

26 changes: 21 additions & 5 deletions arch/m68knommu/platform/coldfire/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* head.S -- common startup code for ColdFire CPUs.
*
* (C) Copyright 1999-2006, Greg Ungerer <gerg@snapgear.com>.
* (C) Copyright 1999-2010, Greg Ungerer <gerg@snapgear.com>.
*/

/*****************************************************************************/
Expand All @@ -13,7 +13,6 @@
#include <linux/init.h>
#include <asm/asm-offsets.h>
#include <asm/coldfire.h>
#include <asm/mcfcache.h>
#include <asm/mcfsim.h>
#include <asm/thread_info.h>

Expand Down Expand Up @@ -173,10 +172,27 @@ _start:

/*
* Now that we know what the memory is, lets enable cache
* and get things moving. This is Coldfire CPU specific.
* and get things moving. This is Coldfire CPU specific. Not
* all version cores have identical cache register setup. But
* it is very similar. Define the exact settings in the headers
* then the code here is the same for all.
*/
CACHE_ENABLE /* enable CPU cache */

movel #CACHE_INIT,%d0 /* invalidate whole cache */
movec %d0,%CACR
nop
movel #ACR0_MODE,%d0 /* set RAM region for caching */
movec %d0,%ACR0
movel #ACR1_MODE,%d0 /* anything else to cache? */
movec %d0,%ACR1
#ifdef ACR2_MODE
movel #ACR2_MODE,%d0
movec %d0,%ACR2
movel #ACR3_MODE,%d0
movec %d0,%ACR3
#endif
movel #CACHE_MODE,%d0 /* enable cache */
movec %d0,%CACR
nop

#ifdef CONFIG_ROMFS_FS
/*
Expand Down

0 comments on commit 8ce877a

Please sign in to comment.