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