Home | History | Annotate | Line # | Download | only in uvm
uvm_object.h revision 1.29.4.1
      1 /*	$NetBSD: uvm_object.h,v 1.29.4.1 2011/02/08 16:20:07 bouyer Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  *
     27  * from: Id: uvm_object.h,v 1.1.2.2 1998/01/04 22:44:51 chuck Exp
     28  */
     29 
     30 #ifndef _UVM_UVM_OBJECT_H_
     31 #define _UVM_UVM_OBJECT_H_
     32 
     33 /*
     34  * uvm_object.h
     35  */
     36 
     37 #include <sys/rbtree.h>
     38 #include <uvm/uvm_pglist.h>
     39 
     40 /*
     41  * uvm_object: all that is left of mach objects.
     42  */
     43 
     44 struct uvm_object {
     45 	kmutex_t		vmobjlock;	/* lock on memq */
     46 	const struct uvm_pagerops *pgops;	/* pager ops */
     47 	struct pglist		memq;		/* pages in this object */
     48 	int			uo_npages;	/* # of pages in memq */
     49 	unsigned		uo_refs;	/* reference count */
     50 	struct rb_tree		rb_tree;	/* tree of pages */
     51 };
     52 
     53 /*
     54  * UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the
     55  * object is a kernel memory object rather than a normal one (kernel
     56  * memory objects don't have reference counts -- they never die).
     57  *
     58  * this value is used to detected kernel object mappings at uvm_unmap()
     59  * time.   normally when an object is unmapped its pages eventaully become
     60  * deactivated and then paged out and/or freed.    this is not useful
     61  * for kernel objects... when a kernel object is unmapped we always want
     62  * to free the resources associated with the mapping.   UVM_OBJ_KERN
     63  * allows us to decide which type of unmapping we want to do.
     64  */
     65 #define UVM_OBJ_KERN		(-2)
     66 
     67 #define	UVM_OBJ_IS_KERN_OBJECT(uobj)					\
     68 	((uobj)->uo_refs == UVM_OBJ_KERN)
     69 
     70 #ifdef _KERNEL
     71 
     72 extern const struct uvm_pagerops uvm_vnodeops;
     73 extern const struct uvm_pagerops uvm_deviceops;
     74 extern const struct uvm_pagerops ubc_pager;
     75 extern const struct uvm_pagerops aobj_pager;
     76 
     77 #define	UVM_OBJ_IS_VNODE(uobj)						\
     78 	((uobj)->pgops == &uvm_vnodeops)
     79 
     80 #define	UVM_OBJ_IS_DEVICE(uobj)						\
     81 	((uobj)->pgops == &uvm_deviceops)
     82 
     83 #define	UVM_OBJ_IS_VTEXT(uobj)						\
     84 	(UVM_OBJ_IS_VNODE(uobj) && uvn_text_p(uobj))
     85 
     86 #define	UVM_OBJ_IS_CLEAN(uobj)						\
     87 	(UVM_OBJ_IS_VNODE(uobj) && uvn_clean_p(uobj))
     88 
     89 /*
     90  * UVM_OBJ_NEEDS_WRITEFAULT: true if the uobj needs to detect modification.
     91  * (ie. wants to avoid writable user mappings.)
     92  *
     93  * XXX bad name
     94  */
     95 
     96 #define	UVM_OBJ_NEEDS_WRITEFAULT(uobj)					\
     97 	(UVM_OBJ_IS_VNODE(uobj) && uvn_needs_writefault_p(uobj))
     98 
     99 #define	UVM_OBJ_IS_AOBJ(uobj)						\
    100 	((uobj)->pgops == &aobj_pager)
    101 
    102 extern const rb_tree_ops_t uvm_page_tree_ops;
    103 
    104 #define	UVM_OBJ_INIT(uobj, ops, refs)					\
    105 	do {								\
    106 		mutex_init(&(uobj)->vmobjlock, MUTEX_DEFAULT, IPL_NONE);\
    107 		(uobj)->pgops = (ops);					\
    108 		TAILQ_INIT(&(uobj)->memq);				\
    109 		(uobj)->uo_npages = 0;					\
    110 		(uobj)->uo_refs = (refs);				\
    111 		rb_tree_init(&(uobj)->rb_tree, &uvm_page_tree_ops);	\
    112 	} while (/* CONSTCOND */ 0)
    113 
    114 #ifdef DIAGNOSTIC
    115 #define	UVM_OBJ_DESTROY(uobj)						\
    116 	do {								\
    117 		voff_t _xo = 0;						\
    118 		void *_xn;						\
    119 		mutex_destroy(&(uobj)->vmobjlock);			\
    120 		_xn = rb_tree_find_node_geq(&(uobj)->rb_tree, &_xo);	\
    121 		KASSERT(_xn == NULL);					\
    122 	} while (/* CONSTCOND */ 0)
    123 #else
    124 #define	UVM_OBJ_DESTROY(uobj)						\
    125 	do {								\
    126 		mutex_destroy(&(uobj)->vmobjlock);			\
    127 	} while (/* CONSTCOND */ 0)
    128 #endif	/* DIAGNOSTIC */
    129 
    130 #endif /* _KERNEL */
    131 
    132 #endif /* _UVM_UVM_OBJECT_H_ */
    133