15b81b6b3SRodney W. Grimes /*- 25b81b6b3SRodney W. Grimes * Copyright (c) 1982, 1986 The Regents of the University of California. 35b81b6b3SRodney W. Grimes * Copyright (c) 1989, 1990 William Jolitz 41561d038SDavid Greenman * Copyright (c) 1994 John Dyson 55b81b6b3SRodney W. Grimes * All rights reserved. 65b81b6b3SRodney W. Grimes * 75b81b6b3SRodney W. Grimes * This code is derived from software contributed to Berkeley by 85b81b6b3SRodney W. Grimes * the Systems Programming Group of the University of Utah Computer 95b81b6b3SRodney W. Grimes * Science Department, and William Jolitz. 105b81b6b3SRodney W. Grimes * 115b81b6b3SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 125b81b6b3SRodney W. Grimes * modification, are permitted provided that the following conditions 135b81b6b3SRodney W. Grimes * are met: 145b81b6b3SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 155b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 165b81b6b3SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 175b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 185b81b6b3SRodney W. Grimes * documentation and/or other materials provided with the distribution. 195b81b6b3SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 205b81b6b3SRodney W. Grimes * must display the following acknowledgement: 215b81b6b3SRodney W. Grimes * This product includes software developed by the University of 225b81b6b3SRodney W. Grimes * California, Berkeley and its contributors. 235b81b6b3SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 245b81b6b3SRodney W. Grimes * may be used to endorse or promote products derived from this software 255b81b6b3SRodney W. Grimes * without specific prior written permission. 265b81b6b3SRodney W. Grimes * 275b81b6b3SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 285b81b6b3SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 295b81b6b3SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 305b81b6b3SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 315b81b6b3SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 325b81b6b3SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 335b81b6b3SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 345b81b6b3SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 355b81b6b3SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 365b81b6b3SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 375b81b6b3SRodney W. Grimes * SUCH DAMAGE. 385b81b6b3SRodney W. Grimes * 39960173b9SRodney W. Grimes * from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 405b81b6b3SRodney W. Grimes * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ 411561d038SDavid Greenman * $Id: vm_machdep.c,v 1.17 1994/03/30 02:47:13 davidg Exp $ 425b81b6b3SRodney W. Grimes */ 435b81b6b3SRodney W. Grimes 44960173b9SRodney W. Grimes #include "npx.h" 455b81b6b3SRodney W. Grimes #include "param.h" 465b81b6b3SRodney W. Grimes #include "systm.h" 475b81b6b3SRodney W. Grimes #include "proc.h" 485b81b6b3SRodney W. Grimes #include "malloc.h" 495b81b6b3SRodney W. Grimes #include "buf.h" 505b81b6b3SRodney W. Grimes #include "user.h" 515b81b6b3SRodney W. Grimes 525b81b6b3SRodney W. Grimes #include "../include/cpu.h" 535b81b6b3SRodney W. Grimes 545b81b6b3SRodney W. Grimes #include "vm/vm.h" 555b81b6b3SRodney W. Grimes #include "vm/vm_kern.h" 565b81b6b3SRodney W. Grimes 571561d038SDavid Greenman #define b_cylin b_resid 581561d038SDavid Greenman 59d5e26ef0SDavid Greenman #ifndef NOBOUNCE 60d5e26ef0SDavid Greenman 61d5e26ef0SDavid Greenman caddr_t bouncememory; 62d5e26ef0SDavid Greenman vm_offset_t bouncepa, bouncepaend; 63ed7fcbd0SDavid Greenman int bouncepages, bpwait; 641561d038SDavid Greenman vm_map_t io_map; 65d5e26ef0SDavid Greenman int bmwait, bmfreeing; 66d5e26ef0SDavid Greenman 67ed7fcbd0SDavid Greenman #define BITS_IN_UNSIGNED (8*sizeof(unsigned)) 68d5e26ef0SDavid Greenman int bounceallocarraysize; 69d5e26ef0SDavid Greenman unsigned *bounceallocarray; 70d5e26ef0SDavid Greenman int bouncefree; 71d5e26ef0SDavid Greenman 72d5e26ef0SDavid Greenman #define SIXTEENMEG (4096*4096) 731561d038SDavid Greenman #define MAXBKVA 1024 74d5e26ef0SDavid Greenman 75d5e26ef0SDavid Greenman /* special list that can be used at interrupt time for eventual kva free */ 76d5e26ef0SDavid Greenman struct kvasfree { 77d5e26ef0SDavid Greenman vm_offset_t addr; 78d5e26ef0SDavid Greenman vm_offset_t size; 79d5e26ef0SDavid Greenman } kvaf[MAXBKVA]; 80d5e26ef0SDavid Greenman 81d5e26ef0SDavid Greenman int kvasfreecnt; 82d5e26ef0SDavid Greenman 831561d038SDavid Greenman vm_offset_t vm_bounce_kva(); 84d5e26ef0SDavid Greenman /* 85d5e26ef0SDavid Greenman * get bounce buffer pages (count physically contiguous) 86d5e26ef0SDavid Greenman * (only 1 inplemented now) 87d5e26ef0SDavid Greenman */ 88d5e26ef0SDavid Greenman vm_offset_t 89d5e26ef0SDavid Greenman vm_bounce_page_find(count) 90d5e26ef0SDavid Greenman int count; 91d5e26ef0SDavid Greenman { 92d5e26ef0SDavid Greenman int bit; 93d5e26ef0SDavid Greenman int s,i; 94d5e26ef0SDavid Greenman 95d5e26ef0SDavid Greenman if (count != 1) 96d5e26ef0SDavid Greenman panic("vm_bounce_page_find -- no support for > 1 page yet!!!"); 97d5e26ef0SDavid Greenman 98d5e26ef0SDavid Greenman s = splbio(); 99d5e26ef0SDavid Greenman retry: 100d5e26ef0SDavid Greenman for (i = 0; i < bounceallocarraysize; i++) { 101d5e26ef0SDavid Greenman if (bounceallocarray[i] != 0xffffffff) { 102d5e26ef0SDavid Greenman if (bit = ffs(~bounceallocarray[i])) { 103d5e26ef0SDavid Greenman bounceallocarray[i] |= 1 << (bit - 1) ; 104d5e26ef0SDavid Greenman bouncefree -= count; 105d5e26ef0SDavid Greenman splx(s); 106ed7fcbd0SDavid Greenman return bouncepa + (i * BITS_IN_UNSIGNED + (bit - 1)) * NBPG; 107d5e26ef0SDavid Greenman } 108d5e26ef0SDavid Greenman } 109d5e26ef0SDavid Greenman } 110ed7fcbd0SDavid Greenman bpwait = 1; 111d5e26ef0SDavid Greenman tsleep((caddr_t) &bounceallocarray, PRIBIO, "bncwai", 0); 112d5e26ef0SDavid Greenman goto retry; 113d5e26ef0SDavid Greenman } 114d5e26ef0SDavid Greenman 1151561d038SDavid Greenman void 1161561d038SDavid Greenman vm_bounce_kva_free(addr, size, now) 1171561d038SDavid Greenman vm_offset_t addr; 1181561d038SDavid Greenman vm_offset_t size; 1191561d038SDavid Greenman int now; 1201561d038SDavid Greenman { 1211561d038SDavid Greenman int s = splbio(); 1221561d038SDavid Greenman kvaf[kvasfreecnt].addr = addr; 1231561d038SDavid Greenman kvaf[kvasfreecnt++].size = size; 1241561d038SDavid Greenman if( now) 1251561d038SDavid Greenman vm_bounce_kva(0,0); 1261561d038SDavid Greenman else 1271561d038SDavid Greenman wakeup((caddr_t) io_map); 1281561d038SDavid Greenman splx(s); 1291561d038SDavid Greenman } 1301561d038SDavid Greenman 131d5e26ef0SDavid Greenman /* 132d5e26ef0SDavid Greenman * free count bounce buffer pages 133d5e26ef0SDavid Greenman */ 134d5e26ef0SDavid Greenman void 135d5e26ef0SDavid Greenman vm_bounce_page_free(pa, count) 136d5e26ef0SDavid Greenman vm_offset_t pa; 137d5e26ef0SDavid Greenman int count; 138d5e26ef0SDavid Greenman { 139d5e26ef0SDavid Greenman int allocindex; 140d5e26ef0SDavid Greenman int index; 141d5e26ef0SDavid Greenman int bit; 142d5e26ef0SDavid Greenman 143d5e26ef0SDavid Greenman if (count != 1) 144d5e26ef0SDavid Greenman panic("vm_bounce_page_free -- no support for > 1 page yet!!!\n"); 145d5e26ef0SDavid Greenman 146d5e26ef0SDavid Greenman index = (pa - bouncepa) / NBPG; 147d5e26ef0SDavid Greenman 148d5e26ef0SDavid Greenman if ((index < 0) || (index >= bouncepages)) 149d5e26ef0SDavid Greenman panic("vm_bounce_page_free -- bad index\n"); 150d5e26ef0SDavid Greenman 151ed7fcbd0SDavid Greenman allocindex = index / BITS_IN_UNSIGNED; 152ed7fcbd0SDavid Greenman bit = index % BITS_IN_UNSIGNED; 153d5e26ef0SDavid Greenman 154d5e26ef0SDavid Greenman bounceallocarray[allocindex] &= ~(1 << bit); 155d5e26ef0SDavid Greenman 156d5e26ef0SDavid Greenman bouncefree += count; 157ed7fcbd0SDavid Greenman if (bpwait) { 158ed7fcbd0SDavid Greenman bpwait = 0; 159d5e26ef0SDavid Greenman wakeup((caddr_t) &bounceallocarray); 160d5e26ef0SDavid Greenman } 161ed7fcbd0SDavid Greenman } 162d5e26ef0SDavid Greenman 163d5e26ef0SDavid Greenman /* 164d5e26ef0SDavid Greenman * allocate count bounce buffer kva pages 165d5e26ef0SDavid Greenman */ 166d5e26ef0SDavid Greenman vm_offset_t 1671561d038SDavid Greenman vm_bounce_kva(count, waitok) 168d5e26ef0SDavid Greenman int count; 1691561d038SDavid Greenman int waitok; 170d5e26ef0SDavid Greenman { 171d5e26ef0SDavid Greenman int tofree; 172d5e26ef0SDavid Greenman int i; 173d5e26ef0SDavid Greenman int startfree; 1746b4ac811SDavid Greenman vm_offset_t kva = 0; 175d5e26ef0SDavid Greenman int s = splbio(); 1761561d038SDavid Greenman int size = count; 177d5e26ef0SDavid Greenman startfree = 0; 178d5e26ef0SDavid Greenman more: 179d5e26ef0SDavid Greenman if (!bmfreeing && (tofree = kvasfreecnt)) { 180d5e26ef0SDavid Greenman bmfreeing = 1; 181d5e26ef0SDavid Greenman for (i = startfree; i < kvasfreecnt; i++) { 1826b4ac811SDavid Greenman /* 1836b4ac811SDavid Greenman * if we have a kva of the right size, no sense 1846b4ac811SDavid Greenman * in freeing/reallocating... 1856b4ac811SDavid Greenman * might affect fragmentation short term, but 1861561d038SDavid Greenman * as long as the amount of io_map is 1876b4ac811SDavid Greenman * significantly more than the maximum transfer 1886b4ac811SDavid Greenman * size, I don't think that it is a problem. 1896b4ac811SDavid Greenman */ 190d5e26ef0SDavid Greenman pmap_remove(kernel_pmap, 191d5e26ef0SDavid Greenman kvaf[i].addr, kvaf[i].addr + kvaf[i].size); 1921561d038SDavid Greenman if( size && !kva && kvaf[i].size == size) { 1936b4ac811SDavid Greenman kva = kvaf[i].addr; 1946b4ac811SDavid Greenman } else { 1951561d038SDavid Greenman kmem_free_wakeup(io_map, kvaf[i].addr, 196d5e26ef0SDavid Greenman kvaf[i].size); 197d5e26ef0SDavid Greenman } 1986b4ac811SDavid Greenman } 199d5e26ef0SDavid Greenman if (kvasfreecnt != tofree) { 200d5e26ef0SDavid Greenman startfree = i; 201d5e26ef0SDavid Greenman bmfreeing = 0; 202d5e26ef0SDavid Greenman goto more; 203d5e26ef0SDavid Greenman } 204d5e26ef0SDavid Greenman kvasfreecnt = 0; 205d5e26ef0SDavid Greenman bmfreeing = 0; 206d5e26ef0SDavid Greenman } 207d5e26ef0SDavid Greenman 2081561d038SDavid Greenman if( size == 0) { 2091561d038SDavid Greenman splx(s); 2101561d038SDavid Greenman return NULL; 2111561d038SDavid Greenman } 2121561d038SDavid Greenman 2131561d038SDavid Greenman if (!kva && !(kva = kmem_alloc_pageable(io_map, size))) { 2141561d038SDavid Greenman if( !waitok) { 2151561d038SDavid Greenman splx(s); 2161561d038SDavid Greenman return NULL; 2171561d038SDavid Greenman } 218d5e26ef0SDavid Greenman bmwait = 1; 2191561d038SDavid Greenman tsleep((caddr_t) io_map, PRIBIO, "bmwait", 0); 220d5e26ef0SDavid Greenman goto more; 221d5e26ef0SDavid Greenman } 222d5e26ef0SDavid Greenman splx(s); 223d5e26ef0SDavid Greenman 224d5e26ef0SDavid Greenman return kva; 225d5e26ef0SDavid Greenman } 226d5e26ef0SDavid Greenman 227d5e26ef0SDavid Greenman /* 228d5e26ef0SDavid Greenman * do the things necessary to the struct buf to implement 229d5e26ef0SDavid Greenman * bounce buffers... inserted before the disk sort 230d5e26ef0SDavid Greenman */ 231d5e26ef0SDavid Greenman void 232d5e26ef0SDavid Greenman vm_bounce_alloc(bp) 233d5e26ef0SDavid Greenman struct buf *bp; 234d5e26ef0SDavid Greenman { 235d5e26ef0SDavid Greenman int countvmpg; 236d5e26ef0SDavid Greenman vm_offset_t vastart, vaend; 237d5e26ef0SDavid Greenman vm_offset_t vapstart, vapend; 238d5e26ef0SDavid Greenman vm_offset_t va, kva; 239d5e26ef0SDavid Greenman vm_offset_t pa; 240d5e26ef0SDavid Greenman int dobounceflag = 0; 241d5e26ef0SDavid Greenman int bounceindex; 242d5e26ef0SDavid Greenman int i; 243d5e26ef0SDavid Greenman int s; 244d5e26ef0SDavid Greenman 245d5e26ef0SDavid Greenman if (bouncepages == 0) 246d5e26ef0SDavid Greenman return; 247d5e26ef0SDavid Greenman 2481561d038SDavid Greenman if (bp->b_bufsize < bp->b_bcount) { 2491561d038SDavid Greenman printf("vm_bounce_alloc: b_bufsize(%d) < b_bcount(%d) !!!!\n", 2501561d038SDavid Greenman bp->b_bufsize, bp->b_bcount); 2511561d038SDavid Greenman bp->b_bufsize = bp->b_bcount; 2521561d038SDavid Greenman } 2531561d038SDavid Greenman 254d5e26ef0SDavid Greenman vastart = (vm_offset_t) bp->b_un.b_addr; 255ac322158SDavid Greenman vaend = (vm_offset_t) bp->b_un.b_addr + bp->b_bufsize; 256d5e26ef0SDavid Greenman 257d5e26ef0SDavid Greenman vapstart = i386_trunc_page(vastart); 258d5e26ef0SDavid Greenman vapend = i386_round_page(vaend); 259d5e26ef0SDavid Greenman countvmpg = (vapend - vapstart) / NBPG; 260d5e26ef0SDavid Greenman 261d5e26ef0SDavid Greenman /* 262d5e26ef0SDavid Greenman * if any page is above 16MB, then go into bounce-buffer mode 263d5e26ef0SDavid Greenman */ 264d5e26ef0SDavid Greenman va = vapstart; 265d5e26ef0SDavid Greenman for (i = 0; i < countvmpg; i++) { 266ed7fcbd0SDavid Greenman pa = pmap_kextract(va); 267d5e26ef0SDavid Greenman if (pa >= SIXTEENMEG) 268d5e26ef0SDavid Greenman ++dobounceflag; 269d5e26ef0SDavid Greenman va += NBPG; 270d5e26ef0SDavid Greenman } 271d5e26ef0SDavid Greenman if (dobounceflag == 0) 272d5e26ef0SDavid Greenman return; 273d5e26ef0SDavid Greenman 274d5e26ef0SDavid Greenman if (bouncepages < dobounceflag) 275d5e26ef0SDavid Greenman panic("Not enough bounce buffers!!!"); 276d5e26ef0SDavid Greenman 277d5e26ef0SDavid Greenman /* 278d5e26ef0SDavid Greenman * allocate a replacement kva for b_addr 279d5e26ef0SDavid Greenman */ 2801561d038SDavid Greenman kva = vm_bounce_kva(countvmpg*NBPG, 1); 281d5e26ef0SDavid Greenman va = vapstart; 282d5e26ef0SDavid Greenman for (i = 0; i < countvmpg; i++) { 283ed7fcbd0SDavid Greenman pa = pmap_kextract(va); 284d5e26ef0SDavid Greenman if (pa >= SIXTEENMEG) { 285d5e26ef0SDavid Greenman /* 286d5e26ef0SDavid Greenman * allocate a replacement page 287d5e26ef0SDavid Greenman */ 288d5e26ef0SDavid Greenman vm_offset_t bpa = vm_bounce_page_find(1); 2896b4ac811SDavid Greenman pmap_kenter(kva + (NBPG * i), bpa); 290d5e26ef0SDavid Greenman /* 291d5e26ef0SDavid Greenman * if we are writing, the copy the data into the page 292d5e26ef0SDavid Greenman */ 2931561d038SDavid Greenman if ((bp->b_flags & B_READ) == 0) { 2941561d038SDavid Greenman pmap_update(); 295d5e26ef0SDavid Greenman bcopy((caddr_t) va, (caddr_t) kva + (NBPG * i), NBPG); 2961561d038SDavid Greenman } 297d5e26ef0SDavid Greenman } else { 298d5e26ef0SDavid Greenman /* 299d5e26ef0SDavid Greenman * use original page 300d5e26ef0SDavid Greenman */ 3016b4ac811SDavid Greenman pmap_kenter(kva + (NBPG * i), pa); 302d5e26ef0SDavid Greenman } 303d5e26ef0SDavid Greenman va += NBPG; 304d5e26ef0SDavid Greenman } 3056b4ac811SDavid Greenman pmap_update(); 306d5e26ef0SDavid Greenman 307d5e26ef0SDavid Greenman /* 308d5e26ef0SDavid Greenman * flag the buffer as being bounced 309d5e26ef0SDavid Greenman */ 310d5e26ef0SDavid Greenman bp->b_flags |= B_BOUNCE; 311d5e26ef0SDavid Greenman /* 312d5e26ef0SDavid Greenman * save the original buffer kva 313d5e26ef0SDavid Greenman */ 314d5e26ef0SDavid Greenman bp->b_savekva = bp->b_un.b_addr; 315d5e26ef0SDavid Greenman /* 316d5e26ef0SDavid Greenman * put our new kva into the buffer (offset by original offset) 317d5e26ef0SDavid Greenman */ 318d5e26ef0SDavid Greenman bp->b_un.b_addr = (caddr_t) (((vm_offset_t) kva) | 319d5e26ef0SDavid Greenman ((vm_offset_t) bp->b_savekva & (NBPG - 1))); 320d5e26ef0SDavid Greenman return; 321d5e26ef0SDavid Greenman } 322d5e26ef0SDavid Greenman 323d5e26ef0SDavid Greenman /* 324d5e26ef0SDavid Greenman * hook into biodone to free bounce buffer 325d5e26ef0SDavid Greenman */ 326d5e26ef0SDavid Greenman void 327d5e26ef0SDavid Greenman vm_bounce_free(bp) 328d5e26ef0SDavid Greenman struct buf *bp; 329d5e26ef0SDavid Greenman { 330d5e26ef0SDavid Greenman int i; 331d5e26ef0SDavid Greenman vm_offset_t origkva, bouncekva; 332d5e26ef0SDavid Greenman vm_offset_t vastart, vaend; 333d5e26ef0SDavid Greenman vm_offset_t vapstart, vapend; 334d5e26ef0SDavid Greenman int countbounce = 0; 335d5e26ef0SDavid Greenman vm_offset_t firstbouncepa = 0; 336d5e26ef0SDavid Greenman int firstbounceindex; 337d5e26ef0SDavid Greenman int countvmpg; 338d5e26ef0SDavid Greenman vm_offset_t bcount; 339d5e26ef0SDavid Greenman int s; 340d5e26ef0SDavid Greenman 341d5e26ef0SDavid Greenman /* 342d5e26ef0SDavid Greenman * if this isn't a bounced buffer, then just return 343d5e26ef0SDavid Greenman */ 344d5e26ef0SDavid Greenman if ((bp->b_flags & B_BOUNCE) == 0) 345d5e26ef0SDavid Greenman return; 346d5e26ef0SDavid Greenman 347d5e26ef0SDavid Greenman origkva = (vm_offset_t) bp->b_savekva; 348d5e26ef0SDavid Greenman bouncekva = (vm_offset_t) bp->b_un.b_addr; 349d5e26ef0SDavid Greenman 350d5e26ef0SDavid Greenman vastart = bouncekva; 351ac322158SDavid Greenman vaend = bouncekva + bp->b_bufsize; 352ac322158SDavid Greenman bcount = bp->b_bufsize; 353d5e26ef0SDavid Greenman 354d5e26ef0SDavid Greenman vapstart = i386_trunc_page(vastart); 355d5e26ef0SDavid Greenman vapend = i386_round_page(vaend); 356d5e26ef0SDavid Greenman 357d5e26ef0SDavid Greenman countvmpg = (vapend - vapstart) / NBPG; 358d5e26ef0SDavid Greenman 359d5e26ef0SDavid Greenman /* 360d5e26ef0SDavid Greenman * check every page in the kva space for b_addr 361d5e26ef0SDavid Greenman */ 362d5e26ef0SDavid Greenman for (i = 0; i < countvmpg; i++) { 363d5e26ef0SDavid Greenman vm_offset_t mybouncepa; 364d5e26ef0SDavid Greenman vm_offset_t copycount; 365d5e26ef0SDavid Greenman 366d5e26ef0SDavid Greenman copycount = i386_round_page(bouncekva + 1) - bouncekva; 367ed7fcbd0SDavid Greenman mybouncepa = pmap_kextract(i386_trunc_page(bouncekva)); 368d5e26ef0SDavid Greenman 369d5e26ef0SDavid Greenman /* 370d5e26ef0SDavid Greenman * if this is a bounced pa, then process as one 371d5e26ef0SDavid Greenman */ 372d5e26ef0SDavid Greenman if ((mybouncepa >= bouncepa) && (mybouncepa < bouncepaend)) { 373d5e26ef0SDavid Greenman if (copycount > bcount) 374d5e26ef0SDavid Greenman copycount = bcount; 375d5e26ef0SDavid Greenman /* 376d5e26ef0SDavid Greenman * if this is a read, then copy from bounce buffer into original buffer 377d5e26ef0SDavid Greenman */ 378d5e26ef0SDavid Greenman if (bp->b_flags & B_READ) 379d5e26ef0SDavid Greenman bcopy((caddr_t) bouncekva, (caddr_t) origkva, copycount); 380d5e26ef0SDavid Greenman /* 381d5e26ef0SDavid Greenman * free the bounce allocation 382d5e26ef0SDavid Greenman */ 383d5e26ef0SDavid Greenman vm_bounce_page_free(i386_trunc_page(mybouncepa), 1); 384d5e26ef0SDavid Greenman } 385d5e26ef0SDavid Greenman 386d5e26ef0SDavid Greenman origkva += copycount; 387d5e26ef0SDavid Greenman bouncekva += copycount; 388d5e26ef0SDavid Greenman bcount -= copycount; 389d5e26ef0SDavid Greenman } 390d5e26ef0SDavid Greenman 391d5e26ef0SDavid Greenman /* 392d5e26ef0SDavid Greenman * add the old kva into the "to free" list 393d5e26ef0SDavid Greenman */ 394d5e26ef0SDavid Greenman bouncekva = i386_trunc_page((vm_offset_t) bp->b_un.b_addr); 3951561d038SDavid Greenman vm_bounce_kva_free( bouncekva, countvmpg*NBPG, 0); 396d5e26ef0SDavid Greenman if (bmwait) { 397d5e26ef0SDavid Greenman /* 398d5e26ef0SDavid Greenman * if anyone is waiting on the bounce-map, then wakeup 399d5e26ef0SDavid Greenman */ 4001561d038SDavid Greenman wakeup((caddr_t) io_map); 401d5e26ef0SDavid Greenman bmwait = 0; 402d5e26ef0SDavid Greenman } 403d5e26ef0SDavid Greenman 404d5e26ef0SDavid Greenman bp->b_un.b_addr = bp->b_savekva; 405d5e26ef0SDavid Greenman bp->b_savekva = 0; 406d5e26ef0SDavid Greenman bp->b_flags &= ~B_BOUNCE; 407d5e26ef0SDavid Greenman 408d5e26ef0SDavid Greenman return; 409d5e26ef0SDavid Greenman } 410d5e26ef0SDavid Greenman 411d5e26ef0SDavid Greenman #endif /* NOBOUNCE */ 412d5e26ef0SDavid Greenman 4135b81b6b3SRodney W. Grimes /* 4141561d038SDavid Greenman * init the bounce buffer system 4151561d038SDavid Greenman */ 4161561d038SDavid Greenman void 4171561d038SDavid Greenman vm_bounce_init() 4181561d038SDavid Greenman { 4191561d038SDavid Greenman vm_offset_t minaddr, maxaddr; 4201561d038SDavid Greenman 4211561d038SDavid Greenman io_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, MAXBKVA * NBPG, FALSE); 4221561d038SDavid Greenman kvasfreecnt = 0; 4231561d038SDavid Greenman 4241561d038SDavid Greenman #ifndef NOBOUNCE 4251561d038SDavid Greenman if (bouncepages == 0) 4261561d038SDavid Greenman return; 4271561d038SDavid Greenman 4281561d038SDavid Greenman bounceallocarraysize = (bouncepages + BITS_IN_UNSIGNED - 1) / BITS_IN_UNSIGNED; 4291561d038SDavid Greenman bounceallocarray = malloc(bounceallocarraysize * sizeof(unsigned), M_TEMP, M_NOWAIT); 4301561d038SDavid Greenman 4311561d038SDavid Greenman if (!bounceallocarray) 4321561d038SDavid Greenman panic("Cannot allocate bounce resource array\n"); 4331561d038SDavid Greenman 4341561d038SDavid Greenman bzero(bounceallocarray, bounceallocarraysize * sizeof(long)); 4351561d038SDavid Greenman 4361561d038SDavid Greenman 4371561d038SDavid Greenman bouncepa = pmap_kextract((vm_offset_t) bouncememory); 4381561d038SDavid Greenman bouncepaend = bouncepa + bouncepages * NBPG; 4391561d038SDavid Greenman bouncefree = bouncepages; 4401561d038SDavid Greenman #endif 4411561d038SDavid Greenman 4421561d038SDavid Greenman } 4431561d038SDavid Greenman 4441561d038SDavid Greenman 4451561d038SDavid Greenman void 4461561d038SDavid Greenman cldisksort(struct buf *dp, struct buf *bp, vm_offset_t maxio) 4471561d038SDavid Greenman { 4481561d038SDavid Greenman register struct buf *ap, *newbp; 4491561d038SDavid Greenman int i, trycount=0; 4501561d038SDavid Greenman vm_offset_t orig1pages, orig2pages; 4511561d038SDavid Greenman vm_offset_t orig1begin, orig2begin; 4521561d038SDavid Greenman vm_offset_t orig1end, orig2end; 4531561d038SDavid Greenman vm_offset_t origpages, newpages; 4541561d038SDavid Greenman vm_offset_t origbegin, newbegin; 4551561d038SDavid Greenman vm_offset_t origend, newend; 4561561d038SDavid Greenman vm_offset_t kvanew, kvaorig; 4571561d038SDavid Greenman 4581561d038SDavid Greenman /* 4591561d038SDavid Greenman * If nothing on the activity queue, then 4601561d038SDavid Greenman * we become the only thing. 4611561d038SDavid Greenman */ 4621561d038SDavid Greenman ap = dp->b_actf; 4631561d038SDavid Greenman if(ap == NULL) { 4641561d038SDavid Greenman dp->b_actf = bp; 4651561d038SDavid Greenman dp->b_actl = bp; 4661561d038SDavid Greenman bp->av_forw = NULL; 4671561d038SDavid Greenman return; 4681561d038SDavid Greenman } 4691561d038SDavid Greenman 4701561d038SDavid Greenman /* 4711561d038SDavid Greenman * If we lie after the first (currently active) 4721561d038SDavid Greenman * request, then we must locate the second request list 4731561d038SDavid Greenman * and add ourselves to it. 4741561d038SDavid Greenman */ 4751561d038SDavid Greenman 4761561d038SDavid Greenman if (bp->b_cylin < ap->b_cylin) { 4771561d038SDavid Greenman while (ap->av_forw) { 4781561d038SDavid Greenman /* 4791561d038SDavid Greenman * Check for an ``inversion'' in the 4801561d038SDavid Greenman * normally ascending cylinder numbers, 4811561d038SDavid Greenman * indicating the start of the second request list. 4821561d038SDavid Greenman */ 4831561d038SDavid Greenman if (ap->av_forw->b_cylin < ap->b_cylin) { 4841561d038SDavid Greenman /* 4851561d038SDavid Greenman * Search the second request list 4861561d038SDavid Greenman * for the first request at a larger 4871561d038SDavid Greenman * cylinder number. We go before that; 4881561d038SDavid Greenman * if there is no such request, we go at end. 4891561d038SDavid Greenman */ 4901561d038SDavid Greenman do { 4911561d038SDavid Greenman if (bp->b_cylin < ap->av_forw->b_cylin) 4921561d038SDavid Greenman goto insert; 4931561d038SDavid Greenman ap = ap->av_forw; 4941561d038SDavid Greenman } while (ap->av_forw); 4951561d038SDavid Greenman goto insert; /* after last */ 4961561d038SDavid Greenman } 4971561d038SDavid Greenman ap = ap->av_forw; 4981561d038SDavid Greenman } 4991561d038SDavid Greenman /* 5001561d038SDavid Greenman * No inversions... we will go after the last, and 5011561d038SDavid Greenman * be the first request in the second request list. 5021561d038SDavid Greenman */ 5031561d038SDavid Greenman goto insert; 5041561d038SDavid Greenman } 5051561d038SDavid Greenman /* 5061561d038SDavid Greenman * Request is at/after the current request... 5071561d038SDavid Greenman * sort in the first request list. 5081561d038SDavid Greenman */ 5091561d038SDavid Greenman while (ap->av_forw) { 5101561d038SDavid Greenman /* 5111561d038SDavid Greenman * We want to go after the current request 5121561d038SDavid Greenman * if there is an inversion after it (i.e. it is 5131561d038SDavid Greenman * the end of the first request list), or if 5141561d038SDavid Greenman * the next request is a larger cylinder than our request. 5151561d038SDavid Greenman */ 5161561d038SDavid Greenman if (ap->av_forw->b_cylin < ap->b_cylin || 5171561d038SDavid Greenman bp->b_cylin < ap->av_forw->b_cylin ) 5181561d038SDavid Greenman goto insert; 5191561d038SDavid Greenman ap = ap->av_forw; 5201561d038SDavid Greenman } 5211561d038SDavid Greenman 5221561d038SDavid Greenman insert: 5231561d038SDavid Greenman /* 5241561d038SDavid Greenman * we currently only cluster I/O transfers that are at page-aligned 5251561d038SDavid Greenman * kvas and transfers that are multiples of page lengths. 5261561d038SDavid Greenman */ 5271561d038SDavid Greenman if(((bp->b_bcount & (PAGE_SIZE-1)) == 0) && 5281561d038SDavid Greenman (((vm_offset_t) bp->b_un.b_addr & (PAGE_SIZE-1)) == 0)) { 5291561d038SDavid Greenman /* 5301561d038SDavid Greenman * merge with previous? 5311561d038SDavid Greenman * conditions: 5321561d038SDavid Greenman * 1) We reside physically immediately after the previous block. 5331561d038SDavid Greenman * 2) The previous block is not first on the device queue because 5341561d038SDavid Greenman * such a block might be active. 5351561d038SDavid Greenman * 3) The mode of the two I/Os is identical. 5361561d038SDavid Greenman * 4) The previous kva is page aligned and the previous transfer 5371561d038SDavid Greenman * is a multiple of a page in length. 5381561d038SDavid Greenman * 5) And the total I/O size would be below the maximum. 5391561d038SDavid Greenman */ 5401561d038SDavid Greenman if( (ap->b_blkno + (ap->b_bcount / DEV_BSIZE) == bp->b_blkno) && 5411561d038SDavid Greenman (dp->b_actf != ap) && 5421561d038SDavid Greenman ((ap->b_flags & ~B_CLUSTER) == bp->b_flags) && 5431561d038SDavid Greenman ((ap->b_bcount & (PAGE_SIZE-1)) == 0) && 5441561d038SDavid Greenman (((vm_offset_t) ap->b_un.b_addr & (PAGE_SIZE-1)) == 0) && 5451561d038SDavid Greenman (ap->b_bcount + bp->b_bcount < maxio)) { 5461561d038SDavid Greenman 5471561d038SDavid Greenman if( (ap->b_flags & B_CLUSTER) == 0) { 5481561d038SDavid Greenman 5491561d038SDavid Greenman orig1begin = (vm_offset_t) ap->b_un.b_addr; 5501561d038SDavid Greenman orig1end = (vm_offset_t) ap->b_un.b_addr + ap->b_bcount; 5511561d038SDavid Greenman orig1pages = ap->b_bcount / PAGE_SIZE; 5521561d038SDavid Greenman 5531561d038SDavid Greenman orig2begin = (vm_offset_t) bp->b_un.b_addr; 5541561d038SDavid Greenman orig2end = (vm_offset_t) bp->b_un.b_addr + bp->b_bcount; 5551561d038SDavid Greenman orig2pages = bp->b_bcount / PAGE_SIZE; 5561561d038SDavid Greenman 5571561d038SDavid Greenman /* 5581561d038SDavid Greenman * see if we can allocate a kva, if we cannot, the don't 5591561d038SDavid Greenman * cluster. 5601561d038SDavid Greenman */ 5611561d038SDavid Greenman kvanew = vm_bounce_kva( PAGE_SIZE * (orig1pages + orig2pages), 0); 5621561d038SDavid Greenman if( !kvanew) { 5631561d038SDavid Greenman goto nocluster; 5641561d038SDavid Greenman } 5651561d038SDavid Greenman 5661561d038SDavid Greenman /* 5671561d038SDavid Greenman * get a physical buf pointer 5681561d038SDavid Greenman */ 5691561d038SDavid Greenman newbp = (struct buf *)trypbuf(); 5701561d038SDavid Greenman if( !newbp) { 5711561d038SDavid Greenman vm_bounce_kva_free( kvanew, PAGE_SIZE * (orig1pages + orig2pages), 1); 5721561d038SDavid Greenman goto nocluster; 5731561d038SDavid Greenman } 5741561d038SDavid Greenman 5751561d038SDavid Greenman /* 5761561d038SDavid Greenman * enter the transfer physical addresses into the new kva 5771561d038SDavid Greenman */ 5781561d038SDavid Greenman for(i=0;i<orig1pages;i++) { 5791561d038SDavid Greenman vm_offset_t pa; 5801561d038SDavid Greenman pa = pmap_kextract((caddr_t) orig1begin + i * PAGE_SIZE); 5811561d038SDavid Greenman pmap_kenter(kvanew + i * PAGE_SIZE, pa); 5821561d038SDavid Greenman } 5831561d038SDavid Greenman 5841561d038SDavid Greenman for(i=0;i<orig2pages;i++) { 5851561d038SDavid Greenman vm_offset_t pa; 5861561d038SDavid Greenman pa = pmap_kextract((caddr_t) orig2begin + i * PAGE_SIZE); 5871561d038SDavid Greenman pmap_kenter(kvanew + (i + orig1pages) * PAGE_SIZE, pa); 5881561d038SDavid Greenman } 5891561d038SDavid Greenman 5901561d038SDavid Greenman /* 5911561d038SDavid Greenman * build the new bp to be handed off to the device 5921561d038SDavid Greenman */ 5931561d038SDavid Greenman 5941561d038SDavid Greenman *newbp = *ap; 5951561d038SDavid Greenman newbp->b_flags |= B_CLUSTER; 5961561d038SDavid Greenman newbp->b_un.b_addr = (caddr_t) kvanew; 5971561d038SDavid Greenman newbp->b_bcount += bp->b_bcount; 5981561d038SDavid Greenman newbp->b_bufsize = newbp->b_bcount; 5991561d038SDavid Greenman newbp->b_clusterf = ap; 6001561d038SDavid Greenman newbp->b_clusterl = bp; 6011561d038SDavid Greenman 6021561d038SDavid Greenman /* 6031561d038SDavid Greenman * enter the new bp onto the device queue 6041561d038SDavid Greenman */ 6051561d038SDavid Greenman if( ap->av_forw) 6061561d038SDavid Greenman ap->av_forw->av_back = newbp; 6071561d038SDavid Greenman else 6081561d038SDavid Greenman dp->b_actl = newbp; 6091561d038SDavid Greenman 6101561d038SDavid Greenman if( dp->b_actf != ap ) 6111561d038SDavid Greenman ap->av_back->av_forw = newbp; 6121561d038SDavid Greenman else 6131561d038SDavid Greenman dp->b_actf = newbp; 6141561d038SDavid Greenman 6151561d038SDavid Greenman /* 6161561d038SDavid Greenman * enter the previous bps onto the cluster queue 6171561d038SDavid Greenman */ 6181561d038SDavid Greenman ap->av_forw = bp; 6191561d038SDavid Greenman bp->av_back = ap; 6201561d038SDavid Greenman 6211561d038SDavid Greenman ap->av_back = NULL; 6221561d038SDavid Greenman bp->av_forw = NULL; 6231561d038SDavid Greenman 6241561d038SDavid Greenman } else { 6251561d038SDavid Greenman vm_offset_t addr; 6261561d038SDavid Greenman 6271561d038SDavid Greenman origbegin = (vm_offset_t) ap->b_un.b_addr; 6281561d038SDavid Greenman origend = (vm_offset_t) ap->b_un.b_addr + ap->b_bcount; 6291561d038SDavid Greenman origpages = ap->b_bcount/PAGE_SIZE; 6301561d038SDavid Greenman 6311561d038SDavid Greenman newbegin = (vm_offset_t) bp->b_un.b_addr; 6321561d038SDavid Greenman newend = (vm_offset_t) bp->b_un.b_addr + bp->b_bcount; 6331561d038SDavid Greenman newpages = bp->b_bcount/PAGE_SIZE; 6341561d038SDavid Greenman 6351561d038SDavid Greenman /* 6361561d038SDavid Greenman * see if we can allocate a kva, if we cannot, the don't 6371561d038SDavid Greenman * cluster. 6381561d038SDavid Greenman */ 6391561d038SDavid Greenman kvanew = vm_bounce_kva( PAGE_SIZE * (newpages + origpages), 0); 6401561d038SDavid Greenman if( !kvanew) { 6411561d038SDavid Greenman goto nocluster; 6421561d038SDavid Greenman } 6431561d038SDavid Greenman 6441561d038SDavid Greenman 6451561d038SDavid Greenman /* 6461561d038SDavid Greenman * enter the transfer physical addresses into the new kva 6471561d038SDavid Greenman */ 6481561d038SDavid Greenman for(i=0; i<origpages; i++) { 6491561d038SDavid Greenman vm_offset_t pa; 6501561d038SDavid Greenman pa = pmap_kextract(origbegin + i * PAGE_SIZE); 6511561d038SDavid Greenman pmap_kenter(kvanew + i * PAGE_SIZE, pa); 6521561d038SDavid Greenman } 6531561d038SDavid Greenman 6541561d038SDavid Greenman /* 6551561d038SDavid Greenman * free the old kva 6561561d038SDavid Greenman */ 6571561d038SDavid Greenman vm_bounce_kva_free( origbegin, ap->b_bufsize, 0); 6581561d038SDavid Greenman 6591561d038SDavid Greenman for(i=0; i<newpages; i++) { 6601561d038SDavid Greenman vm_offset_t pa; 6611561d038SDavid Greenman pa = pmap_kextract(newbegin + i * PAGE_SIZE); 6621561d038SDavid Greenman pmap_kenter(kvanew + (i + origpages) * PAGE_SIZE, pa); 6631561d038SDavid Greenman } 6641561d038SDavid Greenman 6651561d038SDavid Greenman ap->b_un.b_addr = (caddr_t) kvanew; 6661561d038SDavid Greenman 6671561d038SDavid Greenman ap->b_clusterl->av_forw = bp; 6681561d038SDavid Greenman bp->av_forw = NULL; 6691561d038SDavid Greenman bp->av_back = ap->b_clusterl; 6701561d038SDavid Greenman ap->b_clusterl = bp; 6711561d038SDavid Greenman 6721561d038SDavid Greenman ap->b_bcount += bp->b_bcount; 6731561d038SDavid Greenman ap->b_bufsize = ap->b_bcount; 6741561d038SDavid Greenman } 6751561d038SDavid Greenman pmap_update(); 6761561d038SDavid Greenman return; 6771561d038SDavid Greenman /* 6781561d038SDavid Greenman * merge with next? 6791561d038SDavid Greenman * conditions: 6801561d038SDavid Greenman * 1) We reside physically before the next block. 6811561d038SDavid Greenman * 3) The mode of the two I/Os is identical. 6821561d038SDavid Greenman * 4) The next kva is page aligned and the next transfer 6831561d038SDavid Greenman * is a multiple of a page in length. 6841561d038SDavid Greenman * 5) And the total I/O size would be below the maximum. 6851561d038SDavid Greenman */ 6861561d038SDavid Greenman } else if( ap->av_forw && 6871561d038SDavid Greenman (bp->b_blkno + (bp->b_bcount / DEV_BSIZE) == ap->av_forw->b_blkno) && 6881561d038SDavid Greenman (bp->b_flags == (ap->av_forw->b_flags & ~B_CLUSTER)) && 6891561d038SDavid Greenman ((ap->av_forw->b_bcount & (PAGE_SIZE-1)) == 0) && 6901561d038SDavid Greenman (((vm_offset_t) ap->av_forw->b_un.b_addr & (PAGE_SIZE-1)) == 0) && 6911561d038SDavid Greenman (ap->av_forw->b_bcount + bp->b_bcount < maxio)) { 6921561d038SDavid Greenman 6931561d038SDavid Greenman /* 6941561d038SDavid Greenman * if next isn't a cluster we need to create one 6951561d038SDavid Greenman */ 6961561d038SDavid Greenman if( (ap->av_forw->b_flags & B_CLUSTER) == 0) { 6971561d038SDavid Greenman 6981561d038SDavid Greenman orig1begin = (vm_offset_t) bp->b_un.b_addr; 6991561d038SDavid Greenman orig1end = (vm_offset_t) bp->b_un.b_addr + bp->b_bcount; 7001561d038SDavid Greenman orig1pages = bp->b_bcount / PAGE_SIZE; 7011561d038SDavid Greenman 7021561d038SDavid Greenman orig2begin = (vm_offset_t) ap->av_forw->b_un.b_addr; 7031561d038SDavid Greenman orig2end = (vm_offset_t) ap->av_forw->b_un.b_addr + ap->av_forw->b_bcount; 7041561d038SDavid Greenman orig2pages = ap->av_forw->b_bcount / PAGE_SIZE; 7051561d038SDavid Greenman 7061561d038SDavid Greenman /* 7071561d038SDavid Greenman * see if we can allocate a kva, if we cannot, the don't 7081561d038SDavid Greenman * cluster. 7091561d038SDavid Greenman */ 7101561d038SDavid Greenman kvanew = vm_bounce_kva( PAGE_SIZE * (orig1pages + orig2pages), 0); 7111561d038SDavid Greenman if( !kvanew) { 7121561d038SDavid Greenman goto nocluster; 7131561d038SDavid Greenman } 7141561d038SDavid Greenman 7151561d038SDavid Greenman /* 7161561d038SDavid Greenman * get a physical buf pointer 7171561d038SDavid Greenman */ 7181561d038SDavid Greenman newbp = (struct buf *)trypbuf(); 7191561d038SDavid Greenman if( !newbp) { 7201561d038SDavid Greenman vm_bounce_kva_free( kvanew, PAGE_SIZE * (orig1pages + orig2pages), 1); 7211561d038SDavid Greenman goto nocluster; 7221561d038SDavid Greenman } 7231561d038SDavid Greenman 7241561d038SDavid Greenman ap = ap->av_forw; 7251561d038SDavid Greenman 7261561d038SDavid Greenman for(i=0;i<orig1pages;i++) { 7271561d038SDavid Greenman vm_offset_t pa; 7281561d038SDavid Greenman pa = pmap_kextract((caddr_t) orig1begin + i * PAGE_SIZE); 7291561d038SDavid Greenman pmap_kenter(kvanew + i * PAGE_SIZE, pa); 7301561d038SDavid Greenman } 7311561d038SDavid Greenman 7321561d038SDavid Greenman for(i=0;i<orig2pages;i++) { 7331561d038SDavid Greenman vm_offset_t pa; 7341561d038SDavid Greenman pa = pmap_kextract((caddr_t) orig2begin + i * PAGE_SIZE); 7351561d038SDavid Greenman pmap_kenter(kvanew + (i + orig1pages) * PAGE_SIZE, pa); 7361561d038SDavid Greenman } 7371561d038SDavid Greenman 7381561d038SDavid Greenman *newbp = *ap; 7391561d038SDavid Greenman newbp->b_flags |= B_CLUSTER; 7401561d038SDavid Greenman newbp->b_un.b_addr = (caddr_t) kvanew; 7411561d038SDavid Greenman newbp->b_blkno = bp->b_blkno; 7421561d038SDavid Greenman newbp->b_bcount += bp->b_bcount; 7431561d038SDavid Greenman newbp->b_bufsize = newbp->b_bcount; 7441561d038SDavid Greenman newbp->b_clusterf = bp; 7451561d038SDavid Greenman newbp->b_clusterl = ap; 7461561d038SDavid Greenman 7471561d038SDavid Greenman if( ap->av_forw) 7481561d038SDavid Greenman ap->av_forw->av_back = newbp; 7491561d038SDavid Greenman else 7501561d038SDavid Greenman dp->b_actl = newbp; 7511561d038SDavid Greenman 7521561d038SDavid Greenman if( dp->b_actf != ap ) 7531561d038SDavid Greenman ap->av_back->av_forw = newbp; 7541561d038SDavid Greenman else 7551561d038SDavid Greenman dp->b_actf = newbp; 7561561d038SDavid Greenman 7571561d038SDavid Greenman bp->av_forw = ap; 7581561d038SDavid Greenman ap->av_back = bp; 7591561d038SDavid Greenman 7601561d038SDavid Greenman bp->av_back = NULL; 7611561d038SDavid Greenman ap->av_forw = NULL; 7621561d038SDavid Greenman } else { 7631561d038SDavid Greenman vm_offset_t addr; 7641561d038SDavid Greenman 7651561d038SDavid Greenman newbegin = (vm_offset_t) bp->b_un.b_addr; 7661561d038SDavid Greenman newend = (vm_offset_t) bp->b_un.b_addr + bp->b_bcount; 7671561d038SDavid Greenman newpages = bp->b_bcount/PAGE_SIZE; 7681561d038SDavid Greenman 7691561d038SDavid Greenman origbegin = (vm_offset_t) ap->av_forw->b_un.b_addr; 7701561d038SDavid Greenman origend = (vm_offset_t) ap->av_forw->b_un.b_addr + ap->av_forw->b_bcount; 7711561d038SDavid Greenman origpages = ap->av_forw->b_bcount/PAGE_SIZE; 7721561d038SDavid Greenman 7731561d038SDavid Greenman /* 7741561d038SDavid Greenman * see if we can allocate a kva, if we cannot, the don't 7751561d038SDavid Greenman * cluster. 7761561d038SDavid Greenman */ 7771561d038SDavid Greenman kvanew = vm_bounce_kva( PAGE_SIZE * (newpages + origpages), 0); 7781561d038SDavid Greenman if( !kvanew) { 7791561d038SDavid Greenman goto nocluster; 7801561d038SDavid Greenman } 7811561d038SDavid Greenman 7821561d038SDavid Greenman ap = ap->av_forw; 7831561d038SDavid Greenman 7841561d038SDavid Greenman for(i=0; i<newpages; i++) { 7851561d038SDavid Greenman vm_offset_t pa; 7861561d038SDavid Greenman pa = pmap_kextract(newbegin + i * PAGE_SIZE); 7871561d038SDavid Greenman pmap_kenter(kvanew + i * PAGE_SIZE, pa); 7881561d038SDavid Greenman } 7891561d038SDavid Greenman 7901561d038SDavid Greenman for(i=0; i<origpages; i++) { 7911561d038SDavid Greenman vm_offset_t pa; 7921561d038SDavid Greenman pa = pmap_kextract(origbegin + i * PAGE_SIZE); 7931561d038SDavid Greenman pmap_kenter(kvanew + (i + newpages) * PAGE_SIZE, pa); 7941561d038SDavid Greenman } 7951561d038SDavid Greenman 7961561d038SDavid Greenman vm_bounce_kva_free( origbegin, ap->b_bufsize, 0); 7971561d038SDavid Greenman 7981561d038SDavid Greenman ap->b_un.b_addr = (caddr_t) kvanew; 7991561d038SDavid Greenman bp->av_forw = ap->b_clusterf; 8001561d038SDavid Greenman ap->b_clusterf->av_back = bp; 8011561d038SDavid Greenman ap->b_clusterf = bp; 8021561d038SDavid Greenman bp->av_back = NULL; 8031561d038SDavid Greenman 8041561d038SDavid Greenman ap->b_blkno = bp->b_blkno; 8051561d038SDavid Greenman ap->b_bcount += bp->b_bcount; 8061561d038SDavid Greenman ap->b_bufsize = ap->b_bcount; 8071561d038SDavid Greenman 8081561d038SDavid Greenman } 8091561d038SDavid Greenman pmap_update(); 8101561d038SDavid Greenman return; 8111561d038SDavid Greenman } 8121561d038SDavid Greenman } 8131561d038SDavid Greenman /* 8141561d038SDavid Greenman * don't merge 8151561d038SDavid Greenman */ 8161561d038SDavid Greenman nocluster: 8171561d038SDavid Greenman bp->av_forw = ap->av_forw; 8181561d038SDavid Greenman if( bp->av_forw) 8191561d038SDavid Greenman bp->av_forw->av_back = bp; 8201561d038SDavid Greenman else 8211561d038SDavid Greenman dp->b_actl = bp; 8221561d038SDavid Greenman 8231561d038SDavid Greenman ap->av_forw = bp; 8241561d038SDavid Greenman bp->av_back = ap; 8251561d038SDavid Greenman } 8261561d038SDavid Greenman 8271561d038SDavid Greenman 8281561d038SDavid Greenman /* 8295b81b6b3SRodney W. Grimes * Finish a fork operation, with process p2 nearly set up. 8305b81b6b3SRodney W. Grimes * Copy and update the kernel stack and pcb, making the child 8315b81b6b3SRodney W. Grimes * ready to run, and marking it so that it can return differently 8325b81b6b3SRodney W. Grimes * than the parent. Returns 1 in the child process, 0 in the parent. 8335b81b6b3SRodney W. Grimes * We currently double-map the user area so that the stack is at the same 8345b81b6b3SRodney W. Grimes * address in each process; in the future we will probably relocate 8355b81b6b3SRodney W. Grimes * the frame pointers on the stack after copying. 8365b81b6b3SRodney W. Grimes */ 837381fe1aaSGarrett Wollman int 8385b81b6b3SRodney W. Grimes cpu_fork(p1, p2) 8395b81b6b3SRodney W. Grimes register struct proc *p1, *p2; 8405b81b6b3SRodney W. Grimes { 8415b81b6b3SRodney W. Grimes register struct user *up = p2->p_addr; 8425b81b6b3SRodney W. Grimes int foo, offset, addr, i; 8435b81b6b3SRodney W. Grimes extern char kstack[]; 8445b81b6b3SRodney W. Grimes extern int mvesp(); 8455b81b6b3SRodney W. Grimes 8465b81b6b3SRodney W. Grimes /* 8475b81b6b3SRodney W. Grimes * Copy pcb and stack from proc p1 to p2. 8485b81b6b3SRodney W. Grimes * We do this as cheaply as possible, copying only the active 8495b81b6b3SRodney W. Grimes * part of the stack. The stack and pcb need to agree; 8505b81b6b3SRodney W. Grimes * this is tricky, as the final pcb is constructed by savectx, 8515b81b6b3SRodney W. Grimes * but its frame isn't yet on the stack when the stack is copied. 8525b81b6b3SRodney W. Grimes * swtch compensates for this when the child eventually runs. 8535b81b6b3SRodney W. Grimes * This should be done differently, with a single call 8545b81b6b3SRodney W. Grimes * that copies and updates the pcb+stack, 8555b81b6b3SRodney W. Grimes * replacing the bcopy and savectx. 8565b81b6b3SRodney W. Grimes */ 8575b81b6b3SRodney W. Grimes p2->p_addr->u_pcb = p1->p_addr->u_pcb; 8585b81b6b3SRodney W. Grimes offset = mvesp() - (int)kstack; 8595b81b6b3SRodney W. Grimes bcopy((caddr_t)kstack + offset, (caddr_t)p2->p_addr + offset, 8605b81b6b3SRodney W. Grimes (unsigned) ctob(UPAGES) - offset); 8615b81b6b3SRodney W. Grimes p2->p_regs = p1->p_regs; 8625b81b6b3SRodney W. Grimes 8635b81b6b3SRodney W. Grimes /* 8645b81b6b3SRodney W. Grimes * Wire top of address space of child to it's kstack. 8655b81b6b3SRodney W. Grimes * First, fault in a page of pte's to map it. 8665b81b6b3SRodney W. Grimes */ 8677f8cb368SDavid Greenman #if 0 8685b81b6b3SRodney W. Grimes addr = trunc_page((u_int)vtopte(kstack)); 8695b81b6b3SRodney W. Grimes vm_map_pageable(&p2->p_vmspace->vm_map, addr, addr+NBPG, FALSE); 8705b81b6b3SRodney W. Grimes for (i=0; i < UPAGES; i++) 8717f8cb368SDavid Greenman pmap_enter(&p2->p_vmspace->vm_pmap, kstack+i*NBPG, 87226931201SDavid Greenman pmap_extract(kernel_pmap, ((int)p2->p_addr)+i*NBPG), 87326931201SDavid Greenman /* 87426931201SDavid Greenman * The user area has to be mapped writable because 87526931201SDavid Greenman * it contains the kernel stack (when CR0_WP is on 87626931201SDavid Greenman * on a 486 there is no user-read/kernel-write 87726931201SDavid Greenman * mode). It is protected from user mode access 87826931201SDavid Greenman * by the segment limits. 87926931201SDavid Greenman */ 88026931201SDavid Greenman VM_PROT_READ|VM_PROT_WRITE, TRUE); 8817f8cb368SDavid Greenman #endif 8825b81b6b3SRodney W. Grimes pmap_activate(&p2->p_vmspace->vm_pmap, &up->u_pcb); 8835b81b6b3SRodney W. Grimes 8845b81b6b3SRodney W. Grimes /* 8855b81b6b3SRodney W. Grimes * 8865b81b6b3SRodney W. Grimes * Arrange for a non-local goto when the new process 8875b81b6b3SRodney W. Grimes * is started, to resume here, returning nonzero from setjmp. 8885b81b6b3SRodney W. Grimes */ 8895b81b6b3SRodney W. Grimes if (savectx(up, 1)) { 8905b81b6b3SRodney W. Grimes /* 8915b81b6b3SRodney W. Grimes * Return 1 in child. 8925b81b6b3SRodney W. Grimes */ 8935b81b6b3SRodney W. Grimes return (1); 8945b81b6b3SRodney W. Grimes } 8955b81b6b3SRodney W. Grimes return (0); 8965b81b6b3SRodney W. Grimes } 8975b81b6b3SRodney W. Grimes 8985b81b6b3SRodney W. Grimes #ifdef notyet 8995b81b6b3SRodney W. Grimes /* 9005b81b6b3SRodney W. Grimes * cpu_exit is called as the last action during exit. 9015b81b6b3SRodney W. Grimes * 9025b81b6b3SRodney W. Grimes * We change to an inactive address space and a "safe" stack, 9035b81b6b3SRodney W. Grimes * passing thru an argument to the new stack. Now, safely isolated 9045b81b6b3SRodney W. Grimes * from the resources we're shedding, we release the address space 9055b81b6b3SRodney W. Grimes * and any remaining machine-dependent resources, including the 9065b81b6b3SRodney W. Grimes * memory for the user structure and kernel stack. 9075b81b6b3SRodney W. Grimes * 9085b81b6b3SRodney W. Grimes * Next, we assign a dummy context to be written over by swtch, 9095b81b6b3SRodney W. Grimes * calling it to send this process off to oblivion. 9105b81b6b3SRodney W. Grimes * [The nullpcb allows us to minimize cost in swtch() by not having 9115b81b6b3SRodney W. Grimes * a special case]. 9125b81b6b3SRodney W. Grimes */ 9135b81b6b3SRodney W. Grimes struct proc *swtch_to_inactive(); 91475124a8bSPaul Richards volatile void 9155b81b6b3SRodney W. Grimes cpu_exit(p) 9165b81b6b3SRodney W. Grimes register struct proc *p; 9175b81b6b3SRodney W. Grimes { 9185b81b6b3SRodney W. Grimes static struct pcb nullpcb; /* pcb to overwrite on last swtch */ 9195b81b6b3SRodney W. Grimes 920960173b9SRodney W. Grimes #if NNPX > 0 9215b81b6b3SRodney W. Grimes npxexit(p); 922960173b9SRodney W. Grimes #endif /* NNPX */ 9235b81b6b3SRodney W. Grimes 9245b81b6b3SRodney W. Grimes /* move to inactive space and stack, passing arg accross */ 9255b81b6b3SRodney W. Grimes p = swtch_to_inactive(p); 9265b81b6b3SRodney W. Grimes 9275b81b6b3SRodney W. Grimes /* drop per-process resources */ 9285b81b6b3SRodney W. Grimes vmspace_free(p->p_vmspace); 9295b81b6b3SRodney W. Grimes kmem_free(kernel_map, (vm_offset_t)p->p_addr, ctob(UPAGES)); 9305b81b6b3SRodney W. Grimes 9315b81b6b3SRodney W. Grimes p->p_addr = (struct user *) &nullpcb; 9325b81b6b3SRodney W. Grimes splclock(); 9335b81b6b3SRodney W. Grimes swtch(); 9345b81b6b3SRodney W. Grimes /* NOTREACHED */ 9355b81b6b3SRodney W. Grimes } 9365b81b6b3SRodney W. Grimes #else 9377c2b54e8SNate Williams void 9385b81b6b3SRodney W. Grimes cpu_exit(p) 9395b81b6b3SRodney W. Grimes register struct proc *p; 9405b81b6b3SRodney W. Grimes { 9415b81b6b3SRodney W. Grimes 942960173b9SRodney W. Grimes #if NNPX > 0 9435b81b6b3SRodney W. Grimes npxexit(p); 944960173b9SRodney W. Grimes #endif /* NNPX */ 9455b81b6b3SRodney W. Grimes splclock(); 9467f8cb368SDavid Greenman curproc = 0; 9475b81b6b3SRodney W. Grimes swtch(); 9487c2b54e8SNate Williams /* 9497c2b54e8SNate Williams * This is to shutup the compiler, and if swtch() failed I suppose 9507c2b54e8SNate Williams * this would be a good thing. This keeps gcc happy because panic 9517c2b54e8SNate Williams * is a volatile void function as well. 9527c2b54e8SNate Williams */ 9537c2b54e8SNate Williams panic("cpu_exit"); 9545b81b6b3SRodney W. Grimes } 9555b81b6b3SRodney W. Grimes 956381fe1aaSGarrett Wollman void 9577f8cb368SDavid Greenman cpu_wait(p) struct proc *p; { 9587f8cb368SDavid Greenman /* extern vm_map_t upages_map; */ 9597f8cb368SDavid Greenman extern char kstack[]; 9605b81b6b3SRodney W. Grimes 9615b81b6b3SRodney W. Grimes /* drop per-process resources */ 9627f8cb368SDavid Greenman pmap_remove(vm_map_pmap(kernel_map), (vm_offset_t) p->p_addr, 9637f8cb368SDavid Greenman ((vm_offset_t) p->p_addr) + ctob(UPAGES)); 9645b81b6b3SRodney W. Grimes kmem_free(kernel_map, (vm_offset_t)p->p_addr, ctob(UPAGES)); 9657f8cb368SDavid Greenman vmspace_free(p->p_vmspace); 9665b81b6b3SRodney W. Grimes } 9675b81b6b3SRodney W. Grimes #endif 9685b81b6b3SRodney W. Grimes 9695b81b6b3SRodney W. Grimes /* 9705b81b6b3SRodney W. Grimes * Set a red zone in the kernel stack after the u. area. 9715b81b6b3SRodney W. Grimes */ 972381fe1aaSGarrett Wollman void 9735b81b6b3SRodney W. Grimes setredzone(pte, vaddr) 9745b81b6b3SRodney W. Grimes u_short *pte; 9755b81b6b3SRodney W. Grimes caddr_t vaddr; 9765b81b6b3SRodney W. Grimes { 9775b81b6b3SRodney W. Grimes /* eventually do this by setting up an expand-down stack segment 9785b81b6b3SRodney W. Grimes for ss0: selector, allowing stack access down to top of u. 9795b81b6b3SRodney W. Grimes this means though that protection violations need to be handled 9805b81b6b3SRodney W. Grimes thru a double fault exception that must do an integral task 9815b81b6b3SRodney W. Grimes switch to a known good context, within which a dump can be 9825b81b6b3SRodney W. Grimes taken. a sensible scheme might be to save the initial context 9835b81b6b3SRodney W. Grimes used by sched (that has physical memory mapped 1:1 at bottom) 9845b81b6b3SRodney W. Grimes and take the dump while still in mapped mode */ 9855b81b6b3SRodney W. Grimes } 9865b81b6b3SRodney W. Grimes 9875b81b6b3SRodney W. Grimes /* 9885b81b6b3SRodney W. Grimes * Convert kernel VA to physical address 9895b81b6b3SRodney W. Grimes */ 990aaf08d94SGarrett Wollman u_long 9917f8cb368SDavid Greenman kvtop(void *addr) 9925b81b6b3SRodney W. Grimes { 9935b81b6b3SRodney W. Grimes vm_offset_t va; 9945b81b6b3SRodney W. Grimes 995ed7fcbd0SDavid Greenman va = pmap_kextract((vm_offset_t)addr); 9965b81b6b3SRodney W. Grimes if (va == 0) 9975b81b6b3SRodney W. Grimes panic("kvtop: zero page frame"); 9987f8cb368SDavid Greenman return((int)va); 9995b81b6b3SRodney W. Grimes } 10005b81b6b3SRodney W. Grimes 10015b81b6b3SRodney W. Grimes extern vm_map_t phys_map; 10025b81b6b3SRodney W. Grimes 10035b81b6b3SRodney W. Grimes /* 1004ac322158SDavid Greenman * Map an IO request into kernel virtual address space. 10055b81b6b3SRodney W. Grimes * 1006ac322158SDavid Greenman * All requests are (re)mapped into kernel VA space. 1007ac322158SDavid Greenman * Notice that we use b_bufsize for the size of the buffer 1008ac322158SDavid Greenman * to be mapped. b_bcount might be modified by the driver. 10095b81b6b3SRodney W. Grimes */ 1010381fe1aaSGarrett Wollman void 10115b81b6b3SRodney W. Grimes vmapbuf(bp) 10125b81b6b3SRodney W. Grimes register struct buf *bp; 10135b81b6b3SRodney W. Grimes { 10145b81b6b3SRodney W. Grimes register int npf; 10155b81b6b3SRodney W. Grimes register caddr_t addr; 10165b81b6b3SRodney W. Grimes register long flags = bp->b_flags; 10175b81b6b3SRodney W. Grimes struct proc *p; 10185b81b6b3SRodney W. Grimes int off; 10195b81b6b3SRodney W. Grimes vm_offset_t kva; 10205b81b6b3SRodney W. Grimes register vm_offset_t pa; 10215b81b6b3SRodney W. Grimes 10225b81b6b3SRodney W. Grimes if ((flags & B_PHYS) == 0) 10235b81b6b3SRodney W. Grimes panic("vmapbuf"); 10245b81b6b3SRodney W. Grimes addr = bp->b_saveaddr = bp->b_un.b_addr; 10255b81b6b3SRodney W. Grimes off = (int)addr & PGOFSET; 10265b81b6b3SRodney W. Grimes p = bp->b_proc; 1027ac322158SDavid Greenman npf = btoc(round_page(bp->b_bufsize + off)); 10285b81b6b3SRodney W. Grimes kva = kmem_alloc_wait(phys_map, ctob(npf)); 10295b81b6b3SRodney W. Grimes bp->b_un.b_addr = (caddr_t) (kva + off); 10305b81b6b3SRodney W. Grimes while (npf--) { 10315b81b6b3SRodney W. Grimes pa = pmap_extract(&p->p_vmspace->vm_pmap, (vm_offset_t)addr); 10325b81b6b3SRodney W. Grimes if (pa == 0) 10335b81b6b3SRodney W. Grimes panic("vmapbuf: null page frame"); 10346b4ac811SDavid Greenman pmap_kenter(kva, trunc_page(pa)); 10355b81b6b3SRodney W. Grimes addr += PAGE_SIZE; 10365b81b6b3SRodney W. Grimes kva += PAGE_SIZE; 10375b81b6b3SRodney W. Grimes } 10386b4ac811SDavid Greenman pmap_update(); 10395b81b6b3SRodney W. Grimes } 10405b81b6b3SRodney W. Grimes 10415b81b6b3SRodney W. Grimes /* 10425b81b6b3SRodney W. Grimes * Free the io map PTEs associated with this IO operation. 10435b81b6b3SRodney W. Grimes * We also invalidate the TLB entries and restore the original b_addr. 10445b81b6b3SRodney W. Grimes */ 1045381fe1aaSGarrett Wollman void 10465b81b6b3SRodney W. Grimes vunmapbuf(bp) 10475b81b6b3SRodney W. Grimes register struct buf *bp; 10485b81b6b3SRodney W. Grimes { 10495b81b6b3SRodney W. Grimes register int npf; 10505b81b6b3SRodney W. Grimes register caddr_t addr = bp->b_un.b_addr; 10515b81b6b3SRodney W. Grimes vm_offset_t kva; 10525b81b6b3SRodney W. Grimes 10535b81b6b3SRodney W. Grimes if ((bp->b_flags & B_PHYS) == 0) 10545b81b6b3SRodney W. Grimes panic("vunmapbuf"); 1055ac322158SDavid Greenman npf = btoc(round_page(bp->b_bufsize + ((int)addr & PGOFSET))); 10565b81b6b3SRodney W. Grimes kva = (vm_offset_t)((int)addr & ~PGOFSET); 10575b81b6b3SRodney W. Grimes kmem_free_wakeup(phys_map, kva, ctob(npf)); 10585b81b6b3SRodney W. Grimes bp->b_un.b_addr = bp->b_saveaddr; 10595b81b6b3SRodney W. Grimes bp->b_saveaddr = NULL; 10605b81b6b3SRodney W. Grimes } 10615b81b6b3SRodney W. Grimes 10625b81b6b3SRodney W. Grimes /* 10635b81b6b3SRodney W. Grimes * Force reset the processor by invalidating the entire address space! 10645b81b6b3SRodney W. Grimes */ 10657f8cb368SDavid Greenman void 10665b81b6b3SRodney W. Grimes cpu_reset() { 10675b81b6b3SRodney W. Grimes 10685b81b6b3SRodney W. Grimes /* force a shutdown by unmapping entire address space ! */ 10695b81b6b3SRodney W. Grimes bzero((caddr_t) PTD, NBPG); 10705b81b6b3SRodney W. Grimes 10715b81b6b3SRodney W. Grimes /* "good night, sweet prince .... <THUNK!>" */ 10725b81b6b3SRodney W. Grimes tlbflush(); 10735b81b6b3SRodney W. Grimes /* NOTREACHED */ 10747f8cb368SDavid Greenman while(1); 10755b81b6b3SRodney W. Grimes } 1076b9d60b3fSDavid Greenman 1077b9d60b3fSDavid Greenman /* 1078b9d60b3fSDavid Greenman * Grow the user stack to allow for 'sp'. This version grows the stack in 107929360eb0SDavid Greenman * chunks of SGROWSIZ. 1080b9d60b3fSDavid Greenman */ 1081b9d60b3fSDavid Greenman int 1082b9d60b3fSDavid Greenman grow(p, sp) 1083b9d60b3fSDavid Greenman struct proc *p; 1084b9d60b3fSDavid Greenman int sp; 1085b9d60b3fSDavid Greenman { 1086b9d60b3fSDavid Greenman unsigned int nss; 1087b9d60b3fSDavid Greenman caddr_t v; 1088b9d60b3fSDavid Greenman struct vmspace *vm = p->p_vmspace; 1089b9d60b3fSDavid Greenman 1090b9d60b3fSDavid Greenman if ((caddr_t)sp <= vm->vm_maxsaddr || (unsigned)sp >= (unsigned)USRSTACK) 1091b9d60b3fSDavid Greenman return (1); 1092b9d60b3fSDavid Greenman 1093b9d60b3fSDavid Greenman nss = roundup(USRSTACK - (unsigned)sp, PAGE_SIZE); 1094b9d60b3fSDavid Greenman 1095b9d60b3fSDavid Greenman if (nss > p->p_rlimit[RLIMIT_STACK].rlim_cur) 1096b9d60b3fSDavid Greenman return (0); 1097b9d60b3fSDavid Greenman 1098b9d60b3fSDavid Greenman if (vm->vm_ssize && roundup(vm->vm_ssize << PAGE_SHIFT, 109929360eb0SDavid Greenman SGROWSIZ) < nss) { 1100b9d60b3fSDavid Greenman int grow_amount; 1101b9d60b3fSDavid Greenman /* 1102b9d60b3fSDavid Greenman * If necessary, grow the VM that the stack occupies 1103b9d60b3fSDavid Greenman * to allow for the rlimit. This allows us to not have 1104b9d60b3fSDavid Greenman * to allocate all of the VM up-front in execve (which 1105b9d60b3fSDavid Greenman * is expensive). 1106b9d60b3fSDavid Greenman * Grow the VM by the amount requested rounded up to 110729360eb0SDavid Greenman * the nearest SGROWSIZ to provide for some hysteresis. 1108b9d60b3fSDavid Greenman */ 110929360eb0SDavid Greenman grow_amount = roundup((nss - (vm->vm_ssize << PAGE_SHIFT)), SGROWSIZ); 1110b9d60b3fSDavid Greenman v = (char *)USRSTACK - roundup(vm->vm_ssize << PAGE_SHIFT, 111129360eb0SDavid Greenman SGROWSIZ) - grow_amount; 1112b9d60b3fSDavid Greenman /* 111329360eb0SDavid Greenman * If there isn't enough room to extend by SGROWSIZ, then 1114b9d60b3fSDavid Greenman * just extend to the maximum size 1115b9d60b3fSDavid Greenman */ 1116b9d60b3fSDavid Greenman if (v < vm->vm_maxsaddr) { 1117b9d60b3fSDavid Greenman v = vm->vm_maxsaddr; 1118b9d60b3fSDavid Greenman grow_amount = MAXSSIZ - (vm->vm_ssize << PAGE_SHIFT); 1119b9d60b3fSDavid Greenman } 1120b9d60b3fSDavid Greenman if (vm_allocate(&vm->vm_map, (vm_offset_t *)&v, 1121b9d60b3fSDavid Greenman grow_amount, FALSE) != KERN_SUCCESS) { 1122b9d60b3fSDavid Greenman return (0); 1123b9d60b3fSDavid Greenman } 1124b9d60b3fSDavid Greenman vm->vm_ssize += grow_amount >> PAGE_SHIFT; 1125b9d60b3fSDavid Greenman } 1126b9d60b3fSDavid Greenman 1127b9d60b3fSDavid Greenman return (1); 1128b9d60b3fSDavid Greenman } 1129