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