| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cpufunc.c,v 1.5.4.1 2019/09/22 12:27:22 martin Exp $ */ | | 1 | /* $NetBSD: cpufunc.c,v 1.5.4.2 2021/01/01 12:38:49 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org> | | 4 | * Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -19,32 +19,35 @@ | | | @@ -19,32 +19,35 @@ |
19 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | | 19 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
20 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | 20 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
24 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | | 24 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
25 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include "opt_multiprocessor.h" | | 29 | #include "opt_multiprocessor.h" |
30 | | | 30 | |
31 | #include <sys/cdefs.h> | | 31 | #include <sys/cdefs.h> |
32 | __KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.5.4.1 2019/09/22 12:27:22 martin Exp $"); | | 32 | __KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.5.4.2 2021/01/01 12:38:49 martin Exp $"); |
33 | | | 33 | |
34 | #include <sys/param.h> | | 34 | #include <sys/param.h> |
35 | #include <sys/types.h> | | 35 | #include <sys/types.h> |
36 | #include <sys/kmem.h> | | 36 | #include <sys/kmem.h> |
37 | | | 37 | |
| | | 38 | #include <uvm/uvm.h> |
| | | 39 | #include <uvm/uvm_page.h> |
| | | 40 | |
38 | #include <aarch64/cpu.h> | | 41 | #include <aarch64/cpu.h> |
39 | #include <aarch64/cpufunc.h> | | 42 | #include <aarch64/cpufunc.h> |
40 | | | 43 | |
41 | u_int cputype; /* compat arm */ | | 44 | u_int cputype; /* compat arm */ |
42 | u_int arm_dcache_align; /* compat arm */ | | 45 | u_int arm_dcache_align; /* compat arm */ |
43 | u_int arm_dcache_align_mask; /* compat arm */ | | 46 | u_int arm_dcache_align_mask; /* compat arm */ |
44 | u_int arm_dcache_maxline; | | 47 | u_int arm_dcache_maxline; |
45 | | | 48 | |
46 | u_int aarch64_cache_vindexsize; | | 49 | u_int aarch64_cache_vindexsize; |
47 | u_int aarch64_cache_prefer_mask; | | 50 | u_int aarch64_cache_prefer_mask; |
48 | | | 51 | |
49 | /* cache info per cluster. the same cluster has the same cache configuration? */ | | 52 | /* cache info per cluster. the same cluster has the same cache configuration? */ |
50 | #define MAXCPUPACKAGES MAXCPUS /* maximum of ci->ci_package_id */ | | 53 | #define MAXCPUPACKAGES MAXCPUS /* maximum of ci->ci_package_id */ |
| @@ -81,26 +84,27 @@ extract_cacheunit(int level, bool insn, | | | @@ -81,26 +84,27 @@ extract_cacheunit(int level, bool insn, |
81 | cunit->cache_size = cunit->cache_way_size * cunit->cache_ways; | | 84 | cunit->cache_size = cunit->cache_way_size * cunit->cache_ways; |
82 | | | 85 | |
83 | /* cache purging */ | | 86 | /* cache purging */ |
84 | cunit->cache_purging = (ccsidr & CCSIDR_WT) ? CACHE_PURGING_WT : 0; | | 87 | cunit->cache_purging = (ccsidr & CCSIDR_WT) ? CACHE_PURGING_WT : 0; |
85 | cunit->cache_purging |= (ccsidr & CCSIDR_WB) ? CACHE_PURGING_WB : 0; | | 88 | cunit->cache_purging |= (ccsidr & CCSIDR_WB) ? CACHE_PURGING_WB : 0; |
86 | cunit->cache_purging |= (ccsidr & CCSIDR_RA) ? CACHE_PURGING_RA : 0; | | 89 | cunit->cache_purging |= (ccsidr & CCSIDR_RA) ? CACHE_PURGING_RA : 0; |
87 | cunit->cache_purging |= (ccsidr & CCSIDR_WA) ? CACHE_PURGING_WA : 0; | | 90 | cunit->cache_purging |= (ccsidr & CCSIDR_WA) ? CACHE_PURGING_WA : 0; |
88 | } | | 91 | } |
89 | | | 92 | |
90 | void | | 93 | void |
91 | aarch64_getcacheinfo(void) | | 94 | aarch64_getcacheinfo(void) |
92 | { | | 95 | { |
93 | uint32_t clidr, ctr; | | 96 | uint32_t clidr, ctr; |
| | | 97 | u_int vindexsize; |
94 | int level, cachetype; | | 98 | int level, cachetype; |
95 | struct aarch64_cache_info *cinfo; | | 99 | struct aarch64_cache_info *cinfo; |
96 | | | 100 | |
97 | if (cputype == 0) | | 101 | if (cputype == 0) |
98 | cputype = aarch64_cpuid(); | | 102 | cputype = aarch64_cpuid(); |
99 | | | 103 | |
100 | /* already extract about this cluster? */ | | 104 | /* already extract about this cluster? */ |
101 | KASSERT(curcpu()->ci_package_id < MAXCPUPACKAGES); | | 105 | KASSERT(curcpu()->ci_package_id < MAXCPUPACKAGES); |
102 | cinfo = aarch64_cacheinfo[curcpu()->ci_package_id]; | | 106 | cinfo = aarch64_cacheinfo[curcpu()->ci_package_id]; |
103 | if (cinfo != NULL) { | | 107 | if (cinfo != NULL) { |
104 | curcpu()->ci_cacheinfo = cinfo; | | 108 | curcpu()->ci_cacheinfo = cinfo; |
105 | return; | | 109 | return; |
106 | } | | 110 | } |
| @@ -191,34 +195,40 @@ aarch64_getcacheinfo(void) | | | @@ -191,34 +195,40 @@ aarch64_getcacheinfo(void) |
191 | /* | | 195 | /* |
192 | * L1 insn cachetype is CTR_EL0:L1IP, | | 196 | * L1 insn cachetype is CTR_EL0:L1IP, |
193 | * all other cachetype is PIPT. | | 197 | * all other cachetype is PIPT. |
194 | */ | | 198 | */ |
195 | cachetype = CACHE_TYPE_PIPT; | | 199 | cachetype = CACHE_TYPE_PIPT; |
196 | } | | 200 | } |
197 | | | 201 | |
198 | /* calculate L1 icache virtual index size */ | | 202 | /* calculate L1 icache virtual index size */ |
199 | if (((cinfo[0].icache.cache_type == CACHE_TYPE_VIVT) || | | 203 | if (((cinfo[0].icache.cache_type == CACHE_TYPE_VIVT) || |
200 | (cinfo[0].icache.cache_type == CACHE_TYPE_VIPT)) && | | 204 | (cinfo[0].icache.cache_type == CACHE_TYPE_VIPT)) && |
201 | ((cinfo[0].cacheable == CACHE_CACHEABLE_ICACHE) || | | 205 | ((cinfo[0].cacheable == CACHE_CACHEABLE_ICACHE) || |
202 | (cinfo[0].cacheable == CACHE_CACHEABLE_IDCACHE))) { | | 206 | (cinfo[0].cacheable == CACHE_CACHEABLE_IDCACHE))) { |
203 | | | 207 | |
204 | aarch64_cache_vindexsize = | | 208 | vindexsize = |
205 | cinfo[0].icache.cache_size / | | 209 | cinfo[0].icache.cache_size / |
206 | cinfo[0].icache.cache_ways; | | 210 | cinfo[0].icache.cache_ways; |
207 | | | 211 | |
208 | KASSERT(aarch64_cache_vindexsize != 0); | | 212 | KASSERT(vindexsize != 0); |
209 | aarch64_cache_prefer_mask = aarch64_cache_vindexsize - 1; | | | |
210 | } else { | | 213 | } else { |
211 | aarch64_cache_vindexsize = 0; | | 214 | vindexsize = 0; |
| | | 215 | } |
| | | 216 | |
| | | 217 | if (vindexsize > aarch64_cache_vindexsize) { |
| | | 218 | aarch64_cache_vindexsize = vindexsize; |
| | | 219 | aarch64_cache_prefer_mask = vindexsize - 1; |
| | | 220 | if (uvm.page_init_done) |
| | | 221 | uvm_page_recolor(vindexsize / PAGE_SIZE); |
212 | } | | 222 | } |
213 | } | | 223 | } |
214 | | | 224 | |
215 | static int | | 225 | static int |
216 | prt_cache(device_t self, struct aarch64_cache_info *cinfo, int level) | | 226 | prt_cache(device_t self, struct aarch64_cache_info *cinfo, int level) |
217 | { | | 227 | { |
218 | struct aarch64_cache_unit *cunit; | | 228 | struct aarch64_cache_unit *cunit; |
219 | u_int purging; | | 229 | u_int purging; |
220 | int i; | | 230 | int i; |
221 | const char *cacheable, *cachetype; | | 231 | const char *cacheable, *cachetype; |
222 | | | 232 | |
223 | if (cinfo[level].cacheable == CACHE_CACHEABLE_NONE) | | 233 | if (cinfo[level].cacheable == CACHE_CACHEABLE_NONE) |
224 | return -1; | | 234 | return -1; |