Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | /* $Id: cache.c,v 1.4 2000/01/25 00:11:38 prumpf Exp $ * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 1999 Helge Deller (07-13-1999) * Copyright (C) 1999 SuSE GmbH Nuernberg * Copyright (C) 2000 Philipp Rumpf (prumpf@tux.org) * * Cache and TLB management * */ #include <linux/init.h> #include <linux/kernel.h> #include <linux/mm.h> #include <asm/pdc.h> #include <asm/cache.h> #include <asm/system.h> #include <asm/page.h> #include <asm/pgalloc.h> struct pdc_cache_info cache_info; #ifndef __LP64__ static struct pdc_btlb_info btlb_info; #endif void __flush_page_to_ram(unsigned long address) { __flush_dcache_range(address, PAGE_SIZE); __flush_icache_range(address, PAGE_SIZE); } void flush_data_cache(void) { register unsigned long base = cache_info.dc_base; register unsigned long count = cache_info.dc_count; register unsigned long loop = cache_info.dc_loop; register unsigned long stride = cache_info.dc_stride; register unsigned long addr; register long i, j; for(i=0,addr=base; i<count; i++,addr+=stride) for(j=0; j<loop; j++) fdce(addr); } static inline void flush_data_tlb_space(void) { unsigned long base = cache_info.dt_off_base; unsigned long count = cache_info.dt_off_count; unsigned long stride = cache_info.dt_off_stride; unsigned long loop = cache_info.dt_loop; unsigned long addr; long i,j; for(i=0,addr=base; i<count; i++,addr+=stride) for(j=0; j<loop; j++) pdtlbe(addr); } void flush_data_tlb(void) { unsigned long base = cache_info.dt_sp_base; unsigned long count = cache_info.dt_sp_count; unsigned long stride = cache_info.dt_sp_stride; unsigned long space; unsigned long old_sr1; long i; old_sr1 = mfsp(1); for(i=0,space=base; i<count; i++, space+=stride) { mtsp(space,1); flush_data_tlb_space(); } mtsp(old_sr1, 1); } static inline void flush_instruction_tlb_space(void) { unsigned long base = cache_info.it_off_base; unsigned long count = cache_info.it_off_count; unsigned long stride = cache_info.it_off_stride; unsigned long loop = cache_info.it_loop; unsigned long addr; long i,j; for(i=0,addr=base; i<count; i++,addr+=stride) for(j=0; j<loop; j++) pitlbe(addr); } void flush_instruction_tlb(void) { unsigned long base = cache_info.it_sp_base; unsigned long count = cache_info.it_sp_count; unsigned long stride = cache_info.it_sp_stride; unsigned long space; unsigned long old_sr1; unsigned int i; old_sr1 = mfsp(1); for(i=0,space=base; i<count; i++, space+=stride) { mtsp(space,1); flush_instruction_tlb_space(); } mtsp(old_sr1, 1); } void __flush_tlb_space(unsigned long space) { unsigned long old_sr1; old_sr1 = mfsp(1); mtsp(space, 1); flush_data_tlb_space(); flush_instruction_tlb_space(); mtsp(old_sr1, 1); } void flush_instruction_cache(void) { register unsigned long base = cache_info.ic_base; register unsigned long count = cache_info.ic_count; register unsigned long loop = cache_info.ic_loop; register unsigned long stride = cache_info.ic_stride; register unsigned long addr; register long i, j; unsigned long old_sr1; old_sr1 = mfsp(1); mtsp(0,1); /* * Note: fice instruction has 3 bit space field, so one must * be specified (otherwise you are justing using whatever * happens to be in sr0). */ for(i=0,addr=base; i<count; i++,addr+=stride) for(j=0; j<loop; j++) fice(addr); mtsp(old_sr1, 1); } /* not yet ... fdc() needs to be implemented in cache.h ! void flush_datacache_range( unsigned int base, unsigned int end ) { register long offset,offset_add; offset_add = ( (1<<(cache_info.dc_conf.cc_block-1)) * cache_info.dc_conf.cc_line ) << 4; for (offset=base; offset<=end; offset+=offset_add) fdc(space,offset); fdc(space,end); } */ /* flushes code and data-cache */ void flush_all_caches(void) { flush_instruction_cache(); flush_data_cache(); flush_instruction_tlb(); flush_data_tlb(); asm volatile("sync"); asm volatile("syncdma"); asm volatile("sync"); } int get_cache_info(char *buffer) { char *p = buffer; p += sprintf(p, "I-cache\t\t: %ld KB\n", cache_info.ic_size/1024 ); p += sprintf(p, "D-cache\t\t: %ld KB (%s)%s\n", cache_info.dc_size/1024, (cache_info.dc_conf.cc_wt ? "WT":"WB"), (cache_info.dc_conf.cc_sh ? " - shared I/D":"") ); p += sprintf(p, "ITLB entries\t: %ld\n" "DTLB entries\t: %ld%s\n", cache_info.it_size, cache_info.dt_size, cache_info.dt_conf.tc_sh ? " - shared with ITLB":"" ); #ifndef __LP64__ /* BTLB - Block TLB */ if (btlb_info.max_size==0) { p += sprintf(p, "BTLB\t\t: not supported\n" ); } else { p += sprintf(p, "BTLB fixed\t: max. %d pages, pagesize=%d (%dMB)\n" "BTLB fix-entr.\t: %d instruction, %d data (%d combined)\n" "BTLB var-entr.\t: %d instruction, %d data (%d combined)\n", btlb_info.max_size, (int)4096, btlb_info.max_size>>8, btlb_info.fixed_range_info.num_i, btlb_info.fixed_range_info.num_d, btlb_info.fixed_range_info.num_comb, btlb_info.variable_range_info.num_i, btlb_info.variable_range_info.num_d, btlb_info.variable_range_info.num_comb ); } #endif return p - buffer; } void __init cache_init(void) { if(pdc_cache_info(&cache_info)<0) panic("cache_init: pdc_cache_info failed"); #if 0 printk("ic_size %lx dc_size %lx it_size %lx pdc_cache_info %d*long pdc_cache_cf %d\n", cache_info.ic_size, cache_info.dc_size, cache_info.it_size, sizeof (struct pdc_cache_info) / sizeof (long), sizeof (struct pdc_cache_cf) ); #endif #ifndef __LP64__ if(pdc_btlb_info(&btlb_info)<0) { memset(&btlb_info, 0, sizeof btlb_info); } #endif } |