xref: /dragonfly/sys/vm/vm_pager.h (revision 926deccb)
1 /*
2  * Copyright (c) 1990 University of Utah.
3  * Copyright (c) 1991, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)vm_pager.h	8.4 (Berkeley) 1/12/94
39  * $FreeBSD: src/sys/vm/vm_pager.h,v 1.24.2.2 2002/12/31 09:34:51 dillon Exp $
40  */
41 
42 /*
43  * Pager routine interface definition.
44  */
45 
46 #ifndef	_VM_VM_PAGER_H_
47 #define	_VM_VM_PAGER_H_
48 
49 #ifndef _SYS_QUEUE_H_
50 #include <sys/queue.h>
51 #endif
52 #ifndef _VM_VM_PAGE_H_
53 #include <vm/vm_page.h>
54 #endif
55 #ifndef _VM_VM_OBJECT_H_
56 #include <vm/vm_object.h>
57 #endif
58 
59 TAILQ_HEAD(pagerlst, vm_object);
60 
61 struct buf;
62 struct bio;
63 
64 struct pagerops {
65 	void (*pgo_dealloc) (vm_object_t);
66 	int (*pgo_getpage) (vm_object_t, vm_page_t *, int);
67 	void (*pgo_putpages) (vm_object_t, vm_page_t *, int, int, int *);
68 	boolean_t (*pgo_haspage) (vm_object_t, vm_pindex_t);
69 };
70 
71 /*
72  * get/put return values
73  * OK	 operation was successful
74  * BAD	 specified data was out of the accepted range
75  * FAIL	 specified data was in range, but doesn't exist
76  * PEND	 operations was initiated but not completed
77  * ERROR error while accessing data that is in range and exists
78  * AGAIN temporary resource shortage prevented operation from happening
79  */
80 #define	VM_PAGER_OK	0
81 #define	VM_PAGER_BAD	1
82 #define	VM_PAGER_FAIL	2
83 #define	VM_PAGER_PEND	3
84 #define	VM_PAGER_ERROR	4
85 #define VM_PAGER_AGAIN	5
86 
87 #define	VM_PAGER_PUT_SYNC		0x0001
88 #define	VM_PAGER_PUT_INVAL		0x0002
89 #define	VM_PAGER_IGNORE_CLEANCHK	0x0004
90 #define	VM_PAGER_CLUSTER_OK		0x0008
91 
92 #ifdef _KERNEL
93 
94 struct vnode;
95 
96 extern struct vm_map pager_map;
97 extern int pager_map_size;
98 extern struct pagerops *pagertab[];
99 
100 vm_object_t default_pager_alloc(void *, off_t, vm_prot_t, off_t);
101 vm_object_t dev_pager_alloc(void *, off_t, vm_prot_t, off_t);
102 vm_object_t phys_pager_alloc(void *, off_t, vm_prot_t, off_t);
103 vm_object_t swap_pager_alloc(void *, off_t, vm_prot_t, off_t);
104 vm_object_t vnode_pager_alloc (void *, off_t, vm_prot_t, off_t, int, int);
105 vm_object_t vnode_pager_reference (struct vnode *);
106 
107 void vm_pager_bufferinit (void);
108 void vm_pager_deallocate (vm_object_t);
109 static __inline int vm_pager_get_page (vm_object_t, vm_page_t *, int);
110 static __inline boolean_t vm_pager_has_page (vm_object_t, vm_pindex_t);
111 vm_object_t vm_pager_object_lookup(struct pagerlst *, void *);
112 void vm_pager_sync (void);
113 struct buf *getchainbuf(struct buf *bp, struct vnode *vp, int flags);
114 void flushchainbuf(struct buf *nbp);
115 void waitchainbuf(struct buf *bp, int count, int done);
116 void autochaindone(struct buf *bp);
117 void swap_pager_strategy(vm_object_t object, struct bio *bio);
118 void swap_pager_unswapped (vm_page_t m);
119 
120 /*
121  * vm_page_get_pages:
122  *
123  * Retrieve the contents of the page from the object pager.  Note that the
124  * object pager might replace the page.
125  *
126  * If the pagein was successful, we must fully validate it so it can be
127  * memory mapped.
128  */
129 
130 static __inline int
131 vm_pager_get_page(vm_object_t object, vm_page_t *m, int seqaccess)
132 {
133 	int r;
134 
135 	r = (*pagertab[object->type]->pgo_getpage)(object, m, seqaccess);
136 	if (r == VM_PAGER_OK && (*m)->valid != VM_PAGE_BITS_ALL) {
137 		vm_page_zero_invalid(*m, TRUE);
138 	}
139 	return(r);
140 }
141 
142 static __inline void
143 vm_pager_put_pages(
144 	vm_object_t object,
145 	vm_page_t *m,
146 	int count,
147 	int flags,
148 	int *rtvals
149 ) {
150 	(*pagertab[object->type]->pgo_putpages)
151 	    (object, m, count, flags, rtvals);
152 }
153 
154 /*
155  *	vm_pager_haspage
156  *
157  *	Check to see if an object's pager has the requested page.  The
158  *	object's pager will also set before and after to give the caller
159  *	some idea of the number of pages before and after the requested
160  *	page can be I/O'd efficiently.
161  *
162  *	This routine does not have to be called at any particular spl.
163  */
164 
165 static __inline boolean_t
166 vm_pager_has_page(vm_object_t object, vm_pindex_t offset)
167 {
168         return ((*pagertab[object->type]->pgo_haspage)(object, offset));
169 }
170 
171 struct cdev_pager_ops {
172 	int (*cdev_pg_fault)(vm_object_t vm_obj, vm_ooffset_t offset,
173 	    int prot, vm_page_t *mres);
174 	int (*cdev_pg_ctor)(void *handle, vm_ooffset_t size, vm_prot_t prot,
175 	    vm_ooffset_t foff, struct ucred *cred, u_short *color);
176 	void (*cdev_pg_dtor)(void *handle);
177 };
178 
179 vm_object_t cdev_pager_allocate(void *handle, enum obj_type tp,
180     struct cdev_pager_ops *ops, vm_ooffset_t size, vm_prot_t prot,
181     vm_ooffset_t foff, struct ucred *cred);
182 vm_object_t cdev_pager_lookup(void *handle);
183 void cdev_pager_free_page(vm_object_t object, vm_page_t m);
184 
185 #endif
186 
187 #endif				/* _VM_VM_PAGER_H_ */
188