2 * Copyright (c) 2003 Jake Burkholder.
3 * Copyright (c) 2005, 2008 Marius Strobl <marius@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/mutex.h>
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>
52 /* A FLUSH is required after changing LSU_IC (the address is ignored). */
53 #define CHEETAH_FLUSH_LSU_IC() __asm __volatile("flush %%g0" : :)
55 #define CHEETAH_ICACHE_TAG_LOWER 0x30
58 * CPU-specific initialization
66 * Disable interrupts for safety, this shouldn't be actually
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.
77 wr(asr18, rd(asr18) & ~DCR_IFPOE, 0);
79 /* Ensure the TSB Extension Registers hold 0 as TSB_Base. */
81 stxa(AA_DMMU_TSB_PEXT_REG, ASI_DMMU, 0);
82 stxa(AA_IMMU_TSB_PEXT_REG, ASI_IMMU, 0);
85 stxa(AA_DMMU_TSB_SEXT_REG, ASI_DMMU, 0);
87 * NB: the secondary context was removed from the iMMU.
91 stxa(AA_DMMU_TSB_NEXT_REG, ASI_DMMU, 0);
92 stxa(AA_IMMU_TSB_NEXT_REG, ASI_IMMU, 0);
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.
103 stxa(TLB_DEMAP_ALL, ASI_DMMU_DEMAP, 0);
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));
119 * Enable level 1 caches.
122 cheetah_cache_enable(void)
126 lsu = ldxa(0, ASI_LSU_CTL_REG);
127 if (cpu_impl == CPU_IMPL_ULTRASPARCIII) {
128 /* Disable P$ due to Cheetah erratum #18. */
131 stxa(0, ASI_LSU_CTL_REG, lsu | LSU_IC | LSU_DC);
132 CHEETAH_FLUSH_LSU_IC();
136 * Flush all lines from the level 1 caches.
139 cheetah_cache_flush(void)
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);
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();
160 * Flush a physical page from the data cache.
163 cheetah_dcache_page_inval(vm_paddr_t spa)
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);
176 * Flush a physical page from the intsruction cache. Instruction cache
177 * consistency is maintained by hardware.
180 cheetah_icache_page_inval(vm_paddr_t pa)
185 #define cheetah_dmap_all() do { \
186 stxa(TLB_DEMAP_ALL, ASI_DMMU_DEMAP, 0); \
187 stxa(TLB_DEMAP_ALL, ASI_IMMU_DEMAP, 0); \
192 * Flush all non-locked mappings from the TLB.
195 cheetah_tlb_flush_nonlocked(void)
202 * Flush all user mappings from the TLB.
205 cheetah_tlb_flush_user()
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.