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