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