vm_pager.h revision 75474
1119482Sobrien/* 2199855Ssobomax * Copyright (c) 1990 University of Utah. 366133Sarchie * Copyright (c) 1991, 1993 4199855Ssobomax * The Regents of the University of California. All rights reserved. 5199855Ssobomax * 666133Sarchie * This code is derived from software contributed to Berkeley by 766133Sarchie * the Systems Programming Group of the University of Utah Computer 866133Sarchie * Science Department. 966133Sarchie * 1066133Sarchie * Redistribution and use in source and binary forms, with or without 1166133Sarchie * modification, are permitted provided that the following conditions 1266133Sarchie * are met: 1366133Sarchie * 1. Redistributions of source code must retain the above copyright 1466133Sarchie * notice, this list of conditions and the following disclaimer. 1566133Sarchie * 2. Redistributions in binary form must reproduce the above copyright 1666133Sarchie * notice, this list of conditions and the following disclaimer in the 1766133Sarchie * documentation and/or other materials provided with the distribution. 1866133Sarchie * 3. All advertising materials mentioning features or use of this software 1966133Sarchie * must display the following acknowledgement: 2066133Sarchie * This product includes software developed by the University of 2166133Sarchie * California, Berkeley and its contributors. 2266133Sarchie * 4. Neither the name of the University nor the names of its contributors 2366133Sarchie * may be used to endorse or promote products derived from this software 2466133Sarchie * without specific prior written permission. 2566133Sarchie * 2666133Sarchie * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2766133Sarchie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2866133Sarchie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2966133Sarchie * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3066133Sarchie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3166133Sarchie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3266133Sarchie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3366133Sarchie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3466133Sarchie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3566133Sarchie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3666133Sarchie * SUCH DAMAGE. 3766133Sarchie * 38119482Sobrien * @(#)vm_pager.h 8.4 (Berkeley) 1/12/94 39119482Sobrien * $FreeBSD: head/sys/vm/vm_pager.h 75474 2001-04-13 10:23:32Z alfred $ 40119482Sobrien */ 4166133Sarchie 4266133Sarchie/* 4366133Sarchie * Pager routine interface definition. 44199855Ssobomax */ 45199855Ssobomax 46199855Ssobomax#ifndef _VM_PAGER_ 4766133Sarchie#define _VM_PAGER_ 48199855Ssobomax 49199855Ssobomax#include <sys/queue.h> 50199855Ssobomax 51199855SsobomaxTAILQ_HEAD(pagerlst, vm_object); 52199855Ssobomax 53199855Ssobomaxstruct bio; 54199855Ssobomax 55199855Ssobomaxstruct pagerops { 56199855Ssobomax void (*pgo_init) __P((void)); /* Initialize pager. */ 5766133Sarchie vm_object_t (*pgo_alloc) __P((void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t)); /* Allocate pager. */ 58199855Ssobomax void (*pgo_dealloc) __P((vm_object_t)); /* Disassociate. */ 59199855Ssobomax int (*pgo_getpages) __P((vm_object_t, vm_page_t *, int, int)); /* Get (read) page. */ 60199855Ssobomax void (*pgo_putpages) __P((vm_object_t, vm_page_t *, int, int, int *)); /* Put (write) page. */ 61199855Ssobomax boolean_t (*pgo_haspage) __P((vm_object_t, vm_pindex_t, int *, int *)); /* Does pager have page? */ 62199855Ssobomax void (*pgo_pageunswapped) __P((vm_page_t)); 6366133Sarchie void (*pgo_strategy) __P((vm_object_t, struct bio *)); 6466133Sarchie}; 6566133Sarchie 66199855Ssobomax/* 6766133Sarchie * get/put return values 6866133Sarchie * OK operation was successful 6966133Sarchie * BAD specified data was out of the accepted range 7066133Sarchie * FAIL specified data was in range, but doesn't exist 7166133Sarchie * PEND operations was initiated but not completed 72199855Ssobomax * ERROR error while accessing data that is in range and exists 7366133Sarchie * AGAIN temporary resource shortage prevented operation from happening 7466133Sarchie */ 7566133Sarchie#define VM_PAGER_OK 0 7666133Sarchie#define VM_PAGER_BAD 1 7766133Sarchie#define VM_PAGER_FAIL 2 78199855Ssobomax#define VM_PAGER_PEND 3 7966133Sarchie#define VM_PAGER_ERROR 4 80199855Ssobomax#define VM_PAGER_AGAIN 5 81199855Ssobomax 82199857Ssobomax#define VM_PAGER_PUT_SYNC 0x1 83199855Ssobomax#define VM_PAGER_PUT_INVAL 0x2 84199855Ssobomax 85199856Ssobomax#ifdef _KERNEL 86199856Ssobomax 87199856Ssobomax#ifdef MALLOC_DECLARE 88199856SsobomaxMALLOC_DECLARE(M_VMPGDATA); 89199855Ssobomax#endif 90199855Ssobomax 91199855Ssobomaxextern vm_map_t pager_map; 92199855Ssobomaxextern int pager_map_size; 93199855Ssobomaxextern struct pagerops *pagertab[]; 9466133Sarchieextern struct mtx pbuf_mtx; 9566133Sarchie 9666133Sarchievm_object_t vm_pager_allocate __P((objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t)); 97199855Ssobomaxvoid vm_pager_bufferinit __P((void)); 9866133Sarchievoid vm_pager_deallocate __P((vm_object_t)); 9966133Sarchiestatic __inline int vm_pager_get_pages __P((vm_object_t, vm_page_t *, int, int)); 10066133Sarchiestatic __inline boolean_t vm_pager_has_page __P((vm_object_t, vm_pindex_t, int *, int *)); 10166133Sarchievoid vm_pager_init __P((void)); 10266133Sarchievm_object_t vm_pager_object_lookup __P((struct pagerlst *, void *)); 103199855Ssobomaxvm_offset_t vm_pager_map_pages __P((vm_page_t *, int, boolean_t)); 10466133Sarchievm_offset_t vm_pager_map_page __P((vm_page_t)); 10566133Sarchievoid vm_pager_sync __P((void)); 10666133Sarchievoid vm_pager_unmap_pages __P((vm_offset_t, int)); 107void vm_pager_unmap_page __P((vm_offset_t)); 108void vm_pager_strategy __P((vm_object_t object, struct bio *bp)); 109 110/* 111 * vm_page_get_pages: 112 * 113 * Retrieve pages from the VM system in order to map them into an object 114 * ( or into VM space somewhere ). If the pagein was successful, we 115 * must fully validate it. 116 */ 117 118static __inline int 119vm_pager_get_pages( 120 vm_object_t object, 121 vm_page_t *m, 122 int count, 123 int reqpage 124) { 125 int r; 126 127 r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage); 128 if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) { 129 vm_page_zero_invalid(m[reqpage], TRUE); 130 } 131 return(r); 132} 133 134static __inline void 135vm_pager_put_pages( 136 vm_object_t object, 137 vm_page_t *m, 138 int count, 139 int flags, 140 int *rtvals 141) { 142 (*pagertab[object->type]->pgo_putpages) 143 (object, m, count, flags, rtvals); 144} 145 146/* 147 * vm_pager_haspage 148 * 149 * Check to see if an object's pager has the requested page. The 150 * object's pager will also set before and after to give the caller 151 * some idea of the number of pages before and after the requested 152 * page can be I/O'd efficiently. 153 * 154 * This routine does not have to be called at any particular spl. 155 */ 156 157static __inline boolean_t 158vm_pager_has_page( 159 vm_object_t object, 160 vm_pindex_t offset, 161 int *before, 162 int *after 163) { 164 return ((*pagertab[object->type]->pgo_haspage) (object, offset, before, after)); 165} 166 167/* 168 * vm_pager_page_unswapped 169 * 170 * called at splvm() to destroy swap associated with the page. 171 * 172 * This function may not block. 173 */ 174 175static __inline void 176vm_pager_page_unswapped(vm_page_t m) 177{ 178 if (pagertab[m->object->type]->pgo_pageunswapped) 179 (*pagertab[m->object->type]->pgo_pageunswapped)(m); 180} 181 182#endif 183 184#endif /* _VM_PAGER_ */ 185