コード例 #1
0
static int
netmap_dev_pager_fault(vm_object_t object, vm_ooffset_t offset,
                       int prot, vm_page_t *mres)
{
    struct netmap_vm_handle_t *vmh = object->handle;
    struct netmap_priv_d *priv = vmh->priv;
    vm_paddr_t paddr;
    vm_page_t page;
    vm_memattr_t memattr;
    vm_pindex_t pidx;

    ND("object %p offset %jd prot %d mres %p",
       object, (intmax_t)offset, prot, mres);
    memattr = object->memattr;
    pidx = OFF_TO_IDX(offset);
    paddr = netmap_mem_ofstophys(priv->np_mref, offset);
    if (paddr == 0)
        return VM_PAGER_FAIL;

    if (((*mres)->flags & PG_FICTITIOUS) != 0) {
        /*
         * If the passed in result page is a fake page, update it with
         * the new physical address.
         */
        page = *mres;
        vm_page_updatefake(page, paddr, memattr);
    } else {
        /*
         * Replace the passed in reqpage page with our own fake page and
         * free up the all of the original pages.
         */
#ifndef VM_OBJECT_WUNLOCK	/* FreeBSD < 10.x */
#define VM_OBJECT_WUNLOCK VM_OBJECT_UNLOCK
#define VM_OBJECT_WLOCK	VM_OBJECT_LOCK
#endif /* VM_OBJECT_WUNLOCK */

        VM_OBJECT_WUNLOCK(object);
        page = vm_page_getfake(paddr, memattr);
        VM_OBJECT_WLOCK(object);
        vm_page_free(*mres);
        *mres = page;
        vm_page_insert(page, object, pidx);
    }
    page->valid = VM_PAGE_BITS_ALL;
    return (VM_PAGER_OK);
}
コード例 #2
0
ファイル: sg_pager.c プロジェクト: JabirTech/Source
static int
sg_pager_getpages(vm_object_t object, vm_page_t *m, int count, int reqpage)
{
	struct sglist *sg;
	vm_page_t m_paddr, page;
	vm_pindex_t offset;
	vm_paddr_t paddr;
	vm_memattr_t memattr;
	size_t space;
	int i;

	VM_OBJECT_ASSERT_WLOCKED(object);
	sg = object->handle;
	memattr = object->memattr;
	VM_OBJECT_WUNLOCK(object);
	offset = m[reqpage]->pindex;

	/*
	 * Lookup the physical address of the requested page.  An initial
	 * value of '1' instead of '0' is used so we can assert that the
	 * page is found since '0' can be a valid page-aligned physical
	 * address.
	 */
	space = 0;
	paddr = 1;
	for (i = 0; i < sg->sg_nseg; i++) {
		if (space + sg->sg_segs[i].ss_len <= (offset * PAGE_SIZE)) {
			space += sg->sg_segs[i].ss_len;
			continue;
		}
		paddr = sg->sg_segs[i].ss_paddr + offset * PAGE_SIZE - space;
		break;
	}
	KASSERT(paddr != 1, ("invalid SG page index"));

	/* If "paddr" is a real page, perform a sanity check on "memattr". */
	if ((m_paddr = vm_phys_paddr_to_vm_page(paddr)) != NULL &&
	    pmap_page_get_memattr(m_paddr) != memattr) {
		memattr = pmap_page_get_memattr(m_paddr);
		printf(
	    "WARNING: A device driver has set \"memattr\" inconsistently.\n");
	}

	/* Return a fake page for the requested page. */
	KASSERT(!(m[reqpage]->flags & PG_FICTITIOUS),
	    ("backing page for SG is fake"));

	/* Construct a new fake page. */
	page = vm_page_getfake(paddr, memattr);
	VM_OBJECT_WLOCK(object);
	TAILQ_INSERT_TAIL(&object->un_pager.sgp.sgp_pglist, page, plinks.q);

	/* Free the original pages and insert this fake page into the object. */
	for (i = 0; i < count; i++) {
		if (i == reqpage &&
		    vm_page_replace(page, object, offset) != m[i])
			panic("sg_pager_getpages: invalid place replacement");
		vm_page_lock(m[i]);
		vm_page_free(m[i]);
		vm_page_unlock(m[i]);
	}
	m[reqpage] = page;
	page->valid = VM_PAGE_BITS_ALL;

	return (VM_PAGER_OK);
}
コード例 #3
0
/* See: old_dev_pager_fault() in device_pager.c as an example. */
static int
cheri_compositor_cfb_pg_fault(vm_object_t vm_obj, vm_ooffset_t offset, int prot,
    vm_page_t *mres)
{
	vm_pindex_t pidx;
	vm_paddr_t paddr;
	vm_page_t page;
	struct cfb_vm_object *cfb_vm_obj;
	struct cdev *dev;
	struct cheri_compositor_softc *sc;
	struct cdevsw *csw;
	vm_memattr_t memattr;
	int ref;
	int retval;

	pidx = OFF_TO_IDX(offset);

	VM_OBJECT_WUNLOCK(vm_obj);

	cfb_vm_obj = vm_obj->handle;
	dev = cfb_vm_obj->dev;
	sc = dev->si_drv1;

	retval = VM_PAGER_OK;

	CHERI_COMPOSITOR_DEBUG(sc, "vm_obj: %p, offset: %lu, prot: %i", vm_obj,
	    offset, prot);

	csw = dev_refthread(dev, &ref);

	if (csw == NULL) {
		retval = VM_PAGER_FAIL;
		goto done_unlocked;
	}

	/* Traditional d_mmap() call. */
	CHERI_COMPOSITOR_DEBUG(sc, "offset: %lu, nprot: %i", offset, prot);

	if (validate_prot_and_offset(sc, cfb_vm_obj->pool->mapped_fd,
	    prot, offset) != 0) {
		retval = VM_PAGER_FAIL;
		goto done_unlocked;
	}

	paddr = calculate_physical_address(sc, cfb_vm_obj->pool, offset);
	memattr = VM_MEMATTR_UNCACHEABLE;

	CHERI_COMPOSITOR_DEBUG(sc, "paddr: %p, memattr: %i",
	    (void *) paddr, memattr);

	dev_relthread(dev, ref);

	/* Sanity checks. */
	KASSERT((((*mres)->flags & PG_FICTITIOUS) == 0),
	    ("Expected non-fictitious page."));

	/*
	 * Replace the passed in reqpage page with our own fake page and
	 * free up the all of the original pages.
	 */
	page = vm_page_getfake(paddr, memattr);
	VM_OBJECT_WLOCK(vm_obj);
	vm_page_lock(*mres);
	vm_page_free(*mres);
	vm_page_unlock(*mres);
	*mres = page;
	vm_page_insert(page, vm_obj, pidx);

	page->valid = VM_PAGE_BITS_ALL;

	/* Success! */
	retval = VM_PAGER_OK;
	goto done;

done_unlocked:
	VM_OBJECT_WLOCK(vm_obj);
done:
	CHERI_COMPOSITOR_DEBUG(sc, "Finished with mres: %p (retval: %i)", *mres,
	    retval);

	return (retval);
}