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