arm32_machdep.c revision 1.6.2.4 1 1.6.2.4 nathanw /* $NetBSD: arm32_machdep.c,v 1.6.2.4 2002/01/11 23:37:59 nathanw Exp $ */
2 1.6.2.2 thorpej
3 1.6.2.2 thorpej /*
4 1.6.2.2 thorpej * Copyright (c) 1994-1998 Mark Brinicombe.
5 1.6.2.2 thorpej * Copyright (c) 1994 Brini.
6 1.6.2.2 thorpej * All rights reserved.
7 1.6.2.2 thorpej *
8 1.6.2.2 thorpej * This code is derived from software written for Brini by Mark Brinicombe
9 1.6.2.2 thorpej *
10 1.6.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.6.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.6.2.2 thorpej * are met:
13 1.6.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.6.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.6.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.6.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.6.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.6.2.2 thorpej * must display the following acknowledgement:
20 1.6.2.2 thorpej * This product includes software developed by Mark Brinicombe
21 1.6.2.2 thorpej * for the NetBSD Project.
22 1.6.2.2 thorpej * 4. The name of the company nor the name of the author may be used to
23 1.6.2.2 thorpej * endorse or promote products derived from this software without specific
24 1.6.2.2 thorpej * prior written permission.
25 1.6.2.2 thorpej *
26 1.6.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 1.6.2.2 thorpej * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 1.6.2.2 thorpej * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 1.6.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 1.6.2.2 thorpej * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 1.6.2.2 thorpej * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 1.6.2.2 thorpej * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.6.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.6.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.6.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.6.2.2 thorpej * SUCH DAMAGE.
37 1.6.2.2 thorpej *
38 1.6.2.2 thorpej * Machine dependant functions for kernel setup
39 1.6.2.2 thorpej *
40 1.6.2.2 thorpej * Created : 17/09/94
41 1.6.2.2 thorpej * Updated : 18/04/01 updated for new wscons
42 1.6.2.2 thorpej */
43 1.6.2.2 thorpej
44 1.6.2.2 thorpej #include "opt_md.h"
45 1.6.2.2 thorpej #include "opt_pmap_debug.h"
46 1.6.2.2 thorpej
47 1.6.2.2 thorpej #include <sys/param.h>
48 1.6.2.2 thorpej #include <sys/systm.h>
49 1.6.2.2 thorpej #include <sys/reboot.h>
50 1.6.2.2 thorpej #include <sys/proc.h>
51 1.6.2.2 thorpej #include <sys/user.h>
52 1.6.2.2 thorpej #include <sys/kernel.h>
53 1.6.2.2 thorpej #include <sys/mbuf.h>
54 1.6.2.2 thorpej #include <sys/mount.h>
55 1.6.2.2 thorpej #include <sys/buf.h>
56 1.6.2.2 thorpej #include <sys/msgbuf.h>
57 1.6.2.2 thorpej #include <sys/device.h>
58 1.6.2.2 thorpej #include <uvm/uvm_extern.h>
59 1.6.2.2 thorpej #include <sys/sysctl.h>
60 1.6.2.2 thorpej
61 1.6.2.2 thorpej #include <dev/cons.h>
62 1.6.2.2 thorpej
63 1.6.2.3 nathanw #include <arm/arm32/katelib.h>
64 1.6.2.4 nathanw #include <arm/arm32/machdep.h>
65 1.6.2.2 thorpej #include <machine/bootconfig.h>
66 1.6.2.2 thorpej
67 1.6.2.2 thorpej #include "opt_ipkdb.h"
68 1.6.2.2 thorpej #include "opt_mdsize.h"
69 1.6.2.2 thorpej #include "md.h"
70 1.6.2.2 thorpej
71 1.6.2.2 thorpej struct vm_map *exec_map = NULL;
72 1.6.2.2 thorpej struct vm_map *mb_map = NULL;
73 1.6.2.2 thorpej struct vm_map *phys_map = NULL;
74 1.6.2.2 thorpej
75 1.6.2.2 thorpej extern int physmem;
76 1.6.2.2 thorpej
77 1.6.2.2 thorpej #ifndef PMAP_STATIC_L1S
78 1.6.2.2 thorpej extern int max_processes;
79 1.6.2.2 thorpej #endif /* !PMAP_STATIC_L1S */
80 1.6.2.2 thorpej #if NMD > 0 && defined(MEMORY_DISK_HOOKS) && !defined(MINIROOTSIZE)
81 1.6.2.2 thorpej extern u_int memory_disc_size; /* Memory disc size */
82 1.6.2.2 thorpej #endif /* NMD && MEMORY_DISK_HOOKS && !MINIROOTSIZE */
83 1.6.2.2 thorpej
84 1.6.2.2 thorpej pv_addr_t systempage;
85 1.6.2.2 thorpej pv_addr_t kernelstack;
86 1.6.2.2 thorpej
87 1.6.2.2 thorpej /* the following is used externally (sysctl_hw) */
88 1.6.2.2 thorpej char machine[] = MACHINE; /* from <machine/param.h> */
89 1.6.2.2 thorpej char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
90 1.6.2.2 thorpej
91 1.6.2.2 thorpej /* Our exported CPU info; we can have only one. */
92 1.6.2.2 thorpej struct cpu_info cpu_info_store;
93 1.6.2.2 thorpej
94 1.6.2.2 thorpej extern pt_entry_t msgbufpte;
95 1.6.2.2 thorpej caddr_t msgbufaddr;
96 1.6.2.2 thorpej extern paddr_t msgbufphys;
97 1.6.2.2 thorpej
98 1.6.2.2 thorpej int kernel_debug = 0;
99 1.6.2.2 thorpej
100 1.6.2.2 thorpej struct user *proc0paddr;
101 1.6.2.2 thorpej
102 1.6.2.2 thorpej char *booted_kernel;
103 1.6.2.2 thorpej
104 1.6.2.2 thorpej
105 1.6.2.2 thorpej /* Prototypes */
106 1.6.2.2 thorpej
107 1.6.2.2 thorpej void map_section __P((vaddr_t pt, vaddr_t va, paddr_t pa,
108 1.6.2.2 thorpej int cacheable));
109 1.6.2.2 thorpej void map_pagetable __P((vaddr_t pt, vaddr_t va, paddr_t pa));
110 1.6.2.2 thorpej void map_entry __P((vaddr_t pt, vaddr_t va, paddr_t pa));
111 1.6.2.2 thorpej void map_entry_nc __P((vaddr_t pt, vaddr_t va, paddr_t pa));
112 1.6.2.2 thorpej void map_entry_ro __P((vaddr_t pt, vaddr_t va, paddr_t pa));
113 1.6.2.2 thorpej
114 1.6.2.2 thorpej u_long strtoul __P((const char *s, char **ptr, int base));
115 1.6.2.2 thorpej void data_abort_handler __P((trapframe_t *frame));
116 1.6.2.2 thorpej void prefetch_abort_handler __P((trapframe_t *frame));
117 1.6.2.2 thorpej void zero_page_readonly __P((void));
118 1.6.2.2 thorpej void zero_page_readwrite __P((void));
119 1.6.2.2 thorpej extern void configure __P((void));
120 1.6.2.2 thorpej
121 1.6.2.2 thorpej /*
122 1.6.2.2 thorpej * Debug function just to park the CPU
123 1.6.2.2 thorpej */
124 1.6.2.2 thorpej
125 1.6.2.2 thorpej void
126 1.6.2.2 thorpej halt()
127 1.6.2.2 thorpej {
128 1.6.2.2 thorpej while (1)
129 1.6.2.2 thorpej cpu_sleep(0);
130 1.6.2.2 thorpej }
131 1.6.2.2 thorpej
132 1.6.2.2 thorpej
133 1.6.2.2 thorpej /* Sync the discs and unmount the filesystems */
134 1.6.2.2 thorpej
135 1.6.2.2 thorpej void
136 1.6.2.2 thorpej bootsync(void)
137 1.6.2.2 thorpej {
138 1.6.2.2 thorpej static int bootsyncdone = 0;
139 1.6.2.2 thorpej
140 1.6.2.2 thorpej if (bootsyncdone) return;
141 1.6.2.2 thorpej
142 1.6.2.2 thorpej bootsyncdone = 1;
143 1.6.2.2 thorpej
144 1.6.2.2 thorpej /* Make sure we can still manage to do things */
145 1.6.2.2 thorpej if (GetCPSR() & I32_bit) {
146 1.6.2.2 thorpej /*
147 1.6.2.2 thorpej * If we get here then boot has been called without RB_NOSYNC
148 1.6.2.2 thorpej * and interrupts were disabled. This means the boot() call
149 1.6.2.2 thorpej * did not come from a user process e.g. shutdown, but must
150 1.6.2.2 thorpej * have come from somewhere in the kernel.
151 1.6.2.2 thorpej */
152 1.6.2.2 thorpej IRQenable;
153 1.6.2.2 thorpej printf("Warning IRQ's disabled during boot()\n");
154 1.6.2.2 thorpej }
155 1.6.2.2 thorpej
156 1.6.2.2 thorpej vfs_shutdown();
157 1.6.2.2 thorpej }
158 1.6.2.2 thorpej
159 1.6.2.2 thorpej /*
160 1.6.2.2 thorpej * A few functions that are used to help construct the page tables
161 1.6.2.2 thorpej * during the bootstrap process.
162 1.6.2.2 thorpej */
163 1.6.2.2 thorpej
164 1.6.2.2 thorpej void
165 1.6.2.2 thorpej map_section(pagetable, va, pa, cacheable)
166 1.6.2.2 thorpej vaddr_t pagetable;
167 1.6.2.2 thorpej vaddr_t va;
168 1.6.2.2 thorpej paddr_t pa;
169 1.6.2.2 thorpej int cacheable;
170 1.6.2.2 thorpej {
171 1.6.2.2 thorpej #ifdef DIAGNOSTIC
172 1.6.2.2 thorpej if (((va | pa) & (L1_SEC_SIZE - 1)) != 0)
173 1.6.2.2 thorpej panic("initarm: Cannot allocate 1MB section on non 1MB boundry\n");
174 1.6.2.2 thorpej #endif /* DIAGNOSTIC */
175 1.6.2.2 thorpej
176 1.6.2.2 thorpej if (cacheable)
177 1.6.2.2 thorpej ((u_int *)pagetable)[(va >> PDSHIFT)] =
178 1.6.2.2 thorpej L1_SEC((pa & PD_MASK), pte_cache_mode);
179 1.6.2.2 thorpej else
180 1.6.2.2 thorpej ((u_int *)pagetable)[(va >> PDSHIFT)] =
181 1.6.2.2 thorpej L1_SEC((pa & PD_MASK), 0);
182 1.6.2.2 thorpej }
183 1.6.2.2 thorpej
184 1.6.2.2 thorpej
185 1.6.2.2 thorpej void
186 1.6.2.2 thorpej map_pagetable(pagetable, va, pa)
187 1.6.2.2 thorpej vaddr_t pagetable;
188 1.6.2.2 thorpej vaddr_t va;
189 1.6.2.2 thorpej paddr_t pa;
190 1.6.2.2 thorpej {
191 1.6.2.2 thorpej #ifdef DIAGNOSTIC
192 1.6.2.2 thorpej if ((pa & 0xc00) != 0)
193 1.6.2.2 thorpej panic("pagetables should be group allocated on pageboundry");
194 1.6.2.2 thorpej #endif /* DIAGNOSTIC */
195 1.6.2.2 thorpej
196 1.6.2.2 thorpej ((u_int *)pagetable)[(va >> PDSHIFT) + 0] =
197 1.6.2.2 thorpej L1_PTE((pa & PG_FRAME) + 0x000);
198 1.6.2.2 thorpej ((u_int *)pagetable)[(va >> PDSHIFT) + 1] =
199 1.6.2.2 thorpej L1_PTE((pa & PG_FRAME) + 0x400);
200 1.6.2.2 thorpej ((u_int *)pagetable)[(va >> PDSHIFT) + 2] =
201 1.6.2.2 thorpej L1_PTE((pa & PG_FRAME) + 0x800);
202 1.6.2.2 thorpej ((u_int *)pagetable)[(va >> PDSHIFT) + 3] =
203 1.6.2.2 thorpej L1_PTE((pa & PG_FRAME) + 0xc00);
204 1.6.2.2 thorpej }
205 1.6.2.2 thorpej
206 1.6.2.2 thorpej vsize_t
207 1.6.2.2 thorpej map_chunk(pd, pt, va, pa, size, acc, flg)
208 1.6.2.2 thorpej vaddr_t pd;
209 1.6.2.2 thorpej vaddr_t pt;
210 1.6.2.2 thorpej vaddr_t va;
211 1.6.2.2 thorpej paddr_t pa;
212 1.6.2.2 thorpej vsize_t size;
213 1.6.2.2 thorpej u_int acc;
214 1.6.2.2 thorpej u_int flg;
215 1.6.2.2 thorpej {
216 1.6.2.2 thorpej pd_entry_t *l1pt = (pd_entry_t *)pd;
217 1.6.2.2 thorpej pt_entry_t *l2pt = (pt_entry_t *)pt;
218 1.6.2.2 thorpej vsize_t remain;
219 1.6.2.2 thorpej u_int loop;
220 1.6.2.2 thorpej
221 1.6.2.2 thorpej remain = (size + (NBPG - 1)) & ~(NBPG - 1);
222 1.6.2.2 thorpej #ifdef VERBOSE_INIT_ARM
223 1.6.2.2 thorpej printf("map_chunk: pa=%lx va=%lx sz=%lx rem=%lx acc=%x flg=%x\n",
224 1.6.2.2 thorpej pa, va, size, remain, acc, flg);
225 1.6.2.2 thorpej printf("map_chunk: ");
226 1.6.2.2 thorpej #endif
227 1.6.2.2 thorpej size = remain;
228 1.6.2.2 thorpej
229 1.6.2.2 thorpej while (remain > 0) {
230 1.6.2.2 thorpej /* Can we do a section mapping ? */
231 1.6.2.2 thorpej if (l1pt && !((pa | va) & (L1_SEC_SIZE - 1))
232 1.6.2.2 thorpej && remain >= L1_SEC_SIZE) {
233 1.6.2.2 thorpej #ifdef VERBOSE_INIT_ARM
234 1.6.2.2 thorpej printf("S");
235 1.6.2.2 thorpej #endif
236 1.6.2.2 thorpej l1pt[(va >> PDSHIFT)] = L1_SECPTE(pa, acc, flg);
237 1.6.2.2 thorpej va += L1_SEC_SIZE;
238 1.6.2.2 thorpej pa += L1_SEC_SIZE;
239 1.6.2.2 thorpej remain -= L1_SEC_SIZE;
240 1.6.2.2 thorpej } else
241 1.6.2.2 thorpej /* Can we do a large page mapping ? */
242 1.6.2.2 thorpej if (!((pa | va) & (L2_LPAGE_SIZE - 1))
243 1.6.2.2 thorpej && (remain >= L2_LPAGE_SIZE)) {
244 1.6.2.2 thorpej #ifdef VERBOSE_INIT_ARM
245 1.6.2.2 thorpej printf("L");
246 1.6.2.2 thorpej #endif
247 1.6.2.2 thorpej for (loop = 0; loop < 16; ++loop)
248 1.6.2.2 thorpej l2pt[((va >> PGSHIFT) & 0x3f0) + loop] =
249 1.6.2.2 thorpej L2_LPTE(pa, acc, flg);
250 1.6.2.2 thorpej va += L2_LPAGE_SIZE;
251 1.6.2.2 thorpej pa += L2_LPAGE_SIZE;
252 1.6.2.2 thorpej remain -= L2_LPAGE_SIZE;
253 1.6.2.2 thorpej } else
254 1.6.2.2 thorpej /* All we can do is a small page mapping */
255 1.6.2.2 thorpej {
256 1.6.2.2 thorpej #ifdef VERBOSE_INIT_ARM
257 1.6.2.2 thorpej printf("P");
258 1.6.2.2 thorpej #endif
259 1.6.2.2 thorpej l2pt[((va >> PGSHIFT) & 0x3ff)] = L2_SPTE(pa, acc, flg);
260 1.6.2.2 thorpej va += NBPG;
261 1.6.2.2 thorpej pa += NBPG;
262 1.6.2.2 thorpej remain -= NBPG;
263 1.6.2.2 thorpej }
264 1.6.2.2 thorpej }
265 1.6.2.2 thorpej #ifdef VERBOSE_INIT_ARM
266 1.6.2.2 thorpej printf("\n");
267 1.6.2.2 thorpej #endif
268 1.6.2.2 thorpej return(size);
269 1.6.2.2 thorpej }
270 1.6.2.2 thorpej
271 1.6.2.2 thorpej
272 1.6.2.2 thorpej void
273 1.6.2.2 thorpej map_entry(pagetable, va, pa)
274 1.6.2.2 thorpej vaddr_t pagetable;
275 1.6.2.2 thorpej vaddr_t va;
276 1.6.2.2 thorpej paddr_t pa;
277 1.6.2.2 thorpej {
278 1.6.2.2 thorpej ((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000003ff)] =
279 1.6.2.2 thorpej L2_PTE((pa & PG_FRAME), AP_KRW);
280 1.6.2.2 thorpej }
281 1.6.2.2 thorpej
282 1.6.2.2 thorpej
283 1.6.2.2 thorpej void
284 1.6.2.2 thorpej map_entry_nc(pagetable, va, pa)
285 1.6.2.2 thorpej vaddr_t pagetable;
286 1.6.2.2 thorpej vaddr_t va;
287 1.6.2.2 thorpej paddr_t pa;
288 1.6.2.2 thorpej {
289 1.6.2.2 thorpej ((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000003ff)] =
290 1.6.2.2 thorpej L2_PTE_NC_NB((pa & PG_FRAME), AP_KRW);
291 1.6.2.2 thorpej }
292 1.6.2.2 thorpej
293 1.6.2.2 thorpej
294 1.6.2.2 thorpej void
295 1.6.2.2 thorpej map_entry_ro(pagetable, va, pa)
296 1.6.2.2 thorpej vaddr_t pagetable;
297 1.6.2.2 thorpej vaddr_t va;
298 1.6.2.2 thorpej paddr_t pa;
299 1.6.2.2 thorpej {
300 1.6.2.2 thorpej ((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000003ff)] =
301 1.6.2.2 thorpej L2_PTE((pa & PG_FRAME), AP_KR);
302 1.6.2.2 thorpej }
303 1.6.2.2 thorpej
304 1.6.2.2 thorpej
305 1.6.2.2 thorpej /*
306 1.6.2.2 thorpej * void cpu_startup(void)
307 1.6.2.2 thorpej *
308 1.6.2.2 thorpej * Machine dependant startup code.
309 1.6.2.2 thorpej *
310 1.6.2.2 thorpej */
311 1.6.2.2 thorpej
312 1.6.2.2 thorpej void
313 1.6.2.2 thorpej cpu_startup()
314 1.6.2.2 thorpej {
315 1.6.2.2 thorpej int loop;
316 1.6.2.2 thorpej paddr_t minaddr;
317 1.6.2.2 thorpej paddr_t maxaddr;
318 1.6.2.2 thorpej caddr_t sysbase;
319 1.6.2.2 thorpej caddr_t size;
320 1.6.2.2 thorpej vsize_t bufsize;
321 1.6.2.2 thorpej int base, residual;
322 1.6.2.2 thorpej char pbuf[9];
323 1.6.2.2 thorpej
324 1.6.2.2 thorpej proc0paddr = (struct user *)kernelstack.pv_va;
325 1.6.2.2 thorpej lwp0.l_addr = proc0paddr;
326 1.6.2.2 thorpej
327 1.6.2.2 thorpej /* Set the cpu control register */
328 1.6.2.2 thorpej cpu_setup(boot_args);
329 1.6.2.2 thorpej
330 1.6.2.2 thorpej /* All domains MUST be clients, permissions are VERY important */
331 1.6.2.2 thorpej cpu_domains(DOMAIN_CLIENT);
332 1.6.2.2 thorpej
333 1.6.2.2 thorpej /* Lock down zero page */
334 1.6.2.2 thorpej zero_page_readonly();
335 1.6.2.2 thorpej
336 1.6.2.2 thorpej /*
337 1.6.2.2 thorpej * Give pmap a chance to set up a few more things now the vm
338 1.6.2.2 thorpej * is initialised
339 1.6.2.2 thorpej */
340 1.6.2.2 thorpej pmap_postinit();
341 1.6.2.2 thorpej
342 1.6.2.2 thorpej /*
343 1.6.2.2 thorpej * Initialize error message buffer (at end of core).
344 1.6.2.2 thorpej */
345 1.6.2.2 thorpej
346 1.6.2.2 thorpej /* msgbufphys was setup during the secondary boot strap */
347 1.6.2.2 thorpej for (loop = 0; loop < btoc(MSGBUFSIZE); ++loop)
348 1.6.2.2 thorpej pmap_kenter_pa((vaddr_t)msgbufaddr + loop * NBPG,
349 1.6.2.2 thorpej msgbufphys + loop * NBPG, VM_PROT_READ|VM_PROT_WRITE);
350 1.6.2.2 thorpej pmap_update(pmap_kernel());
351 1.6.2.2 thorpej initmsgbuf(msgbufaddr, round_page(MSGBUFSIZE));
352 1.6.2.2 thorpej
353 1.6.2.2 thorpej /*
354 1.6.2.2 thorpej * Identify ourselves for the msgbuf (everything printed earlier will
355 1.6.2.2 thorpej * not be buffered).
356 1.6.2.2 thorpej */
357 1.6.2.2 thorpej printf(version);
358 1.6.2.2 thorpej
359 1.6.2.2 thorpej format_bytes(pbuf, sizeof(pbuf), arm_page_to_byte(physmem));
360 1.6.2.2 thorpej printf("total memory = %s\n", pbuf);
361 1.6.2.2 thorpej
362 1.6.2.2 thorpej /*
363 1.6.2.2 thorpej * Find out how much space we need, allocate it,
364 1.6.2.2 thorpej * and then give everything true virtual addresses.
365 1.6.2.2 thorpej */
366 1.6.2.2 thorpej size = allocsys(NULL, NULL);
367 1.6.2.2 thorpej sysbase = (caddr_t)uvm_km_zalloc(kernel_map, round_page((vaddr_t)size));
368 1.6.2.2 thorpej if (sysbase == 0)
369 1.6.2.2 thorpej panic(
370 1.6.2.2 thorpej "cpu_startup: no room for system tables; %d bytes required",
371 1.6.2.2 thorpej (u_int)size);
372 1.6.2.2 thorpej if ((caddr_t)((allocsys(sysbase, NULL) - sysbase)) != size)
373 1.6.2.2 thorpej panic("cpu_startup: system table size inconsistency");
374 1.6.2.2 thorpej
375 1.6.2.2 thorpej /*
376 1.6.2.2 thorpej * Now allocate buffers proper. They are different than the above
377 1.6.2.2 thorpej * in that they usually occupy more virtual memory than physical.
378 1.6.2.2 thorpej */
379 1.6.2.2 thorpej bufsize = MAXBSIZE * nbuf;
380 1.6.2.2 thorpej if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(bufsize),
381 1.6.2.2 thorpej NULL, UVM_UNKNOWN_OFFSET, 0,
382 1.6.2.2 thorpej UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
383 1.6.2.2 thorpej UVM_ADV_NORMAL, 0)) != 0)
384 1.6.2.2 thorpej panic("cpu_startup: cannot allocate UVM space for buffers");
385 1.6.2.2 thorpej minaddr = (vaddr_t)buffers;
386 1.6.2.2 thorpej if ((bufpages / nbuf) >= btoc(MAXBSIZE)) {
387 1.6.2.2 thorpej /* don't want to alloc more physical mem than needed */
388 1.6.2.2 thorpej bufpages = btoc(MAXBSIZE) * nbuf;
389 1.6.2.2 thorpej }
390 1.6.2.2 thorpej
391 1.6.2.2 thorpej base = bufpages / nbuf;
392 1.6.2.2 thorpej residual = bufpages % nbuf;
393 1.6.2.2 thorpej for (loop = 0; loop < nbuf; ++loop) {
394 1.6.2.2 thorpej vsize_t curbufsize;
395 1.6.2.2 thorpej vaddr_t curbuf;
396 1.6.2.2 thorpej struct vm_page *pg;
397 1.6.2.2 thorpej
398 1.6.2.2 thorpej /*
399 1.6.2.2 thorpej * Each buffer has MAXBSIZE bytes of VM space allocated. Of
400 1.6.2.2 thorpej * that MAXBSIZE space, we allocate and map (base+1) pages
401 1.6.2.2 thorpej * for the first "residual" buffers, and then we allocate
402 1.6.2.2 thorpej * "base" pages for the rest.
403 1.6.2.2 thorpej */
404 1.6.2.2 thorpej curbuf = (vaddr_t) buffers + (loop * MAXBSIZE);
405 1.6.2.2 thorpej curbufsize = NBPG * ((loop < residual) ? (base+1) : base);
406 1.6.2.2 thorpej
407 1.6.2.2 thorpej while (curbufsize) {
408 1.6.2.2 thorpej pg = uvm_pagealloc(NULL, 0, NULL, 0);
409 1.6.2.2 thorpej if (pg == NULL)
410 1.6.2.2 thorpej panic("cpu_startup: not enough memory for buffer cache");
411 1.6.2.2 thorpej pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg),
412 1.6.2.2 thorpej VM_PROT_READ|VM_PROT_WRITE);
413 1.6.2.2 thorpej curbuf += PAGE_SIZE;
414 1.6.2.2 thorpej curbufsize -= PAGE_SIZE;
415 1.6.2.2 thorpej }
416 1.6.2.2 thorpej }
417 1.6.2.2 thorpej pmap_update(pmap_kernel());
418 1.6.2.2 thorpej
419 1.6.2.2 thorpej /*
420 1.6.2.2 thorpej * Allocate a submap for exec arguments. This map effectively
421 1.6.2.2 thorpej * limits the number of processes exec'ing at any time.
422 1.6.2.2 thorpej */
423 1.6.2.2 thorpej exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
424 1.6.2.2 thorpej 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
425 1.6.2.2 thorpej
426 1.6.2.2 thorpej /*
427 1.6.2.2 thorpej * Allocate a submap for physio
428 1.6.2.2 thorpej */
429 1.6.2.2 thorpej phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
430 1.6.2.2 thorpej VM_PHYS_SIZE, 0, FALSE, NULL);
431 1.6.2.2 thorpej
432 1.6.2.2 thorpej /*
433 1.6.2.2 thorpej * Finally, allocate mbuf cluster submap.
434 1.6.2.2 thorpej */
435 1.6.2.2 thorpej mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
436 1.6.2.2 thorpej nmbclusters * mclbytes, VM_MAP_INTRSAFE,
437 1.6.2.2 thorpej FALSE, NULL);
438 1.6.2.2 thorpej
439 1.6.2.2 thorpej format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
440 1.6.2.2 thorpej printf("avail memory = %s\n", pbuf);
441 1.6.2.2 thorpej format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
442 1.6.2.2 thorpej printf("using %d buffers containing %s of memory\n", nbuf, pbuf);
443 1.6.2.2 thorpej
444 1.6.2.2 thorpej /*
445 1.6.2.2 thorpej * Set up buffers, so they can be used to read disk labels.
446 1.6.2.2 thorpej */
447 1.6.2.2 thorpej bufinit();
448 1.6.2.2 thorpej
449 1.6.2.2 thorpej curpcb = &lwp0.l_addr->u_pcb;
450 1.6.2.2 thorpej curpcb->pcb_flags = 0;
451 1.6.2.2 thorpej curpcb->pcb_un.un_32.pcb32_und_sp = (u_int)lwp0.l_addr +
452 1.6.2.2 thorpej USPACE_UNDEF_STACK_TOP;
453 1.6.2.2 thorpej curpcb->pcb_un.un_32.pcb32_sp = (u_int)lwp0.l_addr +
454 1.6.2.2 thorpej USPACE_SVC_STACK_TOP;
455 1.6.2.2 thorpej (void) pmap_extract(pmap_kernel(), (vaddr_t)(pmap_kernel())->pm_pdir,
456 1.6.2.2 thorpej (paddr_t *)&curpcb->pcb_pagedir);
457 1.6.2.2 thorpej
458 1.6.2.2 thorpej curpcb->pcb_tf = (struct trapframe *)curpcb->pcb_un.un_32.pcb32_sp - 1;
459 1.6.2.2 thorpej }
460 1.6.2.2 thorpej
461 1.6.2.2 thorpej /*
462 1.6.2.2 thorpej * Modify the current mapping for zero page to make it read only
463 1.6.2.2 thorpej *
464 1.6.2.2 thorpej * This routine is only used until things start forking. Then new
465 1.6.2.2 thorpej * system pages are mapped read only in pmap_enter().
466 1.6.2.2 thorpej */
467 1.6.2.2 thorpej
468 1.6.2.2 thorpej void
469 1.6.2.2 thorpej zero_page_readonly()
470 1.6.2.2 thorpej {
471 1.6.2.2 thorpej WriteWord(PROCESS_PAGE_TBLS_BASE + 0,
472 1.6.2.2 thorpej L2_PTE((systempage.pv_pa & PG_FRAME), AP_KR));
473 1.6.2.2 thorpej cpu_tlb_flushID_SE(0x00000000);
474 1.6.2.2 thorpej }
475 1.6.2.2 thorpej
476 1.6.2.2 thorpej
477 1.6.2.2 thorpej /*
478 1.6.2.2 thorpej * Modify the current mapping for zero page to make it read/write
479 1.6.2.2 thorpej *
480 1.6.2.2 thorpej * This routine is only used until things start forking. Then system
481 1.6.2.2 thorpej * pages belonging to user processes are never made writable.
482 1.6.2.2 thorpej */
483 1.6.2.2 thorpej
484 1.6.2.2 thorpej void
485 1.6.2.2 thorpej zero_page_readwrite()
486 1.6.2.2 thorpej {
487 1.6.2.2 thorpej WriteWord(PROCESS_PAGE_TBLS_BASE + 0,
488 1.6.2.2 thorpej L2_PTE((systempage.pv_pa & PG_FRAME), AP_KRW));
489 1.6.2.2 thorpej cpu_tlb_flushID_SE(0x00000000);
490 1.6.2.2 thorpej }
491 1.6.2.2 thorpej
492 1.6.2.2 thorpej
493 1.6.2.2 thorpej /*
494 1.6.2.2 thorpej * machine dependent system variables.
495 1.6.2.2 thorpej */
496 1.6.2.2 thorpej
497 1.6.2.2 thorpej int
498 1.6.2.2 thorpej cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
499 1.6.2.2 thorpej int *name;
500 1.6.2.2 thorpej u_int namelen;
501 1.6.2.2 thorpej void *oldp;
502 1.6.2.2 thorpej size_t *oldlenp;
503 1.6.2.2 thorpej void *newp;
504 1.6.2.2 thorpej size_t newlen;
505 1.6.2.2 thorpej struct proc *p;
506 1.6.2.2 thorpej {
507 1.6.2.2 thorpej /* all sysctl names at this level are terminal */
508 1.6.2.2 thorpej if (namelen != 1)
509 1.6.2.2 thorpej return (ENOTDIR); /* overloaded */
510 1.6.2.2 thorpej
511 1.6.2.2 thorpej switch (name[0]) {
512 1.6.2.2 thorpej case CPU_DEBUG:
513 1.6.2.2 thorpej return(sysctl_int(oldp, oldlenp, newp, newlen, &kernel_debug));
514 1.6.2.2 thorpej
515 1.6.2.2 thorpej case CPU_BOOTED_DEVICE:
516 1.6.2.2 thorpej if (booted_device != NULL)
517 1.6.2.2 thorpej return (sysctl_rdstring(oldp, oldlenp, newp,
518 1.6.2.2 thorpej booted_device->dv_xname));
519 1.6.2.2 thorpej return (EOPNOTSUPP);
520 1.6.2.2 thorpej
521 1.6.2.2 thorpej case CPU_CONSDEV: {
522 1.6.2.2 thorpej dev_t consdev;
523 1.6.2.2 thorpej if (cn_tab != NULL)
524 1.6.2.2 thorpej consdev = cn_tab->cn_dev;
525 1.6.2.2 thorpej else
526 1.6.2.2 thorpej consdev = NODEV;
527 1.6.2.2 thorpej return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
528 1.6.2.2 thorpej sizeof consdev));
529 1.6.2.2 thorpej }
530 1.6.2.2 thorpej case CPU_BOOTED_KERNEL: {
531 1.6.2.2 thorpej if (booted_kernel != NULL && booted_kernel[0] != '\0')
532 1.6.2.2 thorpej return sysctl_rdstring(oldp, oldlenp, newp,
533 1.6.2.2 thorpej booted_kernel);
534 1.6.2.2 thorpej return (EOPNOTSUPP);
535 1.6.2.2 thorpej }
536 1.6.2.2 thorpej
537 1.6.2.2 thorpej default:
538 1.6.2.2 thorpej return (EOPNOTSUPP);
539 1.6.2.2 thorpej }
540 1.6.2.2 thorpej /* NOTREACHED */
541 1.6.2.2 thorpej }
542 1.6.2.2 thorpej
543 1.6.2.2 thorpej void
544 1.6.2.2 thorpej parse_mi_bootargs(args)
545 1.6.2.2 thorpej char *args;
546 1.6.2.2 thorpej {
547 1.6.2.2 thorpej int integer;
548 1.6.2.2 thorpej
549 1.6.2.2 thorpej if (get_bootconf_option(args, "single", BOOTOPT_TYPE_BOOLEAN, &integer)
550 1.6.2.2 thorpej || get_bootconf_option(args, "-s", BOOTOPT_TYPE_BOOLEAN, &integer))
551 1.6.2.2 thorpej if (integer)
552 1.6.2.2 thorpej boothowto |= RB_SINGLE;
553 1.6.2.2 thorpej if (get_bootconf_option(args, "kdb", BOOTOPT_TYPE_BOOLEAN, &integer)
554 1.6.2.2 thorpej || get_bootconf_option(args, "-k", BOOTOPT_TYPE_BOOLEAN, &integer))
555 1.6.2.2 thorpej if (integer)
556 1.6.2.2 thorpej boothowto |= RB_KDB;
557 1.6.2.2 thorpej if (get_bootconf_option(args, "ask", BOOTOPT_TYPE_BOOLEAN, &integer)
558 1.6.2.2 thorpej || get_bootconf_option(args, "-a", BOOTOPT_TYPE_BOOLEAN, &integer))
559 1.6.2.2 thorpej if (integer)
560 1.6.2.2 thorpej boothowto |= RB_ASKNAME;
561 1.6.2.2 thorpej
562 1.6.2.2 thorpej #ifdef PMAP_DEBUG
563 1.6.2.2 thorpej if (get_bootconf_option(args, "pmapdebug", BOOTOPT_TYPE_INT, &integer)) {
564 1.6.2.2 thorpej pmap_debug_level = integer;
565 1.6.2.2 thorpej pmap_debug(pmap_debug_level);
566 1.6.2.2 thorpej }
567 1.6.2.2 thorpej #endif /* PMAP_DEBUG */
568 1.6.2.2 thorpej
569 1.6.2.2 thorpej /* if (get_bootconf_option(args, "nbuf", BOOTOPT_TYPE_INT, &integer))
570 1.6.2.2 thorpej bufpages = integer;*/
571 1.6.2.2 thorpej
572 1.6.2.2 thorpej #ifndef PMAP_STATIC_L1S
573 1.6.2.2 thorpej if (get_bootconf_option(args, "maxproc", BOOTOPT_TYPE_INT, &integer)) {
574 1.6.2.2 thorpej max_processes = integer;
575 1.6.2.2 thorpej if (max_processes < 16)
576 1.6.2.2 thorpej max_processes = 16;
577 1.6.2.2 thorpej /* Limit is PDSIZE * (max_processes + 1) <= 4MB */
578 1.6.2.2 thorpej if (max_processes > 255)
579 1.6.2.2 thorpej max_processes = 255;
580 1.6.2.2 thorpej }
581 1.6.2.2 thorpej #endif /* !PMAP_STATUC_L1S */
582 1.6.2.2 thorpej #if NMD > 0 && defined(MEMORY_DISK_HOOKS) && !defined(MINIROOTSIZE)
583 1.6.2.2 thorpej if (get_bootconf_option(args, "memorydisc", BOOTOPT_TYPE_INT, &integer)
584 1.6.2.2 thorpej || get_bootconf_option(args, "memorydisk", BOOTOPT_TYPE_INT, &integer)) {
585 1.6.2.2 thorpej memory_disc_size = integer;
586 1.6.2.2 thorpej memory_disc_size *= 1024;
587 1.6.2.2 thorpej if (memory_disc_size < 32*1024)
588 1.6.2.2 thorpej memory_disc_size = 32*1024;
589 1.6.2.2 thorpej if (memory_disc_size > 2048*1024)
590 1.6.2.2 thorpej memory_disc_size = 2048*1024;
591 1.6.2.2 thorpej }
592 1.6.2.2 thorpej #endif /* NMD && MEMORY_DISK_HOOKS && !MINIROOTSIZE */
593 1.6.2.2 thorpej
594 1.6.2.2 thorpej if (get_bootconf_option(args, "quiet", BOOTOPT_TYPE_BOOLEAN, &integer)
595 1.6.2.2 thorpej || get_bootconf_option(args, "-q", BOOTOPT_TYPE_BOOLEAN, &integer))
596 1.6.2.2 thorpej if (integer)
597 1.6.2.2 thorpej boothowto |= AB_QUIET;
598 1.6.2.2 thorpej if (get_bootconf_option(args, "verbose", BOOTOPT_TYPE_BOOLEAN, &integer)
599 1.6.2.2 thorpej || get_bootconf_option(args, "-v", BOOTOPT_TYPE_BOOLEAN, &integer))
600 1.6.2.2 thorpej if (integer)
601 1.6.2.2 thorpej boothowto |= AB_VERBOSE;
602 1.6.2.2 thorpej }
603 1.6.2.2 thorpej
604 1.6.2.2 thorpej /* End of machdep.c */
605