uvm_object.h revision 1.26
1/*	$OpenBSD: uvm_object.h,v 1.26 2021/06/16 09:02:21 mpi 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
42struct 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
75extern const struct uvm_pagerops uvm_vnodeops;
76extern const struct uvm_pagerops uvm_deviceops;
77
78/* For object trees */
79int	uvm_pagecmp(const struct vm_page *, const struct vm_page *);
80RBT_PROTOTYPE(uvm_objtree, vm_page, objt, uvm_pagecmp)
81
82#define	UVM_OBJ_IS_VNODE(uobj)						\
83	((uobj)->pgops == &uvm_vnodeops)
84
85#define	UVM_OBJ_IS_DEVICE(uobj)						\
86	((uobj)->pgops == &uvm_deviceops)
87
88#define	UVM_OBJ_IS_VTEXT(uobj)						\
89	((uobj)->pgops == &uvm_vnodeops &&				\
90	 ((struct vnode *)uobj)->v_flag & VTEXT)
91
92#define	UVM_OBJ_IS_AOBJ(uobj)						\
93	((uobj)->pgops == &aobj_pager)
94
95void	uvm_obj_init(struct uvm_object *, const struct uvm_pagerops *, int);
96int	uvm_obj_wire(struct uvm_object *, voff_t, voff_t, struct pglist *);
97void	uvm_obj_unwire(struct uvm_object *, voff_t, voff_t);
98void	uvm_obj_free(struct uvm_object *);
99
100#endif /* _KERNEL */
101
102#endif /* _UVM_UVM_OBJECT_H_ */
103