Home | History | Annotate | Line # | Download | only in uvm
uvm_init.c revision 1.4
      1 /*	$NetBSD: uvm_init.c,v 1.4 1998/02/07 11:08:38 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 UVMHIST_DECL(maphist);
     75 
     76 /*
     77  * local prototypes
     78  */
     79 
     80 /*
     81  * uvm_init: init the VM system.   called from kern/init_main.c.
     82  */
     83 
     84 void uvm_init()
     85 
     86 {
     87   vm_offset_t kvm_start, kvm_end;
     88 
     89   /*
     90    * step 0: ensure that the hardware set the page size
     91    */
     92 
     93   if (uvmexp.pagesize == 0) {
     94     panic("uvm_init: page size not set");
     95   }
     96 
     97   /*
     98    * step 1: zero the uvm structure
     99    */
    100 
    101   bzero(&uvm, sizeof(uvm));
    102   averunnable.fscale = FSCALE;
    103 
    104   /*
    105    * step 2: init the page sub-system.  this includes allocating the
    106    * vm_page structures, and setting up all the page queues (and
    107    * locks).  available memory will be put in the "free" queue.
    108    * kvm_start and kvm_end will be set to the area of kernel virtual
    109    * memory which is available for general use.
    110    */
    111 
    112   uvm_page_init(&kvm_start, &kvm_end);
    113 
    114   /*
    115    * step 3: init the map sub-system.  allocates the static pool of
    116    * vm_map_entry structures that are used for "special" kernel maps
    117    * (e.g. kernel_map, kmem_map, etc...).
    118    */
    119 
    120   uvm_map_init();
    121 
    122   /*
    123    * step 4: setup the kernel's virtual memory data structures.  this
    124    * includes setting up the kernel_map/kernel_object and the kmem_map/
    125    * kmem_object.
    126    */
    127 
    128   uvm_km_init(kvm_start, kvm_end);
    129 
    130   /*
    131    * step 5: init the pmap module.   the pmap module is free to allocate
    132    * memory for its private use (e.g. pvlists).
    133    */
    134 
    135   pmap_init();
    136 
    137   /*
    138    * step 6: init the kernel memory allocator.   after this call the
    139    * kernel memory allocator (malloc) can be used.
    140    */
    141 
    142   kmeminit();
    143 
    144   /*
    145    * step 7: init all pagers and the pager_map.
    146    */
    147 
    148   uvm_pager_init();
    149 
    150   /*
    151    * step 8: allocate anons (can add more as we add swap... later)
    152    */
    153 
    154   uvm_anon_init();
    155 
    156   /*
    157    * the VM system is now up!  now that malloc is up we can resize the
    158    * <obj,off> => <page> hash table for general use and enable paging
    159    * of kernel objects.
    160    */
    161 
    162   uvm_page_rehash();
    163   uao_create(VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS, UAO_FLAG_KERNSWAP);
    164 
    165 
    166   /*
    167    * done!
    168    */
    169 
    170   return;
    171 }
    172