ixm1200_machdep.c revision 1.36 1 /* $NetBSD: ixm1200_machdep.c,v 1.36 2008/11/12 12:35:59 ad Exp $ */
2
3 /*
4 * Copyright (c) 2002, 2003
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 <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: ixm1200_machdep.c,v 1.36 2008/11/12 12:35:59 ad Exp $");
71
72 #include "opt_ddb.h"
73 #include "opt_pmap_debug.h"
74
75 #include <sys/param.h>
76 #include <sys/device.h>
77 #include <sys/systm.h>
78 #include <sys/kernel.h>
79 #include <sys/exec.h>
80 #include <sys/proc.h>
81 #include <sys/msgbuf.h>
82 #include <sys/reboot.h>
83 #include <sys/termios.h>
84 #include <sys/ksyms.h>
85
86 #include <uvm/uvm_extern.h>
87
88 #include <dev/cons.h>
89
90 #include "ksyms.h"
91
92 #if NKSYMS || defined(DDB) || defined(MODULAR)
93 #include <machine/db_machdep.h>
94 #include <ddb/db_sym.h>
95 #include <ddb/db_extern.h>
96 #ifndef DB_ELFSIZE
97 #error Must define DB_ELFSIZE!
98 #endif
99 #define ELFSIZE DB_ELFSIZE
100 #include <sys/exec_elf.h>
101 #endif
102
103 #include <machine/bootconfig.h>
104 #include <machine/bus.h>
105 #include <machine/cpu.h>
106 #include <machine/frame.h>
107 #include <arm/undefined.h>
108
109 #include <arm/arm32/machdep.h>
110
111 #include <arm/ixp12x0/ixp12x0reg.h>
112 #include <arm/ixp12x0/ixp12x0var.h>
113 #include <arm/ixp12x0/ixp12x0_comreg.h>
114 #include <arm/ixp12x0/ixp12x0_comvar.h>
115 #include <arm/ixp12x0/ixp12x0_pcireg.h>
116
117 #include <evbarm/ixm1200/ixm1200reg.h>
118 #include <evbarm/ixm1200/ixm1200var.h>
119
120 /* XXX for consinit related hacks */
121 #include <sys/conf.h>
122
123 void ixp12x0_reset(void) __attribute__((noreturn));
124
125 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
126 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
127 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
128
129 /*
130 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
131 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
132 */
133 #define KERNEL_VM_SIZE 0x0C000000
134
135 /*
136 * Address to call from cpu_reset() to reset the machine.
137 * This is machine architecture dependant as it varies depending
138 * on where the ROM appears when you turn the MMU off.
139 */
140
141 u_int cpu_reset_address = (u_int) ixp12x0_reset;
142
143 /*
144 * Define the default console speed for the board.
145 */
146 #ifndef CONMODE
147 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
148 #endif
149 #ifndef CONSPEED
150 #define CONSPEED B38400
151 #endif
152 #ifndef CONADDR
153 #define CONADDR IXPCOM_UART_BASE
154 #endif
155
156 /* Define various stack sizes in pages */
157 #define IRQ_STACK_SIZE 1
158 #define ABT_STACK_SIZE 1
159 #define UND_STACK_SIZE 1
160
161 BootConfig bootconfig; /* Boot config storage */
162 char *boot_args = NULL;
163 char *boot_file = NULL;
164
165 vm_offset_t physical_start;
166 vm_offset_t physical_freestart;
167 vm_offset_t physical_freeend;
168 vm_offset_t physical_end;
169 u_int free_pages;
170 vm_offset_t pagetables_start;
171 int physmem = 0;
172
173 /*int debug_flags;*/
174 #ifndef PMAP_STATIC_L1S
175 int max_processes = 64; /* Default number */
176 #endif /* !PMAP_STATIC_L1S */
177
178 /* Physical and virtual addresses for some global pages */
179 pv_addr_t irqstack;
180 pv_addr_t undstack;
181 pv_addr_t abtstack;
182 pv_addr_t kernelstack;
183
184 vm_offset_t msgbufphys;
185
186 extern u_int data_abort_handler_address;
187 extern u_int prefetch_abort_handler_address;
188 extern u_int undefined_handler_address;
189 extern int end;
190
191 #ifdef PMAP_DEBUG
192 extern int pmap_debug_level;
193 #endif /* PMAP_DEBUG */
194
195 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
196 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
197 #define KERNEL_PT_KERNEL_NUM 2
198 #define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
199 /* Page table for mapping IO */
200 #define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1)
201 /* Page tables for mapping kernel VM */
202 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
203 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
204
205 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
206
207 struct user *proc0paddr;
208
209 #ifdef CPU_IXP12X0
210 #define CPU_IXP12X0_CACHE_CLEAN_SIZE (0x4000 * 2)
211 extern unsigned int ixp12x0_cache_clean_addr;
212 extern unsigned int ixp12x0_cache_clean_size;
213 static vaddr_t ixp12x0_cc_base;
214 #endif /* CPU_IXP12X0 */
215
216 /* Prototypes */
217
218 void consinit __P((void));
219 u_int cpu_get_control __P((void));
220
221 void ixdp_ixp12x0_cc_setup(void);
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
232 void
233 cpu_reboot(howto, bootstr)
234 int howto;
235 char *bootstr;
236 {
237 /*
238 * If we are still cold then hit the air brakes
239 * and crash to earth fast
240 */
241 if (cold) {
242 doshutdownhooks();
243 pmf_system_shutdown(boothowto);
244 printf("Halted while still in the ICE age.\n");
245 printf("The operating system has halted.\n");
246 printf("Please press any key to reboot.\n\n");
247 cngetc();
248 printf("rebooting...\n");
249 ixp12x0_reset();
250 }
251
252 /* Disable console buffering */
253 cnpollc(1);
254
255 /*
256 * If RB_NOSYNC was not specified sync the discs.
257 * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
258 * It looks like syslogd is getting woken up only to find that it cannot
259 * page part of the binary in as the filesystem has been unmounted.
260 */
261 if (!(howto & RB_NOSYNC))
262 bootsync();
263
264 /* Say NO to interrupts */
265 splhigh();
266
267 /* Do a dump if requested. */
268 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
269 dumpsys();
270
271 /* Run any shutdown hooks */
272 doshutdownhooks();
273
274 pmf_system_shutdown(boothowto);
275
276 /* Make sure IRQ's are disabled */
277 IRQdisable;
278
279 if (howto & RB_HALT) {
280 printf("The operating system has halted.\n");
281 printf("Please press any key to reboot.\n\n");
282 cngetc();
283 }
284
285 printf("rebooting...\n");
286
287 /* all interrupts are disabled */
288 disable_interrupts(I32_bit);
289
290 ixp12x0_reset();
291
292 /* ...and if that didn't work, just croak. */
293 printf("RESET FAILED!\n");
294 for (;;);
295 }
296
297 /* Static device mappings. */
298 static const struct pmap_devmap ixm1200_devmap[] = {
299 /* StrongARM System and Peripheral Registers */
300 {
301 IXP12X0_SYS_VBASE,
302 IXP12X0_SYS_HWBASE,
303 IXP12X0_SYS_SIZE,
304 VM_PROT_READ|VM_PROT_WRITE,
305 PTE_NOCACHE,
306 },
307 /* PCI Registers Accessible Through StrongARM Core */
308 {
309 IXP12X0_PCI_VBASE, IXP12X0_PCI_HWBASE,
310 IXP12X0_PCI_SIZE,
311 VM_PROT_READ|VM_PROT_WRITE,
312 PTE_NOCACHE,
313 },
314 /* PCI Registers Accessible Through I/O Cycle Access */
315 {
316 IXP12X0_PCI_IO_VBASE, IXP12X0_PCI_IO_HWBASE,
317 IXP12X0_PCI_IO_SIZE,
318 VM_PROT_READ|VM_PROT_WRITE,
319 PTE_NOCACHE,
320 },
321 /* PCI Type0 Configuration Space */
322 {
323 IXP12X0_PCI_TYPE0_VBASE, IXP12X0_PCI_TYPE0_HWBASE,
324 IXP12X0_PCI_TYPE0_SIZE,
325 VM_PROT_READ|VM_PROT_WRITE,
326 PTE_NOCACHE,
327 },
328 /* PCI Type1 Configuration Space */
329 {
330 IXP12X0_PCI_TYPE1_VBASE, IXP12X0_PCI_TYPE1_HWBASE,
331 IXP12X0_PCI_TYPE1_SIZE,
332 VM_PROT_READ|VM_PROT_WRITE,
333 PTE_NOCACHE,
334 },
335 {
336 0,
337 0,
338 0,
339 0,
340 0
341 },
342 };
343
344 /*
345 * Initial entry point on startup. This gets called before main() is
346 * entered.
347 * It should be responsible for setting up everything that must be
348 * in place when main is called.
349 * This includes
350 * Taking a copy of the boot configuration structure.
351 * Initialising the physical console so characters can be printed.
352 * Setting up page tables for the kernel
353 * Relocating the kernel to the bottom of physical memory
354 */
355 u_int
356 initarm(void *arg)
357 {
358 int loop;
359 int loop1;
360 u_int kerneldatasize, symbolsize;
361 vaddr_t l1pagetable;
362 vaddr_t freemempos;
363 #if NKSYMS || defined(DDB) || defined(MODULAR)
364 Elf_Shdr *sh;
365 #endif
366
367 /*
368 * Since we map v0xf0000000 == p0x90000000, it's possible for
369 * us to initialize the console now.
370 */
371 consinit();
372
373 #ifdef VERBOSE_INIT_ARM
374 /* Talk to the user */
375 printf("\nNetBSD/evbarm (IXM1200) booting ...\n");
376 #endif
377
378 /*
379 * Heads up ... Setup the CPU / MMU / TLB functions
380 */
381 if (set_cpufuncs())
382 panic("CPU not recognized!");
383
384 /* XXX overwrite bootconfig to hardcoded values */
385 bootconfig.dram[0].address = 0xc0000000;
386 bootconfig.dram[0].pages = 0x10000000 / PAGE_SIZE; /* SDRAM 256MB */
387 bootconfig.dramblocks = 1;
388
389 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
390
391 symbolsize = 0;
392
393 #ifdef PMAP_DEBUG
394 pmap_debug(-1);
395 #endif
396
397 #if NKSYMS || defined(DDB) || defined(MODULAR)
398 if (! memcmp(&end, "\177ELF", 4)) {
399 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff);
400 loop = ((Elf_Ehdr *)&end)->e_shnum;
401 for(; loop; loop--, sh++)
402 if (sh->sh_offset > 0 &&
403 (sh->sh_offset + sh->sh_size) > symbolsize)
404 symbolsize = sh->sh_offset + sh->sh_size;
405 }
406 #endif
407 #ifdef VERBOSE_INIT_ARM
408 printf("kernsize=0x%x\n", kerneldatasize);
409 #endif
410 kerneldatasize += symbolsize;
411 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
412
413 /*
414 * Set up the variables that define the availablilty of physcial
415 * memory
416 */
417 physical_start = bootconfig.dram[0].address;
418 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
419
420 physical_freestart = physical_start
421 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
422 physical_freeend = physical_end;
423
424 physmem = (physical_end - physical_start) / PAGE_SIZE;
425
426 freemempos = 0xc0000000;
427
428 #ifdef VERBOSE_INIT_ARM
429 printf("Allocating page tables\n");
430 #endif
431 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
432
433 #ifdef VERBOSE_INIT_ARM
434 printf("CP15 Register1 = 0x%08x\n", cpu_get_control());
435 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
436 physical_freestart, free_pages, free_pages);
437 printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
438 physical_start, physical_end);
439 #endif
440
441 /* Define a macro to simplify memory allocation */
442 #define valloc_pages(var, np) \
443 alloc_pages((var).pv_pa, (np)); \
444 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
445 #define alloc_pages(var, np) \
446 (var) = freemempos; \
447 memset((char *)(var), 0, ((np) * PAGE_SIZE)); \
448 freemempos += (np) * PAGE_SIZE;
449
450 loop1 = 0;
451 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
452 /* Are we 16KB aligned for an L1 ? */
453 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
454 && kernel_l1pt.pv_pa == 0) {
455 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
456 } else {
457 valloc_pages(kernel_pt_table[loop1],
458 L2_TABLE_SIZE / PAGE_SIZE);
459 ++loop1;
460 }
461 }
462
463 #ifdef DIAGNOSTIC
464 /* This should never be able to happen but better confirm that. */
465 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
466 panic("initarm: Failed to align the kernel page directory");
467 #endif
468
469 /*
470 * Allocate a page for the system page mapped to V0x00000000
471 * This page will just contain the system vectors and can be
472 * shared by all processes.
473 */
474 alloc_pages(systempage.pv_pa, 1);
475
476 /* Allocate stacks for all modes */
477 valloc_pages(irqstack, IRQ_STACK_SIZE);
478 valloc_pages(abtstack, ABT_STACK_SIZE);
479 valloc_pages(undstack, UND_STACK_SIZE);
480 valloc_pages(kernelstack, UPAGES);
481
482 #ifdef VERBOSE_INIT_ARM
483 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
484 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
485 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
486 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
487 #endif
488
489 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
490
491 #ifdef CPU_IXP12X0
492 /*
493 * XXX totally stuffed hack to work round problems introduced
494 * in recent versions of the pmap code. Due to the calls used there
495 * we cannot allocate virtual memory during bootstrap.
496 */
497 for(;;) {
498 alloc_pages(ixp12x0_cc_base, 1);
499 if (! (ixp12x0_cc_base & (CPU_IXP12X0_CACHE_CLEAN_SIZE - 1)))
500 break;
501 }
502 {
503 vaddr_t dummy;
504 alloc_pages(dummy, CPU_IXP12X0_CACHE_CLEAN_SIZE / PAGE_SIZE - 1);
505 }
506 ixp12x0_cache_clean_addr = ixp12x0_cc_base;
507 ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
508 #endif /* CPU_IXP12X0 */
509
510 #ifdef VERBOSE_INIT_ARM
511 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
512 #endif
513
514 /*
515 * Now we start construction of the L1 page table
516 * We start by mapping the L2 page tables into the L1.
517 * This means that we can replace L1 mappings later on if necessary
518 */
519 l1pagetable = kernel_l1pt.pv_pa;
520
521 /* Map the L2 pages tables in the L1 page table */
522 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
523 &kernel_pt_table[KERNEL_PT_SYS]);
524
525 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
526 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
527 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
528
529 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
530 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
531 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
532
533 /* update the top of the kernel VM */
534 pmap_curmaxkvaddr =
535 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
536
537 pmap_link_l2pt(l1pagetable, IXP12X0_IO_VBASE,
538 &kernel_pt_table[KERNEL_PT_IO]);
539
540 #ifdef VERBOSE_INIT_ARM
541 printf("Mapping kernel\n");
542 #endif
543
544 #if XXX
545 /* Now we fill in the L2 pagetable for the kernel code/data */
546 {
547 extern char etext[], _end[];
548 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
549 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
550 u_int logical;
551
552 textsize = (textsize + PGOFSET) & ~PGOFSET;
553 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
554
555 logical = 0x00200000; /* offset of kernel in RAM */
556
557 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
558 physical_start + logical, textsize,
559 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
560 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
561 physical_start + logical, totalsize - textsize,
562 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
563 }
564 #else
565 {
566 pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
567 KERNEL_TEXT_BASE, kerneldatasize,
568 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
569 }
570 #endif
571
572 #ifdef VERBOSE_INIT_ARM
573 printf("Constructing L2 page tables\n");
574 #endif
575
576 /* Map the stack pages */
577 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
578 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
579 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
580 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
581 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
582 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
583 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
584 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
585
586 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
587 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
588
589 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
590 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
591 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
592 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
593 }
594
595 /* Map the vector page. */
596 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
597 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
598
599 #ifdef VERBOSE_INIT_ARM
600 printf("systempage (vector page): p0x%08lx v0x%08lx\n",
601 systempage.pv_pa, vector_page);
602 #endif
603
604 /* Map the statically mapped devices. */
605 pmap_devmap_bootstrap(l1pagetable, ixm1200_devmap);
606
607 #ifdef VERBOSE_INIT_ARM
608 printf("done.\n");
609 #endif
610
611 /*
612 * Map the Dcache Flush page.
613 * Hw Ref Manual 3.2.4.5 Software Dcache Flush
614 */
615 pmap_map_chunk(l1pagetable, ixp12x0_cache_clean_addr, 0xe0000000,
616 CPU_IXP12X0_CACHE_CLEAN_SIZE, VM_PROT_READ, PTE_CACHE);
617
618 /*
619 * Now we have the real page tables in place so we can switch to them.
620 * Once this is done we will be running with the REAL kernel page
621 * tables.
622 */
623
624 /* Switch tables */
625 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
626 setttb(kernel_l1pt.pv_pa);
627 cpu_tlb_flushID();
628 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
629
630 /*
631 * Moved here from cpu_startup() as data_abort_handler() references
632 * this during init
633 */
634 proc0paddr = (struct user *)kernelstack.pv_va;
635 lwp0.l_addr = proc0paddr;
636
637 /*
638 * We must now clean the cache again....
639 * Cleaning may be done by reading new data to displace any
640 * dirty data in the cache. This will have happened in setttb()
641 * but since we are boot strapping the addresses used for the read
642 * may have just been remapped and thus the cache could be out
643 * of sync. A re-clean after the switch will cure this.
644 * After booting there are no gross reloations of the kernel thus
645 * this problem will not occur after initarm().
646 */
647 cpu_idcache_wbinv_all();
648
649 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
650
651 /*
652 * Pages were allocated during the secondary bootstrap for the
653 * stacks for different CPU modes.
654 * We must now set the r13 registers in the different CPU modes to
655 * point to these stacks.
656 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
657 * of the stack memory.
658 */
659 #ifdef VERBOSE_INIT_ARM
660 printf("init subsystems: stacks ");
661 #endif
662
663 set_stackptr(PSR_IRQ32_MODE,
664 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
665 set_stackptr(PSR_ABT32_MODE,
666 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
667 set_stackptr(PSR_UND32_MODE,
668 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
669 #ifdef PMAP_DEBUG
670 if (pmap_debug_level >= 0)
671 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va,
672 kernelstack.pv_pa);
673 #endif /* PMAP_DEBUG */
674
675 /*
676 * Well we should set a data abort handler.
677 * Once things get going this will change as we will need a proper
678 * handler. Until then we will use a handler that just panics but
679 * tells us why.
680 * Initialisation of the vetcors will just panic on a data abort.
681 * This just fills in a slightly better one.
682 */
683 #ifdef VERBOSE_INIT_ARM
684 printf("vectors ");
685 #endif
686 data_abort_handler_address = (u_int)data_abort_handler;
687 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
688 undefined_handler_address = (u_int)undefinedinstruction_bounce;
689 #ifdef VERBOSE_INIT_ARM
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 #endif
694
695 /* Initialise the undefined instruction handlers */
696 #ifdef VERBOSE_INIT_ARM
697 printf("undefined ");
698 #endif
699 undefined_init();
700
701 /* Load memory into UVM. */
702 #ifdef VERBOSE_INIT_ARM
703 printf("page ");
704 #endif
705 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
706 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
707 atop(physical_freestart), atop(physical_freeend),
708 VM_FREELIST_DEFAULT);
709
710 /* Boot strap pmap telling it where the kernel page table is */
711 #ifdef VERBOSE_INIT_ARM
712 printf("pmap ");
713 #endif
714 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
715
716 /* Setup the IRQ system */
717 #ifdef VERBOSE_INIT_ARM
718 printf("irq ");
719 #endif
720 ixp12x0_intr_init();
721
722 #ifdef VERBOSE_INIT_ARM
723 printf("done.\n");
724 #endif
725
726 #ifdef VERBOSE_INIT_ARM
727 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
728 physical_freestart, free_pages, free_pages);
729 printf("freemempos=%08lx\n", freemempos);
730 printf("switching to new L1 page table @%#lx... \n", kernel_l1pt.pv_pa);
731 #endif
732
733 consinit();
734 #ifdef VERBOSE_INIT_ARM
735 printf("consinit \n");
736 #endif
737
738 ixdp_ixp12x0_cc_setup();
739
740 #ifdef VERBOSE_INIT_ARM
741 printf("bootstrap done.\n");
742 #endif
743
744 #if NKSYMS || defined(DDB) || defined(MODULAR)
745 ksyms_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize);
746 #endif
747
748 #ifdef DDB
749 db_machine_init();
750 if (boothowto & RB_KDB)
751 Debugger();
752 #endif
753
754 /* We return the new stack pointer address */
755 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
756 }
757
758 void
759 consinit(void)
760 {
761 static int consinit_called = 0;
762
763 if (consinit_called != 0)
764 return;
765
766 consinit_called = 1;
767
768 pmap_devmap_register(ixm1200_devmap);
769
770 if (ixpcomcnattach(&ixp12x0_bs_tag,
771 IXPCOM_UART_HWBASE, IXPCOM_UART_VBASE,
772 CONSPEED, CONMODE))
773 panic("can't init serial console @%lx", IXPCOM_UART_HWBASE);
774 }
775
776 /*
777 * For optimal cache cleaning we need two 16K banks of
778 * virtual address space that NOTHING else will access
779 * and then we alternate the cache cleaning between the
780 * two banks.
781 * The cache cleaning code requires requires 2 banks aligned
782 * on total size boundry so the banks can be alternated by
783 * eorring the size bit (assumes the bank size is a power of 2)
784 */
785 void
786 ixdp_ixp12x0_cc_setup(void)
787 {
788 int loop;
789 paddr_t kaddr;
790 pt_entry_t *pte;
791
792 (void) pmap_extract(pmap_kernel(), KERNEL_TEXT_BASE, &kaddr);
793 for (loop = 0; loop < CPU_IXP12X0_CACHE_CLEAN_SIZE; loop += PAGE_SIZE) {
794 pte = vtopte(ixp12x0_cc_base + loop);
795 *pte = L2_S_PROTO | kaddr |
796 L2_S_PROT(PTE_KERNEL, VM_PROT_READ) | pte_l2_s_cache_mode;
797 PTE_SYNC(pte);
798 }
799 ixp12x0_cache_clean_addr = ixp12x0_cc_base;
800 ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
801 }
802