armadillo9_machdep.c revision 1.1 1 /* $NetBSD: armadillo9_machdep.c,v 1.1 2005/11/13 06:33:05 hamajima Exp $ */
2
3 /*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Based on code written by Jason R. Thorpe and Steve C. Woodford for
8 * Wasabi Systems, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by
21 * Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
24 * written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1997,1998 Mark Brinicombe.
41 * Copyright (c) 1997,1998 Causality Limited.
42 * All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by Mark Brinicombe
55 * for the NetBSD Project.
56 * 4. The name of the company nor the name of the author may be used to
57 * endorse or promote products derived from this software without specific
58 * prior written permission.
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
61 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
64 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
65 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
66 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * SUCH DAMAGE.
71 *
72 * Machine dependant functions for kernel setup for Iyonix.
73 */
74
75 /* Armadillo-9 physical memory map
76 0000 0000 - 0fff ffff reserved
77 1000 0000 - 1000 000f I/O Control Register
78 1000 0010 - 11dd ffff reserved
79 1200 0000 - 1200 ffff PC/104 I/O space (8bit)
80 1201 0000 - 12ff ffff reserved
81 1300 0000 - 13ff ffff PC/104 Memory space (8bit)
82 1400 0000 - 1fff ffff reserved
83 2000 0000 - 21ff ffff reserved
84 2200 0000 - 2200 ffff PC/104 I/O space (16bit)
85 2201 0000 - 22ff ffff reserved
86 2300 0000 - 23ff ffff PC/104 Memory space (16bit)
87 2400 0000 - 2fff ffff reserved
88 3000 0000 - 3fff ffff reserved
89 4000 0000 - 43ff ffff Compact Flash I/O space
90 4400 0000 - 47ff ffff reserved
91 4800 0000 - 4bff ffff Compact Flash Attribute space
92 4c00 0000 - 4fff ffff Compact Flash memory space
93 5000 0000 - 5fff ffff reserved
94 6000 0000 - 607f ffff Flash Memory (8MByte)
95 6080 0000 - 6fff ffff reserved
96 7000 0000 - 7fff ffff reserved
97 8000 0000 - 8008 ffff EP9315 Internal Register (AHB)
98 8009 0000 - 8009 3fff Internal Boot ROM (16kByte)
99 8009 4000 - 8009 ffff reserved
100 800a 0000 - 800f ffff EP9315 Internal Register (AHB)
101 8010 0000 - 807f ffff reserved
102 8080 0000 - 8094 ffff EP9315 Internal Register (APB)
103 8095 0000 - 8fff ffff reserved
104 9000 0000 - bfff ffff reserved
105 c000 0000 - c1ff ffff SDRAM (32MByte)
106 c200 0000 - c3ff ffff reserved
107 c400 0000 - c5ff ffff SDRAM (32MByte)
108 c600 0000 - cfff ffff reserved
109 d000 0000 - ffff ffff reserved
110 */
111
112 #include <sys/cdefs.h>
113 __KERNEL_RCSID(0, "$NetBSD: armadillo9_machdep.c,v 1.1 2005/11/13 06:33:05 hamajima Exp $");
114
115 #include "opt_ddb.h"
116 #include "opt_kgdb.h"
117 #include "opt_pmap_debug.h"
118
119 #include <sys/param.h>
120 #include <sys/device.h>
121 #include <sys/systm.h>
122 #include <sys/kernel.h>
123 #include <sys/exec.h>
124 #include <sys/proc.h>
125 #include <sys/msgbuf.h>
126 #include <sys/reboot.h>
127 #include <sys/termios.h>
128 #include <sys/ksyms.h>
129
130 #include <uvm/uvm_extern.h>
131
132 #include <dev/cons.h>
133
134 #include <machine/db_machdep.h>
135 #include <ddb/db_sym.h>
136 #include <ddb/db_extern.h>
137
138 #include <machine/bootconfig.h>
139 #include <machine/bus.h>
140 #include <machine/cpu.h>
141 #include <machine/frame.h>
142 #include <arm/undefined.h>
143
144 #include <arm/arm32/machdep.h>
145
146 #include <arm/ep93xx/ep93xxreg.h>
147 #include <arm/ep93xx/ep93xxvar.h>
148
149 #include "epwdog.h"
150 #if NEPWDOG > 0
151 #include <arm/ep93xx/epwdogvar.h>
152 #endif
153 #include <arm/ep93xx/epwdogreg.h>
154
155 #include <dev/ic/comreg.h>
156 #include <dev/ic/comvar.h>
157
158 #include "epcom.h"
159 #if NEPCOM > 0
160 #include <arm/ep93xx/epcomvar.h>
161 #endif
162
163 #include "isa.h"
164 #if NISA > 0
165 #include <dev/isa/isareg.h>
166 #include <dev/isa/isavar.h>
167 #endif
168
169 #include <machine/isa_machdep.h>
170
171 #include <evbarm/armadillo/armadillo9reg.h>
172
173 #include "opt_ipkdb.h"
174 #include "ksyms.h"
175
176 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
177 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
178 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
179
180 /*
181 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
182 * Core-logic registers and I/O mappings occupy 0xf0000000 - 0xffffffff
183 */
184 #define KERNEL_VM_SIZE 0x0c000000
185
186 /*
187 * Address to call from cpu_reset() to reset the machine.
188 * This is machine architecture dependant as it varies depending
189 * on where the ROM appears when you turn the MMU off.
190 */
191
192 u_int cpu_reset_address = 0x80090000;
193
194 /* Define various stack sizes in pages */
195 #define IRQ_STACK_SIZE 8
196 #define ABT_STACK_SIZE 8
197 #ifdef IPKDB
198 #define UND_STACK_SIZE 16
199 #else
200 #define UND_STACK_SIZE 8
201 #endif
202
203 BootConfig bootconfig; /* Boot config storage */
204 char *boot_args = NULL;
205 char *boot_file = NULL;
206
207 vm_offset_t physical_start;
208 vm_offset_t physical_freestart;
209 vm_offset_t physical_freeend;
210 vm_offset_t physical_freeend_low;
211 vm_offset_t physical_end;
212 u_int free_pages;
213 int physmem = 0;
214
215 /* Physical and virtual addresses for some global pages */
216 pv_addr_t systempage;
217 pv_addr_t irqstack;
218 pv_addr_t undstack;
219 pv_addr_t abtstack;
220 pv_addr_t kernelstack;
221
222 vm_offset_t msgbufphys;
223
224 static struct arm32_dma_range armadillo9_dma_ranges[4];
225
226 #if NISA > 0
227 extern void isa_armadillo9_init(u_int, u_int);
228 #endif
229
230 extern u_int data_abort_handler_address;
231 extern u_int prefetch_abort_handler_address;
232 extern u_int undefined_handler_address;
233
234 #ifdef PMAP_DEBUG
235 extern int pmap_debug_level;
236 #endif
237
238 #define KERNEL_PT_SYS 0 /* L2 table for mapping vectors page */
239
240 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
241 #define KERNEL_PT_KERNEL_NUM 4
242 /* L2 tables for mapping kernel VM */
243 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
244
245 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
246 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
247
248 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
249
250 struct user *proc0paddr;
251
252 /* Prototypes */
253
254 void consinit(void);
255 /*
256 * Define the default console speed for the machine.
257 */
258 #ifndef CONSPEED
259 #define CONSPEED B115200
260 #endif /* ! CONSPEED */
261
262 #ifndef CONMODE
263 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
264 #endif
265
266 int comcnspeed = CONSPEED;
267 int comcnmode = CONMODE;
268
269 #if KGDB
270 #ifndef KGDB_DEVNAME
271 #error Must define KGDB_DEVNAME
272 #endif
273 const char kgdb_devname[] = KGDB_DEVNAME;
274
275 #ifndef KGDB_DEVADDR
276 #error Must define KGDB_DEVADDR
277 #endif
278 unsigned long kgdb_devaddr = KGDB_DEVADDR;
279
280 #ifndef KGDB_DEVRATE
281 #define KGDB_DEVRATE CONSPEED
282 #endif
283 int kgdb_devrate = KGDB_DEVRATE;
284
285 #ifndef KGDB_DEVMODE
286 #define KGDB_DEVMODE CONMODE
287 #endif
288 int kgdb_devmode = KGDB_DEVMODE;
289 #endif /* KGDB */
290
291 /*
292 * void cpu_reboot(int howto, char *bootstr)
293 *
294 * Reboots the system
295 *
296 * Deal with any syncing, unmounting, dumping and shutdown hooks,
297 * then reset the CPU.
298 */
299 void
300 cpu_reboot(int howto, char *bootstr)
301 {
302 /*
303 * If we are still cold then hit the air brakes
304 * and crash to earth fast
305 */
306 if (cold) {
307 doshutdownhooks();
308 printf("\r\n");
309 printf("The operating system has halted.\r\n");
310 printf("Please press any key to reboot.\r\n");
311 cngetc();
312 printf("\r\nrebooting...\r\n");
313 goto reset;
314 }
315
316 /* Disable console buffering */
317
318 /*
319 * If RB_NOSYNC was not specified sync the discs.
320 * Note: Unless cold is set to 1 here, syslogd will die during the
321 * unmount. It looks like syslogd is getting woken up only to find
322 * that it cannot page part of the binary in as the filesystem has
323 * been unmounted.
324 */
325 if (!(howto & RB_NOSYNC))
326 bootsync();
327
328 /* Say NO to interrupts */
329 splhigh();
330
331 /* Do a dump if requested. */
332 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
333 dumpsys();
334
335 /* Run any shutdown hooks */
336 doshutdownhooks();
337
338 /* Make sure IRQ's are disabled */
339 IRQdisable;
340
341 if (howto & RB_HALT) {
342 printf("\r\n");
343 printf("The operating system has halted.\r\n");
344 printf("Please press any key to reboot.\r\n");
345 cngetc();
346 }
347
348 printf("\r\nrebooting...\r\n");
349 reset:
350 /*
351 * Make really really sure that all interrupts are disabled,
352 * and poke the Internal Bus and Peripheral Bus reset lines.
353 */
354 (void) disable_interrupts(I32_bit|F32_bit);
355 #if NEPWDOG > 0
356 epwdog_reset();
357 #else
358 {
359 u_int32_t ctrl = EP93XX_APB_VBASE + EP93XX_APB_WDOG + EP93XX_WDOG_Ctrl;
360 u_int32_t val = EP93XX_WDOG_ENABLE;
361 asm volatile (
362 "str %1, [%0]\n"
363 :
364 : "r" (ctrl), "r" (val)
365 );
366 }
367 #endif
368 for (;;);
369 }
370
371 /* Static device mappings. */
372 static const struct pmap_devmap armadillo9_devmap[] = {
373 {
374 EP93XX_AHB_VBASE,
375 EP93XX_AHB_HWBASE,
376 EP93XX_AHB_SIZE,
377 VM_PROT_READ|VM_PROT_WRITE,
378 PTE_NOCACHE,
379 },
380
381 {
382 EP93XX_APB_VBASE,
383 EP93XX_APB_HWBASE,
384 EP93XX_APB_SIZE,
385 VM_PROT_READ|VM_PROT_WRITE,
386 PTE_NOCACHE,
387 },
388
389 {
390 EP93XX_PCMCIA0_VBASE,
391 EP93XX_PCMCIA0_HWBASE,
392 EP93XX_PCMCIA_SIZE,
393 VM_PROT_READ|VM_PROT_WRITE,
394 PTE_NOCACHE,
395 },
396
397 /*
398 * IO8 and IO16 space *must* be mapped contiguously with
399 * IO8_VA == IO16_VA - 64 Mbytes. ISA busmap driver depends
400 * on that!
401 */
402 {
403 ARMADILLO9_IO8_VBASE,
404 ARMADILLO9_IO8_HWBASE,
405 ARMADILLO9_IO8_SIZE,
406 VM_PROT_READ|VM_PROT_WRITE,
407 PTE_NOCACHE,
408 },
409
410 {
411 ARMADILLO9_IO16_VBASE,
412 ARMADILLO9_IO16_HWBASE,
413 ARMADILLO9_IO16_SIZE,
414 VM_PROT_READ|VM_PROT_WRITE,
415 PTE_NOCACHE,
416 },
417
418 {
419 0,
420 0,
421 0,
422 0,
423 0,
424 }
425 };
426
427 /*
428 * u_int initarm(...)
429 *
430 * Initial entry point on startup. This gets called before main() is
431 * entered.
432 * It should be responsible for setting up everything that must be
433 * in place when main is called.
434 * This includes
435 * Taking a copy of the boot configuration structure.
436 * Initialising the physical console so characters can be printed.
437 * Setting up page tables for the kernel
438 * Initialising interrupt controllers to a sane default state
439 */
440 u_int
441 initarm(void *arg)
442 {
443 int loop;
444 int loop1;
445 u_int l1pagetable;
446 pv_addr_t kernel_l1pt;
447
448 /*
449 * Since we map the on-board devices VA==PA, and the kernel
450 * is running VA==PA, it's possible for us to initialize
451 * the console now.
452 */
453 consinit();
454
455 #ifdef VERBOSE_INIT_ARM
456 /* Talk to the user */
457 printf("\nNetBSD/armadillo9 booting ...\n");
458 #endif
459
460 /*
461 * Heads up ... Setup the CPU / MMU / TLB functions
462 */
463 if (set_cpufuncs())
464 panic("cpu not recognized!");
465
466 #ifdef VERBOSE_INIT_ARM
467 printf("initarm: Configuring system ...\n");
468 #endif
469
470 /* Fake bootconfig structure for the benefit of pmap.c */
471 /* XXX must make the memory description h/w independant */
472 bootconfig.dramblocks = 2;
473 bootconfig.dram[0].address = 0xc0000000UL;
474 bootconfig.dram[0].pages = 0x2000000UL / PAGE_SIZE;
475 bootconfig.dram[1].address = 0xc4000000UL;
476 bootconfig.dram[1].pages = 0x2000000UL / PAGE_SIZE;
477
478 /*
479 * Set up the variables that define the availablilty of
480 * physical memory. For now, we're going to set
481 * physical_freestart to 0xc0200000 (where the kernel
482 * was loaded), and allocate the memory we need downwards.
483 * If we get too close to the L1 table that we set up, we
484 * will panic. We will update physical_freestart and
485 * physical_freeend later to reflect what pmap_bootstrap()
486 * wants to see.
487 *
488 * XXX pmap_bootstrap() needs an enema.
489 */
490 physical_start = bootconfig.dram[0].address;
491 physical_end = bootconfig.dram[0].address
492 + (bootconfig.dram[0].pages * PAGE_SIZE);
493
494 physical_freestart = 0xc0018000UL;
495 physical_freeend = 0xc0200000UL;
496
497 physmem = (physical_end - physical_start) / PAGE_SIZE;
498
499 #ifdef VERBOSE_INIT_ARM
500 /* Tell the user about the memory */
501 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
502 physical_start, physical_end - 1);
503 #endif
504
505 /*
506 * Okay, the kernel starts 2MB in from the bottom of physical
507 * memory. We are going to allocate our bootstrap pages downwards
508 * from there.
509 *
510 * We need to allocate some fixed page tables to get the kernel
511 * going. We allocate one page directory and a number of page
512 * tables and store the physical addresses in the kernel_pt_table
513 * array.
514 *
515 * The kernel page directory must be on a 16K boundary. The page
516 * tables must be on 4K bounaries. What we do is allocate the
517 * page directory on the first 16K boundary that we encounter, and
518 * the page tables on 4K boundaries otherwise. Since we allocate
519 * at least 3 L2 page tables, we are guaranteed to encounter at
520 * least one 16K aligned region.
521 */
522
523 #ifdef VERBOSE_INIT_ARM
524 printf("Allocating page tables\n");
525 #endif
526
527 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
528
529 #ifdef VERBOSE_INIT_ARM
530 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
531 physical_freestart, free_pages, free_pages);
532 #endif
533
534 /* Define a macro to simplify memory allocation */
535 #define valloc_pages(var, np) \
536 alloc_pages((var).pv_pa, (np)); \
537 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
538
539 #define alloc_pages(var, np) \
540 physical_freeend -= ((np) * PAGE_SIZE); \
541 if (physical_freeend < physical_freestart) \
542 panic("initarm: out of memory"); \
543 (var) = physical_freeend; \
544 free_pages -= (np); \
545 memset((char *)(var), 0, ((np) * PAGE_SIZE));
546
547 loop1 = 0;
548 kernel_l1pt.pv_pa = 0;
549 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
550 /* Are we 16KB aligned for an L1 ? */
551 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
552 && kernel_l1pt.pv_pa == 0) {
553 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
554 } else {
555 valloc_pages(kernel_pt_table[loop1],
556 L2_TABLE_SIZE / PAGE_SIZE);
557 ++loop1;
558 }
559 }
560
561 /* This should never be able to happen but better confirm that. */
562 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
563 panic("initarm: Failed to align the kernel page directory");
564
565 /*
566 * Allocate a page for the system vectors page
567 */
568 alloc_pages(systempage.pv_pa, 1);
569
570 /* Allocate stacks for all modes */
571 valloc_pages(irqstack, IRQ_STACK_SIZE);
572 valloc_pages(abtstack, ABT_STACK_SIZE);
573 valloc_pages(undstack, UND_STACK_SIZE);
574 valloc_pages(kernelstack, UPAGES);
575
576 #ifdef VERBOSE_INIT_ARM
577 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
578 irqstack.pv_va);
579 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
580 abtstack.pv_va);
581 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
582 undstack.pv_va);
583 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
584 kernelstack.pv_va);
585 #endif
586
587 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
588
589 /*
590 * Ok we have allocated physical pages for the primary kernel
591 * page tables. Save physical_freeend for when we give whats left
592 * of memory below 2Mbyte to UVM.
593 */
594
595 physical_freeend_low = physical_freeend;
596
597 #ifdef VERBOSE_INIT_ARM
598 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
599 #endif
600
601 /*
602 * Now we start construction of the L1 page table
603 * We start by mapping the L2 page tables into the L1.
604 * This means that we can replace L1 mappings later on if necessary
605 */
606 l1pagetable = kernel_l1pt.pv_pa;
607
608 /* Map the L2 pages tables in the L1 page table */
609 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
610 &kernel_pt_table[KERNEL_PT_SYS]);
611 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
612 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
613 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
614 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
615 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
616 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
617
618 /* update the top of the kernel VM */
619 pmap_curmaxkvaddr =
620 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
621
622 #ifdef VERBOSE_INIT_ARM
623 printf("Mapping kernel\n");
624 #endif
625
626 /* Now we fill in the L2 pagetable for the kernel static code/data */
627 {
628 extern char etext[], _end[];
629 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
630 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
631 u_int logical;
632
633 textsize = (textsize + PGOFSET) & ~PGOFSET;
634 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
635
636 logical = 0x00200000; /* offset of kernel in RAM */
637 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
638 physical_start + logical, textsize,
639 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
640 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
641 physical_start + logical, totalsize - textsize,
642 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
643 }
644
645 #ifdef VERBOSE_INIT_ARM
646 printf("Constructing L2 page tables\n");
647 #endif
648
649 /* Map the stack pages */
650 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
651 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
652 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
653 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
654 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
655 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
656 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
657 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
658
659 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
660 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
661
662 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
663 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
664 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
665 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
666 }
667
668 /* Map the vector page. */
669 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
670 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
671
672 /* Map the statically mapped devices. */
673 pmap_devmap_bootstrap(l1pagetable, armadillo9_devmap);
674
675 /*
676 * Update the physical_freestart/physical_freeend/free_pages
677 * variables.
678 */
679 {
680 extern char _end[];
681
682 physical_freestart = physical_start +
683 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
684 KERNEL_BASE);
685 physical_freeend = physical_end;
686 free_pages =
687 (physical_freeend - physical_freestart) / PAGE_SIZE;
688 }
689
690 /*
691 * Now we have the real page tables in place so we can switch to them.
692 * Once this is done we will be running with the REAL kernel page
693 * tables.
694 */
695
696 /* Switch tables */
697 #ifdef VERBOSE_INIT_ARM
698 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
699 physical_freestart, free_pages, free_pages);
700 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
701 #endif
702 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
703 setttb(kernel_l1pt.pv_pa);
704 cpu_tlb_flushID();
705 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
706
707 /*
708 * Moved from cpu_startup() as data_abort_handler() references
709 * this during uvm init
710 */
711 proc0paddr = (struct user *)kernelstack.pv_va;
712 lwp0.l_addr = proc0paddr;
713
714 #ifdef VERBOSE_INIT_ARM
715 printf("done!\n");
716 #endif
717
718 #ifdef VERBOSE_INIT_ARM
719 printf("bootstrap done.\n");
720 #endif
721
722 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
723
724 /*
725 * Pages were allocated during the secondary bootstrap for the
726 * stacks for different CPU modes.
727 * We must now set the r13 registers in the different CPU modes to
728 * point to these stacks.
729 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
730 * of the stack memory.
731 */
732 #ifdef VERBOSE_INIT_ARM
733 printf("init subsystems: stacks ");
734 #endif
735
736 set_stackptr(PSR_IRQ32_MODE,
737 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
738 set_stackptr(PSR_ABT32_MODE,
739 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
740 set_stackptr(PSR_UND32_MODE,
741 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
742
743 /*
744 * Well we should set a data abort handler.
745 * Once things get going this will change as we will need a proper
746 * handler.
747 * Until then we will use a handler that just panics but tells us
748 * why.
749 * Initialisation of the vectors will just panic on a data abort.
750 * This just fills in a slightly better one.
751 */
752 #ifdef VERBOSE_INIT_ARM
753 printf("vectors ");
754 #endif
755 data_abort_handler_address = (u_int)data_abort_handler;
756 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
757 undefined_handler_address = (u_int)undefinedinstruction_bounce;
758
759 /* Initialise the undefined instruction handlers */
760 #ifdef VERBOSE_INIT_ARM
761 printf("undefined ");
762 #endif
763 undefined_init();
764
765 /* Load memory into UVM. */
766 #ifdef VERBOSE_INIT_ARM
767 printf("page ");
768 #endif
769 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
770 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
771 atop(physical_freestart), atop(physical_freeend),
772 VM_FREELIST_DEFAULT);
773 uvm_page_physload(atop(0xc0000000), atop(physical_freeend_low),
774 atop(0xc0000000), atop(physical_freeend_low),
775 VM_FREELIST_DEFAULT);
776 /*
777 * There is 64 MB of memory on the Armadillo-9 in 2 32MB chunks, so
778 * for we've only been working with the first one mapped at
779 * 0xc0000000. Tell UVM about the others.
780 */
781 uvm_page_physload(atop(0xc4000000), atop(0xc6000000),
782 atop(0xc4000000), atop(0xc6000000),
783 VM_FREELIST_DEFAULT);
784
785 physmem = 0x4000000 / PAGE_SIZE;
786
787
788 /* Boot strap pmap telling it where the kernel page table is */
789 #ifdef VERBOSE_INIT_ARM
790 printf("pmap ");
791 #endif
792 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
793 KERNEL_VM_BASE + KERNEL_VM_SIZE);
794
795 /* Setup the IRQ system */
796 #ifdef VERBOSE_INIT_ARM
797 printf("irq ");
798 #endif
799 ep93xx_intr_init();
800 #if NISA > 0
801 isa_intr_init();
802
803 #ifdef VERBOSE_INIT_ARM
804 printf("isa ");
805 #endif
806 isa_armadillo9_init(ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAIO,
807 ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAMEM);
808 #endif
809
810 #ifdef VERBOSE_INIT_ARM
811 printf("done.\n");
812 #endif
813
814 #ifdef BOOTHOWTO
815 boothowto = BOOTHOWTO;
816 #endif
817
818 #ifdef IPKDB
819 /* Initialise ipkdb */
820 ipkdb_init();
821 if (boothowto & RB_KDB)
822 ipkdb_connect(0);
823 #endif
824
825 #if NKSYMS || defined(DDB) || defined(LKM)
826 /* Firmware doesn't load symbols. */
827 ksyms_init(0, NULL, NULL);
828 #endif
829
830 #ifdef DDB
831 db_machine_init();
832 if (boothowto & RB_KDB)
833 Debugger();
834 #endif
835
836 /* We return the new stack pointer address */
837 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
838 }
839
840 void
841 consinit(void)
842 {
843 static int consinit_called;
844 #if NEPCOM > 0
845 bus_space_handle_t ioh;
846 #endif
847
848 if (consinit_called != 0)
849 return;
850
851 consinit_called = 1;
852
853 /*
854 * Console devices are already mapped in VA. Our devmap reflects
855 * this, so register it now so drivers can map the console
856 * device.
857 */
858 pmap_devmap_register(armadillo9_devmap);
859 #if 0
860 isa_armadillo9_init(ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAIO,
861 ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAMEM);
862
863 if (comcnattach(&isa_io_bs_tag, 0x3e8, comcnspeed,
864 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
865 {
866 panic("can't init serial console");
867 }
868 #endif
869
870 #if NEPCOM > 0
871 bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
872 EP93XX_APB_UART_SIZE, 0, &ioh);
873 if (epcomcnattach(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
874 ioh, comcnspeed, comcnmode))
875 {
876 panic("can't init serial console");
877 }
878 #else
879 panic("serial console not configured");
880 #endif
881 #if KGDB
882 #if NEPCOM > 0
883 if (strcmp(kgdb_devname, "epcom") == 0) {
884 com_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
885 kgdb_devmode);
886 }
887 #endif /* NEPCOM > 0 */
888 #endif /* KGDB */
889 }
890
891
892 bus_dma_tag_t
893 ep93xx_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
894 {
895 int i;
896 struct arm32_bus_dma_tag *dmat;
897
898 for (i = 0; i < bootconfig.dramblocks; i++) {
899 armadillo9_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
900 armadillo9_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
901 armadillo9_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
902 PAGE_SIZE;
903 }
904
905 dmat = dma_tag_template;
906
907 dmat->_ranges = armadillo9_dma_ranges;
908 dmat->_nranges = bootconfig.dramblocks;
909
910 return dmat;
911 }
912