ixm1200_machdep.c revision 1.2 1 /* $NetBSD: ixm1200_machdep.c,v 1.2 2002/07/21 14:26:05 ichiro Exp $ */
2 #undef DEBUG_BEFOREMMU
3 /*
4 * Copyright (c) 2002
5 * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Ichiro FUKUHARA.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35 /*
36 * Copyright (c) 1997,1998 Mark Brinicombe.
37 * Copyright (c) 1997,1998 Causality Limited.
38 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by Mark Brinicombe
51 * for the NetBSD Project.
52 * 4. The name of the company nor the name of the author may be used to
53 * endorse or promote products derived from this software without specific
54 * prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
57 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
58 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
60 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
61 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
62 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * SUCH DAMAGE.
67 */
68
69 #include "opt_ddb.h"
70 #include "opt_pmap_debug.h"
71
72 #include <sys/param.h>
73 #include <sys/device.h>
74 #include <sys/systm.h>
75 #include <sys/kernel.h>
76 #include <sys/exec.h>
77 #include <sys/proc.h>
78 #include <sys/msgbuf.h>
79 #include <sys/reboot.h>
80 #include <sys/termios.h>
81
82 #include <dev/cons.h>
83
84 #ifdef DDB
85 #include <machine/db_machdep.h>
86 #include <ddb/db_sym.h>
87 #include <ddb/db_extern.h>
88 #ifndef DB_ELFSIZE
89 #error Must define DB_ELFSIZE!
90 #endif
91 #define ELFSIZE DB_ELFSIZE
92 #include <sys/exec_elf.h>
93 #endif
94
95 #include <machine/bootconfig.h>
96 #include <machine/bus.h>
97 #include <machine/cpu.h>
98 #include <machine/frame.h>
99 #include <arm/undefined.h>
100
101 #include <arm/arm32/machdep.h>
102
103 #include <arm/ixp12x0/ixp12x0reg.h>
104 #include <arm/ixp12x0/ixp12x0var.h>
105 #include <arm/ixp12x0/ixp12x0_comreg.h>
106 #include <arm/ixp12x0/ixp12x0_comvar.h>
107 #include <arm/ixp12x0/ixp12x0_pcireg.h>
108
109 #include <evbarm/ixm1200/ixm1200reg.h>
110 #include <evbarm/ixm1200/ixm1200var.h>
111
112 #include "opt_ipkdb.h"
113
114 /* XXX for consinit related hacks */
115 #include <sys/conf.h>
116
117 void ixp12x0_reset(void) __attribute__((noreturn));
118
119 /*
120 * Address to call from cpu_reset() to reset the machine.
121 * This is machine architecture dependant as it varies depending
122 * on where the ROM appears when you turn the MMU off.
123 */
124
125 u_int cpu_reset_address = (u_int) ixp12x0_reset;
126
127 /*
128 * Define the default console speed for the board.
129 */
130 #ifndef CONMODE
131 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
132 #endif
133 #ifndef CONSPEED
134 #define CONSPEED B38400
135 #endif
136 #ifndef CONADDR
137 #define CONADDR IXPCOM_UART_BASE
138 #endif
139
140 cons_decl(com);
141 cons_decl(ixpcom);
142
143 struct consdev constab[] = {
144 #if (NIXPCOM > 0)
145 cons_init(ixpcom),
146 #endif
147 { 0 },
148 };
149
150 /* Define various stack sizes in pages */
151 #define IRQ_STACK_SIZE 1
152 #define ABT_STACK_SIZE 1
153 #ifdef IPKDB
154 #define UND_STACK_SIZE 2
155 #else
156 #define UND_STACK_SIZE 1
157 #endif
158
159 BootConfig bootconfig; /* Boot config storage */
160 char *boot_args = NULL;
161 char *boot_file = NULL;
162
163 vm_offset_t physical_start;
164 vm_offset_t physical_freestart;
165 vm_offset_t physical_freeend;
166 vm_offset_t physical_end;
167 u_int free_pages;
168 vm_offset_t pagetables_start;
169 int physmem = 0;
170
171 /*int debug_flags;*/
172 #ifndef PMAP_STATIC_L1S
173 int max_processes = 64; /* Default number */
174 #endif /* !PMAP_STATIC_L1S */
175
176 /* Physical and virtual addresses for some global pages */
177 pv_addr_t systempage;
178 pv_addr_t irqstack;
179 pv_addr_t undstack;
180 pv_addr_t abtstack;
181 pv_addr_t kernelstack;
182
183 vm_offset_t msgbufphys;
184
185 extern u_int data_abort_handler_address;
186 extern u_int prefetch_abort_handler_address;
187 extern u_int undefined_handler_address;
188 extern int end;
189
190 #ifdef PMAP_DEBUG
191 extern int pmap_debug_level;
192 #endif /* PMAP_DEBUG */
193
194 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
195 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
196 #define KERNEL_PT_KERNEL_NUM 2
197 #define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
198 /* Page table for mapping IO */
199 #define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1)
200 /* Page tables for mapping kernel VM */
201 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
202 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
203
204 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
205
206 struct user *proc0paddr;
207
208 #ifdef CPU_IXP12X0
209 #define CPU_IXP12X0_CACHE_CLEAN_SIZE (0x4000 * 2)
210 extern unsigned int ixp12x0_cache_clean_addr;
211 extern unsigned int ixp12x0_cache_clean_size;
212 static vaddr_t ixp12x0_cc_base;
213 #endif /* CPU_IXP12X0 */
214
215 /* Prototypes */
216
217 void consinit __P((void));
218 u_int cpu_get_control __P((void));
219
220 void ixdp_ixp12x0_cc_setup(void);
221
222 #ifdef DEBUG_BEFOREMMU
223 static void fakecninit();
224 #endif
225
226 extern int db_trapper();
227
228 /*
229 * void cpu_reboot(int howto, char *bootstr)
230 *
231 * Reboots the system
232 *
233 * Deal with any syncing, unmounting, dumping and shutdown hooks,
234 * then reset the CPU.
235 */
236
237 void
238 cpu_reboot(howto, bootstr)
239 int howto;
240 char *bootstr;
241 {
242 /*
243 * If we are still cold then hit the air brakes
244 * and crash to earth fast
245 */
246 if (cold) {
247 doshutdownhooks();
248 printf("Halted while still in the ICE age.\n");
249 printf("The operating system has halted.\n");
250 printf("Please press any key to reboot.\n\n");
251 cngetc();
252 printf("rebooting...\n");
253 ixp12x0_reset();
254 }
255
256 /* Disable console buffering */
257 cnpollc(1);
258
259 /*
260 * If RB_NOSYNC was not specified sync the discs.
261 * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
262 * It looks like syslogd is getting woken up only to find that it cannot
263 * page part of the binary in as the filesystem has been unmounted.
264 */
265 if (!(howto & RB_NOSYNC))
266 bootsync();
267
268 /* Say NO to interrupts */
269 splhigh();
270
271 /* Do a dump if requested. */
272 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
273 dumpsys();
274
275 /* Run any shutdown hooks */
276 doshutdownhooks();
277
278 /* Make sure IRQ's are disabled */
279 IRQdisable;
280
281 if (howto & RB_HALT) {
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
289 /* all interrupts are disabled */
290 disable_interrupts(I32_bit);
291
292 ixp12x0_reset();
293
294 /* ...and if that didn't work, just croak. */
295 printf("RESET FAILED!\n");
296 for (;;);
297 }
298
299 /*
300 * pmap table
301 */
302 /*
303 * IXM1200 specific I/O registers mapping table
304 */
305 static struct pmap_ent map_tbl_ixm1200[] = {
306 { "IXM1200 SlowPort I/O Registers",
307 IXM1200_LED_VADDR, IXM1200_LED_ADDR,
308 IXM1200_LED_ADDR_SIZE,
309 VM_PROT_READ|VM_PROT_WRITE,
310 PTE_NOCACHE, },
311
312 { NULL,
313 0,
314 0,
315 0,
316 0,
317 0,
318 }
319 };
320
321 /*
322 * Initial entry point on startup. This gets called before main() is
323 * entered.
324 * It should be responsible for setting up everything that must be
325 * in place when main is called.
326 * This includes
327 * Taking a copy of the boot configuration structure.
328 * Initialising the physical console so characters can be printed.
329 * Setting up page tables for the kernel
330 * Relocating the kernel to the bottom of physical memory
331 */
332 u_int
333 initarm(void *arg)
334 {
335 int loop;
336 int loop1;
337 u_int kerneldatasize, symbolsize;
338 vaddr_t l1pagetable;
339 vaddr_t freemempos;
340 pv_addr_t kernel_l1pt;
341 pv_addr_t kernel_ptpt;
342 #ifdef DDB
343 Elf_Shdr *sh;
344 #endif
345
346 #ifdef PMAP_DEBUG
347 pmap_debug(-1);
348 #endif
349
350 #ifdef DEBUG_BEFOREMMU
351 /*
352 * At this point, we cannot call real consinit().
353 * Just call a faked up version of consinit(), which does the thing
354 * with MMU disabled.
355 */
356 fakecninit();
357 #endif
358 /*
359 * Since we map v0xf0000000 == p0x90000000, it's possible for
360 * us to initialize the console now.
361 */
362 consinit();
363
364 /* Talk to the user */
365 printf("\nNetBSD/evbarm (IXM1200) booting ...\n");
366
367 /*
368 * Heads up ... Setup the CPU / MMU / TLB functions
369 */
370 if (set_cpufuncs())
371 panic("cpu not recognized!");
372
373 /* XXX overwrite bootconfig to hardcoded values */
374 bootconfig.dram[0].address = 0xc0000000;
375 bootconfig.dram[0].pages = 0x10000000 / NBPG; /* SDRAM 256MB */
376 bootconfig.dramblocks = 1;
377
378 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
379
380 symbolsize = 0;
381 #ifdef DDB
382 if (! memcmp(&end, "\177ELF", 4)) {
383 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff);
384 loop = ((Elf_Ehdr *)&end)->e_shnum;
385 for(; loop; loop--, sh++)
386 if (sh->sh_offset > 0 &&
387 (sh->sh_offset + sh->sh_size) > symbolsize)
388 symbolsize = sh->sh_offset + sh->sh_size;
389 }
390 #endif
391 printf("kernsize=0x%x\n", kerneldatasize);
392 kerneldatasize += symbolsize;
393 kerneldatasize = ((kerneldatasize - 1) & ~(NBPG * 4 - 1)) + NBPG * 8;
394
395 /*
396 * Set up the variables that define the availablilty of physcial
397 * memory
398 */
399 physical_start = bootconfig.dram[0].address;
400 physical_end = physical_start + (bootconfig.dram[0].pages * NBPG);
401
402 physical_freestart = physical_start
403 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
404 physical_freeend = physical_end;
405
406 physmem = (physical_end - physical_start) / NBPG;
407
408 freemempos = 0xc0000000;
409
410 #ifdef VERBOSE_INIT_ARM
411 printf("Allocating page tables\n");
412 #endif
413 free_pages = (physical_freeend - physical_freestart) / NBPG;
414
415 #ifdef VERBOSE_INIT_ARM
416 printf("CP15 Register1 = 0x%08x\n", cpu_get_control());
417 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
418 physical_freestart, free_pages, free_pages);
419 printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
420 physical_start, physical_end);
421 #endif
422
423 /* Define a macro to simplify memory allocation */
424 #define valloc_pages(var, np) \
425 alloc_pages((var).pv_pa, (np)); \
426 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
427 #define alloc_pages(var, np) \
428 (var) = freemempos; \
429 memset((char *)(var), 0, ((np) * NBPG)); \
430 freemempos += (np) * NBPG;
431
432 loop1 = 0;
433 kernel_l1pt.pv_pa = 0;
434 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
435 /* Are we 16KB aligned for an L1 ? */
436 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
437 && kernel_l1pt.pv_pa == 0) {
438 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / NBPG);
439 } else {
440 alloc_pages(kernel_pt_table[loop1].pv_pa,
441 L2_TABLE_SIZE / NBPG);
442 kernel_pt_table[loop1].pv_va =
443 kernel_pt_table[loop1].pv_pa;
444 ++loop1;
445 }
446 }
447
448 #ifdef DIAGNOSTIC
449 /* This should never be able to happen but better confirm that. */
450 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
451 panic("initarm: Failed to align the kernel page directory\n");
452 #endif
453
454 /*
455 * Allocate a page for the system page mapped to V0x00000000
456 * This page will just contain the system vectors and can be
457 * shared by all processes.
458 */
459 alloc_pages(systempage.pv_pa, 1);
460
461 /* Allocate a page for the page table to map kernel page tables. */
462 valloc_pages(kernel_ptpt, L2_TABLE_SIZE / NBPG);
463
464 /* Allocate stacks for all modes */
465 valloc_pages(irqstack, IRQ_STACK_SIZE);
466 valloc_pages(abtstack, ABT_STACK_SIZE);
467 valloc_pages(undstack, UND_STACK_SIZE);
468 valloc_pages(kernelstack, UPAGES);
469
470 #ifdef VERBOSE_INIT_ARM
471 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
472 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
473 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
474 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
475 #endif
476
477 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
478
479 #ifdef CPU_IXP12X0
480 /*
481 * XXX totally stuffed hack to work round problems introduced
482 * in recent versions of the pmap code. Due to the calls used there
483 * we cannot allocate virtual memory during bootstrap.
484 */
485 for(;;) {
486 alloc_pages(ixp12x0_cc_base, 1);
487 if (! (ixp12x0_cc_base & (CPU_IXP12X0_CACHE_CLEAN_SIZE - 1)))
488 break;
489 }
490 {
491 vaddr_t dummy;
492 alloc_pages(dummy, CPU_IXP12X0_CACHE_CLEAN_SIZE / NBPG - 1);
493 }
494 ixp12x0_cache_clean_addr = ixp12x0_cc_base;
495 ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
496 #endif /* CPU_IXP12X0 */
497
498 #ifdef VERBOSE_INIT_ARM
499 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
500 #endif
501
502 /*
503 * Now we start construction of the L1 page table
504 * We start by mapping the L2 page tables into the L1.
505 * This means that we can replace L1 mappings later on if necessary
506 */
507 l1pagetable = kernel_l1pt.pv_pa;
508
509 /* Map the L2 pages tables in the L1 page table */
510 pmap_link_l2pt(l1pagetable, 0x00000000,
511 &kernel_pt_table[KERNEL_PT_SYS]);
512
513 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
514 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
515 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
516
517 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
518 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
519 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
520 pmap_link_l2pt(l1pagetable, PTE_BASE, &kernel_ptpt);
521
522 /* update the top of the kernel VM */
523 pmap_curmaxkvaddr =
524 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
525
526 pmap_link_l2pt(l1pagetable, IXP12X0_IO_VBASE,
527 &kernel_pt_table[KERNEL_PT_IO]);
528
529 #ifdef VERBOSE_INIT_ARM
530 printf("Mapping kernel\n");
531 #endif
532
533 #if XXX
534 /* Now we fill in the L2 pagetable for the kernel code/data */
535 {
536 extern char etext[], _end[];
537 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
538 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
539 u_int logical;
540
541 textsize = (textsize + PGOFSET) & ~PGOFSET;
542 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
543
544 logical = 0x00200000; /* offset of kernel in RAM */
545
546 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
547 physical_start + logical, textsize,
548 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
549 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
550 physical_start + logical, totalsize - textsize,
551 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
552 }
553 #else
554 {
555 pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
556 KERNEL_TEXT_BASE, kerneldatasize,
557 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
558 }
559 #endif
560
561 #ifdef VERBOSE_INIT_ARM
562 printf("Constructing L2 page tables\n");
563 #endif
564
565 /* Map the stack pages */
566 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
567 IRQ_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
568 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
569 ABT_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
570 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
571 UND_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
572 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
573 UPAGES * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
574
575 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
576 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
577
578 /* Map the page table that maps the kernel pages */
579 pmap_map_entry(l1pagetable, kernel_ptpt.pv_va, kernel_ptpt.pv_pa,
580 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
581
582 /*
583 * Map entries in the page table used to map PTE's
584 * Basically every kernel page table gets mapped here
585 */
586 /* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
587 pmap_map_entry(l1pagetable,
588 PTE_BASE + (0x00000000 >> (PGSHIFT-2)),
589 kernel_pt_table[KERNEL_PT_SYS].pv_pa,
590 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
591
592 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
593 pmap_map_entry(l1pagetable,
594 PTE_BASE + ((KERNEL_BASE +
595 (loop * 0x00400000)) >> (PGSHIFT-2)),
596 kernel_pt_table[KERNEL_PT_KERNEL + loop].pv_pa,
597 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
598
599 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
600 pmap_map_entry(l1pagetable,
601 PTE_BASE + ((KERNEL_VM_BASE +
602 (loop * 0x00400000)) >> (PGSHIFT-2)),
603 kernel_pt_table[KERNEL_PT_VMDATA + loop].pv_pa,
604 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
605
606 pmap_map_entry(l1pagetable,
607 PTE_BASE + (PTE_BASE >> (PGSHIFT-2)),
608 kernel_ptpt.pv_pa, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
609
610 /* Map the vector page. */
611 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
612 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
613
614 #ifdef VERBOSE_INIT_ARM
615 printf("systempage (vector page): p0x%08lx v0x%08lx\n",
616 systempage.pv_pa, vector_page);
617 #endif
618
619 /*
620 * Map the PCI I/O spaces and IXP12x0 registers
621 */
622
623 ixp12x0_pmap_io_reg(l1pagetable);
624 ixp12x0_pmap_chunk_table(l1pagetable, map_tbl_ixm1200);
625
626 printf("done.\n");
627
628 /*
629 * Map the Dcache Flush page.
630 * Hw Ref Manual 3.2.4.5 Software Dcache Flush
631 */
632 pmap_map_chunk(l1pagetable, ixp12x0_cache_clean_addr, 0xe0000000,
633 CPU_IXP12X0_CACHE_CLEAN_SIZE, VM_PROT_READ, PTE_CACHE);
634
635 /*
636 * Now we have the real page tables in place so we can switch to them.
637 * Once this is done we will be running with the REAL kernel page
638 * tables.
639 */
640
641 /* Switch tables */
642 setttb(kernel_l1pt.pv_pa);
643 cpu_tlb_flushID();
644
645 /*
646 * We must now clean the cache again....
647 * Cleaning may be done by reading new data to displace any
648 * dirty data in the cache. This will have happened in setttb()
649 * but since we are boot strapping the addresses used for the read
650 * may have just been remapped and thus the cache could be out
651 * of sync. A re-clean after the switch will cure this.
652 * After booting there are no gross reloations of the kernel thus
653 * this problem will not occur after initarm().
654 */
655 cpu_idcache_wbinv_all();
656
657 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
658
659 /*
660 * Pages were allocated during the secondary bootstrap for the
661 * stacks for different CPU modes.
662 * We must now set the r13 registers in the different CPU modes to
663 * point to these stacks.
664 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
665 * of the stack memory.
666 */
667 printf("init subsystems: stacks ");
668
669 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
670 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
671 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
672 #ifdef PMAP_DEBUG
673 if (pmap_debug_level >= 0)
674 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va,
675 kernelstack.pv_pa);
676 #endif /* PMAP_DEBUG */
677
678 /*
679 * Well we should set a data abort handler.
680 * Once things get going this will change as we will need a proper
681 * handler. Until then we will use a handler that just panics but
682 * tells us why.
683 * Initialisation of the vetcors will just panic on a data abort.
684 * This just fills in a slighly better one.
685 */
686 printf("vectors ");
687 data_abort_handler_address = (u_int)data_abort_handler;
688 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
689 undefined_handler_address = (u_int)undefinedinstruction_bounce;
690 printf("\ndata_abort_handler_address = %08x\n", data_abort_handler_address);
691 printf("prefetch_abort_handler_address = %08x\n", prefetch_abort_handler_address);
692 printf("undefined_handler_address = %08x\n", undefined_handler_address);
693
694 /* Initialise the undefined instruction handlers */
695 printf("undefined ");
696 undefined_init();
697
698 /* Boot strap pmap telling it where the kernel page table is */
699 printf("pmap ");
700 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
701
702 /* Setup the IRQ system */
703 printf("irq ");
704 ixp12x0_intr_init();
705 printf("done.\n");
706
707 #ifdef VERBOSE_INIT_ARM
708 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
709 physical_freestart, free_pages, free_pages);
710 printf("freemempos=%08lx\n", freemempos);
711 printf("switching to new L1 page table @%#lx... \n", kernel_l1pt.pv_pa);
712 #endif
713
714 consinit();
715 printf("consinit \n");
716
717 ixdp_ixp12x0_cc_setup();
718
719 printf("bootstrap done.\n");
720
721 #ifdef IPKDB
722 /* Initialise ipkdb */
723 ipkdb_init();
724 if (boothowto & RB_KDB)
725 ipkdb_connect(0);
726 #endif /* NIPKDB */
727
728 #ifdef DDB
729 {
730 static struct undefined_handler uh;
731
732 uh.uh_handler = db_trapper;
733 install_coproc_handler_static(0, &uh);
734 }
735 ddb_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize);
736
737 if (boothowto & RB_KDB)
738 Debugger();
739 #endif
740
741 /* We return the new stack pointer address */
742 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
743 }
744
745 void
746 consinit(void)
747 {
748 extern struct bus_space ixpsip_bs_tag;
749 static int consinit_called = 0;
750
751 if (consinit_called != 0)
752 return;
753
754 consinit_called = 1;
755
756 if (ixpcomcnattach(&ixpsip_bs_tag, IXPCOM_UART_BASE,
757 CONSPEED, CONMODE))
758 panic("can't init serial console @%lx", IXPCOM_UART_BASE);
759 }
760
761 #ifdef DEBUG_BEFOREMMU
762 cons_decl(ixpcom);
763 void
764 fakecninit()
765 {
766 static struct consdev fakecntab = cons_init(ixpcom);
767 cn_tab = &fakecntab;
768
769 (*cn_tab->cn_init)(0);
770 cn_tab->cn_pri = CN_REMOTE;
771 }
772 #endif
773
774 /*
775 * For optimal cache cleaning we need two 16K banks of
776 * virtual address space that NOTHING else will access
777 * and then we alternate the cache cleaning between the
778 * two banks.
779 * The cache cleaning code requires requires 2 banks aligned
780 * on total size boundry so the banks can be alternated by
781 * eorring the size bit (assumes the bank size is a power of 2)
782 */
783 void
784 ixdp_ixp12x0_cc_setup(void)
785 {
786 int loop;
787 paddr_t kaddr;
788 pt_entry_t *pte;
789
790 (void) pmap_extract(pmap_kernel(), KERNEL_TEXT_BASE, &kaddr);
791 for (loop = 0; loop < CPU_IXP12X0_CACHE_CLEAN_SIZE; loop += NBPG) {
792 pte = vtopte(ixp12x0_cc_base + loop);
793 *pte = L2_S_PROTO | kaddr |
794 L2_S_PROT(PTE_KERNEL, VM_PROT_READ) | pte_l2_s_cache_mode;
795 }
796 ixp12x0_cache_clean_addr = ixp12x0_cc_base;
797 ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
798 }
799