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