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