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