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