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