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