1*6c8f7fc3SBen Gras /* $NetBSD: uvm_object.h,v 1.33 2012/09/14 22:20:50 rmind Exp $ */ 2*6c8f7fc3SBen Gras 3*6c8f7fc3SBen Gras /* 4*6c8f7fc3SBen Gras * Copyright (c) 1997 Charles D. Cranor and Washington University. 5*6c8f7fc3SBen Gras * All rights reserved. 6*6c8f7fc3SBen Gras * 7*6c8f7fc3SBen Gras * Redistribution and use in source and binary forms, with or without 8*6c8f7fc3SBen Gras * modification, are permitted provided that the following conditions 9*6c8f7fc3SBen Gras * are met: 10*6c8f7fc3SBen Gras * 1. Redistributions of source code must retain the above copyright 11*6c8f7fc3SBen Gras * notice, this list of conditions and the following disclaimer. 12*6c8f7fc3SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 13*6c8f7fc3SBen Gras * notice, this list of conditions and the following disclaimer in the 14*6c8f7fc3SBen Gras * documentation and/or other materials provided with the distribution. 15*6c8f7fc3SBen Gras * 16*6c8f7fc3SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17*6c8f7fc3SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18*6c8f7fc3SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19*6c8f7fc3SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20*6c8f7fc3SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21*6c8f7fc3SBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22*6c8f7fc3SBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23*6c8f7fc3SBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*6c8f7fc3SBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25*6c8f7fc3SBen Gras * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*6c8f7fc3SBen Gras * 27*6c8f7fc3SBen Gras * from: Id: uvm_object.h,v 1.1.2.2 1998/01/04 22:44:51 chuck Exp 28*6c8f7fc3SBen Gras */ 29*6c8f7fc3SBen Gras 30*6c8f7fc3SBen Gras #ifndef _UVM_UVM_OBJECT_H_ 31*6c8f7fc3SBen Gras #define _UVM_UVM_OBJECT_H_ 32*6c8f7fc3SBen Gras 33*6c8f7fc3SBen Gras #include <sys/queue.h> 34*6c8f7fc3SBen Gras #include <sys/rbtree.h> 35*6c8f7fc3SBen Gras #include <uvm/uvm_pglist.h> 36*6c8f7fc3SBen Gras 37*6c8f7fc3SBen Gras /* 38*6c8f7fc3SBen Gras * The UVM memory object interface. Notes: 39*6c8f7fc3SBen Gras * 40*6c8f7fc3SBen Gras * A UVM memory object represents a list of pages, which are managed by 41*6c8f7fc3SBen Gras * the object's pager operations (uvm_object::pgops). All pages belonging 42*6c8f7fc3SBen Gras * to an object are owned by it and thus protected by the object lock. 43*6c8f7fc3SBen Gras * 44*6c8f7fc3SBen Gras * The lock (uvm_object::vmobjlock) may be shared amongst the UVM objects. 45*6c8f7fc3SBen Gras * By default, the lock is allocated dynamically using mutex_obj(9) cache. 46*6c8f7fc3SBen Gras * Lock sharing is normally used when there is an underlying object. For 47*6c8f7fc3SBen Gras * example, vnode representing a file may have an underlying node, which 48*6c8f7fc3SBen Gras * is the case for tmpfs and layered file systems. In such case, vnode's 49*6c8f7fc3SBen Gras * UVM object and the underlying UVM object shares the lock (note that the 50*6c8f7fc3SBen Gras * vnode_t::v_interlock points to uvm_object::vmobjlock). 51*6c8f7fc3SBen Gras * 52*6c8f7fc3SBen Gras * The reference count is managed atomically for the anonymous UVM objects. 53*6c8f7fc3SBen Gras * For other objects, it is arbitrary (may use the lock or atomics). 54*6c8f7fc3SBen Gras */ 55*6c8f7fc3SBen Gras 56*6c8f7fc3SBen Gras struct uvm_object { 57*6c8f7fc3SBen Gras kmutex_t * vmobjlock; /* lock on memq */ 58*6c8f7fc3SBen Gras const struct uvm_pagerops *pgops; /* pager ops */ 59*6c8f7fc3SBen Gras struct pglist memq; /* pages in this object */ 60*6c8f7fc3SBen Gras int uo_npages; /* # of pages in memq */ 61*6c8f7fc3SBen Gras unsigned uo_refs; /* reference count */ 62*6c8f7fc3SBen Gras struct rb_tree rb_tree; /* tree of pages */ 63*6c8f7fc3SBen Gras LIST_HEAD(,ubc_map) uo_ubc; /* ubc mappings */ 64*6c8f7fc3SBen Gras }; 65*6c8f7fc3SBen Gras 66*6c8f7fc3SBen Gras /* 67*6c8f7fc3SBen Gras * UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the 68*6c8f7fc3SBen Gras * object is a kernel memory object rather than a normal one (kernel 69*6c8f7fc3SBen Gras * memory objects don't have reference counts -- they never die). 70*6c8f7fc3SBen Gras * 71*6c8f7fc3SBen Gras * this value is used to detected kernel object mappings at uvm_unmap() 72*6c8f7fc3SBen Gras * time. normally when an object is unmapped its pages eventaully become 73*6c8f7fc3SBen Gras * deactivated and then paged out and/or freed. this is not useful 74*6c8f7fc3SBen Gras * for kernel objects... when a kernel object is unmapped we always want 75*6c8f7fc3SBen Gras * to free the resources associated with the mapping. UVM_OBJ_KERN 76*6c8f7fc3SBen Gras * allows us to decide which type of unmapping we want to do. 77*6c8f7fc3SBen Gras */ 78*6c8f7fc3SBen Gras #define UVM_OBJ_KERN (-2) 79*6c8f7fc3SBen Gras 80*6c8f7fc3SBen Gras #define UVM_OBJ_IS_KERN_OBJECT(uobj) \ 81*6c8f7fc3SBen Gras ((uobj)->uo_refs == UVM_OBJ_KERN) 82*6c8f7fc3SBen Gras 83*6c8f7fc3SBen Gras #ifdef _KERNEL 84*6c8f7fc3SBen Gras 85*6c8f7fc3SBen Gras extern const struct uvm_pagerops uvm_vnodeops; 86*6c8f7fc3SBen Gras extern const struct uvm_pagerops uvm_deviceops; 87*6c8f7fc3SBen Gras extern const struct uvm_pagerops ubc_pager; 88*6c8f7fc3SBen Gras extern const struct uvm_pagerops aobj_pager; 89*6c8f7fc3SBen Gras 90*6c8f7fc3SBen Gras #define UVM_OBJ_IS_VNODE(uobj) \ 91*6c8f7fc3SBen Gras ((uobj)->pgops == &uvm_vnodeops) 92*6c8f7fc3SBen Gras 93*6c8f7fc3SBen Gras #define UVM_OBJ_IS_DEVICE(uobj) \ 94*6c8f7fc3SBen Gras ((uobj)->pgops == &uvm_deviceops) 95*6c8f7fc3SBen Gras 96*6c8f7fc3SBen Gras #define UVM_OBJ_IS_VTEXT(uobj) \ 97*6c8f7fc3SBen Gras (UVM_OBJ_IS_VNODE(uobj) && uvn_text_p(uobj)) 98*6c8f7fc3SBen Gras 99*6c8f7fc3SBen Gras #define UVM_OBJ_IS_CLEAN(uobj) \ 100*6c8f7fc3SBen Gras (UVM_OBJ_IS_VNODE(uobj) && uvn_clean_p(uobj)) 101*6c8f7fc3SBen Gras 102*6c8f7fc3SBen Gras /* 103*6c8f7fc3SBen Gras * UVM_OBJ_NEEDS_WRITEFAULT: true if the uobj needs to detect modification. 104*6c8f7fc3SBen Gras * (ie. wants to avoid writable user mappings.) 105*6c8f7fc3SBen Gras * 106*6c8f7fc3SBen Gras * XXX bad name 107*6c8f7fc3SBen Gras */ 108*6c8f7fc3SBen Gras 109*6c8f7fc3SBen Gras #define UVM_OBJ_NEEDS_WRITEFAULT(uobj) \ 110*6c8f7fc3SBen Gras (UVM_OBJ_IS_VNODE(uobj) && uvn_needs_writefault_p(uobj)) 111*6c8f7fc3SBen Gras 112*6c8f7fc3SBen Gras #define UVM_OBJ_IS_AOBJ(uobj) \ 113*6c8f7fc3SBen Gras ((uobj)->pgops == &aobj_pager) 114*6c8f7fc3SBen Gras 115*6c8f7fc3SBen Gras extern const rb_tree_ops_t uvm_page_tree_ops; 116*6c8f7fc3SBen Gras 117*6c8f7fc3SBen Gras #endif /* _KERNEL */ 118*6c8f7fc3SBen Gras 119*6c8f7fc3SBen Gras #endif /* _UVM_UVM_OBJECT_H_ */ 120