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