brh_machdep.c revision 1.23.12.1 1 /* $NetBSD: brh_machdep.c,v 1.23.12.1 2006/05/24 15:47:53 tron Exp $ */
2
3 /*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Copyright (c) 1997,1998 Mark Brinicombe.
40 * Copyright (c) 1997,1998 Causality Limited.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by Mark Brinicombe
54 * for the NetBSD Project.
55 * 4. The name of the company nor the name of the author may be used to
56 * endorse or promote products derived from this software without specific
57 * prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
63 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * Machine dependant functions for kernel setup for the ADI Engineering
72 * BRH i80200 evaluation platform.
73 */
74
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: brh_machdep.c,v 1.23.12.1 2006/05/24 15:47:53 tron Exp $");
77
78 #include "opt_ddb.h"
79 #include "opt_pmap_debug.h"
80
81 #include <sys/param.h>
82 #include <sys/device.h>
83 #include <sys/systm.h>
84 #include <sys/kernel.h>
85 #include <sys/exec.h>
86 #include <sys/proc.h>
87 #include <sys/msgbuf.h>
88 #include <sys/reboot.h>
89 #include <sys/termios.h>
90 #include <sys/ksyms.h>
91
92 #include <uvm/uvm_extern.h>
93
94 #include <dev/cons.h>
95
96 #include <machine/db_machdep.h>
97 #include <ddb/db_sym.h>
98 #include <ddb/db_extern.h>
99
100 #include <machine/bootconfig.h>
101 #include <machine/bus.h>
102 #include <machine/cpu.h>
103 #include <machine/frame.h>
104 #include <arm/undefined.h>
105
106 #include <arm/arm32/machdep.h>
107
108 #include <arm/xscale/i80200reg.h>
109 #include <arm/xscale/i80200var.h>
110
111 #include <dev/pci/ppbreg.h>
112
113 #include <arm/xscale/beccreg.h>
114 #include <arm/xscale/beccvar.h>
115
116 #include <evbarm/adi_brh/brhreg.h>
117 #include <evbarm/adi_brh/brhvar.h>
118 #include <evbarm/adi_brh/obiovar.h>
119
120 #include "opt_ipkdb.h"
121 #include "ksyms.h"
122
123 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
124 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
125 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
126
127 /*
128 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
129 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
130 */
131 #define KERNEL_VM_SIZE 0x0C000000
132
133 /*
134 * Address to call from cpu_reset() to reset the machine.
135 * This is machine architecture dependant as it varies depending
136 * on where the ROM appears when you turn the MMU off.
137 */
138
139 u_int cpu_reset_address = 0x00000000;
140
141 /* Define various stack sizes in pages */
142 #define IRQ_STACK_SIZE 1
143 #define ABT_STACK_SIZE 1
144 #ifdef IPKDB
145 #define UND_STACK_SIZE 2
146 #else
147 #define UND_STACK_SIZE 1
148 #endif
149
150 BootConfig bootconfig; /* Boot config storage */
151 char *boot_args = NULL;
152 char *boot_file = NULL;
153
154 vm_offset_t physical_start;
155 vm_offset_t physical_freestart;
156 vm_offset_t physical_freeend;
157 vm_offset_t physical_end;
158 u_int free_pages;
159 vm_offset_t pagetables_start;
160 int physmem = 0;
161
162 /*int debug_flags;*/
163 #ifndef PMAP_STATIC_L1S
164 int max_processes = 64; /* Default number */
165 #endif /* !PMAP_STATIC_L1S */
166
167 /* Physical and virtual addresses for some global pages */
168 pv_addr_t systempage;
169 pv_addr_t irqstack;
170 pv_addr_t undstack;
171 pv_addr_t abtstack;
172 pv_addr_t kernelstack;
173 pv_addr_t minidataclean;
174
175 vm_offset_t msgbufphys;
176
177 extern u_int data_abort_handler_address;
178 extern u_int prefetch_abort_handler_address;
179 extern u_int undefined_handler_address;
180
181 #ifdef PMAP_DEBUG
182 extern int pmap_debug_level;
183 #endif
184
185 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
186
187 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
188 #define KERNEL_PT_KERNEL_NUM 2
189
190 /* L2 tables for mapping kernel VM */
191 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
192 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
193 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
194
195 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
196
197 struct user *proc0paddr;
198
199 /* Prototypes */
200
201 void consinit(void);
202
203 #include "com.h"
204 #if NCOM > 0
205 #include <dev/ic/comreg.h>
206 #include <dev/ic/comvar.h>
207 #endif
208
209 /*
210 * Define the default console speed for the board. This is generally
211 * what the firmware provided with the board defaults to.
212 */
213 #ifndef CONSPEED
214 #define CONSPEED B57600
215 #endif /* ! CONSPEED */
216
217 #ifndef CONUNIT
218 #define CONUNIT 0
219 #endif
220
221 #ifndef CONMODE
222 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
223 #endif
224
225 int comcnspeed = CONSPEED;
226 int comcnmode = CONMODE;
227 int comcnunit = CONUNIT;
228
229 /*
230 * void cpu_reboot(int howto, char *bootstr)
231 *
232 * Reboots the system
233 *
234 * Deal with any syncing, unmounting, dumping and shutdown hooks,
235 * then reset the CPU.
236 */
237 void
238 cpu_reboot(int howto, char *bootstr)
239 {
240
241 /*
242 * If we are still cold then hit the air brakes
243 * and crash to earth fast
244 */
245 if (cold) {
246 doshutdownhooks();
247 printf("The operating system has halted.\n");
248 printf("Please press any key to reboot.\n\n");
249 cngetc();
250 printf("rebooting...\n");
251 goto reset;
252 }
253
254 /* Disable console buffering */
255
256 /*
257 * If RB_NOSYNC was not specified sync the discs.
258 * Note: Unless cold is set to 1 here, syslogd will die during the
259 * unmount. It looks like syslogd is getting woken up only to find
260 * that it cannot page part of the binary in as the filesystem has
261 * been unmounted.
262 */
263 if (!(howto & RB_NOSYNC))
264 bootsync();
265
266 /* Say NO to interrupts */
267 splhigh();
268
269 /* Do a dump if requested. */
270 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
271 dumpsys();
272
273 /* Run any shutdown hooks */
274 doshutdownhooks();
275
276 /* Make sure IRQ's are disabled */
277 IRQdisable;
278
279 if (howto & RB_HALT) {
280 brh_7seg('8');
281 printf("The operating system has halted.\n");
282 printf("Please press any key to reboot.\n\n");
283 cngetc();
284 }
285
286 printf("rebooting...\n\r");
287 reset:
288 cpu_reset();
289 }
290
291 /* Static device mappings. */
292 static const struct pmap_devmap brh_devmap[] = {
293 {
294 BRH_PCI_CONF_VBASE,
295 BECC_PCI_CONF_BASE,
296 BRH_PCI_CONF_VSIZE,
297 VM_PROT_READ|VM_PROT_WRITE,
298 PTE_NOCACHE,
299 },
300 {
301 BRH_PCI_MEM1_VBASE,
302 BECC_PCI_MEM1_BASE,
303 BRH_PCI_MEM1_VSIZE,
304 VM_PROT_READ|VM_PROT_WRITE,
305 PTE_NOCACHE,
306 },
307 {
308 BRH_PCI_MEM2_VBASE,
309 BECC_PCI_MEM2_BASE,
310 BRH_PCI_MEM2_VSIZE,
311 VM_PROT_READ|VM_PROT_WRITE,
312 PTE_NOCACHE,
313 },
314 {
315 BRH_UART1_VBASE,
316 BRH_UART1_BASE,
317 BRH_UART1_VSIZE,
318 VM_PROT_READ|VM_PROT_WRITE,
319 PTE_NOCACHE,
320 },
321 {
322 BRH_UART2_VBASE,
323 BRH_UART2_BASE,
324 BRH_UART2_VSIZE,
325 VM_PROT_READ|VM_PROT_WRITE,
326 PTE_NOCACHE,
327 },
328 {
329 BRH_LED_VBASE,
330 BRH_LED_BASE,
331 BRH_LED_VSIZE,
332 VM_PROT_READ|VM_PROT_WRITE,
333 PTE_NOCACHE,
334 },
335 {
336 BRH_PCI_IO_VBASE,
337 BECC_PCI_IO_BASE,
338 BRH_PCI_IO_VSIZE,
339 VM_PROT_READ|VM_PROT_WRITE,
340 PTE_NOCACHE,
341 },
342 {
343 BRH_BECC_VBASE,
344 BECC_REG_BASE,
345 BRH_BECC_VSIZE,
346 VM_PROT_READ|VM_PROT_WRITE,
347 PTE_NOCACHE,
348 },
349 {
350 0,
351 0,
352 0,
353 0,
354 0,
355 }
356 };
357
358 static void
359 brh_hardclock_hook(void)
360 {
361 static int snakefreq;
362
363 if ((snakefreq++ & 15) == 0)
364 brh_7seg_snake();
365 }
366
367 /*
368 * u_int initarm(...)
369 *
370 * Initial entry point on startup. This gets called before main() is
371 * entered.
372 * It should be responsible for setting up everything that must be
373 * in place when main is called.
374 * This includes
375 * Taking a copy of the boot configuration structure.
376 * Initialising the physical console so characters can be printed.
377 * Setting up page tables for the kernel
378 * Relocating the kernel to the bottom of physical memory
379 */
380 u_int
381 initarm(void *arg)
382 {
383 extern vaddr_t xscale_cache_clean_addr;
384 #ifdef DIAGNOSTIC
385 extern vsize_t xscale_minidata_clean_size;
386 #endif
387 int loop;
388 int loop1;
389 u_int l1pagetable;
390 pv_addr_t kernel_l1pt;
391 paddr_t memstart;
392 psize_t memsize;
393
394 kernel_l1pt.pv_pa = 0;
395 kernel_l1pt.pv_va = 0;
396
397 /*
398 * Clear out the 7-segment display. Whee, the first visual
399 * indication that we're running kernel code.
400 */
401 brh_7seg(' ');
402
403 /*
404 * Since we have mapped the on-board devices at their permanent
405 * locations already, it is possible for us to initialize
406 * the console now.
407 */
408 consinit();
409
410 #ifdef VERBOSE_INIT_ARM
411 /* Talk to the user */
412 printf("\nNetBSD/evbarm (ADI BRH) booting ...\n");
413 #endif
414
415 /* Calibrate the delay loop. */
416 becc_hardclock_hook = brh_hardclock_hook;
417
418 /*
419 * Heads up ... Setup the CPU / MMU / TLB functions
420 */
421 if (set_cpufuncs())
422 panic("CPU not recognized!");
423
424 /*
425 * We are currently running with the MMU enabled and the
426 * entire address space mapped VA==PA. Memory conveniently
427 * starts at 0xc0000000, which is where we want it. Certain
428 * on-board devices have already been mapped where we want
429 * them to be. There is an L1 page table at 0xc0004000.
430 */
431
432 becc_icu_init();
433
434 /*
435 * Memory always starts at 0xc0000000 on a BRH, and the
436 * memory size is always 128M.
437 */
438 memstart = 0xc0000000UL;
439 memsize = (128UL * 1024 * 1024);
440
441 #ifdef VERBOSE_INIT_ARM
442 printf("initarm: Configuring system ...\n");
443 #endif
444
445 /* Fake bootconfig structure for the benefit of pmap.c */
446 /* XXX must make the memory description h/w independant */
447 bootconfig.dramblocks = 1;
448 bootconfig.dram[0].address = memstart;
449 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
450
451 /*
452 * Set up the variables that define the availablilty of
453 * physical memory. For now, we're going to set
454 * physical_freestart to 0xc0200000 (where the kernel
455 * was loaded), and allocate the memory we need downwards.
456 * If we get too close to the L1 table that we set up, we
457 * will panic. We will update physical_freestart and
458 * physical_freeend later to reflect what pmap_bootstrap()
459 * wants to see.
460 *
461 * XXX pmap_bootstrap() needs an enema.
462 */
463 physical_start = bootconfig.dram[0].address;
464 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
465
466 physical_freestart = 0xc0009000UL;
467 physical_freeend = 0xc0200000UL;
468
469 #ifdef VERBOSE_INIT_ARM
470 /* Tell the user about the memory */
471 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
472 physical_start, physical_end - 1);
473 #endif
474
475 /*
476 * Okay, the kernel starts 2MB in from the bottom of physical
477 * memory. We are going to allocate our bootstrap pages downwards
478 * from there.
479 *
480 * We need to allocate some fixed page tables to get the kernel
481 * going. We allocate one page directory and a number of page
482 * tables and store the physical addresses in the kernel_pt_table
483 * array.
484 *
485 * The kernel page directory must be on a 16K boundary. The page
486 * tables must be on 4K boundaries. What we do is allocate the
487 * page directory on the first 16K boundary that we encounter, and
488 * the page tables on 4K boundaries otherwise. Since we allocate
489 * at least 3 L2 page tables, we are guaranteed to encounter at
490 * least one 16K aligned region.
491 */
492
493 #ifdef VERBOSE_INIT_ARM
494 printf("Allocating page tables\n");
495 #endif
496
497 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
498
499 #ifdef VERBOSE_INIT_ARM
500 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
501 physical_freestart, free_pages, free_pages);
502 #endif
503
504 /* Define a macro to simplify memory allocation */
505 #define valloc_pages(var, np) \
506 alloc_pages((var).pv_pa, (np)); \
507 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
508
509 #define alloc_pages(var, np) \
510 physical_freeend -= ((np) * PAGE_SIZE); \
511 if (physical_freeend < physical_freestart) \
512 panic("initarm: out of memory"); \
513 (var) = physical_freeend; \
514 free_pages -= (np); \
515 memset((char *)(var), 0, ((np) * PAGE_SIZE));
516
517 loop1 = 0;
518 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
519 /* Are we 16KB aligned for an L1 ? */
520 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
521 && kernel_l1pt.pv_pa == 0) {
522 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
523 } else {
524 valloc_pages(kernel_pt_table[loop1],
525 L2_TABLE_SIZE / PAGE_SIZE);
526 ++loop1;
527 }
528 }
529
530 /* This should never be able to happen but better confirm that. */
531 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
532 panic("initarm: Failed to align the kernel page directory\n");
533
534 /*
535 * Allocate a page for the system page mapped to V0x00000000
536 * This page will just contain the system vectors and can be
537 * shared by all processes.
538 */
539 alloc_pages(systempage.pv_pa, 1);
540
541 /* Allocate stacks for all modes */
542 valloc_pages(irqstack, IRQ_STACK_SIZE);
543 valloc_pages(abtstack, ABT_STACK_SIZE);
544 valloc_pages(undstack, UND_STACK_SIZE);
545 valloc_pages(kernelstack, UPAGES);
546
547 /* Allocate enough pages for cleaning the Mini-Data cache. */
548 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
549 valloc_pages(minidataclean, 1);
550
551 #ifdef VERBOSE_INIT_ARM
552 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
553 irqstack.pv_va);
554 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
555 abtstack.pv_va);
556 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
557 undstack.pv_va);
558 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
559 kernelstack.pv_va);
560 #endif
561
562 /*
563 * XXX Defer this to later so that we can reclaim the memory
564 * XXX used by the RedBoot page tables.
565 */
566 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
567
568 /*
569 * Ok we have allocated physical pages for the primary kernel
570 * page tables
571 */
572
573 #ifdef VERBOSE_INIT_ARM
574 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
575 #endif
576
577 /*
578 * Now we start construction of the L1 page table
579 * We start by mapping the L2 page tables into the L1.
580 * This means that we can replace L1 mappings later on if necessary
581 */
582 l1pagetable = kernel_l1pt.pv_pa;
583
584 /* Map the L2 pages tables in the L1 page table */
585 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
586 &kernel_pt_table[KERNEL_PT_SYS]);
587 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
588 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
589 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
590 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
591 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
592 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
593
594 /* update the top of the kernel VM */
595 pmap_curmaxkvaddr =
596 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
597
598 #ifdef VERBOSE_INIT_ARM
599 printf("Mapping kernel\n");
600 #endif
601
602 /* Now we fill in the L2 pagetable for the kernel static code/data */
603 {
604 extern char etext[], _end[];
605 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
606 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
607 u_int logical;
608
609 textsize = (textsize + PGOFSET) & ~PGOFSET;
610 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
611
612 logical = 0x00200000; /* offset of kernel in RAM */
613
614 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
615 physical_start + logical, textsize,
616 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
617 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
618 physical_start + logical, totalsize - textsize,
619 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
620 }
621
622 #ifdef VERBOSE_INIT_ARM
623 printf("Constructing L2 page tables\n");
624 #endif
625
626 /* Map the stack pages */
627 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
628 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
629 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
630 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
631 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
632 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
633 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
634 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
635
636 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
637 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
638
639 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
640 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
641 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
642 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
643 }
644
645 /* Map the Mini-Data cache clean area. */
646 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
647 minidataclean.pv_pa);
648
649 /* Map the vector page. */
650 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
651 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
652
653 /* Map the statically mapped devices. */
654 pmap_devmap_bootstrap(l1pagetable, brh_devmap);
655
656 /*
657 * Give the XScale global cache clean code an appropriately
658 * sized chunk of unmapped VA space starting at 0xff500000
659 * (our device mappings end before this address).
660 */
661 xscale_cache_clean_addr = 0xff500000U;
662
663 /*
664 * Now we have the real page tables in place so we can switch to them.
665 * Once this is done we will be running with the REAL kernel page
666 * tables.
667 */
668
669 /* Switch tables */
670 #ifdef VERBOSE_INIT_ARM
671 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
672 #endif
673 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
674 setttb(kernel_l1pt.pv_pa);
675 cpu_tlb_flushID();
676 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
677
678 /*
679 * Move from cpu_startup() as data_abort_handler() references
680 * this during uvm init
681 */
682 proc0paddr = (struct user *)kernelstack.pv_va;
683 lwp0.l_addr = proc0paddr;
684
685 #ifdef VERBOSE_INIT_ARM
686 printf("done!\n");
687 #endif
688
689 #ifdef VERBOSE_INIT_ARM
690 printf("bootstrap done.\n");
691 #endif
692
693 /*
694 * Inform the BECC code where the BECC is mapped.
695 */
696 becc_vaddr = BRH_BECC_VBASE;
697
698 /*
699 * Now that we have becc_vaddr set, calibrate delay.
700 */
701 becc_calibrate_delay();
702
703 /*
704 * BECC <= Rev7 can only address 64M through the inbound
705 * PCI windows. Limit memory to 64M on those revs. (This
706 * problem was fixed in Rev8 of the BECC; get an FPGA upgrade.)
707 */
708 {
709 vaddr_t va = BRH_PCI_CONF_VBASE | (1U << BECC_IDSEL_BIT) |
710 PCI_CLASS_REG;
711 uint32_t reg;
712
713 reg = *(volatile uint32_t *) va;
714 becc_rev = PCI_REVISION(reg);
715 if (becc_rev <= BECC_REV_V7 &&
716 memsize > (64UL * 1024 * 1024)) {
717 memsize = (64UL * 1024 * 1024);
718 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
719 physical_end = physical_start +
720 (bootconfig.dram[0].pages * PAGE_SIZE);
721 printf("BECC <= Rev7: memory truncated to 64M\n");
722 }
723 }
724
725 /*
726 * Update the physical_freestart/physical_freeend/free_pages
727 * variables.
728 */
729 {
730 extern char _end[];
731
732 physical_freestart = physical_start +
733 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
734 KERNEL_BASE);
735 physical_freeend = physical_end;
736 free_pages =
737 (physical_freeend - physical_freestart) / PAGE_SIZE;
738 }
739 #ifdef VERBOSE_INIT_ARM
740 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
741 physical_freestart, free_pages, free_pages);
742 #endif
743
744 physmem = (physical_end - physical_start) / PAGE_SIZE;
745
746 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
747
748 /*
749 * Pages were allocated during the secondary bootstrap for the
750 * stacks for different CPU modes.
751 * We must now set the r13 registers in the different CPU modes to
752 * point to these stacks.
753 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
754 * of the stack memory.
755 */
756 #ifdef VERBOSE_INIT_ARM
757 printf("init subsystems: stacks ");
758 #endif
759
760 set_stackptr(PSR_IRQ32_MODE,
761 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
762 set_stackptr(PSR_ABT32_MODE,
763 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
764 set_stackptr(PSR_UND32_MODE,
765 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
766
767 /*
768 * Well we should set a data abort handler.
769 * Once things get going this will change as we will need a proper
770 * handler.
771 * Until then we will use a handler that just panics but tells us
772 * why.
773 * Initialisation of the vectors will just panic on a data abort.
774 * This just fills in a slightly better one.
775 */
776 #ifdef VERBOSE_INIT_ARM
777 printf("vectors ");
778 #endif
779 data_abort_handler_address = (u_int)data_abort_handler;
780 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
781 undefined_handler_address = (u_int)undefinedinstruction_bounce;
782
783 /* Initialise the undefined instruction handlers */
784 #ifdef VERBOSE_INIT_ARM
785 printf("undefined ");
786 #endif
787 undefined_init();
788
789 /* Load memory into UVM. */
790 #ifdef VERBOSE_INIT_ARM
791 printf("page ");
792 #endif
793 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
794 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
795 atop(physical_freestart), atop(physical_freeend),
796 VM_FREELIST_DEFAULT);
797
798 /* Boot strap pmap telling it where the kernel page table is */
799 #ifdef VERBOSE_INIT_ARM
800 printf("pmap ");
801 #endif
802 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
803 KERNEL_VM_BASE + KERNEL_VM_SIZE);
804
805 /* Setup the IRQ system */
806 #ifdef VERBOSE_INIT_ARM
807 printf("irq ");
808 #endif
809 becc_intr_init();
810 #ifdef VERBOSE_INIT_ARM
811 printf("done.\n");
812 #endif
813
814 #ifdef IPKDB
815 /* Initialise ipkdb */
816 ipkdb_init();
817 if (boothowto & RB_KDB)
818 ipkdb_connect(0);
819 #endif
820
821
822 #if NKSYMS || defined(DDB) || defined(LKM)
823 /* Firmware doesn't load symbols. */
824 ksyms_init(0, NULL, NULL);
825 #endif
826
827 #ifdef DDB
828 db_machine_init();
829 if (boothowto & RB_KDB)
830 Debugger();
831 #endif
832
833 /* We return the new stack pointer address */
834 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
835 }
836
837 void
838 consinit(void)
839 {
840 static const bus_addr_t comcnaddrs[] = {
841 BRH_UART1_BASE, /* com0 */
842 BRH_UART2_BASE, /* com1 */
843 };
844 static int consinit_called;
845
846 if (consinit_called != 0)
847 return;
848
849 consinit_called = 1;
850
851 /*
852 * brh_start() has mapped the console devices for us per
853 * the devmap, so register it now so drivers can map the
854 * console device.
855 */
856 pmap_devmap_register(brh_devmap);
857
858 #if NCOM > 0
859 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
860 BECC_PERIPH_CLOCK, COM_TYPE_NORMAL, comcnmode))
861 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
862 #else
863 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
864 #endif
865 }
866