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