xref: /openbsd-src/sys/uvm/uvm_pager.h (revision d6b79e511bc936dc4cfc4406b11100861ddd6e7c)
1*d6b79e51Smpi /*	$OpenBSD: uvm_pager.h,v 1.33 2021/10/12 07:38:22 mpi Exp $	*/
21414b0faSart /*	$NetBSD: uvm_pager.h,v 1.20 2000/11/27 08:40:05 chs Exp $	*/
3cd7ee8acSart 
4cd7ee8acSart /*
5cd7ee8acSart  * Copyright (c) 1997 Charles D. Cranor and Washington University.
6cd7ee8acSart  * All rights reserved.
7cd7ee8acSart  *
8cd7ee8acSart  * Redistribution and use in source and binary forms, with or without
9cd7ee8acSart  * modification, are permitted provided that the following conditions
10cd7ee8acSart  * are met:
11cd7ee8acSart  * 1. Redistributions of source code must retain the above copyright
12cd7ee8acSart  *    notice, this list of conditions and the following disclaimer.
13cd7ee8acSart  * 2. Redistributions in binary form must reproduce the above copyright
14cd7ee8acSart  *    notice, this list of conditions and the following disclaimer in the
15cd7ee8acSart  *    documentation and/or other materials provided with the distribution.
16cd7ee8acSart  *
17cd7ee8acSart  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18cd7ee8acSart  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19cd7ee8acSart  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20cd7ee8acSart  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21cd7ee8acSart  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22cd7ee8acSart  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23cd7ee8acSart  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24cd7ee8acSart  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25cd7ee8acSart  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26cd7ee8acSart  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27cd7ee8acSart  *
28cd7ee8acSart  * from: Id: uvm_pager.h,v 1.1.2.14 1998/01/13 19:00:50 chuck Exp
29cd7ee8acSart  */
30cd7ee8acSart 
316dc095b3Sart /*
326dc095b3Sart  * Copyright (c) 1990 University of Utah.
336dc095b3Sart  * Copyright (c) 1991, 1993
346dc095b3Sart  *	The Regents of the University of California.  All rights reserved.
356dc095b3Sart  *
366dc095b3Sart  * This code is derived from software contributed to Berkeley by
376dc095b3Sart  * the Systems Programming Group of the University of Utah Computer
386dc095b3Sart  * Science Department.
396dc095b3Sart  *
406dc095b3Sart  * Redistribution and use in source and binary forms, with or without
416dc095b3Sart  * modification, are permitted provided that the following conditions
426dc095b3Sart  * are met:
436dc095b3Sart  * 1. Redistributions of source code must retain the above copyright
446dc095b3Sart  *    notice, this list of conditions and the following disclaimer.
456dc095b3Sart  * 2. Redistributions in binary form must reproduce the above copyright
466dc095b3Sart  *    notice, this list of conditions and the following disclaimer in the
476dc095b3Sart  *    documentation and/or other materials provided with the distribution.
4829295d1cSmillert  * 3. Neither the name of the University nor the names of its contributors
496dc095b3Sart  *    may be used to endorse or promote products derived from this software
506dc095b3Sart  *    without specific prior written permission.
516dc095b3Sart  *
526dc095b3Sart  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
536dc095b3Sart  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
546dc095b3Sart  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
556dc095b3Sart  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
566dc095b3Sart  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
576dc095b3Sart  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
586dc095b3Sart  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
596dc095b3Sart  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
606dc095b3Sart  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
616dc095b3Sart  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
626dc095b3Sart  * SUCH DAMAGE.
636dc095b3Sart  *
646dc095b3Sart  *	@(#)vm_pager.h	8.5 (Berkeley) 7/7/94
656dc095b3Sart  */
666dc095b3Sart 
67cd7ee8acSart #ifndef _UVM_UVM_PAGER_H_
68cd7ee8acSart #define _UVM_UVM_PAGER_H_
69cd7ee8acSart 
70bb0a6debSderaadt #ifdef _KERNEL
71cd7ee8acSart 
72cd7ee8acSart struct uvm_pagerops {
7300caae4bSmillert 						/* init pager */
7400caae4bSmillert 	void			(*pgo_init)(void);
7500caae4bSmillert 						/* add reference to obj */
7600caae4bSmillert 	void			(*pgo_reference)(struct uvm_object *);
7700caae4bSmillert 						/* drop reference to obj */
7800caae4bSmillert 	void			(*pgo_detach)(struct uvm_object *);
7900caae4bSmillert 						/* special nonstd fault fn */
8000caae4bSmillert 	int			(*pgo_fault)(struct uvm_faultinfo *, vaddr_t,
811414b0faSart 				 vm_page_t *, int, int, vm_fault_t,
82c4071fd1Smillert 				 vm_prot_t, int);
8300caae4bSmillert 						/* flush pages out of obj */
8400caae4bSmillert 	boolean_t		(*pgo_flush)(struct uvm_object *, voff_t,
8500caae4bSmillert 				 voff_t, int);
8600caae4bSmillert 						/* get/read page */
8700caae4bSmillert 	int			(*pgo_get)(struct uvm_object *, voff_t,
88c4071fd1Smillert 				 vm_page_t *, int *, int, vm_prot_t, int, int);
8900caae4bSmillert 						/* put/write page */
9000caae4bSmillert 	int			(*pgo_put)(struct uvm_object *, vm_page_t *,
91c4071fd1Smillert 				 int, boolean_t);
9200caae4bSmillert 						/* return range of cluster */
9300caae4bSmillert 	void			(*pgo_cluster)(struct uvm_object *, voff_t,
9400caae4bSmillert 				 voff_t *, voff_t *);
9500caae4bSmillert 						/* make "put" cluster */
9600caae4bSmillert 	struct vm_page **	(*pgo_mk_pcluster)(struct uvm_object *,
9700caae4bSmillert 				 struct vm_page **, int *, struct vm_page *,
9800caae4bSmillert 				 int, voff_t, voff_t);
99cd7ee8acSart };
100cd7ee8acSart 
101cd7ee8acSart /* pager flags [mostly for flush] */
102cd7ee8acSart 
103cd7ee8acSart #define PGO_CLEANIT	0x001	/* write dirty pages to backing store */
1041aa8821bSart #define PGO_SYNCIO	0x002	/* if PGO_CLEANIT: use sync I/O? */
105cd7ee8acSart #define PGO_DEACTIVATE	0x004	/* deactivate flushed pages */
106cd7ee8acSart #define PGO_FREE	0x008	/* free flushed pages */
1071aa8821bSart /* if PGO_FREE is not set then the pages stay where they are. */
108cd7ee8acSart 
109cd7ee8acSart #define PGO_ALLPAGES	0x010	/* flush whole object/get all pages */
110cd7ee8acSart #define PGO_DOACTCLUST	0x020	/* flag to mk_pcluster to include active */
111cd7ee8acSart #define PGO_LOCKED	0x040	/* fault data structures are locked [get] */
112cd7ee8acSart #define PGO_PDFREECLUST	0x080	/* daemon's free cluster flag [uvm_pager_put] */
113cd7ee8acSart #define PGO_REALLOCSWAP	0x100	/* reallocate swap area [pager_dropcluster] */
114*d6b79e51Smpi #define PGO_NOWAIT	0x200	/* do not wait for inode lock */
115cd7ee8acSart 
116cd7ee8acSart /* page we are not interested in getting */
1171aa8821bSart #define PGO_DONTCARE ((struct vm_page *) -1L)	/* [get only] */
118cd7ee8acSart 
119cd7ee8acSart /*
120cd7ee8acSart  * prototypes
121cd7ee8acSart  */
122cd7ee8acSart 
123ca5c6958Soga void		uvm_pager_dropcluster(struct uvm_object *, struct vm_page *,
124ca5c6958Soga 		    struct vm_page **, int *, int);
125c4071fd1Smillert void		uvm_pager_init(void);
126c4071fd1Smillert int		uvm_pager_put(struct uvm_object *, struct vm_page *,
127ca5c6958Soga 		    struct vm_page ***, int *, int, voff_t, voff_t);
128cd7ee8acSart 
129cd7ee8acSart 
130c4071fd1Smillert vaddr_t		uvm_pagermapin(struct vm_page **, int, int);
131c4071fd1Smillert void		uvm_pagermapout(vaddr_t, int);
132c4071fd1Smillert struct vm_page **uvm_mk_pcluster(struct uvm_object *, struct vm_page **,
133ca5c6958Soga 		    int *, struct vm_page *, int, voff_t, voff_t);
134ca5c6958Soga 
135b1990b04Sart /* Flags to uvm_pagermapin() */
136b1990b04Sart #define	UVMPAGER_MAPIN_WAITOK	0x01	/* it's okay to wait */
137b1990b04Sart #define	UVMPAGER_MAPIN_READ	0x02	/* host <- device */
138b1990b04Sart #define	UVMPAGER_MAPIN_WRITE	0x00	/* device -> host (pseudo flag) */
139cd7ee8acSart 
1406dc095b3Sart /*
1411414b0faSart  * get/put return values
1421414b0faSart  * OK	   operation was successful
1431414b0faSart  * BAD	   specified data was out of the accepted range
1441414b0faSart  * FAIL	   specified data was in range, but doesn't exist
1451414b0faSart  * PEND	   operations was initiated but not completed
1461414b0faSart  * ERROR   error while accessing data that is in range and exists
1471414b0faSart  * AGAIN   temporary resource shortage prevented operation from happening
1481414b0faSart  * UNLOCK  unlock the map and try again
1491414b0faSart  * REFAULT [uvm_fault internal use only!] unable to relock data structures,
1504af3577fSjsg  *         thus the mapping needs to be reverified before we can proceed
1511414b0faSart  */
1521414b0faSart #define	VM_PAGER_OK		0
1531414b0faSart #define	VM_PAGER_BAD		1
1541414b0faSart #define	VM_PAGER_FAIL		2
1551414b0faSart #define	VM_PAGER_PEND		3
1561414b0faSart #define	VM_PAGER_ERROR		4
1571414b0faSart #define VM_PAGER_AGAIN		5
1581414b0faSart #define VM_PAGER_UNLOCK		6
1591414b0faSart #define VM_PAGER_REFAULT	7
1601414b0faSart 
1611414b0faSart /*
162fd628a11Sart  * XXX
163fd628a11Sart  * this is needed until the device strategy interface
164fd628a11Sart  * is changed to do physically-addressed i/o.
165fd628a11Sart  */
166fd628a11Sart 
1671aa8821bSart #ifndef PAGER_MAP_SIZE
168fd628a11Sart #define PAGER_MAP_SIZE       (16 * 1024 * 1024)
1691aa8821bSart #endif
170fd628a11Sart 
171ab87c361Ssmart #endif /* _KERNEL */
172cd7ee8acSart 
173cd7ee8acSart #endif /* _UVM_UVM_PAGER_H_ */
174