vm_pager.h revision 1541
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 391541Srgrimes */ 401541Srgrimes 411541Srgrimes/* 421541Srgrimes * Pager routine interface definition. 431541Srgrimes * For BSD we use a cleaner version of the internal pager interface. 441541Srgrimes */ 451541Srgrimes 461541Srgrimes#ifndef _VM_PAGER_ 471541Srgrimes#define _VM_PAGER_ 481541Srgrimes 491541SrgrimesTAILQ_HEAD(pagerlst, pager_struct); 501541Srgrimes 511541Srgrimesstruct pager_struct { 521541Srgrimes TAILQ_ENTRY(pager_struct) pg_list; /* links for list management */ 531541Srgrimes caddr_t pg_handle; /* ext. handle (vp, dev, fp) */ 541541Srgrimes int pg_type; /* type of pager */ 551541Srgrimes int pg_flags; /* flags */ 561541Srgrimes struct pagerops *pg_ops; /* pager operations */ 571541Srgrimes void *pg_data; /* private pager data */ 581541Srgrimes}; 591541Srgrimes 601541Srgrimes/* pager types */ 611541Srgrimes#define PG_DFLT -1 621541Srgrimes#define PG_SWAP 0 631541Srgrimes#define PG_VNODE 1 641541Srgrimes#define PG_DEVICE 2 651541Srgrimes 661541Srgrimes/* flags */ 671541Srgrimes#define PG_CLUSTERGET 1 681541Srgrimes#define PG_CLUSTERPUT 2 691541Srgrimes 701541Srgrimesstruct pagerops { 711541Srgrimes void (*pgo_init) /* Initialize pager. */ 721541Srgrimes __P((void)); 731541Srgrimes vm_pager_t (*pgo_alloc) /* Allocate pager. */ 741541Srgrimes __P((caddr_t, vm_size_t, vm_prot_t, vm_offset_t)); 751541Srgrimes void (*pgo_dealloc) /* Disassociate. */ 761541Srgrimes __P((vm_pager_t)); 771541Srgrimes int (*pgo_getpages) /* Get (read) page. */ 781541Srgrimes __P((vm_pager_t, vm_page_t *, int, boolean_t)); 791541Srgrimes int (*pgo_putpages) /* Put (write) page. */ 801541Srgrimes __P((vm_pager_t, vm_page_t *, int, boolean_t)); 811541Srgrimes boolean_t (*pgo_haspage) /* Does pager have page? */ 821541Srgrimes __P((vm_pager_t, vm_offset_t)); 831541Srgrimes void (*pgo_cluster) /* Return range of cluster. */ 841541Srgrimes __P((vm_pager_t, vm_offset_t, 851541Srgrimes vm_offset_t *, vm_offset_t *)); 861541Srgrimes}; 871541Srgrimes 881541Srgrimes/* 891541Srgrimes * get/put return values 901541Srgrimes * OK operation was successful 911541Srgrimes * BAD specified data was out of the accepted range 921541Srgrimes * FAIL specified data was in range, but doesn't exist 931541Srgrimes * PEND operations was initiated but not completed 941541Srgrimes * ERROR error while accessing data that is in range and exists 951541Srgrimes * AGAIN temporary resource shortage prevented operation from happening 961541Srgrimes */ 971541Srgrimes#define VM_PAGER_OK 0 981541Srgrimes#define VM_PAGER_BAD 1 991541Srgrimes#define VM_PAGER_FAIL 2 1001541Srgrimes#define VM_PAGER_PEND 3 1011541Srgrimes#define VM_PAGER_ERROR 4 1021541Srgrimes#define VM_PAGER_AGAIN 5 1031541Srgrimes 1041541Srgrimes#ifdef KERNEL 1051541Srgrimesextern struct pagerops *dfltpagerops; 1061541Srgrimes 1071541Srgrimesvm_pager_t vm_pager_allocate 1081541Srgrimes __P((int, caddr_t, vm_size_t, vm_prot_t, vm_offset_t)); 1091541Srgrimesvm_page_t vm_pager_atop __P((vm_offset_t)); 1101541Srgrimesvoid vm_pager_cluster 1111541Srgrimes __P((vm_pager_t, vm_offset_t, 1121541Srgrimes vm_offset_t *, vm_offset_t *)); 1131541Srgrimesvoid vm_pager_clusternull 1141541Srgrimes __P((vm_pager_t, vm_offset_t, 1151541Srgrimes vm_offset_t *, vm_offset_t *)); 1161541Srgrimesvoid vm_pager_deallocate __P((vm_pager_t)); 1171541Srgrimesint vm_pager_get_pages 1181541Srgrimes __P((vm_pager_t, vm_page_t *, int, boolean_t)); 1191541Srgrimesboolean_t vm_pager_has_page __P((vm_pager_t, vm_offset_t)); 1201541Srgrimesvoid vm_pager_init __P((void)); 1211541Srgrimesvm_pager_t vm_pager_lookup __P((struct pagerlst *, caddr_t)); 1221541Srgrimesvm_offset_t vm_pager_map_pages __P((vm_page_t *, int, boolean_t)); 1231541Srgrimesint vm_pager_put_pages 1241541Srgrimes __P((vm_pager_t, vm_page_t *, int, boolean_t)); 1251541Srgrimesvoid vm_pager_sync __P((void)); 1261541Srgrimesvoid vm_pager_unmap_pages __P((vm_offset_t, int)); 1271541Srgrimes 1281541Srgrimes#define vm_pager_cancluster(p, b) ((p)->pg_flags & (b)) 1291541Srgrimes 1301541Srgrimes/* 1311541Srgrimes * XXX compat with old interface 1321541Srgrimes */ 1331541Srgrimes#define vm_pager_get(p, m, s) \ 1341541Srgrimes({ \ 1351541Srgrimes vm_page_t ml[1]; \ 1361541Srgrimes ml[0] = (m); \ 1371541Srgrimes vm_pager_get_pages(p, ml, 1, s); \ 1381541Srgrimes}) 1391541Srgrimes#define vm_pager_put(p, m, s) \ 1401541Srgrimes({ \ 1411541Srgrimes vm_page_t ml[1]; \ 1421541Srgrimes ml[0] = (m); \ 1431541Srgrimes vm_pager_put_pages(p, ml, 1, s); \ 1441541Srgrimes}) 1451541Srgrimes#endif 1461541Srgrimes 1471541Srgrimes#endif /* _VM_PAGER_ */ 148