xref: /freebsd-13-stable/sys/mips/nlm/hal/mmu.h (revision 4b40a16f0d188422227478889b38cc341d50f88f)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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  */
32 
33 #ifndef __XLP_MMU_H__
34 #define	__XLP_MMU_H__
35 
36 #include <mips/nlm/hal/mips-extns.h>
37 
38 static __inline__ uint32_t
nlm_read_c0_config6(void)39 nlm_read_c0_config6(void)
40 {
41 	uint32_t rv;
42 
43 	__asm__ __volatile__ (
44 		".set	push\n"
45 		".set	mips64\n"
46 		"mfc0	%0, $16, 6\n"
47 		".set	pop\n"
48 		: "=r" (rv));
49 
50         return rv;
51 }
52 
53 static __inline__ void
nlm_write_c0_config6(uint32_t value)54 nlm_write_c0_config6(uint32_t value)
55 {
56 	__asm__ __volatile__ (
57 		".set	push\n"
58 		".set	mips64\n"
59 		"mtc0	%0, $16, 6\n"
60 		".set	pop\n"
61 		: : "r" (value));
62 }
63 
64 static __inline__ uint32_t
nlm_read_c0_config7(void)65 nlm_read_c0_config7(void)
66 {
67 	uint32_t rv;
68 
69 	__asm__ __volatile__ (
70 		".set	push\n"
71 		".set	mips64\n"
72 		"mfc0	%0, $16, 7\n"
73 		".set	pop\n"
74 		: "=r" (rv));
75 
76         return rv;
77 }
78 
79 static __inline__ void
nlm_write_c0_config7(uint32_t value)80 nlm_write_c0_config7(uint32_t value)
81 {
82 	__asm__ __volatile__ (
83 		".set	push\n"
84 		".set	mips64\n"
85 		"mtc0	%0, $16, 7\n"
86 		".set	pop\n"
87 		: : "r" (value));
88 }
89 /**
90  * On power on reset, XLP comes up with 64 TLBs.
91  * Large-variable-tlb's (ELVT) and extended TLB is disabled.
92  * Enabling large-variable-tlb's sets up the standard
93  * TLB size from 64 to 128 TLBs.
94  * Enabling fixed TLB (EFT) sets up an additional 2048 tlbs.
95  * ELVT + EFT = 128 + 2048 = 2176 TLB entries.
96  * threads  64-entry-standard-tlb    128-entry-standard-tlb
97  * per      std-tlb-only| std+EFT  | std-tlb-only| std+EFT
98  * core                 |          |             |
99  * --------------------------------------------------------
100  * 1         64           64+2048     128          128+2048
101  * 2         64           64+1024      64           64+1024
102  * 4         32           32+512       32           32+512
103  *
104  * 1(G)      64           64+2048     128          128+2048
105  * 2(G)      128         128+2048     128          128+2048
106  * 4(G)      128         128+2048     128          128+2048
107  * (G) = Global mode
108  */
109 
110 /* en = 1 to enable
111  * en = 0 to disable
112  */
nlm_large_variable_tlb_en(int en)113 static __inline__ void nlm_large_variable_tlb_en (int en)
114 {
115 	unsigned int val;
116 
117 	val = nlm_read_c0_config6();
118 	val |= (en << 5);
119 	nlm_write_c0_config6(val);
120 	return;
121 }
122 
123 /* en = 1 to enable
124  * en = 0 to disable
125  */
nlm_pagewalker_en(int en)126 static __inline__ void nlm_pagewalker_en(int en)
127 {
128 	unsigned int val;
129 
130 	val = nlm_read_c0_config6();
131 	val |= (en << 3);
132 	nlm_write_c0_config6(val);
133 	return;
134 }
135 
136 /* en = 1 to enable
137  * en = 0 to disable
138  */
nlm_extended_tlb_en(int en)139 static __inline__ void nlm_extended_tlb_en(int en)
140 {
141 	unsigned int val;
142 
143 	val = nlm_read_c0_config6();
144 	val |= (en << 2);
145 	nlm_write_c0_config6(val);
146 	return;
147 }
148 
nlm_get_num_combined_tlbs(void)149 static __inline__ int nlm_get_num_combined_tlbs(void)
150 {
151 	return (((nlm_read_c0_config6() >> 16) & 0xffff) + 1);
152 }
153 
154 /* get number of variable TLB entries */
nlm_get_num_vtlbs(void)155 static __inline__ int nlm_get_num_vtlbs(void)
156 {
157 	return (((nlm_read_c0_config6() >> 6) & 0x3ff) + 1);
158 }
159 
nlm_setup_extended_pagemask(int mask)160 static __inline__ void nlm_setup_extended_pagemask(int mask)
161 {
162 	nlm_write_c0_config7(mask);
163 }
164 
165 #endif
166