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