vm_pager.h revision 43129
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1990 University of Utah.
31541Srgrimes * Copyright (c) 1991, 1993
41541Srgrimes *	The Regents of the University of California.  All rights reserved.
51541Srgrimes *
61541Srgrimes * This code is derived from software contributed to Berkeley by
71541Srgrimes * the Systems Programming Group of the University of Utah Computer
81541Srgrimes * Science Department.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
381541Srgrimes *	@(#)vm_pager.h	8.4 (Berkeley) 1/12/94
3943129Sdillon * $Id: vm_pager.h,v 1.19 1999/01/21 10:15:47 dillon Exp $
401541Srgrimes */
411541Srgrimes
421541Srgrimes/*
431541Srgrimes * Pager routine interface definition.
441541Srgrimes */
451541Srgrimes
461541Srgrimes#ifndef	_VM_PAGER_
471541Srgrimes#define	_VM_PAGER_
481541Srgrimes
4933058Sbde#include <sys/queue.h>
5033058Sbde
519507SdgTAILQ_HEAD(pagerlst, vm_object);
521541Srgrimes
535455Sdgstruct pagerops {
545455Sdg	void (*pgo_init) __P((void));		/* Initialize pager. */
5540286Sdg	vm_object_t (*pgo_alloc) __P((void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t));	/* Allocate pager. */
569507Sdg	void (*pgo_dealloc) __P((vm_object_t));	/* Disassociate. */
579507Sdg	int (*pgo_getpages) __P((vm_object_t, vm_page_t *, int, int));	/* Get (read) page. */
5843129Sdillon	void (*pgo_putpages) __P((vm_object_t, vm_page_t *, int, int, int *)); /* Put (write) page. */
5912767Sdyson	boolean_t (*pgo_haspage) __P((vm_object_t, vm_pindex_t, int *, int *)); /* Does pager have page? */
6042957Sdillon	void (*pgo_pageunswapped) __P((vm_page_t));
611541Srgrimes};
621541Srgrimes
631541Srgrimes/*
641541Srgrimes * get/put return values
651541Srgrimes * OK	 operation was successful
661541Srgrimes * BAD	 specified data was out of the accepted range
671541Srgrimes * FAIL	 specified data was in range, but doesn't exist
681541Srgrimes * PEND	 operations was initiated but not completed
691541Srgrimes * ERROR error while accessing data that is in range and exists
701541Srgrimes * AGAIN temporary resource shortage prevented operation from happening
711541Srgrimes */
721541Srgrimes#define	VM_PAGER_OK	0
731541Srgrimes#define	VM_PAGER_BAD	1
741541Srgrimes#define	VM_PAGER_FAIL	2
751541Srgrimes#define	VM_PAGER_PEND	3
761541Srgrimes#define	VM_PAGER_ERROR	4
771541Srgrimes#define VM_PAGER_AGAIN	5
781541Srgrimes
7934206Sdyson#define	VM_PAGER_PUT_SYNC	0x1
8034206Sdyson#define	VM_PAGER_PUT_INVAL	0x2
8134206Sdyson
821541Srgrimes#ifdef KERNEL
8330354Sphk
8430354Sphk#ifdef MALLOC_DECLARE
8530354SphkMALLOC_DECLARE(M_VMPGDATA);
8630354Sphk#endif
8730354Sphk
889759Sbdeextern vm_map_t pager_map;
899759Sbdeextern int pager_map_size;
9042957Sdillonextern struct pagerops *pagertab[];
919759Sbde
9240286Sdgvm_object_t vm_pager_allocate __P((objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t));
937090Sbdevoid vm_pager_bufferinit __P((void));
949507Sdgvoid vm_pager_deallocate __P((vm_object_t));
9542957Sdillonstatic __inline int vm_pager_get_pages __P((vm_object_t, vm_page_t *, int, int));
9642957Sdillonstatic __inline boolean_t vm_pager_has_page __P((vm_object_t, vm_pindex_t, int *, int *));
975455Sdgvoid vm_pager_init __P((void));
989507Sdgvm_object_t vm_pager_object_lookup __P((struct pagerlst *, void *));
995455Sdgvm_offset_t vm_pager_map_pages __P((vm_page_t *, int, boolean_t));
1005455Sdgvm_offset_t vm_pager_map_page __P((vm_page_t));
1015455Sdgvoid vm_pager_sync __P((void));
1025455Sdgvoid vm_pager_unmap_pages __P((vm_offset_t, int));
1035455Sdgvoid vm_pager_unmap_page __P((vm_offset_t));
10442957Sdillon
10542957Sdillonstatic __inline int
10642957Sdillonvm_pager_get_pages(
10742957Sdillon	vm_object_t object,
10842957Sdillon	vm_page_t *m,
10942957Sdillon	int count,
11042957Sdillon	int reqpage
11142957Sdillon) {
11242957Sdillon	return ((*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage));
11342957Sdillon}
11442957Sdillon
11543129Sdillonstatic __inline void
11642957Sdillonvm_pager_put_pages(
11742957Sdillon	vm_object_t object,
11842957Sdillon	vm_page_t *m,
11942957Sdillon	int count,
12042957Sdillon	int flags,
12142957Sdillon	int *rtvals
12242957Sdillon) {
12343129Sdillon	(*pagertab[object->type]->pgo_putpages)
12443129Sdillon	    (object, m, count, flags, rtvals);
12542957Sdillon}
12642957Sdillon
12742957Sdillonstatic __inline boolean_t
12842957Sdillonvm_pager_has_page(
12942957Sdillon	vm_object_t object,
13042957Sdillon	vm_pindex_t offset,
13142957Sdillon	int *before,
13242957Sdillon	int *after
13342957Sdillon) {
13442957Sdillon        return ((*pagertab[object->type]->pgo_haspage) (object, offset, before, after));
13542957Sdillon}
13642957Sdillon
13742957Sdillon/*
13842957Sdillon *      vm_pager_page_unswapped
13942957Sdillon *
14042957Sdillon *      called at splvm() to destroy swap associated with the page.
14142957Sdillon *
14242957Sdillon *      This function may not block.
14342957Sdillon */
14442957Sdillon
14542957Sdillonstatic __inline void
14642957Sdillonvm_pager_page_unswapped(vm_page_t m)
14742957Sdillon{
14842957Sdillon	if (pagertab[m->object->type]->pgo_pageunswapped)
14942957Sdillon		(*pagertab[m->object->type]->pgo_pageunswapped)(m);
15042957Sdillon}
15142957Sdillon
15242957Sdillon
1531541Srgrimes#endif
1541541Srgrimes
1555455Sdg#endif				/* _VM_PAGER_ */
156