vm_pager.h revision 46349
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1990 University of Utah. 31541Srgrimes * Copyright (c) 1991, 1993 41541Srgrimes * The Regents of the University of California. All rights reserved. 51541Srgrimes * 61541Srgrimes * This code is derived from software contributed to Berkeley by 71541Srgrimes * the Systems Programming Group of the University of Utah Computer 81541Srgrimes * Science Department. 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 3. All advertising materials mentioning features or use of this software 191541Srgrimes * must display the following acknowledgement: 201541Srgrimes * This product includes software developed by the University of 211541Srgrimes * California, Berkeley and its contributors. 221541Srgrimes * 4. Neither the name of the University nor the names of its contributors 231541Srgrimes * may be used to endorse or promote products derived from this software 241541Srgrimes * without specific prior written permission. 251541Srgrimes * 261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361541Srgrimes * SUCH DAMAGE. 371541Srgrimes * 381541Srgrimes * @(#)vm_pager.h 8.4 (Berkeley) 1/12/94 3946349Salc * $Id: vm_pager.h,v 1.21 1999/03/14 09:20:00 julian Exp $ 401541Srgrimes */ 411541Srgrimes 421541Srgrimes/* 431541Srgrimes * Pager routine interface definition. 441541Srgrimes */ 451541Srgrimes 461541Srgrimes#ifndef _VM_PAGER_ 471541Srgrimes#define _VM_PAGER_ 481541Srgrimes 4933058Sbde#include <sys/queue.h> 5033058Sbde 519507SdgTAILQ_HEAD(pagerlst, vm_object); 521541Srgrimes 5344739Sjulianstruct buf; 5444739Sjulian 555455Sdgstruct pagerops { 565455Sdg void (*pgo_init) __P((void)); /* Initialize pager. */ 5740286Sdg vm_object_t (*pgo_alloc) __P((void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t)); /* Allocate pager. */ 589507Sdg void (*pgo_dealloc) __P((vm_object_t)); /* Disassociate. */ 599507Sdg int (*pgo_getpages) __P((vm_object_t, vm_page_t *, int, int)); /* Get (read) page. */ 6043129Sdillon void (*pgo_putpages) __P((vm_object_t, vm_page_t *, int, int, int *)); /* Put (write) page. */ 6112767Sdyson boolean_t (*pgo_haspage) __P((vm_object_t, vm_pindex_t, int *, int *)); /* Does pager have page? */ 6242957Sdillon void (*pgo_pageunswapped) __P((vm_page_t)); 6344739Sjulian void (*pgo_strategy) __P((vm_object_t, struct buf *)); 641541Srgrimes}; 651541Srgrimes 661541Srgrimes/* 671541Srgrimes * get/put return values 681541Srgrimes * OK operation was successful 691541Srgrimes * BAD specified data was out of the accepted range 701541Srgrimes * FAIL specified data was in range, but doesn't exist 711541Srgrimes * PEND operations was initiated but not completed 721541Srgrimes * ERROR error while accessing data that is in range and exists 731541Srgrimes * AGAIN temporary resource shortage prevented operation from happening 741541Srgrimes */ 751541Srgrimes#define VM_PAGER_OK 0 761541Srgrimes#define VM_PAGER_BAD 1 771541Srgrimes#define VM_PAGER_FAIL 2 781541Srgrimes#define VM_PAGER_PEND 3 791541Srgrimes#define VM_PAGER_ERROR 4 801541Srgrimes#define VM_PAGER_AGAIN 5 811541Srgrimes 8234206Sdyson#define VM_PAGER_PUT_SYNC 0x1 8334206Sdyson#define VM_PAGER_PUT_INVAL 0x2 8434206Sdyson 851541Srgrimes#ifdef KERNEL 8630354Sphk 8730354Sphk#ifdef MALLOC_DECLARE 8830354SphkMALLOC_DECLARE(M_VMPGDATA); 8930354Sphk#endif 9030354Sphk 919759Sbdeextern vm_map_t pager_map; 929759Sbdeextern int pager_map_size; 9342957Sdillonextern struct pagerops *pagertab[]; 949759Sbde 9540286Sdgvm_object_t vm_pager_allocate __P((objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t)); 967090Sbdevoid vm_pager_bufferinit __P((void)); 979507Sdgvoid vm_pager_deallocate __P((vm_object_t)); 9842957Sdillonstatic __inline int vm_pager_get_pages __P((vm_object_t, vm_page_t *, int, int)); 9942957Sdillonstatic __inline boolean_t vm_pager_has_page __P((vm_object_t, vm_pindex_t, int *, int *)); 1005455Sdgvoid vm_pager_init __P((void)); 1019507Sdgvm_object_t vm_pager_object_lookup __P((struct pagerlst *, void *)); 1025455Sdgvm_offset_t vm_pager_map_pages __P((vm_page_t *, int, boolean_t)); 1035455Sdgvm_offset_t vm_pager_map_page __P((vm_page_t)); 1045455Sdgvoid vm_pager_sync __P((void)); 1055455Sdgvoid vm_pager_unmap_pages __P((vm_offset_t, int)); 1065455Sdgvoid vm_pager_unmap_page __P((vm_offset_t)); 10744739Sjulianvoid vm_pager_strategy __P((vm_object_t object, struct buf *bp)); 10844739Sjulianstruct buf *getchainbuf(struct buf *bp, struct vnode *vp, int flags); 10944739Sjulianvoid flushchainbuf(struct buf *nbp); 11044739Sjulianvoid waitchainbuf(struct buf *bp, int count, int done); 11144739Sjulianvoid autochaindone(struct buf *bp); 11242957Sdillon 11346349Salc/* 11446349Salc * vm_page_get_pages: 11546349Salc * 11646349Salc * Retrieve pages from the VM system in order to map them into an object 11746349Salc * ( or into VM space somewhere ). If the pagein was successful, we 11846349Salc * must fully validate it. 11946349Salc */ 12046349Salc 12142957Sdillonstatic __inline int 12242957Sdillonvm_pager_get_pages( 12342957Sdillon vm_object_t object, 12442957Sdillon vm_page_t *m, 12542957Sdillon int count, 12642957Sdillon int reqpage 12742957Sdillon) { 12846349Salc int r; 12946349Salc 13046349Salc r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage); 13146349Salc if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) { 13246349Salc vm_page_zero_invalid(m[reqpage], TRUE); 13346349Salc } 13446349Salc return(r); 13542957Sdillon} 13642957Sdillon 13743129Sdillonstatic __inline void 13842957Sdillonvm_pager_put_pages( 13942957Sdillon vm_object_t object, 14042957Sdillon vm_page_t *m, 14142957Sdillon int count, 14242957Sdillon int flags, 14342957Sdillon int *rtvals 14442957Sdillon) { 14543129Sdillon (*pagertab[object->type]->pgo_putpages) 14643129Sdillon (object, m, count, flags, rtvals); 14742957Sdillon} 14842957Sdillon 14942957Sdillonstatic __inline boolean_t 15042957Sdillonvm_pager_has_page( 15142957Sdillon vm_object_t object, 15242957Sdillon vm_pindex_t offset, 15342957Sdillon int *before, 15442957Sdillon int *after 15542957Sdillon) { 15642957Sdillon return ((*pagertab[object->type]->pgo_haspage) (object, offset, before, after)); 15742957Sdillon} 15842957Sdillon 15942957Sdillon/* 16042957Sdillon * vm_pager_page_unswapped 16142957Sdillon * 16242957Sdillon * called at splvm() to destroy swap associated with the page. 16342957Sdillon * 16442957Sdillon * This function may not block. 16542957Sdillon */ 16642957Sdillon 16742957Sdillonstatic __inline void 16842957Sdillonvm_pager_page_unswapped(vm_page_t m) 16942957Sdillon{ 17042957Sdillon if (pagertab[m->object->type]->pgo_pageunswapped) 17142957Sdillon (*pagertab[m->object->type]->pgo_pageunswapped)(m); 17242957Sdillon} 17342957Sdillon 1741541Srgrimes#endif 1751541Srgrimes 1765455Sdg#endif /* _VM_PAGER_ */ 177