uvm_vnode.c revision 1.93.2.4 1 1.93.2.1 uebayasi /* $NetBSD: uvm_vnode.c,v 1.93.2.4 2010/11/18 16:16:36 uebayasi Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 1.1 mrg * Copyright (c) 1991, 1993
6 1.49 chs * The Regents of the University of California.
7 1.1 mrg * Copyright (c) 1990 University of Utah.
8 1.1 mrg *
9 1.1 mrg * All rights reserved.
10 1.1 mrg *
11 1.1 mrg * This code is derived from software contributed to Berkeley by
12 1.1 mrg * the Systems Programming Group of the University of Utah Computer
13 1.1 mrg * Science Department.
14 1.1 mrg *
15 1.1 mrg * Redistribution and use in source and binary forms, with or without
16 1.1 mrg * modification, are permitted provided that the following conditions
17 1.1 mrg * are met:
18 1.1 mrg * 1. Redistributions of source code must retain the above copyright
19 1.1 mrg * notice, this list of conditions and the following disclaimer.
20 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
21 1.1 mrg * notice, this list of conditions and the following disclaimer in the
22 1.1 mrg * documentation and/or other materials provided with the distribution.
23 1.1 mrg * 3. All advertising materials mentioning features or use of this software
24 1.1 mrg * must display the following acknowledgement:
25 1.1 mrg * This product includes software developed by Charles D. Cranor,
26 1.49 chs * Washington University, the University of California, Berkeley and
27 1.1 mrg * its contributors.
28 1.1 mrg * 4. Neither the name of the University nor the names of its contributors
29 1.1 mrg * may be used to endorse or promote products derived from this software
30 1.1 mrg * without specific prior written permission.
31 1.1 mrg *
32 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 mrg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 mrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 mrg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 mrg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 mrg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 mrg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 mrg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 mrg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 mrg * SUCH DAMAGE.
43 1.1 mrg *
44 1.1 mrg * @(#)vnode_pager.c 8.8 (Berkeley) 2/13/94
45 1.3 mrg * from: Id: uvm_vnode.c,v 1.1.2.26 1998/02/02 20:38:07 chuck Exp
46 1.1 mrg */
47 1.1 mrg
48 1.55 lukem /*
49 1.55 lukem * uvm_vnode.c: the vnode pager.
50 1.55 lukem */
51 1.55 lukem
52 1.55 lukem #include <sys/cdefs.h>
53 1.93.2.1 uebayasi __KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.93.2.4 2010/11/18 16:16:36 uebayasi Exp $");
54 1.55 lukem
55 1.4 mrg #include "opt_uvmhist.h"
56 1.93.2.2 uebayasi #include "opt_xip.h"
57 1.1 mrg
58 1.1 mrg #include <sys/param.h>
59 1.1 mrg #include <sys/systm.h>
60 1.37 chs #include <sys/kernel.h>
61 1.1 mrg #include <sys/proc.h>
62 1.1 mrg #include <sys/malloc.h>
63 1.1 mrg #include <sys/vnode.h>
64 1.13 thorpej #include <sys/disklabel.h>
65 1.13 thorpej #include <sys/ioctl.h>
66 1.13 thorpej #include <sys/fcntl.h>
67 1.13 thorpej #include <sys/conf.h>
68 1.37 chs #include <sys/pool.h>
69 1.37 chs #include <sys/mount.h>
70 1.13 thorpej
71 1.13 thorpej #include <miscfs/specfs/specdev.h>
72 1.1 mrg
73 1.1 mrg #include <uvm/uvm.h>
74 1.68 yamt #include <uvm/uvm_readahead.h>
75 1.1 mrg
76 1.1 mrg /*
77 1.1 mrg * functions
78 1.1 mrg */
79 1.1 mrg
80 1.66 thorpej static void uvn_detach(struct uvm_object *);
81 1.66 thorpej static int uvn_get(struct uvm_object *, voff_t, struct vm_page **, int *,
82 1.66 thorpej int, vm_prot_t, int, int);
83 1.66 thorpej static int uvn_put(struct uvm_object *, voff_t, voff_t, int);
84 1.66 thorpej static void uvn_reference(struct uvm_object *);
85 1.52 chs
86 1.66 thorpej static int uvn_findpage(struct uvm_object *, voff_t, struct vm_page **,
87 1.66 thorpej int);
88 1.1 mrg
89 1.1 mrg /*
90 1.1 mrg * master pager structure
91 1.1 mrg */
92 1.1 mrg
93 1.89 yamt const struct uvm_pagerops uvm_vnodeops = {
94 1.88 yamt .pgo_reference = uvn_reference,
95 1.88 yamt .pgo_detach = uvn_detach,
96 1.88 yamt .pgo_get = uvn_get,
97 1.88 yamt .pgo_put = uvn_put,
98 1.1 mrg };
99 1.1 mrg
100 1.1 mrg /*
101 1.1 mrg * the ops!
102 1.1 mrg */
103 1.1 mrg
104 1.1 mrg /*
105 1.1 mrg * uvn_reference
106 1.1 mrg *
107 1.1 mrg * duplicate a reference to a VM object. Note that the reference
108 1.49 chs * count must already be at least one (the passed in reference) so
109 1.1 mrg * there is no chance of the uvn being killed or locked out here.
110 1.1 mrg *
111 1.49 chs * => caller must call with object unlocked.
112 1.1 mrg * => caller must be using the same accessprot as was used at attach time
113 1.1 mrg */
114 1.1 mrg
115 1.66 thorpej static void
116 1.65 thorpej uvn_reference(struct uvm_object *uobj)
117 1.1 mrg {
118 1.93 pooka vref((struct vnode *)uobj);
119 1.1 mrg }
120 1.1 mrg
121 1.52 chs
122 1.1 mrg /*
123 1.1 mrg * uvn_detach
124 1.1 mrg *
125 1.1 mrg * remove a reference to a VM object.
126 1.1 mrg *
127 1.1 mrg * => caller must call with object unlocked and map locked.
128 1.1 mrg */
129 1.52 chs
130 1.66 thorpej static void
131 1.65 thorpej uvn_detach(struct uvm_object *uobj)
132 1.8 mrg {
133 1.37 chs vrele((struct vnode *)uobj);
134 1.1 mrg }
135 1.1 mrg
136 1.1 mrg /*
137 1.1 mrg * uvn_put: flush page data to backing store.
138 1.1 mrg *
139 1.53 sommerfe * => object must be locked on entry! VOP_PUTPAGES must unlock it.
140 1.1 mrg * => flags: PGO_SYNCIO -- use sync. I/O
141 1.1 mrg * => note: caller must set PG_CLEAN and pmap_clear_modify (if needed)
142 1.1 mrg */
143 1.1 mrg
144 1.66 thorpej static int
145 1.65 thorpej uvn_put(struct uvm_object *uobj, voff_t offlo, voff_t offhi, int flags)
146 1.1 mrg {
147 1.37 chs struct vnode *vp = (struct vnode *)uobj;
148 1.37 chs int error;
149 1.1 mrg
150 1.90 ad KASSERT(mutex_owned(&vp->v_interlock));
151 1.54 chs error = VOP_PUTPAGES(vp, offlo, offhi, flags);
152 1.90 ad
153 1.48 chs return error;
154 1.1 mrg }
155 1.1 mrg
156 1.1 mrg
157 1.1 mrg /*
158 1.1 mrg * uvn_get: get pages (synchronously) from backing store
159 1.1 mrg *
160 1.1 mrg * => prefer map unlocked (not required)
161 1.1 mrg * => object must be locked! we will _unlock_ it before starting any I/O.
162 1.1 mrg * => flags: PGO_ALLPAGES: get all of the pages
163 1.1 mrg * PGO_LOCKED: fault data structures are locked
164 1.1 mrg * => NOTE: offset is the offset of pps[0], _NOT_ pps[centeridx]
165 1.1 mrg * => NOTE: caller must check for released pages!!
166 1.1 mrg */
167 1.49 chs
168 1.66 thorpej static int
169 1.65 thorpej uvn_get(struct uvm_object *uobj, voff_t offset,
170 1.65 thorpej struct vm_page **pps /* IN/OUT */,
171 1.65 thorpej int *npagesp /* IN (OUT if PGO_LOCKED)*/,
172 1.65 thorpej int centeridx, vm_prot_t access_type, int advice, int flags)
173 1.8 mrg {
174 1.37 chs struct vnode *vp = (struct vnode *)uobj;
175 1.37 chs int error;
176 1.67 yamt
177 1.37 chs UVMHIST_FUNC("uvn_get"); UVMHIST_CALLED(ubchist);
178 1.37 chs
179 1.37 chs UVMHIST_LOG(ubchist, "vp %p off 0x%x", vp, (int)offset, 0,0);
180 1.68 yamt
181 1.93.2.1 uebayasi #ifdef XIP
182 1.93.2.2 uebayasi if ((vp->v_vflag & VV_XIP) != 0)
183 1.93.2.1 uebayasi goto uvn_get_ra_done;
184 1.93.2.1 uebayasi #endif
185 1.68 yamt if ((access_type & VM_PROT_WRITE) == 0 && (flags & PGO_LOCKED) == 0) {
186 1.68 yamt vn_ra_allocctx(vp);
187 1.68 yamt uvm_ra_request(vp->v_ractx, advice, uobj, offset,
188 1.68 yamt *npagesp << PAGE_SHIFT);
189 1.68 yamt }
190 1.93.2.1 uebayasi #ifdef XIP
191 1.93.2.1 uebayasi uvn_get_ra_done:
192 1.93.2.1 uebayasi #endif
193 1.68 yamt
194 1.37 chs error = VOP_GETPAGES(vp, offset, pps, npagesp, centeridx,
195 1.37 chs access_type, advice, flags);
196 1.67 yamt
197 1.90 ad KASSERT(((flags & PGO_LOCKED) != 0 && mutex_owned(&vp->v_interlock)) ||
198 1.90 ad (flags & PGO_LOCKED) == 0);
199 1.48 chs return error;
200 1.37 chs }
201 1.8 mrg
202 1.8 mrg
203 1.37 chs /*
204 1.37 chs * uvn_findpages:
205 1.37 chs * return the page for the uobj and offset requested, allocating if needed.
206 1.37 chs * => uobj must be locked.
207 1.52 chs * => returned pages will be BUSY.
208 1.37 chs */
209 1.1 mrg
210 1.58 enami int
211 1.65 thorpej uvn_findpages(struct uvm_object *uobj, voff_t offset, int *npagesp,
212 1.65 thorpej struct vm_page **pgs, int flags)
213 1.37 chs {
214 1.58 enami int i, count, found, npages, rv;
215 1.8 mrg
216 1.58 enami count = found = 0;
217 1.37 chs npages = *npagesp;
218 1.52 chs if (flags & UFP_BACKWARD) {
219 1.52 chs for (i = npages - 1; i >= 0; i--, offset -= PAGE_SIZE) {
220 1.52 chs rv = uvn_findpage(uobj, offset, &pgs[i], flags);
221 1.58 enami if (rv == 0) {
222 1.58 enami if (flags & UFP_DIRTYONLY)
223 1.58 enami break;
224 1.58 enami } else
225 1.58 enami found++;
226 1.52 chs count++;
227 1.52 chs }
228 1.52 chs } else {
229 1.52 chs for (i = 0; i < npages; i++, offset += PAGE_SIZE) {
230 1.52 chs rv = uvn_findpage(uobj, offset, &pgs[i], flags);
231 1.58 enami if (rv == 0) {
232 1.58 enami if (flags & UFP_DIRTYONLY)
233 1.58 enami break;
234 1.58 enami } else
235 1.58 enami found++;
236 1.52 chs count++;
237 1.52 chs }
238 1.37 chs }
239 1.52 chs *npagesp = count;
240 1.58 enami return (found);
241 1.37 chs }
242 1.8 mrg
243 1.66 thorpej static int
244 1.65 thorpej uvn_findpage(struct uvm_object *uobj, voff_t offset, struct vm_page **pgp,
245 1.65 thorpej int flags)
246 1.37 chs {
247 1.37 chs struct vm_page *pg;
248 1.79 thorpej bool dirty;
249 1.37 chs UVMHIST_FUNC("uvn_findpage"); UVMHIST_CALLED(ubchist);
250 1.37 chs UVMHIST_LOG(ubchist, "vp %p off 0x%lx", uobj, offset,0,0);
251 1.8 mrg
252 1.37 chs if (*pgp != NULL) {
253 1.37 chs UVMHIST_LOG(ubchist, "dontcare", 0,0,0,0);
254 1.37 chs return 0;
255 1.37 chs }
256 1.37 chs for (;;) {
257 1.37 chs /* look for an existing page */
258 1.37 chs pg = uvm_pagelookup(uobj, offset);
259 1.37 chs
260 1.52 chs /* nope? allocate one now */
261 1.37 chs if (pg == NULL) {
262 1.37 chs if (flags & UFP_NOALLOC) {
263 1.37 chs UVMHIST_LOG(ubchist, "noalloc", 0,0,0,0);
264 1.37 chs return 0;
265 1.37 chs }
266 1.47 chs pg = uvm_pagealloc(uobj, offset, NULL, 0);
267 1.37 chs if (pg == NULL) {
268 1.37 chs if (flags & UFP_NOWAIT) {
269 1.37 chs UVMHIST_LOG(ubchist, "nowait",0,0,0,0);
270 1.37 chs return 0;
271 1.8 mrg }
272 1.90 ad mutex_exit(&uobj->vmobjlock);
273 1.37 chs uvm_wait("uvn_fp1");
274 1.90 ad mutex_enter(&uobj->vmobjlock);
275 1.37 chs continue;
276 1.47 chs }
277 1.52 chs UVMHIST_LOG(ubchist, "alloced %p", pg,0,0,0);
278 1.37 chs break;
279 1.37 chs } else if (flags & UFP_NOCACHE) {
280 1.37 chs UVMHIST_LOG(ubchist, "nocache",0,0,0,0);
281 1.37 chs return 0;
282 1.8 mrg }
283 1.8 mrg
284 1.37 chs /* page is there, see if we need to wait on it */
285 1.52 chs if ((pg->flags & PG_BUSY) != 0) {
286 1.37 chs if (flags & UFP_NOWAIT) {
287 1.37 chs UVMHIST_LOG(ubchist, "nowait",0,0,0,0);
288 1.37 chs return 0;
289 1.37 chs }
290 1.37 chs pg->flags |= PG_WANTED;
291 1.58 enami UVMHIST_LOG(ubchist, "wait %p", pg,0,0,0);
292 1.37 chs UVM_UNLOCK_AND_WAIT(pg, &uobj->vmobjlock, 0,
293 1.37 chs "uvn_fp2", 0);
294 1.90 ad mutex_enter(&uobj->vmobjlock);
295 1.37 chs continue;
296 1.8 mrg }
297 1.49 chs
298 1.37 chs /* skip PG_RDONLY pages if requested */
299 1.37 chs if ((flags & UFP_NORDONLY) && (pg->flags & PG_RDONLY)) {
300 1.37 chs UVMHIST_LOG(ubchist, "nordonly",0,0,0,0);
301 1.37 chs return 0;
302 1.8 mrg }
303 1.8 mrg
304 1.52 chs /* stop on clean pages if requested */
305 1.52 chs if (flags & UFP_DIRTYONLY) {
306 1.52 chs dirty = pmap_clear_modify(pg) ||
307 1.52 chs (pg->flags & PG_CLEAN) == 0;
308 1.52 chs pg->flags |= PG_CLEAN;
309 1.52 chs if (!dirty) {
310 1.58 enami UVMHIST_LOG(ubchist, "dirtonly", 0,0,0,0);
311 1.52 chs return 0;
312 1.52 chs }
313 1.52 chs }
314 1.52 chs
315 1.37 chs /* mark the page BUSY and we're done. */
316 1.37 chs pg->flags |= PG_BUSY;
317 1.37 chs UVM_PAGE_OWN(pg, "uvn_findpage");
318 1.52 chs UVMHIST_LOG(ubchist, "found %p", pg,0,0,0);
319 1.37 chs break;
320 1.8 mrg }
321 1.37 chs *pgp = pg;
322 1.37 chs return 1;
323 1.1 mrg }
324 1.1 mrg
325 1.1 mrg /*
326 1.52 chs * uvm_vnp_setsize: grow or shrink a vnode uobj
327 1.1 mrg *
328 1.1 mrg * grow => just update size value
329 1.1 mrg * shrink => toss un-needed pages
330 1.1 mrg *
331 1.49 chs * => we assume that the caller has a reference of some sort to the
332 1.1 mrg * vnode in question so that it will not be yanked out from under
333 1.1 mrg * us.
334 1.1 mrg */
335 1.1 mrg
336 1.8 mrg void
337 1.65 thorpej uvm_vnp_setsize(struct vnode *vp, voff_t newsize)
338 1.8 mrg {
339 1.52 chs struct uvm_object *uobj = &vp->v_uobj;
340 1.46 enami voff_t pgend = round_page(newsize);
341 1.72 yamt voff_t oldsize;
342 1.37 chs UVMHIST_FUNC("uvm_vnp_setsize"); UVMHIST_CALLED(ubchist);
343 1.37 chs
344 1.90 ad mutex_enter(&uobj->vmobjlock);
345 1.52 chs UVMHIST_LOG(ubchist, "vp %p old 0x%x new 0x%x",
346 1.52 chs vp, vp->v_size, newsize, 0);
347 1.1 mrg
348 1.8 mrg /*
349 1.37 chs * now check if the size has changed: if we shrink we had better
350 1.37 chs * toss some pages...
351 1.8 mrg */
352 1.1 mrg
353 1.85 pooka KASSERT(newsize != VSIZENOTSET);
354 1.85 pooka KASSERT(vp->v_size <= vp->v_writesize);
355 1.85 pooka KASSERT(vp->v_size == vp->v_writesize ||
356 1.85 pooka newsize == vp->v_writesize || newsize <= vp->v_size);
357 1.85 pooka
358 1.85 pooka oldsize = vp->v_writesize;
359 1.85 pooka KASSERT(oldsize != VSIZENOTSET || pgend > oldsize);
360 1.85 pooka
361 1.85 pooka if (oldsize > pgend) {
362 1.57 chs (void) uvn_put(uobj, pgend, 0, PGO_FREE | PGO_SYNCIO);
363 1.90 ad mutex_enter(&uobj->vmobjlock);
364 1.8 mrg }
365 1.82 yamt vp->v_size = vp->v_writesize = newsize;
366 1.90 ad mutex_exit(&uobj->vmobjlock);
367 1.1 mrg }
368 1.1 mrg
369 1.82 yamt void
370 1.82 yamt uvm_vnp_setwritesize(struct vnode *vp, voff_t newsize)
371 1.82 yamt {
372 1.82 yamt
373 1.90 ad mutex_enter(&vp->v_interlock);
374 1.85 pooka KASSERT(newsize != VSIZENOTSET);
375 1.82 yamt KASSERT(vp->v_size != VSIZENOTSET);
376 1.82 yamt KASSERT(vp->v_writesize != VSIZENOTSET);
377 1.82 yamt KASSERT(vp->v_size <= vp->v_writesize);
378 1.82 yamt KASSERT(vp->v_size <= newsize);
379 1.82 yamt vp->v_writesize = newsize;
380 1.90 ad mutex_exit(&vp->v_interlock);
381 1.82 yamt }
382 1.82 yamt
383 1.79 thorpej bool
384 1.75 yamt uvn_text_p(struct uvm_object *uobj)
385 1.75 yamt {
386 1.75 yamt struct vnode *vp = (struct vnode *)uobj;
387 1.75 yamt
388 1.86 ad return (vp->v_iflag & VI_EXECMAP) != 0;
389 1.75 yamt }
390 1.75 yamt
391 1.79 thorpej bool
392 1.75 yamt uvn_clean_p(struct uvm_object *uobj)
393 1.75 yamt {
394 1.75 yamt struct vnode *vp = (struct vnode *)uobj;
395 1.75 yamt
396 1.86 ad return (vp->v_iflag & VI_ONWORKLST) == 0;
397 1.75 yamt }
398 1.75 yamt
399 1.79 thorpej bool
400 1.75 yamt uvn_needs_writefault_p(struct uvm_object *uobj)
401 1.75 yamt {
402 1.75 yamt struct vnode *vp = (struct vnode *)uobj;
403 1.75 yamt
404 1.75 yamt return uvn_clean_p(uobj) ||
405 1.86 ad (vp->v_iflag & (VI_WRMAP|VI_WRMAPDIRTY)) == VI_WRMAP;
406 1.75 yamt }
407 1.93.2.3 uebayasi
408 1.93.2.3 uebayasi /*
409 1.93.2.3 uebayasi * uvn_findpage_xip
410 1.93.2.3 uebayasi * Lookup a physical page identity (== struct vm_page * in
411 1.93.2.3 uebayasi * the current UVM design) within the given vnode, at the
412 1.93.2.3 uebayasi * given offset.
413 1.93.2.3 uebayasi */
414 1.93.2.3 uebayasi struct vm_page *
415 1.93.2.4 uebayasi uvn_findpage_xip(struct vnode *devvp, struct uvm_object *uobj, off_t off)
416 1.93.2.3 uebayasi {
417 1.93.2.4 uebayasi #if defined(DIAGNOSTIC)
418 1.93.2.3 uebayasi struct vnode *vp = (struct vnode *)uobj;
419 1.93.2.4 uebayasi #endif
420 1.93.2.3 uebayasi struct vm_physseg *seg;
421 1.93.2.3 uebayasi struct vm_page *pg;
422 1.93.2.3 uebayasi
423 1.93.2.4 uebayasi #if defined(XIP)
424 1.93.2.4 uebayasi #if !defined(XIP_CDEV_MMAP)
425 1.93.2.3 uebayasi KASSERT((vp->v_vflag & VV_XIP) != 0);
426 1.93.2.3 uebayasi KASSERT((off & PAGE_MASK) == 0);
427 1.93.2.3 uebayasi
428 1.93.2.3 uebayasi /*
429 1.93.2.3 uebayasi * Lookup a physical page identity from the underlying physical
430 1.93.2.3 uebayasi * segment.
431 1.93.2.3 uebayasi *
432 1.93.2.3 uebayasi * Eventually, this will be replaced by a call of character
433 1.93.2.3 uebayasi * device pager method, which is a generalized version of
434 1.93.2.3 uebayasi * cdev_mmap(). Which means that v_physseg will become struct
435 1.93.2.3 uebayasi * uvm_object *, and this will call cdev_page(uobj, off).
436 1.93.2.3 uebayasi */
437 1.93.2.3 uebayasi
438 1.93.2.4 uebayasi seg = devvp->v_physseg;
439 1.93.2.3 uebayasi KASSERT(seg != NULL);
440 1.93.2.3 uebayasi
441 1.93.2.3 uebayasi pg = seg->pgs + (off >> PAGE_SHIFT);
442 1.93.2.4 uebayasi #else
443 1.93.2.4 uebayasi dev_t dev;
444 1.93.2.4 uebayasi paddr_t mdpgno, pa, pfn;
445 1.93.2.4 uebayasi int segno, segidx;
446 1.93.2.4 uebayasi
447 1.93.2.4 uebayasi KASSERT(vp != NULL);
448 1.93.2.4 uebayasi KASSERT((vp->v_vflag & VV_XIP) != 0);
449 1.93.2.4 uebayasi KASSERT((off & PAGE_MASK) == 0);
450 1.93.2.4 uebayasi
451 1.93.2.4 uebayasi /*
452 1.93.2.4 uebayasi * Get an "mmap cookie" from device.
453 1.93.2.4 uebayasi */
454 1.93.2.4 uebayasi dev = devsw_blk2chr(devvp->v_rdev);
455 1.93.2.4 uebayasi mdpgno = cdev_mmap(dev, off, 0);
456 1.93.2.4 uebayasi KASSERT(mdpgno != -1);
457 1.93.2.4 uebayasi
458 1.93.2.4 uebayasi /*
459 1.93.2.4 uebayasi * Index the matching vm_page and return it the vnode pager
460 1.93.2.4 uebayasi * (genfs_getpages).
461 1.93.2.4 uebayasi */
462 1.93.2.4 uebayasi pa = pmap_phys_address(mdpgno);
463 1.93.2.4 uebayasi pfn = atop(pa);
464 1.93.2.4 uebayasi segno = vm_physseg_find_device(pfn, &segidx);
465 1.93.2.4 uebayasi seg = VM_PHYSDEV_PTR(segno);
466 1.93.2.4 uebayasi KASSERT(seg != NULL);
467 1.93.2.4 uebayasi KASSERT(segidx == pfn - seg->start);
468 1.93.2.4 uebayasi KASSERT(seg->pgs != NULL);
469 1.93.2.4 uebayasi
470 1.93.2.4 uebayasi pg = seg->pgs + segidx;
471 1.93.2.4 uebayasi #endif
472 1.93.2.4 uebayasi #endif
473 1.93.2.3 uebayasi
474 1.93.2.3 uebayasi KASSERT(pg->phys_addr == (seg->start << PAGE_SHIFT) + off);
475 1.93.2.3 uebayasi
476 1.93.2.3 uebayasi return pg;
477 1.93.2.3 uebayasi }
478