arm32_machdep.c revision 1.44 1 1.44 atatat /* $NetBSD: arm32_machdep.c,v 1.44 2004/03/24 15:34:47 atatat Exp $ */
2 1.1 chris
3 1.1 chris /*
4 1.1 chris * Copyright (c) 1994-1998 Mark Brinicombe.
5 1.1 chris * Copyright (c) 1994 Brini.
6 1.1 chris * All rights reserved.
7 1.1 chris *
8 1.1 chris * This code is derived from software written for Brini by Mark Brinicombe
9 1.1 chris *
10 1.1 chris * Redistribution and use in source and binary forms, with or without
11 1.1 chris * modification, are permitted provided that the following conditions
12 1.1 chris * are met:
13 1.1 chris * 1. Redistributions of source code must retain the above copyright
14 1.1 chris * notice, this list of conditions and the following disclaimer.
15 1.1 chris * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 chris * notice, this list of conditions and the following disclaimer in the
17 1.1 chris * documentation and/or other materials provided with the distribution.
18 1.1 chris * 3. All advertising materials mentioning features or use of this software
19 1.1 chris * must display the following acknowledgement:
20 1.1 chris * This product includes software developed by Mark Brinicombe
21 1.1 chris * for the NetBSD Project.
22 1.1 chris * 4. The name of the company nor the name of the author may be used to
23 1.1 chris * endorse or promote products derived from this software without specific
24 1.1 chris * prior written permission.
25 1.1 chris *
26 1.1 chris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 1.1 chris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 1.1 chris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 1.1 chris * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 1.1 chris * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 1.1 chris * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 1.1 chris * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 chris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 chris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 chris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 chris * SUCH DAMAGE.
37 1.1 chris *
38 1.1 chris * Machine dependant functions for kernel setup
39 1.1 chris *
40 1.1 chris * Created : 17/09/94
41 1.1 chris * Updated : 18/04/01 updated for new wscons
42 1.1 chris */
43 1.37 lukem
44 1.37 lukem #include <sys/cdefs.h>
45 1.44 atatat __KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.44 2004/03/24 15:34:47 atatat Exp $");
46 1.1 chris
47 1.1 chris #include "opt_md.h"
48 1.1 chris #include "opt_pmap_debug.h"
49 1.1 chris
50 1.1 chris #include <sys/param.h>
51 1.1 chris #include <sys/systm.h>
52 1.1 chris #include <sys/reboot.h>
53 1.1 chris #include <sys/proc.h>
54 1.1 chris #include <sys/user.h>
55 1.1 chris #include <sys/kernel.h>
56 1.1 chris #include <sys/mbuf.h>
57 1.1 chris #include <sys/mount.h>
58 1.1 chris #include <sys/buf.h>
59 1.1 chris #include <sys/msgbuf.h>
60 1.1 chris #include <sys/device.h>
61 1.1 chris #include <uvm/uvm_extern.h>
62 1.1 chris #include <sys/sysctl.h>
63 1.1 chris
64 1.1 chris #include <dev/cons.h>
65 1.1 chris
66 1.7 thorpej #include <arm/arm32/katelib.h>
67 1.9 chris #include <arm/arm32/machdep.h>
68 1.1 chris #include <machine/bootconfig.h>
69 1.1 chris
70 1.1 chris #include "opt_ipkdb.h"
71 1.1 chris #include "md.h"
72 1.1 chris
73 1.1 chris struct vm_map *exec_map = NULL;
74 1.1 chris struct vm_map *mb_map = NULL;
75 1.1 chris struct vm_map *phys_map = NULL;
76 1.1 chris
77 1.1 chris extern int physmem;
78 1.1 chris
79 1.21 lukem #if NMD > 0 && defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
80 1.24 jdolecek extern size_t md_root_size; /* Memory disc size */
81 1.21 lukem #endif /* NMD && MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
82 1.1 chris
83 1.1 chris pv_addr_t kernelstack;
84 1.1 chris
85 1.1 chris /* the following is used externally (sysctl_hw) */
86 1.1 chris char machine[] = MACHINE; /* from <machine/param.h> */
87 1.1 chris char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
88 1.1 chris
89 1.1 chris /* Our exported CPU info; we can have only one. */
90 1.1 chris struct cpu_info cpu_info_store;
91 1.1 chris
92 1.1 chris caddr_t msgbufaddr;
93 1.1 chris extern paddr_t msgbufphys;
94 1.1 chris
95 1.1 chris int kernel_debug = 0;
96 1.1 chris
97 1.1 chris struct user *proc0paddr;
98 1.1 chris
99 1.12 reinoud /* exported variable to be filled in by the bootloaders */
100 1.1 chris char *booted_kernel;
101 1.1 chris
102 1.1 chris
103 1.1 chris /* Prototypes */
104 1.1 chris
105 1.1 chris void data_abort_handler __P((trapframe_t *frame));
106 1.1 chris void prefetch_abort_handler __P((trapframe_t *frame));
107 1.1 chris extern void configure __P((void));
108 1.1 chris
109 1.1 chris /*
110 1.22 thorpej * arm32_vector_init:
111 1.22 thorpej *
112 1.22 thorpej * Initialize the vector page, and select whether or not to
113 1.22 thorpej * relocate the vectors.
114 1.22 thorpej *
115 1.22 thorpej * NOTE: We expect the vector page to be mapped at its expected
116 1.22 thorpej * destination.
117 1.22 thorpej */
118 1.22 thorpej void
119 1.22 thorpej arm32_vector_init(vaddr_t va, int which)
120 1.22 thorpej {
121 1.22 thorpej extern unsigned int page0[], page0_data[];
122 1.22 thorpej unsigned int *vectors = (int *) va;
123 1.22 thorpej unsigned int *vectors_data = vectors + (page0_data - page0);
124 1.22 thorpej int vec;
125 1.22 thorpej
126 1.22 thorpej /*
127 1.22 thorpej * Loop through the vectors we're taking over, and copy the
128 1.22 thorpej * vector's insn and data word.
129 1.22 thorpej */
130 1.22 thorpej for (vec = 0; vec < ARM_NVEC; vec++) {
131 1.22 thorpej if ((which & (1 << vec)) == 0) {
132 1.22 thorpej /* Don't want to take over this vector. */
133 1.22 thorpej continue;
134 1.22 thorpej }
135 1.22 thorpej vectors[vec] = page0[vec];
136 1.22 thorpej vectors_data[vec] = page0_data[vec];
137 1.22 thorpej }
138 1.22 thorpej
139 1.22 thorpej /* Now sync the vectors. */
140 1.22 thorpej cpu_icache_sync_range(va, (ARM_NVEC * 2) * sizeof(u_int));
141 1.22 thorpej
142 1.22 thorpej vector_page = va;
143 1.30 scw
144 1.30 scw if (va == ARM_VECTORS_HIGH) {
145 1.30 scw /*
146 1.30 scw * Assume the MD caller knows what it's doing here, and
147 1.30 scw * really does want the vector page relocated.
148 1.30 scw *
149 1.30 scw * Note: This has to be done here (and not just in
150 1.30 scw * cpu_setup()) because the vector page needs to be
151 1.30 scw * accessible *before* cpu_startup() is called.
152 1.30 scw * Think ddb(9) ...
153 1.32 thorpej *
154 1.32 thorpej * NOTE: If the CPU control register is not readable,
155 1.32 thorpej * this will totally fail! We'll just assume that
156 1.32 thorpej * any system that has high vector support has a
157 1.32 thorpej * readable CPU control register, for now. If we
158 1.32 thorpej * ever encounter one that does not, we'll have to
159 1.32 thorpej * rethink this.
160 1.30 scw */
161 1.30 scw cpu_control(CPU_CONTROL_VECRELOC, CPU_CONTROL_VECRELOC);
162 1.30 scw }
163 1.22 thorpej }
164 1.22 thorpej
165 1.22 thorpej /*
166 1.1 chris * Debug function just to park the CPU
167 1.1 chris */
168 1.1 chris
169 1.1 chris void
170 1.1 chris halt()
171 1.1 chris {
172 1.1 chris while (1)
173 1.1 chris cpu_sleep(0);
174 1.1 chris }
175 1.1 chris
176 1.1 chris
177 1.1 chris /* Sync the discs and unmount the filesystems */
178 1.1 chris
179 1.1 chris void
180 1.1 chris bootsync(void)
181 1.1 chris {
182 1.1 chris static int bootsyncdone = 0;
183 1.1 chris
184 1.1 chris if (bootsyncdone) return;
185 1.1 chris
186 1.1 chris bootsyncdone = 1;
187 1.1 chris
188 1.1 chris /* Make sure we can still manage to do things */
189 1.1 chris if (GetCPSR() & I32_bit) {
190 1.1 chris /*
191 1.1 chris * If we get here then boot has been called without RB_NOSYNC
192 1.1 chris * and interrupts were disabled. This means the boot() call
193 1.1 chris * did not come from a user process e.g. shutdown, but must
194 1.1 chris * have come from somewhere in the kernel.
195 1.1 chris */
196 1.1 chris IRQenable;
197 1.1 chris printf("Warning IRQ's disabled during boot()\n");
198 1.1 chris }
199 1.1 chris
200 1.1 chris vfs_shutdown();
201 1.1 chris }
202 1.1 chris
203 1.1 chris /*
204 1.1 chris * void cpu_startup(void)
205 1.1 chris *
206 1.1 chris * Machine dependant startup code.
207 1.1 chris *
208 1.1 chris */
209 1.1 chris void
210 1.1 chris cpu_startup()
211 1.1 chris {
212 1.42 pk vaddr_t minaddr;
213 1.42 pk vaddr_t maxaddr;
214 1.42 pk u_int loop;
215 1.1 chris char pbuf[9];
216 1.1 chris
217 1.43 wiz /* Set the CPU control register */
218 1.1 chris cpu_setup(boot_args);
219 1.1 chris
220 1.1 chris /* Lock down zero page */
221 1.22 thorpej vector_page_setprot(VM_PROT_READ);
222 1.1 chris
223 1.1 chris /*
224 1.1 chris * Give pmap a chance to set up a few more things now the vm
225 1.1 chris * is initialised
226 1.1 chris */
227 1.1 chris pmap_postinit();
228 1.1 chris
229 1.1 chris /*
230 1.1 chris * Initialize error message buffer (at end of core).
231 1.1 chris */
232 1.1 chris
233 1.1 chris /* msgbufphys was setup during the secondary boot strap */
234 1.1 chris for (loop = 0; loop < btoc(MSGBUFSIZE); ++loop)
235 1.29 thorpej pmap_kenter_pa((vaddr_t)msgbufaddr + loop * PAGE_SIZE,
236 1.29 thorpej msgbufphys + loop * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE);
237 1.5 chris pmap_update(pmap_kernel());
238 1.1 chris initmsgbuf(msgbufaddr, round_page(MSGBUFSIZE));
239 1.1 chris
240 1.1 chris /*
241 1.1 chris * Identify ourselves for the msgbuf (everything printed earlier will
242 1.1 chris * not be buffered).
243 1.1 chris */
244 1.1 chris printf(version);
245 1.1 chris
246 1.20 thorpej format_bytes(pbuf, sizeof(pbuf), arm_ptob(physmem));
247 1.1 chris printf("total memory = %s\n", pbuf);
248 1.1 chris
249 1.42 pk minaddr = 0;
250 1.1 chris
251 1.1 chris /*
252 1.1 chris * Allocate a submap for exec arguments. This map effectively
253 1.1 chris * limits the number of processes exec'ing at any time.
254 1.1 chris */
255 1.1 chris exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
256 1.1 chris 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
257 1.1 chris
258 1.1 chris /*
259 1.1 chris * Allocate a submap for physio
260 1.1 chris */
261 1.1 chris phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
262 1.1 chris VM_PHYS_SIZE, 0, FALSE, NULL);
263 1.1 chris
264 1.1 chris /*
265 1.1 chris * Finally, allocate mbuf cluster submap.
266 1.1 chris */
267 1.1 chris mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
268 1.1 chris nmbclusters * mclbytes, VM_MAP_INTRSAFE,
269 1.1 chris FALSE, NULL);
270 1.1 chris
271 1.1 chris format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
272 1.1 chris printf("avail memory = %s\n", pbuf);
273 1.1 chris
274 1.27 thorpej curpcb = &lwp0.l_addr->u_pcb;
275 1.1 chris curpcb->pcb_flags = 0;
276 1.27 thorpej curpcb->pcb_un.un_32.pcb32_und_sp = (u_int)lwp0.l_addr +
277 1.4 toshii USPACE_UNDEF_STACK_TOP;
278 1.27 thorpej curpcb->pcb_un.un_32.pcb32_sp = (u_int)lwp0.l_addr +
279 1.4 toshii USPACE_SVC_STACK_TOP;
280 1.31 scw pmap_set_pcb_pagedir(pmap_kernel(), curpcb);
281 1.1 chris
282 1.4 toshii curpcb->pcb_tf = (struct trapframe *)curpcb->pcb_un.un_32.pcb32_sp - 1;
283 1.1 chris }
284 1.1 chris
285 1.1 chris /*
286 1.1 chris * machine dependent system variables.
287 1.1 chris */
288 1.39 atatat static int
289 1.39 atatat sysctl_machdep_booted_device(SYSCTLFN_ARGS)
290 1.39 atatat {
291 1.39 atatat struct sysctlnode node;
292 1.39 atatat
293 1.39 atatat if (booted_device == NULL)
294 1.39 atatat return (EOPNOTSUPP);
295 1.39 atatat
296 1.39 atatat node = *rnode;
297 1.39 atatat node.sysctl_data = booted_device->dv_xname;
298 1.39 atatat node.sysctl_size = strlen(booted_device->dv_xname) + 1;
299 1.39 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
300 1.39 atatat }
301 1.1 chris
302 1.39 atatat static int
303 1.39 atatat sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
304 1.1 chris {
305 1.39 atatat struct sysctlnode node;
306 1.39 atatat
307 1.39 atatat if (booted_kernel == NULL || booted_kernel[0] == '\0')
308 1.1 chris return (EOPNOTSUPP);
309 1.1 chris
310 1.39 atatat node = *rnode;
311 1.39 atatat node.sysctl_data = booted_kernel;
312 1.39 atatat node.sysctl_size = strlen(booted_kernel) + 1;
313 1.39 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
314 1.39 atatat }
315 1.25 thorpej
316 1.39 atatat static int
317 1.39 atatat sysctl_machdep_powersave(SYSCTLFN_ARGS)
318 1.39 atatat {
319 1.39 atatat struct sysctlnode node = *rnode;
320 1.39 atatat int error, newval;
321 1.25 thorpej
322 1.39 atatat newval = cpu_do_powersave;
323 1.39 atatat node.sysctl_data = &newval;
324 1.39 atatat if (cpufuncs.cf_sleep == (void *) cpufunc_nullop)
325 1.44 atatat node.sysctl_flags &= ~CTLFLAG_READWRITE;
326 1.39 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
327 1.39 atatat if (error || newp == NULL || newval == cpu_do_powersave)
328 1.39 atatat return (error);
329 1.39 atatat
330 1.39 atatat if (newval < 0 || newval > 1)
331 1.39 atatat return (EINVAL);
332 1.39 atatat cpu_do_powersave = newval;
333 1.25 thorpej
334 1.39 atatat return (0);
335 1.39 atatat }
336 1.25 thorpej
337 1.39 atatat SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
338 1.39 atatat {
339 1.1 chris
340 1.44 atatat sysctl_createv(clog, 0, NULL, NULL,
341 1.44 atatat CTLFLAG_PERMANENT,
342 1.39 atatat CTLTYPE_NODE, "machdep", NULL,
343 1.39 atatat NULL, 0, NULL, 0,
344 1.39 atatat CTL_MACHDEP, CTL_EOL);
345 1.39 atatat
346 1.44 atatat sysctl_createv(clog, 0, NULL, NULL,
347 1.44 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
348 1.40 atatat CTLTYPE_INT, "debug", NULL,
349 1.39 atatat NULL, 0, &kernel_debug, 0,
350 1.41 rearnsha CTL_MACHDEP, CPU_DEBUG, CTL_EOL);
351 1.44 atatat sysctl_createv(clog, 0, NULL, NULL,
352 1.44 atatat CTLFLAG_PERMANENT,
353 1.39 atatat CTLTYPE_STRING, "booted_device", NULL,
354 1.39 atatat sysctl_machdep_booted_device, 0, NULL, 0,
355 1.39 atatat CTL_MACHDEP, CPU_BOOTED_DEVICE, CTL_EOL);
356 1.44 atatat sysctl_createv(clog, 0, NULL, NULL,
357 1.44 atatat CTLFLAG_PERMANENT,
358 1.39 atatat CTLTYPE_STRING, "booted_kernel", NULL,
359 1.39 atatat sysctl_machdep_booted_kernel, 0, NULL, 0,
360 1.39 atatat CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
361 1.44 atatat sysctl_createv(clog, 0, NULL, NULL,
362 1.44 atatat CTLFLAG_PERMANENT,
363 1.39 atatat CTLTYPE_STRUCT, "console_device", NULL,
364 1.39 atatat sysctl_consdev, 0, NULL, sizeof(dev_t),
365 1.39 atatat CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
366 1.44 atatat sysctl_createv(clog, 0, NULL, NULL,
367 1.44 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
368 1.39 atatat CTLTYPE_INT, "powersave", NULL,
369 1.39 atatat sysctl_machdep_powersave, 0, &cpu_do_powersave, 0,
370 1.39 atatat CTL_MACHDEP, CPU_POWERSAVE, CTL_EOL);
371 1.1 chris }
372 1.1 chris
373 1.1 chris void
374 1.1 chris parse_mi_bootargs(args)
375 1.1 chris char *args;
376 1.1 chris {
377 1.1 chris int integer;
378 1.1 chris
379 1.1 chris if (get_bootconf_option(args, "single", BOOTOPT_TYPE_BOOLEAN, &integer)
380 1.1 chris || get_bootconf_option(args, "-s", BOOTOPT_TYPE_BOOLEAN, &integer))
381 1.1 chris if (integer)
382 1.1 chris boothowto |= RB_SINGLE;
383 1.1 chris if (get_bootconf_option(args, "kdb", BOOTOPT_TYPE_BOOLEAN, &integer)
384 1.1 chris || get_bootconf_option(args, "-k", BOOTOPT_TYPE_BOOLEAN, &integer))
385 1.1 chris if (integer)
386 1.1 chris boothowto |= RB_KDB;
387 1.1 chris if (get_bootconf_option(args, "ask", BOOTOPT_TYPE_BOOLEAN, &integer)
388 1.1 chris || get_bootconf_option(args, "-a", BOOTOPT_TYPE_BOOLEAN, &integer))
389 1.1 chris if (integer)
390 1.1 chris boothowto |= RB_ASKNAME;
391 1.1 chris
392 1.1 chris #ifdef PMAP_DEBUG
393 1.1 chris if (get_bootconf_option(args, "pmapdebug", BOOTOPT_TYPE_INT, &integer)) {
394 1.1 chris pmap_debug_level = integer;
395 1.1 chris pmap_debug(pmap_debug_level);
396 1.1 chris }
397 1.1 chris #endif /* PMAP_DEBUG */
398 1.1 chris
399 1.1 chris /* if (get_bootconf_option(args, "nbuf", BOOTOPT_TYPE_INT, &integer))
400 1.1 chris bufpages = integer;*/
401 1.1 chris
402 1.21 lukem #if NMD > 0 && defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
403 1.1 chris if (get_bootconf_option(args, "memorydisc", BOOTOPT_TYPE_INT, &integer)
404 1.1 chris || get_bootconf_option(args, "memorydisk", BOOTOPT_TYPE_INT, &integer)) {
405 1.24 jdolecek md_root_size = integer;
406 1.24 jdolecek md_root_size *= 1024;
407 1.24 jdolecek if (md_root_size < 32*1024)
408 1.24 jdolecek md_root_size = 32*1024;
409 1.24 jdolecek if (md_root_size > 2048*1024)
410 1.24 jdolecek md_root_size = 2048*1024;
411 1.1 chris }
412 1.21 lukem #endif /* NMD && MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
413 1.1 chris
414 1.1 chris if (get_bootconf_option(args, "quiet", BOOTOPT_TYPE_BOOLEAN, &integer)
415 1.1 chris || get_bootconf_option(args, "-q", BOOTOPT_TYPE_BOOLEAN, &integer))
416 1.1 chris if (integer)
417 1.1 chris boothowto |= AB_QUIET;
418 1.1 chris if (get_bootconf_option(args, "verbose", BOOTOPT_TYPE_BOOLEAN, &integer)
419 1.1 chris || get_bootconf_option(args, "-v", BOOTOPT_TYPE_BOOLEAN, &integer))
420 1.1 chris if (integer)
421 1.1 chris boothowto |= AB_VERBOSE;
422 1.1 chris }
423