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