xref: /netbsd-src/sys/uvm/uvm_init.c (revision dc306354b0b29af51801a7632f1e95265a68cd81)
1 /*	$NetBSD: uvm_init.c,v 1.9 1998/08/13 02:11:00 eeh 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/proc.h>
52 #include <sys/malloc.h>
53 #include <sys/vnode.h>
54 #include <sys/conf.h>
55 
56 
57 #include <vm/vm.h>
58 #include <vm/vm_page.h>
59 #include <vm/vm_kern.h>
60 
61 #include <uvm/uvm.h>
62 
63 /*
64  * struct uvm: we store all global vars in this structure to make them
65  * easier to spot...
66  */
67 
68 struct uvm uvm;		/* decl */
69 struct uvmexp uvmexp;	/* decl */
70 
71 /*
72  * local prototypes
73  */
74 
75 /*
76  * uvm_init: init the VM system.   called from kern/init_main.c.
77  */
78 
79 void
80 uvm_init()
81 {
82 	vaddr_t kvm_start, kvm_end;
83 
84 	/*
85 	 * step 0: ensure that the hardware set the page size
86 	 */
87 
88 	if (uvmexp.pagesize == 0) {
89 		panic("uvm_init: page size not set");
90 	}
91 
92 	/*
93 	 * step 1: zero the uvm structure
94 	 */
95 
96 	memset(&uvm, 0, sizeof(uvm));
97 	averunnable.fscale = FSCALE;
98 
99 	/*
100 	 * step 2: init the page sub-system.  this includes allocating the
101 	 * vm_page structures, and setting up all the page queues (and
102 	 * locks).  available memory will be put in the "free" queue.
103 	 * kvm_start and kvm_end will be set to the area of kernel virtual
104 	 * memory which is available for general use.
105 	 */
106 
107 	uvm_page_init(&kvm_start, &kvm_end);
108 
109 	/*
110 	 * step 3: init the map sub-system.  allocates the static pool of
111 	 * vm_map_entry structures that are used for "special" kernel maps
112 	 * (e.g. kernel_map, kmem_map, etc...).
113 	 */
114 
115 	uvm_map_init();
116 
117 	/*
118 	 * step 4: setup the kernel's virtual memory data structures.  this
119 	 * includes setting up the kernel_map/kernel_object and the kmem_map/
120 	 * kmem_object.
121 	 */
122 
123 	uvm_km_init(kvm_start, kvm_end);
124 
125 	/*
126 	 * step 5: init the pmap module.   the pmap module is free to allocate
127 	 * memory for its private use (e.g. pvlists).
128 	 */
129 
130 	pmap_init();
131 
132 	/*
133 	 * step 6: init the kernel memory allocator.   after this call the
134 	 * kernel memory allocator (malloc) can be used.
135 	 */
136 
137 	kmeminit();
138 
139 	/*
140 	 * step 7: init all pagers and the pager_map.
141 	 */
142 
143 	uvm_pager_init();
144 
145 	/*
146 	 * step 8: allocate anons (can add more as we add swap... later)
147 	 */
148 
149 	uvm_anon_init();
150 
151 	/*
152 	 * the VM system is now up!  now that malloc is up we can resize the
153 	 * <obj,off> => <page> hash table for general use and enable paging
154 	 * of kernel objects.
155 	 */
156 
157 	uvm_page_rehash();
158 	uao_create(VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS,
159 	    UAO_FLAG_KERNSWAP);
160 
161 	/*
162 	 * done!
163 	 */
164 
165 	return;
166 }
167