xref: /f-stack/freebsd/mips/nlm/hal/mmu.h (revision 22ce4aff)
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
nlm_read_c0_config6(void)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
nlm_write_c0_config6(uint32_t value)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
nlm_read_c0_config7(void)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
nlm_write_c0_config7(uint32_t value)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 /* en = 1 to enable
112  * en = 0 to disable
113  */
nlm_large_variable_tlb_en(int en)114 static __inline__ void nlm_large_variable_tlb_en (int en)
115 {
116 	unsigned int val;
117 
118 	val = nlm_read_c0_config6();
119 	val |= (en << 5);
120 	nlm_write_c0_config6(val);
121 	return;
122 }
123 
124 /* en = 1 to enable
125  * en = 0 to disable
126  */
nlm_pagewalker_en(int en)127 static __inline__ void nlm_pagewalker_en(int en)
128 {
129 	unsigned int val;
130 
131 	val = nlm_read_c0_config6();
132 	val |= (en << 3);
133 	nlm_write_c0_config6(val);
134 	return;
135 }
136 
137 /* en = 1 to enable
138  * en = 0 to disable
139  */
nlm_extended_tlb_en(int en)140 static __inline__ void nlm_extended_tlb_en(int en)
141 {
142 	unsigned int val;
143 
144 	val = nlm_read_c0_config6();
145 	val |= (en << 2);
146 	nlm_write_c0_config6(val);
147 	return;
148 }
149 
nlm_get_num_combined_tlbs(void)150 static __inline__ int nlm_get_num_combined_tlbs(void)
151 {
152 	return (((nlm_read_c0_config6() >> 16) & 0xffff) + 1);
153 }
154 
155 /* get number of variable TLB entries */
nlm_get_num_vtlbs(void)156 static __inline__ int nlm_get_num_vtlbs(void)
157 {
158 	return (((nlm_read_c0_config6() >> 6) & 0x3ff) + 1);
159 }
160 
nlm_setup_extended_pagemask(int mask)161 static __inline__ void nlm_setup_extended_pagemask(int mask)
162 {
163 	nlm_write_c0_config7(mask);
164 }
165 
166 #endif
167