integrator_machdep.c revision 1.47 1 1.47 rearnsha /* $NetBSD: integrator_machdep.c,v 1.47 2003/09/06 10:57:12 rearnsha Exp $ */
2 1.1 rearnsha
3 1.1 rearnsha /*
4 1.23 rearnsha * Copyright (c) 2001,2002 ARM Ltd
5 1.1 rearnsha * All rights reserved.
6 1.1 rearnsha *
7 1.1 rearnsha * Redistribution and use in source and binary forms, with or without
8 1.1 rearnsha * modification, are permitted provided that the following conditions
9 1.1 rearnsha * are met:
10 1.1 rearnsha * 1. Redistributions of source code must retain the above copyright
11 1.1 rearnsha * notice, this list of conditions and the following disclaimer.
12 1.1 rearnsha * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 rearnsha * notice, this list of conditions and the following disclaimer in the
14 1.1 rearnsha * documentation and/or other materials provided with the distribution.
15 1.1 rearnsha * 3. The name of the company may not be used to endorse or promote
16 1.1 rearnsha * products derived from this software without specific prior written
17 1.1 rearnsha * permission.
18 1.1 rearnsha *
19 1.23 rearnsha * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND
20 1.23 rearnsha * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.23 rearnsha * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.23 rearnsha * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD
23 1.23 rearnsha * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.23 rearnsha * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.23 rearnsha * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.23 rearnsha * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.23 rearnsha * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.23 rearnsha * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.23 rearnsha * POSSIBILITY OF SUCH DAMAGE.
30 1.23 rearnsha */
31 1.23 rearnsha
32 1.23 rearnsha /*
33 1.1 rearnsha * Copyright (c) 1997,1998 Mark Brinicombe.
34 1.1 rearnsha * Copyright (c) 1997,1998 Causality Limited.
35 1.1 rearnsha * All rights reserved.
36 1.1 rearnsha *
37 1.1 rearnsha * Redistribution and use in source and binary forms, with or without
38 1.1 rearnsha * modification, are permitted provided that the following conditions
39 1.1 rearnsha * are met:
40 1.1 rearnsha * 1. Redistributions of source code must retain the above copyright
41 1.1 rearnsha * notice, this list of conditions and the following disclaimer.
42 1.1 rearnsha * 2. Redistributions in binary form must reproduce the above copyright
43 1.1 rearnsha * notice, this list of conditions and the following disclaimer in the
44 1.1 rearnsha * documentation and/or other materials provided with the distribution.
45 1.1 rearnsha * 3. All advertising materials mentioning features or use of this software
46 1.1 rearnsha * must display the following acknowledgement:
47 1.1 rearnsha * This product includes software developed by Mark Brinicombe
48 1.1 rearnsha * for the NetBSD Project.
49 1.1 rearnsha * 4. The name of the company nor the name of the author may be used to
50 1.1 rearnsha * endorse or promote products derived from this software without specific
51 1.1 rearnsha * prior written permission.
52 1.1 rearnsha *
53 1.1 rearnsha * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
54 1.1 rearnsha * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
55 1.1 rearnsha * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 1.1 rearnsha * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
57 1.1 rearnsha * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
58 1.1 rearnsha * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
59 1.1 rearnsha * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 1.1 rearnsha * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 1.1 rearnsha * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 1.1 rearnsha * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 1.1 rearnsha * SUCH DAMAGE.
64 1.1 rearnsha *
65 1.1 rearnsha * Machine dependant functions for kernel setup for integrator board
66 1.1 rearnsha *
67 1.1 rearnsha * Created : 24/11/97
68 1.1 rearnsha */
69 1.43 lukem
70 1.43 lukem #include <sys/cdefs.h>
71 1.47 rearnsha __KERNEL_RCSID(0, "$NetBSD: integrator_machdep.c,v 1.47 2003/09/06 10:57:12 rearnsha Exp $");
72 1.1 rearnsha
73 1.1 rearnsha #include "opt_ddb.h"
74 1.1 rearnsha #include "opt_pmap_debug.h"
75 1.1 rearnsha
76 1.1 rearnsha #include <sys/param.h>
77 1.1 rearnsha #include <sys/device.h>
78 1.1 rearnsha #include <sys/systm.h>
79 1.1 rearnsha #include <sys/kernel.h>
80 1.1 rearnsha #include <sys/exec.h>
81 1.1 rearnsha #include <sys/proc.h>
82 1.1 rearnsha #include <sys/msgbuf.h>
83 1.1 rearnsha #include <sys/reboot.h>
84 1.1 rearnsha #include <sys/termios.h>
85 1.32 ragge #include <sys/ksyms.h>
86 1.1 rearnsha
87 1.31 thorpej #include <uvm/uvm_extern.h>
88 1.31 thorpej
89 1.1 rearnsha #include <dev/cons.h>
90 1.1 rearnsha
91 1.1 rearnsha #include <machine/db_machdep.h>
92 1.1 rearnsha #include <ddb/db_sym.h>
93 1.1 rearnsha #include <ddb/db_extern.h>
94 1.1 rearnsha
95 1.1 rearnsha #include <machine/bootconfig.h>
96 1.1 rearnsha #include <machine/bus.h>
97 1.1 rearnsha #include <machine/cpu.h>
98 1.1 rearnsha #include <machine/frame.h>
99 1.1 rearnsha #include <machine/intr.h>
100 1.8 thorpej #include <evbarm/ifpga/irqhandler.h> /* XXX XXX XXX */
101 1.6 thorpej #include <arm/undefined.h>
102 1.1 rearnsha
103 1.23 rearnsha #include <arm/arm32/machdep.h>
104 1.23 rearnsha
105 1.1 rearnsha #include <evbarm/integrator/integrator_boot.h>
106 1.1 rearnsha
107 1.1 rearnsha #include "opt_ipkdb.h"
108 1.1 rearnsha #include "pci.h"
109 1.32 ragge #include "ksyms.h"
110 1.1 rearnsha
111 1.1 rearnsha void ifpga_reset(void) __attribute__((noreturn));
112 1.36 thorpej
113 1.36 thorpej /* Kernel text starts 2MB in from the bottom of the kernel address space. */
114 1.36 thorpej #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
115 1.39 thorpej #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
116 1.40 thorpej
117 1.40 thorpej /*
118 1.40 thorpej * The range 0xc1000000 - 0xccffffff is available for kernel VM space
119 1.40 thorpej * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
120 1.40 thorpej */
121 1.40 thorpej #define KERNEL_VM_SIZE 0x0C000000
122 1.36 thorpej
123 1.1 rearnsha /*
124 1.1 rearnsha * Address to call from cpu_reset() to reset the machine.
125 1.1 rearnsha * This is machine architecture dependant as it varies depending
126 1.1 rearnsha * on where the ROM appears when you turn the MMU off.
127 1.1 rearnsha */
128 1.1 rearnsha
129 1.1 rearnsha u_int cpu_reset_address = (u_int) ifpga_reset;
130 1.1 rearnsha
131 1.1 rearnsha /* Define various stack sizes in pages */
132 1.1 rearnsha #define IRQ_STACK_SIZE 1
133 1.1 rearnsha #define ABT_STACK_SIZE 1
134 1.1 rearnsha #ifdef IPKDB
135 1.1 rearnsha #define UND_STACK_SIZE 2
136 1.1 rearnsha #else
137 1.1 rearnsha #define UND_STACK_SIZE 1
138 1.1 rearnsha #endif
139 1.1 rearnsha
140 1.1 rearnsha BootConfig bootconfig; /* Boot config storage */
141 1.1 rearnsha char *boot_args = NULL;
142 1.1 rearnsha char *boot_file = NULL;
143 1.1 rearnsha
144 1.1 rearnsha vm_offset_t physical_start;
145 1.1 rearnsha vm_offset_t physical_end;
146 1.1 rearnsha vm_offset_t pagetables_start;
147 1.1 rearnsha int physmem = 0;
148 1.1 rearnsha
149 1.1 rearnsha /*int debug_flags;*/
150 1.1 rearnsha #ifndef PMAP_STATIC_L1S
151 1.1 rearnsha int max_processes = 64; /* Default number */
152 1.1 rearnsha #endif /* !PMAP_STATIC_L1S */
153 1.1 rearnsha
154 1.1 rearnsha /* Physical and virtual addresses for some global pages */
155 1.1 rearnsha pv_addr_t systempage;
156 1.1 rearnsha pv_addr_t irqstack;
157 1.1 rearnsha pv_addr_t undstack;
158 1.1 rearnsha pv_addr_t abtstack;
159 1.1 rearnsha pv_addr_t kernelstack;
160 1.1 rearnsha
161 1.1 rearnsha vm_offset_t msgbufphys;
162 1.1 rearnsha
163 1.1 rearnsha extern u_int data_abort_handler_address;
164 1.1 rearnsha extern u_int prefetch_abort_handler_address;
165 1.1 rearnsha extern u_int undefined_handler_address;
166 1.1 rearnsha
167 1.1 rearnsha #ifdef PMAP_DEBUG
168 1.1 rearnsha extern int pmap_debug_level;
169 1.1 rearnsha #endif
170 1.1 rearnsha
171 1.23 rearnsha #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
172 1.23 rearnsha
173 1.23 rearnsha #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
174 1.23 rearnsha #define KERNEL_PT_KERNEL_NUM 2
175 1.23 rearnsha /* L2 tables for mapping kernel VM */
176 1.23 rearnsha #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
177 1.17 chris #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
178 1.1 rearnsha #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
179 1.1 rearnsha
180 1.14 thorpej pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
181 1.1 rearnsha
182 1.1 rearnsha struct user *proc0paddr;
183 1.1 rearnsha
184 1.1 rearnsha /* Prototypes */
185 1.1 rearnsha
186 1.23 rearnsha static void integrator_sdram_bounds (paddr_t *, psize_t *);
187 1.1 rearnsha
188 1.23 rearnsha void consinit(void);
189 1.1 rearnsha
190 1.1 rearnsha /* A load of console goo. */
191 1.1 rearnsha #include "vga.h"
192 1.23 rearnsha #if NVGA > 0
193 1.1 rearnsha #include <dev/ic/mc6845reg.h>
194 1.1 rearnsha #include <dev/ic/pcdisplayvar.h>
195 1.1 rearnsha #include <dev/ic/vgareg.h>
196 1.1 rearnsha #include <dev/ic/vgavar.h>
197 1.1 rearnsha #endif
198 1.1 rearnsha
199 1.1 rearnsha #include "pckbc.h"
200 1.23 rearnsha #if NPCKBC > 0
201 1.1 rearnsha #include <dev/ic/i8042reg.h>
202 1.1 rearnsha #include <dev/ic/pckbcvar.h>
203 1.1 rearnsha #endif
204 1.1 rearnsha
205 1.1 rearnsha #include "com.h"
206 1.23 rearnsha #if NCOM > 0
207 1.1 rearnsha #include <dev/ic/comreg.h>
208 1.1 rearnsha #include <dev/ic/comvar.h>
209 1.1 rearnsha #ifndef CONCOMADDR
210 1.1 rearnsha #define CONCOMADDR 0x3f8
211 1.1 rearnsha #endif
212 1.1 rearnsha #endif
213 1.1 rearnsha
214 1.23 rearnsha /*
215 1.23 rearnsha * Define the default console speed for the board. This is generally
216 1.23 rearnsha * what the firmware provided with the board defaults to.
217 1.23 rearnsha */
218 1.30 mycroft #ifndef CONSPEED
219 1.1 rearnsha #define CONSPEED B115200
220 1.1 rearnsha #endif
221 1.1 rearnsha #ifndef CONMODE
222 1.1 rearnsha #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
223 1.1 rearnsha #endif
224 1.1 rearnsha
225 1.1 rearnsha int comcnspeed = CONSPEED;
226 1.1 rearnsha int comcnmode = CONMODE;
227 1.1 rearnsha
228 1.1 rearnsha #include "plcom.h"
229 1.1 rearnsha #if (NPLCOM > 0)
230 1.1 rearnsha #include <evbarm/dev/plcomreg.h>
231 1.1 rearnsha #include <evbarm/dev/plcomvar.h>
232 1.1 rearnsha
233 1.1 rearnsha #include <evbarm/ifpga/ifpgamem.h>
234 1.1 rearnsha #include <evbarm/ifpga/ifpgareg.h>
235 1.1 rearnsha #include <evbarm/ifpga/ifpgavar.h>
236 1.1 rearnsha #endif
237 1.1 rearnsha
238 1.1 rearnsha #ifndef CONSDEVNAME
239 1.1 rearnsha #define CONSDEVNAME "plcom"
240 1.1 rearnsha #endif
241 1.1 rearnsha
242 1.1 rearnsha #ifndef PLCONSPEED
243 1.1 rearnsha #define PLCONSPEED B38400
244 1.1 rearnsha #endif
245 1.1 rearnsha #ifndef PLCONMODE
246 1.1 rearnsha #define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
247 1.1 rearnsha #endif
248 1.1 rearnsha #ifndef PLCOMCNUNIT
249 1.1 rearnsha #define PLCOMCNUNIT -1
250 1.1 rearnsha #endif
251 1.1 rearnsha
252 1.1 rearnsha int plcomcnspeed = PLCONSPEED;
253 1.1 rearnsha int plcomcnmode = PLCONMODE;
254 1.1 rearnsha
255 1.1 rearnsha #if 0
256 1.1 rearnsha extern struct consdev kcomcons;
257 1.1 rearnsha static void kcomcnputc(dev_t, int);
258 1.1 rearnsha #endif
259 1.1 rearnsha
260 1.1 rearnsha /*
261 1.1 rearnsha * void cpu_reboot(int howto, char *bootstr)
262 1.1 rearnsha *
263 1.1 rearnsha * Reboots the system
264 1.1 rearnsha *
265 1.1 rearnsha * Deal with any syncing, unmounting, dumping and shutdown hooks,
266 1.1 rearnsha * then reset the CPU.
267 1.1 rearnsha */
268 1.1 rearnsha void
269 1.23 rearnsha cpu_reboot(int howto, char *bootstr)
270 1.1 rearnsha {
271 1.1 rearnsha
272 1.1 rearnsha /*
273 1.1 rearnsha * If we are still cold then hit the air brakes
274 1.1 rearnsha * and crash to earth fast
275 1.1 rearnsha */
276 1.1 rearnsha if (cold) {
277 1.1 rearnsha doshutdownhooks();
278 1.1 rearnsha printf("The operating system has halted.\n");
279 1.1 rearnsha printf("Please press any key to reboot.\n\n");
280 1.1 rearnsha cngetc();
281 1.1 rearnsha printf("rebooting...\n");
282 1.1 rearnsha ifpga_reset();
283 1.1 rearnsha /*NOTREACHED*/
284 1.1 rearnsha }
285 1.1 rearnsha
286 1.1 rearnsha /* Disable console buffering */
287 1.1 rearnsha
288 1.1 rearnsha /*
289 1.1 rearnsha * If RB_NOSYNC was not specified sync the discs.
290 1.23 rearnsha * Note: Unless cold is set to 1 here, syslogd will die during the
291 1.23 rearnsha * unmount. It looks like syslogd is getting woken up only to find
292 1.23 rearnsha * that it cannot page part of the binary in as the filesystem has
293 1.23 rearnsha * been unmounted.
294 1.1 rearnsha */
295 1.1 rearnsha if (!(howto & RB_NOSYNC))
296 1.1 rearnsha bootsync();
297 1.1 rearnsha
298 1.1 rearnsha /* Say NO to interrupts */
299 1.1 rearnsha splhigh();
300 1.1 rearnsha
301 1.1 rearnsha /* Do a dump if requested. */
302 1.1 rearnsha if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
303 1.1 rearnsha dumpsys();
304 1.1 rearnsha
305 1.1 rearnsha /* Run any shutdown hooks */
306 1.1 rearnsha doshutdownhooks();
307 1.1 rearnsha
308 1.1 rearnsha /* Make sure IRQ's are disabled */
309 1.1 rearnsha IRQdisable;
310 1.1 rearnsha
311 1.1 rearnsha if (howto & RB_HALT) {
312 1.1 rearnsha printf("The operating system has halted.\n");
313 1.1 rearnsha printf("Please press any key to reboot.\n\n");
314 1.1 rearnsha cngetc();
315 1.1 rearnsha }
316 1.1 rearnsha
317 1.1 rearnsha printf("rebooting...\n");
318 1.1 rearnsha ifpga_reset();
319 1.1 rearnsha /*NOTREACHED*/
320 1.1 rearnsha }
321 1.1 rearnsha
322 1.42 thorpej /* Statically mapped devices. */
323 1.42 thorpej static const struct pmap_devmap integrator_devmap[] = {
324 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
325 1.23 rearnsha {
326 1.23 rearnsha UART0_BOOT_BASE,
327 1.23 rearnsha IFPGA_IO_BASE + IFPGA_UART0,
328 1.23 rearnsha 1024 * 1024,
329 1.23 rearnsha VM_PROT_READ|VM_PROT_WRITE,
330 1.23 rearnsha PTE_NOCACHE
331 1.23 rearnsha },
332 1.23 rearnsha
333 1.23 rearnsha {
334 1.23 rearnsha UART1_BOOT_BASE,
335 1.23 rearnsha IFPGA_IO_BASE + IFPGA_UART1,
336 1.23 rearnsha 1024 * 1024,
337 1.23 rearnsha VM_PROT_READ|VM_PROT_WRITE,
338 1.23 rearnsha PTE_NOCACHE
339 1.23 rearnsha },
340 1.1 rearnsha #endif
341 1.1 rearnsha #if NPCI > 0
342 1.23 rearnsha {
343 1.23 rearnsha IFPGA_PCI_IO_VBASE,
344 1.23 rearnsha IFPGA_PCI_IO_BASE,
345 1.23 rearnsha IFPGA_PCI_IO_VSIZE,
346 1.23 rearnsha VM_PROT_READ|VM_PROT_WRITE,
347 1.23 rearnsha PTE_NOCACHE
348 1.23 rearnsha },
349 1.23 rearnsha
350 1.23 rearnsha {
351 1.23 rearnsha IFPGA_PCI_CONF_VBASE,
352 1.23 rearnsha IFPGA_PCI_CONF_BASE,
353 1.23 rearnsha IFPGA_PCI_CONF_VSIZE,
354 1.23 rearnsha VM_PROT_READ|VM_PROT_WRITE,
355 1.42 thorpej PTE_NOCACHE
356 1.42 thorpej },
357 1.1 rearnsha #endif
358 1.1 rearnsha
359 1.23 rearnsha {
360 1.23 rearnsha 0,
361 1.23 rearnsha 0,
362 1.23 rearnsha 0,
363 1.23 rearnsha 0,
364 1.23 rearnsha 0
365 1.23 rearnsha }
366 1.1 rearnsha };
367 1.1 rearnsha
368 1.1 rearnsha /*
369 1.23 rearnsha * u_int initarm(...)
370 1.1 rearnsha *
371 1.1 rearnsha * Initial entry point on startup. This gets called before main() is
372 1.1 rearnsha * entered.
373 1.1 rearnsha * It should be responsible for setting up everything that must be
374 1.1 rearnsha * in place when main is called.
375 1.1 rearnsha * This includes
376 1.1 rearnsha * Taking a copy of the boot configuration structure.
377 1.1 rearnsha * Initialising the physical console so characters can be printed.
378 1.1 rearnsha * Setting up page tables for the kernel
379 1.1 rearnsha * Relocating the kernel to the bottom of physical memory
380 1.1 rearnsha */
381 1.1 rearnsha
382 1.1 rearnsha u_int
383 1.23 rearnsha initarm(void *arg)
384 1.1 rearnsha {
385 1.1 rearnsha int loop;
386 1.1 rearnsha int loop1;
387 1.1 rearnsha u_int l1pagetable;
388 1.47 rearnsha extern char etext asm ("_etext");
389 1.47 rearnsha extern char end asm ("_end");
390 1.1 rearnsha pv_addr_t kernel_l1pt;
391 1.23 rearnsha paddr_t memstart;
392 1.23 rearnsha psize_t memsize;
393 1.47 rearnsha vm_offset_t physical_freestart;
394 1.47 rearnsha vm_offset_t physical_freeend;
395 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
396 1.1 rearnsha static struct bus_space plcom_bus_space;
397 1.1 rearnsha #endif
398 1.1 rearnsha
399 1.1 rearnsha /*
400 1.1 rearnsha * Heads up ... Setup the CPU / MMU / TLB functions
401 1.1 rearnsha */
402 1.1 rearnsha if (set_cpufuncs())
403 1.1 rearnsha panic("cpu not recognized!");
404 1.1 rearnsha
405 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
406 1.1 rearnsha /*
407 1.1 rearnsha * Initialise the diagnostic serial console
408 1.1 rearnsha * This allows a means of generating output during initarm().
409 1.1 rearnsha * Once all the memory map changes are complete we can call consinit()
410 1.1 rearnsha * and not have to worry about things moving.
411 1.1 rearnsha */
412 1.1 rearnsha
413 1.1 rearnsha if (PLCOMCNUNIT == 0) {
414 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd600000);
415 1.1 rearnsha plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
416 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
417 1.1 rearnsha } else if (PLCOMCNUNIT == 1) {
418 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd700000);
419 1.1 rearnsha plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
420 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
421 1.1 rearnsha }
422 1.1 rearnsha #endif
423 1.1 rearnsha
424 1.38 thorpej #ifdef VERBOSE_INIT_ARM
425 1.1 rearnsha /* Talk to the user */
426 1.23 rearnsha printf("\nNetBSD/evbarm (Integrator) booting ...\n");
427 1.38 thorpej #endif
428 1.1 rearnsha
429 1.1 rearnsha /*
430 1.23 rearnsha * Fetch the SDRAM start/size from the CM configuration registers.
431 1.1 rearnsha */
432 1.23 rearnsha integrator_sdram_bounds(&memstart, &memsize);
433 1.1 rearnsha
434 1.38 thorpej #ifdef VERBOSE_INIT_ARM
435 1.1 rearnsha printf("initarm: Configuring system ...\n");
436 1.38 thorpej #endif
437 1.1 rearnsha
438 1.23 rearnsha /* Fake bootconfig structure for the benefit of pmap.c */
439 1.23 rearnsha /* XXX must make the memory description h/w independent */
440 1.23 rearnsha bootconfig.dramblocks = 1;
441 1.23 rearnsha bootconfig.dram[0].address = memstart;
442 1.31 thorpej bootconfig.dram[0].pages = memsize / PAGE_SIZE;
443 1.47 rearnsha bootconfig.dram[0].flags = BOOT_DRAM_CAN_DMA | BOOT_DRAM_PREFER;
444 1.23 rearnsha
445 1.1 rearnsha /*
446 1.1 rearnsha * Set up the variables that define the availablilty of
447 1.23 rearnsha * physical memory. For now, we're going to set
448 1.23 rearnsha * physical_freestart to 0x00200000 (where the kernel
449 1.23 rearnsha * was loaded), and allocate the memory we need downwards.
450 1.23 rearnsha * If we get too close to the L1 table that we set up, we
451 1.23 rearnsha * will panic. We will update physical_freestart and
452 1.23 rearnsha * physical_freeend later to reflect what pmap_bootstrap()
453 1.23 rearnsha * wants to see.
454 1.23 rearnsha *
455 1.47 rearnsha * We assume that the kernel is loaded into bank[0].
456 1.47 rearnsha *
457 1.23 rearnsha * XXX pmap_bootstrap() needs an enema.
458 1.1 rearnsha */
459 1.23 rearnsha physical_start = bootconfig.dram[0].address;
460 1.47 rearnsha physical_end = 0;
461 1.1 rearnsha
462 1.47 rearnsha /* Update the address of the first free 16KB chunk of physical memory */
463 1.47 rearnsha physical_freestart = ((uintptr_t) &end - KERNEL_BASE + PGOFSET)
464 1.47 rearnsha & ~PGOFSET;
465 1.47 rearnsha if (physical_freestart < bootconfig.dram[0].address)
466 1.47 rearnsha physical_freestart = bootconfig.dram[0].address;
467 1.47 rearnsha physical_freeend = bootconfig.dram[0].address +
468 1.47 rearnsha bootconfig.dram[0].pages * PAGE_SIZE;
469 1.47 rearnsha
470 1.47 rearnsha for (loop = 0, physmem = 0; loop < bootconfig.dramblocks; loop++) {
471 1.47 rearnsha paddr_t memoryblock_end;
472 1.47 rearnsha
473 1.47 rearnsha memoryblock_end = bootconfig.dram[loop].address +
474 1.47 rearnsha bootconfig.dram[loop].pages * PAGE_SIZE;
475 1.47 rearnsha if (memoryblock_end > physical_end)
476 1.47 rearnsha physical_end = memoryblock_end;
477 1.47 rearnsha if (bootconfig.dram[loop].address < physical_start)
478 1.47 rearnsha physical_start = bootconfig.dram[loop].address;
479 1.47 rearnsha
480 1.47 rearnsha physmem += bootconfig.dram[loop].pages;
481 1.47 rearnsha }
482 1.1 rearnsha
483 1.38 thorpej #ifdef VERBOSE_INIT_ARM
484 1.1 rearnsha /* Tell the user about the memory */
485 1.1 rearnsha printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
486 1.1 rearnsha physical_start, physical_end - 1);
487 1.38 thorpej #endif
488 1.1 rearnsha
489 1.1 rearnsha /*
490 1.23 rearnsha * Okay, the kernel starts 2MB in from the bottom of physical
491 1.23 rearnsha * memory. We are going to allocate our bootstrap pages downwards
492 1.23 rearnsha * from there.
493 1.1 rearnsha *
494 1.23 rearnsha * We need to allocate some fixed page tables to get the kernel
495 1.23 rearnsha * going. We allocate one page directory and a number of page
496 1.23 rearnsha * tables and store the physical addresses in the kernel_pt_table
497 1.23 rearnsha * array.
498 1.23 rearnsha *
499 1.23 rearnsha * The kernel page directory must be on a 16K boundary. The page
500 1.23 rearnsha * tables must be on 4K bounaries. What we do is allocate the
501 1.23 rearnsha * page directory on the first 16K boundary that we encounter, and
502 1.23 rearnsha * the page tables on 4K boundaries otherwise. Since we allocate
503 1.23 rearnsha * at least 3 L2 page tables, we are guaranteed to encounter at
504 1.23 rearnsha * least one 16K aligned region.
505 1.1 rearnsha */
506 1.1 rearnsha
507 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
508 1.1 rearnsha printf("Allocating page tables\n");
509 1.1 rearnsha #endif
510 1.1 rearnsha
511 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
512 1.47 rearnsha printf("freestart = 0x%08lx, free pages = %d (0x%08x)\n",
513 1.47 rearnsha physical_freestart, physmem, physmem);
514 1.1 rearnsha #endif
515 1.1 rearnsha
516 1.1 rearnsha /* Define a macro to simplify memory allocation */
517 1.23 rearnsha #define valloc_pages(var, np) \
518 1.23 rearnsha alloc_pages((var).pv_pa, (np)); \
519 1.47 rearnsha (var).pv_va = KERNEL_BASE + (var).pv_pa;
520 1.23 rearnsha
521 1.23 rearnsha #define alloc_pages(var, np) \
522 1.47 rearnsha (var) = physical_freestart; \
523 1.47 rearnsha physical_freestart += ((np) * PAGE_SIZE); \
524 1.23 rearnsha if (physical_freeend < physical_freestart) \
525 1.23 rearnsha panic("initarm: out of memory"); \
526 1.31 thorpej memset((char *)(var), 0, ((np) * PAGE_SIZE));
527 1.1 rearnsha
528 1.1 rearnsha loop1 = 0;
529 1.1 rearnsha kernel_l1pt.pv_pa = 0;
530 1.1 rearnsha for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
531 1.1 rearnsha /* Are we 16KB aligned for an L1 ? */
532 1.47 rearnsha if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
533 1.1 rearnsha && kernel_l1pt.pv_pa == 0) {
534 1.31 thorpej valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
535 1.1 rearnsha } else {
536 1.33 thorpej valloc_pages(kernel_pt_table[loop1],
537 1.33 thorpej L2_TABLE_SIZE / PAGE_SIZE);
538 1.23 rearnsha ++loop1;
539 1.1 rearnsha }
540 1.1 rearnsha }
541 1.1 rearnsha
542 1.1 rearnsha /* This should never be able to happen but better confirm that. */
543 1.21 thorpej if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
544 1.28 provos panic("initarm: Failed to align the kernel page directory");
545 1.1 rearnsha
546 1.1 rearnsha /*
547 1.1 rearnsha * Allocate a page for the system page mapped to V0x00000000
548 1.1 rearnsha * This page will just contain the system vectors and can be
549 1.1 rearnsha * shared by all processes.
550 1.1 rearnsha */
551 1.1 rearnsha alloc_pages(systempage.pv_pa, 1);
552 1.1 rearnsha
553 1.1 rearnsha /* Allocate stacks for all modes */
554 1.1 rearnsha valloc_pages(irqstack, IRQ_STACK_SIZE);
555 1.1 rearnsha valloc_pages(abtstack, ABT_STACK_SIZE);
556 1.1 rearnsha valloc_pages(undstack, UND_STACK_SIZE);
557 1.1 rearnsha valloc_pages(kernelstack, UPAGES);
558 1.1 rearnsha
559 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
560 1.23 rearnsha printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
561 1.23 rearnsha irqstack.pv_va);
562 1.23 rearnsha printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
563 1.23 rearnsha abtstack.pv_va);
564 1.23 rearnsha printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
565 1.23 rearnsha undstack.pv_va);
566 1.23 rearnsha printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
567 1.23 rearnsha kernelstack.pv_va);
568 1.1 rearnsha #endif
569 1.1 rearnsha
570 1.31 thorpej alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
571 1.1 rearnsha
572 1.1 rearnsha /*
573 1.1 rearnsha * Ok we have allocated physical pages for the primary kernel
574 1.1 rearnsha * page tables
575 1.1 rearnsha */
576 1.1 rearnsha
577 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
578 1.23 rearnsha printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
579 1.1 rearnsha #endif
580 1.1 rearnsha
581 1.1 rearnsha /*
582 1.23 rearnsha * Now we start construction of the L1 page table
583 1.1 rearnsha * We start by mapping the L2 page tables into the L1.
584 1.1 rearnsha * This means that we can replace L1 mappings later on if necessary
585 1.1 rearnsha */
586 1.1 rearnsha l1pagetable = kernel_l1pt.pv_pa;
587 1.1 rearnsha
588 1.1 rearnsha /* Map the L2 pages tables in the L1 page table */
589 1.11 thorpej pmap_link_l2pt(l1pagetable, 0x00000000,
590 1.14 thorpej &kernel_pt_table[KERNEL_PT_SYS]);
591 1.23 rearnsha for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
592 1.23 rearnsha pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
593 1.23 rearnsha &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
594 1.23 rearnsha for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
595 1.11 thorpej pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
596 1.14 thorpej &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
597 1.17 chris
598 1.17 chris /* update the top of the kernel VM */
599 1.19 thorpej pmap_curmaxkvaddr =
600 1.19 thorpej KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
601 1.1 rearnsha
602 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
603 1.1 rearnsha printf("Mapping kernel\n");
604 1.1 rearnsha #endif
605 1.1 rearnsha
606 1.1 rearnsha /* Now we fill in the L2 pagetable for the kernel static code/data */
607 1.1 rearnsha {
608 1.1 rearnsha size_t textsize = (uintptr_t) &etext - KERNEL_TEXT_BASE;
609 1.1 rearnsha size_t totalsize = (uintptr_t) &end - KERNEL_TEXT_BASE;
610 1.23 rearnsha u_int logical;
611 1.1 rearnsha
612 1.23 rearnsha textsize = (textsize + PGOFSET) & ~PGOFSET;
613 1.1 rearnsha totalsize = (totalsize + PGOFSET) & ~PGOFSET;
614 1.23 rearnsha
615 1.23 rearnsha logical = 0x00200000; /* offset of kernel in RAM */
616 1.23 rearnsha
617 1.23 rearnsha logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
618 1.47 rearnsha logical, textsize, VM_PROT_READ | VM_PROT_WRITE,
619 1.47 rearnsha PTE_CACHE);
620 1.23 rearnsha logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
621 1.47 rearnsha logical, totalsize - textsize,
622 1.47 rearnsha VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
623 1.1 rearnsha }
624 1.1 rearnsha
625 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
626 1.1 rearnsha printf("Constructing L2 page tables\n");
627 1.1 rearnsha #endif
628 1.1 rearnsha
629 1.1 rearnsha /* Map the stack pages */
630 1.14 thorpej pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
631 1.31 thorpej IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
632 1.14 thorpej pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
633 1.31 thorpej ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
634 1.14 thorpej pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
635 1.31 thorpej UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
636 1.14 thorpej pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
637 1.31 thorpej UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
638 1.13 thorpej
639 1.33 thorpej pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
640 1.33 thorpej L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
641 1.1 rearnsha
642 1.33 thorpej for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
643 1.33 thorpej pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
644 1.44 rearnsha kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
645 1.33 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
646 1.33 thorpej }
647 1.1 rearnsha
648 1.20 thorpej /* Map the vector page. */
649 1.1 rearnsha #if 1
650 1.1 rearnsha /* MULTI-ICE requires that page 0 is NC/NB so that it can download
651 1.1 rearnsha the cache-clean code there. */
652 1.20 thorpej pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
653 1.10 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
654 1.1 rearnsha #else
655 1.20 thorpej pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
656 1.20 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
657 1.1 rearnsha #endif
658 1.1 rearnsha
659 1.42 thorpej /* Map the statically mapped devices. */
660 1.42 thorpej pmap_devmap_bootstrap(l1pagetable, integrator_devmap);
661 1.1 rearnsha
662 1.1 rearnsha /*
663 1.1 rearnsha * Now we have the real page tables in place so we can switch to them.
664 1.23 rearnsha * Once this is done we will be running with the REAL kernel page
665 1.23 rearnsha * tables.
666 1.23 rearnsha */
667 1.23 rearnsha
668 1.1 rearnsha /* Switch tables */
669 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
670 1.1 rearnsha printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
671 1.1 rearnsha #endif
672 1.33 thorpej cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
673 1.1 rearnsha setttb(kernel_l1pt.pv_pa);
674 1.23 rearnsha cpu_tlb_flushID();
675 1.33 thorpej cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
676 1.33 thorpej
677 1.33 thorpej /*
678 1.33 thorpej * Moved from cpu_startup() as data_abort_handler() references
679 1.33 thorpej * this during uvm init
680 1.33 thorpej */
681 1.33 thorpej proc0paddr = (struct user *)kernelstack.pv_va;
682 1.33 thorpej lwp0.l_addr = proc0paddr;
683 1.1 rearnsha
684 1.1 rearnsha #ifdef PLCONSOLE
685 1.1 rearnsha /*
686 1.1 rearnsha * The IFPGA registers have just moved.
687 1.1 rearnsha * Detach the diagnostic serial port and reattach at the new address.
688 1.1 rearnsha */
689 1.1 rearnsha plcomcndetach();
690 1.1 rearnsha #endif
691 1.1 rearnsha
692 1.1 rearnsha /*
693 1.1 rearnsha * XXX this should only be done in main() but it useful to
694 1.1 rearnsha * have output earlier ...
695 1.1 rearnsha */
696 1.1 rearnsha consinit();
697 1.1 rearnsha
698 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
699 1.1 rearnsha printf("bootstrap done.\n");
700 1.1 rearnsha #endif
701 1.1 rearnsha
702 1.20 thorpej arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
703 1.1 rearnsha
704 1.1 rearnsha /*
705 1.1 rearnsha * Pages were allocated during the secondary bootstrap for the
706 1.1 rearnsha * stacks for different CPU modes.
707 1.1 rearnsha * We must now set the r13 registers in the different CPU modes to
708 1.1 rearnsha * point to these stacks.
709 1.1 rearnsha * Since the ARM stacks use STMFD etc. we must set r13 to the top end
710 1.1 rearnsha * of the stack memory.
711 1.1 rearnsha */
712 1.38 thorpej #ifdef VERBOSE_INIT_ARM
713 1.1 rearnsha printf("init subsystems: stacks ");
714 1.38 thorpej #endif
715 1.1 rearnsha
716 1.31 thorpej set_stackptr(PSR_IRQ32_MODE,
717 1.31 thorpej irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
718 1.31 thorpej set_stackptr(PSR_ABT32_MODE,
719 1.31 thorpej abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
720 1.31 thorpej set_stackptr(PSR_UND32_MODE,
721 1.31 thorpej undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
722 1.1 rearnsha
723 1.1 rearnsha /*
724 1.1 rearnsha * Well we should set a data abort handler.
725 1.23 rearnsha * Once things get going this will change as we will need a proper
726 1.23 rearnsha * handler.
727 1.1 rearnsha * Until then we will use a handler that just panics but tells us
728 1.1 rearnsha * why.
729 1.1 rearnsha * Initialisation of the vectors will just panic on a data abort.
730 1.1 rearnsha * This just fills in a slighly better one.
731 1.1 rearnsha */
732 1.38 thorpej #ifdef VERBOSE_INIT_ARM
733 1.1 rearnsha printf("vectors ");
734 1.38 thorpej #endif
735 1.1 rearnsha data_abort_handler_address = (u_int)data_abort_handler;
736 1.1 rearnsha prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
737 1.1 rearnsha undefined_handler_address = (u_int)undefinedinstruction_bounce;
738 1.1 rearnsha
739 1.1 rearnsha /* Initialise the undefined instruction handlers */
740 1.38 thorpej #ifdef VERBOSE_INIT_ARM
741 1.1 rearnsha printf("undefined ");
742 1.38 thorpej #endif
743 1.1 rearnsha undefined_init();
744 1.1 rearnsha
745 1.25 thorpej /* Load memory into UVM. */
746 1.38 thorpej #ifdef VERBOSE_INIT_ARM
747 1.25 thorpej printf("page ");
748 1.38 thorpej #endif
749 1.25 thorpej uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
750 1.47 rearnsha
751 1.47 rearnsha /* Round the start up and the end down to a page. */
752 1.47 rearnsha physical_freestart = (physical_freestart + PGOFSET) & ~PGOFSET;
753 1.47 rearnsha physical_freeend &= ~PGOFSET;
754 1.47 rearnsha
755 1.47 rearnsha for (loop = 0; loop < bootconfig.dramblocks; loop++) {
756 1.47 rearnsha paddr_t block_start = (paddr_t) bootconfig.dram[loop].address;
757 1.47 rearnsha paddr_t block_end = block_start +
758 1.47 rearnsha (bootconfig.dram[loop].pages * PAGE_SIZE);
759 1.47 rearnsha
760 1.47 rearnsha if (loop == 0) {
761 1.47 rearnsha block_start = physical_freestart;
762 1.47 rearnsha block_end = physical_freeend;
763 1.47 rearnsha }
764 1.47 rearnsha
765 1.47 rearnsha
766 1.47 rearnsha uvm_page_physload(atop(block_start), atop(block_end),
767 1.47 rearnsha atop(block_start), atop(block_end),
768 1.47 rearnsha (bootconfig.dram[loop].flags & BOOT_DRAM_PREFER) ?
769 1.47 rearnsha VM_FREELIST_DEFAULT : VM_FREELIST_DEFAULT + 1);
770 1.47 rearnsha }
771 1.25 thorpej
772 1.1 rearnsha /* Boot strap pmap telling it where the kernel page table is */
773 1.38 thorpej #ifdef VERBOSE_INIT_ARM
774 1.1 rearnsha printf("pmap ");
775 1.38 thorpej #endif
776 1.35 thorpej pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
777 1.35 thorpej KERNEL_VM_BASE + KERNEL_VM_SIZE);
778 1.1 rearnsha
779 1.1 rearnsha /* Setup the IRQ system */
780 1.38 thorpej #ifdef VERBOSE_INIT_ARM
781 1.1 rearnsha printf("irq ");
782 1.38 thorpej #endif
783 1.1 rearnsha irq_init();
784 1.1 rearnsha
785 1.38 thorpej #ifdef VERBOSE_INIT_ARM
786 1.1 rearnsha printf("done.\n");
787 1.38 thorpej #endif
788 1.1 rearnsha
789 1.1 rearnsha #ifdef IPKDB
790 1.1 rearnsha /* Initialise ipkdb */
791 1.1 rearnsha ipkdb_init();
792 1.1 rearnsha if (boothowto & RB_KDB)
793 1.1 rearnsha ipkdb_connect(0);
794 1.1 rearnsha #endif
795 1.1 rearnsha
796 1.32 ragge #if NKSYMS || defined(DDB) || defined(LKM)
797 1.32 ragge /* Firmware doesn't load symbols. */
798 1.32 ragge ksyms_init(0, NULL, NULL);
799 1.32 ragge #endif
800 1.32 ragge
801 1.1 rearnsha #ifdef DDB
802 1.1 rearnsha db_machine_init();
803 1.1 rearnsha if (boothowto & RB_KDB)
804 1.1 rearnsha Debugger();
805 1.1 rearnsha #endif
806 1.1 rearnsha
807 1.1 rearnsha /* We return the new stack pointer address */
808 1.1 rearnsha return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
809 1.1 rearnsha }
810 1.1 rearnsha
811 1.1 rearnsha void
812 1.1 rearnsha consinit(void)
813 1.1 rearnsha {
814 1.1 rearnsha static int consinit_called = 0;
815 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
816 1.1 rearnsha static struct bus_space plcom_bus_space;
817 1.1 rearnsha #endif
818 1.1 rearnsha #if 0
819 1.1 rearnsha char *console = CONSDEVNAME;
820 1.1 rearnsha #endif
821 1.1 rearnsha
822 1.1 rearnsha if (consinit_called != 0)
823 1.1 rearnsha return;
824 1.1 rearnsha
825 1.1 rearnsha consinit_called = 1;
826 1.1 rearnsha
827 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
828 1.1 rearnsha if (PLCOMCNUNIT == 0) {
829 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space,
830 1.1 rearnsha (void*)UART0_BOOT_BASE);
831 1.1 rearnsha if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
832 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
833 1.1 rearnsha panic("can't init serial console");
834 1.1 rearnsha return;
835 1.1 rearnsha } else if (PLCOMCNUNIT == 1) {
836 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space,
837 1.1 rearnsha (void*)UART0_BOOT_BASE);
838 1.1 rearnsha if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
839 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
840 1.1 rearnsha panic("can't init serial console");
841 1.1 rearnsha return;
842 1.1 rearnsha }
843 1.1 rearnsha #endif
844 1.1 rearnsha #if (NCOM > 0)
845 1.1 rearnsha if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
846 1.41 thorpej COM_FREQ, COM_TYPE_NORMAL, comcnmode))
847 1.1 rearnsha panic("can't init serial console @%x", CONCOMADDR);
848 1.1 rearnsha return;
849 1.1 rearnsha #endif
850 1.1 rearnsha panic("No serial console configured");
851 1.23 rearnsha }
852 1.23 rearnsha
853 1.23 rearnsha static void
854 1.23 rearnsha integrator_sdram_bounds(paddr_t *memstart, psize_t *memsize)
855 1.23 rearnsha {
856 1.23 rearnsha volatile unsigned long *cm_sdram
857 1.23 rearnsha = (volatile unsigned long *)0x10000020;
858 1.46 rearnsha volatile unsigned long *cm_stat
859 1.46 rearnsha = (volatile unsigned long *)0x10000010;
860 1.23 rearnsha
861 1.46 rearnsha *memstart = *cm_stat & 0x00ff0000;
862 1.23 rearnsha
863 1.46 rearnsha /*
864 1.46 rearnsha * Although the SSRAM overlaps the SDRAM, we can use the wrap-around
865 1.46 rearnsha * to access the entire bank.
866 1.46 rearnsha */
867 1.23 rearnsha switch ((*cm_sdram >> 2) & 0x7)
868 1.23 rearnsha {
869 1.23 rearnsha case 0:
870 1.23 rearnsha *memsize = 16 * 1024 * 1024;
871 1.23 rearnsha break;
872 1.23 rearnsha case 1:
873 1.23 rearnsha *memsize = 32 * 1024 * 1024;
874 1.23 rearnsha break;
875 1.23 rearnsha case 2:
876 1.23 rearnsha *memsize = 64 * 1024 * 1024;
877 1.23 rearnsha break;
878 1.23 rearnsha case 3:
879 1.23 rearnsha *memsize = 128 * 1024 * 1024;
880 1.23 rearnsha break;
881 1.23 rearnsha case 4:
882 1.46 rearnsha /* With 256M of memory there is no wrap-around. */
883 1.46 rearnsha *memsize = 256 * 1024 * 1024 - *memstart;
884 1.23 rearnsha break;
885 1.23 rearnsha default:
886 1.23 rearnsha printf("CM_SDRAM retuns unknown value, using 16M\n");
887 1.23 rearnsha *memsize = 16 * 1024 * 1024;
888 1.23 rearnsha break;
889 1.23 rearnsha }
890 1.1 rearnsha }
891