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