pmap.h revision 1.134 1 1.134 riastrad /* $NetBSD: pmap.h,v 1.134 2022/08/20 23:49:31 riastradh Exp $ */
2 1.2 yamt
3 1.2 yamt /*
4 1.2 yamt * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 1.2 yamt * All rights reserved.
6 1.2 yamt *
7 1.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.2 yamt * modification, are permitted provided that the following conditions
9 1.2 yamt * are met:
10 1.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.2 yamt * documentation and/or other materials provided with the distribution.
15 1.2 yamt *
16 1.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.2 yamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.2 yamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.2 yamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.2 yamt */
27 1.2 yamt
28 1.2 yamt /*
29 1.2 yamt * Copyright (c) 2001 Wasabi Systems, Inc.
30 1.2 yamt * All rights reserved.
31 1.2 yamt *
32 1.2 yamt * Written by Frank van der Linden for Wasabi Systems, Inc.
33 1.2 yamt *
34 1.2 yamt * Redistribution and use in source and binary forms, with or without
35 1.2 yamt * modification, are permitted provided that the following conditions
36 1.2 yamt * are met:
37 1.2 yamt * 1. Redistributions of source code must retain the above copyright
38 1.2 yamt * notice, this list of conditions and the following disclaimer.
39 1.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
40 1.2 yamt * notice, this list of conditions and the following disclaimer in the
41 1.2 yamt * documentation and/or other materials provided with the distribution.
42 1.2 yamt * 3. All advertising materials mentioning features or use of this software
43 1.2 yamt * must display the following acknowledgement:
44 1.2 yamt * This product includes software developed for the NetBSD Project by
45 1.2 yamt * Wasabi Systems, Inc.
46 1.2 yamt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
47 1.2 yamt * or promote products derived from this software without specific prior
48 1.2 yamt * written permission.
49 1.2 yamt *
50 1.2 yamt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
51 1.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
52 1.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 1.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
54 1.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
55 1.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
56 1.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57 1.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58 1.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59 1.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60 1.2 yamt * POSSIBILITY OF SUCH DAMAGE.
61 1.2 yamt */
62 1.2 yamt
63 1.2 yamt /*
64 1.2 yamt * pmap.h: see pmap.c for the history of this pmap module.
65 1.2 yamt */
66 1.2 yamt
67 1.2 yamt #ifndef _X86_PMAP_H_
68 1.2 yamt #define _X86_PMAP_H_
69 1.2 yamt
70 1.2 yamt #if defined(_KERNEL)
71 1.94 maxv #include <x86/pmap_pv.h>
72 1.57 skrll #include <uvm/pmap/pmap_pvt.h>
73 1.2 yamt
74 1.2 yamt /*
75 1.28 cegger * MD flags that we use for pmap_enter and pmap_kenter_pa:
76 1.23 cegger */
77 1.23 cegger
78 1.23 cegger /*
79 1.2 yamt * macros
80 1.2 yamt */
81 1.2 yamt
82 1.104 maxv #define pmap_clear_modify(pg) pmap_clear_attrs(pg, PP_ATTRS_D)
83 1.104 maxv #define pmap_clear_reference(pg) pmap_clear_attrs(pg, PP_ATTRS_A)
84 1.55 christos #define pmap_copy(DP,SP,D,L,S) __USE(L)
85 1.104 maxv #define pmap_is_modified(pg) pmap_test_attrs(pg, PP_ATTRS_D)
86 1.104 maxv #define pmap_is_referenced(pg) pmap_test_attrs(pg, PP_ATTRS_A)
87 1.2 yamt #define pmap_move(DP,SP,D,L,S)
88 1.35 jmcneill #define pmap_phys_address(ppn) (x86_ptob(ppn) & ~X86_MMAP_FLAG_MASK)
89 1.35 jmcneill #define pmap_mmap_flags(ppn) x86_mmap_flags(ppn)
90 1.2 yamt
91 1.35 jmcneill #if defined(__x86_64__) || defined(PAE)
92 1.35 jmcneill #define X86_MMAP_FLAG_SHIFT (64 - PGSHIFT)
93 1.35 jmcneill #else
94 1.35 jmcneill #define X86_MMAP_FLAG_SHIFT (32 - PGSHIFT)
95 1.35 jmcneill #endif
96 1.35 jmcneill
97 1.35 jmcneill #define X86_MMAP_FLAG_MASK 0xf
98 1.35 jmcneill #define X86_MMAP_FLAG_PREFETCH 0x1
99 1.2 yamt
100 1.2 yamt /*
101 1.2 yamt * prototypes
102 1.2 yamt */
103 1.2 yamt
104 1.2 yamt void pmap_activate(struct lwp *);
105 1.2 yamt void pmap_bootstrap(vaddr_t);
106 1.2 yamt bool pmap_clear_attrs(struct vm_page *, unsigned);
107 1.56 riastrad bool pmap_pv_clear_attrs(paddr_t, unsigned);
108 1.2 yamt void pmap_deactivate(struct lwp *);
109 1.56 riastrad void pmap_page_remove(struct vm_page *);
110 1.56 riastrad void pmap_pv_remove(paddr_t);
111 1.2 yamt void pmap_remove(struct pmap *, vaddr_t, vaddr_t);
112 1.2 yamt bool pmap_test_attrs(struct vm_page *, unsigned);
113 1.2 yamt void pmap_write_protect(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
114 1.2 yamt void pmap_load(void);
115 1.6 jmcneill paddr_t pmap_init_tmp_pgtbl(paddr_t);
116 1.112 ad bool pmap_remove_all(struct pmap *);
117 1.60 maya void pmap_ldt_cleanup(struct lwp *);
118 1.22 ad void pmap_ldt_sync(struct pmap *);
119 1.53 chs void pmap_kremove_local(vaddr_t, vsize_t);
120 1.2 yamt
121 1.56 riastrad #define __HAVE_PMAP_PV_TRACK 1
122 1.56 riastrad void pmap_pv_init(void);
123 1.56 riastrad void pmap_pv_track(paddr_t, psize_t);
124 1.56 riastrad void pmap_pv_untrack(paddr_t, psize_t);
125 1.56 riastrad
126 1.35 jmcneill u_int x86_mmap_flags(paddr_t);
127 1.35 jmcneill
128 1.2 yamt #define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */
129 1.19 jmcneill #define PMAP_FORK /* turn on pmap_fork interface */
130 1.2 yamt
131 1.2 yamt /*
132 1.2 yamt * inline functions
133 1.2 yamt */
134 1.2 yamt
135 1.2 yamt /*
136 1.2 yamt * pmap_page_protect: change the protection of all recorded mappings
137 1.2 yamt * of a managed page
138 1.2 yamt *
139 1.2 yamt * => this function is a frontend for pmap_page_remove/pmap_clear_attrs
140 1.2 yamt * => we only have to worry about making the page more protected.
141 1.2 yamt * unprotecting a page is done on-demand at fault time.
142 1.2 yamt */
143 1.2 yamt
144 1.7 perry __inline static void __unused
145 1.2 yamt pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
146 1.2 yamt {
147 1.2 yamt if ((prot & VM_PROT_WRITE) == 0) {
148 1.2 yamt if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
149 1.94 maxv (void)pmap_clear_attrs(pg, PP_ATTRS_W);
150 1.2 yamt } else {
151 1.2 yamt pmap_page_remove(pg);
152 1.2 yamt }
153 1.2 yamt }
154 1.2 yamt }
155 1.2 yamt
156 1.2 yamt /*
157 1.56 riastrad * pmap_pv_protect: change the protection of all recorded mappings
158 1.56 riastrad * of an unmanaged page
159 1.56 riastrad */
160 1.56 riastrad
161 1.56 riastrad __inline static void __unused
162 1.56 riastrad pmap_pv_protect(paddr_t pa, vm_prot_t prot)
163 1.56 riastrad {
164 1.56 riastrad if ((prot & VM_PROT_WRITE) == 0) {
165 1.56 riastrad if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
166 1.94 maxv (void)pmap_pv_clear_attrs(pa, PP_ATTRS_W);
167 1.56 riastrad } else {
168 1.56 riastrad pmap_pv_remove(pa);
169 1.56 riastrad }
170 1.56 riastrad }
171 1.56 riastrad }
172 1.56 riastrad
173 1.56 riastrad /*
174 1.2 yamt * pmap_protect: change the protection of pages in a pmap
175 1.2 yamt *
176 1.2 yamt * => this function is a frontend for pmap_remove/pmap_write_protect
177 1.2 yamt * => we only have to worry about making the page more protected.
178 1.2 yamt * unprotecting a page is done on-demand at fault time.
179 1.2 yamt */
180 1.2 yamt
181 1.7 perry __inline static void __unused
182 1.2 yamt pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot)
183 1.2 yamt {
184 1.2 yamt if ((prot & VM_PROT_WRITE) == 0) {
185 1.2 yamt if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
186 1.2 yamt pmap_write_protect(pmap, sva, eva, prot);
187 1.2 yamt } else {
188 1.2 yamt pmap_remove(pmap, sva, eva);
189 1.2 yamt }
190 1.2 yamt }
191 1.2 yamt }
192 1.2 yamt
193 1.2 yamt paddr_t vtophys(vaddr_t);
194 1.2 yamt vaddr_t pmap_map(vaddr_t, paddr_t, paddr_t, vm_prot_t);
195 1.2 yamt void pmap_cpu_init_late(struct cpu_info *);
196 1.2 yamt
197 1.5 bouyer /* pmap functions with machine addresses */
198 1.27 cegger void pmap_kenter_ma(vaddr_t, paddr_t, vm_prot_t, u_int);
199 1.5 bouyer int pmap_enter_ma(struct pmap *, vaddr_t, paddr_t, paddr_t,
200 1.24 cegger vm_prot_t, u_int, int);
201 1.5 bouyer bool pmap_extract_ma(pmap_t, vaddr_t, paddr_t *);
202 1.20 bouyer
203 1.85 maxv paddr_t pmap_get_physpage(void);
204 1.85 maxv
205 1.2 yamt /*
206 1.2 yamt * Hooks for the pool allocator.
207 1.2 yamt */
208 1.2 yamt #define POOL_VTOPHYS(va) vtophys((vaddr_t) (va))
209 1.2 yamt
210 1.49 chs #ifdef __HAVE_DIRECT_MAP
211 1.49 chs
212 1.72 maxv extern vaddr_t pmap_direct_base;
213 1.72 maxv extern vaddr_t pmap_direct_end;
214 1.72 maxv
215 1.72 maxv #define PMAP_DIRECT_BASE pmap_direct_base
216 1.72 maxv #define PMAP_DIRECT_END pmap_direct_end
217 1.49 chs
218 1.49 chs #define PMAP_DIRECT_MAP(pa) ((vaddr_t)PMAP_DIRECT_BASE + (pa))
219 1.49 chs #define PMAP_DIRECT_UNMAP(va) ((paddr_t)(va) - PMAP_DIRECT_BASE)
220 1.49 chs
221 1.49 chs /*
222 1.49 chs * Alternate mapping hooks for pool pages.
223 1.49 chs */
224 1.49 chs #define PMAP_MAP_POOLPAGE(pa) PMAP_DIRECT_MAP((pa))
225 1.49 chs #define PMAP_UNMAP_POOLPAGE(va) PMAP_DIRECT_UNMAP((va))
226 1.49 chs
227 1.122 ad #endif /* __HAVE_DIRECT_MAP */
228 1.49 chs
229 1.131 riastrad #define __HAVE_VM_PAGE_MD
230 1.131 riastrad #define VM_MDPAGE_INIT(pg) \
231 1.131 riastrad memset(&(pg)->mdpage, 0, sizeof((pg)->mdpage)); \
232 1.131 riastrad PMAP_PAGE_INIT(&(pg)->mdpage.mp_pp)
233 1.131 riastrad
234 1.131 riastrad struct vm_page_md {
235 1.131 riastrad struct pmap_page mp_pp;
236 1.131 riastrad };
237 1.131 riastrad
238 1.2 yamt #endif /* _KERNEL */
239 1.2 yamt
240 1.2 yamt #endif /* _X86_PMAP_H_ */
241