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