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