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