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