eb7500atx_machdep.c revision 1.26 1 /* $NetBSD: eb7500atx_machdep.c,v 1.26 2013/08/18 21:42:16 matt Exp $ */
2
3 /*
4 * Copyright (c) 2000-2002 Reinoud Zandijk.
5 * Copyright (c) 1994-1998 Mark Brinicombe.
6 * Copyright (c) 1994 Brini.
7 * All rights reserved.
8 *
9 * This code is derived from software written for Brini by Mark Brinicombe
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Brini.
22 * 4. The name of the company nor the name of the author may be used to
23 * endorse or promote products derived from this software without specific
24 * prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * RiscBSD kernel project
39 *
40 * machdep.c
41 *
42 * Machine dependent functions for kernel setup
43 *
44 * This file still needs a lot of work
45 *
46 * Created : 17/09/94
47 * Updated for yet another new bootloader 28/12/02
48 */
49
50 #include "opt_ddb.h"
51 #include "opt_modular.h"
52 #include "opt_pmap_debug.h"
53 #include "vidcvideo.h"
54 #include "pckbc.h"
55
56 #include <sys/param.h>
57
58 __KERNEL_RCSID(0, "$NetBSD: eb7500atx_machdep.c,v 1.26 2013/08/18 21:42:16 matt Exp $");
59
60 #include <sys/systm.h>
61 #include <sys/kernel.h>
62 #include <sys/reboot.h>
63 #include <sys/proc.h>
64 #include <sys/msgbuf.h>
65 #include <sys/exec.h>
66 #include <sys/exec_aout.h>
67 #include <sys/ksyms.h>
68 #include <sys/bus.h>
69 #include <sys/cpu.h>
70 #include <sys/intr.h>
71 #include <sys/device.h>
72
73 #include <dev/cons.h>
74
75 #include <dev/ic/pckbcvar.h>
76
77 #include <dev/i2c/i2cvar.h>
78 #include <dev/i2c/pcf8583var.h>
79
80 #include <machine/db_machdep.h>
81 #include <ddb/db_sym.h>
82 #include <ddb/db_extern.h>
83
84 #include <uvm/uvm.h>
85
86 #include <arm/locore.h>
87 #include <arm/undefined.h>
88
89 #include <machine/signal.h>
90 #include <machine/bootconfig.h>
91 #include <machine/io.h>
92 #include <arm/arm32/katelib.h>
93 #include <arm/arm32/machdep.h>
94 #include <machine/rtc.h>
95
96 #include <arm/iomd/vidc.h>
97 #include <arm/iomd/iomdreg.h>
98 #include <arm/iomd/iomdvar.h>
99 #include <arm/iomd/vidcvideo.h>
100 #include <arm/iomd/iomdiicvar.h>
101
102 /* static i2c_tag_t acorn32_i2c_tag;*/
103
104 #include "ksyms.h"
105
106 /* Kernel text starts at the base of the kernel address space. */
107 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00000000)
108 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
109
110 /*
111 * The range 0xf1000000 - 0xf5ffffff is available for kernel VM space
112 * Fixed mappings exist from 0xf6000000 - 0xffffffff
113 */
114 #define KERNEL_VM_SIZE 0x05000000
115
116 /*
117 * Address to call from cpu_reset() to reset the machine.
118 * This is machine architecture dependent as it varies depending
119 * on where the ROM appears when you turn the MMU off.
120 */
121
122 #define VERBOSE_INIT_ARM
123
124 struct bootconfig bootconfig; /* Boot config storage */
125 videomemory_t videomemory; /* Video memory descriptor */
126
127 char *boot_args = NULL; /* holds the pre-processed boot arguments */
128 extern char *booted_kernel; /* used for ioctl to retrieve booted kernel */
129
130 extern int *vidc_base;
131 extern uint32_t iomd_base;
132 extern struct bus_space iomd_bs_tag;
133
134 paddr_t physical_start;
135 paddr_t physical_freestart;
136 paddr_t physical_freeend;
137 paddr_t physical_end;
138 paddr_t dma_range_begin;
139 paddr_t dma_range_end;
140
141 u_int free_pages;
142 paddr_t memoryblock_end;
143
144 #ifndef PMAP_STATIC_L1S
145 int max_processes = 64; /* Default number */
146 #endif /* !PMAP_STATIC_L1S */
147
148 u_int videodram_size = 0; /* Amount of DRAM to reserve for video */
149
150 paddr_t msgbufphys;
151
152 #ifdef PMAP_DEBUG
153 extern int pmap_debug_level;
154 #endif /* PMAP_DEBUG */
155
156 #define KERNEL_PT_VMEM 0 /* Page table for mapping video memory */
157 #define KERNEL_PT_SYS 1 /* Page table for mapping proc0 zero page */
158 #define KERNEL_PT_KERNEL 2 /* Page table for mapping kernel */
159 #define KERNEL_PT_VMDATA 3 /* Page tables for mapping kernel VM */
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
166 #ifdef CPU_SA110
167 #define CPU_SA110_CACHE_CLEAN_SIZE (0x4000 * 2)
168 static vaddr_t sa110_cc_base;
169 #endif /* CPU_SA110 */
170
171 /* Prototypes */
172 void physcon_display_base(u_int);
173 extern void consinit(void);
174
175 void data_abort_handler(trapframe_t *);
176 void prefetch_abort_handler(trapframe_t *);
177 void undefinedinstruction_bounce(trapframe_t *frame);
178
179 static void canonicalise_bootconfig(struct bootconfig *, struct bootconfig *);
180 static void process_kernel_args(void);
181
182 extern void dump_spl_masks(void);
183
184 void rpc_sa110_cc_setup(void);
185
186 void parse_rpc_bootargs(char *args);
187
188 extern void dumpsys(void);
189
190
191 # define console_flush() /* empty */
192
193
194 #define panic2(a) do { \
195 memset((void *) (videomemory.vidm_vbase), 0x55, 50*1024); \
196 consinit(); \
197 panic a; \
198 } while (/* CONSTCOND */ 0)
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
209 /* NOTE: These variables will be removed, well some of them */
210
211 extern u_int current_mask;
212
213 void
214 cpu_reboot(int howto, char *bootstr)
215 {
216
217 #ifdef DIAGNOSTIC
218 printf("boot: howto=%08x curlwp=%p\n", howto, curlwp);
219
220 printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_vm=%08x\n",
221 irqmasks[IPL_BIO], irqmasks[IPL_NET], irqmasks[IPL_TTY],
222 irqmasks[IPL_VM]);
223 printf("ipl_audio=%08x ipl_clock=%08x ipl_none=%08x\n",
224 irqmasks[IPL_AUDIO], irqmasks[IPL_CLOCK], irqmasks[IPL_NONE]);
225
226 /* dump_spl_masks(); */
227 #endif /* DIAGNOSTIC */
228
229 /*
230 * If we are still cold then hit the air brakes
231 * and crash to earth fast
232 */
233 if (cold) {
234 doshutdownhooks();
235 pmf_system_shutdown(boothowto);
236 printf("Halted while still in the ICE age.\n");
237 printf("The operating system has halted.\n");
238 printf("Please press any key to reboot.\n\n");
239 cngetc();
240 printf("rebooting...\n");
241 cpu_reset();
242 /*NOTREACHED*/
243 }
244
245 /* Disable console buffering */
246 cnpollc(1);
247
248 /*
249 * If RB_NOSYNC was not specified sync the discs.
250 * Note: Unless cold is set to 1 here, syslogd will die during
251 * the unmount. It looks like syslogd is getting woken up
252 * only to find that it cannot page part of the binary in as
253 * the filesystem has been unmounted.
254 */
255 if (!(howto & RB_NOSYNC))
256 bootsync();
257
258 /* Say NO to interrupts */
259 splhigh();
260
261 /* Do a dump if requested. */
262 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
263 dumpsys();
264
265 /*
266 * Auto reboot overload protection
267 *
268 * This code stops the kernel entering an endless loop of reboot
269 * - panic cycles. This will have the effect of stopping further
270 * reboots after it has rebooted 8 times after panics. A clean
271 * halt or reboot will reset the counter.
272 */
273
274 /* Run any shutdown hooks */
275 doshutdownhooks();
276
277 pmf_system_shutdown(boothowto);
278
279 /* Make sure IRQ's are disabled */
280 IRQdisable;
281
282 if (howto & RB_HALT) {
283 printf("The operating system has halted.\n");
284 printf("Please press any key to reboot.\n\n");
285 cngetc();
286 }
287
288 printf("rebooting...\n");
289 cpu_reset();
290 /*NOTREACHED*/
291 }
292
293
294 /*
295 * u_int initarm(BootConfig *bootconf)
296 *
297 * Initial entry point on startup. This gets called before main() is
298 * entered.
299 * It should be responsible for setting up everything that must be
300 * in place when main is called.
301 * This includes
302 * Taking a copy of the boot configuration structure.
303 * Initialising the physical console so characters can be printed.
304 * Setting up page tables for the kernel
305 * Relocating the kernel to the bottom of physical memory
306 */
307
308 /*
309 * this part is completely rewritten for the new bootloader ... It features
310 * a flat memory map with a mapping comparable to the EBSA arm32 machine
311 * to boost the portability and likeness of the code
312 */
313
314 /*
315 * Mapping table for core kernel memory. This memory is mapped at init
316 * time with section mappings.
317 *
318 * XXX One big assumption in the current architecture seems that the kernel is
319 * XXX supposed to be mapped into bootconfig.dram[0].
320 */
321
322 #define ONE_MB 0x100000
323
324 struct l1_sec_map {
325 vaddr_t va;
326 paddr_t pa;
327 vsize_t size;
328 vm_prot_t prot;
329 int cache;
330 } l1_sec_table[] = {
331 /* Map 1Mb section for VIDC20 */
332 { VIDC_BASE, VIDC_HW_BASE,
333 ONE_MB, VM_PROT_READ|VM_PROT_WRITE,
334 PTE_NOCACHE },
335
336 /* Map 1Mb section from IOMD */
337 { IOMD_BASE, IOMD_HW_BASE,
338 ONE_MB, VM_PROT_READ|VM_PROT_WRITE,
339 PTE_NOCACHE },
340
341 /* Map 1Mb of COMBO (and module space) */
342 { IO_BASE, IO_HW_BASE,
343 ONE_MB, VM_PROT_READ|VM_PROT_WRITE,
344 PTE_NOCACHE },
345 { 0, 0, 0, 0, 0 }
346 };
347
348
349 static void
350 canonicalise_bootconfig(struct bootconfig *bootconf, struct bootconfig *raw_bootconf)
351 {
352 /* check for bootconfig v2+ structure */
353 if (raw_bootconf->magic == BOOTCONFIG_MAGIC) {
354 /* v2+ cleaned up structure found */
355 *bootconf = *raw_bootconf;
356 return;
357 } else {
358 panic2(("Internal error: no valid bootconfig block found"));
359 }
360 }
361
362
363 u_int
364 initarm(void *cookie)
365 {
366 struct bootconfig *raw_bootconf = cookie;
367 int loop;
368 int loop1;
369 u_int logical;
370 u_int kerneldatasize;
371 u_int l1pagetable;
372 struct exec *kernexec = (struct exec *)KERNEL_TEXT_BASE;
373
374 /*
375 * Heads up ... Setup the CPU / MMU / TLB functions
376 */
377 set_cpufuncs();
378
379 /* canonicalise the boot configuration structure to alow versioning */
380 canonicalise_bootconfig(&bootconfig, raw_bootconf);
381 booted_kernel = bootconfig.kernelname;
382
383 /* if the wscons interface is used, switch off VERBOSE booting :( */
384 #if NVIDCVIDEO>0
385 # undef VERBOSE_INIT_ARM
386 # undef PMAP_DEBUG
387 #endif
388
389 /*
390 * Initialise the video memory descriptor
391 *
392 * Note: all references to the video memory virtual/physical address
393 * should go via this structure.
394 */
395
396 /* Hardwire it on the place the bootloader tells us */
397 videomemory.vidm_vbase = bootconfig.display_start;
398 videomemory.vidm_pbase = bootconfig.display_phys;
399 videomemory.vidm_size = bootconfig.display_size;
400 if (bootconfig.vram[0].pages)
401 videomemory.vidm_type = VIDEOMEM_TYPE_VRAM;
402 else
403 videomemory.vidm_type = VIDEOMEM_TYPE_DRAM;
404 vidc_base = (int *) VIDC_HW_BASE;
405 iomd_base = IOMD_HW_BASE;
406
407 /*
408 * Initialise the physical console
409 * This is done in main() but for the moment we do it here so that
410 * we can use printf in initarm() before main() has been called.
411 * only for `vidcconsole!' ... not wscons
412 */
413 #if NVIDCVIDEO == 0
414 consinit();
415 #endif
416
417 /*
418 * Initialise the diagnostic serial console
419 * This allows a means of generating output during initarm().
420 * Once all the memory map changes are complete we can call consinit()
421 * and not have to worry about things moving.
422 */
423 /* fcomcnattach(DC21285_ARMCSR_BASE, comcnspeed, comcnmode); */
424 /* XXX snif .... i am still not able to this */
425
426 /*
427 * We have the following memory map (derived from EBSA)
428 *
429 * virtual address == physical address apart from the areas:
430 * 0x00000000 -> 0x000fffff which is mapped to
431 * top 1MB of physical memory
432 * 0xf0000000 -> 0xf0ffffff wich is mapped to
433 * physical address 0x01000000 -> 0x01ffffff (DRAM0a, dram[0])
434 *
435 * This means that the kernel is mapped suitably for continuing
436 * execution, all I/O is mapped 1:1 virtual to physical and
437 * physical memory is accessible.
438 *
439 * The initarm() has the responsibility for creating the kernel
440 * page tables.
441 * It must also set up various memory pointers that are used
442 * by pmap etc.
443 */
444
445 /* START OF REAL NEW STUFF */
446
447 /* Check to make sure the page size is correct */
448 if (PAGE_SIZE != bootconfig.pagesize)
449 panic2(("Page size is %d bytes instead of %d !! (huh?)\n",
450 bootconfig.pagesize, PAGE_SIZE));
451
452 /* process arguments */
453 process_kernel_args();
454
455
456 /*
457 * Now set up the page tables for the kernel ... this part is copied
458 * in a (modified?) way from the EBSA machine port....
459 */
460
461 #ifdef VERBOSE_INIT_ARM
462 printf("Allocating page tables\n");
463 #endif
464 /*
465 * Set up the variables that define the availablilty of physical
466 * memory
467 */
468 physical_start = 0xffffffff;
469 physical_end = 0;
470 for (loop = 0, physmem = 0; loop < bootconfig.dramblocks; ++loop) {
471 if (bootconfig.dram[loop].address < physical_start)
472 physical_start = bootconfig.dram[loop].address;
473 memoryblock_end = bootconfig.dram[loop].address +
474 bootconfig.dram[loop].pages * PAGE_SIZE;
475 if (memoryblock_end > physical_end)
476 physical_end = memoryblock_end;
477 physmem += bootconfig.dram[loop].pages;
478 };
479 /* constants for now, but might be changed/configured */
480 dma_range_begin = (paddr_t) physical_start;
481 dma_range_end = (paddr_t) MIN(physical_end, 512*1024*1024);
482 /* XXX HACK HACK XXX */
483 /* dma_range_end = 0x18000000; */
484
485 if (physical_start != bootconfig.dram[0].address) {
486 int oldblocks = 0;
487
488 /*
489 * must be a kinetic, as it's the only thing to shuffle memory
490 * around
491 */
492 /* hack hack - throw away the slow dram */
493 for (loop = 0; loop < bootconfig.dramblocks; ++loop) {
494 if (bootconfig.dram[loop].address <
495 bootconfig.dram[0].address) {
496 /* non kinetic ram */
497 bootconfig.dram[loop].address = 0;
498 physmem -= bootconfig.dram[loop].pages;
499 bootconfig.drampages -=
500 bootconfig.dram[loop].pages;
501 bootconfig.dram[loop].pages = 0;
502 oldblocks++;
503 }
504 }
505 physical_start = bootconfig.dram[0].address;
506 bootconfig.dramblocks -= oldblocks;
507 }
508
509 physical_freestart = physical_start;
510 free_pages = bootconfig.drampages;
511 physical_freeend = physical_end;
512
513
514 /*
515 * AHUM !! set this variable ... it was set up in the old 1st
516 * stage bootloader
517 */
518 kerneldatasize = bootconfig.kernsize + bootconfig.MDFsize;
519
520 /* Update the address of the first free page of physical memory */
521 /* XXX Assumption that the kernel and stuff is at the LOWEST physical memory address? XXX */
522 physical_freestart +=
523 bootconfig.kernsize + bootconfig.MDFsize + bootconfig.scratchsize;
524 free_pages -= (physical_freestart - physical_start) / PAGE_SIZE;
525
526 /* Define a macro to simplify memory allocation */
527 #define valloc_pages(var, np) \
528 alloc_pages((var).pv_pa, (np)); \
529 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
530
531 #define alloc_pages(var, np) \
532 (var) = physical_freestart; \
533 physical_freestart += ((np) * PAGE_SIZE); \
534 free_pages -= (np); \
535 memset((char *)(var), 0, ((np) * PAGE_SIZE));
536
537 loop1 = 0;
538 kernel_l1pt.pv_pa = 0;
539 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
540 /* Are we 16KB aligned for an L1 ? */
541 if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
542 && kernel_l1pt.pv_pa == 0) {
543 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
544 } else {
545 valloc_pages(kernel_pt_table[loop1],
546 L2_TABLE_SIZE / PAGE_SIZE);
547 ++loop1;
548 }
549 }
550
551
552 #ifdef DIAGNOSTIC
553 /* This should never be able to happen but better confirm that. */
554 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
555 panic2(("initarm: Failed to align the kernel page "
556 "directory\n"));
557 #endif
558
559 /*
560 * Allocate a page for the system page mapped to V0x00000000
561 * This page will just contain the system vectors and can be
562 * shared by all processes.
563 */
564 alloc_pages(systempage.pv_pa, 1);
565
566 /* Allocate stacks for all modes */
567 valloc_pages(irqstack, IRQ_STACK_SIZE);
568 valloc_pages(abtstack, ABT_STACK_SIZE);
569 valloc_pages(undstack, UND_STACK_SIZE);
570 valloc_pages(kernelstack, UPAGES);
571
572 #ifdef VERBOSE_INIT_ARM
573 printf("Setting up stacks :\n");
574 printf("IRQ stack: p0x%08lx v0x%08lx\n",
575 irqstack.pv_pa, irqstack.pv_va);
576 printf("ABT stack: p0x%08lx v0x%08lx\n",
577 abtstack.pv_pa, abtstack.pv_va);
578 printf("UND stack: p0x%08lx v0x%08lx\n",
579 undstack.pv_pa, undstack.pv_va);
580 printf("SVC stack: p0x%08lx v0x%08lx\n",
581 kernelstack.pv_pa, kernelstack.pv_va);
582 printf("\n");
583 #endif
584
585 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
586
587 #ifdef CPU_SA110
588 /*
589 * XXX totally stuffed hack to work round problems introduced
590 * in recent versions of the pmap code. Due to the calls used there
591 * we cannot allocate virtual memory during bootstrap.
592 */
593 sa110_cc_base = (KERNEL_BASE + (physical_freestart - physical_start)
594 + (CPU_SA110_CACHE_CLEAN_SIZE - 1))
595 & ~(CPU_SA110_CACHE_CLEAN_SIZE - 1);
596 #endif /* CPU_SA110 */
597
598 /*
599 * Ok we have allocated physical pages for the primary kernel
600 * page tables
601 */
602
603 #ifdef VERBOSE_INIT_ARM
604 printf("Creating L1 page table\n");
605 #endif
606
607 /*
608 * Now we start construction of the L1 page table
609 * We start by mapping the L2 page tables into the L1.
610 * This means that we can replace L1 mappings later on if necessary
611 */
612 l1pagetable = kernel_l1pt.pv_pa;
613
614 /* Map the L2 pages tables in the L1 page table */
615 pmap_link_l2pt(l1pagetable, 0x00000000,
616 &kernel_pt_table[KERNEL_PT_SYS]);
617 pmap_link_l2pt(l1pagetable, KERNEL_BASE,
618 &kernel_pt_table[KERNEL_PT_KERNEL]);
619 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
620 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
621 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
622 pmap_link_l2pt(l1pagetable, VMEM_VBASE,
623 &kernel_pt_table[KERNEL_PT_VMEM]);
624
625 /* update the top of the kernel VM */
626 pmap_curmaxkvaddr =
627 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
628
629 #ifdef VERBOSE_INIT_ARM
630 printf("Mapping kernel\n");
631 #endif
632
633 /* Now we fill in the L2 pagetable for the kernel code/data */
634 /* XXX Kernel doesn't have to be on physical_start (!) use bootconfig XXX */
635 /*
636 * The defines are a workaround for a recent problem that occurred
637 * with ARM 610 processors and some ARM 710 processors
638 * Other ARM 710 and StrongARM processors don't have a problem.
639 */
640 if (N_GETMAGIC(kernexec[0]) == ZMAGIC) {
641 #if defined(CPU_ARM6) || defined(CPU_ARM7)
642 logical = pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
643 physical_start, kernexec->a_text,
644 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
645 #else /* CPU_ARM6 || CPU_ARM7 */
646 logical = pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
647 physical_start, kernexec->a_text,
648 VM_PROT_READ, PTE_CACHE);
649 #endif /* CPU_ARM6 || CPU_ARM7 */
650 logical += pmap_map_chunk(l1pagetable,
651 KERNEL_TEXT_BASE + logical, physical_start + logical,
652 kerneldatasize - kernexec->a_text,
653 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
654 } else { /* !ZMAGIC */
655 /*
656 * Most likely an ELF kernel ...
657 * XXX no distinction yet between read only and
658 * read/write area's ...
659 */
660 pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
661 physical_start, kerneldatasize,
662 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
663 };
664
665
666 #ifdef VERBOSE_INIT_ARM
667 printf("Constructing L2 page tables\n");
668 #endif
669
670 /* Map the stack pages */
671 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
672 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
673 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
674 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
675 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
676 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
677 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
678 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
679
680 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
681 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
682
683 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
684 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
685 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
686 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
687 }
688
689 /* Now we fill in the L2 pagetable for the VRAM */
690 /*
691 * Current architectures mean that the VRAM is always in 1
692 * continuous bank. This means that we can just map the 2 meg
693 * that the VRAM would occupy. In theory we don't need a page
694 * table for VRAM, we could section map it but we would need
695 * the page tables if DRAM was in use.
696 * XXX please map two adjacent virtual areas to ONE physical
697 * area
698 */
699 pmap_map_chunk(l1pagetable, VMEM_VBASE, videomemory.vidm_pbase,
700 videomemory.vidm_size, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
701 pmap_map_chunk(l1pagetable, VMEM_VBASE + videomemory.vidm_size,
702 videomemory.vidm_pbase, videomemory.vidm_size,
703 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
704
705 /* Map the vector page. */
706 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
707 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
708
709 /* Map the core memory needed before autoconfig */
710 loop = 0;
711 while (l1_sec_table[loop].size) {
712 vm_size_t sz;
713
714 #ifdef VERBOSE_INIT_ARM
715 printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
716 l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
717 l1_sec_table[loop].va);
718 #endif
719 for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_S_SIZE)
720 pmap_map_section(l1pagetable,
721 l1_sec_table[loop].va + sz,
722 l1_sec_table[loop].pa + sz,
723 l1_sec_table[loop].prot,
724 l1_sec_table[loop].cache);
725 ++loop;
726 }
727
728 /*
729 * Now we have the real page tables in place so we can switch
730 * to them. Once this is done we will be running with the
731 * REAL kernel page tables.
732 */
733
734 #ifdef VERBOSE_INIT_ARM
735 printf("switching domains\n");
736 #endif
737 /* be a client to all domains */
738 cpu_domains(0x55555555);
739
740 /* Switch tables */
741 #ifdef VERBOSE_INIT_ARM
742 printf("switching to new L1 page table\n");
743 #endif
744 cpu_setttb(kernel_l1pt.pv_pa, true);
745
746 /*
747 * We must now clean the cache again....
748 * Cleaning may be done by reading new data to displace any
749 * dirty data in the cache. This will have happened in cpu_setttb()
750 * but since we are boot strapping the addresses used for the read
751 * may have just been remapped and thus the cache could be out
752 * of sync. A re-clean after the switch will cure this.
753 * After booting there are no gross reloations of the kernel thus
754 * this problem will not occur after initarm().
755 */
756 cpu_idcache_wbinv_all();
757 cpu_tlb_flushID();
758 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
759
760 /*
761 * Moved from cpu_startup() as data_abort_handler() references
762 * this during uvm init
763 */
764 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
765
766 /*
767 * if there is support for a serial console ...we should now
768 * reattach it
769 */
770 /* fcomcndetach();*/
771
772 /*
773 * Reflect videomemory relocation in the videomemory structure
774 * and reinit console
775 */
776 if (bootconfig.vram[0].pages == 0) {
777 videomemory.vidm_vbase = VMEM_VBASE;
778 } else {
779 videomemory.vidm_vbase = VMEM_VBASE;
780 bootconfig.display_start = VMEM_VBASE;
781 };
782 vidc_base = (int *) VIDC_BASE;
783 iomd_base = IOMD_BASE;
784
785 #ifdef VERBOSE_INIT_ARM
786 printf("running on the new L1 page table!\n");
787 printf("done.\n");
788 #endif
789
790 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
791
792 #ifdef VERBOSE_INIT_ARM
793 printf("\n");
794 #endif
795
796 /*
797 * Pages were allocated during the secondary bootstrap for the
798 * stacks for different CPU modes.
799 * We must now set the r13 registers in the different CPU modes to
800 * point to these stacks.
801 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
802 * of the stack memory.
803 */
804 #ifdef VERBOSE_INIT_ARM
805 printf("init subsystems: stacks ");
806 console_flush();
807 #endif
808
809 set_stackptr(PSR_IRQ32_MODE,
810 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
811 set_stackptr(PSR_ABT32_MODE,
812 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
813 set_stackptr(PSR_UND32_MODE,
814 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
815 #ifdef PMAP_DEBUG
816 if (pmap_debug_level >= 0)
817 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va,
818 kernelstack.pv_pa);
819 #endif /* PMAP_DEBUG */
820
821 /*
822 * Well we should set a data abort handler.
823 * Once things get going this will change as we will need a proper
824 * handler. Until then we will use a handler that just panics but
825 * tells us why.
826 * Initialisation of the vectors will just panic on a data abort.
827 * This just fills in a slightly better one.
828 */
829 #ifdef VERBOSE_INIT_ARM
830 printf("vectors ");
831 #endif
832 data_abort_handler_address = (u_int)data_abort_handler;
833 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
834 undefined_handler_address = (u_int)undefinedinstruction_bounce;
835 console_flush();
836
837
838 /*
839 * At last !
840 * We now have the kernel in physical memory from the bottom upwards.
841 * Kernel page tables are physically above this.
842 * The kernel is mapped to 0xf0000000
843 * The kernel data PTs will handle the mapping of
844 * 0xf1000000-0xf5ffffff (80 Mb)
845 * 2Meg of VRAM is mapped to 0xf7000000
846 * The page tables are mapped to 0xefc00000
847 * The IOMD is mapped to 0xf6000000
848 * The VIDC is mapped to 0xf6100000
849 * The IOMD/VIDC could be pushed up higher but i havent got
850 * sufficient documentation to do so; the addresses are not
851 * parametized yet and hard to read... better fix this before;
852 * its pretty unforgiving.
853 */
854
855 /* Initialise the undefined instruction handlers */
856 #ifdef VERBOSE_INIT_ARM
857 printf("undefined ");
858 #endif
859 undefined_init();
860 console_flush();
861
862 /* Load memory into UVM. */
863 #ifdef VERBOSE_INIT_ARM
864 printf("page ");
865 #endif
866 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
867 for (loop = 0; loop < bootconfig.dramblocks; loop++) {
868 paddr_t start = (paddr_t)bootconfig.dram[loop].address;
869 paddr_t end = start + (bootconfig.dram[loop].pages * PAGE_SIZE);
870
871 if (start < physical_freestart)
872 start = physical_freestart;
873 if (end > physical_freeend)
874 end = physical_freeend;
875
876 /* XXX Consider DMA range intersection checking. */
877
878 uvm_page_physload(atop(start), atop(end),
879 atop(start), atop(end), VM_FREELIST_DEFAULT);
880 }
881
882 /* Boot strap pmap telling it where the kernel page table is */
883 #ifdef VERBOSE_INIT_ARM
884 printf("pmap ");
885 #endif
886 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
887 console_flush();
888
889 /* Setup the IRQ system */
890 #ifdef VERBOSE_INIT_ARM
891 printf("irq ");
892 #endif
893 console_flush();
894 irq_init();
895 #ifdef VERBOSE_INIT_ARM
896 printf("done.\n\n");
897 #endif
898
899 #if NVIDCVIDEO>0
900 consinit(); /* necessary ? */
901 #endif
902
903 /* Talk to the user */
904 printf("NetBSD/evbarm booting ... \n");
905
906 /* Tell the user if his boot loader is too old */
907 if ((bootconfig.magic < BOOTCONFIG_MAGIC) ||
908 (bootconfig.version != BOOTCONFIG_VERSION)) {
909 printf("\nDETECTED AN OLD BOOTLOADER. PLEASE UPGRADE IT\n\n");
910 delay(5000000);
911 }
912
913 printf("Kernel loaded from file %s\n", bootconfig.kernelname);
914 printf("Kernel arg string (@%p) %s\n",
915 bootconfig.args, bootconfig.args);
916 printf("\nBoot configuration structure reports the following "
917 "memory\n");
918
919 printf(" DRAM block 0a at %08x size %08x "
920 "DRAM block 0b at %08x size %08x\n\r",
921 bootconfig.dram[0].address,
922 bootconfig.dram[0].pages * bootconfig.pagesize,
923 bootconfig.dram[1].address,
924 bootconfig.dram[1].pages * bootconfig.pagesize);
925 printf(" DRAM block 1a at %08x size %08x "
926 "DRAM block 1b at %08x size %08x\n\r",
927 bootconfig.dram[2].address,
928 bootconfig.dram[2].pages * bootconfig.pagesize,
929 bootconfig.dram[3].address,
930 bootconfig.dram[3].pages * bootconfig.pagesize);
931 printf(" VRAM block 0 at %08x size %08x\n\r",
932 bootconfig.vram[0].address,
933 bootconfig.vram[0].pages * bootconfig.pagesize);
934
935 #if NKSYMS || defined(DDB) || defined(MODULAR)
936 ksyms_addsyms_elf(bootconfig.ksym_end - bootconfig.ksym_start,
937 (void *) bootconfig.ksym_start, (void *) bootconfig.ksym_end);
938 #endif
939
940
941 #ifdef DDB
942 db_machine_init();
943 if (boothowto & RB_KDB)
944 Debugger();
945 #endif /* DDB */
946
947 /* We return the new stack pointer address */
948 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
949 }
950
951
952 static void
953 process_kernel_args(void)
954 {
955 char *args;
956
957 /* Ok now we will check the arguments for interesting parameters. */
958 args = bootconfig.args;
959 boothowto = 0;
960
961 /* Only arguments itself are passed from the new bootloader */
962 while (*args == ' ')
963 ++args;
964
965 boot_args = args;
966 parse_mi_bootargs(boot_args);
967 parse_rpc_bootargs(boot_args);
968 }
969
970
971 void
972 parse_rpc_bootargs(char *args)
973 {
974 int integer;
975
976 if (get_bootconf_option(args, "videodram", BOOTOPT_TYPE_INT,
977 &integer)) {
978 videodram_size = integer;
979 /* Round to 4K page */
980 videodram_size *= 1024;
981 videodram_size = round_page(videodram_size);
982 if (videodram_size > 1024*1024)
983 videodram_size = 1024*1024;
984 }
985 }
986 /* End of machdep.c */
987