xref: /386bsd/usr/include/nonstd/bsd/vm_object.h (revision a2142627)
1 /*
2  * Copyright (c) 1991 Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * The Mach Operating System project at Carnegie-Mellon University.
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  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the University of
19  *	California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	$Id: vm_object.h,v 1.3 93/11/28 19:28:59 bill Exp Locker: bill $
37  *
38  *
39  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
40  * All rights reserved.
41  *
42  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
43  *
44  * Permission to use, copy, modify and distribute this software and
45  * its documentation is hereby granted, provided that both the copyright
46  * notice and this permission notice appear in all copies of the
47  * software, derivative works or modified versions, and any portions
48  * thereof, and that both notices appear in supporting documentation.
49  *
50  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
52  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
53  *
54  * Carnegie Mellon requests users of this software to return to
55  *
56  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
57  *  School of Computer Science
58  *  Carnegie Mellon University
59  *  Pittsburgh PA 15213-3890
60  *
61  * any improvements or extensions that they make and grant Carnegie the
62  * rights to redistribute these changes.
63  */
64 
65 /* Holder of resident memory pages */
66 
67 #ifndef	_VM_OBJECT_
68 #define	_VM_OBJECT_
69 
70 struct pager_struct;
71 
72 /*
73  */
74 
75 struct vm_object {
76 	queue_chain_t		memq;		/* Resident memory */
77 	queue_chain_t		object_list;	/* list of all objects */
78 	int			ref_count;	/* How many refs?? */
79 	vm_size_t		size;		/* Object size */
80 	short			resident_page_count;
81 						/* number of resident pages */
82 	struct vm_object	*copy;		/* Object that holds copies of
83 						   my changed pages */
84 	struct pager_struct	*pager;		/* Where to get data */
85 	struct vm_object	*shadow;	/* My shadow */
86 	vm_offset_t		shadow_offset;	/* Offset in shadow */
87 	vm_offset_t		paging_offset;	/* Offset in pager */
88 	unsigned int
89 				paging_in_progress:16,
90 						/* Paging (in or out) - don't
91 						   collapse or destroy */
92 	/* boolean_t */		can_persist:1,	/* allow to persist */
93 	/* boolean_t */		internal:1;	/* internally created object */
94 	queue_chain_t		cached_list;	/* for persistence */
95 };
96 
97 typedef struct vm_object	*vm_object_t;
98 
99 struct vm_object_hash_entry {
100 	queue_chain_t		hash_links;	/* hash chain links */
101 	vm_object_t		object;		/* object we represent */
102 };
103 
104 typedef struct vm_object_hash_entry	*vm_object_hash_entry_t;
105 
106 #ifdef	KERNEL
107 queue_head_t	vm_object_cached_list;	/* list of objects persisting */
108 int		vm_object_cached;	/* size of cached list */
109 
110 long		vm_object_count;	/* count of all objects */
111 					/* lock for object list and count */
112 
113 vm_object_t	kernel_object;		/* the single kernel object */
114 vm_object_t	kmem_object;
115 
116 #endif	KERNEL
117 
118 /*
119  *	Declare procedures that operate on VM objects.
120  */
121 
122 void	vm_object_init();
123 vm_object_t
124 	vm_object_allocate(vm_size_t size);
125 void	vm_object_reference(vm_object_t object);
126 void	vm_object_deallocate(vm_object_t object);
127 void	vm_object_terminate(vm_object_t object);
128 void	vm_object_page_clean(vm_object_t object, vm_offset_t start,
129 		vm_offset_t end);
130 void	vm_object_pmap_copy(vm_object_t object, vm_offset_t start,
131 		vm_offset_t end);
132 void	vm_object_pmap_remove(vm_object_t object, vm_offset_t start,
133 		vm_offset_t end);
134 void	vm_object_page_remove(vm_object_t object, vm_offset_t start,
135 		vm_offset_t end);
136 void	vm_object_copy(vm_object_t src_object, vm_offset_t src_offset,
137 		vm_size_t size, vm_object_t *dst_object,
138 		vm_offset_t *dst_offset, boolean_t *src_needs_copy);
139 void	vm_object_shadow(vm_object_t *object, vm_offset_t *offset,
140 		vm_size_t length);
141 /*void	vm_object_setpager(vm_object_t object, struct pager_struct *pager,
142 		vm_offset_t paging_offset, boolean_t read_only); */
143 vm_object_t
144 	vm_object_lookup(struct pager_struct *pager);
145 /*void	vm_object_enter(vm_object_t object, struct pager_struct *pager);*/
146 void	vm_object_enter(vm_object_t object);
147 void	vm_object_remove(struct pager_struct *pager);
148 void	vm_object_collapse(vm_object_t object);
149 boolean_t
150 	vm_object_coalesce(vm_object_t prev_object, vm_object_t next_object,
151 		vm_offset_t prev_offset, vm_offset_t next_offset,
152 		vm_size_t prev_size, vm_size_t next_size);
153 
154 #define	vm_object_cache(pager)	pager_cache(vm_object_lookup(pager), TRUE)
155 #define	vm_object_uncache(pager) pager_cache(vm_object_lookup(pager), FALSE)
156 
157 /* void		vm_object_cache_clear(); */
158 void	vm_object_print(vm_object_t object, boolean_t full);
159 
160 #define	vm_object_sleep(event, object, interruptible) \
161 	thread_sleep((event), &(object)->Lock, (interruptible))
162 #endif	_VM_OBJECT_
163