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