armadillo9_machdep.c revision 1.4 1 /* $NetBSD: armadillo9_machdep.c,v 1.4 2006/02/13 12:24:21 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 Armadillo.
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.4 2006/02/13 12:24:21 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 #define DRAM_BLOCKS 4
139 #include <machine/bootconfig.h>
140 #include <machine/bus.h>
141 #include <machine/cpu.h>
142 #include <machine/frame.h>
143 #include <arm/undefined.h>
144
145 #include <arm/arm32/machdep.h>
146
147 #include <arm/ep93xx/ep93xxreg.h>
148 #include <arm/ep93xx/ep93xxvar.h>
149
150 #include "epwdog.h"
151 #if NEPWDOG > 0
152 #include <arm/ep93xx/epwdogvar.h>
153 #endif
154 #include <arm/ep93xx/epwdogreg.h>
155
156 #include <dev/ic/comreg.h>
157 #include <dev/ic/comvar.h>
158
159 #include "epcom.h"
160 #if NEPCOM > 0
161 #include <arm/ep93xx/epcomvar.h>
162 #endif
163
164 #include "isa.h"
165 #if NISA > 0
166 #include <dev/isa/isareg.h>
167 #include <dev/isa/isavar.h>
168 #endif
169
170 #include <machine/isa_machdep.h>
171
172 #include <evbarm/armadillo/armadillo9reg.h>
173 #include <evbarm/armadillo/armadillo9var.h>
174
175 struct armadillo_model_t *armadillo_model = 0;
176 static struct armadillo_model_t armadillo_model_table[] = {
177 { DEVCFG_ARMADILLO9, "Armadillo-9" },
178 { DEVCFG_ARMADILLO210, "Armadillo-210" },
179 { 0, "Armadillo(unknown model)" } };
180
181 #include "opt_ipkdb.h"
182 #include "ksyms.h"
183
184 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
185 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
186 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
187
188 /*
189 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
190 * Core-logic registers and I/O mappings occupy 0xf0000000 - 0xffffffff
191 */
192 #define KERNEL_VM_SIZE 0x0c000000
193
194 /*
195 * Address to call from cpu_reset() to reset the machine.
196 * This is machine architecture dependant as it varies depending
197 * on where the ROM appears when you turn the MMU off.
198 */
199
200 u_int cpu_reset_address = 0x80090000;
201
202 /* Define various stack sizes in pages */
203 #define IRQ_STACK_SIZE 8
204 #define ABT_STACK_SIZE 8
205 #ifdef IPKDB
206 #define UND_STACK_SIZE 16
207 #else
208 #define UND_STACK_SIZE 8
209 #endif
210
211 BootConfig bootconfig; /* Boot config storage */
212 char *boot_args = NULL;
213 char *boot_file = NULL;
214
215 vm_offset_t physical_start;
216 vm_offset_t physical_freestart;
217 vm_offset_t physical_freeend;
218 vm_offset_t physical_freeend_low;
219 vm_offset_t physical_end;
220 u_int free_pages;
221 int physmem = 0;
222
223 /* Physical and virtual addresses for some global pages */
224 pv_addr_t systempage;
225 pv_addr_t irqstack;
226 pv_addr_t undstack;
227 pv_addr_t abtstack;
228 pv_addr_t kernelstack;
229
230 vm_offset_t msgbufphys;
231
232 static struct arm32_dma_range armadillo9_dma_ranges[4];
233
234 #if NISA > 0
235 extern void isa_armadillo9_init(u_int, u_int);
236 #endif
237
238 extern u_int data_abort_handler_address;
239 extern u_int prefetch_abort_handler_address;
240 extern u_int undefined_handler_address;
241
242 #ifdef PMAP_DEBUG
243 extern int pmap_debug_level;
244 #endif
245
246 #define KERNEL_PT_SYS 0 /* L2 table for mapping vectors page */
247
248 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
249 #define KERNEL_PT_KERNEL_NUM 4
250 /* L2 tables for mapping kernel VM */
251 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
252
253 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
254 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
255
256 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
257
258 struct user *proc0paddr;
259
260 /* Prototypes */
261
262 void consinit(void);
263 /*
264 * Define the default console speed for the machine.
265 */
266 #if NEPCOM > 0
267 #ifndef CONSPEED
268 #define CONSPEED B115200
269 #endif /* ! CONSPEED */
270
271 #ifndef CONMODE
272 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
273 #endif
274
275 #ifndef CONUNIT
276 #define CONUNIT 0
277 #endif
278
279 int comcnspeed = CONSPEED;
280 int comcnmode = CONMODE;
281 const unsigned long comaddr[] = {
282 EP93XX_APB_UART1, EP93XX_APB_UART2 };
283 #endif
284
285 #if KGDB
286 #ifndef KGDB_DEVNAME
287 #error Must define KGDB_DEVNAME
288 #endif
289 const char kgdb_devname[] = KGDB_DEVNAME;
290
291 #ifndef KGDB_DEVADDR
292 #error Must define KGDB_DEVADDR
293 #endif
294 unsigned long kgdb_devaddr = KGDB_DEVADDR;
295
296 #ifndef KGDB_DEVRATE
297 #define KGDB_DEVRATE CONSPEED
298 #endif
299 int kgdb_devrate = KGDB_DEVRATE;
300
301 #ifndef KGDB_DEVMODE
302 #define KGDB_DEVMODE CONMODE
303 #endif
304 int kgdb_devmode = KGDB_DEVMODE;
305 #endif /* KGDB */
306
307 /*
308 * void cpu_reboot(int howto, char *bootstr)
309 *
310 * Reboots the system
311 *
312 * Deal with any syncing, unmounting, dumping and shutdown hooks,
313 * then reset the CPU.
314 */
315 void
316 cpu_reboot(int howto, char *bootstr)
317 {
318 /*
319 * If we are still cold then hit the air brakes
320 * and crash to earth fast
321 */
322 if (cold) {
323 doshutdownhooks();
324 printf("\r\n");
325 printf("The operating system has halted.\r\n");
326 printf("Please press any key to reboot.\r\n");
327 cngetc();
328 printf("\r\nrebooting...\r\n");
329 goto reset;
330 }
331
332 /* Disable console buffering */
333
334 /*
335 * If RB_NOSYNC was not specified sync the discs.
336 * Note: Unless cold is set to 1 here, syslogd will die during the
337 * unmount. It looks like syslogd is getting woken up only to find
338 * that it cannot page part of the binary in as the filesystem has
339 * been unmounted.
340 */
341 if (!(howto & RB_NOSYNC))
342 bootsync();
343
344 /* Say NO to interrupts */
345 splhigh();
346
347 /* Do a dump if requested. */
348 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
349 dumpsys();
350
351 /* Run any shutdown hooks */
352 doshutdownhooks();
353
354 /* Make sure IRQ's are disabled */
355 IRQdisable;
356
357 if (howto & RB_HALT) {
358 printf("\r\n");
359 printf("The operating system has halted.\r\n");
360 printf("Please press any key to reboot.\r\n");
361 cngetc();
362 }
363
364 printf("\r\nrebooting...\r\n");
365 reset:
366 /*
367 * Make really really sure that all interrupts are disabled,
368 * and poke the Internal Bus and Peripheral Bus reset lines.
369 */
370 (void) disable_interrupts(I32_bit|F32_bit);
371 #if NEPWDOG > 0
372 epwdog_reset();
373 #else
374 {
375 u_int32_t ctrl = EP93XX_APB_VBASE + EP93XX_APB_WDOG + EP93XX_WDOG_Ctrl;
376 u_int32_t val = EP93XX_WDOG_ENABLE;
377 __asm volatile (
378 "str %1, [%0]\n"
379 :
380 : "r" (ctrl), "r" (val)
381 );
382 }
383 #endif
384 for (;;);
385 }
386
387 /* Static device mappings. */
388 static const struct pmap_devmap armadillo9_devmap[] = {
389 {
390 EP93XX_AHB_VBASE,
391 EP93XX_AHB_HWBASE,
392 EP93XX_AHB_SIZE,
393 VM_PROT_READ|VM_PROT_WRITE,
394 PTE_NOCACHE,
395 },
396
397 {
398 EP93XX_APB_VBASE,
399 EP93XX_APB_HWBASE,
400 EP93XX_APB_SIZE,
401 VM_PROT_READ|VM_PROT_WRITE,
402 PTE_NOCACHE,
403 },
404
405 {
406 EP93XX_PCMCIA0_VBASE,
407 EP93XX_PCMCIA0_HWBASE,
408 EP93XX_PCMCIA_SIZE,
409 VM_PROT_READ|VM_PROT_WRITE,
410 PTE_NOCACHE,
411 },
412
413 /*
414 * IO8 and IO16 space *must* be mapped contiguously with
415 * IO8_VA == IO16_VA - 64 Mbytes. ISA busmap driver depends
416 * on that!
417 */
418 {
419 ARMADILLO9_IO8_VBASE,
420 ARMADILLO9_IO8_HWBASE,
421 ARMADILLO9_IO8_SIZE,
422 VM_PROT_READ|VM_PROT_WRITE,
423 PTE_NOCACHE,
424 },
425
426 {
427 ARMADILLO9_IO16_VBASE,
428 ARMADILLO9_IO16_HWBASE,
429 ARMADILLO9_IO16_SIZE,
430 VM_PROT_READ|VM_PROT_WRITE,
431 PTE_NOCACHE,
432 },
433
434 {
435 0,
436 0,
437 0,
438 0,
439 0,
440 }
441 };
442
443 /*
444 * u_int initarm(...)
445 *
446 * Initial entry point on startup. This gets called before main() is
447 * entered.
448 * It should be responsible for setting up everything that must be
449 * in place when main is called.
450 * This includes
451 * Taking a copy of the boot configuration structure.
452 * Initialising the physical console so characters can be printed.
453 * Setting up page tables for the kernel
454 * Initialising interrupt controllers to a sane default state
455 */
456 u_int
457 initarm(void *arg)
458 {
459 int loop;
460 int loop1;
461 u_int l1pagetable;
462 pv_addr_t kernel_l1pt;
463 struct bootparam_tag *bootparam_p;
464 unsigned long devcfg;
465
466 /*
467 * Since we map the on-board devices VA==PA, and the kernel
468 * is running VA==PA, it's possible for us to initialize
469 * the console now.
470 */
471 consinit();
472
473 /* identify model */
474 devcfg = *((volatile unsigned long*)(EP93XX_APB_HWBASE
475 + EP93XX_APB_SYSCON
476 + EP93XX_SYSCON_DeviceCfg));
477 for (armadillo_model = &armadillo_model_table[0];
478 armadillo_model->devcfg; armadillo_model++)
479 if (devcfg == armadillo_model->devcfg)
480 break;
481
482 /* Talk to the user */
483 printf("\nNetBSD/%s booting ...\n", armadillo_model->name);
484
485 /* set some informations from bootloader */
486 bootparam_p = (struct bootparam_tag *)bootparam;
487 bootconfig.dramblocks = 0;
488 while (bootparam_p->hdr.tag != BOOTPARAM_TAG_NONE) {
489 switch (bootparam_p->hdr.tag) {
490 case BOOTPARAM_TAG_MEM:
491 if (bootconfig.dramblocks < DRAM_BLOCKS) {
492 #ifdef VERBOSE_INIT_ARM
493 printf("dram[%d]: address=0x%08lx, size=0x%08lx\n",
494 bootconfig.dramblocks,
495 bootparam_p->u.mem.start,
496 bootparam_p->u.mem.size);
497 #endif
498 bootconfig.dram[bootconfig.dramblocks].address =
499 bootparam_p->u.mem.start;
500 bootconfig.dram[bootconfig.dramblocks].pages =
501 bootparam_p->u.mem.size / PAGE_SIZE;
502 bootconfig.dramblocks++;
503 }
504 break;
505 case BOOTPARAM_TAG_CMDLINE:
506 #ifdef VERBOSE_INIT_ARM
507 printf("cmdline: %s\n", bootparam_p->u.cmdline.cmdline);
508 #endif
509 parse_mi_bootargs(bootparam_p->u.cmdline.cmdline);
510 break;
511 }
512 bootparam_p = bootparam_tag_next(bootparam_p);
513 }
514
515 /*
516 * Heads up ... Setup the CPU / MMU / TLB functions
517 */
518 if (set_cpufuncs())
519 panic("cpu not recognized!");
520
521 #ifdef VERBOSE_INIT_ARM
522 printf("initarm: Configuring system ...\n");
523 #endif
524 /*
525 * Set up the variables that define the availablilty of
526 * physical memory. For now, we're going to set
527 * physical_freestart to 0xc0200000 (where the kernel
528 * was loaded), and allocate the memory we need downwards.
529 * If we get too close to the L1 table that we set up, we
530 * will panic. We will update physical_freestart and
531 * physical_freeend later to reflect what pmap_bootstrap()
532 * wants to see.
533 *
534 * XXX pmap_bootstrap() needs an enema.
535 */
536 physical_start = bootconfig.dram[0].address;
537 physical_end = bootconfig.dram[0].address
538 + (bootconfig.dram[0].pages * PAGE_SIZE);
539
540 physical_freestart = 0xc0018000UL;
541 physical_freeend = 0xc0200000UL;
542
543 physmem = (physical_end - physical_start) / PAGE_SIZE;
544
545 #ifdef VERBOSE_INIT_ARM
546 /* Tell the user about the memory */
547 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
548 physical_start, physical_end - 1);
549 #endif
550
551 /*
552 * Okay, the kernel starts 2MB in from the bottom of physical
553 * memory. We are going to allocate our bootstrap pages downwards
554 * from there.
555 *
556 * We need to allocate some fixed page tables to get the kernel
557 * going. We allocate one page directory and a number of page
558 * tables and store the physical addresses in the kernel_pt_table
559 * array.
560 *
561 * The kernel page directory must be on a 16K boundary. The page
562 * tables must be on 4K bounaries. What we do is allocate the
563 * page directory on the first 16K boundary that we encounter, and
564 * the page tables on 4K boundaries otherwise. Since we allocate
565 * at least 3 L2 page tables, we are guaranteed to encounter at
566 * least one 16K aligned region.
567 */
568
569 #ifdef VERBOSE_INIT_ARM
570 printf("Allocating page tables\n");
571 #endif
572
573 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
574
575 #ifdef VERBOSE_INIT_ARM
576 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
577 physical_freestart, free_pages, free_pages);
578 #endif
579
580 /* Define a macro to simplify memory allocation */
581 #define valloc_pages(var, np) \
582 alloc_pages((var).pv_pa, (np)); \
583 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
584
585 #define alloc_pages(var, np) \
586 physical_freeend -= ((np) * PAGE_SIZE); \
587 if (physical_freeend < physical_freestart) \
588 panic("initarm: out of memory"); \
589 (var) = physical_freeend; \
590 free_pages -= (np); \
591 memset((char *)(var), 0, ((np) * PAGE_SIZE));
592
593 loop1 = 0;
594 kernel_l1pt.pv_pa = 0;
595 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
596 /* Are we 16KB aligned for an L1 ? */
597 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
598 && kernel_l1pt.pv_pa == 0) {
599 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
600 } else {
601 valloc_pages(kernel_pt_table[loop1],
602 L2_TABLE_SIZE / PAGE_SIZE);
603 ++loop1;
604 }
605 }
606
607 /* This should never be able to happen but better confirm that. */
608 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
609 panic("initarm: Failed to align the kernel page directory");
610
611 /*
612 * Allocate a page for the system vectors page
613 */
614 alloc_pages(systempage.pv_pa, 1);
615
616 /* Allocate stacks for all modes */
617 valloc_pages(irqstack, IRQ_STACK_SIZE);
618 valloc_pages(abtstack, ABT_STACK_SIZE);
619 valloc_pages(undstack, UND_STACK_SIZE);
620 valloc_pages(kernelstack, UPAGES);
621
622 #ifdef VERBOSE_INIT_ARM
623 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
624 irqstack.pv_va);
625 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
626 abtstack.pv_va);
627 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
628 undstack.pv_va);
629 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
630 kernelstack.pv_va);
631 #endif
632
633 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
634
635 /*
636 * Ok we have allocated physical pages for the primary kernel
637 * page tables. Save physical_freeend for when we give whats left
638 * of memory below 2Mbyte to UVM.
639 */
640
641 physical_freeend_low = physical_freeend;
642
643 #ifdef VERBOSE_INIT_ARM
644 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
645 #endif
646
647 /*
648 * Now we start construction of the L1 page table
649 * We start by mapping the L2 page tables into the L1.
650 * This means that we can replace L1 mappings later on if necessary
651 */
652 l1pagetable = kernel_l1pt.pv_pa;
653
654 /* Map the L2 pages tables in the L1 page table */
655 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
656 &kernel_pt_table[KERNEL_PT_SYS]);
657 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
658 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
659 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
660 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
661 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
662 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
663
664 /* update the top of the kernel VM */
665 pmap_curmaxkvaddr =
666 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
667
668 #ifdef VERBOSE_INIT_ARM
669 printf("Mapping kernel\n");
670 #endif
671
672 /* Now we fill in the L2 pagetable for the kernel static code/data */
673 {
674 extern char etext[], _end[];
675 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
676 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
677 u_int logical;
678
679 textsize = (textsize + PGOFSET) & ~PGOFSET;
680 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
681
682 logical = 0x00200000; /* offset of kernel in RAM */
683 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
684 physical_start + logical, textsize,
685 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
686 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
687 physical_start + logical, totalsize - textsize,
688 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
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 /* Map the vector page. */
715 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
716 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
717
718 /* Map the statically mapped devices. */
719 pmap_devmap_bootstrap(l1pagetable, armadillo9_devmap);
720
721 /*
722 * Update the physical_freestart/physical_freeend/free_pages
723 * variables.
724 */
725 {
726 extern char _end[];
727
728 physical_freestart = physical_start +
729 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
730 KERNEL_BASE);
731 physical_freeend = physical_end;
732 free_pages =
733 (physical_freeend - physical_freestart) / PAGE_SIZE;
734 }
735
736 /*
737 * Now we have the real page tables in place so we can switch to them.
738 * Once this is done we will be running with the REAL kernel page
739 * tables.
740 */
741
742 /* Switch tables */
743 #ifdef VERBOSE_INIT_ARM
744 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
745 physical_freestart, free_pages, free_pages);
746 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
747 #endif
748 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
749 setttb(kernel_l1pt.pv_pa);
750 cpu_tlb_flushID();
751 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
752
753 /*
754 * Moved from cpu_startup() as data_abort_handler() references
755 * this during uvm init
756 */
757 proc0paddr = (struct user *)kernelstack.pv_va;
758 lwp0.l_addr = proc0paddr;
759
760 #ifdef VERBOSE_INIT_ARM
761 printf("done!\n");
762 #endif
763
764 #ifdef VERBOSE_INIT_ARM
765 printf("bootstrap done.\n");
766 #endif
767
768 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
769
770 /*
771 * Pages were allocated during the secondary bootstrap for the
772 * stacks for different CPU modes.
773 * We must now set the r13 registers in the different CPU modes to
774 * point to these stacks.
775 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
776 * of the stack memory.
777 */
778 #ifdef VERBOSE_INIT_ARM
779 printf("init subsystems: stacks ");
780 #endif
781
782 set_stackptr(PSR_IRQ32_MODE,
783 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
784 set_stackptr(PSR_ABT32_MODE,
785 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
786 set_stackptr(PSR_UND32_MODE,
787 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
788
789 /*
790 * Well we should set a data abort handler.
791 * Once things get going this will change as we will need a proper
792 * handler.
793 * Until then we will use a handler that just panics but tells us
794 * why.
795 * Initialisation of the vectors will just panic on a data abort.
796 * This just fills in a slightly better one.
797 */
798 #ifdef VERBOSE_INIT_ARM
799 printf("vectors ");
800 #endif
801 data_abort_handler_address = (u_int)data_abort_handler;
802 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
803 undefined_handler_address = (u_int)undefinedinstruction_bounce;
804
805 /* Initialise the undefined instruction handlers */
806 #ifdef VERBOSE_INIT_ARM
807 printf("undefined ");
808 #endif
809 undefined_init();
810
811 /* Load memory into UVM. */
812 #ifdef VERBOSE_INIT_ARM
813 printf("page ");
814 #endif
815 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
816 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
817 atop(physical_freestart), atop(physical_freeend),
818 VM_FREELIST_DEFAULT);
819 uvm_page_physload(atop(0xc0000000), atop(physical_freeend_low),
820 atop(0xc0000000), atop(physical_freeend_low),
821 VM_FREELIST_DEFAULT);
822 physmem = bootconfig.dram[0].pages;
823 for (loop = 1; loop < bootconfig.dramblocks; ++loop) {
824 size_t start = bootconfig.dram[loop].address;
825 size_t size = bootconfig.dram[loop].pages * PAGE_SIZE;
826 uvm_page_physload(atop(start), atop(start + size),
827 atop(start), atop(start + size),
828 VM_FREELIST_DEFAULT);
829 physmem += bootconfig.dram[loop].pages;
830 }
831
832 /* Boot strap pmap telling it where the kernel page table is */
833 #ifdef VERBOSE_INIT_ARM
834 printf("pmap ");
835 #endif
836 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
837 KERNEL_VM_BASE + KERNEL_VM_SIZE);
838
839 /* Setup the IRQ system */
840 #ifdef VERBOSE_INIT_ARM
841 printf("irq ");
842 #endif
843 ep93xx_intr_init();
844 #if NISA > 0
845 isa_intr_init();
846
847 #ifdef VERBOSE_INIT_ARM
848 printf("isa ");
849 #endif
850 isa_armadillo9_init(ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAIO,
851 ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAMEM);
852 #endif
853
854 #ifdef VERBOSE_INIT_ARM
855 printf("done.\n");
856 #endif
857
858 #ifdef BOOTHOWTO
859 boothowto = BOOTHOWTO;
860 #endif
861
862 #ifdef IPKDB
863 /* Initialise ipkdb */
864 ipkdb_init();
865 if (boothowto & RB_KDB)
866 ipkdb_connect(0);
867 #endif
868
869 #if NKSYMS || defined(DDB) || defined(LKM)
870 /* Firmware doesn't load symbols. */
871 ksyms_init(0, NULL, NULL);
872 #endif
873
874 #ifdef DDB
875 db_machine_init();
876 if (boothowto & RB_KDB)
877 Debugger();
878 #endif
879
880 /* We return the new stack pointer address */
881 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
882 }
883
884 void
885 consinit(void)
886 {
887 static int consinit_called;
888 #if NEPCOM > 0
889 bus_space_handle_t ioh;
890 #endif
891
892 if (consinit_called != 0)
893 return;
894
895 consinit_called = 1;
896
897 /*
898 * Console devices are already mapped in VA. Our devmap reflects
899 * this, so register it now so drivers can map the console
900 * device.
901 */
902 pmap_devmap_register(armadillo9_devmap);
903
904 #if NEPCOM > 0
905 bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + comaddr[CONUNIT],
906 EP93XX_APB_UART_SIZE, 0, &ioh);
907 if (epcomcnattach(&ep93xx_bs_tag, EP93XX_APB_HWBASE + comaddr[CONUNIT],
908 ioh, comcnspeed, comcnmode))
909 {
910 panic("can't init serial console");
911 }
912 #else
913 panic("serial console not configured");
914 #endif
915 #if KGDB
916 #if NEPCOM > 0
917 if (strcmp(kgdb_devname, "epcom") == 0) {
918 com_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
919 kgdb_devmode);
920 }
921 #endif /* NEPCOM > 0 */
922 #endif /* KGDB */
923 }
924
925
926 bus_dma_tag_t
927 ep93xx_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
928 {
929 int i;
930 struct arm32_bus_dma_tag *dmat;
931
932 for (i = 0; i < bootconfig.dramblocks; i++) {
933 armadillo9_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
934 armadillo9_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
935 armadillo9_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
936 PAGE_SIZE;
937 }
938
939 dmat = dma_tag_template;
940
941 dmat->_ranges = armadillo9_dma_ranges;
942 dmat->_nranges = bootconfig.dramblocks;
943
944 return dmat;
945 }
946