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