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