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