Home | History | Annotate | Line # | Download | only in mips
cache_r10k.c revision 1.2
      1  1.1  tsutsui /*	$NetBSD: cache_r10k.c,v 1.2 2003/11/01 04:42:56 shin Exp $	*/
      2  1.1  tsutsui 
      3  1.2     shin /*-
      4  1.2     shin  * Copyright (c) 2003 Takao Shinohara.
      5  1.1  tsutsui  *
      6  1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      7  1.1  tsutsui  * modification, are permitted provided that the following conditions
      8  1.1  tsutsui  * are met:
      9  1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     10  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     11  1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     14  1.1  tsutsui  *
     15  1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.1  tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  1.1  tsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  1.1  tsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  1.1  tsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  1.1  tsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  1.1  tsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  1.1  tsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  1.1  tsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  1.1  tsutsui  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  1.1  tsutsui  */
     26  1.1  tsutsui 
     27  1.1  tsutsui /*
     28  1.1  tsutsui  * Copyright 2001 Wasabi Systems, Inc.
     29  1.1  tsutsui  * All rights reserved.
     30  1.1  tsutsui  *
     31  1.1  tsutsui  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     32  1.1  tsutsui  *
     33  1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
     34  1.1  tsutsui  * modification, are permitted provided that the following conditions
     35  1.1  tsutsui  * are met:
     36  1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     37  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     38  1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     39  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     40  1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     41  1.1  tsutsui  * 3. All advertising materials mentioning features or use of this software
     42  1.1  tsutsui  *    must display the following acknowledgement:
     43  1.1  tsutsui  *	This product includes software developed for the NetBSD Project by
     44  1.1  tsutsui  *	Wasabi Systems, Inc.
     45  1.1  tsutsui  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     46  1.1  tsutsui  *    or promote products derived from this software without specific prior
     47  1.1  tsutsui  *    written permission.
     48  1.1  tsutsui  *
     49  1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     50  1.1  tsutsui  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     51  1.1  tsutsui  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     52  1.1  tsutsui  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     53  1.1  tsutsui  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     54  1.1  tsutsui  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     55  1.1  tsutsui  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     56  1.1  tsutsui  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     57  1.1  tsutsui  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     58  1.1  tsutsui  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     59  1.1  tsutsui  * POSSIBILITY OF SUCH DAMAGE.
     60  1.1  tsutsui  */
     61  1.1  tsutsui 
     62  1.1  tsutsui #include <sys/param.h>
     63  1.1  tsutsui 
     64  1.1  tsutsui #include <mips/cache.h>
     65  1.1  tsutsui #include <mips/cache_r4k.h>
     66  1.1  tsutsui #include <mips/cache_r10k.h>
     67  1.1  tsutsui 
     68  1.1  tsutsui /*
     69  1.1  tsutsui  * Cache operations for R10000-style caches:
     70  1.1  tsutsui  *
     71  1.2     shin  *	2-way, write-back
     72  1.2     shin  *	primary cache: virtual index/physical tag
     73  1.2     shin  *	secondary cache: physical index/physical tag
     74  1.1  tsutsui  */
     75  1.1  tsutsui 
     76  1.2     shin __asm(".set mips3");
     77  1.1  tsutsui 
     78  1.2     shin #define	round_line(x)	(((x) + 64 - 1) & ~(64 - 1))
     79  1.2     shin #define	trunc_line(x)	((x) & ~(64 - 1))
     80  1.1  tsutsui 
     81  1.1  tsutsui void
     82  1.2     shin r10k_icache_sync_all(void)
     83  1.1  tsutsui {
     84  1.1  tsutsui 	vaddr_t va = MIPS_PHYS_TO_KSEG0(0);
     85  1.2     shin 	vaddr_t eva = va + mips_picache_way_size;
     86  1.1  tsutsui 
     87  1.1  tsutsui 	mips_dcache_wbinv_all();
     88  1.1  tsutsui 
     89  1.1  tsutsui 	__asm __volatile("sync");
     90  1.1  tsutsui 
     91  1.1  tsutsui 	while (va < eva) {
     92  1.2     shin 		cache_op_r4k_line(va+0, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
     93  1.2     shin 		cache_op_r4k_line(va+1, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
     94  1.2     shin 		va += 64;
     95  1.1  tsutsui 	}
     96  1.1  tsutsui }
     97  1.1  tsutsui 
     98  1.1  tsutsui void
     99  1.2     shin r10k_icache_sync_range(vaddr_t va, vsize_t size)
    100  1.1  tsutsui {
    101  1.1  tsutsui 	vaddr_t eva = round_line(va + size);
    102  1.1  tsutsui 
    103  1.1  tsutsui 	va = trunc_line(va);
    104  1.1  tsutsui 
    105  1.1  tsutsui 	mips_dcache_wb_range(va, (eva - va));
    106  1.1  tsutsui 
    107  1.1  tsutsui 	__asm __volatile("sync");
    108  1.1  tsutsui 
    109  1.1  tsutsui 	while (va < eva) {
    110  1.1  tsutsui 		cache_op_r4k_line(va, CACHE_R4K_I|CACHEOP_R4K_HIT_INV);
    111  1.1  tsutsui 		va += 64;
    112  1.1  tsutsui 	}
    113  1.1  tsutsui }
    114  1.1  tsutsui 
    115  1.1  tsutsui void
    116  1.2     shin r10k_icache_sync_range_index(vaddr_t va, vsize_t size)
    117  1.1  tsutsui {
    118  1.2     shin 	vaddr_t eva, orig_va;
    119  1.1  tsutsui 
    120  1.1  tsutsui 	orig_va = va;
    121  1.1  tsutsui 
    122  1.1  tsutsui 	eva = round_line(va + size);
    123  1.1  tsutsui 	va = trunc_line(va);
    124  1.1  tsutsui 
    125  1.1  tsutsui 	mips_dcache_wbinv_range_index(va, (eva - va));
    126  1.1  tsutsui 
    127  1.1  tsutsui 	__asm __volatile("sync");
    128  1.1  tsutsui 
    129  1.1  tsutsui 	/*
    130  1.1  tsutsui 	 * Since we're doing Index ops, we expect to not be able
    131  1.1  tsutsui 	 * to access the address we've been given.  So, get the
    132  1.1  tsutsui 	 * bits that determine the cache index, and make a KSEG0
    133  1.1  tsutsui 	 * address out of them.
    134  1.1  tsutsui 	 */
    135  1.1  tsutsui 	va = MIPS_PHYS_TO_KSEG0(orig_va & mips_picache_way_mask);
    136  1.1  tsutsui 
    137  1.1  tsutsui 	eva = round_line(va + size);
    138  1.1  tsutsui 	va = trunc_line(va);
    139  1.1  tsutsui 
    140  1.2     shin 	while (va < eva) {
    141  1.2     shin 		cache_op_r4k_line(va+0, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
    142  1.2     shin 		cache_op_r4k_line(va+1, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
    143  1.2     shin 		va += 64;
    144  1.2     shin 	}
    145  1.2     shin }
    146  1.2     shin 
    147  1.2     shin #undef round_line
    148  1.2     shin #undef trunc_line
    149  1.2     shin 
    150  1.2     shin #define	round_line(x)	(((x) + 32 - 1) & ~(32 - 1))
    151  1.2     shin #define	trunc_line(x)	((x) & ~(32 - 1))
    152  1.2     shin 
    153  1.2     shin void
    154  1.2     shin r10k_pdcache_wbinv_all(void)
    155  1.2     shin {
    156  1.2     shin 	vaddr_t va = MIPS_PHYS_TO_KSEG0(0);
    157  1.2     shin 	vaddr_t eva = va + mips_pdcache_way_size;
    158  1.2     shin 
    159  1.2     shin 	while (va < eva) {
    160  1.2     shin 		cache_op_r4k_line(va+0, CACHE_R4K_D|CACHEOP_R4K_INDEX_WB_INV);
    161  1.2     shin 		cache_op_r4k_line(va+1, CACHE_R4K_D|CACHEOP_R4K_INDEX_WB_INV);
    162  1.2     shin 		va += 32;
    163  1.2     shin 	}
    164  1.2     shin }
    165  1.2     shin 
    166  1.2     shin void
    167  1.2     shin r10k_pdcache_wbinv_range(vaddr_t va, vsize_t size)
    168  1.2     shin {
    169  1.2     shin 	vaddr_t eva = round_line(va + size);
    170  1.2     shin 
    171  1.2     shin 	va = trunc_line(va);
    172  1.2     shin 
    173  1.2     shin 	while (va < eva) {
    174  1.2     shin 		cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_WB_INV);
    175  1.2     shin 		va += 32;
    176  1.2     shin 	}
    177  1.2     shin }
    178  1.2     shin 
    179  1.2     shin void
    180  1.2     shin r10k_pdcache_wbinv_range_index(vaddr_t va, vsize_t size)
    181  1.2     shin {
    182  1.2     shin 	vaddr_t eva;
    183  1.2     shin 
    184  1.2     shin 	/*
    185  1.2     shin 	 * Since we're doing Index ops, we expect to not be able
    186  1.2     shin 	 * to access the address we've been given.  So, get the
    187  1.2     shin 	 * bits that determine the cache index, and make a KSEG0
    188  1.2     shin 	 * address out of them.
    189  1.2     shin 	 */
    190  1.2     shin 	va = MIPS_PHYS_TO_KSEG0(va & mips_pdcache_way_mask);
    191  1.2     shin 
    192  1.2     shin 	eva = round_line(va + size);
    193  1.2     shin 	va = trunc_line(va);
    194  1.2     shin 
    195  1.2     shin 	while (va < eva) {
    196  1.2     shin 		cache_op_r4k_line(va+0, CACHE_R4K_D|CACHEOP_R4K_INDEX_WB_INV);
    197  1.2     shin 		cache_op_r4k_line(va+1, CACHE_R4K_D|CACHEOP_R4K_INDEX_WB_INV);
    198  1.2     shin 		va += 32;
    199  1.1  tsutsui 	}
    200  1.2     shin }
    201  1.2     shin 
    202  1.2     shin void
    203  1.2     shin r10k_pdcache_inv_range(vaddr_t va, vsize_t size)
    204  1.2     shin {
    205  1.2     shin 	vaddr_t eva = round_line(va + size);
    206  1.2     shin 
    207  1.2     shin 	va = trunc_line(va);
    208  1.1  tsutsui 
    209  1.1  tsutsui 	while (va < eva) {
    210  1.2     shin 		cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_INV);
    211  1.2     shin 		va += 32;
    212  1.1  tsutsui 	}
    213  1.1  tsutsui }
    214  1.1  tsutsui 
    215  1.1  tsutsui void
    216  1.1  tsutsui r10k_pdcache_wb_range(vaddr_t va, vsize_t size)
    217  1.1  tsutsui {
    218  1.2     shin 	vaddr_t eva = round_line(va + size);
    219  1.2     shin 
    220  1.2     shin 	va = trunc_line(va);
    221  1.2     shin 
    222  1.2     shin 	while (va < eva) {
    223  1.2     shin 		/* R10000 does not support HitWriteBack operation */
    224  1.2     shin 		cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_WB_INV);
    225  1.2     shin 		va += 32;
    226  1.2     shin 	}
    227  1.2     shin }
    228  1.2     shin 
    229  1.2     shin #undef round_line
    230  1.2     shin #undef trunc_line
    231  1.2     shin 
    232  1.2     shin #define	round_line(x)	(((x) + mips_sdcache_line_size - 1) & ~(mips_sdcache_line_size - 1))
    233  1.2     shin #define	trunc_line(x)	((x) & ~(mips_sdcache_line_size - 1))
    234  1.2     shin 
    235  1.2     shin void
    236  1.2     shin r10k_sdcache_wbinv_all(void)
    237  1.2     shin {
    238  1.2     shin 	vaddr_t va = MIPS_PHYS_TO_KSEG0(0);
    239  1.2     shin 	vaddr_t eva = va + mips_sdcache_way_size;
    240  1.2     shin 	int line_size = mips_sdcache_line_size;
    241  1.2     shin 
    242  1.2     shin 	while (va < eva) {
    243  1.2     shin 		cache_op_r4k_line(va+0, CACHE_R4K_SD|CACHEOP_R4K_INDEX_WB_INV);
    244  1.2     shin 		cache_op_r4k_line(va+1, CACHE_R4K_SD|CACHEOP_R4K_INDEX_WB_INV);
    245  1.2     shin 		va += line_size;
    246  1.2     shin 	}
    247  1.2     shin }
    248  1.2     shin 
    249  1.2     shin void
    250  1.2     shin r10k_sdcache_wbinv_range(vaddr_t va, vsize_t size)
    251  1.2     shin {
    252  1.2     shin 	vaddr_t eva = round_line(va + size);
    253  1.2     shin 	int line_size = mips_sdcache_line_size;
    254  1.2     shin 
    255  1.2     shin 	va = trunc_line(va);
    256  1.2     shin 
    257  1.2     shin 	while (va < eva) {
    258  1.2     shin 		cache_op_r4k_line(va, CACHE_R4K_SD|CACHEOP_R4K_HIT_WB_INV);
    259  1.2     shin 		va += line_size;
    260  1.2     shin 	}
    261  1.2     shin }
    262  1.2     shin 
    263  1.2     shin void
    264  1.2     shin r10k_sdcache_wbinv_range_index(vaddr_t va, vsize_t size)
    265  1.2     shin {
    266  1.2     shin 	vaddr_t eva;
    267  1.2     shin 	int line_size = mips_sdcache_line_size;
    268  1.2     shin 
    269  1.2     shin 	/*
    270  1.2     shin 	 * Since we're doing Index ops, we expect to not be able
    271  1.2     shin 	 * to access the address we've been given.  So, get the
    272  1.2     shin 	 * bits that determine the cache index, and make a KSEG0
    273  1.2     shin 	 * address out of them.
    274  1.2     shin 	 */
    275  1.2     shin 	va = MIPS_PHYS_TO_KSEG0(va & mips_sdcache_way_mask);
    276  1.2     shin 
    277  1.2     shin 	eva = round_line(va + size);
    278  1.2     shin 	va = trunc_line(va);
    279  1.2     shin 
    280  1.2     shin 	while (va < eva) {
    281  1.2     shin 		cache_op_r4k_line(va+0, CACHE_R4K_SD|CACHEOP_R4K_INDEX_WB_INV);
    282  1.2     shin 		cache_op_r4k_line(va+1, CACHE_R4K_SD|CACHEOP_R4K_INDEX_WB_INV);
    283  1.2     shin 		va += line_size;
    284  1.2     shin 	}
    285  1.2     shin }
    286  1.2     shin 
    287  1.2     shin void
    288  1.2     shin r10k_sdcache_inv_range(vaddr_t va, vsize_t size)
    289  1.2     shin {
    290  1.2     shin 	vaddr_t eva = round_line(va + size);
    291  1.2     shin 	int line_size = mips_sdcache_line_size;
    292  1.2     shin 
    293  1.2     shin 	va = trunc_line(va);
    294  1.2     shin 
    295  1.2     shin 	while (va < eva) {
    296  1.2     shin 		cache_op_r4k_line(va, CACHE_R4K_SD|CACHEOP_R4K_HIT_INV);
    297  1.2     shin 		va += line_size;
    298  1.2     shin 	}
    299  1.2     shin }
    300  1.2     shin 
    301  1.2     shin void
    302  1.2     shin r10k_sdcache_wb_range(vaddr_t va, vsize_t size)
    303  1.2     shin {
    304  1.2     shin 	vaddr_t eva = round_line(va + size);
    305  1.2     shin 	int line_size = mips_sdcache_line_size;
    306  1.2     shin 
    307  1.2     shin 	va = trunc_line(va);
    308  1.2     shin 
    309  1.2     shin 	while (va < eva) {
    310  1.2     shin 		/* R10000 does not support HitWriteBack operation */
    311  1.2     shin 		cache_op_r4k_line(va, CACHE_R4K_SD|CACHEOP_R4K_HIT_WB_INV);
    312  1.2     shin 		va += line_size;
    313  1.2     shin 	}
    314  1.1  tsutsui }
    315  1.1  tsutsui 
    316  1.2     shin #undef round_line
    317  1.2     shin #undef trunc_line
    318