1 /* $OpenBSD: uvm_init.c,v 1.30 2012/03/15 17:52:28 ariane Exp $ */ 2 /* $NetBSD: uvm_init.c,v 1.14 2000/06/27 17:29:23 mrg Exp $ */ 3 4 /* 5 * 6 * Copyright (c) 1997 Charles D. Cranor and Washington University. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by Charles D. Cranor and 20 * Washington University. 21 * 4. The name of the author may not be used to endorse or promote products 22 * derived from this software without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * from: Id: uvm_init.c,v 1.1.2.3 1998/02/06 05:15:27 chs Exp 36 */ 37 38 /* 39 * uvm_init.c: init the vm system. 40 */ 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/file.h> 45 #include <sys/filedesc.h> 46 #include <sys/resourcevar.h> 47 #include <sys/mman.h> 48 #include <sys/proc.h> 49 #include <sys/malloc.h> 50 #include <sys/vnode.h> 51 #include <sys/pool.h> 52 53 #include <uvm/uvm.h> 54 #include <uvm/uvm_addr.h> 55 56 /* 57 * struct uvm: we store all global vars in this structure to make them 58 * easier to spot... 59 */ 60 61 struct uvm uvm; /* decl */ 62 struct uvmexp uvmexp; /* decl */ 63 64 /* 65 * local prototypes 66 */ 67 68 /* 69 * uvm_init: init the VM system. called from kern/init_main.c. 70 */ 71 72 void 73 uvm_init(void) 74 { 75 vaddr_t kvm_start, kvm_end; 76 77 /* 78 * step 0: ensure that the hardware set the page size 79 */ 80 81 if (uvmexp.pagesize == 0) { 82 panic("uvm_init: page size not set"); 83 } 84 85 /* 86 * step 1: set up stats. 87 */ 88 averunnable.fscale = FSCALE; 89 90 /* 91 * step 2: init the page sub-system. this includes allocating the 92 * vm_page structures, and setting up all the page queues (and 93 * locks). available memory will be put in the "free" queue. 94 * kvm_start and kvm_end will be set to the area of kernel virtual 95 * memory which is available for general use. 96 */ 97 98 uvm_page_init(&kvm_start, &kvm_end); 99 100 /* 101 * step 3: init the map sub-system. allocates the static pool of 102 * vm_map_entry structures that are used for "special" kernel maps 103 * (e.g. kernel_map, kmem_map, etc...). 104 */ 105 106 uvm_map_init(); 107 108 /* 109 * step 4: setup the kernel's virtual memory data structures. this 110 * includes setting up the kernel_map/kernel_object and the kmem_map/ 111 * kmem_object. 112 */ 113 114 uvm_km_init(kvm_start, kvm_end); 115 116 /* 117 * step 5: init the pmap module. the pmap module is free to allocate 118 * memory for its private use (e.g. pvlists). 119 */ 120 121 pmap_init(); 122 123 /* 124 * step 6: init the kernel memory allocator. after this call the 125 * kernel memory allocator (malloc) can be used. 126 */ 127 128 kmeminit(); 129 130 /* 131 * step 6.5: init the dma allocator, which is backed by pools. 132 */ 133 dma_alloc_init(); 134 135 /* 136 * step 7: init all pagers and the pager_map. 137 */ 138 139 uvm_pager_init(); 140 141 /* 142 * step 8: init anonymous memory system 143 */ 144 145 amap_init(); /* init amap module */ 146 147 /* 148 * step 9: init uvm_km_page allocator memory. 149 */ 150 uvm_km_page_init(); 151 152 /* 153 * the VM system is now up! now that malloc is up we can 154 * enable paging of kernel objects. 155 */ 156 157 uao_create(VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS, 158 UAO_FLAG_KERNSWAP); 159 160 /* 161 * reserve some unmapped space for malloc/pool use after free usage 162 */ 163 #ifdef DEADBEEF0 164 kvm_start = trunc_page(DEADBEEF0) - PAGE_SIZE; 165 if (uvm_map(kernel_map, &kvm_start, 3 * PAGE_SIZE, 166 NULL, UVM_UNKNOWN_OFFSET, 0, UVM_MAPFLAG(UVM_PROT_NONE, 167 UVM_PROT_NONE, UVM_INH_NONE, UVM_ADV_RANDOM, UVM_FLAG_FIXED))) 168 panic("uvm_init: cannot reserve dead beef @0x%x", DEADBEEF0); 169 #endif 170 #ifdef DEADBEEF1 171 kvm_start = trunc_page(DEADBEEF1) - PAGE_SIZE; 172 if (uvm_map(kernel_map, &kvm_start, 3 * PAGE_SIZE, 173 NULL, UVM_UNKNOWN_OFFSET, 0, UVM_MAPFLAG(UVM_PROT_NONE, 174 UVM_PROT_NONE, UVM_INH_NONE, UVM_ADV_RANDOM, UVM_FLAG_FIXED))) 175 panic("uvm_init: cannot reserve dead beef @0x%x", DEADBEEF1); 176 #endif 177 /* 178 * init anonymous memory systems 179 */ 180 uvm_anon_init(); 181 182 #ifndef SMALL_KERNEL 183 /* 184 * Switch kernel and kmem_map over to a best-fit allocator, 185 * instead of walking the tree. 186 */ 187 uvm_map_set_uaddr(kernel_map, &kernel_map->uaddr_any[3], 188 uaddr_bestfit_create(vm_map_min(kernel_map), 189 vm_map_max(kernel_map))); 190 uvm_map_set_uaddr(kmem_map, &kmem_map->uaddr_any[3], 191 uaddr_bestfit_create(vm_map_min(kmem_map), 192 vm_map_max(kmem_map))); 193 #endif /* !SMALL_KERNEL */ 194 } 195