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$ 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 int pg_flags; /* flags */ 58 struct pagerops *pg_ops; /* pager operations */ 59 void *pg_data; /* private pager data */ 60 }; 61 62 /* pager types */ 63 #define PG_DFLT -1 64 #define PG_SWAP 0 65 #define PG_VNODE 1 66 #define PG_DEVICE 2 67 68 /* flags */ 69 #define PG_CLUSTERGET 1 70 #define PG_CLUSTERPUT 2 71 72 struct pagerops { 73 void (*pgo_init) /* Initialize pager. */ 74 __P((void)); 75 vm_pager_t (*pgo_alloc) /* Allocate pager. */ 76 __P((caddr_t, vm_size_t, vm_prot_t, vm_offset_t)); 77 void (*pgo_dealloc) /* Disassociate. */ 78 __P((vm_pager_t)); 79 int (*pgo_getpage) 80 __P((vm_pager_t, vm_page_t, boolean_t)); 81 int (*pgo_getpages) /* Get (read) page. */ 82 __P((vm_pager_t, vm_page_t *, int, int, boolean_t)); 83 int (*pgo_putpage) 84 __P((vm_pager_t, vm_page_t, boolean_t)); 85 int (*pgo_putpages) /* Put (write) page. */ 86 __P((vm_pager_t, vm_page_t *, int, boolean_t, int *)); 87 boolean_t (*pgo_haspage) /* Does pager have page? */ 88 __P((vm_pager_t, vm_offset_t)); 89 }; 90 91 #define VM_PAGER_ALLOC(h, s, p, o) (*(pg)->pg_ops->pgo_alloc)(h, s, p, o) 92 #define VM_PAGER_DEALLOC(pg) (*(pg)->pg_ops->pgo_dealloc)(pg) 93 #define VM_PAGER_GET(pg, m, s) (*(pg)->pg_ops->pgo_getpage)(pg, m, s) 94 #define VM_PAGER_GET_MULTI(pg, m, c, r, s) (*(pg)->pg_ops->pgo_getpages)(pg, m, c, r, s) 95 #define VM_PAGER_PUT(pg, m, s) (*(pg)->pg_ops->pgo_putpage)(pg, m, s) 96 #define VM_PAGER_PUT_MULTI(pg, m, c, s, rtval) (*(pg)->pg_ops->pgo_putpages)(pg, m, c, s, rtval) 97 #define VM_PAGER_HASPAGE(pg, o) (*(pg)->pg_ops->pgo_haspage)(pg, o) 98 99 /* 100 * get/put return values 101 * OK operation was successful 102 * BAD specified data was out of the accepted range 103 * FAIL specified data was in range, but doesn't exist 104 * PEND operations was initiated but not completed 105 * ERROR error while accessing data that is in range and exists 106 * AGAIN temporary resource shortage prevented operation from happening 107 */ 108 #define VM_PAGER_OK 0 109 #define VM_PAGER_BAD 1 110 #define VM_PAGER_FAIL 2 111 #define VM_PAGER_PEND 3 112 #define VM_PAGER_ERROR 4 113 #define VM_PAGER_AGAIN 5 114 115 #ifdef KERNEL 116 extern struct pagerops *dfltpagerops; 117 118 vm_pager_t vm_pager_allocate 119 __P((int, caddr_t, vm_size_t, vm_prot_t, vm_offset_t)); 120 vm_page_t vm_pager_atop __P((vm_offset_t)); 121 void vm_pager_deallocate __P((vm_pager_t)); 122 int vm_pager_get_pages 123 __P((vm_pager_t, vm_page_t *, int, int, boolean_t)); 124 boolean_t vm_pager_has_page __P((vm_pager_t, vm_offset_t)); 125 void vm_pager_init __P((void)); 126 vm_pager_t vm_pager_lookup __P((struct pagerlst *, caddr_t)); 127 vm_offset_t vm_pager_map_pages __P((vm_page_t *, int, boolean_t)); 128 int vm_pager_put_pages 129 __P((vm_pager_t, vm_page_t *, int, boolean_t, int *)); 130 void vm_pager_sync __P((void)); 131 void vm_pager_unmap_pages __P((vm_offset_t, int)); 132 133 #define vm_pager_cancluster(p, b) ((p)->pg_flags & (b)) 134 135 /* 136 * XXX compat with old interface 137 */ 138 #define vm_pager_get(p, m, s) \ 139 ({ \ 140 vm_page_t ml[1]; \ 141 ml[0] = (m); \ 142 vm_pager_get_pages(p, ml, 1, 0, s); \ 143 }) 144 145 #define vm_pager_put(p, m, s) \ 146 ({ \ 147 int rtval; \ 148 vm_page_t ml[1]; \ 149 ml[0] = (m); \ 150 vm_pager_put_pages(p, ml, 1, s, &rtval); \ 151 rtval; \ 152 }) 153 #endif 154 155 #endif /* _VM_PAGER_ */ 156