1 /* $NetBSD: cache.h,v 1.8 2006/09/24 00:43:44 tsutsui Exp $ */ 2 3 /*- 4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Cache configurations. 41 * 42 * SH3 I/D unified virtual-index physical-tag cache. 43 * SH4 I/D separated virtual-index physical-tag cache. 44 * 45 * 46 * size line-size entry way type 47 * SH7708 4/8K 16B 128 2/4 P0,P2,U0 [1] 48 * P1 [2] 49 * SH7709 4/8K 16B 128 2/4 [1] 50 * SH7709A 16K 16B 256 4 [1] 51 * 52 * SH7750 I$ D$ line-size entry way 53 * 8K 8/16K 32B 256 1 [1] 54 * SH7750 55 * SH7750S 56 * SH7751 I$ D$ line-size entry way 57 * 8K 8/16K 32B 256 1 [1] 58 * 59 * SH7750R 60 * SH7751R I$ D$ line-size entry way 61 * 16K 16/32K 32B 512 2 [1] 62 * 63 * [1] write-through/back selectable 64 * [2] write-through only 65 * 66 * Cache operations. 67 * 68 * There are some rules that must be followed: 69 * 70 * I-cache Synch (all or range): 71 * The goal is to synchronize the instruction stream, 72 * so you may need to write-back dirty data cache 73 * blocks first. If a range is requested, and you 74 * can't synchronize just a range, you have to hit 75 * the whole thing. 76 * 77 * D-cache Write-back Invalidate range: 78 * If you can't WB-Inv a range, you must WB-Inv the 79 * entire D-cache. 80 * 81 * D-cache Invalidate: 82 * If you can't Inv the D-cache without doing a 83 * Write-back, YOU MUST PANIC. This is to catch 84 * errors in calling code. Callers must be aware 85 * of this scenario, and must handle it appropriately 86 * (consider the bus_dma(9) operations). 87 * 88 * D-cache Write-back: 89 * If you can't Write-back without doing an invalidate, 90 * that's fine. Then treat this as a WB-Inv. Skipping 91 * the invalidate is merely an optimization. 92 * 93 * All operations: 94 * Valid virtual addresses must be passed to the 95 * cache operation. 96 * 97 * 98 * sh_icache_sync_all Synchronize I-cache 99 * 100 * sh_icache_sync_range Synchronize I-cache range 101 * 102 * sh_icache_sync_range_index (index ops) 103 * 104 * sh_dcache_wbinv_all Write-back Invalidate D-cache 105 * 106 * sh_dcache_wbinv_range Write-back Invalidate D-cache range 107 * 108 * sh_dcache_wbinv_range_index (index ops) 109 * 110 * sh_dcache_inv_range Invalidate D-cache range 111 * 112 * sh_dcache_wb_range Write-back D-cache range 113 * 114 * If I/D unified cache (SH3), I-cache ops are writeback invalidate 115 * operation. 116 * If write-through mode, sh_dcache_wb_range is no-operation. 117 * 118 */ 119 120 #ifndef _SH3_CACHE_H_ 121 #define _SH3_CACHE_H_ 122 123 #ifdef _KERNEL 124 struct sh_cache_ops { 125 void (*_icache_sync_all)(void); 126 void (*_icache_sync_range)(vaddr_t, vsize_t); 127 void (*_icache_sync_range_index)(vaddr_t, vsize_t); 128 129 void (*_dcache_wbinv_all)(void); 130 void (*_dcache_wbinv_range)(vaddr_t, vsize_t); 131 void (*_dcache_wbinv_range_index)(vaddr_t, vsize_t); 132 void (*_dcache_inv_range)(vaddr_t, vsize_t); 133 void (*_dcache_wb_range)(vaddr_t, vsize_t); 134 }; 135 136 /* Cache configurations */ 137 #define sh_cache_enable_unified sh_cache_enable_icache 138 extern int sh_cache_enable_icache; 139 extern int sh_cache_enable_dcache; 140 extern int sh_cache_write_through; 141 extern int sh_cache_write_through_p0_u0_p3; 142 extern int sh_cache_write_through_p1; 143 extern int sh_cache_ways; 144 extern int sh_cache_unified; 145 #define sh_cache_size_unified sh_cache_size_icache 146 extern int sh_cache_size_icache; 147 extern int sh_cache_size_dcache; 148 extern int sh_cache_line_size; 149 /* for n-way set associative cache */ 150 extern int sh_cache_way_size; 151 extern int sh_cache_way_shift; 152 extern int sh_cache_entry_mask; 153 154 /* Special mode */ 155 extern int sh_cache_ram_mode; 156 extern int sh_cache_index_mode_icache; 157 extern int sh_cache_index_mode_dcache; 158 159 extern int sh_cache_alias_mask; 160 #define sh_cache_indexof(x) (sh_cache_alias_mask & (x)) 161 extern int sh_cache_prefer_mask; 162 163 extern struct sh_cache_ops sh_cache_ops; 164 165 #define sh_icache_sync_all() \ 166 (*sh_cache_ops._icache_sync_all)() 167 168 #define sh_icache_sync_range(v, s) \ 169 (*sh_cache_ops._icache_sync_range)((v), (s)) 170 171 #define sh_icache_sync_range_index(v, s) \ 172 (*sh_cache_ops._icache_sync_range_index)((v), (s)) 173 174 #define sh_dcache_wbinv_all() \ 175 (*sh_cache_ops._dcache_wbinv_all)() 176 177 #define sh_dcache_wbinv_range(v, s) \ 178 (*sh_cache_ops._dcache_wbinv_range)((v), (s)) 179 180 #define sh_dcache_wbinv_range_index(v, s) \ 181 (*sh_cache_ops._dcache_wbinv_range_index)((v), (s)) 182 183 #define sh_dcache_inv_range(v, s) \ 184 (*sh_cache_ops._dcache_inv_range)((v), (s)) 185 186 #define sh_dcache_wb_range(v, s) \ 187 (*sh_cache_ops._dcache_wb_range)((v), (s)) 188 189 void sh_cache_init(void); 190 void sh_cache_information(void); 191 192 #define SH_HAS_UNIFIED_CACHE CPU_IS_SH3 193 #define SH_HAS_VIRTUAL_ALIAS CPU_IS_SH4 194 #define SH_HAS_WRITEBACK_CACHE (!sh_cache_write_through) 195 196 #endif /* _KERNEL */ 197 #endif /* _SH3_CACHE_H_ */ 198