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