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