cache_r10k.c revision 1.1 1 1.1 tsutsui /* $NetBSD: cache_r10k.c,v 1.1 2003/10/05 11:10:25 tsutsui Exp $ */
2 1.1 tsutsui
3 1.1 tsutsui /*
4 1.1 tsutsui * Copyright (c) 2003 KIYOHARA Takashi <kiyohara (at) kk.iij4u.or.jp>
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/cdefs.h>
63 1.1 tsutsui
64 1.1 tsutsui #include <sys/param.h>
65 1.1 tsutsui
66 1.1 tsutsui #include <mips/cache.h>
67 1.1 tsutsui #include <mips/cache_r4k.h>
68 1.1 tsutsui #include <mips/cache_r5k.h>
69 1.1 tsutsui #include <mips/cache_r10k.h>
70 1.1 tsutsui #include <mips/locore.h>
71 1.1 tsutsui
72 1.1 tsutsui /*
73 1.1 tsutsui * Cache operations for R10000-style caches:
74 1.1 tsutsui *
75 1.1 tsutsui * - 2-way set-associative
76 1.1 tsutsui * - Write-back
77 1.1 tsutsui * - Virtually indexed, physically tagged
78 1.1 tsutsui *
79 1.1 tsutsui */
80 1.1 tsutsui
81 1.1 tsutsui #define round_line(x) (((x) + 63) & ~63)
82 1.1 tsutsui #define trunc_line(x) ((x) & ~63)
83 1.1 tsutsui
84 1.1 tsutsui __asm(".set mips3");
85 1.1 tsutsui
86 1.1 tsutsui void
87 1.1 tsutsui r10k_icache_sync_all_64(void)
88 1.1 tsutsui {
89 1.1 tsutsui vaddr_t va = MIPS_PHYS_TO_KSEG0(0);
90 1.1 tsutsui vaddr_t eva = va + mips_picache_size;
91 1.1 tsutsui
92 1.1 tsutsui /*
93 1.1 tsutsui * Since we're hitting the whole thing, we don't have to
94 1.1 tsutsui * worry about the 2 different "ways".
95 1.1 tsutsui */
96 1.1 tsutsui
97 1.1 tsutsui mips_dcache_wbinv_all();
98 1.1 tsutsui
99 1.1 tsutsui __asm __volatile("sync");
100 1.1 tsutsui
101 1.1 tsutsui while (va < eva) {
102 1.1 tsutsui cache_r10k_op_32lines_64(va, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
103 1.1 tsutsui va += (32 * 64);
104 1.1 tsutsui }
105 1.1 tsutsui }
106 1.1 tsutsui
107 1.1 tsutsui void
108 1.1 tsutsui r10k_icache_sync_range_64(vaddr_t va, vsize_t size)
109 1.1 tsutsui {
110 1.1 tsutsui vaddr_t eva = round_line(va + size);
111 1.1 tsutsui
112 1.1 tsutsui va = trunc_line(va);
113 1.1 tsutsui
114 1.1 tsutsui mips_dcache_wb_range(va, (eva - va));
115 1.1 tsutsui
116 1.1 tsutsui __asm __volatile("sync");
117 1.1 tsutsui
118 1.1 tsutsui while ((eva - va) >= (32 * 64)) {
119 1.1 tsutsui cache_r10k_op_32lines_64(va, CACHE_R4K_I|CACHEOP_R4K_HIT_INV);
120 1.1 tsutsui va += (32 * 64);
121 1.1 tsutsui }
122 1.1 tsutsui
123 1.1 tsutsui while (va < eva) {
124 1.1 tsutsui cache_op_r4k_line(va, CACHE_R4K_I|CACHEOP_R4K_HIT_INV);
125 1.1 tsutsui va += 64;
126 1.1 tsutsui }
127 1.1 tsutsui }
128 1.1 tsutsui
129 1.1 tsutsui void
130 1.1 tsutsui r10k_icache_sync_range_index_64(vaddr_t va, vsize_t size)
131 1.1 tsutsui {
132 1.1 tsutsui vaddr_t w2va, eva, orig_va;
133 1.1 tsutsui
134 1.1 tsutsui orig_va = va;
135 1.1 tsutsui
136 1.1 tsutsui eva = round_line(va + size);
137 1.1 tsutsui va = trunc_line(va);
138 1.1 tsutsui
139 1.1 tsutsui mips_dcache_wbinv_range_index(va, (eva - va));
140 1.1 tsutsui
141 1.1 tsutsui __asm __volatile("sync");
142 1.1 tsutsui
143 1.1 tsutsui /*
144 1.1 tsutsui * Since we're doing Index ops, we expect to not be able
145 1.1 tsutsui * to access the address we've been given. So, get the
146 1.1 tsutsui * bits that determine the cache index, and make a KSEG0
147 1.1 tsutsui * address out of them.
148 1.1 tsutsui */
149 1.1 tsutsui va = MIPS_PHYS_TO_KSEG0(orig_va & mips_picache_way_mask);
150 1.1 tsutsui
151 1.1 tsutsui eva = round_line(va + size);
152 1.1 tsutsui va = trunc_line(va);
153 1.1 tsutsui w2va = va + mips_picache_way_size;
154 1.1 tsutsui
155 1.1 tsutsui while ((eva - va) >= (16 * 64)) {
156 1.1 tsutsui cache_r10k_op_16lines_64_2way(va, w2va,
157 1.1 tsutsui CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
158 1.1 tsutsui va += (16 * 64);
159 1.1 tsutsui w2va += (16 * 64);
160 1.1 tsutsui }
161 1.1 tsutsui
162 1.1 tsutsui while (va < eva) {
163 1.1 tsutsui cache_op_r4k_line( va, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
164 1.1 tsutsui cache_op_r4k_line(w2va, CACHE_R4K_I|CACHEOP_R4K_INDEX_INV);
165 1.1 tsutsui va += 64;
166 1.1 tsutsui w2va += 64;
167 1.1 tsutsui }
168 1.1 tsutsui }
169 1.1 tsutsui
170 1.1 tsutsui void
171 1.1 tsutsui r10k_pdcache_wb_range(vaddr_t va, vsize_t size)
172 1.1 tsutsui {
173 1.1 tsutsui /* R10000 processor does not support */
174 1.1 tsutsui }
175 1.1 tsutsui
176