iq80310_machdep.c revision 1.92 1 /* $NetBSD: iq80310_machdep.c,v 1.92 2020/04/18 10:55:44 skrll Exp $ */
2
3 /*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Copyright (c) 1997,1998 Mark Brinicombe.
40 * Copyright (c) 1997,1998 Causality Limited.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by Mark Brinicombe
54 * for the NetBSD Project.
55 * 4. The name of the company nor the name of the author may be used to
56 * endorse or promote products derived from this software without specific
57 * prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
63 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * Machine dependent functions for kernel setup for Intel IQ80310 evaluation
72 * boards using RedBoot firmware.
73 */
74
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: iq80310_machdep.c,v 1.92 2020/04/18 10:55:44 skrll Exp $");
77
78 #include "opt_arm_debug.h"
79 #include "opt_console.h"
80 #include "opt_ddb.h"
81 #include "opt_pmap_debug.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 <machine/bootconfig.h>
105 #include <arm/locore.h>
106 #include <arm/undefined.h>
107
108 #include <arm/arm32/machdep.h>
109
110 #include <arm/xscale/i80312reg.h>
111 #include <arm/xscale/i80312var.h>
112
113 #include <dev/pci/ppbreg.h>
114
115 #include <evbarm/iq80310/iq80310reg.h>
116 #include <evbarm/iq80310/iq80310var.h>
117 #include <evbarm/iq80310/obiovar.h>
118
119 #include "ksyms.h"
120
121 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
122 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
123 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
124
125 /*
126 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
127 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
128 */
129 #define KERNEL_VM_SIZE 0x0C000000
130
131 BootConfig bootconfig; /* Boot config storage */
132 char *boot_args = NULL;
133 char *boot_file = NULL;
134
135 vaddr_t physical_start;
136 vaddr_t physical_freestart;
137 vaddr_t physical_freeend;
138 vaddr_t physical_end;
139 u_int free_pages;
140
141 /*int debug_flags;*/
142 #ifndef PMAP_STATIC_L1S
143 int max_processes = 64; /* Default number */
144 #endif /* !PMAP_STATIC_L1S */
145
146 pv_addr_t minidataclean;
147
148 paddr_t msgbufphys;
149
150 #ifdef PMAP_DEBUG
151 extern int pmap_debug_level;
152 #endif
153
154 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
155
156 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
157 #define KERNEL_PT_KERNEL_NUM 4
158
159 /* L2 table for mapping i80312 */
160 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
161
162 /* L2 tables for mapping kernel VM */
163 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
164 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
165 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
166
167 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
168
169 /* Prototypes */
170
171 void consinit(void);
172
173 #include "com.h"
174 #if NCOM > 0
175 #include <dev/ic/comreg.h>
176 #include <dev/ic/comvar.h>
177 #endif
178
179 /*
180 * Define the default console speed for the board. This is generally
181 * what the firmware provided with the board defaults to.
182 */
183 #ifndef CONSPEED
184 #define CONSPEED B115200
185 #endif /* ! CONSPEED */
186
187 #ifndef CONUNIT
188 #define CONUNIT 0
189 #endif
190
191 #ifndef CONMODE
192 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
193 #endif
194
195 int comcnspeed = CONSPEED;
196 int comcnmode = CONMODE;
197 int comcnunit = CONUNIT;
198
199 /*
200 * void cpu_reboot(int howto, char *bootstr)
201 *
202 * Reboots the system
203 *
204 * Deal with any syncing, unmounting, dumping and shutdown hooks,
205 * then reset the CPU.
206 */
207 void
208 cpu_reboot(int howto, char *bootstr)
209 {
210
211 /*
212 * If we are still cold then hit the air brakes
213 * and crash to earth fast
214 */
215 if (cold) {
216 doshutdownhooks();
217 pmf_system_shutdown(boothowto);
218 printf("The operating system has halted.\n");
219 printf("Please press any key to reboot.\n\n");
220 cngetc();
221 printf("rebooting...\n");
222 cpu_reset();
223 /*NOTREACHED*/
224 }
225
226 /* Disable console buffering */
227
228 /*
229 * If RB_NOSYNC was not specified sync the discs.
230 * Note: Unless cold is set to 1 here, syslogd will die during the
231 * unmount. It looks like syslogd is getting woken up only to find
232 * that it cannot page part of the binary in as the filesystem has
233 * been unmounted.
234 */
235 if (!(howto & RB_NOSYNC))
236 bootsync();
237
238 /* Say NO to interrupts */
239 splhigh();
240
241 /* Do a dump if requested. */
242 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
243 dumpsys();
244
245 /* Run any shutdown hooks */
246 doshutdownhooks();
247
248 pmf_system_shutdown(boothowto);
249
250 /* Make sure IRQ's are disabled */
251 IRQdisable;
252
253 if (howto & RB_HALT) {
254 iq80310_7seg('.', '.');
255 printf("The operating system has halted.\n");
256 printf("Please press any key to reboot.\n\n");
257 cngetc();
258 }
259
260 printf("rebooting...\n");
261 cpu_reset();
262 /*NOTREACHED*/
263 }
264
265 /* Static device mappings. */
266 static const struct pmap_devmap iq80310_devmap[] = {
267 /*
268 * Map the on-board devices VA == PA so that we can access them
269 * with the MMU on or off.
270 */
271 {
272 IQ80310_OBIO_BASE,
273 IQ80310_OBIO_BASE,
274 IQ80310_OBIO_SIZE,
275 VM_PROT_READ|VM_PROT_WRITE,
276 PTE_NOCACHE,
277 },
278 {
279 IQ80310_PIOW_VBASE,
280 I80312_PCI_XLATE_PIOW_BASE,
281 I80312_PCI_XLATE_IOSIZE,
282 VM_PROT_READ|VM_PROT_WRITE,
283 PTE_NOCACHE,
284 },
285 {
286 IQ80310_SIOW_VBASE,
287 I80312_PCI_XLATE_SIOW_BASE,
288 I80312_PCI_XLATE_IOSIZE,
289 VM_PROT_READ|VM_PROT_WRITE,
290 PTE_NOCACHE,
291 },
292 {
293 IQ80310_80312_VBASE,
294 I80312_PMMR_BASE,
295 I80312_PMMR_SIZE,
296 VM_PROT_READ|VM_PROT_WRITE,
297 PTE_NOCACHE,
298 },
299
300 {
301 0,
302 0,
303 0,
304 0,
305 0,
306 }
307 };
308
309 /*
310 * vaddr_t initarm(...)
311 *
312 * Initial entry point on startup. This gets called before main() is
313 * entered.
314 * It should be responsible for setting up everything that must be
315 * in place when main is called.
316 * This includes
317 * Taking a copy of the boot configuration structure.
318 * Initialising the physical console so characters can be printed.
319 * Setting up page tables for the kernel
320 * Relocating the kernel to the bottom of physical memory
321 */
322 vaddr_t
323 initarm(void *arg)
324 {
325 extern vaddr_t xscale_cache_clean_addr;
326 #ifdef DIAGNOSTIC
327 extern vsize_t xscale_minidata_clean_size;
328 #endif
329 int loop;
330 int loop1;
331 u_int l1pagetable;
332 paddr_t memstart;
333 psize_t memsize;
334
335 /*
336 * Clear out the 7-segment display. Whee, the first visual
337 * indication that we're running kernel code.
338 */
339 iq80310_7seg(' ', ' ');
340
341 /*
342 * Heads up ... Setup the CPU / MMU / TLB functions
343 */
344 if (set_cpufuncs())
345 panic("CPU not recognized!");
346
347 /* Calibrate the delay loop. */
348 iq80310_calibrate_delay();
349
350 /*
351 * Since we map the on-board devices VA==PA, and the kernel
352 * is running VA==PA, it's possible for us to initialize
353 * the console now.
354 */
355 consinit();
356
357 #ifdef VERBOSE_INIT_ARM
358 /* Talk to the user */
359 printf("\nNetBSD/evbarm (IQ80310) booting ...\n");
360 #endif
361
362 /*
363 * Reset the secondary PCI bus. RedBoot doesn't stop devices
364 * on the PCI bus before handing us control, so we have to
365 * do this.
366 *
367 * XXX This is arguably a bug in RedBoot, and doing this reset
368 * XXX could be problematic in the future if we encounter an
369 * XXX application where the PPB in the i80312 is used as a
370 * XXX PPB.
371 */
372 {
373 uint32_t reg;
374
375 #ifdef VERBOSE_INIT_ARM
376 printf("Resetting secondary PCI bus...\n");
377 #endif
378 reg = bus_space_read_4(&obio_bs_tag,
379 I80312_PMMR_BASE + I80312_PPB_BASE, PCI_BRIDGE_CONTROL_REG);
380 bus_space_write_4(&obio_bs_tag,
381 I80312_PMMR_BASE + I80312_PPB_BASE, PCI_BRIDGE_CONTROL_REG,
382 reg | PCI_BRIDGE_CONTROL_SECBR);
383 delay(10 * 1000); /* 10ms enough? */
384 bus_space_write_4(&obio_bs_tag,
385 I80312_PMMR_BASE + I80312_PPB_BASE, PCI_BRIDGE_CONTROL_REG,
386 reg);
387 }
388
389 /*
390 * We are currently running with the MMU enabled and the
391 * entire address space mapped VA==PA, except for the
392 * first 64M of RAM is also double-mapped at 0xc0000000.
393 * There is an L1 page table at 0xa0004000.
394 */
395
396 /*
397 * Fetch the SDRAM start/size from the i80312 SDRAM configuration
398 * registers.
399 */
400 i80312_sdram_bounds(&obio_bs_tag, I80312_PMMR_BASE + I80312_MEM_BASE,
401 &memstart, &memsize);
402
403 #ifdef VERBOSE_INIT_ARM
404 printf("initarm: Configuring system ...\n");
405 #endif
406
407 /* Fake bootconfig structure for the benefit of pmap.c */
408 /* XXX must make the memory description h/w independent */
409 bootconfig.dramblocks = 1;
410 bootconfig.dram[0].address = memstart;
411 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
412
413 /*
414 * Set up the variables that define the availablilty of
415 * physical memory. For now, we're going to set
416 * physical_freestart to 0xa0200000 (where the kernel
417 * was loaded), and allocate the memory we need downwards.
418 * If we get too close to the L1 table that we set up, we
419 * will panic. We will update physical_freestart and
420 * physical_freeend later to reflect what pmap_bootstrap()
421 * wants to see.
422 *
423 * XXX pmap_bootstrap() needs an enema.
424 */
425 physical_start = bootconfig.dram[0].address;
426 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
427
428 physical_freestart = 0xa0009000UL;
429 physical_freeend = 0xa0200000UL;
430
431 physmem = (physical_end - physical_start) / PAGE_SIZE;
432
433 #ifdef VERBOSE_INIT_ARM
434 /* Tell the user about the memory */
435 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
436 physical_start, physical_end - 1);
437 #endif
438
439 /*
440 * Okay, the kernel starts 2MB in from the bottom of physical
441 * memory. We are going to allocate our bootstrap pages downwards
442 * from there.
443 *
444 * We need to allocate some fixed page tables to get the kernel
445 * going. We allocate one page directory and a number of page
446 * tables and store the physical addresses in the kernel_pt_table
447 * array.
448 *
449 * The kernel page directory must be on a 16K boundary. The page
450 * tables must be on 4K boundaries. What we do is allocate the
451 * page directory on the first 16K boundary that we encounter, and
452 * the page tables on 4K boundaries otherwise. Since we allocate
453 * at least 3 L2 page tables, we are guaranteed to encounter at
454 * least one 16K aligned region.
455 */
456
457 #ifdef VERBOSE_INIT_ARM
458 printf("Allocating page tables\n");
459 #endif
460
461 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
462
463 #ifdef VERBOSE_INIT_ARM
464 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
465 physical_freestart, free_pages, free_pages);
466 #endif
467
468 /* Define a macro to simplify memory allocation */
469 #define valloc_pages(var, np) \
470 alloc_pages((var).pv_pa, (np)); \
471 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
472
473 #define alloc_pages(var, np) \
474 physical_freeend -= ((np) * PAGE_SIZE); \
475 if (physical_freeend < physical_freestart) \
476 panic("initarm: out of memory"); \
477 (var) = physical_freeend; \
478 free_pages -= (np); \
479 memset((char *)(var), 0, ((np) * PAGE_SIZE));
480
481 loop1 = 0;
482 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
483 /* Are we 16KB aligned for an L1 ? */
484 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
485 && kernel_l1pt.pv_pa == 0) {
486 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
487 } else {
488 valloc_pages(kernel_pt_table[loop1],
489 L2_TABLE_SIZE / PAGE_SIZE);
490 ++loop1;
491 }
492 }
493
494 /* This should never be able to happen but better confirm that. */
495 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
496 panic("initarm: Failed to align the kernel page directory");
497
498 /*
499 * Allocate a page for the system page mapped to V0x00000000
500 * This page will just contain the system vectors and can be
501 * shared by all processes.
502 */
503 alloc_pages(systempage.pv_pa, 1);
504
505 /* Allocate stacks for all modes */
506 valloc_pages(irqstack, IRQ_STACK_SIZE);
507 valloc_pages(abtstack, ABT_STACK_SIZE);
508 valloc_pages(undstack, UND_STACK_SIZE);
509 valloc_pages(kernelstack, UPAGES);
510
511 /* Allocate enough pages for cleaning the Mini-Data cache. */
512 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
513 valloc_pages(minidataclean, 1);
514
515 #ifdef VERBOSE_INIT_ARM
516 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
517 irqstack.pv_va);
518 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
519 abtstack.pv_va);
520 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
521 undstack.pv_va);
522 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
523 kernelstack.pv_va);
524 #endif
525
526 /*
527 * XXX Defer this to later so that we can reclaim the memory
528 * XXX used by the RedBoot page tables.
529 */
530 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
531
532 /*
533 * Ok we have allocated physical pages for the primary kernel
534 * page tables
535 */
536
537 #ifdef VERBOSE_INIT_ARM
538 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
539 #endif
540
541 /*
542 * Now we start construction of the L1 page table
543 * We start by mapping the L2 page tables into the L1.
544 * This means that we can replace L1 mappings later on if necessary
545 */
546 l1pagetable = kernel_l1pt.pv_pa;
547
548 /* Map the L2 pages tables in the L1 page table */
549 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
550 &kernel_pt_table[KERNEL_PT_SYS]);
551 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
552 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
553 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
554 pmap_link_l2pt(l1pagetable, IQ80310_IOPXS_VBASE,
555 &kernel_pt_table[KERNEL_PT_IOPXS]);
556 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
557 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
558 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
559
560 /* update the top of the kernel VM */
561 pmap_curmaxkvaddr =
562 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
563
564 #ifdef VERBOSE_INIT_ARM
565 printf("Mapping kernel\n");
566 #endif
567
568 /* Now we fill in the L2 pagetable for the kernel static code/data */
569 {
570 extern char etext[], _end[];
571 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
572 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
573 u_int logical;
574
575 textsize = (textsize + PGOFSET) & ~PGOFSET;
576 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
577
578 logical = 0x00200000; /* offset of kernel in RAM */
579
580 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
581 physical_start + logical, textsize,
582 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
583 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
584 physical_start + logical, totalsize - textsize,
585 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
586 }
587
588 #ifdef VERBOSE_INIT_ARM
589 printf("Constructing L2 page tables\n");
590 #endif
591
592 /* Map the stack pages */
593 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
594 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
595 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
596 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
597 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
598 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
599 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
600 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
601
602 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
603 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
604
605 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
606 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
607 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
608 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
609 }
610
611 /* Map the Mini-Data cache clean area. */
612 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
613 minidataclean.pv_pa);
614
615 /* Map the vector page. */
616 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
617 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
618
619 /* Map the statically mapped devices. */
620 pmap_devmap_bootstrap(l1pagetable, iq80310_devmap);
621
622 /*
623 * Give the XScale global cache clean code an appropriately
624 * sized chunk of unmapped VA space starting at 0xff000000
625 * (our device mappings end before this address).
626 */
627 xscale_cache_clean_addr = 0xff000000U;
628
629 /*
630 * Now we have the real page tables in place so we can switch to them.
631 * Once this is done we will be running with the REAL kernel page
632 * tables.
633 */
634
635 /*
636 * Update the physical_freestart/physical_freeend/free_pages
637 * variables.
638 */
639 {
640 extern char _end[];
641
642 physical_freestart = physical_start +
643 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
644 KERNEL_BASE);
645 physical_freeend = physical_end;
646 free_pages =
647 (physical_freeend - physical_freestart) / PAGE_SIZE;
648 }
649
650 /* Switch tables */
651 #ifdef VERBOSE_INIT_ARM
652 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
653 physical_freestart, free_pages, free_pages);
654 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
655 #endif
656 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
657 cpu_setttb(kernel_l1pt.pv_pa, true);
658 cpu_tlb_flushID();
659 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
660
661 /*
662 * Moved from cpu_startup() as data_abort_handler() references
663 * this during uvm init
664 */
665 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
666
667 #ifdef VERBOSE_INIT_ARM
668 printf("done!\n");
669 #endif
670
671 #ifdef VERBOSE_INIT_ARM
672 printf("bootstrap done.\n");
673 #endif
674
675 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
676
677 /*
678 * Pages were allocated during the secondary bootstrap for the
679 * stacks for different CPU modes.
680 * We must now set the r13 registers in the different CPU modes to
681 * point to these stacks.
682 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
683 * of the stack memory.
684 */
685 #ifdef VERBOSE_INIT_ARM
686 printf("init subsystems: stacks ");
687 #endif
688
689 set_stackptr(PSR_IRQ32_MODE,
690 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
691 set_stackptr(PSR_ABT32_MODE,
692 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
693 set_stackptr(PSR_UND32_MODE,
694 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
695
696 /*
697 * Well we should set a data abort handler.
698 * Once things get going this will change as we will need a proper
699 * handler.
700 * Until then we will use a handler that just panics but tells us
701 * why.
702 * Initialisation of the vectors will just panic on a data abort.
703 * This just fills in a slightly better one.
704 */
705 #ifdef VERBOSE_INIT_ARM
706 printf("vectors ");
707 #endif
708 data_abort_handler_address = (u_int)data_abort_handler;
709 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
710 undefined_handler_address = (u_int)undefinedinstruction_bounce;
711
712 /* Initialise the undefined instruction handlers */
713 #ifdef VERBOSE_INIT_ARM
714 printf("undefined ");
715 #endif
716 undefined_init();
717
718 /* Load memory into UVM. */
719 #ifdef VERBOSE_INIT_ARM
720 printf("page ");
721 #endif
722 uvm_md_init();
723 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
724 atop(physical_freestart), atop(physical_freeend),
725 VM_FREELIST_DEFAULT);
726
727 /* Boot strap pmap telling it where managed kernel virtual memory is */
728 #ifdef VERBOSE_INIT_ARM
729 printf("pmap ");
730 #endif
731 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
732
733 /* Setup the IRQ system */
734 #ifdef VERBOSE_INIT_ARM
735 printf("irq ");
736 #endif
737 iq80310_intr_init();
738
739 #ifdef VERBOSE_INIT_ARM
740 printf("done.\n");
741 #endif
742
743 #ifdef DDB
744 db_machine_init();
745 if (boothowto & RB_KDB)
746 Debugger();
747 #endif
748
749 /* We return the new stack pointer address */
750 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
751 }
752
753 void
754 consinit(void)
755 {
756 static const bus_addr_t comcnaddrs[] = {
757 IQ80310_UART2, /* com0 (J9) */
758 IQ80310_UART1, /* com1 (J10) */
759 };
760 static int consinit_called;
761
762 if (consinit_called != 0)
763 return;
764
765 consinit_called = 1;
766
767 /*
768 * Console devices are mapped VA==PA. Our devmap reflects
769 * this, so register it now so drivers can map the console
770 * device.
771 */
772 pmap_devmap_register(iq80310_devmap);
773
774 #if NCOM > 0
775 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
776 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
777 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
778 #else
779 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
780 #endif
781 }
782