pmap.h revision 1.68 1 1.68 matt /* $NetBSD: pmap.h,v 1.68 2016/07/11 16:15:35 matt Exp $ */
2 1.5 cgd
3 1.26 simonb /*
4 1.3 glass * Copyright (c) 1992, 1993
5 1.3 glass * The Regents of the University of California. All rights reserved.
6 1.44 agc *
7 1.44 agc * This code is derived from software contributed to Berkeley by
8 1.44 agc * Ralph Campbell.
9 1.44 agc *
10 1.44 agc * Redistribution and use in source and binary forms, with or without
11 1.44 agc * modification, are permitted provided that the following conditions
12 1.44 agc * are met:
13 1.44 agc * 1. Redistributions of source code must retain the above copyright
14 1.44 agc * notice, this list of conditions and the following disclaimer.
15 1.44 agc * 2. Redistributions in binary form must reproduce the above copyright
16 1.44 agc * notice, this list of conditions and the following disclaimer in the
17 1.44 agc * documentation and/or other materials provided with the distribution.
18 1.44 agc * 3. Neither the name of the University nor the names of its contributors
19 1.44 agc * may be used to endorse or promote products derived from this software
20 1.44 agc * without specific prior written permission.
21 1.44 agc *
22 1.44 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.44 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.44 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.44 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.44 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.44 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.44 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.44 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.44 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.44 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.44 agc * SUCH DAMAGE.
33 1.44 agc *
34 1.44 agc * @(#)pmap.h 8.1 (Berkeley) 6/10/93
35 1.44 agc */
36 1.44 agc
37 1.44 agc /*
38 1.44 agc * Copyright (c) 1987 Carnegie-Mellon University
39 1.1 deraadt *
40 1.1 deraadt * This code is derived from software contributed to Berkeley by
41 1.1 deraadt * Ralph Campbell.
42 1.1 deraadt *
43 1.1 deraadt * Redistribution and use in source and binary forms, with or without
44 1.1 deraadt * modification, are permitted provided that the following conditions
45 1.1 deraadt * are met:
46 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
47 1.1 deraadt * notice, this list of conditions and the following disclaimer.
48 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
50 1.1 deraadt * documentation and/or other materials provided with the distribution.
51 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
52 1.1 deraadt * must display the following acknowledgement:
53 1.1 deraadt * This product includes software developed by the University of
54 1.1 deraadt * California, Berkeley and its contributors.
55 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
56 1.1 deraadt * may be used to endorse or promote products derived from this software
57 1.1 deraadt * without specific prior written permission.
58 1.1 deraadt *
59 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 deraadt * SUCH DAMAGE.
70 1.1 deraadt *
71 1.5 cgd * @(#)pmap.h 8.1 (Berkeley) 6/10/93
72 1.1 deraadt */
73 1.1 deraadt
74 1.41 simonb #ifndef _MIPS_PMAP_H_
75 1.41 simonb #define _MIPS_PMAP_H_
76 1.1 deraadt
77 1.60 matt #ifdef _KERNEL_OPT
78 1.60 matt #include "opt_multiprocessor.h"
79 1.68 matt #include "opt_uvmhist.h"
80 1.60 matt #endif
81 1.60 matt
82 1.64 matt #include <sys/evcnt.h>
83 1.65 matt #include <sys/kcpuset.h>
84 1.68 matt #include <sys/kernhist.h>
85 1.64 matt
86 1.68 matt #ifndef __BSD_PTENTRY_T__
87 1.68 matt #define __BSD_PTENTRY_T__
88 1.68 matt typedef uint32_t pt_entry_t;
89 1.68 matt #define PRIxPTE PRIx32
90 1.68 matt #endif /* __BSD_PTENTRY_T__ */
91 1.68 matt
92 1.68 matt #define KERNEL_PID 0
93 1.68 matt
94 1.68 matt #if defined(__PMAP_PRIVATE)
95 1.68 matt
96 1.68 matt #include <mips/locore.h>
97 1.68 matt #include <mips/cache.h>
98 1.68 matt
99 1.68 matt #define PMAP_VIRTUAL_CACHE_ALIASES
100 1.68 matt #define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)NULL)
101 1.68 matt #define PMAP_TLB_NEED_SHOOTDOWN
102 1.68 matt #define PMAP_TLB_FLUSH_ASID_ON_RESET false
103 1.68 matt #if UPAGES > 1
104 1.68 matt #define PMAP_TLB_WIRED_UPAGES MIPS3_TLB_WIRED_UPAGES
105 1.68 matt #endif
106 1.68 matt #define pmap_md_tlb_asid_max() (MIPS_TLB_NUM_PIDS - 1)
107 1.68 matt #ifdef MULTIPROCESSOR
108 1.68 matt #define PMAP_NO_PV_UNCACHED
109 1.68 matt #endif
110 1.68 matt
111 1.68 matt /*
112 1.68 matt * We need the pmap_segtab's to be aligned on MIPS*R2 so we can use the
113 1.68 matt * EXT/INS instructions on their addresses.
114 1.68 matt */
115 1.68 matt #if (MIPS32R2 + MIPS64R2 + MIPS64R2_RMIXL) > 0
116 1.68 matt #define PMAP_SEGTAB_ALIGN __aligned(sizeof(void *)*NSEGPG) __section(".data1")
117 1.68 matt #endif
118 1.68 matt
119 1.68 matt struct vm_physseg;
120 1.68 matt
121 1.68 matt void pmap_md_init(void);
122 1.68 matt void pmap_md_icache_sync_all(void);
123 1.68 matt void pmap_md_icache_sync_range_index(vaddr_t, vsize_t);
124 1.68 matt void pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
125 1.68 matt bool pmap_md_vca_add(struct vm_page *, vaddr_t, pt_entry_t *);
126 1.68 matt void pmap_md_vca_clean(struct vm_page *, int);
127 1.68 matt void pmap_md_vca_remove(struct vm_page *, vaddr_t, bool, bool);
128 1.68 matt bool pmap_md_ok_to_steal_p(const struct vm_physseg *, size_t);
129 1.68 matt bool pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
130 1.68 matt
131 1.68 matt static inline bool
132 1.68 matt pmap_md_virtual_cache_aliasing_p(void)
133 1.68 matt {
134 1.68 matt return MIPS_CACHE_VIRTUAL_ALIAS;
135 1.68 matt }
136 1.68 matt
137 1.68 matt static inline vsize_t
138 1.68 matt pmap_md_cache_prefer_mask(void)
139 1.68 matt {
140 1.68 matt return MIPS_HAS_R4K_MMU ? mips_cache_info.mci_cache_prefer_mask : 0;
141 1.68 matt }
142 1.68 matt #endif /* __PMAP_PRIVATE */
143 1.68 matt
144 1.68 matt struct tlbmask {
145 1.68 matt vaddr_t tlb_hi;
146 1.68 matt #ifdef __mips_o32
147 1.68 matt uint32_t tlb_lo0;
148 1.68 matt uint32_t tlb_lo1;
149 1.68 matt #else
150 1.68 matt uint64_t tlb_lo0;
151 1.68 matt uint64_t tlb_lo1;
152 1.68 matt #endif
153 1.68 matt uint32_t tlb_mask;
154 1.68 matt };
155 1.68 matt
156 1.68 matt #ifdef _LP64
157 1.68 matt #define PMAP_SEGTABSIZE NSEGPG
158 1.68 matt #else
159 1.68 matt #define PMAP_SEGTABSIZE (1 << (31 - SEGSHIFT))
160 1.68 matt #endif
161 1.68 matt
162 1.68 matt #include <uvm/pmap/vmpagemd.h>
163 1.68 matt #include <uvm/pmap/pmap.h>
164 1.68 matt #include <uvm/pmap/pmap_tlb.h>
165 1.68 matt #include <uvm/pmap/pmap_synci.h>
166 1.68 matt
167 1.68 matt #ifdef _KERNEL
168 1.68 matt /*
169 1.68 matt * Select CCA to use for unmanaged pages.
170 1.68 matt */
171 1.68 matt #define PMAP_CCA_FOR_PA(pa) CCA_UNCACHED /* uncached */
172 1.68 matt
173 1.68 matt #if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
174 1.68 matt #define PGC_NOCACHE 0x4000000000000000ULL
175 1.68 matt #define PGC_PREFETCH 0x2000000000000000ULL
176 1.68 matt #endif
177 1.68 matt
178 1.68 matt #if defined(__PMAP_PRIVATE)
179 1.68 matt #include <mips/pte.h>
180 1.68 matt #endif
181 1.18 thorpej
182 1.1 deraadt /*
183 1.3 glass * The user address space is 2Gb (0x0 - 0x80000000).
184 1.3 glass * User programs are laid out in memory as follows:
185 1.3 glass * address
186 1.3 glass * USRTEXT 0x00001000
187 1.3 glass * USRDATA USRTEXT + text_size
188 1.3 glass * USRSTACK 0x7FFFFFFF
189 1.3 glass *
190 1.3 glass * The user address space is mapped using a two level structure where
191 1.3 glass * virtual address bits 30..22 are used to index into a segment table which
192 1.3 glass * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
193 1.26 simonb * Bits 21..12 are then used to index a PTE which describes a page within
194 1.3 glass * a segment.
195 1.3 glass *
196 1.1 deraadt * The wired entries in the TLB will contain the following:
197 1.3 glass * 0-1 (UPAGES) for curproc user struct and kernel stack.
198 1.3 glass *
199 1.3 glass * Note: The kernel doesn't use the same data structures as user programs.
200 1.3 glass * All the PTE entries are stored in a single array in Sysmap which is
201 1.3 glass * dynamically allocated at boot time.
202 1.1 deraadt */
203 1.1 deraadt
204 1.51 macallan #define pmap_phys_address(x) mips_ptob(x)
205 1.39 chs
206 1.12 jonathan /*
207 1.13 jonathan * Bootstrap the system enough to run with virtual memory.
208 1.13 jonathan */
209 1.38 simonb void pmap_bootstrap(void);
210 1.68 matt void pmap_md_alloc_ephemeral_address_space(struct cpu_info *);
211 1.38 simonb void pmap_procwr(struct proc *, vaddr_t, size_t);
212 1.25 is #define PMAP_NEED_PROCWR
213 1.13 jonathan
214 1.13 jonathan /*
215 1.28 soren * pmap_prefer() helps reduce virtual-coherency exceptions in
216 1.13 jonathan * the virtually-indexed cache on mips3 CPUs.
217 1.13 jonathan */
218 1.38 simonb #ifdef MIPS3_PLUS
219 1.60 matt #define PMAP_PREFER(pa, va, sz, td) pmap_prefer((pa), (va), (sz), (td))
220 1.60 matt void pmap_prefer(vaddr_t, vaddr_t *, vsize_t, int);
221 1.38 simonb #endif /* MIPS3_PLUS */
222 1.13 jonathan
223 1.63 skrll #define PMAP_ENABLE_PMAP_KMPAGE /* enable the PMAP_KMPAGE flag */
224 1.18 thorpej
225 1.68 matt // these use register_t so we can pass XKPHYS adddresses to them on N32
226 1.68 matt bool pmap_md_direct_mapped_vaddr_p(register_t);
227 1.68 matt paddr_t pmap_md_direct_mapped_vaddr_to_paddr(register_t);
228 1.68 matt bool pmap_md_io_vaddr_p(vaddr_t);
229 1.66 matt
230 1.18 thorpej /*
231 1.18 thorpej * Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
232 1.18 thorpej */
233 1.68 matt vaddr_t pmap_md_map_poolpage(paddr_t, size_t);
234 1.68 matt paddr_t pmap_md_unmap_poolpage(vaddr_t, size_t);
235 1.68 matt struct vm_page *pmap_md_alloc_poolpage(int);
236 1.42 thorpej
237 1.42 thorpej /*
238 1.42 thorpej * Other hooks for the pool allocator.
239 1.42 thorpej */
240 1.68 matt paddr_t pmap_md_pool_vtophys(vaddr_t);
241 1.68 matt vaddr_t pmap_md_pool_phystov(paddr_t);
242 1.68 matt #define POOL_VTOPHYS(va) pmap_md_pool_vtophys((vaddr_t)va)
243 1.68 matt #define POOL_PHYSTOV(pa) pmap_md_pool_phystov((paddr_t)pa)
244 1.60 matt
245 1.6 jtc #endif /* _KERNEL */
246 1.41 simonb #endif /* _MIPS_PMAP_H_ */
247