uvm_object.h revision 1.31.2.3 1 /* $NetBSD: uvm_object.h,v 1.31.2.3 2012/04/17 00:09:00 yamt 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 #include <sys/queue.h>
34 #include <sys/radixtree.h>
35 #include <uvm/uvm_pglist.h>
36
37 /*
38 * The UVM memory object interface. Notes:
39 *
40 * A UVM memory object represents a list of pages, which are managed by
41 * the object's pager operations (uvm_object::pgops). All pages belonging
42 * to an object are owned by it and thus protected by the object lock.
43 *
44 * The lock (uvm_object::vmobjlock) may be shared amongst the UVM objects.
45 * By default, the lock is allocated dynamically using mutex_obj(9) cache.
46 * Lock sharing is normally used when there is an underlying object. For
47 * example, vnode representing a file may have an underlying node, which
48 * is the case for tmpfs and layered file systems. In such case, vnode's
49 * UVM object and the underlying UVM object shares the lock (note that the
50 * vnode_t::v_interlock points to uvm_object::vmobjlock).
51 */
52
53 struct uvm_object {
54 kmutex_t * vmobjlock; /* lock on uo_pages */
55 const struct uvm_pagerops *pgops; /* pager ops */
56 int uo_npages; /* # of pages in uo_pages */
57 unsigned uo_refs; /* reference count */
58 struct radix_tree uo_pages; /* tree of pages */
59 LIST_HEAD(,ubc_map) uo_ubc; /* ubc mappings */
60 };
61
62 /*
63 * uo_pages
64 */
65
66 #define UVM_PAGE_DIRTY_TAG 0 /* might be dirty (!PG_CLEAN) */
67
68 /*
69 * UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the
70 * object is a kernel memory object rather than a normal one (kernel
71 * memory objects don't have reference counts -- they never die).
72 *
73 * this value is used to detected kernel object mappings at uvm_unmap()
74 * time. normally when an object is unmapped its pages eventaully become
75 * deactivated and then paged out and/or freed. this is not useful
76 * for kernel objects... when a kernel object is unmapped we always want
77 * to free the resources associated with the mapping. UVM_OBJ_KERN
78 * allows us to decide which type of unmapping we want to do.
79 */
80 #define UVM_OBJ_KERN (-2)
81
82 #define UVM_OBJ_IS_KERN_OBJECT(uobj) \
83 ((uobj)->uo_refs == UVM_OBJ_KERN)
84
85 #ifdef _KERNEL
86
87 extern const struct uvm_pagerops uvm_vnodeops;
88 extern const struct uvm_pagerops uvm_deviceops;
89 extern const struct uvm_pagerops ubc_pager;
90 extern const struct uvm_pagerops aobj_pager;
91
92 #define UVM_OBJ_IS_VNODE(uobj) \
93 ((uobj)->pgops == &uvm_vnodeops)
94
95 #define UVM_OBJ_IS_DEVICE(uobj) \
96 ((uobj)->pgops == &uvm_deviceops)
97
98 #define UVM_OBJ_IS_VTEXT(uobj) \
99 (UVM_OBJ_IS_VNODE(uobj) && uvn_text_p(uobj))
100
101 #define UVM_OBJ_IS_CLEAN(uobj) \
102 (UVM_OBJ_IS_VNODE(uobj) && uvn_clean_p(uobj))
103
104 /*
105 * UVM_OBJ_NEEDS_WRITEFAULT: true if the uobj needs to detect modification.
106 * (ie. wants to avoid writable user mappings.)
107 *
108 * XXX bad name
109 */
110
111 #define UVM_OBJ_NEEDS_WRITEFAULT(uobj) \
112 (UVM_OBJ_IS_VNODE(uobj) && uvn_needs_writefault_p(uobj))
113
114 #define UVM_OBJ_IS_AOBJ(uobj) \
115 ((uobj)->pgops == &aobj_pager)
116
117 #endif /* _KERNEL */
118
119 #endif /* _UVM_UVM_OBJECT_H_ */
120