Home | History | Annotate | Line # | Download | only in mips
cache_r10k.c revision 1.1
      1 /*	$NetBSD: cache_r10k.c,v 1.1 2003/10/05 11:10:25 tsutsui Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2003 KIYOHARA Takashi <kiyohara (at) kk.iij4u.or.jp>
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 /*
     28  * Copyright 2001 Wasabi Systems, Inc.
     29  * All rights reserved.
     30  *
     31  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     32  *
     33  * Redistribution and use in source and binary forms, with or without
     34  * modification, are permitted provided that the following conditions
     35  * are met:
     36  * 1. Redistributions of source code must retain the above copyright
     37  *    notice, this list of conditions and the following disclaimer.
     38  * 2. Redistributions in binary form must reproduce the above copyright
     39  *    notice, this list of conditions and the following disclaimer in the
     40  *    documentation and/or other materials provided with the distribution.
     41  * 3. All advertising materials mentioning features or use of this software
     42  *    must display the following acknowledgement:
     43  *	This product includes software developed for the NetBSD Project by
     44  *	Wasabi Systems, Inc.
     45  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     46  *    or promote products derived from this software without specific prior
     47  *    written permission.
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     51  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     52  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     53  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     54  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     55  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     56  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     57  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     58  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     59  * POSSIBILITY OF SUCH DAMAGE.
     60  */
     61 
     62 #include <sys/cdefs.h>
     63 
     64 #include <sys/param.h>
     65 
     66 #include <mips/cache.h>
     67 #include <mips/cache_r4k.h>
     68 #include <mips/cache_r5k.h>
     69 #include <mips/cache_r10k.h>
     70 #include <mips/locore.h>
     71 
     72 /*
     73  * Cache operations for R10000-style caches:
     74  *
     75  *	- 2-way set-associative
     76  *	- Write-back
     77  *	- Virtually indexed, physically tagged
     78  *
     79  */
     80 
     81 #define	round_line(x)		(((x) + 63) & ~63)
     82 #define	trunc_line(x)		((x) & ~63)
     83 
     84 __asm(".set mips3");
     85 
     86 void
     87 r10k_icache_sync_all_64(void)
     88 {
     89 	vaddr_t va = MIPS_PHYS_TO_KSEG0(0);
     90 	vaddr_t eva = va + mips_picache_size;
     91 
     92 	/*
     93 	 * Since we're hitting the whole thing, we don't have to
     94 	 * worry about the 2 different "ways".
     95 	 */
     96 
     97 	mips_dcache_wbinv_all();
     98 
     99 	__asm __volatile("sync");
    100 
    101 	while (va < eva) {
    102 		cache_r10k_op_32lines_64(va, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
    103 		va += (32 * 64);
    104 	}
    105 }
    106 
    107 void
    108 r10k_icache_sync_range_64(vaddr_t va, vsize_t size)
    109 {
    110 	vaddr_t eva = round_line(va + size);
    111 
    112 	va = trunc_line(va);
    113 
    114 	mips_dcache_wb_range(va, (eva - va));
    115 
    116 	__asm __volatile("sync");
    117 
    118 	while ((eva - va) >= (32 * 64)) {
    119 		cache_r10k_op_32lines_64(va, CACHE_R4K_I|CACHEOP_R4K_HIT_INV);
    120 		va += (32 * 64);
    121 	}
    122 
    123 	while (va < eva) {
    124 		cache_op_r4k_line(va, CACHE_R4K_I|CACHEOP_R4K_HIT_INV);
    125 		va += 64;
    126 	}
    127 }
    128 
    129 void
    130 r10k_icache_sync_range_index_64(vaddr_t va, vsize_t size)
    131 {
    132 	vaddr_t w2va, eva, orig_va;
    133 
    134 	orig_va = va;
    135 
    136 	eva = round_line(va + size);
    137 	va = trunc_line(va);
    138 
    139 	mips_dcache_wbinv_range_index(va, (eva - va));
    140 
    141 	__asm __volatile("sync");
    142 
    143 	/*
    144 	 * Since we're doing Index ops, we expect to not be able
    145 	 * to access the address we've been given.  So, get the
    146 	 * bits that determine the cache index, and make a KSEG0
    147 	 * address out of them.
    148 	 */
    149 	va = MIPS_PHYS_TO_KSEG0(orig_va & mips_picache_way_mask);
    150 
    151 	eva = round_line(va + size);
    152 	va = trunc_line(va);
    153 	w2va = va + mips_picache_way_size;
    154 
    155 	while ((eva - va) >= (16 * 64)) {
    156 		cache_r10k_op_16lines_64_2way(va, w2va,
    157 		    CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
    158 		va   += (16 * 64);
    159 		w2va += (16 * 64);
    160 	}
    161 
    162 	while (va < eva) {
    163 		cache_op_r4k_line(  va, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
    164 		cache_op_r4k_line(w2va, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
    165 		va   += 64;
    166 		w2va += 64;
    167 	}
    168 }
    169 
    170 void
    171 r10k_pdcache_wb_range(vaddr_t va, vsize_t size)
    172 {
    173 	/* R10000 processor does not support */
    174 }
    175 
    176