1*a192f6ddSjsg /* $OpenBSD: uvm_object.h,v 1.30 2022/09/04 06:49:11 jsg Exp $ */ 21414b0faSart /* $NetBSD: uvm_object.h,v 1.11 2001/03/09 01:02:12 chs Exp $ */ 3cd7ee8acSart 4cd7ee8acSart /* 5cd7ee8acSart * Copyright (c) 1997 Charles D. Cranor and Washington University. 6cd7ee8acSart * All rights reserved. 7cd7ee8acSart * 8cd7ee8acSart * Redistribution and use in source and binary forms, with or without 9cd7ee8acSart * modification, are permitted provided that the following conditions 10cd7ee8acSart * are met: 11cd7ee8acSart * 1. Redistributions of source code must retain the above copyright 12cd7ee8acSart * notice, this list of conditions and the following disclaimer. 13cd7ee8acSart * 2. Redistributions in binary form must reproduce the above copyright 14cd7ee8acSart * notice, this list of conditions and the following disclaimer in the 15cd7ee8acSart * documentation and/or other materials provided with the distribution. 16cd7ee8acSart * 17cd7ee8acSart * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18cd7ee8acSart * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19cd7ee8acSart * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20cd7ee8acSart * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21cd7ee8acSart * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22cd7ee8acSart * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23cd7ee8acSart * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24cd7ee8acSart * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25cd7ee8acSart * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26cd7ee8acSart * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27cd7ee8acSart * 28cd7ee8acSart * from: Id: uvm_object.h,v 1.1.2.2 1998/01/04 22:44:51 chuck Exp 29cd7ee8acSart */ 30cd7ee8acSart 31cd7ee8acSart #ifndef _UVM_UVM_OBJECT_H_ 32cd7ee8acSart #define _UVM_UVM_OBJECT_H_ 33cd7ee8acSart 34cd7ee8acSart /* 3569c04514Smpi * The UVM memory object interface. Notes: 3669c04514Smpi * 3769c04514Smpi * A UVM memory object represents a list of pages, which are managed by 3869c04514Smpi * the object's pager operations (uvm_object::pgops). All pages belonging 3969c04514Smpi * to an object are owned by it and thus protected by the object lock. 4069c04514Smpi * 4169c04514Smpi * The lock (uvm_object::vmobjlock) may be shared amongst the UVM objects. 4269c04514Smpi * By default, the lock is allocated dynamically using rw_obj_init() cache. 4369c04514Smpi * Lock sharing is normally used when there is an underlying object. For 4469c04514Smpi * example, vnode representing a file may have an underlying node, which 4569c04514Smpi * is the case for tmpfs and layered file systems. In such case, vnode's 4669c04514Smpi * UVM object and the underlying UVM object shares the lock. 4769c04514Smpi * 4869c04514Smpi * The reference count is managed atomically for the anonymous UVM objects. 4969c04514Smpi * For other objects, it is arbitrary (may use the lock or atomics). 50cd7ee8acSart */ 51cd7ee8acSart 52cd7ee8acSart struct uvm_object { 5369c04514Smpi struct rwlock *vmobjlock; /* lock on object */ 549f7b7ef0Smpi const struct uvm_pagerops *pgops; /* pager ops */ 55262a556aSdlg RBT_HEAD(uvm_objtree, vm_page) memt; /* pages in object */ 567bcb8cc6Soga int uo_npages; /* # of pages in memt */ 57cd7ee8acSart int uo_refs; /* reference count */ 58cd7ee8acSart }; 59cd7ee8acSart 60cd7ee8acSart /* 61cd7ee8acSart * UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the 62cd7ee8acSart * object is a kernel memory object rather than a normal one (kernel 63cd7ee8acSart * memory objects don't have reference counts -- they never die). 64cd7ee8acSart * 65cd7ee8acSart * this value is used to detected kernel object mappings at uvm_unmap() 66*a192f6ddSjsg * time. normally when an object is unmapped its pages eventually become 67cd7ee8acSart * deactivated and then paged out and/or freed. this is not useful 68cd7ee8acSart * for kernel objects... when a kernel object is unmapped we always want 69cd7ee8acSart * to free the resources associated with the mapping. UVM_OBJ_KERN 70cd7ee8acSart * allows us to decide which type of unmapping we want to do. 717cb53682Sart * 727cb53682Sart * in addition, we have kernel objects which may be used in an 737cb53682Sart * interrupt context. these objects get their mappings entered 747cb53682Sart * with pmap_kenter*() and removed with pmap_kremove(), which 757cb53682Sart * are safe to call in interrupt context, and must be used ONLY 767cb53682Sart * for wired kernel mappings in these objects and their associated 777cb53682Sart * maps. 78cd7ee8acSart */ 79cd7ee8acSart #define UVM_OBJ_KERN (-2) 807cb53682Sart 817cb53682Sart #define UVM_OBJ_IS_KERN_OBJECT(uobj) \ 82b7c6e7a5Sart ((uobj)->uo_refs == UVM_OBJ_KERN) 83cd7ee8acSart 84cac1bff1Sart #ifdef _KERNEL 85cac1bff1Sart 869f7b7ef0Smpi extern const struct uvm_pagerops uvm_vnodeops; 879f7b7ef0Smpi extern const struct uvm_pagerops uvm_deviceops; 8894151407Smpi extern const struct uvm_pagerops pmap_pager; 8994151407Smpi extern const struct uvm_pagerops bufcache_pager; 90cac1bff1Sart 917bcb8cc6Soga /* For object trees */ 92262a556aSdlg int uvm_pagecmp(const struct vm_page *, const struct vm_page *); 93262a556aSdlg RBT_PROTOTYPE(uvm_objtree, vm_page, objt, uvm_pagecmp) 947bcb8cc6Soga 95cac1bff1Sart #define UVM_OBJ_IS_VNODE(uobj) \ 96cac1bff1Sart ((uobj)->pgops == &uvm_vnodeops) 97cac1bff1Sart 98676bc291Sart #define UVM_OBJ_IS_DEVICE(uobj) \ 99676bc291Sart ((uobj)->pgops == &uvm_deviceops) 100676bc291Sart 101cac1bff1Sart #define UVM_OBJ_IS_VTEXT(uobj) \ 102cac1bff1Sart ((uobj)->pgops == &uvm_vnodeops && \ 103cac1bff1Sart ((struct vnode *)uobj)->v_flag & VTEXT) 104cac1bff1Sart 10557296fa7Smpi #define UVM_OBJ_IS_AOBJ(uobj) \ 10657296fa7Smpi ((uobj)->pgops == &aobj_pager) 10757296fa7Smpi 10894151407Smpi #define UVM_OBJ_IS_PMAP(uobj) \ 10994151407Smpi ((uobj)->pgops == &pmap_pager) 11094151407Smpi 11194151407Smpi #define UVM_OBJ_IS_BUFCACHE(uobj) \ 11294151407Smpi ((uobj)->pgops == &bufcache_pager) 11394151407Smpi 11469c04514Smpi #define UVM_OBJ_IS_DUMMY(uobj) \ 11569c04514Smpi (UVM_OBJ_IS_PMAP(uobj) || UVM_OBJ_IS_BUFCACHE(uobj)) 11669c04514Smpi 117da3d0110Smpi void uvm_obj_init(struct uvm_object *, const struct uvm_pagerops *, int); 1183c82a206Skettenis void uvm_obj_destroy(struct uvm_object *); 11969c04514Smpi void uvm_obj_setlock(struct uvm_object *, struct rwlock *); 120da3d0110Smpi int uvm_obj_wire(struct uvm_object *, voff_t, voff_t, struct pglist *); 121da3d0110Smpi void uvm_obj_unwire(struct uvm_object *, voff_t, voff_t); 122da3d0110Smpi void uvm_obj_free(struct uvm_object *); 1235a9ec29bSoga 124cac1bff1Sart #endif /* _KERNEL */ 125cac1bff1Sart 126cd7ee8acSart #endif /* _UVM_UVM_OBJECT_H_ */ 127