]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/sparc64/sparc64/cache.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / sparc64 / sparc64 / cache.c
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  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  *
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
27  *      Harvard University.
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.
31  *
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
42  * SUCH DAMAGE.
43  */
44 /*-
45  * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
46  * All rights reserved.
47  *
48  * Redistribution and use in source and binary forms, with or without
49  * modification, are permitted provided that the following conditions
50  * are met:
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.
56  *
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.
67  *
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
70  */
71
72 #include <sys/cdefs.h>
73 __FBSDID("$FreeBSD$");
74
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/pcpu.h>
78
79 #include <dev/ofw/openfirm.h>
80
81 #include <machine/cache.h>
82 #include <machine/tlb.h>
83 #include <machine/ver.h>
84
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;
89
90 #define OF_GET(h, n, v) OF_getprop((h), (n), &(v), sizeof(v))
91
92 /*
93  * Fill in the cache parameters using the cpu node.
94  */
95 void
96 cache_init(struct pcpu *pcpu)
97 {
98         u_long set;
99
100         if (OF_GET(pcpu->pc_node, "icache-size",
101             pcpu->pc_cache.ic_size) == -1 ||
102             OF_GET(pcpu->pc_node, "icache-line-size",
103             pcpu->pc_cache.ic_linesize) == -1 ||
104             OF_GET(pcpu->pc_node, "icache-associativity",
105             pcpu->pc_cache.ic_assoc) == -1 ||
106             OF_GET(pcpu->pc_node, "dcache-size",
107             pcpu->pc_cache.dc_size) == -1 ||
108             OF_GET(pcpu->pc_node, "dcache-line-size",
109             pcpu->pc_cache.dc_linesize) == -1 ||
110             OF_GET(pcpu->pc_node, "dcache-associativity",
111             pcpu->pc_cache.dc_assoc) == -1 ||
112             OF_GET(pcpu->pc_node, "ecache-size",
113             pcpu->pc_cache.ec_size) == -1 ||
114             OF_GET(pcpu->pc_node, "ecache-line-size",
115             pcpu->pc_cache.ec_linesize) == -1 ||
116             OF_GET(pcpu->pc_node, "ecache-associativity",
117             pcpu->pc_cache.ec_assoc) == -1)
118                 panic("cache_init: could not retrieve cache parameters");
119
120         set = pcpu->pc_cache.ic_size / pcpu->pc_cache.ic_assoc;
121         if ((set & ~(1UL << (ffs(set) - 1))) != 0)
122                 panic("cache_init: I$ set size not a power of 2");
123         if ((pcpu->pc_cache.dc_size &
124             ~(1UL << (ffs(pcpu->pc_cache.dc_size) - 1))) != 0)
125                 panic("cache_init: D$ size not a power of 2");
126         if (((pcpu->pc_cache.dc_size / pcpu->pc_cache.dc_assoc) /
127             PAGE_SIZE) != DCACHE_COLORS)
128                 panic("cache_init: too many D$ colors");
129         set = pcpu->pc_cache.ec_size / pcpu->pc_cache.ec_assoc;
130         if ((set & ~(1UL << (ffs(set) - 1))) != 0)
131                 panic("cache_init: E$ set size not a power of 2");
132
133         if (cpu_impl >= CPU_IMPL_ULTRASPARCIII) {
134                 cache_enable = cheetah_cache_enable;
135                 cache_flush = cheetah_cache_flush;
136                 dcache_page_inval = cheetah_dcache_page_inval;
137                 icache_page_inval = cheetah_icache_page_inval;
138                 tlb_flush_nonlocked = cheetah_tlb_flush_nonlocked;
139                 tlb_flush_user = cheetah_tlb_flush_user;
140         } else {
141                 cache_enable = spitfire_cache_enable;
142                 cache_flush = spitfire_cache_flush;
143                 dcache_page_inval = spitfire_dcache_page_inval;
144                 icache_page_inval = spitfire_icache_page_inval;
145                 tlb_flush_nonlocked = spitfire_tlb_flush_nonlocked;
146                 tlb_flush_user = spitfire_tlb_flush_user;
147         }
148 }