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