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