Home | History | Annotate | Line # | Download | only in include
cache_sh3.h revision 1.1
      1  1.1  uch /*	$NetBSD: cache_sh3.h,v 1.1 2002/02/11 18:03:05 uch 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  * 3. All advertising materials mentioning features or use of this software
     19  1.1  uch  *    must display the following acknowledgement:
     20  1.1  uch  *        This product includes software developed by the NetBSD
     21  1.1  uch  *        Foundation, Inc. and its contributors.
     22  1.1  uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  uch  *    contributors may be used to endorse or promote products derived
     24  1.1  uch  *    from this software without specific prior written permission.
     25  1.1  uch  *
     26  1.1  uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  uch  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  uch  */
     38  1.1  uch 
     39  1.1  uch /*
     40  1.1  uch  * SH3: SH7708, SH7708S, SH7708R, SH7709, SH7709A
     41  1.1  uch  */
     42  1.1  uch #ifndef _CACHE_SH3_H_
     43  1.1  uch #define _CACHE_SH3_H_
     44  1.1  uch #ifdef _KERNEL
     45  1.1  uch 
     46  1.1  uch #define SH3REG_CCR		0xffffffec
     47  1.1  uch #define   SH3_CCR_CE			0x00000001
     48  1.1  uch #define   SH3_CCR_WT			0x00000002
     49  1.1  uch /* SH7708 don't have CB bit */
     50  1.1  uch #define   SH3_CCR_CB			0x00000004
     51  1.1  uch #define   SH3_CCR_CF			0x00000008
     52  1.1  uch /* SH7709A don't have RA bit */
     53  1.1  uch #define	  SH3_CCR_RA			0x00000020
     54  1.1  uch 
     55  1.1  uch /* SH7709A specific cache-lock control register */
     56  1.1  uch #define SH7709A_CCR2		0xa40000b0
     57  1.1  uch #define   SH7709A_CCR2_W2LOCK		0x00000001
     58  1.1  uch #define   SH7709A_CCR2_W2LOAD		0x00000002
     59  1.1  uch #define   SH7709A_CCR2_W3LOCK		0x00000100
     60  1.1  uch #define   SH7709A_CCR2_W3LOAD		0x00000200
     61  1.1  uch 
     62  1.1  uch #define SH3REG_CCA		0xf0000000
     63  1.1  uch /* Address specification */
     64  1.1  uch #define   CCA_A				0x00000008
     65  1.1  uch #define   CCA_ENTRY_SHIFT		4
     66  1.1  uch /* 8KB cache (SH7708, SH7708S, SH7708R, SH7709) */
     67  1.1  uch #define   CCA_8K_ENTRY			128
     68  1.1  uch #define   CCA_8K_ENTRY_MASK		0x000007f0	/* [10:4] */
     69  1.1  uch #define   CCA_8K_WAY_SHIFT		11
     70  1.1  uch #define   CCA_8K_WAY_MASK		0x00001800	/* [12:11] */
     71  1.1  uch /* 16KB cache (SH7709A) */
     72  1.1  uch #define   CCA_16K_ENTRY			256
     73  1.1  uch #define   CCA_16K_ENTRY_MASK		0x00000ff0	/* [11:4] */
     74  1.1  uch #define   CCA_16K_WAY_SHIFT		12
     75  1.1  uch #define   CCA_16K_WAY_MASK		0x00003000	/* [13:12] */
     76  1.1  uch 
     77  1.1  uch /* Data specification */
     78  1.1  uch #define   CCA_U				0x00000001
     79  1.1  uch #define	  CCA_V				0x00000002
     80  1.1  uch #define	  CCA_LRU_SHIFT			4
     81  1.1  uch #define   CCA_LRU_MASK			0x000003f0	/* [9:4] */
     82  1.1  uch #define   CCA_TAGADDR_SHIFT		10
     83  1.1  uch #define   CCA_TAGADDR_MASK		0xfffffc00	/* [31:10] */
     84  1.1  uch 
     85  1.1  uch #define SH3REG_CCD		0xf1000000
     86  1.1  uch /* Address specification */
     87  1.1  uch #define   CCD_L_SHIFT			2
     88  1.1  uch #define   CCD_L_MASK			0x0000000c	/* [3:2] */
     89  1.1  uch #define   CCD_E_SHIFT			4
     90  1.1  uch #define   CCD_8K_E_MASK			0x000007f0	/* [10:4] */
     91  1.1  uch #define   CCD_16K_E_MASK		0x00000ff0	/* [11:4] */
     92  1.1  uch #define   CCD_8K_W_SHIFT		11
     93  1.1  uch #define   CCD_8K_W_MASK			0x00001800	/* [12:11] */
     94  1.1  uch #define   CCD_16K_W_SHIFT		12
     95  1.1  uch #define   CCD_16K_W_MASK		0x00003000	/* [13:12] */
     96  1.1  uch /* Data specification */
     97  1.1  uch 
     98  1.1  uch /*
     99  1.1  uch  * Configuration
    100  1.1  uch  */
    101  1.1  uch #define SH3_CACHE_LINESZ		16
    102  1.1  uch #define SH3_CACHE_NORMAL_WAY		4
    103  1.1  uch #define SH3_CACHE_RAMMODE_WAY		2
    104  1.1  uch 
    105  1.1  uch #define SH3_CACHE_8K_ENTRY		128
    106  1.1  uch #define SH3_CACHE_8K_WAY_NORMAL		4
    107  1.1  uch #define SH3_CACHE_8K_WAY_RAMMODE	2
    108  1.1  uch 
    109  1.1  uch #define SH3_CACHE_16K_ENTRY		256
    110  1.1  uch #define SH3_CACHE_16K_WAY		4
    111  1.1  uch 
    112  1.1  uch /*
    113  1.1  uch  * cache flush macro for locore level code.
    114  1.1  uch  */
    115  1.1  uch #define SH3_CACHE_8K_FLUSH(maxway)					\
    116  1.1  uch do {									\
    117  1.1  uch 	u_int32_t __e, __w, __wa, __a;					\
    118  1.1  uch 									\
    119  1.1  uch 	for (__w = 0; __w < maxway; __w++) {				\
    120  1.1  uch 		__wa = SH3REG_CCA | __w << CCA_8K_WAY_SHIFT;		\
    121  1.1  uch 		for (__e = 0; __e < CCA_8K_ENTRY; __e++)	{	\
    122  1.1  uch 			__a = __wa |(__e << CCA_ENTRY_SHIFT);		\
    123  1.1  uch 			(*(__volatile__ u_int32_t *)__a) &=		\
    124  1.1  uch 				~(CCA_U | CCA_V);			\
    125  1.1  uch 		}							\
    126  1.1  uch 	}								\
    127  1.1  uch } while (/*CONSTCOND*/0)
    128  1.1  uch 
    129  1.1  uch #define SH3_CACHE_16K_FLUSH()						\
    130  1.1  uch do {									\
    131  1.1  uch 	u_int32_t __e, __w, __wa, __a;					\
    132  1.1  uch 									\
    133  1.1  uch 	for (__w = 0; __w < SH3_CACHE_16K_WAY; __w++) {			\
    134  1.1  uch 		__wa = SH3REG_CCA | __w << CCA_16K_WAY_SHIFT;		\
    135  1.1  uch 		for (__e = 0; __e < CCA_16K_ENTRY; __e++)	{	\
    136  1.1  uch 			__a = __wa |(__e << CCA_ENTRY_SHIFT);		\
    137  1.1  uch 			(*(__volatile__ u_int32_t *)__a) &=		\
    138  1.1  uch 				~(CCA_U | CCA_V);			\
    139  1.1  uch 		}							\
    140  1.1  uch 	}								\
    141  1.1  uch } while (/*CONSTCOND*/0)
    142  1.1  uch 
    143  1.1  uch #define SH7708_CACHE_FLUSH()		SH3_CACHE_8K_FLUSH(4)
    144  1.1  uch #define SH7708_CACHE_FLUSH_RAMMODE()	SH3_CACHE_8K_FLUSH(2)
    145  1.1  uch #define SH7708S_CACHE_FLUSH()		SH3_CACHE_8K_FLUSH(4)
    146  1.1  uch #define SH7708S_CACHE_FLUSH_RAMMODE()	SH3_CACHE_8K_FLUSH(2)
    147  1.1  uch #define SH7708R_CACHE_FLUSH()		SH3_CACHE_8K_FLUSH(4)
    148  1.1  uch #define SH7708R_CACHE_FLUSH_RAMMODE()	SH3_CACHE_8K_FLUSH(2)
    149  1.1  uch #define SH7709_CACHE_FLUSH()		SH3_CACHE_8K_FLUSH(4)
    150  1.1  uch #define SH7709_CACHE_FLUSH_RAMMODE()	SH3_CACHE_8K_FLUSH(2)
    151  1.1  uch #define SH7709A_CACHE_FLUSH()		SH3_CACHE_16K_FLUSH()
    152  1.1  uch 
    153  1.1  uch #ifndef _LOCORE
    154  1.1  uch extern void sh3_cache_config(int);
    155  1.1  uch #endif
    156  1.1  uch #endif _KERNEL
    157  1.1  uch #endif /* _CACHE_SH3_H_ */
    158