xref: /openbsd-src/sys/uvm/uvm_pager.h (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1 /*	$OpenBSD: uvm_pager.h,v 1.27 2009/07/22 21:05:37 oga 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 };
113 
114 /* pager flags [mostly for flush] */
115 
116 #define PGO_CLEANIT	0x001	/* write dirty pages to backing store */
117 #define PGO_SYNCIO	0x002	/* if PGO_CLEANIT: use sync I/O? */
118 #define PGO_DEACTIVATE	0x004	/* deactivate flushed pages */
119 #define PGO_FREE	0x008	/* free flushed pages */
120 /* if PGO_FREE is not set then the pages stay where they are. */
121 
122 #define PGO_ALLPAGES	0x010	/* flush whole object/get all pages */
123 #define PGO_DOACTCLUST	0x020	/* flag to mk_pcluster to include active */
124 #define PGO_LOCKED	0x040	/* fault data structures are locked [get] */
125 #define PGO_PDFREECLUST	0x080	/* daemon's free cluster flag [uvm_pager_put] */
126 #define PGO_REALLOCSWAP	0x100	/* reallocate swap area [pager_dropcluster] */
127 
128 /* page we are not interested in getting */
129 #define PGO_DONTCARE ((struct vm_page *) -1L)	/* [get only] */
130 
131 #ifdef _KERNEL
132 
133 /*
134  * prototypes
135  */
136 
137 void		uvm_pager_dropcluster(struct uvm_object *, struct vm_page *,
138 		    struct vm_page **, int *, int);
139 void		uvm_pager_init(void);
140 int		uvm_pager_put(struct uvm_object *, struct vm_page *,
141 		    struct vm_page ***, int *, int, voff_t, voff_t);
142 
143 
144 vaddr_t		uvm_pagermapin(struct vm_page **, int, int);
145 void		uvm_pagermapout(vaddr_t, int);
146 struct vm_page **uvm_mk_pcluster(struct uvm_object *, struct vm_page **,
147 		    int *, struct vm_page *, int, voff_t, voff_t);
148 
149 /* Flags to uvm_pagermapin() */
150 #define	UVMPAGER_MAPIN_WAITOK	0x01	/* it's okay to wait */
151 #define	UVMPAGER_MAPIN_READ	0x02	/* host <- device */
152 #define	UVMPAGER_MAPIN_WRITE	0x00	/* device -> host (pseudo flag) */
153 
154 /*
155  * get/put return values
156  * OK	   operation was successful
157  * BAD	   specified data was out of the accepted range
158  * FAIL	   specified data was in range, but doesn't exist
159  * PEND	   operations was initiated but not completed
160  * ERROR   error while accessing data that is in range and exists
161  * AGAIN   temporary resource shortage prevented operation from happening
162  * UNLOCK  unlock the map and try again
163  * REFAULT [uvm_fault internal use only!] unable to relock data structures,
164  *         thus the mapping needs to be reverified before we can procede
165  */
166 #define	VM_PAGER_OK		0
167 #define	VM_PAGER_BAD		1
168 #define	VM_PAGER_FAIL		2
169 #define	VM_PAGER_PEND		3
170 #define	VM_PAGER_ERROR		4
171 #define VM_PAGER_AGAIN		5
172 #define VM_PAGER_UNLOCK		6
173 #define VM_PAGER_REFAULT	7
174 
175 /*
176  * XXX
177  * this is needed until the device strategy interface
178  * is changed to do physically-addressed i/o.
179  */
180 
181 #ifndef PAGER_MAP_SIZE
182 #define PAGER_MAP_SIZE       (16 * 1024 * 1024)
183 #endif
184 
185 #endif /* _KERNEL */
186 
187 #endif /* _UVM_UVM_PAGER_H_ */
188