]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/sparc64/sparc64/cheetah.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / sparc64 / sparc64 / cheetah.c
1 /*-
2  * Copyright (c) 2003 Jake Burkholder.
3  * Copyright (c) 2005, 2008 Marius Strobl <marius@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include "opt_pmap.h"
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/lock.h>
36 #include <sys/mutex.h>
37 #include <sys/smp.h>
38
39 #include <vm/vm.h>
40 #include <vm/pmap.h>
41
42 #include <machine/cache.h>
43 #include <machine/cpu.h>
44 #include <machine/cpufunc.h>
45 #include <machine/dcr.h>
46 #include <machine/lsu.h>
47 #include <machine/smp.h>
48 #include <machine/tlb.h>
49 #include <machine/ver.h>
50 #include <machine/vmparam.h>
51
52 /* A FLUSH is required after changing LSU_IC (the address is ignored). */
53 #define CHEETAH_FLUSH_LSU_IC()  __asm __volatile("flush %%g0" : :)
54
55 #define CHEETAH_ICACHE_TAG_LOWER        0x30
56
57 /*
58  * CPU-specific initialization
59  */
60 void
61 cheetah_init(void)
62 {
63         register_t s;
64
65         /*
66          * Disable interrupts for safety, this shouldn't be actually
67          * necessary though.
68          */
69         s = intr_disable();
70
71         /*
72          * Ensure DCR_IFPOE is disabled as long as we haven't implemented
73          * support for it (if ever) as most if not all firmware versions
74          * apparently turn it on.  Not making use of DCR_IFPOE should also
75          * avoid Cheetah erratum #109.
76          */
77         wr(asr18, rd(asr18) & ~DCR_IFPOE, 0);
78
79         /* Ensure the TSB Extension Registers hold 0 as TSB_Base. */
80
81         stxa(AA_DMMU_TSB_PEXT_REG, ASI_DMMU, 0);
82         stxa(AA_IMMU_TSB_PEXT_REG, ASI_IMMU, 0);
83         membar(Sync);
84
85         stxa(AA_DMMU_TSB_SEXT_REG, ASI_DMMU, 0);
86         /*
87          * NB: the secondary context was removed from the iMMU.
88          */
89         membar(Sync);
90
91         stxa(AA_DMMU_TSB_NEXT_REG, ASI_DMMU, 0);
92         stxa(AA_IMMU_TSB_NEXT_REG, ASI_IMMU, 0);
93         membar(Sync);
94
95         /*
96          * Ensure that the dt512_0 is set to hold 8k pages for all three
97          * contexts and configure the dt512_1 to hold 4MB pages for them
98          * (e.g. for direct mappings).
99          * NB: according to documentation, this requires a contex demap
100          * _before_ changing the corresponding page size, but we hardly
101          * can flush our locked pages here, so we use a demap all instead.
102          */
103         stxa(TLB_DEMAP_ALL, ASI_DMMU_DEMAP, 0);
104         membar(Sync);
105         stxa(AA_DMMU_PCXR, ASI_DMMU,
106             (TS_8K << TLB_PCXR_N_PGSZ0_SHIFT) |
107             (TS_4M << TLB_PCXR_N_PGSZ1_SHIFT) |
108             (TS_8K << TLB_PCXR_P_PGSZ0_SHIFT) |
109             (TS_4M << TLB_PCXR_P_PGSZ1_SHIFT));
110         stxa(AA_DMMU_SCXR, ASI_DMMU,
111             (TS_8K << TLB_SCXR_S_PGSZ0_SHIFT) |
112             (TS_4M << TLB_SCXR_S_PGSZ1_SHIFT));
113         flush(KERNBASE);
114
115         intr_restore(s);
116 }
117
118 /*
119  * Enable level 1 caches.
120  */
121 void
122 cheetah_cache_enable(void)
123 {
124         u_long lsu;
125
126         lsu = ldxa(0, ASI_LSU_CTL_REG);
127         if (cpu_impl == CPU_IMPL_ULTRASPARCIII) {
128                 /* Disable P$ due to Cheetah erratum #18. */
129                 lsu &= ~LSU_PE;
130         }
131         stxa(0, ASI_LSU_CTL_REG, lsu | LSU_IC | LSU_DC);
132         CHEETAH_FLUSH_LSU_IC();
133 }
134
135 /*
136  * Flush all lines from the level 1 caches.
137  */
138 void
139 cheetah_cache_flush(void)
140 {
141         u_long addr, lsu;
142
143         for (addr = 0; addr < PCPU_GET(cache.dc_size);
144             addr += PCPU_GET(cache.dc_linesize))
145                 stxa_sync(addr, ASI_DCACHE_TAG, 0);
146
147         /* The I$ must be disabled when flushing it so ensure it's off. */
148         lsu = ldxa(0, ASI_LSU_CTL_REG);
149         stxa(0, ASI_LSU_CTL_REG, lsu & ~(LSU_IC));
150         CHEETAH_FLUSH_LSU_IC();
151         for (addr = CHEETAH_ICACHE_TAG_LOWER;
152             addr < PCPU_GET(cache.ic_size) * 2;
153             addr += PCPU_GET(cache.ic_linesize) * 2)
154                 stxa_sync(addr, ASI_ICACHE_TAG, 0);
155         stxa(0, ASI_LSU_CTL_REG, lsu);
156         CHEETAH_FLUSH_LSU_IC();
157 }
158
159 /*
160  * Flush a physical page from the data cache.
161  */
162 void
163 cheetah_dcache_page_inval(vm_paddr_t spa)
164 {
165         vm_paddr_t pa;
166         void *cookie;
167
168         KASSERT((spa & PAGE_MASK) == 0, ("%s: pa not page aligned", __func__));
169         cookie = ipi_dcache_page_inval(tl_ipi_cheetah_dcache_page_inval, spa);
170         for (pa = spa; pa < spa + PAGE_SIZE; pa += PCPU_GET(cache.dc_linesize))
171                 stxa_sync(pa, ASI_DCACHE_INVALIDATE, 0);
172         ipi_wait(cookie);
173 }
174
175 /*
176  * Flush a physical page from the intsruction cache.  Instruction cache
177  * consistency is maintained by hardware.
178  */
179 void
180 cheetah_icache_page_inval(vm_paddr_t pa)
181 {
182
183 }
184
185 #define cheetah_dmap_all() do {                                         \
186         stxa(TLB_DEMAP_ALL, ASI_DMMU_DEMAP, 0);                         \
187         stxa(TLB_DEMAP_ALL, ASI_IMMU_DEMAP, 0);                         \
188         flush(KERNBASE);                                                \
189 } while (0)
190
191 /*
192  * Flush all non-locked mappings from the TLB.
193  */
194 void
195 cheetah_tlb_flush_nonlocked(void)
196 {
197
198         cheetah_dmap_all();
199 }
200
201 /*
202  * Flush all user mappings from the TLB.
203  */
204 void
205 cheetah_tlb_flush_user()
206 {
207
208         /*
209          * Just use cheetah_dmap_all() and accept somes TLB misses
210          * rather than searching all 1040 D-TLB and 144 I-TLB slots
211          * for non-kernel mappings.
212          */
213         cheetah_dmap_all();
214 }