1 2 /* 3 * Copyright (c) 1990 University of Utah. 4 * Copyright (c) 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * the Systems Programming Group of the University of Utah Computer 9 * Science Department. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)vm_pager.h 8.4 (Berkeley) 1/12/94 40 * $Id: vm_pager.h,v 1.4 1994/10/09 01:52:17 phk Exp $ 41 */ 42 43 /* 44 * Pager routine interface definition. 45 * For BSD we use a cleaner version of the internal pager interface. 46 */ 47 48 #ifndef _VM_PAGER_ 49 #define _VM_PAGER_ 50 51 TAILQ_HEAD(pagerlst, pager_struct); 52 53 struct pager_struct { 54 TAILQ_ENTRY(pager_struct) pg_list; /* links for list management */ 55 caddr_t pg_handle; /* ext. handle (vp, dev, fp) */ 56 int pg_type; /* type of pager */ 57 struct pagerops *pg_ops; /* pager operations */ 58 void *pg_data; /* private pager data */ 59 }; 60 61 /* pager types */ 62 #define PG_DFLT -1 63 #define PG_SWAP 0 64 #define PG_VNODE 1 65 #define PG_DEVICE 2 66 67 /* flags */ 68 #define PG_CLUSTERGET 1 69 #define PG_CLUSTERPUT 2 70 71 struct pagerops { 72 void (*pgo_init) __P((void)); /* Initialize pager. */ 73 vm_pager_t(*pgo_alloc) __P((caddr_t, vm_size_t, vm_prot_t, vm_offset_t)); /* Allocate pager. */ 74 void (*pgo_dealloc) __P((vm_pager_t)); /* Disassociate. */ 75 int (*pgo_getpage) __P((vm_pager_t, vm_page_t, boolean_t)); 76 int (*pgo_getpages) __P((vm_pager_t, vm_page_t *, int, int, boolean_t)); /* Get (read) page. */ 77 int (*pgo_putpage) __P((vm_pager_t, vm_page_t, boolean_t)); 78 int (*pgo_putpages) __P((vm_pager_t, vm_page_t *, int, boolean_t, int *)); /* Put (write) page. */ 79 boolean_t(*pgo_haspage) __P((vm_pager_t, vm_offset_t)); /* Does pager have page? */ 80 }; 81 82 #define VM_PAGER_ALLOC(h, s, p, o) (*(pg)->pg_ops->pgo_alloc)(h, s, p, o) 83 #define VM_PAGER_DEALLOC(pg) (*(pg)->pg_ops->pgo_dealloc)(pg) 84 #define VM_PAGER_GET(pg, m, s) (*(pg)->pg_ops->pgo_getpage)(pg, m, s) 85 #define VM_PAGER_GET_MULTI(pg, m, c, r, s) (*(pg)->pg_ops->pgo_getpages)(pg, m, c, r, s) 86 #define VM_PAGER_PUT(pg, m, s) (*(pg)->pg_ops->pgo_putpage)(pg, m, s) 87 #define VM_PAGER_PUT_MULTI(pg, m, c, s, rtval) (*(pg)->pg_ops->pgo_putpages)(pg, m, c, s, rtval) 88 #define VM_PAGER_HASPAGE(pg, o) (*(pg)->pg_ops->pgo_haspage)(pg, o) 89 90 /* 91 * get/put return values 92 * OK operation was successful 93 * BAD specified data was out of the accepted range 94 * FAIL specified data was in range, but doesn't exist 95 * PEND operations was initiated but not completed 96 * ERROR error while accessing data that is in range and exists 97 * AGAIN temporary resource shortage prevented operation from happening 98 */ 99 #define VM_PAGER_OK 0 100 #define VM_PAGER_BAD 1 101 #define VM_PAGER_FAIL 2 102 #define VM_PAGER_PEND 3 103 #define VM_PAGER_ERROR 4 104 #define VM_PAGER_AGAIN 5 105 106 #ifdef KERNEL 107 extern struct pagerops *dfltpagerops; 108 109 vm_pager_t vm_pager_allocate __P((int, caddr_t, vm_size_t, vm_prot_t, vm_offset_t)); 110 vm_page_t vm_pager_atop __P((vm_offset_t)); 111 void vm_pager_deallocate __P((vm_pager_t)); 112 int vm_pager_get_pages __P((vm_pager_t, vm_page_t *, int, int, boolean_t)); 113 boolean_t vm_pager_has_page __P((vm_pager_t, vm_offset_t)); 114 void vm_pager_init __P((void)); 115 vm_pager_t vm_pager_lookup __P((struct pagerlst *, caddr_t)); 116 vm_offset_t vm_pager_map_pages __P((vm_page_t *, int, boolean_t)); 117 vm_offset_t vm_pager_map_page __P((vm_page_t)); 118 int vm_pager_put_pages __P((vm_pager_t, vm_page_t *, int, boolean_t, int *)); 119 void vm_pager_sync __P((void)); 120 void vm_pager_unmap_pages __P((vm_offset_t, int)); 121 void vm_pager_unmap_page __P((vm_offset_t)); 122 123 /* 124 * XXX compat with old interface 125 */ 126 #define vm_pager_get(p, m, s) \ 127 ({ \ 128 vm_page_t ml[1]; \ 129 ml[0] = (m); \ 130 vm_pager_get_pages(p, ml, 1, 0, s); \ 131 }) 132 133 #define vm_pager_put(p, m, s) \ 134 ({ \ 135 int rtval; \ 136 vm_page_t ml[1]; \ 137 ml[0] = (m); \ 138 vm_pager_put_pages(p, ml, 1, s, &rtval); \ 139 rtval; \ 140 }) 141 #endif 142 143 #endif /* _VM_PAGER_ */ 144