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