1 /* $NetBSD: tsarm_machdep.c,v 1.37 2024/02/20 23:36:01 andvar 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.37 2024/02/20 23:36:01 andvar 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
cpu_reboot(int howto,char * bootstr)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 DEVMAP_ENTRY(
310 EP93XX_AHB_VBASE,
311 EP93XX_AHB_HWBASE,
312 EP93XX_AHB_SIZE
313 ),
314
315 DEVMAP_ENTRY(
316 EP93XX_APB_VBASE,
317 EP93XX_APB_HWBASE,
318 EP93XX_APB_SIZE
319 ),
320
321 /*
322 * IO8 and IO16 space *must* be mapped contiguously with
323 * IO8_VA == IO16_VA - 64 Mbytes. ISA busmap driver depends
324 * on that!
325 */
326 DEVMAP_ENTRY(
327 TS7XXX_IO8_VBASE,
328 TS7XXX_IO8_HWBASE,
329 TS7XXX_IO8_SIZE
330 ),
331
332 DEVMAP_ENTRY(
333 TS7XXX_IO16_VBASE,
334 TS7XXX_IO16_HWBASE,
335 TS7XXX_IO16_SIZE
336 ),
337
338 DEVMAP_ENTRY_END
339 };
340
341 /*
342 * vaddr_t initarm(...)
343 *
344 * Initial entry point on startup. This gets called before main() is
345 * entered.
346 * It should be responsible for setting up everything that must be
347 * in place when main is called.
348 * This includes
349 * Taking a copy of the boot configuration structure.
350 * Initialising the physical console so characters can be printed.
351 * Setting up page tables for the kernel
352 * Initialising interrupt controllers to a sane default state
353 */
354 vaddr_t
initarm(void * arg)355 initarm(void *arg)
356 {
357 #ifdef FIXME
358 struct bootconfig *passed_bootconfig = arg;
359 extern char _end[];
360 #endif
361 int loop;
362 int loop1;
363 u_int l1pagetable;
364
365 #ifdef FIXME
366 paddr_t memstart;
367 psize_t memsize;
368
369 /* Calibrate the delay loop. */
370 i80321_calibrate_delay();
371 #endif
372
373 /*
374 * Since we map the on-board devices VA==PA, and the kernel
375 * is running VA==PA, it's possible for us to initialize
376 * the console now.
377 */
378 consinit();
379
380 #ifdef VERBOSE_INIT_ARM
381 /* Talk to the user */
382 printf("\nNetBSD/tsarm booting ...\n");
383 #endif
384
385 /*
386 * Heads up ... Setup the CPU / MMU / TLB functions
387 */
388 if (set_cpufuncs())
389 panic("cpu not recognized!");
390
391 /*
392 * We are currently running with the MMU enabled
393 */
394
395 #ifdef FIXME
396 /*
397 * Fetch the SDRAM start/size from the i80321 SDRAM configuration
398 * registers.
399 */
400 i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
401 &memstart, &memsize);
402
403 memstart = 0x0;
404 memsize = 0x2000000;
405 #endif
406
407 #ifdef VERBOSE_INIT_ARM
408 printf("initarm: Configuring system ...\n");
409 #endif
410
411 /* Fake bootconfig structure for the benefit of pmap.c */
412 /* XXX must make the memory description h/w independent */
413 bootconfig.dramblocks = 4;
414 bootconfig.dram[0].address = 0x0UL;
415 bootconfig.dram[0].pages = 0x800000UL / PAGE_SIZE;
416 bootconfig.dram[1].address = 0x1000000UL;
417 bootconfig.dram[1].pages = 0x800000UL / PAGE_SIZE;
418 bootconfig.dram[2].address = 0x4000000UL;
419 bootconfig.dram[2].pages = 0x800000UL / PAGE_SIZE;
420 bootconfig.dram[3].address = 0x5000000UL;
421 bootconfig.dram[3].pages = 0x800000UL / PAGE_SIZE;
422
423 /*
424 * Set up the variables that define the availability of
425 * physical memory. For now, we're going to set
426 * physical_freestart to 0x00200000 (where the kernel
427 * was loaded), and allocate the memory we need downwards.
428 * If we get too close to the L1 table that we set up, we
429 * will panic. We will update physical_freestart and
430 * physical_freeend later to reflect what pmap_bootstrap()
431 * wants to see.
432 *
433 * XXX pmap_bootstrap() needs an enema.
434 */
435 physical_start = bootconfig.dram[0].address;
436 physical_end = bootconfig.dram[0].address +
437 (bootconfig.dram[0].pages * PAGE_SIZE);
438
439 physical_freestart = 0x00009000UL;
440 physical_freeend = 0x00200000UL;
441
442 physmem = (physical_end - physical_start) / PAGE_SIZE;
443
444 #ifdef VERBOSE_INIT_ARM
445 /* Tell the user about the memory */
446 printf("physmemory: 0x%"PRIxPSIZE" pages at 0x%08lx -> 0x%08lx\n", physmem,
447 physical_start, physical_end - 1);
448 #endif
449
450 /*
451 * Okay, the kernel starts 2MB in from the bottom of physical
452 * memory. We are going to allocate our bootstrap pages downwards
453 * from there.
454 *
455 * We need to allocate some fixed page tables to get the kernel
456 * going. We allocate one page directory and a number of page
457 * tables and store the physical addresses in the kernel_pt_table
458 * array.
459 *
460 * The kernel page directory must be on a 16K boundary. The page
461 * tables must be on 4K boundaries. What we do is allocate the
462 * page directory on the first 16K boundary that we encounter, and
463 * the page tables on 4K boundaries otherwise. Since we allocate
464 * at least 3 L2 page tables, we are guaranteed to encounter at
465 * least one 16K aligned region.
466 */
467
468 #ifdef VERBOSE_INIT_ARM
469 printf("Allocating page tables\n");
470 #endif
471
472 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
473
474 #ifdef VERBOSE_INIT_ARM
475 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
476 physical_freestart, free_pages, free_pages);
477 #endif
478
479 /* Define a macro to simplify memory allocation */
480 #define valloc_pages(var, np) \
481 alloc_pages((var).pv_pa, (np)); \
482 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
483
484 #define alloc_pages(var, np) \
485 physical_freeend -= ((np) * PAGE_SIZE); \
486 if (physical_freeend < physical_freestart) \
487 panic("initarm: out of memory"); \
488 (var) = physical_freeend; \
489 free_pages -= (np); \
490 memset((char *)(var), 0, ((np) * PAGE_SIZE));
491
492 loop1 = 0;
493 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
494 /* Are we 16KB aligned for an L1 ? */
495 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
496 && kernel_l1pt.pv_pa == 0) {
497 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
498 } else {
499 valloc_pages(kernel_pt_table[loop1],
500 L2_TABLE_SIZE / PAGE_SIZE);
501 ++loop1;
502 }
503 }
504
505 /* This should never be able to happen but better confirm that. */
506 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
507 panic("initarm: Failed to align the kernel page directory");
508
509 /*
510 * Allocate a page for the system vectors page
511 */
512 alloc_pages(systempage.pv_pa, 1);
513
514 /* Allocate stacks for all modes */
515 valloc_pages(irqstack, IRQ_STACK_SIZE);
516 valloc_pages(abtstack, ABT_STACK_SIZE);
517 valloc_pages(undstack, UND_STACK_SIZE);
518 valloc_pages(kernelstack, UPAGES);
519
520 #ifdef VERBOSE_INIT_ARM
521 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
522 irqstack.pv_va);
523 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
524 abtstack.pv_va);
525 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
526 undstack.pv_va);
527 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
528 kernelstack.pv_va);
529 #endif
530
531 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
532
533 /*
534 * Ok we have allocated physical pages for the primary kernel
535 * page tables. Save physical_freeend for when we give whats left
536 * of memory below 2Mbyte to UVM.
537 */
538
539 physical_freeend_low = physical_freeend;
540
541 #ifdef VERBOSE_INIT_ARM
542 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
543 #endif
544
545 /*
546 * Now we start construction of the L1 page table
547 * We start by mapping the L2 page tables into the L1.
548 * This means that we can replace L1 mappings later on if necessary
549 */
550 l1pagetable = kernel_l1pt.pv_pa;
551
552 /* Map the L2 pages tables in the L1 page table */
553 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
554 &kernel_pt_table[KERNEL_PT_SYS]);
555 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
556 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
557 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
558 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
559 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
560 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
561
562 /* update the top of the kernel VM */
563 pmap_curmaxkvaddr =
564 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
565
566 #ifdef VERBOSE_INIT_ARM
567 printf("Mapping kernel\n");
568 #endif
569
570 /* Now we fill in the L2 pagetable for the kernel static code/data */
571 {
572 extern char etext[], _end[];
573 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
574 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
575 u_int logical;
576
577 textsize = (textsize + PGOFSET) & ~PGOFSET;
578 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
579
580 logical = 0x00200000; /* offset of kernel in RAM */
581 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
582 physical_start + logical, textsize,
583 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
584 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
585 physical_start + logical, totalsize - textsize,
586 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
587 }
588
589 #ifdef VERBOSE_INIT_ARM
590 printf("Constructing L2 page tables\n");
591 #endif
592
593 /* Map the stack pages */
594 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
595 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
596 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
597 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
598 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
599 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
600 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
601 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
602
603 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
604 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
605
606 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
607 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
608 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
609 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
610 }
611
612 /* Map the vector page. */
613 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
614 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
615
616 /* Map the statically mapped devices. */
617 pmap_devmap_bootstrap(l1pagetable, tsarm_devmap);
618
619 /*
620 * Update the physical_freestart/physical_freeend/free_pages
621 * variables.
622 */
623 {
624 extern char _end[];
625
626 physical_freestart = physical_start +
627 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
628 KERNEL_BASE);
629 physical_freeend = physical_end;
630 free_pages =
631 (physical_freeend - physical_freestart) / PAGE_SIZE;
632 }
633
634 /*
635 * Now we have the real page tables in place so we can switch to them.
636 * Once this is done we will be running with the REAL kernel page
637 * tables.
638 */
639
640 /* Switch tables */
641 #ifdef VERBOSE_INIT_ARM
642 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
643 physical_freestart, free_pages, free_pages);
644 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
645 #endif
646 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
647 cpu_setttb(kernel_l1pt.pv_pa, true);
648 cpu_tlb_flushID();
649 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
650
651 /*
652 * Moved from cpu_startup() as data_abort_handler() references
653 * this during uvm init
654 */
655 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
656
657 #ifdef VERBOSE_INIT_ARM
658 printf("done!\n");
659 #endif
660
661 #ifdef VERBOSE_INIT_ARM
662 printf("bootstrap done.\n");
663 #endif
664
665 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
666
667 /*
668 * Pages were allocated during the secondary bootstrap for the
669 * stacks for different CPU modes.
670 * We must now set the r13 registers in the different CPU modes to
671 * point to these stacks.
672 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
673 * of the stack memory.
674 */
675 #ifdef VERBOSE_INIT_ARM
676 printf("init subsystems: stacks ");
677 #endif
678
679 set_stackptr(PSR_IRQ32_MODE,
680 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
681 set_stackptr(PSR_ABT32_MODE,
682 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
683 set_stackptr(PSR_UND32_MODE,
684 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
685
686 /*
687 * Well we should set a data abort handler.
688 * Once things get going this will change as we will need a proper
689 * handler.
690 * Until then we will use a handler that just panics but tells us
691 * why.
692 * Initialisation of the vectors will just panic on a data abort.
693 * This just fills in a slightly better one.
694 */
695 #ifdef VERBOSE_INIT_ARM
696 printf("vectors ");
697 #endif
698 data_abort_handler_address = (u_int)data_abort_handler;
699 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
700 undefined_handler_address = (u_int)undefinedinstruction_bounce;
701
702 /* Initialise the undefined instruction handlers */
703 #ifdef VERBOSE_INIT_ARM
704 printf("undefined ");
705 #endif
706 undefined_init();
707
708 /* Load memory into UVM. */
709 #ifdef VERBOSE_INIT_ARM
710 printf("page ");
711 #endif
712 uvm_md_init();
713 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
714 atop(physical_freestart), atop(physical_freeend),
715 VM_FREELIST_DEFAULT);
716 uvm_page_physload(0, atop(physical_freeend_low),
717 0, atop(physical_freeend_low),
718 VM_FREELIST_DEFAULT);
719 /*
720 * There is 32 Mb of memory on the TS-7200 in 4 8Mb chunks, so far
721 * we've only been working with the first one mapped at 0x0. Tell
722 * UVM about the others.
723 */
724 uvm_page_physload(atop(0x1000000), atop(0x1800000),
725 atop(0x1000000), atop(0x1800000),
726 VM_FREELIST_DEFAULT);
727 uvm_page_physload(atop(0x4000000), atop(0x4800000),
728 atop(0x4000000), atop(0x4800000),
729 VM_FREELIST_DEFAULT);
730 uvm_page_physload(atop(0x5000000), atop(0x5800000),
731 atop(0x5000000), atop(0x5800000),
732 VM_FREELIST_DEFAULT);
733
734 physmem = 0x2000000 / PAGE_SIZE;
735
736
737 /* Boot strap pmap telling it where managed kernel virtual memory is */
738 #ifdef VERBOSE_INIT_ARM
739 printf("pmap ");
740 #endif
741 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
742
743 /* Setup the IRQ system */
744 #ifdef VERBOSE_INIT_ARM
745 printf("irq ");
746 #endif
747 ep93xx_intr_init();
748 #if NISA > 0
749 isa_intr_init();
750
751 #ifdef VERBOSE_INIT_ARM
752 printf("isa ");
753 #endif
754 isa_tsarm_init(TS7XXX_IO16_VBASE + TS7XXX_ISAIO,
755 TS7XXX_IO16_VBASE + TS7XXX_ISAMEM);
756 #endif
757
758 #ifdef VERBOSE_INIT_ARM
759 printf("done.\n");
760 #endif
761
762 #ifdef BOOTHOWTO
763 boothowto = BOOTHOWTO;
764 #endif
765
766 #ifdef DDB
767 db_machine_init();
768 if (boothowto & RB_KDB)
769 Debugger();
770 #endif
771
772 /* We return the new stack pointer address */
773 return kernelstack.pv_va + USPACE_SVC_STACK_TOP;
774 }
775
776 void
consinit(void)777 consinit(void)
778 {
779 static int consinit_called;
780 bus_space_handle_t ioh;
781
782 if (consinit_called != 0)
783 return;
784
785 consinit_called = 1;
786
787 /*
788 * Console devices are already mapped in VA. Our devmap reflects
789 * this, so register it now so drivers can map the console
790 * device.
791 */
792 pmap_devmap_register(tsarm_devmap);
793 #if 0
794 isa_tsarm_init(TS7XXX_IO16_VBASE + TS7XXX_ISAIO,
795 TS7XXX_IO16_VBASE + TS7XXX_ISAMEM);
796
797 if (comcnattach(&isa_io_bs_tag, 0x3e8, comcnspeed,
798 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
799 {
800 panic("can't init serial console");
801 }
802 #endif
803
804 #if NEPCOM > 0
805 bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
806 EP93XX_APB_UART_SIZE, 0, &ioh);
807 if (epcomcnattach(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
808 ioh, comcnspeed, comcnmode))
809 {
810 panic("can't init serial console");
811 }
812 #else
813 panic("serial console not configured");
814 #endif
815 #if KGDB
816 #if NEPCOM > 0
817 if (strcmp(kgdb_devname, "epcom") == 0) {
818 epcom_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
819 kgdb_devmode);
820 }
821 #endif /* NEPCOM > 0 */
822 #endif /* KGDB */
823 }
824
825
826 bus_dma_tag_t
ep93xx_bus_dma_init(struct arm32_bus_dma_tag * dma_tag_template)827 ep93xx_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
828 {
829 int i;
830 struct arm32_bus_dma_tag *dmat;
831
832 for (i = 0; i < bootconfig.dramblocks; i++) {
833 tsarm_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
834 tsarm_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
835 tsarm_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
836 PAGE_SIZE;
837 }
838
839 dmat = dma_tag_template;
840
841 dmat->_ranges = tsarm_dma_ranges;
842 dmat->_nranges = bootconfig.dramblocks;
843
844 return dmat;
845 }
846
847 void
cpu_startup_hook(void)848 cpu_startup_hook(void)
849 {
850 ep93xx_intr_evcnt_attach();
851 }
852