1 1.12 martin /* $NetBSD: cache_sh4.h,v 1.12 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.6 christos * SH4: SH7750 SH7750S SH7750R SH7751 SH7751R 34 1.1 uch */ 35 1.1 uch 36 1.4 uch #ifndef _SH3_CACHE_SH4_H_ 37 1.5 uch #define _SH3_CACHE_SH4_H_ 38 1.3 uch #include <sh3/devreg.h> 39 1.1 uch #ifdef _KERNEL 40 1.1 uch 41 1.5 uch #define SH4_ICACHE_SIZE 8192 42 1.5 uch #define SH4_DCACHE_SIZE 16384 43 1.8 nonaka #define SH4_EMODE_ICACHE_SIZE 16384 44 1.8 nonaka #define SH4_EMODE_DCACHE_SIZE 32768 45 1.5 uch #define SH4_CACHE_LINESZ 32 46 1.5 uch 47 1.5 uch #define SH4_CCR 0xff00001c 48 1.7 nonaka #define SH4_CCR_EMODE 0x80000000 49 1.5 uch #define SH4_CCR_IIX 0x00008000 50 1.5 uch #define SH4_CCR_ICI 0x00000800 51 1.5 uch #define SH4_CCR_ICE 0x00000100 52 1.5 uch #define SH4_CCR_OIX 0x00000080 53 1.5 uch #define SH4_CCR_ORA 0x00000020 54 1.5 uch #define SH4_CCR_OCI 0x00000008 55 1.5 uch #define SH4_CCR_CB 0x00000004 56 1.5 uch #define SH4_CCR_WT 0x00000002 57 1.5 uch #define SH4_CCR_OCE 0x00000001 58 1.5 uch 59 1.5 uch #define SH4_QACR0 0xff000038 60 1.5 uch #define SH4_QACR1 0xff00003c 61 1.5 uch #define SH4_QACR_AREA_SHIFT 2 62 1.5 uch #define SH4_QACR_AREA_MASK 0x0000001c 63 1.1 uch 64 1.1 uch /* I-cache address/data array */ 65 1.5 uch #define SH4_CCIA 0xf0000000 66 1.1 uch /* address specification */ 67 1.5 uch #define CCIA_A 0x00000008 /* associate bit */ 68 1.5 uch #define CCIA_ENTRY_SHIFT 5 /* line size 32B */ 69 1.5 uch #define CCIA_ENTRY_MASK 0x00001fe0 /* [12:5] 256-entries */ 70 1.8 nonaka #define CCIA_EMODE_ENTRY_MASK 0x00003fe0 /* [13:5] 512-entries */ 71 1.1 uch /* data specification */ 72 1.5 uch #define CCIA_V 0x00000001 73 1.5 uch #define CCIA_TAGADDR_MASK 0xfffffc00 /* [31:10] */ 74 1.1 uch 75 1.5 uch #define SH4_CCID 0xf1000000 76 1.1 uch /* address specification */ 77 1.5 uch #define CCID_L_SHIFT 2 78 1.5 uch #define CCID_L_MASK 0x1c /* line-size is 32B */ 79 1.8 nonaka #define CCID_ENTRY_MASK 0x00001fe0 /* [12:5] 256-entries */ 80 1.1 uch 81 1.1 uch /* D-cache address/data array */ 82 1.5 uch #define SH4_CCDA 0xf4000000 83 1.1 uch /* address specification */ 84 1.5 uch #define CCDA_A 0x00000008 /* associate bit */ 85 1.5 uch #define CCDA_ENTRY_SHIFT 5 /* line size 32B */ 86 1.8 nonaka #define CCDA_ENTRY_MASK 0x00003fe0 /* [13:5] 512-entries */ 87 1.1 uch /* data specification */ 88 1.5 uch #define CCDA_V 0x00000001 89 1.5 uch #define CCDA_U 0x00000002 90 1.5 uch #define CCDA_TAGADDR_MASK 0xfffffc00 /* [31:10] */ 91 1.1 uch 92 1.5 uch #define SH4_CCDD 0xf5000000 93 1.1 uch 94 1.1 uch /* Store Queue */ 95 1.5 uch #define SH4_SQ 0xe0000000 96 1.1 uch 97 1.1 uch /* 98 1.1 uch * cache flush macro for locore level code. 99 1.1 uch */ 100 1.5 uch #define SH4_CACHE_FLUSH() \ 101 1.1 uch do { \ 102 1.11 uwe uint32_t __e, __a; \ 103 1.1 uch \ 104 1.1 uch /* D-cache */ \ 105 1.7 nonaka for (__e = 0; __e < (SH4_DCACHE_SIZE / SH4_CACHE_LINESZ); __e++) {\ 106 1.2 uch __a = SH4_CCDA | (__e << CCDA_ENTRY_SHIFT); \ 107 1.10 perry (*(volatile uint32_t *)__a) &= ~(CCDA_U | CCDA_V); \ 108 1.1 uch } \ 109 1.1 uch /* I-cache */ \ 110 1.7 nonaka for (__e = 0; __e < (SH4_ICACHE_SIZE / SH4_CACHE_LINESZ); __e++) {\ 111 1.2 uch __a = SH4_CCIA | (__e << CCIA_ENTRY_SHIFT); \ 112 1.10 perry (*(volatile uint32_t *)__a) &= ~(CCIA_V); \ 113 1.8 nonaka } \ 114 1.8 nonaka } while(/*CONSTCOND*/0) 115 1.8 nonaka 116 1.8 nonaka #define SH4_EMODE_CACHE_FLUSH() \ 117 1.8 nonaka do { \ 118 1.8 nonaka uint32_t __e, __a; \ 119 1.8 nonaka \ 120 1.8 nonaka /* D-cache */ \ 121 1.8 nonaka for (__e = 0;__e < (SH4_EMODE_DCACHE_SIZE / SH4_CACHE_LINESZ);__e++) {\ 122 1.8 nonaka __a = SH4_CCDA | (__e << CCDA_ENTRY_SHIFT); \ 123 1.10 perry (*(volatile uint32_t *)__a) &= ~(CCDA_U | CCDA_V); \ 124 1.8 nonaka } \ 125 1.8 nonaka /* I-cache */ \ 126 1.8 nonaka for (__e = 0;__e < (SH4_EMODE_ICACHE_SIZE / SH4_CACHE_LINESZ);__e++) {\ 127 1.8 nonaka __a = SH4_CCIA | (__e << CCIA_ENTRY_SHIFT); \ 128 1.10 perry (*(volatile uint32_t *)__a) &= ~(CCIA_V); \ 129 1.1 uch } \ 130 1.1 uch } while(/*CONSTCOND*/0) 131 1.1 uch 132 1.5 uch #define SH7750_CACHE_FLUSH() SH4_CACHE_FLUSH() 133 1.5 uch #define SH7750S_CACHE_FLUSH() SH4_CACHE_FLUSH() 134 1.8 nonaka #define SH7751_CACHE_FLUSH() SH4_CACHE_FLUSH() 135 1.8 nonaka #if defined(SH4_CACHE_DISABLE_EMODE) 136 1.6 christos #define SH7750R_CACHE_FLUSH() SH4_CACHE_FLUSH() 137 1.6 christos #define SH7751R_CACHE_FLUSH() SH4_CACHE_FLUSH() 138 1.8 nonaka #else 139 1.8 nonaka #define SH7750R_CACHE_FLUSH() SH4_EMODE_CACHE_FLUSH() 140 1.8 nonaka #define SH7751R_CACHE_FLUSH() SH4_EMODE_CACHE_FLUSH() 141 1.8 nonaka #endif 142 1.6 christos 143 1.1 uch #ifndef _LOCORE 144 1.2 uch extern void sh4_cache_config(void); 145 1.1 uch #endif 146 1.1 uch #endif /* _KERNEL */ 147 1.4 uch #endif /* !_SH3_CACHE_SH4_H_ */ 148