vm.c revision 1.20.2.4 1 1.20.2.4 jmcneill /* $NetBSD: vm.c,v 1.20.2.4 2007/11/04 21:03:49 jmcneill Exp $ */
2 1.20.2.2 joerg
3 1.20.2.2 joerg /*
4 1.20.2.2 joerg * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
5 1.20.2.2 joerg *
6 1.20.2.2 joerg * Development of this software was supported by Google Summer of Code.
7 1.20.2.2 joerg *
8 1.20.2.2 joerg * Redistribution and use in source and binary forms, with or without
9 1.20.2.2 joerg * modification, are permitted provided that the following conditions
10 1.20.2.2 joerg * are met:
11 1.20.2.2 joerg * 1. Redistributions of source code must retain the above copyright
12 1.20.2.2 joerg * notice, this list of conditions and the following disclaimer.
13 1.20.2.2 joerg * 2. Redistributions in binary form must reproduce the above copyright
14 1.20.2.2 joerg * notice, this list of conditions and the following disclaimer in the
15 1.20.2.2 joerg * documentation and/or other materials provided with the distribution.
16 1.20.2.2 joerg *
17 1.20.2.2 joerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 1.20.2.2 joerg * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1.20.2.2 joerg * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 1.20.2.2 joerg * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 1.20.2.2 joerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.20.2.2 joerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.20.2.2 joerg * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.20.2.2 joerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.20.2.2 joerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.20.2.2 joerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.20.2.2 joerg * SUCH DAMAGE.
28 1.20.2.2 joerg */
29 1.20.2.2 joerg
30 1.20.2.2 joerg /*
31 1.20.2.2 joerg * Virtual memory emulation routines. Contents:
32 1.20.2.2 joerg * + UBC
33 1.20.2.2 joerg * + anon objects & pager
34 1.20.2.2 joerg * + vnode objects & pager
35 1.20.2.2 joerg * + misc support routines
36 1.20.2.2 joerg * + kmem
37 1.20.2.2 joerg */
38 1.20.2.2 joerg
39 1.20.2.2 joerg /*
40 1.20.2.2 joerg * XXX: we abuse pg->uanon for the virtual address of the storage
41 1.20.2.2 joerg * for each page. phys_addr would fit the job description better,
42 1.20.2.2 joerg * except that it will create unnecessary lossage on some platforms
43 1.20.2.2 joerg * due to not being a pointer type.
44 1.20.2.2 joerg */
45 1.20.2.2 joerg
46 1.20.2.2 joerg #include <sys/param.h>
47 1.20.2.2 joerg #include <sys/null.h>
48 1.20.2.2 joerg #include <sys/vnode.h>
49 1.20.2.2 joerg #include <sys/buf.h>
50 1.20.2.2 joerg #include <sys/kmem.h>
51 1.20.2.2 joerg
52 1.20.2.2 joerg #include <uvm/uvm.h>
53 1.20.2.2 joerg #include <uvm/uvm_prot.h>
54 1.20.2.2 joerg #include <uvm/uvm_readahead.h>
55 1.20.2.2 joerg
56 1.20.2.2 joerg #include <machine/pmap.h>
57 1.20.2.2 joerg
58 1.20.2.2 joerg #include "rump_private.h"
59 1.20.2.2 joerg #include "rumpuser.h"
60 1.20.2.2 joerg
61 1.20.2.2 joerg /* dumdidumdum */
62 1.20.2.2 joerg #define len2npages(off, len) \
63 1.20.2.2 joerg (((((len) + PAGE_MASK) & ~(PAGE_MASK)) >> PAGE_SHIFT) \
64 1.20.2.2 joerg + (((off & PAGE_MASK) + (len & PAGE_MASK)) > PAGE_SIZE))
65 1.20.2.2 joerg
66 1.20.2.2 joerg struct uvm_pagerops uvm_vnodeops;
67 1.20.2.2 joerg struct uvm_pagerops aobj_pager;
68 1.20.2.2 joerg struct uvmexp uvmexp;
69 1.20.2.2 joerg struct uvm uvm;
70 1.20.2.2 joerg
71 1.20.2.2 joerg struct vmspace rump_vmspace;
72 1.20.2.2 joerg struct vm_map rump_vmmap;
73 1.20.2.2 joerg
74 1.20.2.2 joerg /*
75 1.20.2.2 joerg * vm pages
76 1.20.2.2 joerg */
77 1.20.2.2 joerg
78 1.20.2.2 joerg struct vm_page *
79 1.20.2.2 joerg rumpvm_makepage(struct uvm_object *uobj, voff_t off)
80 1.20.2.2 joerg {
81 1.20.2.2 joerg struct vm_page *pg;
82 1.20.2.2 joerg
83 1.20.2.2 joerg pg = rumpuser_malloc(sizeof(struct vm_page), 0);
84 1.20.2.2 joerg memset(pg, 0, sizeof(struct vm_page));
85 1.20.2.2 joerg pg->offset = off;
86 1.20.2.2 joerg pg->uobject = uobj;
87 1.20.2.2 joerg
88 1.20.2.2 joerg pg->uanon = (void *)rumpuser_malloc(PAGE_SIZE, 0);
89 1.20.2.2 joerg memset((void *)pg->uanon, 0, PAGE_SIZE);
90 1.20.2.2 joerg pg->flags = PG_CLEAN;
91 1.20.2.2 joerg
92 1.20.2.4 jmcneill simple_lock(&uobj->vmobjlock);
93 1.20.2.4 jmcneill TAILQ_INSERT_TAIL(&uobj->memq, pg, listq);
94 1.20.2.4 jmcneill simple_unlock(&uobj->vmobjlock);
95 1.20.2.4 jmcneill
96 1.20.2.2 joerg return pg;
97 1.20.2.2 joerg }
98 1.20.2.2 joerg
99 1.20.2.4 jmcneill /*
100 1.20.2.4 jmcneill * Release a page.
101 1.20.2.4 jmcneill *
102 1.20.2.4 jmcneill * Called with the vm object locked. Returns with the lock released.
103 1.20.2.4 jmcneill */
104 1.20.2.2 joerg void
105 1.20.2.2 joerg rumpvm_freepage(struct vm_page *pg)
106 1.20.2.2 joerg {
107 1.20.2.2 joerg struct uvm_object *uobj = pg->uobject;
108 1.20.2.2 joerg
109 1.20.2.2 joerg TAILQ_REMOVE(&uobj->memq, pg, listq);
110 1.20.2.4 jmcneill simple_unlock(&uobj->vmobjlock);
111 1.20.2.4 jmcneill
112 1.20.2.2 joerg rumpuser_free((void *)pg->uanon);
113 1.20.2.2 joerg rumpuser_free(pg);
114 1.20.2.2 joerg }
115 1.20.2.2 joerg
116 1.20.2.2 joerg struct rumpva {
117 1.20.2.2 joerg vaddr_t addr;
118 1.20.2.2 joerg struct vm_page *pg;
119 1.20.2.2 joerg
120 1.20.2.2 joerg LIST_ENTRY(rumpva) entries;
121 1.20.2.2 joerg };
122 1.20.2.2 joerg static LIST_HEAD(, rumpva) rvahead = LIST_HEAD_INITIALIZER(rvahead);
123 1.20.2.4 jmcneill static kmutex_t rvamtx;
124 1.20.2.2 joerg
125 1.20.2.2 joerg void
126 1.20.2.2 joerg rumpvm_enterva(vaddr_t addr, struct vm_page *pg)
127 1.20.2.2 joerg {
128 1.20.2.2 joerg struct rumpva *rva;
129 1.20.2.2 joerg
130 1.20.2.2 joerg rva = rumpuser_malloc(sizeof(struct rumpva), 0);
131 1.20.2.2 joerg rva->addr = addr;
132 1.20.2.2 joerg rva->pg = pg;
133 1.20.2.4 jmcneill mutex_enter(&rvamtx);
134 1.20.2.2 joerg LIST_INSERT_HEAD(&rvahead, rva, entries);
135 1.20.2.4 jmcneill mutex_exit(&rvamtx);
136 1.20.2.2 joerg }
137 1.20.2.2 joerg
138 1.20.2.2 joerg void
139 1.20.2.2 joerg rumpvm_flushva()
140 1.20.2.2 joerg {
141 1.20.2.2 joerg struct rumpva *rva;
142 1.20.2.2 joerg
143 1.20.2.4 jmcneill mutex_enter(&rvamtx);
144 1.20.2.2 joerg while ((rva = LIST_FIRST(&rvahead)) != NULL) {
145 1.20.2.2 joerg LIST_REMOVE(rva, entries);
146 1.20.2.2 joerg rumpuser_free(rva);
147 1.20.2.2 joerg }
148 1.20.2.4 jmcneill mutex_exit(&rvamtx);
149 1.20.2.2 joerg }
150 1.20.2.2 joerg
151 1.20.2.2 joerg /*
152 1.20.2.2 joerg * vnode pager
153 1.20.2.2 joerg */
154 1.20.2.2 joerg
155 1.20.2.2 joerg static int
156 1.20.2.2 joerg vn_get(struct uvm_object *uobj, voff_t off, struct vm_page **pgs,
157 1.20.2.2 joerg int *npages, int centeridx, vm_prot_t access_type,
158 1.20.2.2 joerg int advice, int flags)
159 1.20.2.2 joerg {
160 1.20.2.2 joerg struct vnode *vp = (struct vnode *)uobj;
161 1.20.2.2 joerg
162 1.20.2.2 joerg return VOP_GETPAGES(vp, off, pgs, npages, centeridx, access_type,
163 1.20.2.2 joerg advice, flags);
164 1.20.2.2 joerg }
165 1.20.2.2 joerg
166 1.20.2.2 joerg static int
167 1.20.2.2 joerg vn_put(struct uvm_object *uobj, voff_t offlo, voff_t offhi, int flags)
168 1.20.2.2 joerg {
169 1.20.2.2 joerg struct vnode *vp = (struct vnode *)uobj;
170 1.20.2.2 joerg
171 1.20.2.2 joerg return VOP_PUTPAGES(vp, offlo, offhi, flags);
172 1.20.2.2 joerg }
173 1.20.2.2 joerg
174 1.20.2.2 joerg /*
175 1.20.2.2 joerg * Anon object stuff
176 1.20.2.2 joerg */
177 1.20.2.2 joerg
178 1.20.2.2 joerg static int
179 1.20.2.2 joerg ao_get(struct uvm_object *uobj, voff_t off, struct vm_page **pgs,
180 1.20.2.2 joerg int *npages, int centeridx, vm_prot_t access_type,
181 1.20.2.2 joerg int advice, int flags)
182 1.20.2.2 joerg {
183 1.20.2.2 joerg struct vm_page *pg;
184 1.20.2.2 joerg int i;
185 1.20.2.2 joerg
186 1.20.2.2 joerg if (centeridx)
187 1.20.2.2 joerg panic("%s: centeridx != 0 not supported", __func__);
188 1.20.2.2 joerg
189 1.20.2.2 joerg /* loop over pages */
190 1.20.2.2 joerg off = trunc_page(off);
191 1.20.2.2 joerg for (i = 0; i < *npages; i++) {
192 1.20.2.2 joerg pg = uvm_pagelookup(uobj, off + (i << PAGE_SHIFT));
193 1.20.2.2 joerg if (pg) {
194 1.20.2.2 joerg pgs[i] = pg;
195 1.20.2.2 joerg } else {
196 1.20.2.2 joerg pg = rumpvm_makepage(uobj, off + (i << PAGE_SHIFT));
197 1.20.2.2 joerg pgs[i] = pg;
198 1.20.2.2 joerg }
199 1.20.2.2 joerg }
200 1.20.2.2 joerg
201 1.20.2.2 joerg return 0;
202 1.20.2.2 joerg
203 1.20.2.2 joerg }
204 1.20.2.2 joerg
205 1.20.2.2 joerg static int
206 1.20.2.2 joerg ao_put(struct uvm_object *uobj, voff_t start, voff_t stop, int flags)
207 1.20.2.2 joerg {
208 1.20.2.2 joerg struct vm_page *pg;
209 1.20.2.2 joerg
210 1.20.2.2 joerg /* we only free all pages for now */
211 1.20.2.2 joerg if ((flags & PGO_FREE) == 0 || (flags & PGO_ALLPAGES) == 0)
212 1.20.2.2 joerg return 0;
213 1.20.2.2 joerg
214 1.20.2.4 jmcneill simple_lock(&uobj->vmobjlock);
215 1.20.2.2 joerg while ((pg = TAILQ_FIRST(&uobj->memq)) != NULL)
216 1.20.2.2 joerg rumpvm_freepage(pg);
217 1.20.2.4 jmcneill simple_unlock(&uobj->vmobjlock);
218 1.20.2.2 joerg
219 1.20.2.2 joerg return 0;
220 1.20.2.2 joerg }
221 1.20.2.2 joerg
222 1.20.2.2 joerg struct uvm_object *
223 1.20.2.2 joerg uao_create(vsize_t size, int flags)
224 1.20.2.2 joerg {
225 1.20.2.2 joerg struct uvm_object *uobj;
226 1.20.2.2 joerg
227 1.20.2.2 joerg uobj = rumpuser_malloc(sizeof(struct uvm_object), 0);
228 1.20.2.2 joerg memset(uobj, 0, sizeof(struct uvm_object));
229 1.20.2.2 joerg uobj->pgops = &aobj_pager;
230 1.20.2.2 joerg TAILQ_INIT(&uobj->memq);
231 1.20.2.2 joerg
232 1.20.2.2 joerg return uobj;
233 1.20.2.2 joerg }
234 1.20.2.2 joerg
235 1.20.2.2 joerg void
236 1.20.2.2 joerg uao_detach(struct uvm_object *uobj)
237 1.20.2.2 joerg {
238 1.20.2.2 joerg
239 1.20.2.2 joerg ao_put(uobj, 0, 0, PGO_ALLPAGES | PGO_FREE);
240 1.20.2.2 joerg rumpuser_free(uobj);
241 1.20.2.2 joerg }
242 1.20.2.2 joerg
243 1.20.2.2 joerg /*
244 1.20.2.2 joerg * UBC
245 1.20.2.2 joerg */
246 1.20.2.2 joerg
247 1.20.2.3 joerg struct ubc_window {
248 1.20.2.3 joerg struct uvm_object *uwin_obj;
249 1.20.2.3 joerg voff_t uwin_off;
250 1.20.2.3 joerg uint8_t *uwin_mem;
251 1.20.2.3 joerg size_t uwin_mapsize;
252 1.20.2.3 joerg
253 1.20.2.3 joerg LIST_ENTRY(ubc_window) uwin_entries;
254 1.20.2.3 joerg };
255 1.20.2.3 joerg
256 1.20.2.3 joerg static LIST_HEAD(, ubc_window) uwinlst = LIST_HEAD_INITIALIZER(uwinlst);
257 1.20.2.4 jmcneill static kmutex_t uwinmtx;
258 1.20.2.3 joerg
259 1.20.2.2 joerg int
260 1.20.2.4 jmcneill rump_ubc_magic_uiomove(void *va, size_t n, struct uio *uio, int *rvp,
261 1.20.2.4 jmcneill struct ubc_window *uwinp)
262 1.20.2.2 joerg {
263 1.20.2.2 joerg struct vm_page **pgs;
264 1.20.2.2 joerg int npages = len2npages(uio->uio_offset, n);
265 1.20.2.2 joerg int i, rv;
266 1.20.2.2 joerg
267 1.20.2.3 joerg if (uwinp == NULL) {
268 1.20.2.4 jmcneill mutex_enter(&uwinmtx);
269 1.20.2.4 jmcneill LIST_FOREACH(uwinp, &uwinlst, uwin_entries)
270 1.20.2.4 jmcneill if ((uint8_t *)va >= uwinp->uwin_mem
271 1.20.2.4 jmcneill && (uint8_t *)va
272 1.20.2.4 jmcneill < (uwinp->uwin_mem + uwinp->uwin_mapsize))
273 1.20.2.4 jmcneill break;
274 1.20.2.4 jmcneill mutex_exit(&uwinmtx);
275 1.20.2.4 jmcneill if (uwinp == NULL) {
276 1.20.2.4 jmcneill KASSERT(rvp != NULL);
277 1.20.2.4 jmcneill return 0;
278 1.20.2.4 jmcneill }
279 1.20.2.3 joerg }
280 1.20.2.2 joerg
281 1.20.2.2 joerg pgs = rumpuser_malloc(npages * sizeof(pgs), 0);
282 1.20.2.2 joerg memset(pgs, 0, sizeof(pgs));
283 1.20.2.3 joerg rv = uwinp->uwin_obj->pgops->pgo_get(uwinp->uwin_obj,
284 1.20.2.3 joerg uwinp->uwin_off + ((uint8_t *)va - uwinp->uwin_mem),
285 1.20.2.2 joerg pgs, &npages, 0, 0, 0, 0);
286 1.20.2.2 joerg if (rv)
287 1.20.2.2 joerg goto out;
288 1.20.2.2 joerg
289 1.20.2.2 joerg for (i = 0; i < npages; i++) {
290 1.20.2.2 joerg size_t xfersize;
291 1.20.2.2 joerg off_t pageoff;
292 1.20.2.2 joerg
293 1.20.2.2 joerg pageoff = uio->uio_offset & PAGE_MASK;
294 1.20.2.2 joerg xfersize = MIN(MIN(n, PAGE_SIZE), PAGE_SIZE-pageoff);
295 1.20.2.2 joerg uiomove((uint8_t *)pgs[i]->uanon + pageoff, xfersize, uio);
296 1.20.2.2 joerg if (uio->uio_rw == UIO_WRITE)
297 1.20.2.2 joerg pgs[i]->flags &= ~PG_CLEAN;
298 1.20.2.2 joerg n -= xfersize;
299 1.20.2.2 joerg }
300 1.20.2.2 joerg
301 1.20.2.2 joerg out:
302 1.20.2.2 joerg rumpuser_free(pgs);
303 1.20.2.3 joerg if (rvp)
304 1.20.2.3 joerg *rvp = rv;
305 1.20.2.3 joerg return 1;
306 1.20.2.2 joerg }
307 1.20.2.2 joerg
308 1.20.2.4 jmcneill static struct ubc_window *
309 1.20.2.4 jmcneill uwin_alloc(struct uvm_object *uobj, voff_t off, vsize_t len)
310 1.20.2.2 joerg {
311 1.20.2.3 joerg struct ubc_window *uwinp; /* pronounced: you wimp! */
312 1.20.2.2 joerg
313 1.20.2.3 joerg uwinp = kmem_alloc(sizeof(struct ubc_window), KM_SLEEP);
314 1.20.2.3 joerg uwinp->uwin_obj = uobj;
315 1.20.2.4 jmcneill uwinp->uwin_off = off;
316 1.20.2.4 jmcneill uwinp->uwin_mapsize = len;
317 1.20.2.4 jmcneill uwinp->uwin_mem = kmem_alloc(len, KM_SLEEP);
318 1.20.2.3 joerg
319 1.20.2.4 jmcneill return uwinp;
320 1.20.2.4 jmcneill }
321 1.20.2.4 jmcneill
322 1.20.2.4 jmcneill static void
323 1.20.2.4 jmcneill uwin_free(struct ubc_window *uwinp)
324 1.20.2.4 jmcneill {
325 1.20.2.4 jmcneill
326 1.20.2.4 jmcneill kmem_free(uwinp->uwin_mem, uwinp->uwin_mapsize);
327 1.20.2.4 jmcneill kmem_free(uwinp, sizeof(struct ubc_window));
328 1.20.2.4 jmcneill }
329 1.20.2.4 jmcneill
330 1.20.2.4 jmcneill void *
331 1.20.2.4 jmcneill ubc_alloc(struct uvm_object *uobj, voff_t offset, vsize_t *lenp, int advice,
332 1.20.2.4 jmcneill int flags)
333 1.20.2.4 jmcneill {
334 1.20.2.4 jmcneill struct ubc_window *uwinp;
335 1.20.2.4 jmcneill
336 1.20.2.4 jmcneill uwinp = uwin_alloc(uobj, offset, *lenp);
337 1.20.2.4 jmcneill mutex_enter(&uwinmtx);
338 1.20.2.3 joerg LIST_INSERT_HEAD(&uwinlst, uwinp, uwin_entries);
339 1.20.2.4 jmcneill mutex_exit(&uwinmtx);
340 1.20.2.3 joerg
341 1.20.2.3 joerg DPRINTF(("UBC_ALLOC offset 0x%llx, uwin %p, mem %p\n",
342 1.20.2.3 joerg (unsigned long long)offset, uwinp, uwinp->uwin_mem));
343 1.20.2.3 joerg
344 1.20.2.3 joerg return uwinp->uwin_mem;
345 1.20.2.2 joerg }
346 1.20.2.2 joerg
347 1.20.2.2 joerg void
348 1.20.2.2 joerg ubc_release(void *va, int flags)
349 1.20.2.2 joerg {
350 1.20.2.3 joerg struct ubc_window *uwinp;
351 1.20.2.2 joerg
352 1.20.2.4 jmcneill mutex_enter(&uwinmtx);
353 1.20.2.3 joerg LIST_FOREACH(uwinp, &uwinlst, uwin_entries)
354 1.20.2.3 joerg if ((uint8_t *)va >= uwinp->uwin_mem
355 1.20.2.3 joerg && (uint8_t *)va < (uwinp->uwin_mem + uwinp->uwin_mapsize))
356 1.20.2.3 joerg break;
357 1.20.2.4 jmcneill mutex_exit(&uwinmtx);
358 1.20.2.3 joerg if (uwinp == NULL)
359 1.20.2.3 joerg panic("%s: releasing invalid window at %p", __func__, va);
360 1.20.2.3 joerg
361 1.20.2.3 joerg LIST_REMOVE(uwinp, uwin_entries);
362 1.20.2.4 jmcneill uwin_free(uwinp);
363 1.20.2.2 joerg }
364 1.20.2.2 joerg
365 1.20.2.2 joerg int
366 1.20.2.2 joerg ubc_uiomove(struct uvm_object *uobj, struct uio *uio, vsize_t todo,
367 1.20.2.2 joerg int advice, int flags)
368 1.20.2.2 joerg {
369 1.20.2.4 jmcneill struct ubc_window *uwinp;
370 1.20.2.2 joerg vsize_t len;
371 1.20.2.2 joerg
372 1.20.2.2 joerg while (todo > 0) {
373 1.20.2.2 joerg len = todo;
374 1.20.2.2 joerg
375 1.20.2.4 jmcneill uwinp = uwin_alloc(uobj, uio->uio_offset, len);
376 1.20.2.4 jmcneill rump_ubc_magic_uiomove(uwinp->uwin_mem, len, uio, NULL, uwinp);
377 1.20.2.4 jmcneill uwin_free(uwinp);
378 1.20.2.2 joerg
379 1.20.2.2 joerg todo -= len;
380 1.20.2.2 joerg }
381 1.20.2.2 joerg return 0;
382 1.20.2.2 joerg }
383 1.20.2.2 joerg
384 1.20.2.2 joerg
385 1.20.2.2 joerg /*
386 1.20.2.2 joerg * Misc routines
387 1.20.2.2 joerg */
388 1.20.2.2 joerg
389 1.20.2.2 joerg void
390 1.20.2.2 joerg rumpvm_init()
391 1.20.2.2 joerg {
392 1.20.2.2 joerg
393 1.20.2.2 joerg uvm_vnodeops.pgo_get = vn_get;
394 1.20.2.2 joerg uvm_vnodeops.pgo_put = vn_put;
395 1.20.2.2 joerg aobj_pager.pgo_get = ao_get;
396 1.20.2.2 joerg aobj_pager.pgo_put = ao_put;
397 1.20.2.2 joerg
398 1.20.2.2 joerg uvmexp.free = 1024*1024; /* XXX */
399 1.20.2.2 joerg uvm.pagedaemon_lwp = NULL; /* doesn't match curlwp */
400 1.20.2.4 jmcneill
401 1.20.2.4 jmcneill mutex_init(&rvamtx, MUTEX_DEFAULT, 0);
402 1.20.2.4 jmcneill mutex_init(&uwinmtx, MUTEX_DEFAULT, 0);
403 1.20.2.2 joerg }
404 1.20.2.2 joerg
405 1.20.2.2 joerg void
406 1.20.2.2 joerg uvm_pageactivate(struct vm_page *pg)
407 1.20.2.2 joerg {
408 1.20.2.2 joerg
409 1.20.2.2 joerg /* nada */
410 1.20.2.2 joerg }
411 1.20.2.2 joerg
412 1.20.2.2 joerg void
413 1.20.2.2 joerg uvm_page_unbusy(struct vm_page **pgs, int npgs)
414 1.20.2.2 joerg {
415 1.20.2.2 joerg
416 1.20.2.2 joerg /* nada */
417 1.20.2.2 joerg }
418 1.20.2.2 joerg
419 1.20.2.2 joerg void
420 1.20.2.2 joerg uvm_pagewire(struct vm_page *pg)
421 1.20.2.2 joerg {
422 1.20.2.2 joerg
423 1.20.2.2 joerg /* nada */
424 1.20.2.2 joerg }
425 1.20.2.2 joerg
426 1.20.2.2 joerg void
427 1.20.2.2 joerg uvm_pageunwire(struct vm_page *pg)
428 1.20.2.2 joerg {
429 1.20.2.2 joerg
430 1.20.2.2 joerg /* nada */
431 1.20.2.2 joerg }
432 1.20.2.2 joerg
433 1.20.2.2 joerg vaddr_t
434 1.20.2.2 joerg uvm_pagermapin(struct vm_page **pps, int npages, int flags)
435 1.20.2.2 joerg {
436 1.20.2.2 joerg
437 1.20.2.2 joerg panic("%s: unimplemented", __func__);
438 1.20.2.2 joerg }
439 1.20.2.2 joerg
440 1.20.2.2 joerg struct vm_page *
441 1.20.2.2 joerg uvm_pagelookup(struct uvm_object *uobj, voff_t off)
442 1.20.2.2 joerg {
443 1.20.2.2 joerg struct vm_page *pg;
444 1.20.2.2 joerg
445 1.20.2.4 jmcneill simple_lock(&uobj->vmobjlock);
446 1.20.2.4 jmcneill TAILQ_FOREACH(pg, &uobj->memq, listq) {
447 1.20.2.4 jmcneill if (pg->offset == off) {
448 1.20.2.4 jmcneill simple_unlock(&uobj->vmobjlock);
449 1.20.2.2 joerg return pg;
450 1.20.2.4 jmcneill }
451 1.20.2.4 jmcneill }
452 1.20.2.4 jmcneill simple_unlock(&uobj->vmobjlock);
453 1.20.2.2 joerg
454 1.20.2.2 joerg return NULL;
455 1.20.2.2 joerg }
456 1.20.2.2 joerg
457 1.20.2.2 joerg struct vm_page *
458 1.20.2.2 joerg uvm_pageratop(vaddr_t va)
459 1.20.2.2 joerg {
460 1.20.2.2 joerg struct rumpva *rva;
461 1.20.2.2 joerg
462 1.20.2.4 jmcneill mutex_enter(&rvamtx);
463 1.20.2.2 joerg LIST_FOREACH(rva, &rvahead, entries)
464 1.20.2.2 joerg if (rva->addr == va)
465 1.20.2.4 jmcneill break;
466 1.20.2.4 jmcneill mutex_exit(&rvamtx);
467 1.20.2.4 jmcneill
468 1.20.2.4 jmcneill if (rva == NULL)
469 1.20.2.4 jmcneill panic("%s: va %llu", __func__, (unsigned long long)va);
470 1.20.2.2 joerg
471 1.20.2.4 jmcneill return rva->pg;
472 1.20.2.2 joerg }
473 1.20.2.2 joerg
474 1.20.2.2 joerg void
475 1.20.2.2 joerg uvm_estimatepageable(int *active, int *inactive)
476 1.20.2.2 joerg {
477 1.20.2.2 joerg
478 1.20.2.2 joerg /* XXX: guessing game */
479 1.20.2.2 joerg *active = 1024;
480 1.20.2.2 joerg *inactive = 1024;
481 1.20.2.2 joerg }
482 1.20.2.2 joerg
483 1.20.2.2 joerg void
484 1.20.2.2 joerg uvm_aio_biodone1(struct buf *bp)
485 1.20.2.2 joerg {
486 1.20.2.2 joerg
487 1.20.2.2 joerg panic("%s: unimplemented", __func__);
488 1.20.2.2 joerg }
489 1.20.2.2 joerg
490 1.20.2.2 joerg void
491 1.20.2.2 joerg uvm_aio_biodone(struct buf *bp)
492 1.20.2.2 joerg {
493 1.20.2.2 joerg
494 1.20.2.2 joerg uvm_aio_aiodone(bp);
495 1.20.2.2 joerg }
496 1.20.2.2 joerg
497 1.20.2.2 joerg void
498 1.20.2.2 joerg uvm_aio_aiodone(struct buf *bp)
499 1.20.2.2 joerg {
500 1.20.2.2 joerg
501 1.20.2.2 joerg if ((bp->b_flags & (B_READ | B_NOCACHE)) == 0 && bioopsp)
502 1.20.2.2 joerg bioopsp->io_pageiodone(bp);
503 1.20.2.2 joerg }
504 1.20.2.2 joerg
505 1.20.2.2 joerg void
506 1.20.2.2 joerg uvm_vnp_setsize(struct vnode *vp, voff_t newsize)
507 1.20.2.2 joerg {
508 1.20.2.2 joerg
509 1.20.2.2 joerg vp->v_size = vp->v_writesize = newsize;
510 1.20.2.2 joerg }
511 1.20.2.2 joerg
512 1.20.2.2 joerg void
513 1.20.2.2 joerg uvm_vnp_setwritesize(struct vnode *vp, voff_t newsize)
514 1.20.2.2 joerg {
515 1.20.2.2 joerg
516 1.20.2.2 joerg vp->v_writesize = newsize;
517 1.20.2.2 joerg }
518 1.20.2.2 joerg
519 1.20.2.2 joerg void
520 1.20.2.2 joerg uvm_vnp_zerorange(struct vnode *vp, off_t off, size_t len)
521 1.20.2.2 joerg {
522 1.20.2.2 joerg struct uvm_object *uobj = &vp->v_uobj;
523 1.20.2.2 joerg struct vm_page **pgs;
524 1.20.2.2 joerg int maxpages = MIN(32, round_page(len) >> PAGE_SHIFT);
525 1.20.2.2 joerg int rv, npages, i;
526 1.20.2.2 joerg
527 1.20.2.2 joerg pgs = rumpuser_malloc(maxpages * sizeof(pgs), 0);
528 1.20.2.2 joerg while (len) {
529 1.20.2.2 joerg npages = MIN(maxpages, round_page(len) >> PAGE_SHIFT);
530 1.20.2.2 joerg memset(pgs, 0, npages * sizeof(struct vm_page *));
531 1.20.2.2 joerg rv = uobj->pgops->pgo_get(uobj, off, pgs, &npages, 0, 0, 0, 0);
532 1.20.2.2 joerg assert(npages > 0);
533 1.20.2.2 joerg
534 1.20.2.2 joerg for (i = 0; i < npages; i++) {
535 1.20.2.2 joerg uint8_t *start;
536 1.20.2.2 joerg size_t chunkoff, chunklen;
537 1.20.2.2 joerg
538 1.20.2.2 joerg chunkoff = off & PAGE_MASK;
539 1.20.2.2 joerg chunklen = MIN(PAGE_SIZE - chunkoff, len);
540 1.20.2.2 joerg start = (uint8_t *)pgs[i]->uanon + chunkoff;
541 1.20.2.2 joerg
542 1.20.2.2 joerg memset(start, 0, chunklen);
543 1.20.2.2 joerg pgs[i]->flags &= PG_CLEAN;
544 1.20.2.2 joerg
545 1.20.2.2 joerg off += chunklen;
546 1.20.2.2 joerg len -= chunklen;
547 1.20.2.2 joerg }
548 1.20.2.2 joerg }
549 1.20.2.2 joerg rumpuser_free(pgs);
550 1.20.2.2 joerg
551 1.20.2.2 joerg return;
552 1.20.2.2 joerg }
553 1.20.2.2 joerg
554 1.20.2.2 joerg struct uvm_ractx *
555 1.20.2.2 joerg uvm_ra_allocctx()
556 1.20.2.2 joerg {
557 1.20.2.2 joerg
558 1.20.2.2 joerg return NULL;
559 1.20.2.2 joerg }
560 1.20.2.2 joerg
561 1.20.2.2 joerg void
562 1.20.2.2 joerg uvm_ra_freectx(struct uvm_ractx *ra)
563 1.20.2.2 joerg {
564 1.20.2.2 joerg
565 1.20.2.2 joerg return;
566 1.20.2.2 joerg }
567 1.20.2.2 joerg
568 1.20.2.2 joerg bool
569 1.20.2.2 joerg uvn_clean_p(struct uvm_object *uobj)
570 1.20.2.2 joerg {
571 1.20.2.2 joerg struct vnode *vp = (void *)uobj;
572 1.20.2.2 joerg
573 1.20.2.2 joerg return (vp->v_iflag & VI_ONWORKLST) == 0;
574 1.20.2.2 joerg }
575 1.20.2.2 joerg
576 1.20.2.2 joerg /*
577 1.20.2.2 joerg * Kmem
578 1.20.2.2 joerg */
579 1.20.2.2 joerg
580 1.20.2.2 joerg void *
581 1.20.2.2 joerg kmem_alloc(size_t size, km_flag_t kmflag)
582 1.20.2.2 joerg {
583 1.20.2.2 joerg
584 1.20.2.2 joerg return rumpuser_malloc(size, kmflag == KM_NOSLEEP);
585 1.20.2.2 joerg }
586 1.20.2.2 joerg
587 1.20.2.2 joerg void *
588 1.20.2.2 joerg kmem_zalloc(size_t size, km_flag_t kmflag)
589 1.20.2.2 joerg {
590 1.20.2.2 joerg void *rv;
591 1.20.2.2 joerg
592 1.20.2.2 joerg rv = kmem_alloc(size, kmflag);
593 1.20.2.2 joerg if (rv)
594 1.20.2.2 joerg memset(rv, 0, size);
595 1.20.2.2 joerg
596 1.20.2.2 joerg return rv;
597 1.20.2.2 joerg }
598 1.20.2.2 joerg
599 1.20.2.2 joerg void
600 1.20.2.2 joerg kmem_free(void *p, size_t size)
601 1.20.2.2 joerg {
602 1.20.2.2 joerg
603 1.20.2.2 joerg rumpuser_free(p);
604 1.20.2.2 joerg }
605 1.20.2.2 joerg
606 1.20.2.2 joerg /*
607 1.20.2.2 joerg * UVM km
608 1.20.2.2 joerg */
609 1.20.2.2 joerg
610 1.20.2.2 joerg vaddr_t
611 1.20.2.2 joerg uvm_km_alloc(struct vm_map *map, vsize_t size, vsize_t align, uvm_flag_t flags)
612 1.20.2.2 joerg {
613 1.20.2.2 joerg void *rv;
614 1.20.2.2 joerg
615 1.20.2.2 joerg rv = rumpuser_malloc(size, flags & (UVM_KMF_CANFAIL | UVM_KMF_NOWAIT));
616 1.20.2.2 joerg if (rv && flags & UVM_KMF_ZERO)
617 1.20.2.2 joerg memset(rv, 0, size);
618 1.20.2.2 joerg
619 1.20.2.2 joerg return (vaddr_t)rv;
620 1.20.2.2 joerg }
621 1.20.2.2 joerg
622 1.20.2.2 joerg void
623 1.20.2.2 joerg uvm_km_free(struct vm_map *map, vaddr_t vaddr, vsize_t size, uvm_flag_t flags)
624 1.20.2.2 joerg {
625 1.20.2.2 joerg
626 1.20.2.2 joerg rumpuser_free((void *)vaddr);
627 1.20.2.2 joerg }
628 1.20.2.2 joerg
629 1.20.2.2 joerg struct vm_map *
630 1.20.2.2 joerg uvm_km_suballoc(struct vm_map *map, vaddr_t *minaddr, vaddr_t *maxaddr,
631 1.20.2.2 joerg vsize_t size, int pageable, bool fixed, struct vm_map_kernel *submap)
632 1.20.2.2 joerg {
633 1.20.2.2 joerg
634 1.20.2.2 joerg return (struct vm_map *)417416;
635 1.20.2.2 joerg }
636