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