3 * The President and Fellows of Harvard College. All rights reserved.
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by Harvard University.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by Aaron Brown and
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
46 * All rights reserved.
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
57 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
61 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
63 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
64 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
65 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
66 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 * from: @(#)cache.c 8.2 (Berkeley) 10/30/93
69 * from: NetBSD: cache.c,v 1.5 2000/12/06 01:47:50 mrg Exp
74 #include <sys/param.h>
75 #include <sys/systm.h>
77 #include <dev/ofw/openfirm.h>
79 #include <machine/cache.h>
80 #include <machine/tlb.h>
81 #include <machine/ver.h>
83 struct cacheinfo cache;
85 cache_enable_t *cache_enable;
86 cache_flush_t *cache_flush;
87 dcache_page_inval_t *dcache_page_inval;
88 icache_page_inval_t *icache_page_inval;
90 #define OF_GET(h, n, v) OF_getprop((h), (n), &(v), sizeof(v))
93 * Fill in the cache parameters using the cpu node.
96 cache_init(phandle_t node)
100 if (OF_GET(node, "icache-size", cache.ic_size) == -1 ||
101 OF_GET(node, "icache-line-size", cache.ic_linesize) == -1 ||
102 OF_GET(node, "icache-associativity", cache.ic_assoc) == -1 ||
103 OF_GET(node, "dcache-size", cache.dc_size) == -1 ||
104 OF_GET(node, "dcache-line-size", cache.dc_linesize) == -1 ||
105 OF_GET(node, "dcache-associativity", cache.dc_assoc) == -1 ||
106 OF_GET(node, "ecache-size", cache.ec_size) == -1 ||
107 OF_GET(node, "ecache-line-size", cache.ec_linesize) == -1 ||
108 OF_GET(node, "ecache-associativity", cache.ec_assoc) == -1)
109 panic("cache_init: could not retrieve cache parameters");
111 cache.ic_set = cache.ic_size / cache.ic_assoc;
112 cache.ic_l2set = ffs(cache.ic_set) - 1;
113 if ((cache.ic_set & ~(1UL << cache.ic_l2set)) != 0)
114 panic("cache_init: I$ set size not a power of 2");
115 cache.dc_l2size = ffs(cache.dc_size) - 1;
116 if ((cache.dc_size & ~(1UL << cache.dc_l2size)) != 0)
117 panic("cache_init: D$ size not a power of 2");
118 if (((cache.dc_size / cache.dc_assoc) / PAGE_SIZE) != DCACHE_COLORS)
119 panic("cache_init: too many D$ colors");
120 set = cache.ec_size / cache.ec_assoc;
121 cache.ec_l2set = ffs(set) - 1;
122 if ((set & ~(1UL << cache.ec_l2set)) != 0)
123 panic("cache_init: E$ set size not a power of 2");
125 if (cpu_impl >= CPU_IMPL_ULTRASPARCIII) {
126 cache_enable = cheetah_cache_enable;
127 cache_flush = cheetah_cache_flush;
128 dcache_page_inval = cheetah_dcache_page_inval;
129 icache_page_inval = cheetah_icache_page_inval;
130 tlb_flush_user = cheetah_tlb_flush_user;
132 cache_enable = spitfire_cache_enable;
133 cache_flush = spitfire_cache_flush;
134 dcache_page_inval = spitfire_dcache_page_inval;
135 icache_page_inval = spitfire_icache_page_inval;
136 tlb_flush_user = spitfire_tlb_flush_user;