Home | History | Annotate | Line # | Download | only in uvm
uvm_init.c revision 1.5
      1 /*	$NetBSD: uvm_init.c,v 1.5 1998/02/10 14:12:13 mrg Exp $	*/
      2 
      3 /*
      4  * XXXCDC: "ROUGH DRAFT" QUALITY UVM PRE-RELEASE FILE!
      5  *	   >>>USE AT YOUR OWN RISK, WORK IS NOT FINISHED<<<
      6  */
      7 /*
      8  *
      9  * Copyright (c) 1997 Charles D. Cranor and Washington University.
     10  * All rights reserved.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *      This product includes software developed by Charles D. Cranor and
     23  *      Washington University.
     24  * 4. The name of the author may not be used to endorse or promote products
     25  *    derived from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     28  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     29  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     30  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     32  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     36  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     37  *
     38  * from: Id: uvm_init.c,v 1.1.2.3 1998/02/06 05:15:27 chs Exp
     39  */
     40 
     41 /*
     42  * uvm_init.c: init the vm system.
     43  */
     44 
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 #include <sys/file.h>
     48 #include <sys/filedesc.h>
     49 #include <sys/resourcevar.h>
     50 #include <sys/mman.h>
     51 #include <sys/mount.h>
     52 #include <sys/proc.h>
     53 #include <sys/malloc.h>
     54 #include <sys/vnode.h>
     55 #include <sys/conf.h>
     56 
     57 
     58 #include <vm/vm.h>
     59 #include <vm/vm_page.h>
     60 #include <vm/vm_kern.h>
     61 
     62 #include <sys/syscallargs.h>
     63 
     64 #include <uvm/uvm.h>
     65 
     66 /*
     67  * struct uvm: we store all global vars in this structure to make them
     68  * easier to spot...
     69  */
     70 
     71 struct uvm uvm;		/* decl */
     72 struct uvmexp uvmexp;	/* decl */
     73 
     74 /*
     75  * local prototypes
     76  */
     77 
     78 /*
     79  * uvm_init: init the VM system.   called from kern/init_main.c.
     80  */
     81 
     82 void uvm_init()
     83 
     84 {
     85   vm_offset_t kvm_start, kvm_end;
     86 
     87   /*
     88    * step 0: ensure that the hardware set the page size
     89    */
     90 
     91   if (uvmexp.pagesize == 0) {
     92     panic("uvm_init: page size not set");
     93   }
     94 
     95   /*
     96    * step 1: zero the uvm structure
     97    */
     98 
     99   bzero(&uvm, sizeof(uvm));
    100   averunnable.fscale = FSCALE;
    101 
    102   /*
    103    * step 2: init the page sub-system.  this includes allocating the
    104    * vm_page structures, and setting up all the page queues (and
    105    * locks).  available memory will be put in the "free" queue.
    106    * kvm_start and kvm_end will be set to the area of kernel virtual
    107    * memory which is available for general use.
    108    */
    109 
    110   uvm_page_init(&kvm_start, &kvm_end);
    111 
    112   /*
    113    * step 3: init the map sub-system.  allocates the static pool of
    114    * vm_map_entry structures that are used for "special" kernel maps
    115    * (e.g. kernel_map, kmem_map, etc...).
    116    */
    117 
    118   uvm_map_init();
    119 
    120   /*
    121    * step 4: setup the kernel's virtual memory data structures.  this
    122    * includes setting up the kernel_map/kernel_object and the kmem_map/
    123    * kmem_object.
    124    */
    125 
    126   uvm_km_init(kvm_start, kvm_end);
    127 
    128   /*
    129    * step 5: init the pmap module.   the pmap module is free to allocate
    130    * memory for its private use (e.g. pvlists).
    131    */
    132 
    133   pmap_init();
    134 
    135   /*
    136    * step 6: init the kernel memory allocator.   after this call the
    137    * kernel memory allocator (malloc) can be used.
    138    */
    139 
    140   kmeminit();
    141 
    142   /*
    143    * step 7: init all pagers and the pager_map.
    144    */
    145 
    146   uvm_pager_init();
    147 
    148   /*
    149    * step 8: allocate anons (can add more as we add swap... later)
    150    */
    151 
    152   uvm_anon_init();
    153 
    154   /*
    155    * the VM system is now up!  now that malloc is up we can resize the
    156    * <obj,off> => <page> hash table for general use and enable paging
    157    * of kernel objects.
    158    */
    159 
    160   uvm_page_rehash();
    161   uao_create(VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS, UAO_FLAG_KERNSWAP);
    162 
    163 
    164   /*
    165    * done!
    166    */
    167 
    168   return;
    169 }
    170