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