Home | History | Annotate | Line # | Download | only in include
cache_sh3.h revision 1.9
      1  1.9  martin /*	$NetBSD: cache_sh3.h,v 1.9 2008/04/28 20:23:35 martin Exp $	*/
      2  1.1     uch 
      3  1.1     uch /*-
      4  1.1     uch  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  1.1     uch  * All rights reserved.
      6  1.1     uch  *
      7  1.1     uch  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1     uch  * by UCHIYAMA Yasushi.
      9  1.1     uch  *
     10  1.1     uch  * Redistribution and use in source and binary forms, with or without
     11  1.1     uch  * modification, are permitted provided that the following conditions
     12  1.1     uch  * are met:
     13  1.1     uch  * 1. Redistributions of source code must retain the above copyright
     14  1.1     uch  *    notice, this list of conditions and the following disclaimer.
     15  1.1     uch  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1     uch  *    notice, this list of conditions and the following disclaimer in the
     17  1.1     uch  *    documentation and/or other materials provided with the distribution.
     18  1.1     uch  *
     19  1.1     uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1     uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1     uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1     uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1     uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1     uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1     uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1     uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1     uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1     uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1     uch  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1     uch  */
     31  1.1     uch 
     32  1.1     uch /*
     33  1.1     uch  * SH3: SH7708, SH7708S, SH7708R, SH7709, SH7709A
     34  1.1     uch  */
     35  1.5     uch #ifndef _SH3_CACHE_SH3_H_
     36  1.6     uch #define	_SH3_CACHE_SH3_H_
     37  1.3     uch #include <sh3/devreg.h>
     38  1.1     uch #ifdef _KERNEL
     39  1.1     uch 
     40  1.6     uch #define	SH3_CCR			0xffffffec
     41  1.6     uch #define	  SH3_CCR_CE		  0x00000001
     42  1.6     uch #define	  SH3_CCR_WT		  0x00000002
     43  1.1     uch /* SH7708 don't have CB bit */
     44  1.6     uch #define	  SH3_CCR_CB		  0x00000004
     45  1.6     uch #define	  SH3_CCR_CF		  0x00000008
     46  1.1     uch /* SH7709A don't have RA bit */
     47  1.2     uch #define	  SH3_CCR_RA		  0x00000020
     48  1.1     uch 
     49  1.1     uch /* SH7709A specific cache-lock control register */
     50  1.6     uch #define	SH7709A_CCR2		0xa40000b0
     51  1.6     uch #define	  SH7709A_CCR2_W2LOCK	  0x00000001
     52  1.6     uch #define	  SH7709A_CCR2_W2LOAD	  0x00000002
     53  1.6     uch #define	  SH7709A_CCR2_W3LOCK	  0x00000100
     54  1.6     uch #define	  SH7709A_CCR2_W3LOAD	  0x00000200
     55  1.1     uch 
     56  1.6     uch #define	SH3_CCA			0xf0000000
     57  1.1     uch /* Address specification */
     58  1.6     uch #define	  CCA_A			  0x00000008
     59  1.6     uch #define	  CCA_ENTRY_SHIFT	  4
     60  1.1     uch /* 8KB cache (SH7708, SH7708S, SH7708R, SH7709) */
     61  1.6     uch #define	  CCA_8K_ENTRY		  128
     62  1.6     uch #define	  CCA_8K_ENTRY_MASK	  0x000007f0	/* [10:4] */
     63  1.6     uch #define	  CCA_8K_WAY_SHIFT	  11
     64  1.6     uch #define	  CCA_8K_WAY_MASK	  0x00001800	/* [12:11] */
     65  1.1     uch /* 16KB cache (SH7709A) */
     66  1.6     uch #define	  CCA_16K_ENTRY		  256
     67  1.6     uch #define	  CCA_16K_ENTRY_MASK	  0x00000ff0	/* [11:4] */
     68  1.6     uch #define	  CCA_16K_WAY_SHIFT	  12
     69  1.6     uch #define	  CCA_16K_WAY_MASK	  0x00003000	/* [13:12] */
     70  1.1     uch 
     71  1.1     uch /* Data specification */
     72  1.2     uch #define	  CCA_V			  0x00000001
     73  1.6     uch #define	  CCA_U			  0x00000002
     74  1.2     uch #define	  CCA_LRU_SHIFT		  4
     75  1.6     uch #define	  CCA_LRU_MASK		  0x000003f0	/* [9:4] */
     76  1.6     uch #define	  CCA_TAGADDR_SHIFT	  10
     77  1.6     uch #define	  CCA_TAGADDR_MASK	  0xfffffc00	/* [31:10] */
     78  1.1     uch 
     79  1.6     uch #define	SH3_CCD			0xf1000000
     80  1.1     uch /* Address specification */
     81  1.6     uch #define	  CCD_L_SHIFT		  2
     82  1.6     uch #define	  CCD_L_MASK		  0x0000000c	/* [3:2] */
     83  1.6     uch #define	  CCD_E_SHIFT		  4
     84  1.6     uch #define	  CCD_8K_E_MASK		  0x000007f0	/* [10:4] */
     85  1.6     uch #define	  CCD_16K_E_MASK	  0x00000ff0	/* [11:4] */
     86  1.6     uch #define	  CCD_8K_W_SHIFT	  11
     87  1.6     uch #define	  CCD_8K_W_MASK		  0x00001800	/* [12:11] */
     88  1.6     uch #define	  CCD_16K_W_SHIFT	  12
     89  1.6     uch #define	  CCD_16K_W_MASK	  0x00003000	/* [13:12] */
     90  1.1     uch /* Data specification */
     91  1.1     uch 
     92  1.1     uch /*
     93  1.1     uch  * Configuration
     94  1.1     uch  */
     95  1.6     uch #define	SH3_CACHE_LINESZ		16
     96  1.6     uch #define	SH3_CACHE_NORMAL_WAY		4
     97  1.6     uch #define	SH3_CACHE_RAMMODE_WAY		2
     98  1.6     uch 
     99  1.6     uch #define	SH3_CACHE_8K_ENTRY		128
    100  1.6     uch #define	SH3_CACHE_8K_WAY_NORMAL		4
    101  1.6     uch #define	SH3_CACHE_8K_WAY_RAMMODE	2
    102  1.1     uch 
    103  1.6     uch #define	SH3_CACHE_16K_ENTRY		256
    104  1.6     uch #define	SH3_CACHE_16K_WAY		4
    105  1.1     uch 
    106  1.1     uch /*
    107  1.1     uch  * cache flush macro for locore level code.
    108  1.1     uch  */
    109  1.6     uch #define	SH3_CACHE_8K_FLUSH(maxway)					\
    110  1.1     uch do {									\
    111  1.8     uwe 	uint32_t __e, __w, __wa, __a;					\
    112  1.1     uch 									\
    113  1.1     uch 	for (__w = 0; __w < maxway; __w++) {				\
    114  1.2     uch 		__wa = SH3_CCA | __w << CCA_8K_WAY_SHIFT;		\
    115  1.1     uch 		for (__e = 0; __e < CCA_8K_ENTRY; __e++)	{	\
    116  1.1     uch 			__a = __wa |(__e << CCA_ENTRY_SHIFT);		\
    117  1.8     uwe 			(*(volatile uint32_t *)__a) &=		\
    118  1.1     uch 				~(CCA_U | CCA_V);			\
    119  1.1     uch 		}							\
    120  1.1     uch 	}								\
    121  1.1     uch } while (/*CONSTCOND*/0)
    122  1.1     uch 
    123  1.6     uch #define	SH3_CACHE_16K_FLUSH()						\
    124  1.1     uch do {									\
    125  1.8     uwe 	uint32_t __e, __w, __wa, __a;					\
    126  1.1     uch 									\
    127  1.1     uch 	for (__w = 0; __w < SH3_CACHE_16K_WAY; __w++) {			\
    128  1.2     uch 		__wa = SH3_CCA | __w << CCA_16K_WAY_SHIFT;		\
    129  1.1     uch 		for (__e = 0; __e < CCA_16K_ENTRY; __e++)	{	\
    130  1.1     uch 			__a = __wa |(__e << CCA_ENTRY_SHIFT);		\
    131  1.8     uwe 			(*(volatile uint32_t *)__a) &=		\
    132  1.1     uch 				~(CCA_U | CCA_V);			\
    133  1.1     uch 		}							\
    134  1.1     uch 	}								\
    135  1.1     uch } while (/*CONSTCOND*/0)
    136  1.1     uch 
    137  1.6     uch #define	SH7708_CACHE_FLUSH()		SH3_CACHE_8K_FLUSH(4)
    138  1.6     uch #define	SH7708_CACHE_FLUSH_RAMMODE()	SH3_CACHE_8K_FLUSH(2)
    139  1.6     uch #define	SH7708S_CACHE_FLUSH()		SH3_CACHE_8K_FLUSH(4)
    140  1.6     uch #define	SH7708S_CACHE_FLUSH_RAMMODE()	SH3_CACHE_8K_FLUSH(2)
    141  1.6     uch #define	SH7708R_CACHE_FLUSH()		SH3_CACHE_8K_FLUSH(4)
    142  1.6     uch #define	SH7708R_CACHE_FLUSH_RAMMODE()	SH3_CACHE_8K_FLUSH(2)
    143  1.6     uch #define	SH7709_CACHE_FLUSH()		SH3_CACHE_8K_FLUSH(4)
    144  1.6     uch #define	SH7709_CACHE_FLUSH_RAMMODE()	SH3_CACHE_8K_FLUSH(2)
    145  1.6     uch #define	SH7709A_CACHE_FLUSH()		SH3_CACHE_16K_FLUSH()
    146  1.1     uch 
    147  1.1     uch #ifndef _LOCORE
    148  1.2     uch extern void sh3_cache_config(void);
    149  1.1     uch #endif
    150  1.4     chs #endif /* _KERNEL */
    151  1.5     uch #endif /* !_SH3_CACHE_SH3_H_ */
    152