tsarm_machdep.c revision 1.1.12.3 1 /* $NetBSD: tsarm_machdep.c,v 1.1.12.3 2008/01/21 09:36:16 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.1.12.3 2008/01/21 09:36:16 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 int physmem = 0;
166
167 /* Physical and virtual addresses for some global pages */
168 pv_addr_t systempage;
169 pv_addr_t irqstack;
170 pv_addr_t undstack;
171 pv_addr_t abtstack;
172 pv_addr_t kernelstack;
173
174 vm_offset_t msgbufphys;
175
176 static struct arm32_dma_range tsarm_dma_ranges[4];
177
178 #if NISA > 0
179 extern void isa_tsarm_init(u_int, u_int);
180 #endif
181
182 extern u_int data_abort_handler_address;
183 extern u_int prefetch_abort_handler_address;
184 extern u_int undefined_handler_address;
185
186 #ifdef PMAP_DEBUG
187 extern int pmap_debug_level;
188 #endif
189
190 #define KERNEL_PT_SYS 0 /* L2 table for mapping vectors page */
191
192 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
193 #define KERNEL_PT_KERNEL_NUM 4
194 /* L2 tables for mapping kernel VM */
195 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
196
197 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
198 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
199
200 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
201
202 struct user *proc0paddr;
203
204 /* Prototypes */
205
206 void consinit(void);
207 /*
208 * Define the default console speed for the machine.
209 */
210 #ifndef CONSPEED
211 #define CONSPEED B115200
212 #endif /* ! CONSPEED */
213
214 #ifndef CONMODE
215 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
216 #endif
217
218 int comcnspeed = CONSPEED;
219 int comcnmode = CONMODE;
220
221 #if KGDB
222 #ifndef KGDB_DEVNAME
223 #error Must define KGDB_DEVNAME
224 #endif
225 const char kgdb_devname[] = KGDB_DEVNAME;
226
227 #ifndef KGDB_DEVADDR
228 #error Must define KGDB_DEVADDR
229 #endif
230 unsigned long kgdb_devaddr = KGDB_DEVADDR;
231
232 #ifndef KGDB_DEVRATE
233 #define KGDB_DEVRATE CONSPEED
234 #endif
235 int kgdb_devrate = KGDB_DEVRATE;
236
237 #ifndef KGDB_DEVMODE
238 #define KGDB_DEVMODE CONMODE
239 #endif
240 int kgdb_devmode = KGDB_DEVMODE;
241 #endif /* KGDB */
242
243 /*
244 * void cpu_reboot(int howto, char *bootstr)
245 *
246 * Reboots the system
247 *
248 * Deal with any syncing, unmounting, dumping and shutdown hooks,
249 * then reset the CPU.
250 */
251 void
252 cpu_reboot(int howto, char *bootstr)
253 {
254
255 /*
256 * If we are still cold then hit the air brakes
257 * and crash to earth fast
258 */
259 if (cold) {
260 doshutdownhooks();
261 printf("\r\n");
262 printf("The operating system has halted.\r\n");
263 printf("Please press any key to reboot.\r\n");
264 cngetc();
265 printf("\r\nrebooting...\r\n");
266 goto reset;
267 }
268
269 /* Disable console buffering */
270
271 /*
272 * If RB_NOSYNC was not specified sync the discs.
273 * Note: Unless cold is set to 1 here, syslogd will die during the
274 * unmount. It looks like syslogd is getting woken up only to find
275 * that it cannot page part of the binary in as the filesystem has
276 * been unmounted.
277 */
278 if (!(howto & RB_NOSYNC))
279 bootsync();
280
281 /* Say NO to interrupts */
282 splhigh();
283
284 /* Do a dump if requested. */
285 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
286 dumpsys();
287
288 /* Run any shutdown hooks */
289 doshutdownhooks();
290
291 /* Make sure IRQ's are disabled */
292 IRQdisable;
293
294 if (howto & RB_HALT) {
295 printf("\r\n");
296 printf("The operating system has halted.\r\n");
297 printf("Please press any key to reboot.\r\n");
298 cngetc();
299 }
300
301 printf("\r\nrebooting...\r\n");
302 reset:
303 /*
304 * Make really really sure that all interrupts are disabled,
305 * and poke the Internal Bus and Peripheral Bus reset lines.
306 */
307 (void) disable_interrupts(I32_bit|F32_bit);
308
309 {
310 u_int32_t feed, ctrl;
311
312 feed = TS7XXX_IO16_VBASE + TS7XXX_WDOGFEED;
313 ctrl = TS7XXX_IO16_VBASE + TS7XXX_WDOGCTRL;
314
315 __asm volatile (
316 "mov r0, #0x5\n"
317 "mov r1, #0x1\n"
318 "strh r0, [%0]\n"
319 "strh r1, [%1]\n"
320 :
321 : "r" (feed), "r" (ctrl)
322 : "r0", "r1"
323 );
324 }
325
326 for (;;);
327 }
328
329 /* Static device mappings. */
330 static const struct pmap_devmap tsarm_devmap[] = {
331 {
332 EP93XX_AHB_VBASE,
333 EP93XX_AHB_HWBASE,
334 EP93XX_AHB_SIZE,
335 VM_PROT_READ|VM_PROT_WRITE,
336 PTE_NOCACHE,
337 },
338
339 {
340 EP93XX_APB_VBASE,
341 EP93XX_APB_HWBASE,
342 EP93XX_APB_SIZE,
343 VM_PROT_READ|VM_PROT_WRITE,
344 PTE_NOCACHE,
345 },
346
347 /*
348 * IO8 and IO16 space *must* be mapped contiguously with
349 * IO8_VA == IO16_VA - 64 Mbytes. ISA busmap driver depends
350 * on that!
351 */
352 {
353 TS7XXX_IO8_VBASE,
354 TS7XXX_IO8_HWBASE,
355 TS7XXX_IO8_SIZE,
356 VM_PROT_READ|VM_PROT_WRITE,
357 PTE_NOCACHE,
358 },
359
360 {
361 TS7XXX_IO16_VBASE,
362 TS7XXX_IO16_HWBASE,
363 TS7XXX_IO16_SIZE,
364 VM_PROT_READ|VM_PROT_WRITE,
365 PTE_NOCACHE,
366 },
367
368 {
369 0,
370 0,
371 0,
372 0,
373 0,
374 }
375 };
376
377 /*
378 * u_int initarm(...)
379 *
380 * Initial entry point on startup. This gets called before main() is
381 * entered.
382 * It should be responsible for setting up everything that must be
383 * in place when main is called.
384 * This includes
385 * Taking a copy of the boot configuration structure.
386 * Initialising the physical console so characters can be printed.
387 * Setting up page tables for the kernel
388 * Initialising interrupt controllers to a sane default state
389 */
390 u_int
391 initarm(void *arg)
392 {
393 #ifdef FIXME
394 struct bootconfig *passed_bootconfig = arg;
395 extern char _end[];
396 #endif
397 int loop;
398 int loop1;
399 u_int l1pagetable;
400 pv_addr_t kernel_l1pt;
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 kernel_l1pt.pv_pa = 0;
530 kernel_l1pt.pv_va = 0;
531 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
532 /* Are we 16KB aligned for an L1 ? */
533 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
534 && kernel_l1pt.pv_pa == 0) {
535 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
536 } else {
537 valloc_pages(kernel_pt_table[loop1],
538 L2_TABLE_SIZE / PAGE_SIZE);
539 ++loop1;
540 }
541 }
542
543 /* This should never be able to happen but better confirm that. */
544 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
545 panic("initarm: Failed to align the kernel page directory");
546
547 /*
548 * Allocate a page for the system vectors page
549 */
550 alloc_pages(systempage.pv_pa, 1);
551
552 /* Allocate stacks for all modes */
553 valloc_pages(irqstack, IRQ_STACK_SIZE);
554 valloc_pages(abtstack, ABT_STACK_SIZE);
555 valloc_pages(undstack, UND_STACK_SIZE);
556 valloc_pages(kernelstack, UPAGES);
557
558 #ifdef VERBOSE_INIT_ARM
559 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
560 irqstack.pv_va);
561 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
562 abtstack.pv_va);
563 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
564 undstack.pv_va);
565 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
566 kernelstack.pv_va);
567 #endif
568
569 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
570
571 /*
572 * Ok we have allocated physical pages for the primary kernel
573 * page tables. Save physical_freeend for when we give whats left
574 * of memory below 2Mbyte to UVM.
575 */
576
577 physical_freeend_low = physical_freeend;
578
579 #ifdef VERBOSE_INIT_ARM
580 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
581 #endif
582
583 /*
584 * Now we start construction of the L1 page table
585 * We start by mapping the L2 page tables into the L1.
586 * This means that we can replace L1 mappings later on if necessary
587 */
588 l1pagetable = kernel_l1pt.pv_pa;
589
590 /* Map the L2 pages tables in the L1 page table */
591 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
592 &kernel_pt_table[KERNEL_PT_SYS]);
593 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
594 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
595 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
596 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
597 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
598 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
599
600 /* update the top of the kernel VM */
601 pmap_curmaxkvaddr =
602 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
603
604 #ifdef VERBOSE_INIT_ARM
605 printf("Mapping kernel\n");
606 #endif
607
608 /* Now we fill in the L2 pagetable for the kernel static code/data */
609 {
610 extern char etext[], _end[];
611 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
612 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
613 u_int logical;
614
615 textsize = (textsize + PGOFSET) & ~PGOFSET;
616 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
617
618 logical = 0x00200000; /* offset of kernel in RAM */
619 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
620 physical_start + logical, textsize,
621 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
622 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
623 physical_start + logical, totalsize - textsize,
624 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
625 }
626
627 #ifdef VERBOSE_INIT_ARM
628 printf("Constructing L2 page tables\n");
629 #endif
630
631 /* Map the stack pages */
632 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
633 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
634 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
635 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
636 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
637 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
638 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
639 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
640
641 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
642 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
643
644 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
645 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
646 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
647 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
648 }
649
650 /* Map the vector page. */
651 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
652 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
653
654 /* Map the statically mapped devices. */
655 pmap_devmap_bootstrap(l1pagetable, tsarm_devmap);
656
657 /*
658 * Update the physical_freestart/physical_freeend/free_pages
659 * variables.
660 */
661 {
662 extern char _end[];
663
664 physical_freestart = physical_start +
665 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
666 KERNEL_BASE);
667 physical_freeend = physical_end;
668 free_pages =
669 (physical_freeend - physical_freestart) / PAGE_SIZE;
670 }
671
672 /*
673 * Now we have the real page tables in place so we can switch to them.
674 * Once this is done we will be running with the REAL kernel page
675 * tables.
676 */
677
678 /* Switch tables */
679 #ifdef VERBOSE_INIT_ARM
680 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
681 physical_freestart, free_pages, free_pages);
682 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
683 #endif
684 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
685 setttb(kernel_l1pt.pv_pa);
686 cpu_tlb_flushID();
687 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
688
689 /*
690 * Moved from cpu_startup() as data_abort_handler() references
691 * this during uvm init
692 */
693 proc0paddr = (struct user *)kernelstack.pv_va;
694 lwp0.l_addr = proc0paddr;
695
696 #ifdef VERBOSE_INIT_ARM
697 printf("done!\n");
698 #endif
699
700 #ifdef VERBOSE_INIT_ARM
701 printf("bootstrap done.\n");
702 #endif
703
704 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
705
706 /*
707 * Pages were allocated during the secondary bootstrap for the
708 * stacks for different CPU modes.
709 * We must now set the r13 registers in the different CPU modes to
710 * point to these stacks.
711 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
712 * of the stack memory.
713 */
714 #ifdef VERBOSE_INIT_ARM
715 printf("init subsystems: stacks ");
716 #endif
717
718 set_stackptr(PSR_IRQ32_MODE,
719 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
720 set_stackptr(PSR_ABT32_MODE,
721 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
722 set_stackptr(PSR_UND32_MODE,
723 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
724
725 /*
726 * Well we should set a data abort handler.
727 * Once things get going this will change as we will need a proper
728 * handler.
729 * Until then we will use a handler that just panics but tells us
730 * why.
731 * Initialisation of the vectors will just panic on a data abort.
732 * This just fills in a slightly better one.
733 */
734 #ifdef VERBOSE_INIT_ARM
735 printf("vectors ");
736 #endif
737 data_abort_handler_address = (u_int)data_abort_handler;
738 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
739 undefined_handler_address = (u_int)undefinedinstruction_bounce;
740
741 /* Initialise the undefined instruction handlers */
742 #ifdef VERBOSE_INIT_ARM
743 printf("undefined ");
744 #endif
745 undefined_init();
746
747 /* Load memory into UVM. */
748 #ifdef VERBOSE_INIT_ARM
749 printf("page ");
750 #endif
751 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
752 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
753 atop(physical_freestart), atop(physical_freeend),
754 VM_FREELIST_DEFAULT);
755 uvm_page_physload(0, atop(physical_freeend_low),
756 0, atop(physical_freeend_low),
757 VM_FREELIST_DEFAULT);
758 /*
759 * There is 32 Mb of memory on the TS-7200 in 4 8Mb chunks, so far
760 * we've only been working with the first one mapped at 0x0. Tell
761 * UVM about the others.
762 */
763 uvm_page_physload(atop(0x1000000), atop(0x1800000),
764 atop(0x1000000), atop(0x1800000),
765 VM_FREELIST_DEFAULT);
766 uvm_page_physload(atop(0x4000000), atop(0x4800000),
767 atop(0x4000000), atop(0x4800000),
768 VM_FREELIST_DEFAULT);
769 uvm_page_physload(atop(0x5000000), atop(0x5800000),
770 atop(0x5000000), atop(0x5800000),
771 VM_FREELIST_DEFAULT);
772
773 physmem = 0x2000000 / PAGE_SIZE;
774
775
776 /* Boot strap pmap telling it where the kernel page table is */
777 #ifdef VERBOSE_INIT_ARM
778 printf("pmap ");
779 #endif
780 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
781 KERNEL_VM_BASE + KERNEL_VM_SIZE);
782
783 /* Setup the IRQ system */
784 #ifdef VERBOSE_INIT_ARM
785 printf("irq ");
786 #endif
787 ep93xx_intr_init();
788 #if NISA > 0
789 isa_intr_init();
790
791 #ifdef VERBOSE_INIT_ARM
792 printf("isa ");
793 #endif
794 isa_tsarm_init(TS7XXX_IO16_VBASE + TS7XXX_ISAIO,
795 TS7XXX_IO16_VBASE + TS7XXX_ISAMEM);
796 #endif
797
798 #ifdef VERBOSE_INIT_ARM
799 printf("done.\n");
800 #endif
801
802 #ifdef BOOTHOWTO
803 boothowto = BOOTHOWTO;
804 #endif
805
806 #if NKSYMS || defined(DDB) || defined(LKM)
807 /* Firmware doesn't load symbols. */
808 ksyms_init(0, NULL, NULL);
809 #endif
810
811 #ifdef DDB
812 db_machine_init();
813 if (boothowto & RB_KDB)
814 Debugger();
815 #endif
816
817 /* We return the new stack pointer address */
818 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
819 }
820
821 void
822 consinit(void)
823 {
824 static int consinit_called;
825 bus_space_handle_t ioh;
826
827 if (consinit_called != 0)
828 return;
829
830 consinit_called = 1;
831
832 /*
833 * Console devices are already mapped in VA. Our devmap reflects
834 * this, so register it now so drivers can map the console
835 * device.
836 */
837 pmap_devmap_register(tsarm_devmap);
838 #if 0
839 isa_tsarm_init(TS7XXX_IO16_VBASE + TS7XXX_ISAIO,
840 TS7XXX_IO16_VBASE + TS7XXX_ISAMEM);
841
842 if (comcnattach(&isa_io_bs_tag, 0x3e8, comcnspeed,
843 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
844 {
845 panic("can't init serial console");
846 }
847 #endif
848
849 #if NEPCOM > 0
850 bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
851 EP93XX_APB_UART_SIZE, 0, &ioh);
852 if (epcomcnattach(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
853 ioh, comcnspeed, comcnmode))
854 {
855 panic("can't init serial console");
856 }
857 #else
858 panic("serial console not configured");
859 #endif
860 #if KGDB
861 #if NEPCOM > 0
862 if (strcmp(kgdb_devname, "epcom") == 0) {
863 com_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
864 kgdb_devmode);
865 }
866 #endif /* NEPCOM > 0 */
867 #endif /* KGDB */
868 }
869
870
871 bus_dma_tag_t
872 ep93xx_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
873 {
874 int i;
875 struct arm32_bus_dma_tag *dmat;
876
877 for (i = 0; i < bootconfig.dramblocks; i++) {
878 tsarm_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
879 tsarm_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
880 tsarm_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
881 PAGE_SIZE;
882 }
883
884 dmat = dma_tag_template;
885
886 dmat->_ranges = tsarm_dma_ranges;
887 dmat->_nranges = bootconfig.dramblocks;
888
889 return dmat;
890 }
891