]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sparc64/sparc64/zeus.c
Upgrade Unbound to 1.6.0. More to follow.
[FreeBSD/FreeBSD.git] / sys / sparc64 / sparc64 / zeus.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2010 - 2011 Marius Strobl <marius@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34
35 #include <machine/asi.h>
36 #include <machine/cache.h>
37 #include <machine/cpu.h>
38 #include <machine/cpufunc.h>
39 #include <machine/mcntl.h>
40 #include <machine/lsu.h>
41 #include <machine/tlb.h>
42 #include <machine/tte.h>
43 #include <machine/vmparam.h>
44
45 #define ZEUS_FTLB_ENTRIES       32
46 #define ZEUS_STLB_ENTRIES       2048
47
48 /*
49  * CPU-specific initialization for Fujitsu Zeus CPUs
50  */
51 void
52 zeus_init(u_int cpu_impl)
53 {
54         u_long val;
55
56         /* Ensure the TSB Extension Registers hold 0 as TSB_Base. */
57
58         stxa(AA_DMMU_TSB_PEXT_REG, ASI_DMMU, 0);
59         stxa(AA_IMMU_TSB_PEXT_REG, ASI_IMMU, 0);
60         membar(Sync);
61
62         stxa(AA_DMMU_TSB_SEXT_REG, ASI_DMMU, 0);
63         /*
64          * NB: the secondary context was removed from the iMMU.
65          */
66         membar(Sync);
67
68         stxa(AA_DMMU_TSB_NEXT_REG, ASI_DMMU, 0);
69         stxa(AA_IMMU_TSB_NEXT_REG, ASI_IMMU, 0);
70         membar(Sync);
71
72         val = ldxa(AA_MCNTL, ASI_MCNTL);
73         /* Ensure MCNTL_JPS1_TSBP is 0. */
74         val &= ~MCNTL_JPS1_TSBP;
75         /*
76          * Ensure 4-Mbyte page entries are stored in the 1024-entry, 2-way set
77          * associative TLB.
78          */
79         val = (val & ~MCNTL_RMD_MASK) | MCNTL_RMD_1024;
80         stxa(AA_MCNTL, ASI_MCNTL, val);
81 }
82
83 /*
84  * Enable level 1 caches.
85  */
86 void
87 zeus_cache_enable(u_int cpu_impl)
88 {
89         u_long lsu;
90
91         lsu = ldxa(0, ASI_LSU_CTL_REG);
92         stxa(0, ASI_LSU_CTL_REG, lsu | LSU_IC | LSU_DC);
93         flush(KERNBASE);
94 }
95
96 /*
97  * Flush all lines from the level 1 caches.
98  */
99 void
100 zeus_cache_flush(void)
101 {
102
103         stxa_sync(0, ASI_FLUSH_L1I, 0);
104 }
105
106 /*
107  * Flush a physical page from the data cache.  Data cache consistency is
108  * maintained by hardware.
109  */
110 void
111 zeus_dcache_page_inval(vm_paddr_t spa __unused)
112 {
113
114 }
115
116 /*
117  * Flush a physical page from the intsruction cache.  Instruction cache
118  * consistency is maintained by hardware.
119  */
120 void
121 zeus_icache_page_inval(vm_paddr_t pa __unused)
122 {
123
124 }
125
126 /*
127  * Flush all non-locked mappings from the TLBs.
128  */
129 void
130 zeus_tlb_flush_nonlocked(void)
131 {
132
133         stxa(TLB_DEMAP_ALL, ASI_DMMU_DEMAP, 0);
134         stxa(TLB_DEMAP_ALL, ASI_IMMU_DEMAP, 0);
135         flush(KERNBASE);
136 }
137
138 /*
139  * Flush all user mappings from the TLBs.
140  */
141 void
142 zeus_tlb_flush_user(void)
143 {
144         u_long data, tag;
145         u_int i, slot;
146
147         for (i = 0; i < ZEUS_FTLB_ENTRIES; i++) {
148                 slot = TLB_DAR_SLOT(TLB_DAR_FTLB, i);
149                 data = ldxa(slot, ASI_DTLB_DATA_ACCESS_REG);
150                 tag = ldxa(slot, ASI_DTLB_TAG_READ_REG);
151                 if ((data & TD_V) != 0 && (data & TD_L) == 0 &&
152                     TLB_TAR_CTX(tag) != TLB_CTX_KERNEL)
153                         stxa_sync(slot, ASI_DTLB_DATA_ACCESS_REG, 0);
154                 data = ldxa(slot, ASI_ITLB_DATA_ACCESS_REG);
155                 tag = ldxa(slot, ASI_ITLB_TAG_READ_REG);
156                 if ((data & TD_V) != 0 && (data & TD_L) == 0 &&
157                     TLB_TAR_CTX(tag) != TLB_CTX_KERNEL)
158                         stxa_sync(slot, ASI_ITLB_DATA_ACCESS_REG, 0);
159         }
160         for (i = 0; i < ZEUS_STLB_ENTRIES; i++) {
161                 slot = TLB_DAR_SLOT(TLB_DAR_STLB, i);
162                 data = ldxa(slot, ASI_DTLB_DATA_ACCESS_REG);
163                 tag = ldxa(slot, ASI_DTLB_TAG_READ_REG);
164                 if ((data & TD_V) != 0 && (data & TD_L) == 0 &&
165                     TLB_TAR_CTX(tag) != TLB_CTX_KERNEL)
166                         stxa_sync(slot, ASI_DTLB_DATA_ACCESS_REG, 0);
167                 data = ldxa(slot, ASI_ITLB_DATA_ACCESS_REG);
168                 tag = ldxa(slot, ASI_ITLB_TAG_READ_REG);
169                 if ((data & TD_V) != 0 && (data & TD_L) == 0 &&
170                     TLB_TAR_CTX(tag) != TLB_CTX_KERNEL)
171                         stxa_sync(slot, ASI_ITLB_DATA_ACCESS_REG, 0);
172         }
173 }