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