2001-11-10 10:36:59 +03:00
|
|
|
/* $NetBSD: uvm_device.c,v 1.39 2001/11/10 07:36:59 lukem Exp $ */
|
1998-02-07 14:07:38 +03:00
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997 Charles D. Cranor and Washington University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Charles D. Cranor and
|
|
|
|
* Washington University.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1998-02-07 14:07:38 +03:00
|
|
|
*
|
|
|
|
* from: Id: uvm_device.c,v 1.1.2.9 1998/02/06 05:11:47 chs Exp
|
1998-02-05 09:25:08 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_device.c: the device pager.
|
|
|
|
*/
|
|
|
|
|
2001-11-10 10:36:59 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: uvm_device.c,v 1.39 2001/11/10 07:36:59 lukem Exp $");
|
|
|
|
|
|
|
|
#include "opt_uvmhist.h"
|
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
|
|
|
#include <uvm/uvm.h>
|
|
|
|
#include <uvm/uvm_device.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* private global data structure
|
|
|
|
*
|
|
|
|
* we keep a list of active device objects in the system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
LIST_HEAD(udv_list_struct, uvm_device);
|
|
|
|
static struct udv_list_struct udv_list;
|
2001-05-26 20:32:40 +04:00
|
|
|
static struct simplelock udv_lock;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* functions
|
|
|
|
*/
|
|
|
|
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
static void udv_init __P((void));
|
|
|
|
static void udv_reference __P((struct uvm_object *));
|
|
|
|
static void udv_detach __P((struct uvm_object *));
|
|
|
|
static int udv_fault __P((struct uvm_faultinfo *, vaddr_t,
|
|
|
|
struct vm_page **, int, int, vm_fault_t, vm_prot_t, int));
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* master pager structure
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct uvm_pagerops uvm_deviceops = {
|
1998-03-09 03:58:55 +03:00
|
|
|
udv_init,
|
|
|
|
udv_reference,
|
|
|
|
udv_detach,
|
|
|
|
udv_fault,
|
1998-02-05 09:25:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the ops!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* udv_init
|
|
|
|
*
|
|
|
|
* init pager private data structures.
|
|
|
|
*/
|
|
|
|
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
static void
|
|
|
|
udv_init(void)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-03-09 03:58:55 +03:00
|
|
|
LIST_INIT(&udv_list);
|
|
|
|
simple_lock_init(&udv_lock);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* udv_attach
|
|
|
|
*
|
|
|
|
* get a VM object that is associated with a device. allocate a new
|
|
|
|
* one if needed.
|
|
|
|
*
|
|
|
|
* => caller must _not_ already be holding the lock on the uvm_object.
|
|
|
|
* => in fact, nothing should be locked so that we can sleep here.
|
|
|
|
*/
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
struct uvm_object *
|
1999-03-24 06:52:41 +03:00
|
|
|
udv_attach(arg, accessprot, off, size)
|
1998-03-09 03:58:55 +03:00
|
|
|
void *arg;
|
|
|
|
vm_prot_t accessprot;
|
2000-05-28 14:21:55 +04:00
|
|
|
voff_t off; /* used only for access check */
|
1999-03-24 06:52:41 +03:00
|
|
|
vsize_t size; /* used only for access check */
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
2000-11-25 09:27:59 +03:00
|
|
|
dev_t device = *((dev_t *)arg);
|
1998-03-09 03:58:55 +03:00
|
|
|
struct uvm_device *udv, *lcv;
|
2000-06-26 08:55:19 +04:00
|
|
|
paddr_t (*mapfn) __P((dev_t, off_t, int));
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_FUNC("udv_attach"); UVMHIST_CALLED(maphist);
|
|
|
|
|
|
|
|
UVMHIST_LOG(maphist, "(device=0x%x)", device,0,0,0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* before we do anything, ensure this device supports mmap
|
|
|
|
*/
|
|
|
|
|
|
|
|
mapfn = cdevsw[major(device)].d_mmap;
|
|
|
|
if (mapfn == NULL ||
|
2000-11-25 09:27:59 +03:00
|
|
|
mapfn == (paddr_t (*) __P((dev_t, off_t, int))) enodev ||
|
|
|
|
mapfn == (paddr_t (*) __P((dev_t, off_t, int))) nullop)
|
1998-03-09 03:58:55 +03:00
|
|
|
return(NULL);
|
|
|
|
|
2000-05-28 14:21:55 +04:00
|
|
|
/*
|
2000-06-26 08:55:19 +04:00
|
|
|
* Negative offsets on the object are not allowed.
|
2000-05-28 14:21:55 +04:00
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
2000-06-26 08:55:19 +04:00
|
|
|
if (off < 0)
|
|
|
|
return(NULL);
|
2000-05-28 14:21:55 +04:00
|
|
|
|
1999-03-24 06:52:41 +03:00
|
|
|
/*
|
|
|
|
* Check that the specified range of the device allows the
|
|
|
|
* desired protection.
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
1999-03-24 06:52:41 +03:00
|
|
|
* XXX assumes VM_PROT_* == PROT_*
|
|
|
|
* XXX clobbers off and size, but nothing else here needs them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (size != 0) {
|
|
|
|
if ((*mapfn)(device, off, accessprot) == -1)
|
|
|
|
return (NULL);
|
1999-04-08 14:26:21 +04:00
|
|
|
off += PAGE_SIZE; size -= PAGE_SIZE;
|
1999-03-24 06:52:41 +03:00
|
|
|
}
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* keep looping until we get it
|
|
|
|
*/
|
|
|
|
|
2000-11-25 09:27:59 +03:00
|
|
|
for (;;) {
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
2001-05-25 08:06:11 +04:00
|
|
|
* first, attempt to find it on the main list
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
simple_lock(&udv_lock);
|
2000-11-25 09:27:59 +03:00
|
|
|
LIST_FOREACH(lcv, &udv_list, u_list) {
|
1998-03-09 03:58:55 +03:00
|
|
|
if (device == lcv->u_device)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* got it on main list. put a hold on it and unlock udv_lock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (lcv) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if someone else has a hold on it, sleep and start
|
|
|
|
* over again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (lcv->u_flags & UVM_DEVICE_HOLD) {
|
|
|
|
lcv->u_flags |= UVM_DEVICE_WANTED;
|
|
|
|
UVM_UNLOCK_AND_WAIT(lcv, &udv_lock, FALSE,
|
|
|
|
"udv_attach",0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we are now holding it */
|
|
|
|
lcv->u_flags |= UVM_DEVICE_HOLD;
|
|
|
|
simple_unlock(&udv_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bump reference count, unhold, return.
|
|
|
|
*/
|
|
|
|
|
|
|
|
simple_lock(&lcv->u_obj.vmobjlock);
|
|
|
|
lcv->u_obj.uo_refs++;
|
|
|
|
simple_unlock(&lcv->u_obj.vmobjlock);
|
2000-11-25 09:27:59 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
simple_lock(&udv_lock);
|
|
|
|
if (lcv->u_flags & UVM_DEVICE_WANTED)
|
|
|
|
wakeup(lcv);
|
|
|
|
lcv->u_flags &= ~(UVM_DEVICE_WANTED|UVM_DEVICE_HOLD);
|
|
|
|
simple_unlock(&udv_lock);
|
|
|
|
return(&lcv->u_obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* did not find it on main list. need to malloc a new one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
simple_unlock(&udv_lock);
|
|
|
|
/* NOTE: we could sleep in the following malloc() */
|
2000-11-25 09:27:59 +03:00
|
|
|
MALLOC(udv, struct uvm_device *, sizeof(*udv), M_TEMP,
|
|
|
|
M_WAITOK);
|
1998-03-09 03:58:55 +03:00
|
|
|
simple_lock(&udv_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now we have to double check to make sure no one added it
|
|
|
|
* to the list while we were sleeping...
|
|
|
|
*/
|
|
|
|
|
2000-11-25 09:27:59 +03:00
|
|
|
LIST_FOREACH(lcv, &udv_list, u_list) {
|
1998-03-09 03:58:55 +03:00
|
|
|
if (device == lcv->u_device)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-11-25 09:27:59 +03:00
|
|
|
* did we lose a race to someone else?
|
|
|
|
* free our memory and retry.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (lcv) {
|
|
|
|
simple_unlock(&udv_lock);
|
|
|
|
FREE(udv, M_TEMP);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have it! init the data structures, add to list
|
|
|
|
* and return.
|
|
|
|
*/
|
|
|
|
|
|
|
|
simple_lock_init(&udv->u_obj.vmobjlock);
|
|
|
|
udv->u_obj.pgops = &uvm_deviceops;
|
2000-11-25 09:27:59 +03:00
|
|
|
TAILQ_INIT(&udv->u_obj.memq);
|
1998-03-09 03:58:55 +03:00
|
|
|
udv->u_obj.uo_npages = 0;
|
|
|
|
udv->u_obj.uo_refs = 1;
|
|
|
|
udv->u_flags = 0;
|
|
|
|
udv->u_device = device;
|
|
|
|
LIST_INSERT_HEAD(&udv_list, udv, u_list);
|
|
|
|
simple_unlock(&udv_lock);
|
|
|
|
return(&udv->u_obj);
|
2000-11-25 09:27:59 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
/*NOTREACHED*/
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
2001-05-25 08:06:11 +04:00
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*
|
|
|
|
* udv_reference
|
|
|
|
*
|
|
|
|
* add a reference to a VM object. Note that the reference count must
|
|
|
|
* already be one (the passed in reference) so there is no chance of the
|
|
|
|
* udv being released or locked out here.
|
|
|
|
*
|
|
|
|
* => caller must call with object unlocked.
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
static void
|
|
|
|
udv_reference(uobj)
|
|
|
|
struct uvm_object *uobj;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_FUNC("udv_reference"); UVMHIST_CALLED(maphist);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
simple_lock(&uobj->vmobjlock);
|
|
|
|
uobj->uo_refs++;
|
2001-05-25 08:06:11 +04:00
|
|
|
UVMHIST_LOG(maphist, "<- done (uobj=0x%x, ref = %d)",
|
2000-11-25 09:27:59 +03:00
|
|
|
uobj, uobj->uo_refs,0,0);
|
1998-03-09 03:58:55 +03:00
|
|
|
simple_unlock(&uobj->vmobjlock);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* udv_detach
|
|
|
|
*
|
|
|
|
* remove a reference to a VM object.
|
|
|
|
*
|
|
|
|
* => caller must call with object unlocked and map locked.
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
static void
|
|
|
|
udv_detach(uobj)
|
|
|
|
struct uvm_object *uobj;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
2000-11-25 09:27:59 +03:00
|
|
|
struct uvm_device *udv = (struct uvm_device *)uobj;
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_FUNC("udv_detach"); UVMHIST_CALLED(maphist);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* loop until done
|
|
|
|
*/
|
2000-06-25 01:47:28 +04:00
|
|
|
again:
|
|
|
|
simple_lock(&uobj->vmobjlock);
|
|
|
|
if (uobj->uo_refs > 1) {
|
2000-11-25 09:27:59 +03:00
|
|
|
uobj->uo_refs--;
|
2000-06-25 01:47:28 +04:00
|
|
|
simple_unlock(&uobj->vmobjlock);
|
2001-05-25 08:06:11 +04:00
|
|
|
UVMHIST_LOG(maphist," <- done, uobj=0x%x, ref=%d",
|
2000-06-25 01:47:28 +04:00
|
|
|
uobj,uobj->uo_refs,0,0);
|
|
|
|
return;
|
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
2000-06-25 01:47:28 +04:00
|
|
|
/*
|
|
|
|
* is it being held? if so, wait until others are done.
|
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
|
|
|
simple_lock(&udv_lock);
|
2000-06-25 01:47:28 +04:00
|
|
|
if (udv->u_flags & UVM_DEVICE_HOLD) {
|
|
|
|
udv->u_flags |= UVM_DEVICE_WANTED;
|
2000-06-25 01:26:16 +04:00
|
|
|
simple_unlock(&uobj->vmobjlock);
|
2000-06-25 01:47:28 +04:00
|
|
|
UVM_UNLOCK_AND_WAIT(udv, &udv_lock, FALSE, "udv_detach",0);
|
|
|
|
goto again;
|
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
2000-06-25 01:47:28 +04:00
|
|
|
/*
|
|
|
|
* got it! nuke it now.
|
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
2000-06-25 01:47:28 +04:00
|
|
|
LIST_REMOVE(udv, u_list);
|
|
|
|
if (udv->u_flags & UVM_DEVICE_WANTED)
|
|
|
|
wakeup(udv);
|
|
|
|
simple_unlock(&udv_lock);
|
|
|
|
simple_unlock(&uobj->vmobjlock);
|
|
|
|
FREE(udv, M_TEMP);
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist," <- done, freed uobj=0x%x", uobj,0,0,0);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* udv_fault: non-standard fault routine for device "pages"
|
|
|
|
*
|
|
|
|
* => rather than having a "get" function, we have a fault routine
|
|
|
|
* since we don't return vm_pages we need full control over the
|
|
|
|
* pmap_enter map in
|
|
|
|
* => all the usual fault data structured are locked by the caller
|
|
|
|
* (i.e. maps(read), amap (if any), uobj)
|
|
|
|
* => on return, we unlock all fault data structures
|
|
|
|
* => flags: PGO_ALLPAGES: get all of the pages
|
|
|
|
* PGO_LOCKED: fault data structures are locked
|
|
|
|
* XXX: currently PGO_LOCKED is always required ... consider removing
|
|
|
|
* it as a flag
|
|
|
|
* => NOTE: vaddr is the VA of pps[0] in ufi->entry, _NOT_ pps[centeridx]
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
static int
|
|
|
|
udv_fault(ufi, vaddr, pps, npages, centeridx, fault_type, access_type, flags)
|
|
|
|
struct uvm_faultinfo *ufi;
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t vaddr;
|
2001-05-27 01:27:10 +04:00
|
|
|
struct vm_page **pps;
|
1998-03-09 03:58:55 +03:00
|
|
|
int npages, centeridx, flags;
|
|
|
|
vm_fault_t fault_type;
|
|
|
|
vm_prot_t access_type;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_map_entry *entry = ufi->entry;
|
|
|
|
struct uvm_object *uobj = entry->object.uvm_obj;
|
|
|
|
struct uvm_device *udv = (struct uvm_device *)uobj;
|
2000-03-27 00:54:45 +04:00
|
|
|
vaddr_t curr_va;
|
2000-06-27 10:14:24 +04:00
|
|
|
off_t curr_offset;
|
2000-06-26 08:55:19 +04:00
|
|
|
paddr_t paddr, mdpgno;
|
|
|
|
int lcv, retval;
|
1998-03-09 03:58:55 +03:00
|
|
|
dev_t device;
|
2000-06-26 08:55:19 +04:00
|
|
|
paddr_t (*mapfn) __P((dev_t, off_t, int));
|
1999-10-24 20:29:23 +04:00
|
|
|
vm_prot_t mapprot;
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_FUNC("udv_fault"); UVMHIST_CALLED(maphist);
|
|
|
|
UVMHIST_LOG(maphist," flags=%d", flags,0,0,0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we do not allow device mappings to be mapped copy-on-write
|
|
|
|
* so we kill any attempt to do so here.
|
|
|
|
*/
|
2001-05-25 08:06:11 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
if (UVM_ET_ISCOPYONWRITE(entry)) {
|
2001-05-25 08:06:11 +04:00
|
|
|
UVMHIST_LOG(maphist, "<- failed -- COW entry (etype=0x%x)",
|
1998-02-05 09:25:08 +03:00
|
|
|
entry->etype, 0,0,0);
|
1998-03-09 03:58:55 +03:00
|
|
|
uvmfault_unlockall(ufi, ufi->entry->aref.ar_amap, uobj, NULL);
|
2001-03-11 01:46:45 +03:00
|
|
|
return(EIO);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-25 08:06:11 +04:00
|
|
|
* get device map function.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
device = udv->u_device;
|
|
|
|
mapfn = cdevsw[major(device)].d_mmap;
|
|
|
|
|
|
|
|
/*
|
1998-10-12 03:02:31 +04:00
|
|
|
* now we must determine the offset in udv to use and the VA to
|
|
|
|
* use for pmap_enter. note that we always use orig_map's pmap
|
|
|
|
* for pmap_enter (even if we have a submap). since virtual
|
|
|
|
* addresses in a submap must match the main map, this is ok.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2000-11-25 09:27:59 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/* udv offset = (offset from start of entry) + entry's offset */
|
2000-06-27 10:14:24 +04:00
|
|
|
curr_offset = entry->offset + (vaddr - entry->start);
|
1998-10-12 03:02:31 +04:00
|
|
|
/* pmap va = vaddr (virtual address of pps[0]) */
|
|
|
|
curr_va = vaddr;
|
2001-05-25 08:06:11 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* loop over the page range entering in as needed
|
|
|
|
*/
|
|
|
|
|
2001-03-11 01:46:45 +03:00
|
|
|
retval = 0;
|
1998-03-09 03:58:55 +03:00
|
|
|
for (lcv = 0 ; lcv < npages ; lcv++, curr_offset += PAGE_SIZE,
|
|
|
|
curr_va += PAGE_SIZE) {
|
|
|
|
if ((flags & PGO_ALLPAGES) == 0 && lcv != centeridx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pps[lcv] == PGO_DONTCARE)
|
|
|
|
continue;
|
|
|
|
|
2000-03-27 00:54:45 +04:00
|
|
|
mdpgno = (*mapfn)(device, curr_offset, access_type);
|
1998-11-19 08:23:26 +03:00
|
|
|
if (mdpgno == -1) {
|
2001-03-11 01:46:45 +03:00
|
|
|
retval = EIO;
|
1998-03-09 03:58:55 +03:00
|
|
|
break;
|
|
|
|
}
|
1998-11-19 08:23:26 +03:00
|
|
|
paddr = pmap_phys_address(mdpgno);
|
1999-10-24 20:29:23 +04:00
|
|
|
mapprot = ufi->entry->protection;
|
1998-03-09 03:58:55 +03:00
|
|
|
UVMHIST_LOG(maphist,
|
2000-06-27 10:14:24 +04:00
|
|
|
" MAPPING: device: pm=0x%x, va=0x%x, pa=0x%lx, at=%d",
|
|
|
|
ufi->orig_map->pmap, curr_va, paddr, mapprot);
|
1999-11-13 03:24:38 +03:00
|
|
|
if (pmap_enter(ufi->orig_map->pmap, curr_va, paddr,
|
2001-03-15 09:10:32 +03:00
|
|
|
mapprot, PMAP_CANFAIL | mapprot) != 0) {
|
1999-11-13 03:24:38 +03:00
|
|
|
/*
|
|
|
|
* pmap_enter() didn't have the resource to
|
|
|
|
* enter this mapping. Unlock everything,
|
|
|
|
* wait for the pagedaemon to free up some
|
|
|
|
* pages, and then tell uvm_fault() to start
|
|
|
|
* the fault again.
|
|
|
|
*
|
|
|
|
* XXX Needs some rethinking for the PGO_ALLPAGES
|
|
|
|
* XXX case.
|
|
|
|
*/
|
|
|
|
uvmfault_unlockall(ufi, ufi->entry->aref.ar_amap,
|
|
|
|
uobj, NULL);
|
2001-09-11 01:19:08 +04:00
|
|
|
pmap_update(ufi->orig_map->pmap); /* sync what we have so far */
|
1999-11-13 03:24:38 +03:00
|
|
|
uvm_wait("udv_fault");
|
2001-03-11 01:46:45 +03:00
|
|
|
return (ERESTART);
|
1999-11-13 03:24:38 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uvmfault_unlockall(ufi, ufi->entry->aref.ar_amap, uobj, NULL);
|
2001-09-11 01:19:08 +04:00
|
|
|
pmap_update(ufi->orig_map->pmap);
|
1999-11-13 03:24:38 +03:00
|
|
|
return (retval);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|