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