xref: /openbsd-src/sys/uvm/uvm_object.h (revision 4e1ee0786f11cc571bd0be17d38e46f635c719fc)
1 /*	$OpenBSD: uvm_object.h,v 1.28 2021/10/12 18:16:51 kettenis Exp $	*/
2 /*	$NetBSD: uvm_object.h,v 1.11 2001/03/09 01:02:12 chs Exp $	*/
3 
4 /*
5  * Copyright (c) 1997 Charles D. Cranor and Washington University.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * from: Id: uvm_object.h,v 1.1.2.2 1998/01/04 22:44:51 chuck Exp
29  */
30 
31 #ifndef _UVM_UVM_OBJECT_H_
32 #define _UVM_UVM_OBJECT_H_
33 
34 /*
35  * uvm_object.h
36  */
37 
38 /*
39  * uvm_object: all that is left of mach objects.
40  */
41 
42 struct uvm_object {
43 	const struct uvm_pagerops	*pgops;		/* pager ops */
44 	RBT_HEAD(uvm_objtree, vm_page)	 memt;		/* pages in object */
45 	int				 uo_npages;	/* # of pages in memt */
46 	int				 uo_refs;	/* reference count */
47 };
48 
49 /*
50  * UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the
51  * object is a kernel memory object rather than a normal one (kernel
52  * memory objects don't have reference counts -- they never die).
53  *
54  * this value is used to detected kernel object mappings at uvm_unmap()
55  * time.  normally when an object is unmapped its pages eventually become
56  * deactivated and then paged out and/or freed.  this is not useful
57  * for kernel objects... when a kernel object is unmapped we always want
58  * to free the resources associated with the mapping.  UVM_OBJ_KERN
59  * allows us to decide which type of unmapping we want to do.
60  *
61  * in addition, we have kernel objects which may be used in an
62  * interrupt context.  these objects get their mappings entered
63  * with pmap_kenter*() and removed with pmap_kremove(), which
64  * are safe to call in interrupt context, and must be used ONLY
65  * for wired kernel mappings in these objects and their associated
66  * maps.
67  */
68 #define UVM_OBJ_KERN		(-2)
69 
70 #define	UVM_OBJ_IS_KERN_OBJECT(uobj)					\
71 	((uobj)->uo_refs == UVM_OBJ_KERN)
72 
73 #ifdef _KERNEL
74 
75 extern const struct uvm_pagerops uvm_vnodeops;
76 extern const struct uvm_pagerops uvm_deviceops;
77 extern const struct uvm_pagerops pmap_pager;
78 extern const struct uvm_pagerops bufcache_pager;
79 
80 /* For object trees */
81 int	uvm_pagecmp(const struct vm_page *, const struct vm_page *);
82 RBT_PROTOTYPE(uvm_objtree, vm_page, objt, uvm_pagecmp)
83 
84 #define	UVM_OBJ_IS_VNODE(uobj)						\
85 	((uobj)->pgops == &uvm_vnodeops)
86 
87 #define	UVM_OBJ_IS_DEVICE(uobj)						\
88 	((uobj)->pgops == &uvm_deviceops)
89 
90 #define	UVM_OBJ_IS_VTEXT(uobj)						\
91 	((uobj)->pgops == &uvm_vnodeops &&				\
92 	 ((struct vnode *)uobj)->v_flag & VTEXT)
93 
94 #define	UVM_OBJ_IS_AOBJ(uobj)						\
95 	((uobj)->pgops == &aobj_pager)
96 
97 #define UVM_OBJ_IS_PMAP(uobj)						\
98 	((uobj)->pgops == &pmap_pager)
99 
100 #define UVM_OBJ_IS_BUFCACHE(uobj)					\
101 	((uobj)->pgops == &bufcache_pager)
102 
103 void	uvm_obj_init(struct uvm_object *, const struct uvm_pagerops *, int);
104 void	uvm_obj_destroy(struct uvm_object *);
105 int	uvm_obj_wire(struct uvm_object *, voff_t, voff_t, struct pglist *);
106 void	uvm_obj_unwire(struct uvm_object *, voff_t, voff_t);
107 void	uvm_obj_free(struct uvm_object *);
108 
109 #endif /* _KERNEL */
110 
111 #endif /* _UVM_UVM_OBJECT_H_ */
112