xref: /freebsd/sys/vm/device_pager.c (revision 3153e878dd4c552fb5c680742041a98dc3deb9ea)
160727d8bSWarner Losh /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 1990 University of Utah.
3df8bae1dSRodney W. Grimes  * Copyright (c) 1991, 1993
4df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
5df8bae1dSRodney W. Grimes  *
6df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
7df8bae1dSRodney W. Grimes  * the Systems Programming Group of the University of Utah Computer
8df8bae1dSRodney W. Grimes  * Science Department.
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
19df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
20df8bae1dSRodney W. Grimes  *    without specific prior written permission.
21df8bae1dSRodney W. Grimes  *
22df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
33df8bae1dSRodney W. Grimes  *
3426f9a767SRodney W. Grimes  *	@(#)device_pager.c	8.1 (Berkeley) 6/11/93
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37874651b1SDavid E. O'Brien #include <sys/cdefs.h>
38874651b1SDavid E. O'Brien __FBSDID("$FreeBSD$");
39874651b1SDavid E. O'Brien 
40df8bae1dSRodney W. Grimes #include <sys/param.h>
41df8bae1dSRodney W. Grimes #include <sys/systm.h>
42df8bae1dSRodney W. Grimes #include <sys/conf.h>
43fb919e4dSMark Murray #include <sys/lock.h>
440cddd8f0SMatthew Dillon #include <sys/proc.h>
45fb919e4dSMark Murray #include <sys/mutex.h>
46df8bae1dSRodney W. Grimes #include <sys/mman.h>
47a9fa2c05SAlfred Perlstein #include <sys/sx.h>
48df8bae1dSRodney W. Grimes 
49df8bae1dSRodney W. Grimes #include <vm/vm.h>
50efeaf95aSDavid Greenman #include <vm/vm_object.h>
51df8bae1dSRodney W. Grimes #include <vm/vm_page.h>
5224a1cce3SDavid Greenman #include <vm/vm_pager.h>
53670d17b5SJeff Roberson #include <vm/uma.h>
54df8bae1dSRodney W. Grimes 
5511caded3SAlfred Perlstein static void dev_pager_init(void);
5611caded3SAlfred Perlstein static vm_object_t dev_pager_alloc(void *, vm_ooffset_t, vm_prot_t,
573364c323SKonstantin Belousov     vm_ooffset_t, struct ucred *);
5811caded3SAlfred Perlstein static void dev_pager_dealloc(vm_object_t);
5911caded3SAlfred Perlstein static int dev_pager_getpages(vm_object_t, vm_page_t *, int, int);
6011caded3SAlfred Perlstein static void dev_pager_putpages(vm_object_t, vm_page_t *, int,
6111caded3SAlfred Perlstein 		boolean_t, int *);
6211caded3SAlfred Perlstein static boolean_t dev_pager_haspage(vm_object_t, vm_pindex_t, int *,
6311caded3SAlfred Perlstein 		int *);
64f708ef1bSPoul-Henning Kamp 
65f708ef1bSPoul-Henning Kamp /* list of device pager objects */
66f708ef1bSPoul-Henning Kamp static struct pagerlst dev_pager_object_list;
67a9fa2c05SAlfred Perlstein /* protect list manipulation */
68a9fa2c05SAlfred Perlstein static struct mtx dev_pager_mtx;
69a9fa2c05SAlfred Perlstein 
70f708ef1bSPoul-Henning Kamp 
71670d17b5SJeff Roberson static uma_zone_t fakepg_zone;
72df8bae1dSRodney W. Grimes 
733153e878SAlan Cox static vm_page_t dev_pager_getfake(vm_paddr_t, vm_memattr_t);
7411caded3SAlfred Perlstein static void dev_pager_putfake(vm_page_t);
753153e878SAlan Cox static void dev_pager_updatefake(vm_page_t, vm_paddr_t, vm_memattr_t);
76df8bae1dSRodney W. Grimes 
77df8bae1dSRodney W. Grimes struct pagerops devicepagerops = {
784e658600SPoul-Henning Kamp 	.pgo_init =	dev_pager_init,
794e658600SPoul-Henning Kamp 	.pgo_alloc =	dev_pager_alloc,
804e658600SPoul-Henning Kamp 	.pgo_dealloc =	dev_pager_dealloc,
814e658600SPoul-Henning Kamp 	.pgo_getpages =	dev_pager_getpages,
824e658600SPoul-Henning Kamp 	.pgo_putpages =	dev_pager_putpages,
834e658600SPoul-Henning Kamp 	.pgo_haspage =	dev_pager_haspage,
84df8bae1dSRodney W. Grimes };
85df8bae1dSRodney W. Grimes 
86f708ef1bSPoul-Henning Kamp static void
87df8bae1dSRodney W. Grimes dev_pager_init()
88df8bae1dSRodney W. Grimes {
8924a1cce3SDavid Greenman 	TAILQ_INIT(&dev_pager_object_list);
906008862bSJohn Baldwin 	mtx_init(&dev_pager_mtx, "dev_pager list", NULL, MTX_DEF);
91670d17b5SJeff Roberson 	fakepg_zone = uma_zcreate("DP fakepg", sizeof(struct vm_page),
92f3c625e4SJeff Roberson 	    NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,
93f3c625e4SJeff Roberson 	    UMA_ZONE_NOFREE|UMA_ZONE_VM);
94df8bae1dSRodney W. Grimes }
95df8bae1dSRodney W. Grimes 
96c8664f82SAlan Cox /*
97c8664f82SAlan Cox  * MPSAFE
98c8664f82SAlan Cox  */
99f708ef1bSPoul-Henning Kamp static vm_object_t
1003364c323SKonstantin Belousov dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
1013364c323SKonstantin Belousov     vm_ooffset_t foff, struct ucred *cred)
102df8bae1dSRodney W. Grimes {
10389c9c53dSPoul-Henning Kamp 	struct cdev *dev;
104deea654eSKonstantin Belousov 	vm_object_t object, object1;
1052f7af3dbSAlan Cox 	vm_pindex_t pindex;
1067095ee91SDoug Rabson 	unsigned int npages;
107227f9a1cSJake Burkholder 	vm_paddr_t paddr;
108227f9a1cSJake Burkholder 	vm_offset_t off;
109751fdd08SPoul-Henning Kamp 	struct cdevsw *csw;
110df8bae1dSRodney W. Grimes 
111df8bae1dSRodney W. Grimes 	/*
112df8bae1dSRodney W. Grimes 	 * Offset should be page aligned.
113df8bae1dSRodney W. Grimes 	 */
114aa8de40aSPoul-Henning Kamp 	if (foff & PAGE_MASK)
115df8bae1dSRodney W. Grimes 		return (NULL);
116df8bae1dSRodney W. Grimes 
1176cde7a16SDavid Greenman 	size = round_page(size);
1182f7af3dbSAlan Cox 	pindex = OFF_TO_IDX(foff + size);
1196cde7a16SDavid Greenman 
120df8bae1dSRodney W. Grimes 	/*
121c8664f82SAlan Cox 	 * Make sure this device can be mapped.
122c8664f82SAlan Cox 	 */
123c8664f82SAlan Cox 	dev = handle;
124751fdd08SPoul-Henning Kamp 	csw = dev_refthread(dev);
125751fdd08SPoul-Henning Kamp 	if (csw == NULL)
126c8664f82SAlan Cox 		return (NULL);
127c8664f82SAlan Cox 
128c8664f82SAlan Cox 	/*
1290d94caffSDavid Greenman 	 * Check that the specified range of the device allows the desired
1300d94caffSDavid Greenman 	 * protection.
131df8bae1dSRodney W. Grimes 	 *
132df8bae1dSRodney W. Grimes 	 * XXX assumes VM_PROT_* == PROT_*
133df8bae1dSRodney W. Grimes 	 */
1346cde7a16SDavid Greenman 	npages = OFF_TO_IDX(size);
135df8bae1dSRodney W. Grimes 	for (off = foff; npages--; off += PAGE_SIZE)
136751fdd08SPoul-Henning Kamp 		if ((*csw->d_mmap)(dev, off, &paddr, (int)prot) != 0) {
137751fdd08SPoul-Henning Kamp 			dev_relthread(dev);
138df8bae1dSRodney W. Grimes 			return (NULL);
139c8664f82SAlan Cox 		}
140df8bae1dSRodney W. Grimes 
141deea654eSKonstantin Belousov 	mtx_lock(&dev_pager_mtx);
14224a1cce3SDavid Greenman 
14324a1cce3SDavid Greenman 	/*
144df8bae1dSRodney W. Grimes 	 * Look up pager, creating as necessary.
145df8bae1dSRodney W. Grimes 	 */
146deea654eSKonstantin Belousov 	object1 = NULL;
14724a1cce3SDavid Greenman 	object = vm_pager_object_lookup(&dev_pager_object_list, handle);
14824a1cce3SDavid Greenman 	if (object == NULL) {
149df8bae1dSRodney W. Grimes 		/*
150e46cd413SAlan Cox 		 * Allocate object and associate it with the pager.  Initialize
151e46cd413SAlan Cox 		 * the object's pg_color based upon the physical address of the
152e46cd413SAlan Cox 		 * device's memory.
153df8bae1dSRodney W. Grimes 		 */
154deea654eSKonstantin Belousov 		mtx_unlock(&dev_pager_mtx);
155deea654eSKonstantin Belousov 		object1 = vm_object_allocate(OBJT_DEVICE, pindex);
156e46cd413SAlan Cox 		object1->flags |= OBJ_COLORED;
157e46cd413SAlan Cox 		object1->pg_color = atop(paddr) - OFF_TO_IDX(off - PAGE_SIZE);
158deea654eSKonstantin Belousov 		mtx_lock(&dev_pager_mtx);
159deea654eSKonstantin Belousov 		object = vm_pager_object_lookup(&dev_pager_object_list, handle);
160deea654eSKonstantin Belousov 		if (object != NULL) {
161deea654eSKonstantin Belousov 			/*
162deea654eSKonstantin Belousov 			 * We raced with other thread while allocating object.
163deea654eSKonstantin Belousov 			 */
164deea654eSKonstantin Belousov 			if (pindex > object->size)
165deea654eSKonstantin Belousov 				object->size = pindex;
166deea654eSKonstantin Belousov 		} else {
167deea654eSKonstantin Belousov 			object = object1;
168deea654eSKonstantin Belousov 			object1 = NULL;
16924a1cce3SDavid Greenman 			object->handle = handle;
17024a1cce3SDavid Greenman 			TAILQ_INIT(&object->un_pager.devp.devp_pglist);
171deea654eSKonstantin Belousov 			TAILQ_INSERT_TAIL(&dev_pager_object_list, object,
172deea654eSKonstantin Belousov 			    pager_object_list);
173deea654eSKonstantin Belousov 		}
174df8bae1dSRodney W. Grimes 	} else {
1752f7af3dbSAlan Cox 		if (pindex > object->size)
1762f7af3dbSAlan Cox 			object->size = pindex;
177df8bae1dSRodney W. Grimes 	}
178deea654eSKonstantin Belousov 	mtx_unlock(&dev_pager_mtx);
179751fdd08SPoul-Henning Kamp 	dev_relthread(dev);
180deea654eSKonstantin Belousov 	vm_object_deallocate(object1);
18124a1cce3SDavid Greenman 	return (object);
18224a1cce3SDavid Greenman }
18324a1cce3SDavid Greenman 
184f708ef1bSPoul-Henning Kamp static void
18524a1cce3SDavid Greenman dev_pager_dealloc(object)
186df8bae1dSRodney W. Grimes 	vm_object_t object;
18724a1cce3SDavid Greenman {
188df8bae1dSRodney W. Grimes 	vm_page_t m;
189df8bae1dSRodney W. Grimes 
190deea654eSKonstantin Belousov 	VM_OBJECT_UNLOCK(object);
191a9fa2c05SAlfred Perlstein 	mtx_lock(&dev_pager_mtx);
19224a1cce3SDavid Greenman 	TAILQ_REMOVE(&dev_pager_object_list, object, pager_object_list);
193a9fa2c05SAlfred Perlstein 	mtx_unlock(&dev_pager_mtx);
194deea654eSKonstantin Belousov 	VM_OBJECT_LOCK(object);
195df8bae1dSRodney W. Grimes 	/*
196df8bae1dSRodney W. Grimes 	 * Free up our fake pages.
197df8bae1dSRodney W. Grimes 	 */
198ce1b857fSAlan Cox 	while ((m = TAILQ_FIRST(&object->un_pager.devp.devp_pglist)) != NULL) {
19924a1cce3SDavid Greenman 		TAILQ_REMOVE(&object->un_pager.devp.devp_pglist, m, pageq);
200df8bae1dSRodney W. Grimes 		dev_pager_putfake(m);
201df8bae1dSRodney W. Grimes 	}
202df8bae1dSRodney W. Grimes }
203df8bae1dSRodney W. Grimes 
204f708ef1bSPoul-Henning Kamp static int
20524a1cce3SDavid Greenman dev_pager_getpages(object, m, count, reqpage)
20624a1cce3SDavid Greenman 	vm_object_t object;
20724a1cce3SDavid Greenman 	vm_page_t *m;
20824a1cce3SDavid Greenman 	int count;
20924a1cce3SDavid Greenman 	int reqpage;
210df8bae1dSRodney W. Grimes {
2116395da54SIan Dowse 	vm_pindex_t offset;
212227f9a1cSJake Burkholder 	vm_paddr_t paddr;
2133153e878SAlan Cox 	vm_page_t m_paddr, page;
2143153e878SAlan Cox 	vm_memattr_t memattr;
21589c9c53dSPoul-Henning Kamp 	struct cdev *dev;
21607159f9cSMaxime Henrion 	int i, ret;
217cac597e4SBruce Evans 	int prot;
218751fdd08SPoul-Henning Kamp 	struct cdevsw *csw;
2197818e0a5SKonstantin Belousov 	struct thread *td;
2207818e0a5SKonstantin Belousov 	struct file *fpop;
221df8bae1dSRodney W. Grimes 
222a8ab4870SAlan Cox 	VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
223ebb4a317SBruce Evans 	dev = object->handle;
224ce1b857fSAlan Cox 	page = m[reqpage];
225ce1b857fSAlan Cox 	offset = page->pindex;
2263153e878SAlan Cox 	memattr = object->memattr;
2278630c117SAlan Cox 	VM_OBJECT_UNLOCK(object);
228751fdd08SPoul-Henning Kamp 	csw = dev_refthread(dev);
229751fdd08SPoul-Henning Kamp 	if (csw == NULL)
230751fdd08SPoul-Henning Kamp 		panic("dev_pager_getpage: no cdevsw");
231df8bae1dSRodney W. Grimes 	prot = PROT_READ;	/* XXX should pass in? */
23226f9a767SRodney W. Grimes 
2337818e0a5SKonstantin Belousov 	td = curthread;
2347818e0a5SKonstantin Belousov 	fpop = td->td_fpop;
2357818e0a5SKonstantin Belousov 	td->td_fpop = NULL;
236751fdd08SPoul-Henning Kamp 	ret = (*csw->d_mmap)(dev, (vm_offset_t)offset << PAGE_SHIFT, &paddr, prot);
23707159f9cSMaxime Henrion 	KASSERT(ret == 0, ("dev_pager_getpage: map function returns error"));
2387818e0a5SKonstantin Belousov 	td->td_fpop = fpop;
239751fdd08SPoul-Henning Kamp 	dev_relthread(dev);
2403153e878SAlan Cox 	/* If "paddr" is a real page, perform a sanity check on "memattr". */
2413153e878SAlan Cox 	if ((m_paddr = vm_phys_paddr_to_vm_page(paddr)) != NULL &&
2423153e878SAlan Cox 	    pmap_page_get_memattr(m_paddr) != memattr) {
2433153e878SAlan Cox 		memattr = pmap_page_get_memattr(m_paddr);
2443153e878SAlan Cox 		printf(
2453153e878SAlan Cox 	    "WARNING: A device driver has set \"memattr\" inconsistently.\n");
2463153e878SAlan Cox 	}
247ce1b857fSAlan Cox 	if ((page->flags & PG_FICTITIOUS) != 0) {
24892bab635SDoug Rabson 		/*
24992bab635SDoug Rabson 		 * If the passed in reqpage page is a fake page, update it with
25092bab635SDoug Rabson 		 * the new physical address.
25192bab635SDoug Rabson 		 */
25292bab635SDoug Rabson 		VM_OBJECT_LOCK(object);
2533153e878SAlan Cox 		dev_pager_updatefake(page, paddr, memattr);
25492bab635SDoug Rabson 		if (count > 1) {
25592bab635SDoug Rabson 			vm_page_lock_queues();
25692bab635SDoug Rabson 			for (i = 0; i < count; i++) {
25792bab635SDoug Rabson 				if (i != reqpage)
25892bab635SDoug Rabson 					vm_page_free(m[i]);
25992bab635SDoug Rabson 			}
26092bab635SDoug Rabson 			vm_page_unlock_queues();
26192bab635SDoug Rabson 		}
26292bab635SDoug Rabson 	} else {
263df8bae1dSRodney W. Grimes 		/*
26407159f9cSMaxime Henrion 		 * Replace the passed in reqpage page with our own fake page and
26507159f9cSMaxime Henrion 		 * free up the all of the original pages.
266df8bae1dSRodney W. Grimes 		 */
2673153e878SAlan Cox 		page = dev_pager_getfake(paddr, memattr);
2688630c117SAlan Cox 		VM_OBJECT_LOCK(object);
26924a1cce3SDavid Greenman 		TAILQ_INSERT_TAIL(&object->un_pager.devp.devp_pglist, page, pageq);
27060e15726SAlan Cox 		vm_page_lock_queues();
27160e15726SAlan Cox 		for (i = 0; i < count; i++)
27224a1cce3SDavid Greenman 			vm_page_free(m[i]);
27360e15726SAlan Cox 		vm_page_unlock_queues();
27426f9a767SRodney W. Grimes 		vm_page_insert(page, object, offset);
2759aa3d17dSAlan Cox 		m[reqpage] = page;
27692bab635SDoug Rabson 	}
277ce1b857fSAlan Cox 	page->valid = VM_PAGE_BITS_ALL;
278df8bae1dSRodney W. Grimes 	return (VM_PAGER_OK);
279df8bae1dSRodney W. Grimes }
280df8bae1dSRodney W. Grimes 
281e4542174SMatthew Dillon static void
28224a1cce3SDavid Greenman dev_pager_putpages(object, m, count, sync, rtvals)
28324a1cce3SDavid Greenman 	vm_object_t object;
28424a1cce3SDavid Greenman 	vm_page_t *m;
28524a1cce3SDavid Greenman 	int count;
286df8bae1dSRodney W. Grimes 	boolean_t sync;
28724a1cce3SDavid Greenman 	int *rtvals;
288df8bae1dSRodney W. Grimes {
289df8bae1dSRodney W. Grimes 	panic("dev_pager_putpage called");
290df8bae1dSRodney W. Grimes }
291df8bae1dSRodney W. Grimes 
292f708ef1bSPoul-Henning Kamp static boolean_t
293a316d390SJohn Dyson dev_pager_haspage(object, pindex, before, after)
29424a1cce3SDavid Greenman 	vm_object_t object;
295a316d390SJohn Dyson 	vm_pindex_t pindex;
29624a1cce3SDavid Greenman 	int *before;
29724a1cce3SDavid Greenman 	int *after;
298df8bae1dSRodney W. Grimes {
29924a1cce3SDavid Greenman 	if (before != NULL)
30024a1cce3SDavid Greenman 		*before = 0;
30124a1cce3SDavid Greenman 	if (after != NULL)
30224a1cce3SDavid Greenman 		*after = 0;
303df8bae1dSRodney W. Grimes 	return (TRUE);
304df8bae1dSRodney W. Grimes }
305df8bae1dSRodney W. Grimes 
30625f2e1c8SAlan Cox /*
3073153e878SAlan Cox  * Create a fictitious page with the specified physical address and memory
3083153e878SAlan Cox  * attribute.
30925f2e1c8SAlan Cox  */
310df8bae1dSRodney W. Grimes static vm_page_t
3113153e878SAlan Cox dev_pager_getfake(vm_paddr_t paddr, vm_memattr_t memattr)
312df8bae1dSRodney W. Grimes {
313df8bae1dSRodney W. Grimes 	vm_page_t m;
314df8bae1dSRodney W. Grimes 
3153153e878SAlan Cox 	m = uma_zalloc(fakepg_zone, M_WAITOK | M_ZERO);
31626f9a767SRodney W. Grimes 	m->phys_addr = paddr;
3173153e878SAlan Cox 	/* Fictitious pages don't use "segind". */
3183153e878SAlan Cox 	m->flags = PG_FICTITIOUS;
3193153e878SAlan Cox 	/* Fictitious pages don't use "order" or "pool". */
3203153e878SAlan Cox 	pmap_page_init(m);
3213153e878SAlan Cox 	m->oflags = VPO_BUSY;
3223153e878SAlan Cox 	m->wire_count = 1;
3233153e878SAlan Cox 	if (memattr != VM_MEMATTR_DEFAULT)
3243153e878SAlan Cox 		pmap_page_set_memattr(m, memattr);
325df8bae1dSRodney W. Grimes 	return (m);
326df8bae1dSRodney W. Grimes }
327df8bae1dSRodney W. Grimes 
3283153e878SAlan Cox /*
3293153e878SAlan Cox  * Release a fictitious page.
3303153e878SAlan Cox  */
331df8bae1dSRodney W. Grimes static void
3323153e878SAlan Cox dev_pager_putfake(vm_page_t m)
333df8bae1dSRodney W. Grimes {
3343153e878SAlan Cox 
335df8bae1dSRodney W. Grimes 	if (!(m->flags & PG_FICTITIOUS))
336df8bae1dSRodney W. Grimes 		panic("dev_pager_putfake: bad page");
3373153e878SAlan Cox 	/* Restore the default memory attribute to "phys_addr". */
3383153e878SAlan Cox 	if (pmap_page_get_memattr(m) != VM_MEMATTR_DEFAULT)
3393153e878SAlan Cox 		pmap_page_set_memattr(m, VM_MEMATTR_DEFAULT);
340670d17b5SJeff Roberson 	uma_zfree(fakepg_zone, m);
341df8bae1dSRodney W. Grimes }
34292bab635SDoug Rabson 
3433153e878SAlan Cox /*
3443153e878SAlan Cox  * Update the given fictitious page to the specified physical address and
3453153e878SAlan Cox  * memory attribute.
3463153e878SAlan Cox  */
34792bab635SDoug Rabson static void
3483153e878SAlan Cox dev_pager_updatefake(vm_page_t m, vm_paddr_t paddr, vm_memattr_t memattr)
34992bab635SDoug Rabson {
3503153e878SAlan Cox 
35192bab635SDoug Rabson 	if (!(m->flags & PG_FICTITIOUS))
35292bab635SDoug Rabson 		panic("dev_pager_updatefake: bad page");
3533153e878SAlan Cox 	/* Restore the default memory attribute before changing "phys_addr". */
3543153e878SAlan Cox 	if (pmap_page_get_memattr(m) != VM_MEMATTR_DEFAULT)
3553153e878SAlan Cox 		pmap_page_set_memattr(m, VM_MEMATTR_DEFAULT);
35692bab635SDoug Rabson 	m->phys_addr = paddr;
3573153e878SAlan Cox 	if (memattr != VM_MEMATTR_DEFAULT)
3583153e878SAlan Cox 		pmap_page_set_memattr(m, memattr);
35992bab635SDoug Rabson }
360