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