1 /* $OpenBSD: uvm_pager.h,v 1.20 2003/06/02 23:28:24 millert Exp $ */
2 /* $NetBSD: uvm_pager.h,v 1.20 2000/11/27 08:40:05 chs Exp $ */
3
4 /*
5 *
6 * Copyright (c) 1997 Charles D. Cranor and Washington University.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Charles D. Cranor and
20 * Washington University.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * from: Id: uvm_pager.h,v 1.1.2.14 1998/01/13 19:00:50 chuck Exp
36 */
37
38 /*
39 * Copyright (c) 1990 University of Utah.
40 * Copyright (c) 1991, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * the Systems Programming Group of the University of Utah Computer
45 * Science Department.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)vm_pager.h 8.5 (Berkeley) 7/7/94
72 */
73
74 #ifndef _UVM_UVM_PAGER_H_
75 #define _UVM_UVM_PAGER_H_
76
77 /*
78 * uvm_pager.h
79 */
80
81 /*
82 * pager ops
83 */
84
85 struct uvm_pagerops {
86 /* init pager */
87 void (*pgo_init)(void);
88 /* add reference to obj */
89 void (*pgo_reference)(struct uvm_object *);
90 /* drop reference to obj */
91 void (*pgo_detach)(struct uvm_object *);
92 /* special nonstd fault fn */
93 int (*pgo_fault)(struct uvm_faultinfo *, vaddr_t,
94 vm_page_t *, int, int, vm_fault_t,
95 vm_prot_t, int);
96 /* flush pages out of obj */
97 boolean_t (*pgo_flush)(struct uvm_object *, voff_t,
98 voff_t, int);
99 /* get/read page */
100 int (*pgo_get)(struct uvm_object *, voff_t,
101 vm_page_t *, int *, int, vm_prot_t, int, int);
102 /* put/write page */
103 int (*pgo_put)(struct uvm_object *, vm_page_t *,
104 int, boolean_t);
105 /* return range of cluster */
106 void (*pgo_cluster)(struct uvm_object *, voff_t,
107 voff_t *, voff_t *);
108 /* make "put" cluster */
109 struct vm_page ** (*pgo_mk_pcluster)(struct uvm_object *,
110 struct vm_page **, int *, struct vm_page *,
111 int, voff_t, voff_t);
112 /* release page */
113 boolean_t (*pgo_releasepg)(struct vm_page *, struct vm_page **);
114 };
115
116 /* pager flags [mostly for flush] */
117
118 #define PGO_CLEANIT 0x001 /* write dirty pages to backing store */
119 #define PGO_SYNCIO 0x002 /* if PGO_CLEANIT: use sync I/O? */
120 #define PGO_DEACTIVATE 0x004 /* deactivate flushed pages */
121 #define PGO_FREE 0x008 /* free flushed pages */
122 /* if PGO_FREE is not set then the pages stay where they are. */
123
124 #define PGO_ALLPAGES 0x010 /* flush whole object/get all pages */
125 #define PGO_DOACTCLUST 0x020 /* flag to mk_pcluster to include active */
126 #define PGO_LOCKED 0x040 /* fault data structures are locked [get] */
127 #define PGO_PDFREECLUST 0x080 /* daemon's free cluster flag [uvm_pager_put] */
128 #define PGO_REALLOCSWAP 0x100 /* reallocate swap area [pager_dropcluster] */
129 #define PGO_OVERWRITE 0x200 /* pages will be overwritten before unlocked */
130 #define PGO_WEAK 0x400 /* "weak" put, for nfs */
131 #define PGO_PASTEOF 0x800 /* allow allocation of pages past EOF */
132
133 /* page we are not interested in getting */
134 #define PGO_DONTCARE ((struct vm_page *) -1L) /* [get only] */
135
136 #ifdef _KERNEL
137
138 /*
139 * handle inline options
140 */
141
142 #ifdef UVM_PAGER_INLINE
143 #define PAGER_INLINE static __inline
144 #else
145 #define PAGER_INLINE /* nothing */
146 #endif /* UVM_PAGER_INLINE */
147
148 /*
149 * prototypes
150 */
151
152 void uvm_pager_dropcluster(struct uvm_object *,
153 struct vm_page *, struct vm_page **,
154 int *, int);
155 void uvm_pager_init(void);
156 int uvm_pager_put(struct uvm_object *, struct vm_page *,
157 struct vm_page ***, int *, int,
158 voff_t, voff_t);
159
160 PAGER_INLINE struct vm_page *uvm_pageratop(vaddr_t);
161
162 vaddr_t uvm_pagermapin(struct vm_page **, int, int);
163 void uvm_pagermapout(vaddr_t, int);
164 struct vm_page **uvm_mk_pcluster(struct uvm_object *, struct vm_page **,
165 int *, struct vm_page *, int,
166 voff_t, voff_t);
167 int uvm_errno2vmerror(int);
168
169 /* Flags to uvm_pagermapin() */
170 #define UVMPAGER_MAPIN_WAITOK 0x01 /* it's okay to wait */
171 #define UVMPAGER_MAPIN_READ 0x02 /* host <- device */
172 #define UVMPAGER_MAPIN_WRITE 0x00 /* device -> host (pseudo flag) */
173
174 /*
175 * get/put return values
176 * OK operation was successful
177 * BAD specified data was out of the accepted range
178 * FAIL specified data was in range, but doesn't exist
179 * PEND operations was initiated but not completed
180 * ERROR error while accessing data that is in range and exists
181 * AGAIN temporary resource shortage prevented operation from happening
182 * UNLOCK unlock the map and try again
183 * REFAULT [uvm_fault internal use only!] unable to relock data structures,
184 * thus the mapping needs to be reverified before we can procede
185 */
186 #define VM_PAGER_OK 0
187 #define VM_PAGER_BAD 1
188 #define VM_PAGER_FAIL 2
189 #define VM_PAGER_PEND 3
190 #define VM_PAGER_ERROR 4
191 #define VM_PAGER_AGAIN 5
192 #define VM_PAGER_UNLOCK 6
193 #define VM_PAGER_REFAULT 7
194
195 /*
196 * XXX
197 * this is needed until the device strategy interface
198 * is changed to do physically-addressed i/o.
199 */
200
201 #ifndef PAGER_MAP_SIZE
202 #define PAGER_MAP_SIZE (16 * 1024 * 1024)
203 #endif
204
205 #endif /* _KERNEL */
206
207 #endif /* _UVM_UVM_PAGER_H_ */