nslu2_machdep.c revision 1.1 1 /* $NetBSD: nslu2_machdep.c,v 1.1 2006/02/28 20:40:33 scw Exp $ */
2
3 /*-
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38 /*
39 * Copyright (c) 2003
40 * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by Ichiro FUKUHARA.
54 * 4. The name of the company nor the name of the author may be used to
55 * endorse or promote products derived from this software without specific
56 * prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
62 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 */
70 /*
71 * Copyright (c) 1997,1998 Mark Brinicombe.
72 * Copyright (c) 1997,1998 Causality Limited.
73 * All rights reserved.
74 *
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
77 * are met:
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
83 * 3. All advertising materials mentioning features or use of this software
84 * must display the following acknowledgement:
85 * This product includes software developed by Mark Brinicombe
86 * for the NetBSD Project.
87 * 4. The name of the company nor the name of the author may be used to
88 * endorse or promote products derived from this software without specific
89 * prior written permission.
90 *
91 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
92 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
93 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
94 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
95 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
96 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
97 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 * SUCH DAMAGE.
102 */
103
104 /*
105 * Machine dependant functions for kernel setup for Linksys NSLU2
106 * using RedBoot firmware.
107 */
108
109 #include <sys/cdefs.h>
110 __KERNEL_RCSID(0, "$NetBSD: nslu2_machdep.c,v 1.1 2006/02/28 20:40:33 scw Exp $");
111
112 #include "opt_ddb.h"
113 #include "opt_kgdb.h"
114 #include "opt_pmap_debug.h"
115
116 #include <sys/param.h>
117 #include <sys/device.h>
118 #include <sys/systm.h>
119 #include <sys/kernel.h>
120 #include <sys/exec.h>
121 #include <sys/proc.h>
122 #include <sys/msgbuf.h>
123 #include <sys/reboot.h>
124 #include <sys/termios.h>
125 #include <sys/ksyms.h>
126
127 #include <uvm/uvm_extern.h>
128
129 #include <dev/cons.h>
130
131 #include <machine/db_machdep.h>
132 #include <ddb/db_sym.h>
133 #include <ddb/db_extern.h>
134
135 #include <machine/bootconfig.h>
136 #include <machine/bus.h>
137 #include <machine/cpu.h>
138 #include <machine/frame.h>
139 #include <arm/undefined.h>
140
141 #include <arm/arm32/machdep.h>
142
143 #include <arm/xscale/ixp425reg.h>
144 #include <arm/xscale/ixp425var.h>
145 #include <arm/xscale/ixp425_sipvar.h>
146
147 #include <evbarm/nslu2/nslu2reg.h>
148
149 #include "com.h"
150 #if NCOM > 0
151 #include <dev/ic/comreg.h>
152 #include <dev/ic/comvar.h>
153 #endif
154
155 #include "opt_ipkdb.h"
156 #include "ksyms.h"
157
158 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
159 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
160 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
161
162 /*
163 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
164 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
165 */
166 #define KERNEL_VM_SIZE 0x0C000000
167
168
169 /*
170 * Address to call from cpu_reset() to reset the machine.
171 * This is machine architecture dependant as it varies depending
172 * on where the ROM appears when you turn the MMU off.
173 */
174
175 u_int cpu_reset_address = 0x00000000;
176
177 /* Define various stack sizes in pages */
178 #define IRQ_STACK_SIZE 1
179 #define ABT_STACK_SIZE 1
180 #ifdef IPKDB
181 #define UND_STACK_SIZE 2
182 #else
183 #define UND_STACK_SIZE 1
184 #endif
185
186 BootConfig bootconfig; /* Boot config storage */
187 char *boot_args = NULL;
188 char *boot_file = NULL;
189
190 vm_offset_t physical_start;
191 vm_offset_t physical_freestart;
192 vm_offset_t physical_freeend;
193 vm_offset_t physical_end;
194 u_int free_pages;
195 vm_offset_t pagetables_start;
196 int physmem = 0;
197
198 /* Physical and virtual addresses for some global pages */
199 pv_addr_t systempage;
200 pv_addr_t irqstack;
201 pv_addr_t undstack;
202 pv_addr_t abtstack;
203 pv_addr_t kernelstack;
204 pv_addr_t minidataclean;
205
206 vm_offset_t msgbufphys;
207
208 extern u_int data_abort_handler_address;
209 extern u_int prefetch_abort_handler_address;
210 extern u_int undefined_handler_address;
211 extern int end;
212
213 #ifdef PMAP_DEBUG
214 extern int pmap_debug_level;
215 #endif
216
217 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
218
219 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
220 #define KERNEL_PT_KERNEL_NUM 4
221 #define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
222 /* L2 tables for mapping kernel VM */
223 #define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1)
224 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
225 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
226
227 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
228
229 struct user *proc0paddr;
230
231 /* Prototypes */
232
233 void consinit(void);
234 u_int cpu_get_control __P((void));
235
236 /*
237 * Define the default console speed for the board. This is generally
238 * what the firmware provided with the board defaults to.
239 */
240 #ifndef CONSPEED
241 #define CONSPEED B115200
242 #endif /* ! CONSPEED */
243
244 #ifndef CONUNIT
245 #define CONUNIT 0
246 #endif
247
248 #ifndef CONMODE
249 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
250 #endif
251
252 int comcnspeed = CONSPEED;
253 int comcnmode = CONMODE;
254 int comcnunit = CONUNIT;
255
256 #if KGDB
257 #ifndef KGDB_DEVNAME
258 #error Must define KGDB_DEVNAME
259 #endif
260 const char kgdb_devname[] = KGDB_DEVNAME;
261
262 #ifndef KGDB_DEVADDR
263 #error Must define KGDB_DEVADDR
264 #endif
265 unsigned long kgdb_devaddr = KGDB_DEVADDR;
266
267 #ifndef KGDB_DEVRATE
268 #define KGDB_DEVRATE CONSPEED
269 #endif
270 int kgdb_devrate = KGDB_DEVRATE;
271
272 #ifndef KGDB_DEVMODE
273 #define KGDB_DEVMODE CONMODE
274 #endif
275 int kgdb_devmode = KGDB_DEVMODE;
276 #endif /* KGDB */
277
278 /*
279 * void cpu_reboot(int howto, char *bootstr)
280 *
281 * Reboots the system
282 *
283 * Deal with any syncing, unmounting, dumping and shutdown hooks,
284 * then reset the CPU.
285 */
286 void
287 cpu_reboot(int howto, char *bootstr)
288 {
289
290 #ifdef DIAGNOSTIC
291 /* info */
292 printf("boot: howto=%08x curproc=%p\n", howto, curproc);
293 #endif
294
295 /*
296 * If we are still cold then hit the air brakes
297 * and crash to earth fast
298 */
299 if (cold) {
300 doshutdownhooks();
301 printf("The operating system has halted.\n");
302 printf("Please press any key to reboot.\n\n");
303 cngetc();
304 goto reset;
305 }
306
307 /* Disable console buffering */
308
309 /*
310 * If RB_NOSYNC was not specified sync the discs.
311 * Note: Unless cold is set to 1 here, syslogd will die during the
312 * unmount. It looks like syslogd is getting woken up only to find
313 * that it cannot page part of the binary in as the filesystem has
314 * been unmounted.
315 */
316 if (!(howto & RB_NOSYNC))
317 bootsync();
318
319 /* Say NO to interrupts */
320 splhigh();
321
322 /* Do a dump if requested. */
323 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
324 dumpsys();
325
326 /* Run any shutdown hooks */
327 doshutdownhooks();
328
329 /* Make sure IRQ's are disabled */
330 IRQdisable;
331
332 if (howto & RB_HALT) {
333 printf("The operating system has halted.\n");
334 printf("Please press any key to %s.\n\n",
335 (howto & RB_POWERDOWN) ? "power down" : "reboot");
336 cngetc();
337 }
338
339 reset:
340 /*
341 * Make really really sure that all interrupts are disabled,
342 */
343 (void) disable_interrupts(I32_bit | F32_bit);
344
345 if (howto & RB_POWERDOWN) {
346 uint32_t reg;
347
348 printf("powering down...\n\r");
349 /* Delay to allow the UART's Tx FIFO to drain */
350 delay(50000);
351
352 #define GPRD(r) *((volatile uint32_t *)(IXP425_GPIO_VBASE+(r)))
353 #define GPWR(r,v) *((volatile uint32_t *)(IXP425_GPIO_VBASE+(r))) = (v)
354
355 /*
356 * Power-down pin requires a short pulse
357 */
358 reg = GPRD(IXP425_GPIO_GPOUTR);
359 reg |= 1u << GPIO_POWER_OFF;
360 GPWR(IXP425_GPIO_GPOUTR, reg);
361
362 delay(1000);
363
364 reg = GPRD(IXP425_GPIO_GPOUTR);
365 reg &= ~(1u << GPIO_POWER_OFF);
366 GPWR(IXP425_GPIO_GPOUTR, reg);
367
368 delay(500000);
369 printf("POWER OFF FAILED! TRYING TO REBOOT INSTEAD\n\r");
370 }
371
372 printf("rebooting...\n\r");
373
374 #define WDWR(r,v) *((volatile uint32_t *)(IXP425_TIMER_VBASE+(r))) = (v)
375 /* Force a watchdog reset */
376 WDWR(IXP425_OST_WDOG_KEY, OST_WDOG_KEY_MAJICK);
377 WDWR(IXP425_OST_WDOG_ENAB, OST_WDOG_ENAB_RST_ENA);
378 WDWR(IXP425_OST_WDOG, 0x1000);
379 WDWR(IXP425_OST_WDOG_ENAB,
380 OST_WDOG_ENAB_RST_ENA | OST_WDOG_ENAB_CNT_ENA);
381
382 delay(500000);
383
384 /* ...and if that didn't work, just croak. */
385 printf("RESET FAILED!\n");
386
387 for (;;);
388 }
389
390 /* Static device mappings. */
391 static const struct pmap_devmap nslu2_devmap[] = {
392 /* Physical/Virtual address for I/O space */
393 {
394 IXP425_IO_VBASE,
395 IXP425_IO_HWBASE,
396 IXP425_IO_SIZE,
397 VM_PROT_READ|VM_PROT_WRITE,
398 PTE_NOCACHE,
399 },
400
401 /* Expansion Bus */
402 {
403 IXP425_EXP_VBASE,
404 IXP425_EXP_HWBASE,
405 IXP425_EXP_SIZE,
406 VM_PROT_READ|VM_PROT_WRITE,
407 PTE_NOCACHE,
408 },
409
410 /* IXP425 PCI Configuration */
411 {
412 IXP425_PCI_VBASE,
413 IXP425_PCI_HWBASE,
414 IXP425_PCI_SIZE,
415 VM_PROT_READ|VM_PROT_WRITE,
416 PTE_NOCACHE,
417 },
418
419 /* SDRAM Controller */
420 {
421 IXP425_MCU_VBASE,
422 IXP425_MCU_HWBASE,
423 IXP425_MCU_SIZE,
424 VM_PROT_READ|VM_PROT_WRITE,
425 PTE_NOCACHE,
426 },
427
428 /* PCI Memory Space */
429 {
430 IXP425_PCI_MEM_VBASE,
431 IXP425_PCI_MEM_HWBASE,
432 IXP425_PCI_MEM_SIZE,
433 VM_PROT_READ|VM_PROT_WRITE,
434 PTE_NOCACHE,
435 },
436
437 /* Flash memory */
438 {
439 NSLU2_FLASH_VBASE,
440 NSLU2_FLASH_HWBASE,
441 NSLU2_FLASH_SIZE,
442 VM_PROT_READ|VM_PROT_WRITE,
443 PTE_NOCACHE,
444 },
445
446 {
447 0,
448 0,
449 0,
450 0,
451 0,
452 }
453 };
454
455 /*
456 * u_int initarm(...)
457 *
458 * Initial entry point on startup. This gets called before main() is
459 * entered.
460 * It should be responsible for setting up everything that must be
461 * in place when main is called.
462 * This includes
463 * Taking a copy of the boot configuration structure.
464 * Initialising the physical console so characters can be printed.
465 * Setting up page tables for the kernel
466 * Relocating the kernel to the bottom of physical memory
467 */
468 u_int
469 initarm(void *arg)
470 {
471 extern vaddr_t xscale_cache_clean_addr;
472 #ifdef DIAGNOSTIC
473 extern vsize_t xscale_minidata_clean_size;
474 #endif
475 int loop;
476 int loop1;
477 u_int kerneldatasize;
478 u_int l1pagetable;
479 u_int freemempos;
480 pv_addr_t kernel_l1pt;
481 uint32_t reg;
482
483 /*
484 * Make sure the power-down GPIO pin is configured correctly, as
485 * cpu_reboot() may be called early on (e.g. from within ddb(9)).
486 */
487 /* Pin is active-high, so make sure it's driven low */
488 reg = GPRD(IXP425_GPIO_GPOUTR);
489 reg &= ~(1u << GPIO_POWER_OFF);
490 GPWR(IXP425_GPIO_GPOUTR, reg);
491
492 /* Set as output */
493 reg = GPRD(IXP425_GPIO_GPOER);
494 reg &= ~(1u << GPIO_POWER_OFF);
495 GPWR(IXP425_GPIO_GPOER, reg);
496
497 /*
498 * Since we map v0xf0000000 == p0xc8000000, it's possible for
499 * us to initialize the console now.
500 */
501 consinit();
502
503 #ifdef VERBOSE_INIT_ARM
504 /* Talk to the user */
505 printf("\nNetBSD/evbarm (Linksys NSLU2) booting ...\n");
506 #endif
507
508 /*
509 * Heads up ... Setup the CPU / MMU / TLB functions
510 */
511 if (set_cpufuncs())
512 panic("cpu not recognized!");
513
514 /* XXX overwrite bootconfig to hardcoded values */
515 bootconfig.dramblocks = 1;
516 bootconfig.dram[0].address = 0x10000000;
517 bootconfig.dram[0].pages = ixp425_sdram_size() / PAGE_SIZE;
518
519 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
520
521 #ifdef VERBOSE_INIT_ARM
522 printf("kernsize=0x%x\n", kerneldatasize);
523 #endif
524 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
525
526 /*
527 * Set up the variables that define the availablilty of
528 * physical memory. For now, we're going to set
529 * physical_freestart to 0x10200000 (where the kernel
530 * was loaded), and allocate the memory we need downwards.
531 * If we get too close to the L1 table that we set up, we
532 * will panic. We will update physical_freestart and
533 * physical_freeend later to reflect what pmap_bootstrap()
534 * wants to see.
535 *
536 * XXX pmap_bootstrap() needs an enema.
537 */
538 physical_start = bootconfig.dram[0].address;
539 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
540
541 physical_freestart = physical_start
542 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
543 physical_freeend = physical_end;
544
545 physmem = (physical_end - physical_start) / PAGE_SIZE;
546
547 /* Tell the user about the memory */
548 #ifdef VERBOSE_INIT_ARM
549 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
550 physical_start, physical_end - 1);
551
552 printf("Allocating page tables\n");
553 #endif
554 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
555
556 freemempos = 0x10000000;
557
558 #ifdef VERBOSE_INIT_ARM
559 printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
560 physical_start, physical_end);
561 #endif
562
563 /* Define a macro to simplify memory allocation */
564 #define valloc_pages(var, np) \
565 alloc_pages((var).pv_pa, (np)); \
566 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
567
568 #if 0
569 #define alloc_pages(var, np) \
570 physical_freeend -= ((np) * PAGE_SIZE); \
571 if (physical_freeend < physical_freestart) \
572 panic("initarm: out of memory"); \
573 (var) = physical_freeend; \
574 free_pages -= (np); \
575 memset((char *)(var), 0, ((np) * PAGE_SIZE));
576 #else
577 #define alloc_pages(var, np) \
578 (var) = freemempos; \
579 memset((char *)(var), 0, ((np) * PAGE_SIZE)); \
580 freemempos += (np) * PAGE_SIZE;
581 #endif
582
583 loop1 = 0;
584 kernel_l1pt.pv_pa = 0;
585 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
586 /* Are we 16KB aligned for an L1 ? */
587 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
588 && kernel_l1pt.pv_pa == 0) {
589 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
590 } else {
591 valloc_pages(kernel_pt_table[loop1],
592 L2_TABLE_SIZE / PAGE_SIZE);
593 ++loop1;
594 }
595 }
596
597 /* This should never be able to happen but better confirm that. */
598 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
599 panic("initarm: Failed to align the kernel page directory");
600
601 /*
602 * Allocate a page for the system page.
603 * This page will just contain the system vectors and can be
604 * shared by all processes.
605 */
606 alloc_pages(systempage.pv_pa, 1);
607
608 /* Allocate stacks for all modes */
609 valloc_pages(irqstack, IRQ_STACK_SIZE);
610 valloc_pages(abtstack, ABT_STACK_SIZE);
611 valloc_pages(undstack, UND_STACK_SIZE);
612 valloc_pages(kernelstack, UPAGES);
613
614 /* Allocate enough pages for cleaning the Mini-Data cache. */
615 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
616 valloc_pages(minidataclean, 1);
617
618 #ifdef VERBOSE_INIT_ARM
619 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
620 irqstack.pv_va);
621 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
622 abtstack.pv_va);
623 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
624 undstack.pv_va);
625 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
626 kernelstack.pv_va);
627 #endif
628
629 /*
630 * XXX Defer this to later so that we can reclaim the memory
631 * XXX used by the RedBoot page tables.
632 */
633 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
634
635 /*
636 * Ok we have allocated physical pages for the primary kernel
637 * page tables
638 */
639
640 #ifdef VERBOSE_INIT_ARM
641 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
642 #endif
643
644 /*
645 * Now we start construction of the L1 page table
646 * We start by mapping the L2 page tables into the L1.
647 * This means that we can replace L1 mappings later on if necessary
648 */
649 l1pagetable = kernel_l1pt.pv_pa;
650
651 /* Map the L2 pages tables in the L1 page table */
652 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
653 &kernel_pt_table[KERNEL_PT_SYS]);
654 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
655 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
656 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
657 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
658 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
659 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
660
661 /* update the top of the kernel VM */
662 pmap_curmaxkvaddr =
663 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
664
665 pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE,
666 &kernel_pt_table[KERNEL_PT_IO]);
667
668 #ifdef VERBOSE_INIT_ARM
669 printf("Mapping kernel\n");
670 #endif
671
672 /* Now we fill in the L2 pagetable for the kernel static code/data */
673 {
674 extern char etext[], _end[];
675 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
676 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
677 u_int logical;
678
679 textsize = (textsize + PGOFSET) & ~PGOFSET;
680 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
681
682 logical = 0x00200000; /* offset of kernel in RAM */
683
684 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
685 physical_start + logical, textsize,
686 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
687 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
688 physical_start + logical, totalsize - textsize,
689 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
690 }
691
692 #ifdef VERBOSE_INIT_ARM
693 printf("Constructing L2 page tables\n");
694 #endif
695
696 /* Map the stack pages */
697 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
698 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
699 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
700 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
701 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
702 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
703 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
704 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
705
706 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
707 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
708
709 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
710 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
711 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
712 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
713 }
714
715 /* Map the Mini-Data cache clean area. */
716 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
717 minidataclean.pv_pa);
718
719 /* Map the vector page. */
720 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
721 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
722
723 /*
724 * Map the IXP425 registers
725 */
726 pmap_devmap_bootstrap(l1pagetable, nslu2_devmap);
727
728 /*
729 * Give the XScale global cache clean code an appropriately
730 * sized chunk of unmapped VA space starting at 0xff000000
731 * (our device mappings end before this address).
732 */
733 xscale_cache_clean_addr = 0xff000000U;
734
735 /*
736 * Now we have the real page tables in place so we can switch to them.
737 * Once this is done we will be running with the REAL kernel page
738 * tables.
739 */
740
741 /*
742 * Update the physical_freestart/physical_freeend/free_pages
743 * variables.
744 */
745 {
746 extern char _end[];
747
748 physical_freestart = physical_start +
749 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
750 KERNEL_BASE);
751 physical_freeend = physical_end;
752 free_pages =
753 (physical_freeend - physical_freestart) / PAGE_SIZE;
754 }
755
756 /* Switch tables */
757 #ifdef VERBOSE_INIT_ARM
758 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
759 physical_freestart, free_pages, free_pages);
760 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
761 #endif
762 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
763 setttb(kernel_l1pt.pv_pa);
764 cpu_tlb_flushID();
765 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
766
767 /*
768 * Moved from cpu_startup() as data_abort_handler() references
769 * this during uvm init
770 */
771 proc0paddr = (struct user *)kernelstack.pv_va;
772 lwp0.l_addr = proc0paddr;
773
774 #ifdef VERBOSE_INIT_ARM
775 printf("bootstrap done.\n");
776 #endif
777
778 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
779
780 /*
781 * Pages were allocated during the secondary bootstrap for the
782 * stacks for different CPU modes.
783 * We must now set the r13 registers in the different CPU modes to
784 * point to these stacks.
785 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
786 * of the stack memory.
787 */
788 #ifdef VERBOSE_INIT_ARM
789 printf("init subsystems: stacks ");
790 #endif
791
792 set_stackptr(PSR_IRQ32_MODE,
793 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
794 set_stackptr(PSR_ABT32_MODE,
795 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
796 set_stackptr(PSR_UND32_MODE,
797 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
798
799 /*
800 * Well we should set a data abort handler.
801 * Once things get going this will change as we will need a proper
802 * handler.
803 * Until then we will use a handler that just panics but tells us
804 * why.
805 * Initialisation of the vectors will just panic on a data abort.
806 * This just fills in a slightly better one.
807 */
808 #ifdef VERBOSE_INIT_ARM
809 printf("vectors ");
810 #endif
811 data_abort_handler_address = (u_int)data_abort_handler;
812 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
813 undefined_handler_address = (u_int)undefinedinstruction_bounce;
814
815 /* Initialise the undefined instruction handlers */
816 #ifdef VERBOSE_INIT_ARM
817 printf("undefined ");
818 #endif
819 undefined_init();
820
821 /* Load memory into UVM. */
822 #ifdef VERBOSE_INIT_ARM
823 printf("page ");
824 #endif
825 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
826 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
827 atop(physical_freestart), atop(physical_freeend),
828 VM_FREELIST_DEFAULT);
829
830 /* Boot strap pmap telling it where the kernel page table is */
831 #ifdef VERBOSE_INIT_ARM
832 printf("pmap ");
833 #endif
834 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
835 KERNEL_VM_BASE + KERNEL_VM_SIZE);
836
837 /* Setup the IRQ system */
838 #ifdef VERBOSE_INIT_ARM
839 printf("irq ");
840 #endif
841 ixp425_intr_init();
842 #ifdef VERBOSE_INIT_ARM
843 printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
844 #endif
845
846 #ifdef BOOTHOWTO
847 boothowto = BOOTHOWTO;
848 #endif
849
850 #ifdef IPKDB
851 /* Initialise ipkdb */
852 ipkdb_init();
853 if (boothowto & RB_KDB)
854 ipkdb_connect(0);
855 #endif
856
857 #if NKSYMS || defined(DDB) || defined(LKM)
858 /* Firmware doesn't load symbols. */
859 ksyms_init(0, NULL, NULL);
860 #endif
861
862 #ifdef DDB
863 db_machine_init();
864 if (boothowto & RB_KDB)
865 Debugger();
866 #endif
867
868 /* We return the new stack pointer address */
869 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
870 }
871
872 /*
873 * consinit
874 */
875 void
876 consinit(void)
877 {
878 static int consinit_called;
879 static const bus_addr_t addrs[2] = {
880 IXP425_UART0_HWBASE, IXP425_UART1_HWBASE
881 };
882
883 if (consinit_called != 0)
884 return;
885
886 consinit_called = 1;
887
888 pmap_devmap_register(nslu2_devmap);
889
890 if (comcnattach(&ixp425_a4x_bs_tag, addrs[comcnunit],
891 comcnspeed, IXP425_UART_FREQ, COM_TYPE_PXA2x0, comcnmode))
892 panic("can't init serial console (UART%d)", comcnunit);
893 }
894