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