Add UVM support.

This commit is contained in:
tsubai 1998-05-03 17:46:41 +00:00
parent f7a658d062
commit ed4f8a8894
1 changed files with 82 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.9 1998/05/01 18:41:27 tsubai Exp $ */
/* $NetBSD: machdep.c,v 1.10 1998/05/03 17:46:41 tsubai Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -43,11 +43,12 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.9 1998/05/01 18:41:27 tsubai Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.10 1998/05/03 17:46:41 tsubai Exp $");
/* from: Utah Hdr: machdep.c 1.63 91/04/24 */
#include "fs_mfs.h"
#include "opt_uvm.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -75,6 +76,11 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.9 1998/05/01 18:41:27 tsubai Exp $");
#include <sys/kcore.h>
#include <vm/vm_kern.h>
#if defined(UVM)
#include <uvm/uvm_extern.h>
#endif
#include <ufs/mfs/mfs_extern.h> /* mfs_initminiroot() */
#include <machine/cpu.h>
@ -98,7 +104,15 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.9 1998/05/01 18:41:27 tsubai Exp $");
char machine[] = MACHINE; /* from <machine/param.h> */
char cpu_model[30];
/* maps for VM objects */
#if defined(UVM)
vm_map_t exec_map = NULL;
vm_map_t mb_map = NULL;
vm_map_t phys_map = NULL;
#else
vm_map_t buffer_map;
#endif
int maxmem; /* max memory per process */
int physmem; /* max supported memory, changes to actual */
@ -199,7 +213,11 @@ mach_init(x_boothowto, x_bootdev, x_bootname, x_maxmem)
/*
* Set the VM page size.
*/
#if defined(UVM)
uvm_setpagesize();
#else
vm_set_page_size();
#endif
boothowto = x_boothowto;
bootdev = x_bootdev;
@ -256,7 +274,11 @@ mach_init(x_boothowto, x_bootdev, x_bootname, x_maxmem)
*/
first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
last = mem_clusters[0].start + mem_clusters[0].size;
#if defined(UVM)
uvm_page_physload(atop(first), atop(last), atop(first), atop(last));
#else
vm_page_physload(atop(first), atop(last), atop(first), atop(last));
#endif
/*
* Initialize error message buffer (at end of core).
@ -333,7 +355,7 @@ cpu_startup()
* Good {morning,afternoon,evening,night}.
*/
printf(version);
printf("real mem = %d\n", ctob(physmem));
printf("real mem = %d\n", ctob(physmem));
/*
* Allocate virtual address space for file I/O buffers.
@ -341,15 +363,52 @@ cpu_startup()
* and usually occupy more virtual memory than physical.
*/
size = MAXBSIZE * nbuf;
#if defined(UVM)
if (uvm_map(kernel_map, (vm_offset_t *) &buffers, round_page(size),
NULL, UVM_UNKNOWN_OFFSET,
UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
panic("startup: cannot allocate VM for buffers");
#else
buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
&maxaddr, size, TRUE);
minaddr = (vm_offset_t)buffers;
if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
&minaddr, size, FALSE) != KERN_SUCCESS)
panic("startup: cannot allocate buffers");
#endif /* UVM */
base = bufpages / nbuf;
residual = bufpages % nbuf;
for (i = 0; i < nbuf; i++) {
#if defined(UVM)
vm_size_t curbufsize;
vm_offset_t curbuf;
struct vm_page *pg;
/*
* Each buffer has MAXBSIZE bytes of VM space allocated. Of
* that MAXBSIZE space, we allocate and map (base+1) pages
* for the first "residual" buffers, and then we allocate
* "base" pages for the rest.
*/
curbuf = (vm_offset_t) buffers + (i * MAXBSIZE);
curbufsize = CLBYTES * ((i < residual) ? (base+1) : base);
while (curbufsize) {
pg = uvm_pagealloc(NULL, 0, NULL);
if (pg == NULL)
panic("cpu_startup: not enough memory for "
"buffer cache");
#if defined(PMAP_NEW)
pmap_kenter_pgs(curbuf, &pg, 1);
#else
pmap_enter(kernel_map->pmap, curbuf,
VM_PAGE_TO_PHYS(pg), VM_PROT_ALL, TRUE);
#endif
curbuf += PAGE_SIZE;
curbufsize -= PAGE_SIZE;
}
#else /* ! UVM */
vm_size_t curbufsize;
vm_offset_t curbuf;
@ -364,24 +423,40 @@ cpu_startup()
curbufsize = CLBYTES * (i < residual ? base+1 : base);
vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
vm_map_simplify(buffer_map, curbuf);
#endif /* UVM */
}
/*
* Allocate a submap for exec arguments. This map effectively
* limits the number of processes exec'ing at any time.
*/
#if defined(UVM)
exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
16 * NCARGS, TRUE, FALSE, NULL);
#else
exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
16 * NCARGS, TRUE);
#endif
/*
* Allocate a submap for physio
*/
#if defined(UVM)
phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
VM_PHYS_SIZE, TRUE, FALSE, NULL);
#else
phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
VM_PHYS_SIZE, TRUE);
#endif
/*
* Finally, allocate mbuf cluster submap.
*/
#if defined(UVM)
mb_map = uvm_km_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
VM_MBUF_SIZE, FALSE, FALSE, NULL);
#else
mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
VM_MBUF_SIZE, FALSE);
#endif
/*
* Initialize callouts
*/
@ -393,7 +468,11 @@ cpu_startup()
#ifdef DEBUG
pmapdebug = opmapdebug;
#endif
#if defined(UVM)
printf("avail mem = %ld\n", ptoa(uvmexp.free));
#else
printf("avail mem = %ld\n", ptoa(cnt.v_free_count));
#endif
printf("using %d buffers containing %d bytes of memory\n",
nbuf, bufpages * CLBYTES);