brh_machdep.c revision 1.26.42.1 1 /* $NetBSD: brh_machdep.c,v 1.26.42.1 2008/01/20 17:51:08 bouyer 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.26.42.1 2008/01/20 17:51:08 bouyer 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 "ksyms.h"
121
122 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
123 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
124 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
125
126 /*
127 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
128 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
129 */
130 #define KERNEL_VM_SIZE 0x0C000000
131
132 /*
133 * Address to call from cpu_reset() to reset the machine.
134 * This is machine architecture dependant as it varies depending
135 * on where the ROM appears when you turn the MMU off.
136 */
137
138 u_int cpu_reset_address = 0x00000000;
139
140 /* Define various stack sizes in pages */
141 #define IRQ_STACK_SIZE 1
142 #define ABT_STACK_SIZE 1
143 #define UND_STACK_SIZE 1
144
145 BootConfig bootconfig; /* Boot config storage */
146 char *boot_args = NULL;
147 char *boot_file = NULL;
148
149 vm_offset_t physical_start;
150 vm_offset_t physical_freestart;
151 vm_offset_t physical_freeend;
152 vm_offset_t physical_end;
153 u_int free_pages;
154 vm_offset_t pagetables_start;
155 int physmem = 0;
156
157 /*int debug_flags;*/
158 #ifndef PMAP_STATIC_L1S
159 int max_processes = 64; /* Default number */
160 #endif /* !PMAP_STATIC_L1S */
161
162 /* Physical and virtual addresses for some global pages */
163 pv_addr_t systempage;
164 pv_addr_t irqstack;
165 pv_addr_t undstack;
166 pv_addr_t abtstack;
167 pv_addr_t kernelstack;
168 pv_addr_t minidataclean;
169
170 vm_offset_t msgbufphys;
171
172 extern u_int data_abort_handler_address;
173 extern u_int prefetch_abort_handler_address;
174 extern u_int undefined_handler_address;
175
176 #ifdef PMAP_DEBUG
177 extern int pmap_debug_level;
178 #endif
179
180 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
181
182 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
183 #define KERNEL_PT_KERNEL_NUM 2
184
185 /* L2 tables for mapping kernel VM */
186 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
187 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
188 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
189
190 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
191
192 struct user *proc0paddr;
193
194 /* Prototypes */
195
196 void consinit(void);
197
198 #include "com.h"
199 #if NCOM > 0
200 #include <dev/ic/comreg.h>
201 #include <dev/ic/comvar.h>
202 #endif
203
204 /*
205 * Define the default console speed for the board. This is generally
206 * what the firmware provided with the board defaults to.
207 */
208 #ifndef CONSPEED
209 #define CONSPEED B57600
210 #endif /* ! CONSPEED */
211
212 #ifndef CONUNIT
213 #define CONUNIT 0
214 #endif
215
216 #ifndef CONMODE
217 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
218 #endif
219
220 int comcnspeed = CONSPEED;
221 int comcnmode = CONMODE;
222 int comcnunit = CONUNIT;
223
224 /*
225 * void cpu_reboot(int howto, char *bootstr)
226 *
227 * Reboots the system
228 *
229 * Deal with any syncing, unmounting, dumping and shutdown hooks,
230 * then reset the CPU.
231 */
232 void
233 cpu_reboot(int howto, char *bootstr)
234 {
235
236 /*
237 * If we are still cold then hit the air brakes
238 * and crash to earth fast
239 */
240 if (cold) {
241 doshutdownhooks();
242 printf("The operating system has halted.\n");
243 printf("Please press any key to reboot.\n\n");
244 cngetc();
245 printf("rebooting...\n");
246 goto reset;
247 }
248
249 /* Disable console buffering */
250
251 /*
252 * If RB_NOSYNC was not specified sync the discs.
253 * Note: Unless cold is set to 1 here, syslogd will die during the
254 * unmount. It looks like syslogd is getting woken up only to find
255 * that it cannot page part of the binary in as the filesystem has
256 * been unmounted.
257 */
258 if (!(howto & RB_NOSYNC))
259 bootsync();
260
261 /* Say NO to interrupts */
262 splhigh();
263
264 /* Do a dump if requested. */
265 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
266 dumpsys();
267
268 /* Run any shutdown hooks */
269 doshutdownhooks();
270
271 /* Make sure IRQ's are disabled */
272 IRQdisable;
273
274 if (howto & RB_HALT) {
275 brh_7seg('8');
276 printf("The operating system has halted.\n");
277 printf("Please press any key to reboot.\n\n");
278 cngetc();
279 }
280
281 printf("rebooting...\n\r");
282 reset:
283 cpu_reset();
284 }
285
286 /* Static device mappings. */
287 static const struct pmap_devmap brh_devmap[] = {
288 {
289 BRH_PCI_CONF_VBASE,
290 BECC_PCI_CONF_BASE,
291 BRH_PCI_CONF_VSIZE,
292 VM_PROT_READ|VM_PROT_WRITE,
293 PTE_NOCACHE,
294 },
295 {
296 BRH_PCI_MEM1_VBASE,
297 BECC_PCI_MEM1_BASE,
298 BRH_PCI_MEM1_VSIZE,
299 VM_PROT_READ|VM_PROT_WRITE,
300 PTE_NOCACHE,
301 },
302 {
303 BRH_PCI_MEM2_VBASE,
304 BECC_PCI_MEM2_BASE,
305 BRH_PCI_MEM2_VSIZE,
306 VM_PROT_READ|VM_PROT_WRITE,
307 PTE_NOCACHE,
308 },
309 {
310 BRH_UART1_VBASE,
311 BRH_UART1_BASE,
312 BRH_UART1_VSIZE,
313 VM_PROT_READ|VM_PROT_WRITE,
314 PTE_NOCACHE,
315 },
316 {
317 BRH_UART2_VBASE,
318 BRH_UART2_BASE,
319 BRH_UART2_VSIZE,
320 VM_PROT_READ|VM_PROT_WRITE,
321 PTE_NOCACHE,
322 },
323 {
324 BRH_LED_VBASE,
325 BRH_LED_BASE,
326 BRH_LED_VSIZE,
327 VM_PROT_READ|VM_PROT_WRITE,
328 PTE_NOCACHE,
329 },
330 {
331 BRH_PCI_IO_VBASE,
332 BECC_PCI_IO_BASE,
333 BRH_PCI_IO_VSIZE,
334 VM_PROT_READ|VM_PROT_WRITE,
335 PTE_NOCACHE,
336 },
337 {
338 BRH_BECC_VBASE,
339 BECC_REG_BASE,
340 BRH_BECC_VSIZE,
341 VM_PROT_READ|VM_PROT_WRITE,
342 PTE_NOCACHE,
343 },
344 {
345 0,
346 0,
347 0,
348 0,
349 0,
350 }
351 };
352
353 static void
354 brh_hardclock_hook(void)
355 {
356 static int snakefreq;
357
358 if ((snakefreq++ & 15) == 0)
359 brh_7seg_snake();
360 }
361
362 /*
363 * u_int 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 u_int
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 l1pagetable;
385 pv_addr_t kernel_l1pt;
386 paddr_t memstart;
387 psize_t memsize;
388
389 kernel_l1pt.pv_pa = 0;
390 kernel_l1pt.pv_va = 0;
391
392 /*
393 * Clear out the 7-segment display. Whee, the first visual
394 * indication that we're running kernel code.
395 */
396 brh_7seg(' ');
397
398 /*
399 * Since we have mapped the on-board devices at their permanent
400 * locations already, it is possible for us to initialize
401 * the console now.
402 */
403 consinit();
404
405 #ifdef VERBOSE_INIT_ARM
406 /* Talk to the user */
407 printf("\nNetBSD/evbarm (ADI BRH) booting ...\n");
408 #endif
409
410 /* Calibrate the delay loop. */
411 becc_hardclock_hook = brh_hardclock_hook;
412
413 /*
414 * Heads up ... Setup the CPU / MMU / TLB functions
415 */
416 if (set_cpufuncs())
417 panic("CPU not recognized!");
418
419 /*
420 * We are currently running with the MMU enabled and the
421 * entire address space mapped VA==PA. Memory conveniently
422 * starts at 0xc0000000, which is where we want it. Certain
423 * on-board devices have already been mapped where we want
424 * them to be. There is an L1 page table at 0xc0004000.
425 */
426
427 becc_icu_init();
428
429 /*
430 * Memory always starts at 0xc0000000 on a BRH, and the
431 * memory size is always 128M.
432 */
433 memstart = 0xc0000000UL;
434 memsize = (128UL * 1024 * 1024);
435
436 #ifdef VERBOSE_INIT_ARM
437 printf("initarm: Configuring system ...\n");
438 #endif
439
440 /* Fake bootconfig structure for the benefit of pmap.c */
441 /* XXX must make the memory description h/w independent */
442 bootconfig.dramblocks = 1;
443 bootconfig.dram[0].address = memstart;
444 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
445
446 /*
447 * Set up the variables that define the availablilty of
448 * physical memory. For now, we're going to set
449 * physical_freestart to 0xc0200000 (where the kernel
450 * was loaded), and allocate the memory we need downwards.
451 * If we get too close to the L1 table that we set up, we
452 * will panic. We will update physical_freestart and
453 * physical_freeend later to reflect what pmap_bootstrap()
454 * wants to see.
455 *
456 * XXX pmap_bootstrap() needs an enema.
457 */
458 physical_start = bootconfig.dram[0].address;
459 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
460
461 physical_freestart = 0xc0009000UL;
462 physical_freeend = 0xc0200000UL;
463
464 #ifdef VERBOSE_INIT_ARM
465 /* Tell the user about the memory */
466 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
467 physical_start, physical_end - 1);
468 #endif
469
470 /*
471 * Okay, the kernel starts 2MB in from the bottom of physical
472 * memory. We are going to allocate our bootstrap pages downwards
473 * from there.
474 *
475 * We need to allocate some fixed page tables to get the kernel
476 * going. We allocate one page directory and a number of page
477 * tables and store the physical addresses in the kernel_pt_table
478 * array.
479 *
480 * The kernel page directory must be on a 16K boundary. The page
481 * tables must be on 4K boundaries. What we do is allocate the
482 * page directory on the first 16K boundary that we encounter, and
483 * the page tables on 4K boundaries otherwise. Since we allocate
484 * at least 3 L2 page tables, we are guaranteed to encounter at
485 * least one 16K aligned region.
486 */
487
488 #ifdef VERBOSE_INIT_ARM
489 printf("Allocating page tables\n");
490 #endif
491
492 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
493
494 #ifdef VERBOSE_INIT_ARM
495 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
496 physical_freestart, free_pages, free_pages);
497 #endif
498
499 /* Define a macro to simplify memory allocation */
500 #define valloc_pages(var, np) \
501 alloc_pages((var).pv_pa, (np)); \
502 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
503
504 #define alloc_pages(var, np) \
505 physical_freeend -= ((np) * PAGE_SIZE); \
506 if (physical_freeend < physical_freestart) \
507 panic("initarm: out of memory"); \
508 (var) = physical_freeend; \
509 free_pages -= (np); \
510 memset((char *)(var), 0, ((np) * PAGE_SIZE));
511
512 loop1 = 0;
513 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
514 /* Are we 16KB aligned for an L1 ? */
515 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
516 && kernel_l1pt.pv_pa == 0) {
517 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
518 } else {
519 valloc_pages(kernel_pt_table[loop1],
520 L2_TABLE_SIZE / PAGE_SIZE);
521 ++loop1;
522 }
523 }
524
525 /* This should never be able to happen but better confirm that. */
526 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
527 panic("initarm: Failed to align the kernel page directory\n");
528
529 /*
530 * Allocate a page for the system page mapped to V0x00000000
531 * This page will just contain the system vectors and can be
532 * shared by all processes.
533 */
534 alloc_pages(systempage.pv_pa, 1);
535
536 /* Allocate stacks for all modes */
537 valloc_pages(irqstack, IRQ_STACK_SIZE);
538 valloc_pages(abtstack, ABT_STACK_SIZE);
539 valloc_pages(undstack, UND_STACK_SIZE);
540 valloc_pages(kernelstack, UPAGES);
541
542 /* Allocate enough pages for cleaning the Mini-Data cache. */
543 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
544 valloc_pages(minidataclean, 1);
545
546 #ifdef VERBOSE_INIT_ARM
547 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
548 irqstack.pv_va);
549 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
550 abtstack.pv_va);
551 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
552 undstack.pv_va);
553 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
554 kernelstack.pv_va);
555 #endif
556
557 /*
558 * XXX Defer this to later so that we can reclaim the memory
559 * XXX used by the RedBoot page tables.
560 */
561 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
562
563 /*
564 * Ok we have allocated physical pages for the primary kernel
565 * page tables
566 */
567
568 #ifdef VERBOSE_INIT_ARM
569 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
570 #endif
571
572 /*
573 * Now we start construction of the L1 page table
574 * We start by mapping the L2 page tables into the L1.
575 * This means that we can replace L1 mappings later on if necessary
576 */
577 l1pagetable = kernel_l1pt.pv_pa;
578
579 /* Map the L2 pages tables in the L1 page table */
580 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
581 &kernel_pt_table[KERNEL_PT_SYS]);
582 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
583 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
584 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
585 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
586 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
587 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
588
589 /* update the top of the kernel VM */
590 pmap_curmaxkvaddr =
591 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
592
593 #ifdef VERBOSE_INIT_ARM
594 printf("Mapping kernel\n");
595 #endif
596
597 /* Now we fill in the L2 pagetable for the kernel static code/data */
598 {
599 extern char etext[], _end[];
600 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
601 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
602 u_int logical;
603
604 textsize = (textsize + PGOFSET) & ~PGOFSET;
605 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
606
607 logical = 0x00200000; /* offset of kernel in RAM */
608
609 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
610 physical_start + logical, textsize,
611 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
612 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
613 physical_start + logical, totalsize - textsize,
614 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
615 }
616
617 #ifdef VERBOSE_INIT_ARM
618 printf("Constructing L2 page tables\n");
619 #endif
620
621 /* Map the stack pages */
622 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
623 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
624 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
625 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
626 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
627 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
628 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
629 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
630
631 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
632 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
633
634 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
635 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
636 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
637 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
638 }
639
640 /* Map the Mini-Data cache clean area. */
641 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
642 minidataclean.pv_pa);
643
644 /* Map the vector page. */
645 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
646 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
647
648 /* Map the statically mapped devices. */
649 pmap_devmap_bootstrap(l1pagetable, brh_devmap);
650
651 /*
652 * Give the XScale global cache clean code an appropriately
653 * sized chunk of unmapped VA space starting at 0xff500000
654 * (our device mappings end before this address).
655 */
656 xscale_cache_clean_addr = 0xff500000U;
657
658 /*
659 * Now we have the real page tables in place so we can switch to them.
660 * Once this is done we will be running with the REAL kernel page
661 * tables.
662 */
663
664 /* Switch tables */
665 #ifdef VERBOSE_INIT_ARM
666 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
667 #endif
668 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
669 setttb(kernel_l1pt.pv_pa);
670 cpu_tlb_flushID();
671 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
672
673 /*
674 * Move from cpu_startup() as data_abort_handler() references
675 * this during uvm init
676 */
677 proc0paddr = (struct user *)kernelstack.pv_va;
678 lwp0.l_addr = proc0paddr;
679
680 #ifdef VERBOSE_INIT_ARM
681 printf("done!\n");
682 #endif
683
684 #ifdef VERBOSE_INIT_ARM
685 printf("bootstrap done.\n");
686 #endif
687
688 /*
689 * Inform the BECC code where the BECC is mapped.
690 */
691 becc_vaddr = BRH_BECC_VBASE;
692
693 /*
694 * Now that we have becc_vaddr set, calibrate delay.
695 */
696 becc_calibrate_delay();
697
698 /*
699 * BECC <= Rev7 can only address 64M through the inbound
700 * PCI windows. Limit memory to 64M on those revs. (This
701 * problem was fixed in Rev8 of the BECC; get an FPGA upgrade.)
702 */
703 {
704 vaddr_t va = BRH_PCI_CONF_VBASE | (1U << BECC_IDSEL_BIT) |
705 PCI_CLASS_REG;
706 uint32_t reg;
707
708 reg = *(volatile uint32_t *) va;
709 becc_rev = PCI_REVISION(reg);
710 if (becc_rev <= BECC_REV_V7 &&
711 memsize > (64UL * 1024 * 1024)) {
712 memsize = (64UL * 1024 * 1024);
713 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
714 physical_end = physical_start +
715 (bootconfig.dram[0].pages * PAGE_SIZE);
716 printf("BECC <= Rev7: memory truncated to 64M\n");
717 }
718 }
719
720 /*
721 * Update the physical_freestart/physical_freeend/free_pages
722 * variables.
723 */
724 {
725 extern char _end[];
726
727 physical_freestart = physical_start +
728 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
729 KERNEL_BASE);
730 physical_freeend = physical_end;
731 free_pages =
732 (physical_freeend - physical_freestart) / PAGE_SIZE;
733 }
734 #ifdef VERBOSE_INIT_ARM
735 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
736 physical_freestart, free_pages, free_pages);
737 #endif
738
739 physmem = (physical_end - physical_start) / PAGE_SIZE;
740
741 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
742
743 /*
744 * Pages were allocated during the secondary bootstrap for the
745 * stacks for different CPU modes.
746 * We must now set the r13 registers in the different CPU modes to
747 * point to these stacks.
748 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
749 * of the stack memory.
750 */
751 #ifdef VERBOSE_INIT_ARM
752 printf("init subsystems: stacks ");
753 #endif
754
755 set_stackptr(PSR_IRQ32_MODE,
756 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
757 set_stackptr(PSR_ABT32_MODE,
758 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
759 set_stackptr(PSR_UND32_MODE,
760 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
761
762 /*
763 * Well we should set a data abort handler.
764 * Once things get going this will change as we will need a proper
765 * handler.
766 * Until then we will use a handler that just panics but tells us
767 * why.
768 * Initialisation of the vectors will just panic on a data abort.
769 * This just fills in a slightly better one.
770 */
771 #ifdef VERBOSE_INIT_ARM
772 printf("vectors ");
773 #endif
774 data_abort_handler_address = (u_int)data_abort_handler;
775 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
776 undefined_handler_address = (u_int)undefinedinstruction_bounce;
777
778 /* Initialise the undefined instruction handlers */
779 #ifdef VERBOSE_INIT_ARM
780 printf("undefined ");
781 #endif
782 undefined_init();
783
784 /* Load memory into UVM. */
785 #ifdef VERBOSE_INIT_ARM
786 printf("page ");
787 #endif
788 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
789 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
790 atop(physical_freestart), atop(physical_freeend),
791 VM_FREELIST_DEFAULT);
792
793 /* Boot strap pmap telling it where the kernel page table is */
794 #ifdef VERBOSE_INIT_ARM
795 printf("pmap ");
796 #endif
797 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
798 KERNEL_VM_BASE + KERNEL_VM_SIZE);
799
800 /* Setup the IRQ system */
801 #ifdef VERBOSE_INIT_ARM
802 printf("irq ");
803 #endif
804 becc_intr_init();
805 #ifdef VERBOSE_INIT_ARM
806 printf("done.\n");
807 #endif
808
809 #if NKSYMS || defined(DDB) || defined(LKM)
810 /* Firmware doesn't load symbols. */
811 ksyms_init(0, NULL, NULL);
812 #endif
813
814 #ifdef DDB
815 db_machine_init();
816 if (boothowto & RB_KDB)
817 Debugger();
818 #endif
819
820 /* We return the new stack pointer address */
821 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
822 }
823
824 void
825 consinit(void)
826 {
827 static const bus_addr_t comcnaddrs[] = {
828 BRH_UART1_BASE, /* com0 */
829 BRH_UART2_BASE, /* com1 */
830 };
831 static int consinit_called;
832
833 if (consinit_called != 0)
834 return;
835
836 consinit_called = 1;
837
838 /*
839 * brh_start() has mapped the console devices for us per
840 * the devmap, so register it now so drivers can map the
841 * console device.
842 */
843 pmap_devmap_register(brh_devmap);
844
845 #if NCOM > 0
846 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
847 BECC_PERIPH_CLOCK, COM_TYPE_NORMAL, comcnmode))
848 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
849 #else
850 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
851 #endif
852 }
853