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