]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/nlm/hal/mmu.h
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / sys / mips / nlm / hal / mmu.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright 2003-2011 Netlogic Microsystems (Netlogic). All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY Netlogic Microsystems ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * NETLOGIC_BSD
31  * $FreeBSD$
32  */
33
34 #ifndef __XLP_MMU_H__
35 #define __XLP_MMU_H__
36
37 #include <mips/nlm/hal/mips-extns.h>
38
39 static __inline__ uint32_t
40 nlm_read_c0_config6(void)
41 {
42         uint32_t rv;
43
44         __asm__ __volatile__ (
45                 ".set   push\n"
46                 ".set   mips64\n"
47                 "mfc0   %0, $16, 6\n"
48                 ".set   pop\n"
49                 : "=r" (rv));
50
51         return rv;
52 }
53
54 static __inline__ void
55 nlm_write_c0_config6(uint32_t value)
56 {
57         __asm__ __volatile__ (
58                 ".set   push\n"
59                 ".set   mips64\n"
60                 "mtc0   %0, $16, 6\n"
61                 ".set   pop\n"
62                 : : "r" (value));
63 }
64
65 static __inline__ uint32_t
66 nlm_read_c0_config7(void)
67 {
68         uint32_t rv;
69
70         __asm__ __volatile__ (
71                 ".set   push\n"
72                 ".set   mips64\n"
73                 "mfc0   %0, $16, 7\n"
74                 ".set   pop\n"
75                 : "=r" (rv));
76
77         return rv;
78 }
79
80 static __inline__ void
81 nlm_write_c0_config7(uint32_t value)
82 {
83         __asm__ __volatile__ (
84                 ".set   push\n"
85                 ".set   mips64\n"
86                 "mtc0   %0, $16, 7\n"
87                 ".set   pop\n"
88                 : : "r" (value));
89 }
90 /**
91  * On power on reset, XLP comes up with 64 TLBs.
92  * Large-variable-tlb's (ELVT) and extended TLB is disabled.
93  * Enabling large-variable-tlb's sets up the standard
94  * TLB size from 64 to 128 TLBs.
95  * Enabling fixed TLB (EFT) sets up an additional 2048 tlbs.
96  * ELVT + EFT = 128 + 2048 = 2176 TLB entries.
97  * threads  64-entry-standard-tlb    128-entry-standard-tlb
98  * per      std-tlb-only| std+EFT  | std-tlb-only| std+EFT
99  * core                 |          |             |
100  * --------------------------------------------------------
101  * 1         64           64+2048     128          128+2048
102  * 2         64           64+1024      64           64+1024
103  * 4         32           32+512       32           32+512
104  *
105  * 1(G)      64           64+2048     128          128+2048
106  * 2(G)      128         128+2048     128          128+2048
107  * 4(G)      128         128+2048     128          128+2048
108  * (G) = Global mode
109  */
110
111
112 /* en = 1 to enable
113  * en = 0 to disable
114  */
115 static __inline__ void nlm_large_variable_tlb_en (int en)
116 {
117         unsigned int val;
118
119         val = nlm_read_c0_config6();
120         val |= (en << 5);
121         nlm_write_c0_config6(val);
122         return;
123 }
124
125 /* en = 1 to enable
126  * en = 0 to disable
127  */
128 static __inline__ void nlm_pagewalker_en(int en)
129 {
130         unsigned int val;
131
132         val = nlm_read_c0_config6();
133         val |= (en << 3);
134         nlm_write_c0_config6(val);
135         return;
136 }
137
138 /* en = 1 to enable
139  * en = 0 to disable
140  */
141 static __inline__ void nlm_extended_tlb_en(int en)
142 {
143         unsigned int val;
144
145         val = nlm_read_c0_config6();
146         val |= (en << 2);
147         nlm_write_c0_config6(val);
148         return;
149 }
150
151 static __inline__ int nlm_get_num_combined_tlbs(void)
152 {
153         return (((nlm_read_c0_config6() >> 16) & 0xffff) + 1);
154 }
155
156 /* get number of variable TLB entries */
157 static __inline__ int nlm_get_num_vtlbs(void)
158 {
159         return (((nlm_read_c0_config6() >> 6) & 0x3ff) + 1);
160 }
161
162 static __inline__ void nlm_setup_extended_pagemask(int mask)
163 {
164         nlm_write_c0_config7(mask);
165 }
166
167 #endif