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