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