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