xref: /freebsd/sys/vm/vm_pager.h (revision 05f0fdd26aa1789c04ae89358880922a54d197c3)
126f9a767SRodney W. Grimes 
2df8bae1dSRodney W. Grimes /*
3df8bae1dSRodney W. Grimes  * Copyright (c) 1990 University of Utah.
4df8bae1dSRodney W. Grimes  * Copyright (c) 1991, 1993
5df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
6df8bae1dSRodney W. Grimes  *
7df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
8df8bae1dSRodney W. Grimes  * the Systems Programming Group of the University of Utah Computer
9df8bae1dSRodney W. Grimes  * Science Department.
10df8bae1dSRodney W. Grimes  *
11df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
12df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
13df8bae1dSRodney W. Grimes  * are met:
14df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
15df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
16df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
17df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
18df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
19df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
20df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
21df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
22df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
23df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
24df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
25df8bae1dSRodney W. Grimes  *    without specific prior written permission.
26df8bae1dSRodney W. Grimes  *
27df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
38df8bae1dSRodney W. Grimes  *
39df8bae1dSRodney W. Grimes  *	@(#)vm_pager.h	8.4 (Berkeley) 1/12/94
4005f0fdd2SPoul-Henning Kamp  * $Id: vm_pager.h,v 1.3 1994/08/02 07:55:36 davidg Exp $
41df8bae1dSRodney W. Grimes  */
42df8bae1dSRodney W. Grimes 
43df8bae1dSRodney W. Grimes /*
44df8bae1dSRodney W. Grimes  * Pager routine interface definition.
45df8bae1dSRodney W. Grimes  * For BSD we use a cleaner version of the internal pager interface.
46df8bae1dSRodney W. Grimes  */
47df8bae1dSRodney W. Grimes 
48df8bae1dSRodney W. Grimes #ifndef	_VM_PAGER_
49df8bae1dSRodney W. Grimes #define	_VM_PAGER_
50df8bae1dSRodney W. Grimes 
51df8bae1dSRodney W. Grimes TAILQ_HEAD(pagerlst, pager_struct);
52df8bae1dSRodney W. Grimes 
53df8bae1dSRodney W. Grimes struct	pager_struct {
54df8bae1dSRodney W. Grimes 	TAILQ_ENTRY(pager_struct) pg_list;	/* links for list management */
55df8bae1dSRodney W. Grimes 	caddr_t			  pg_handle;	/* ext. handle (vp, dev, fp) */
56df8bae1dSRodney W. Grimes 	int			  pg_type;	/* type of pager */
57df8bae1dSRodney W. Grimes 	int			  pg_flags;	/* flags */
58df8bae1dSRodney W. Grimes 	struct pagerops		  *pg_ops;	/* pager operations */
59df8bae1dSRodney W. Grimes 	void			  *pg_data;	/* private pager data */
60df8bae1dSRodney W. Grimes };
61df8bae1dSRodney W. Grimes 
62df8bae1dSRodney W. Grimes /* pager types */
63df8bae1dSRodney W. Grimes #define PG_DFLT		-1
64df8bae1dSRodney W. Grimes #define	PG_SWAP		0
65df8bae1dSRodney W. Grimes #define	PG_VNODE	1
66df8bae1dSRodney W. Grimes #define PG_DEVICE	2
67df8bae1dSRodney W. Grimes 
68df8bae1dSRodney W. Grimes /* flags */
69df8bae1dSRodney W. Grimes #define PG_CLUSTERGET	1
70df8bae1dSRodney W. Grimes #define PG_CLUSTERPUT	2
71df8bae1dSRodney W. Grimes 
72df8bae1dSRodney W. Grimes struct	pagerops {
73df8bae1dSRodney W. Grimes 	void		(*pgo_init)		/* Initialize pager. */
74df8bae1dSRodney W. Grimes 			    __P((void));
75df8bae1dSRodney W. Grimes 	vm_pager_t	(*pgo_alloc)		/* Allocate pager. */
76df8bae1dSRodney W. Grimes 			    __P((caddr_t, vm_size_t, vm_prot_t, vm_offset_t));
77df8bae1dSRodney W. Grimes 	void		(*pgo_dealloc)		/* Disassociate. */
78df8bae1dSRodney W. Grimes 			    __P((vm_pager_t));
7926f9a767SRodney W. Grimes 	int		(*pgo_getpage)
8026f9a767SRodney W. Grimes 			    __P((vm_pager_t, vm_page_t, boolean_t));
81df8bae1dSRodney W. Grimes 	int		(*pgo_getpages)		/* Get (read) page. */
8226f9a767SRodney W. Grimes 			    __P((vm_pager_t, vm_page_t *, int, int, boolean_t));
8326f9a767SRodney W. Grimes 	int		(*pgo_putpage)
8426f9a767SRodney W. Grimes 			    __P((vm_pager_t, vm_page_t, boolean_t));
85df8bae1dSRodney W. Grimes 	int		(*pgo_putpages)		/* Put (write) page. */
8626f9a767SRodney W. Grimes 			    __P((vm_pager_t, vm_page_t *, int, boolean_t, int *));
87df8bae1dSRodney W. Grimes 	boolean_t  	(*pgo_haspage)		/* Does pager have page? */
88df8bae1dSRodney W. Grimes 			    __P((vm_pager_t, vm_offset_t));
89df8bae1dSRodney W. Grimes };
90df8bae1dSRodney W. Grimes 
9126f9a767SRodney W. Grimes #define	VM_PAGER_ALLOC(h, s, p, o)		(*(pg)->pg_ops->pgo_alloc)(h, s, p, o)
9226f9a767SRodney W. Grimes #define	VM_PAGER_DEALLOC(pg)		(*(pg)->pg_ops->pgo_dealloc)(pg)
9326f9a767SRodney W. Grimes #define	VM_PAGER_GET(pg, m, s)		(*(pg)->pg_ops->pgo_getpage)(pg, m, s)
9426f9a767SRodney W. Grimes #define	VM_PAGER_GET_MULTI(pg, m, c, r, s)	(*(pg)->pg_ops->pgo_getpages)(pg, m, c, r, s)
9526f9a767SRodney W. Grimes #define	VM_PAGER_PUT(pg, m, s)		(*(pg)->pg_ops->pgo_putpage)(pg, m, s)
9626f9a767SRodney W. Grimes #define	VM_PAGER_PUT_MULTI(pg, m, c, s, rtval)		(*(pg)->pg_ops->pgo_putpages)(pg, m, c, s, rtval)
9726f9a767SRodney W. Grimes #define	VM_PAGER_HASPAGE(pg, o)		(*(pg)->pg_ops->pgo_haspage)(pg, o)
9826f9a767SRodney W. Grimes 
99df8bae1dSRodney W. Grimes /*
100df8bae1dSRodney W. Grimes  * get/put return values
101df8bae1dSRodney W. Grimes  * OK	 operation was successful
102df8bae1dSRodney W. Grimes  * BAD	 specified data was out of the accepted range
103df8bae1dSRodney W. Grimes  * FAIL	 specified data was in range, but doesn't exist
104df8bae1dSRodney W. Grimes  * PEND	 operations was initiated but not completed
105df8bae1dSRodney W. Grimes  * ERROR error while accessing data that is in range and exists
106df8bae1dSRodney W. Grimes  * AGAIN temporary resource shortage prevented operation from happening
107df8bae1dSRodney W. Grimes  */
108df8bae1dSRodney W. Grimes #define	VM_PAGER_OK	0
109df8bae1dSRodney W. Grimes #define	VM_PAGER_BAD	1
110df8bae1dSRodney W. Grimes #define	VM_PAGER_FAIL	2
111df8bae1dSRodney W. Grimes #define	VM_PAGER_PEND	3
112df8bae1dSRodney W. Grimes #define	VM_PAGER_ERROR	4
113df8bae1dSRodney W. Grimes #define VM_PAGER_AGAIN	5
114df8bae1dSRodney W. Grimes 
115df8bae1dSRodney W. Grimes #ifdef KERNEL
116df8bae1dSRodney W. Grimes extern struct pagerops *dfltpagerops;
117df8bae1dSRodney W. Grimes 
118df8bae1dSRodney W. Grimes vm_pager_t	 vm_pager_allocate
119df8bae1dSRodney W. Grimes 		    __P((int, caddr_t, vm_size_t, vm_prot_t, vm_offset_t));
120df8bae1dSRodney W. Grimes vm_page_t	 vm_pager_atop __P((vm_offset_t));
121df8bae1dSRodney W. Grimes void		 vm_pager_deallocate __P((vm_pager_t));
122df8bae1dSRodney W. Grimes int		 vm_pager_get_pages
12326f9a767SRodney W. Grimes 		    __P((vm_pager_t, vm_page_t *, int, int, boolean_t));
124df8bae1dSRodney W. Grimes boolean_t	 vm_pager_has_page __P((vm_pager_t, vm_offset_t));
125df8bae1dSRodney W. Grimes void		 vm_pager_init __P((void));
126df8bae1dSRodney W. Grimes vm_pager_t	 vm_pager_lookup __P((struct pagerlst *, caddr_t));
127df8bae1dSRodney W. Grimes vm_offset_t	 vm_pager_map_pages __P((vm_page_t *, int, boolean_t));
12805f0fdd2SPoul-Henning Kamp vm_offset_t	 vm_pager_map_page __P((vm_page_t));
129df8bae1dSRodney W. Grimes int		 vm_pager_put_pages
13026f9a767SRodney W. Grimes 		    __P((vm_pager_t, vm_page_t *, int, boolean_t, int *));
131df8bae1dSRodney W. Grimes void		 vm_pager_sync __P((void));
132df8bae1dSRodney W. Grimes void		 vm_pager_unmap_pages __P((vm_offset_t, int));
13305f0fdd2SPoul-Henning Kamp void		 vm_pager_unmap_page __P((vm_offset_t));
134df8bae1dSRodney W. Grimes 
135df8bae1dSRodney W. Grimes #define vm_pager_cancluster(p, b)	((p)->pg_flags & (b))
136df8bae1dSRodney W. Grimes 
137df8bae1dSRodney W. Grimes /*
138df8bae1dSRodney W. Grimes  * XXX compat with old interface
139df8bae1dSRodney W. Grimes  */
140df8bae1dSRodney W. Grimes #define vm_pager_get(p, m, s) \
141df8bae1dSRodney W. Grimes ({ \
142df8bae1dSRodney W. Grimes 	vm_page_t ml[1]; \
143df8bae1dSRodney W. Grimes 	ml[0] = (m); \
14426f9a767SRodney W. Grimes 	vm_pager_get_pages(p, ml, 1, 0, s); \
145df8bae1dSRodney W. Grimes })
14626f9a767SRodney W. Grimes 
147df8bae1dSRodney W. Grimes #define vm_pager_put(p, m, s) \
148df8bae1dSRodney W. Grimes ({ \
14926f9a767SRodney W. Grimes 	int rtval; \
150df8bae1dSRodney W. Grimes 	vm_page_t ml[1]; \
151df8bae1dSRodney W. Grimes 	ml[0] = (m); \
15226f9a767SRodney W. Grimes 	vm_pager_put_pages(p, ml, 1, s, &rtval); \
15326f9a767SRodney W. Grimes 	rtval; \
154df8bae1dSRodney W. Grimes })
155df8bae1dSRodney W. Grimes #endif
156df8bae1dSRodney W. Grimes 
157df8bae1dSRodney W. Grimes #endif	/* _VM_PAGER_ */
158