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