integrator_machdep.c revision 1.1 1 /* $NetBSD: integrator_machdep.c,v 1.1 2001/10/27 16:17:52 rearnsha Exp $ */
2
3 /*
4 * Copyright (c) 2001 ARM Ltd
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the company may not be used to endorse or promote
16 * products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * Copyright (c) 1997,1998 Mark Brinicombe.
32 * Copyright (c) 1997,1998 Causality Limited.
33 * All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by Mark Brinicombe
46 * for the NetBSD Project.
47 * 4. The name of the company nor the name of the author may be used to
48 * endorse or promote products derived from this software without specific
49 * prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
52 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
55 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
56 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
57 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 *
63 * Machine dependant functions for kernel setup for integrator board
64 *
65 * Created : 24/11/97
66 */
67
68 #include "opt_ddb.h"
69 #include "opt_pmap_debug.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
81 #include <dev/cons.h>
82
83 #include <machine/db_machdep.h>
84 #include <ddb/db_sym.h>
85 #include <ddb/db_extern.h>
86
87 #include <machine/bootconfig.h>
88 #include <machine/bus.h>
89 #include <machine/cpu.h>
90 #include <machine/frame.h>
91 #include <machine/intr.h>
92 #include <machine/pte.h>
93 #include <machine/undefined.h>
94
95 #include <evbarm/integrator/integrator_boot.h>
96
97 #include "opt_ipkdb.h"
98 #include "pci.h"
99
100 void ifpga_reset(void) __attribute__((noreturn));
101 /*
102 * Address to call from cpu_reset() to reset the machine.
103 * This is machine architecture dependant as it varies depending
104 * on where the ROM appears when you turn the MMU off.
105 */
106
107 u_int cpu_reset_address = (u_int) ifpga_reset;
108
109 /* Define various stack sizes in pages */
110 #define IRQ_STACK_SIZE 1
111 #define ABT_STACK_SIZE 1
112 #ifdef IPKDB
113 #define UND_STACK_SIZE 2
114 #else
115 #define UND_STACK_SIZE 1
116 #endif
117
118 struct intbootinfo intbootinfo;
119 BootConfig bootconfig; /* Boot config storage */
120 static char bootargs[MAX_BOOT_STRING + 1];
121 char *boot_args = NULL;
122 char *boot_file = NULL;
123
124 vm_offset_t physical_start;
125 vm_offset_t physical_freestart;
126 vm_offset_t physical_freeend;
127 vm_offset_t physical_end;
128 u_int free_pages;
129 vm_offset_t pagetables_start;
130 int physmem = 0;
131
132 /*int debug_flags;*/
133 #ifndef PMAP_STATIC_L1S
134 int max_processes = 64; /* Default number */
135 #endif /* !PMAP_STATIC_L1S */
136
137 /* Physical and virtual addresses for some global pages */
138 pv_addr_t systempage;
139 pv_addr_t irqstack;
140 pv_addr_t undstack;
141 pv_addr_t abtstack;
142 pv_addr_t kernelstack;
143
144 vm_offset_t msgbufphys;
145
146 extern u_int data_abort_handler_address;
147 extern u_int prefetch_abort_handler_address;
148 extern u_int undefined_handler_address;
149
150 #ifdef PMAP_DEBUG
151 extern int pmap_debug_level;
152 #endif
153
154 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
155 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
156 #define KERNEL_PT_VMDATA 2 /* Page tables for mapping kernel VM */
157 #define KERNEL_PT_VMDATA_NUM (KERNEL_VM_SIZE >> (PDSHIFT + 2))
158 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
159
160 pt_entry_t kernel_pt_table[NUM_KERNEL_PTS];
161
162 struct user *proc0paddr;
163
164 /* Prototypes */
165
166 void consinit __P((void));
167
168 void map_section __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa,
169 int cacheable));
170 void map_pagetable __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
171 void map_entry __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
172 void map_entry_nc __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
173 void map_entry_ro __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
174 vm_size_t map_chunk __P((vm_offset_t pd, vm_offset_t pt, vm_offset_t va,
175 vm_offset_t pa, vm_size_t size, u_int acc,
176 u_int flg));
177
178 void process_kernel_args __P((char *));
179 void data_abort_handler __P((trapframe_t *frame));
180 void prefetch_abort_handler __P((trapframe_t *frame));
181 void undefinedinstruction_bounce __P((trapframe_t *frame));
182 void zero_page_readonly __P((void));
183 void zero_page_readwrite __P((void));
184 extern void configure __P((void));
185 extern void db_machine_init __P((void));
186 extern void parse_mi_bootargs __P((char *args));
187 extern void dumpsys __P((void));
188
189 /* A load of console goo. */
190 #include "vga.h"
191 #if (NVGA > 0)
192 #include <dev/ic/mc6845reg.h>
193 #include <dev/ic/pcdisplayvar.h>
194 #include <dev/ic/vgareg.h>
195 #include <dev/ic/vgavar.h>
196 #endif
197
198 #include "pckbc.h"
199 #if (NPCKBC > 0)
200 #include <dev/ic/i8042reg.h>
201 #include <dev/ic/pckbcvar.h>
202 #endif
203
204 #include "com.h"
205 #if (NCOM > 0)
206 #include <dev/ic/comreg.h>
207 #include <dev/ic/comvar.h>
208 #ifndef CONCOMADDR
209 #define CONCOMADDR 0x3f8
210 #endif
211 #endif
212
213 #define CONSPEED B115200
214 #ifndef CONSPEED
215 #define CONSPEED B9600 /* TTYDEF_SPEED */
216 #endif
217 #ifndef CONMODE
218 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
219 #endif
220
221 int comcnspeed = CONSPEED;
222 int comcnmode = CONMODE;
223
224 #include "plcom.h"
225 #if (NPLCOM > 0)
226 #include <evbarm/dev/plcomreg.h>
227 #include <evbarm/dev/plcomvar.h>
228
229 #include <evbarm/ifpga/ifpgamem.h>
230 #include <evbarm/ifpga/ifpgareg.h>
231 #include <evbarm/ifpga/ifpgavar.h>
232 #endif
233
234 #ifndef CONSDEVNAME
235 #define CONSDEVNAME "plcom"
236 #endif
237
238 #ifndef PLCONSPEED
239 #define PLCONSPEED B38400
240 #endif
241 #ifndef PLCONMODE
242 #define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
243 #endif
244 #ifndef PLCOMCNUNIT
245 #define PLCOMCNUNIT -1
246 #endif
247
248 int plcomcnspeed = PLCONSPEED;
249 int plcomcnmode = PLCONMODE;
250
251 #if 0
252 extern struct consdev kcomcons;
253 static void kcomcnputc(dev_t, int);
254 #endif
255
256 /*
257 * void cpu_reboot(int howto, char *bootstr)
258 *
259 * Reboots the system
260 *
261 * Deal with any syncing, unmounting, dumping and shutdown hooks,
262 * then reset the CPU.
263 */
264
265 void
266 cpu_reboot(howto, bootstr)
267 int howto;
268 char *bootstr;
269 {
270 #ifdef DIAGNOSTIC
271 /* info */
272 printf("boot: howto=%08x curproc=%p\n", howto, curproc);
273 #endif
274
275 /*
276 * If we are still cold then hit the air brakes
277 * and crash to earth fast
278 */
279 if (cold) {
280 doshutdownhooks();
281 printf("The operating system has halted.\n");
282 printf("Please press any key to reboot.\n\n");
283 cngetc();
284 printf("rebooting...\n");
285 ifpga_reset();
286 /*NOTREACHED*/
287 }
288
289 /* Disable console buffering */
290 /* cnpollc(1);*/
291
292 /*
293 * If RB_NOSYNC was not specified sync the discs.
294 * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
295 * It looks like syslogd is getting woken up only to find that it cannot
296 * page part of the binary in as the filesystem has been unmounted.
297 */
298 if (!(howto & RB_NOSYNC))
299 bootsync();
300
301 /* Say NO to interrupts */
302 splhigh();
303
304 /* Do a dump if requested. */
305 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
306 dumpsys();
307
308 /* Run any shutdown hooks */
309 doshutdownhooks();
310
311 /* Make sure IRQ's are disabled */
312 IRQdisable;
313
314 if (howto & RB_HALT) {
315 printf("The operating system has halted.\n");
316 printf("Please press any key to reboot.\n\n");
317 cngetc();
318 }
319
320 printf("rebooting...\n");
321 ifpga_reset();
322 /*NOTREACHED*/
323 }
324
325 /*
326 * Mapping table for core kernel memory. This memory is mapped at init
327 * time with section mappings.
328 */
329 struct l1_sec_map {
330 vm_offset_t va;
331 vm_offset_t pa;
332 vm_size_t size;
333 int flags;
334 } l1_sec_table[] = {
335 #if NPLCOM > 0 && defined(PLCONSOLE)
336 { UART0_BOOT_BASE, IFPGA_IO_BASE + IFPGA_UART0, 1024 * 1024, 0},
337 { UART1_BOOT_BASE, IFPGA_IO_BASE + IFPGA_UART1, 1024 * 1024, 0},
338 #endif
339 #if NPCI > 0
340 { IFPGA_PCI_IO_VBASE, IFPGA_PCI_IO_BASE, IFPGA_PCI_IO_VSIZE, 0},
341 { IFPGA_PCI_CONF_VBASE, IFPGA_PCI_CONF_BASE, IFPGA_PCI_CONF_VSIZE, 0},
342 #endif
343
344 { 0, 0, 0, 0 }
345 };
346
347 /*
348 * u_int initarm(struct ebsaboot *bootinfo)
349 *
350 * Initial entry point on startup. This gets called before main() is
351 * entered.
352 * It should be responsible for setting up everything that must be
353 * in place when main is called.
354 * This includes
355 * Taking a copy of the boot configuration structure.
356 * Initialising the physical console so characters can be printed.
357 * Setting up page tables for the kernel
358 * Relocating the kernel to the bottom of physical memory
359 */
360
361 u_int
362 initarm(bootinfo)
363 struct intbootinfo *bootinfo;
364 {
365 int loop;
366 int loop1;
367 u_int l1pagetable;
368 u_int l2pagetable;
369 extern char page0[], page0_end[];
370 extern int etext asm ("_etext");
371 extern int end asm ("_end");
372 pv_addr_t kernel_l1pt;
373 pv_addr_t kernel_ptpt;
374 #if NPLCOM > 0 && defined(PLCONSOLE)
375 static struct bus_space plcom_bus_space;
376 #endif
377
378
379 #if 0
380 cn_tab = &kcomcons;
381 #endif
382 /*
383 * Heads up ... Setup the CPU / MMU / TLB functions
384 */
385 if (set_cpufuncs())
386 panic("cpu not recognized!");
387
388 /* - intbootinfo.bt_memstart) / NBPG */;
389
390 #if NPLCOM > 0 && defined(PLCONSOLE)
391 /*
392 * Initialise the diagnostic serial console
393 * This allows a means of generating output during initarm().
394 * Once all the memory map changes are complete we can call consinit()
395 * and not have to worry about things moving.
396 */
397
398 if (PLCOMCNUNIT == 0) {
399 ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd600000);
400 plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
401 IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
402 } else if (PLCOMCNUNIT == 1) {
403 ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd700000);
404 plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
405 IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
406 }
407 #endif
408
409 /* Talk to the user */
410 printf("\nNetBSD/integrator booting ...\n");
411
412 #if 0
413 if (intbootinfo.bt_magic != BT_MAGIC_NUMBER_EBSA
414 && intbootinfo.bt_magic != BT_MAGIC_NUMBER_CATS)
415 panic("Incompatible magic number passed in boot args\n");
416 #endif
417
418 /* {
419 int loop;
420 for (loop = 0; loop < 8; ++loop) {
421 printf("%08x\n", *(((int *)bootinfo)+loop));
422 }
423 }*/
424
425 /*
426 * Ok we have the following memory map
427 *
428 * virtual address == physical address apart from the areas:
429 * 0x00000000 -> 0x000fffff which is mapped to
430 * top 1MB of physical memory
431 * 0x00100000 -> 0x0fffffff which is mapped to
432 * physical addresses 0x00100000 -> 0x0fffffff
433 * 0x10000000 -> 0x1fffffff which is mapped to
434 * physical addresses 0x00000000 -> 0x0fffffff
435 * 0x20000000 -> 0xefffffff which is mapped to
436 * physical addresses 0x20000000 -> 0xefffffff
437 * 0xf0000000 -> 0xf03fffff which is mapped to
438 * physical addresses 0x00000000 -> 0x003fffff
439 *
440 * This means that the kernel is mapped suitably for continuing
441 * execution, all I/O is mapped 1:1 virtual to physical and
442 * physical memory is accessible.
443 *
444 * The initarm() has the responsibility for creating the kernel
445 * page tables.
446 * It must also set up various memory pointers that are used
447 * by pmap etc.
448 */
449
450 /*
451 * Examine the boot args string for options we need to know about
452 * now.
453 */
454 #if 0
455 process_kernel_args((char *)intbootinfo.bt_args);
456 #endif
457
458 printf("initarm: Configuring system ...\n");
459
460 /*
461 * Set up the variables that define the availablilty of
462 * physical memory
463 */
464 physical_start = 0 /*intbootinfo.bt_memstart*/;
465 physical_freestart = physical_start;
466
467 #if 0
468 physical_end = /*intbootinfo.bt_memend*/ /*intbootinfo.bi_nrpages * NBPG */ 32*1024*1024;
469 #else
470 {
471 volatile unsigned long *cm_sdram
472 = (volatile unsigned long *)0x10000020;
473
474 switch ((*cm_sdram >> 2) & 0x7)
475 {
476 case 0:
477 physical_end = 16 * 1024 * 1024;
478 break;
479 case 1:
480 physical_end = 32 * 1024 * 1024;
481 break;
482 case 2:
483 physical_end = 64 * 1024 * 1024;
484 break;
485 case 3:
486 physical_end = 128 * 1024 * 1024;
487 break;
488 case 4:
489 physical_end = 256 * 1024 * 1024;
490 break;
491 default:
492 printf("CM_SDRAM retuns unknown value, using 16M\n");
493 physical_end = 16 * 1024 * 1024;
494 break;
495 }
496 }
497 #endif
498
499 physical_freeend = physical_end;
500 free_pages = (physical_end - physical_start) / NBPG;
501
502 /* Set up the bootconfig structure for the benefit of pmap.c */
503 bootconfig.dramblocks = 1;
504 bootconfig.dram[0].address = physical_start;
505 bootconfig.dram[0].pages = free_pages;
506
507 physmem = (physical_end - physical_start) / NBPG;
508
509 /* Tell the user about the memory */
510 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
511 physical_start, physical_end - 1);
512
513 /*
514 * Ok the kernel occupies the bottom of physical memory.
515 * The first free page after the kernel can be found in
516 * intbootinfo->bt_memavail
517 * We now need to allocate some fixed page tables to get the kernel
518 * going.
519 * We allocate one page directory and a number page tables and store
520 * the physical addresses in the kernel_pt_table array.
521 *
522 * Ok the next bit of physical allocation may look complex but it is
523 * simple really. I have done it like this so that no memory gets
524 * wasted during the allocation of various pages and tables that are
525 * all different sizes.
526 * The start addresses will be page aligned.
527 * We allocate the kernel page directory on the first free 16KB boundry
528 * we find.
529 * We allocate the kernel page tables on the first 4KB boundry we find.
530 * Since we allocate at least 3 L2 pagetables we know that we must
531 * encounter at least one 16KB aligned address.
532 */
533
534 #ifdef VERBOSE_INIT_ARM
535 printf("Allocating page tables\n");
536 #endif
537
538 /* Update the address of the first free 16KB chunk of physical memory */
539 physical_freestart = ((uintptr_t) &end - KERNEL_TEXT_BASE + PGOFSET)
540 & ~PGOFSET;
541 #if 0
542 physical_freestart += (kernexec->a_syms + sizeof(int)
543 + *(u_int *)((int)end + kernexec->a_syms + sizeof(int))
544 + (NBPG - 1)) & ~(NBPG - 1);
545 #endif
546
547 free_pages -= (physical_freestart - physical_start) / NBPG;
548 #ifdef VERBOSE_INIT_ARM
549 printf("freestart = %#lx, free_pages = %d (%#x)\n",
550 physical_freestart, free_pages, free_pages);
551 #endif
552
553 /* Define a macro to simplify memory allocation */
554 #define valloc_pages(var, np) \
555 alloc_pages((var).pv_pa, (np)); \
556 (var).pv_va = KERNEL_TEXT_BASE + (var).pv_pa - physical_start;
557
558 #define alloc_pages(var, np) \
559 (var) = physical_freestart; \
560 physical_freestart += ((np) * NBPG); \
561 free_pages -= (np); \
562 memset((char *)(var), 0, ((np) * NBPG));
563
564 loop1 = 0;
565 kernel_l1pt.pv_pa = 0;
566 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
567 /* Are we 16KB aligned for an L1 ? */
568 if ((physical_freestart & (PD_SIZE - 1)) == 0
569 && kernel_l1pt.pv_pa == 0) {
570 valloc_pages(kernel_l1pt, PD_SIZE / NBPG);
571 } else {
572 alloc_pages(kernel_pt_table[loop1], PT_SIZE / NBPG);
573 ++loop1;
574 }
575 }
576
577 /* This should never be able to happen but better confirm that. */
578 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (PD_SIZE-1)) != 0)
579 panic("initarm: Failed to align the kernel page directory\n");
580
581 /*
582 * Allocate a page for the system page mapped to V0x00000000
583 * This page will just contain the system vectors and can be
584 * shared by all processes.
585 */
586 alloc_pages(systempage.pv_pa, 1);
587
588 /* Allocate a page for the page table to map kernel page tables*/
589 valloc_pages(kernel_ptpt, PT_SIZE / NBPG);
590
591 /* Allocate stacks for all modes */
592 valloc_pages(irqstack, IRQ_STACK_SIZE);
593 valloc_pages(abtstack, ABT_STACK_SIZE);
594 valloc_pages(undstack, UND_STACK_SIZE);
595 valloc_pages(kernelstack, UPAGES);
596
597 #ifdef VERBOSE_INIT_ARM
598 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
599 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
600 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
601 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
602 #endif
603
604 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
605
606 /*
607 * Ok we have allocated physical pages for the primary kernel
608 * page tables
609 */
610
611 #ifdef VERBOSE_INIT_ARM
612 printf("Creating L1 page table at %#lx\n", kernel_l1pt.pv_pa);
613 #endif
614
615 /*
616 * Now we start consturction of the L1 page table
617 * We start by mapping the L2 page tables into the L1.
618 * This means that we can replace L1 mappings later on if necessary
619 */
620 l1pagetable = kernel_l1pt.pv_pa;
621
622 /* Map the L2 pages tables in the L1 page table */
623 map_pagetable(l1pagetable, 0x00000000,
624 kernel_pt_table[KERNEL_PT_SYS]);
625 map_pagetable(l1pagetable, KERNEL_BASE,
626 kernel_pt_table[KERNEL_PT_KERNEL]);
627 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
628 map_pagetable(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
629 kernel_pt_table[KERNEL_PT_VMDATA + loop]);
630 map_pagetable(l1pagetable, PROCESS_PAGE_TBLS_BASE,
631 kernel_ptpt.pv_pa);
632
633 #ifdef VERBOSE_INIT_ARM
634 printf("Mapping kernel\n");
635 #endif
636
637 /* Now we fill in the L2 pagetable for the kernel static code/data */
638 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL];
639
640 {
641 u_int logical;
642 size_t textsize = (uintptr_t) &etext - KERNEL_TEXT_BASE;
643 size_t totalsize = (uintptr_t) &end - KERNEL_TEXT_BASE;
644
645 /* Round down text size and round up total size
646 */
647 textsize = textsize & ~PGOFSET;
648 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
649 /* logical = map_chunk(l1pagetable, l2pagetable, KERNEL_BASE,
650 physical_start, KERNEL_TEXT_BASE - KERNEL_BASE,
651 AP_KRW, PT_CACHEABLE); */
652 logical = map_chunk(l1pagetable, l2pagetable,
653 KERNEL_TEXT_BASE, physical_start, textsize,
654 AP_KRW, PT_CACHEABLE);
655 logical += map_chunk(l1pagetable, l2pagetable,
656 KERNEL_TEXT_BASE + logical, physical_start + logical,
657 totalsize - textsize, AP_KRW, PT_CACHEABLE);
658 #if 0
659 logical += map_chunk(0, l2pagetable, KERNEL_BASE + logical,
660 physical_start + logical, kernexec->a_syms + sizeof(int)
661 + *(u_int *)((int)end + kernexec->a_syms + sizeof(int)),
662 AP_KRW, PT_CACHEABLE);
663 #endif
664 }
665
666 #ifdef VERBOSE_INIT_ARM
667 printf("Constructing L2 page tables\n");
668 #endif
669
670 /* Map the boot arguments page */
671 #if 0
672 map_entry_ro(l2pagetable, intbootinfo.bt_vargp, intbootinfo.bt_pargp);
673 #endif
674
675 /* Map the stack pages */
676 map_chunk(0, l2pagetable, irqstack.pv_va, irqstack.pv_pa,
677 IRQ_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
678 map_chunk(0, l2pagetable, abtstack.pv_va, abtstack.pv_pa,
679 ABT_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
680 map_chunk(0, l2pagetable, undstack.pv_va, undstack.pv_pa,
681 UND_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
682 map_chunk(0, l2pagetable, kernelstack.pv_va, kernelstack.pv_pa,
683 UPAGES * NBPG, AP_KRW, PT_CACHEABLE);
684 map_chunk(0, l2pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
685 PD_SIZE, AP_KRW, 0);
686
687 /* Map the page table that maps the kernel pages */
688 map_entry_nc(l2pagetable, kernel_ptpt.pv_pa, kernel_ptpt.pv_pa);
689
690 /*
691 * Map entries in the page table used to map PTE's
692 * Basically every kernel page table gets mapped here
693 */
694 /* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
695 l2pagetable = kernel_ptpt.pv_pa;
696 map_entry_nc(l2pagetable, (KERNEL_BASE >> (PGSHIFT-2)),
697 kernel_pt_table[KERNEL_PT_KERNEL]);
698 map_entry_nc(l2pagetable, (PROCESS_PAGE_TBLS_BASE >> (PGSHIFT-2)),
699 kernel_ptpt.pv_pa);
700 map_entry_nc(l2pagetable, (0x00000000 >> (PGSHIFT-2)),
701 kernel_pt_table[KERNEL_PT_SYS]);
702 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
703 map_entry_nc(l2pagetable, ((KERNEL_VM_BASE +
704 (loop * 0x00400000)) >> (PGSHIFT-2)),
705 kernel_pt_table[KERNEL_PT_VMDATA + loop]);
706
707 /*
708 * Map the system page in the kernel page table for the bottom 1Meg
709 * of the virtual memory map.
710 */
711 l2pagetable = kernel_pt_table[KERNEL_PT_SYS];
712 #if 1
713 /* MULTI-ICE requires that page 0 is NC/NB so that it can download
714 the cache-clean code there. */
715 map_entry_nc(l2pagetable, 0x00000000, systempage.pv_pa);
716 #else
717 map_entry_nc(l2pagetable, 0x00000000, systempage.pv_pa);
718 #endif
719 /* Map the core memory needed before autoconfig */
720 loop = 0;
721 while (l1_sec_table[loop].size) {
722 vm_size_t sz;
723
724 #ifdef VERBOSE_INIT_ARM
725 printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
726 l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
727 l1_sec_table[loop].va);
728 #endif
729 for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_SEC_SIZE)
730 map_section(l1pagetable, l1_sec_table[loop].va + sz,
731 l1_sec_table[loop].pa + sz,
732 l1_sec_table[loop].flags);
733 ++loop;
734 }
735
736 /*
737 * Now we have the real page tables in place so we can switch to them.
738 * Once this is done we will be running with the REAL kernel page tables.
739 */
740
741 /* Switch tables */
742 #ifdef VERBOSE_INIT_ARM
743 printf("freestart = %#lx, free_pages = %d (%#x)\n",
744 physical_freestart, free_pages, free_pages);
745 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
746 #endif
747
748 setttb(kernel_l1pt.pv_pa);
749
750 #ifdef VERBOSE_INIT_ARM
751 printf("done!\n");
752 #endif
753
754 #ifdef PLCONSOLE
755 /*
756 * The IFPGA registers have just moved.
757 * Detach the diagnostic serial port and reattach at the new address.
758 */
759 plcomcndetach();
760 #endif
761
762 /*
763 * XXX this should only be done in main() but it useful to
764 * have output earlier ...
765 */
766 consinit();
767
768 #ifdef VERBOSE_INIT_ARM
769 printf("bootstrap done.\n");
770 #endif
771
772 /* Right set up the vectors at the bottom of page 0 */
773 memcpy((char *)0x00000000, page0, page0_end - page0);
774
775 /* We have modified a text page so sync the icache */
776 cpu_cache_syncI();
777
778 /*
779 * Pages were allocated during the secondary bootstrap for the
780 * stacks for different CPU modes.
781 * We must now set the r13 registers in the different CPU modes to
782 * point to these stacks.
783 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
784 * of the stack memory.
785 */
786 printf("init subsystems: stacks ");
787
788 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
789 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
790 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
791
792 /*
793 * Well we should set a data abort handler.
794 * Once things get going this will change as we will need a proper handler.
795 * Until then we will use a handler that just panics but tells us
796 * why.
797 * Initialisation of the vectors will just panic on a data abort.
798 * This just fills in a slighly better one.
799 */
800 printf("vectors ");
801 data_abort_handler_address = (u_int)data_abort_handler;
802 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
803 undefined_handler_address = (u_int)undefinedinstruction_bounce;
804
805 /* At last !
806 * We now have the kernel in physical memory from the bottom upwards.
807 * Kernel page tables are physically above this.
808 * The kernel is mapped to KERNEL_TEXT_BASE
809 * The kernel data PTs will handle the mapping of 0xf1000000-0xf3ffffff
810 * The page tables are mapped to 0xefc00000
811 */
812
813 /* Initialise the undefined instruction handlers */
814 printf("undefined ");
815 undefined_init();
816
817 /* Boot strap pmap telling it where the kernel page table is */
818 printf("pmap ");
819 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
820
821 /* Setup the IRQ system */
822 printf("irq ");
823 irq_init();
824
825 printf("done.\n");
826
827 #ifdef IPKDB
828 /* Initialise ipkdb */
829 ipkdb_init();
830 if (boothowto & RB_KDB)
831 ipkdb_connect(0);
832 #endif
833
834 #ifdef DDB
835 printf("ddb: ");
836 db_machine_init();
837 #if 0
838 ddb_init(end[0], end + 1, esym);
839 #endif
840
841 if (boothowto & RB_KDB)
842 Debugger();
843 #endif
844
845 /* We return the new stack pointer address */
846 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
847 }
848
849 void
850 process_kernel_args(args)
851 char *args;
852 {
853
854 boothowto = 0;
855
856 /* Make a local copy of the bootargs */
857 strncpy(bootargs, args, MAX_BOOT_STRING);
858
859 args = bootargs;
860 boot_file = bootargs;
861
862 /* Skip the kernel image filename */
863 while (*args != ' ' && *args != 0)
864 ++args;
865
866 if (*args != 0)
867 *args++ = 0;
868
869 while (*args == ' ')
870 ++args;
871
872 boot_args = args;
873
874 printf("bootfile: %s\n", boot_file);
875 printf("bootargs: %s\n", boot_args);
876
877 parse_mi_bootargs(boot_args);
878 }
879
880 void
881 consinit(void)
882 {
883 static int consinit_called = 0;
884 #if NPLCOM > 0 && defined(PLCONSOLE)
885 static struct bus_space plcom_bus_space;
886 #endif
887 #if 0
888 char *console = CONSDEVNAME;
889 #endif
890
891 if (consinit_called != 0)
892 return;
893
894 consinit_called = 1;
895
896 #if NPLCOM > 0 && defined(PLCONSOLE)
897 if (PLCOMCNUNIT == 0) {
898 ifpga_create_io_bs_tag(&plcom_bus_space,
899 (void*)UART0_BOOT_BASE);
900 if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
901 IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
902 panic("can't init serial console");
903 return;
904 } else if (PLCOMCNUNIT == 1) {
905 ifpga_create_io_bs_tag(&plcom_bus_space,
906 (void*)UART0_BOOT_BASE);
907 if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
908 IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
909 panic("can't init serial console");
910 return;
911 }
912 #endif
913 #if (NCOM > 0)
914 if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
915 COM_FREQ, comcnmode))
916 panic("can't init serial console @%x", CONCOMADDR);
917 return;
918 #endif
919 panic("No serial console configured");
920 }
921
922 #if 0
923 static bus_space_handle_t kcom_base = (bus_space_handle_t) (DC21285_PCI_IO_VBASE + CONCOMADDR);
924
925 u_int8_t footbridge_bs_r_1(void *, bus_space_handle_t, bus_size_t);
926 void footbridge_bs_w_1(void *, bus_space_handle_t, bus_size_t, u_int8_t);
927
928 #define KCOM_GETBYTE(r) footbridge_bs_r_1(0, kcom_base, (r))
929 #define KCOM_PUTBYTE(r,v) footbridge_bs_w_1(0, kcom_base, (r), (v))
930
931 static int
932 kcomcngetc(dev_t dev)
933 {
934 int stat, c;
935
936 /* block until a character becomes available */
937 while (!ISSET(stat = KCOM_GETBYTE(com_lsr), LSR_RXRDY))
938 ;
939
940 c = KCOM_GETBYTE(com_data);
941 stat = KCOM_GETBYTE(com_iir);
942 return c;
943 }
944
945 /*
946 * Console kernel output character routine.
947 */
948 static void
949 kcomcnputc(dev_t dev, int c)
950 {
951 int timo;
952
953 /* wait for any pending transmission to finish */
954 timo = 150000;
955 while (!ISSET(KCOM_GETBYTE(com_lsr), LSR_TXRDY) && --timo)
956 continue;
957
958 KCOM_PUTBYTE(com_data, c);
959
960 /* wait for this transmission to complete */
961 timo = 1500000;
962 while (!ISSET(KCOM_GETBYTE(com_lsr), LSR_TXRDY) && --timo)
963 continue;
964 }
965
966 static void
967 kcomcnpollc(dev_t dev, int on)
968 {
969 }
970
971 struct consdev kcomcons = {
972 NULL, NULL, kcomcngetc, kcomcnputc, kcomcnpollc, NULL,
973 NODEV, CN_NORMAL
974 };
975
976 #endif
977