iq80310_machdep.c revision 1.81 1 /* $NetBSD: iq80310_machdep.c,v 1.81 2012/07/29 00:07:08 matt Exp $ */
2
3 /*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Copyright (c) 1997,1998 Mark Brinicombe.
40 * Copyright (c) 1997,1998 Causality Limited.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by Mark Brinicombe
54 * for the NetBSD Project.
55 * 4. The name of the company nor the name of the author may be used to
56 * endorse or promote products derived from this software without specific
57 * prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
63 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * Machine dependent functions for kernel setup for Intel IQ80310 evaluation
72 * boards using RedBoot firmware.
73 */
74
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: iq80310_machdep.c,v 1.81 2012/07/29 00:07:08 matt Exp $");
77
78 #include "opt_ddb.h"
79 #include "opt_pmap_debug.h"
80
81 #include <sys/param.h>
82 #include <sys/device.h>
83 #include <sys/systm.h>
84 #include <sys/kernel.h>
85 #include <sys/exec.h>
86 #include <sys/proc.h>
87 #include <sys/msgbuf.h>
88 #include <sys/reboot.h>
89 #include <sys/termios.h>
90 #include <sys/ksyms.h>
91
92 #include <uvm/uvm_extern.h>
93
94 #include <dev/cons.h>
95
96 #include <machine/db_machdep.h>
97 #include <ddb/db_sym.h>
98 #include <ddb/db_extern.h>
99
100 #include <machine/bootconfig.h>
101 #include <sys/bus.h>
102 #include <machine/cpu.h>
103 #include <machine/frame.h>
104 #include <arm/undefined.h>
105
106 #include <arm/arm32/machdep.h>
107
108 #include <arm/xscale/i80312reg.h>
109 #include <arm/xscale/i80312var.h>
110
111 #include <dev/pci/ppbreg.h>
112
113 #include <evbarm/iq80310/iq80310reg.h>
114 #include <evbarm/iq80310/iq80310var.h>
115 #include <evbarm/iq80310/obiovar.h>
116
117 #include "ksyms.h"
118
119 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
120 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
121 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
122
123 /*
124 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
125 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
126 */
127 #define KERNEL_VM_SIZE 0x0C000000
128
129 /*
130 * Address to call from cpu_reset() to reset the machine.
131 * This is machine architecture dependent as it varies depending
132 * on where the ROM appears when you turn the MMU off.
133 */
134
135 u_int cpu_reset_address = 0;
136
137 /* Define various stack sizes in pages */
138 #define IRQ_STACK_SIZE 1
139 #define ABT_STACK_SIZE 1
140 #define UND_STACK_SIZE 1
141
142 BootConfig bootconfig; /* Boot config storage */
143 char *boot_args = NULL;
144 char *boot_file = NULL;
145
146 vm_offset_t physical_start;
147 vm_offset_t physical_freestart;
148 vm_offset_t physical_freeend;
149 vm_offset_t physical_end;
150 u_int free_pages;
151
152 /*int debug_flags;*/
153 #ifndef PMAP_STATIC_L1S
154 int max_processes = 64; /* Default number */
155 #endif /* !PMAP_STATIC_L1S */
156
157 pv_addr_t minidataclean;
158
159 vm_offset_t msgbufphys;
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 4
169
170 /* L2 table for mapping i80312 */
171 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
172
173 /* L2 tables for mapping kernel VM */
174 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
175 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
176 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
177
178 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
179
180 /* Prototypes */
181
182 void consinit(void);
183
184 #include "com.h"
185 #if NCOM > 0
186 #include <dev/ic/comreg.h>
187 #include <dev/ic/comvar.h>
188 #endif
189
190 /*
191 * Define the default console speed for the board. This is generally
192 * what the firmware provided with the board defaults to.
193 */
194 #ifndef CONSPEED
195 #define CONSPEED B115200
196 #endif /* ! CONSPEED */
197
198 #ifndef CONUNIT
199 #define CONUNIT 0
200 #endif
201
202 #ifndef CONMODE
203 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
204 #endif
205
206 int comcnspeed = CONSPEED;
207 int comcnmode = CONMODE;
208 int comcnunit = CONUNIT;
209
210 /*
211 * void cpu_reboot(int howto, char *bootstr)
212 *
213 * Reboots the system
214 *
215 * Deal with any syncing, unmounting, dumping and shutdown hooks,
216 * then reset the CPU.
217 */
218 void
219 cpu_reboot(int howto, char *bootstr)
220 {
221
222 /*
223 * If we are still cold then hit the air brakes
224 * and crash to earth fast
225 */
226 if (cold) {
227 doshutdownhooks();
228 pmf_system_shutdown(boothowto);
229 printf("The operating system has halted.\n");
230 printf("Please press any key to reboot.\n\n");
231 cngetc();
232 printf("rebooting...\n");
233 cpu_reset();
234 /*NOTREACHED*/
235 }
236
237 /* Disable console buffering */
238
239 /*
240 * If RB_NOSYNC was not specified sync the discs.
241 * Note: Unless cold is set to 1 here, syslogd will die during the
242 * unmount. It looks like syslogd is getting woken up only to find
243 * that it cannot page part of the binary in as the filesystem has
244 * been unmounted.
245 */
246 if (!(howto & RB_NOSYNC))
247 bootsync();
248
249 /* Say NO to interrupts */
250 splhigh();
251
252 /* Do a dump if requested. */
253 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
254 dumpsys();
255
256 /* Run any shutdown hooks */
257 doshutdownhooks();
258
259 pmf_system_shutdown(boothowto);
260
261 /* Make sure IRQ's are disabled */
262 IRQdisable;
263
264 if (howto & RB_HALT) {
265 iq80310_7seg('.', '.');
266 printf("The operating system has halted.\n");
267 printf("Please press any key to reboot.\n\n");
268 cngetc();
269 }
270
271 printf("rebooting...\n");
272 cpu_reset();
273 /*NOTREACHED*/
274 }
275
276 /* Static device mappings. */
277 static const struct pmap_devmap iq80310_devmap[] = {
278 /*
279 * Map the on-board devices VA == PA so that we can access them
280 * with the MMU on or off.
281 */
282 {
283 IQ80310_OBIO_BASE,
284 IQ80310_OBIO_BASE,
285 IQ80310_OBIO_SIZE,
286 VM_PROT_READ|VM_PROT_WRITE,
287 PTE_NOCACHE,
288 },
289 {
290 IQ80310_PIOW_VBASE,
291 I80312_PCI_XLATE_PIOW_BASE,
292 I80312_PCI_XLATE_IOSIZE,
293 VM_PROT_READ|VM_PROT_WRITE,
294 PTE_NOCACHE,
295 },
296 {
297 IQ80310_SIOW_VBASE,
298 I80312_PCI_XLATE_SIOW_BASE,
299 I80312_PCI_XLATE_IOSIZE,
300 VM_PROT_READ|VM_PROT_WRITE,
301 PTE_NOCACHE,
302 },
303 {
304 IQ80310_80312_VBASE,
305 I80312_PMMR_BASE,
306 I80312_PMMR_SIZE,
307 VM_PROT_READ|VM_PROT_WRITE,
308 PTE_NOCACHE,
309 },
310
311 {
312 0,
313 0,
314 0,
315 0,
316 0,
317 }
318 };
319
320 /*
321 * u_int initarm(...)
322 *
323 * Initial entry point on startup. This gets called before main() is
324 * entered.
325 * It should be responsible for setting up everything that must be
326 * in place when main is called.
327 * This includes
328 * Taking a copy of the boot configuration structure.
329 * Initialising the physical console so characters can be printed.
330 * Setting up page tables for the kernel
331 * Relocating the kernel to the bottom of physical memory
332 */
333 u_int
334 initarm(void *arg)
335 {
336 extern vaddr_t xscale_cache_clean_addr;
337 #ifdef DIAGNOSTIC
338 extern vsize_t xscale_minidata_clean_size;
339 #endif
340 int loop;
341 int loop1;
342 u_int l1pagetable;
343 paddr_t memstart;
344 psize_t memsize;
345
346 /*
347 * Clear out the 7-segment display. Whee, the first visual
348 * indication that we're running kernel code.
349 */
350 iq80310_7seg(' ', ' ');
351
352 /*
353 * Heads up ... Setup the CPU / MMU / TLB functions
354 */
355 if (set_cpufuncs())
356 panic("CPU not recognized!");
357
358 /* Calibrate the delay loop. */
359 iq80310_calibrate_delay();
360
361 /*
362 * Since we map the on-board devices VA==PA, and the kernel
363 * is running VA==PA, it's possible for us to initialize
364 * the console now.
365 */
366 consinit();
367
368 #ifdef VERBOSE_INIT_ARM
369 /* Talk to the user */
370 printf("\nNetBSD/evbarm (IQ80310) booting ...\n");
371 #endif
372
373 /*
374 * Reset the secondary PCI bus. RedBoot doesn't stop devices
375 * on the PCI bus before handing us control, so we have to
376 * do this.
377 *
378 * XXX This is arguably a bug in RedBoot, and doing this reset
379 * XXX could be problematic in the future if we encounter an
380 * XXX application where the PPB in the i80312 is used as a
381 * XXX PPB.
382 */
383 {
384 uint32_t reg;
385
386 #ifdef VERBOSE_INIT_ARM
387 printf("Resetting secondary PCI bus...\n");
388 #endif
389 reg = bus_space_read_4(&obio_bs_tag,
390 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL);
391 bus_space_write_4(&obio_bs_tag,
392 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL,
393 reg | PPB_BC_SECONDARY_RESET);
394 delay(10 * 1000); /* 10ms enough? */
395 bus_space_write_4(&obio_bs_tag,
396 I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL,
397 reg);
398 }
399
400 /*
401 * We are currently running with the MMU enabled and the
402 * entire address space mapped VA==PA, except for the
403 * first 64M of RAM is also double-mapped at 0xc0000000.
404 * There is an L1 page table at 0xa0004000.
405 */
406
407 /*
408 * Fetch the SDRAM start/size from the i80312 SDRAM configuration
409 * registers.
410 */
411 i80312_sdram_bounds(&obio_bs_tag, I80312_PMMR_BASE + I80312_MEM_BASE,
412 &memstart, &memsize);
413
414 #ifdef VERBOSE_INIT_ARM
415 printf("initarm: Configuring system ...\n");
416 #endif
417
418 /* Fake bootconfig structure for the benefit of pmap.c */
419 /* XXX must make the memory description h/w independent */
420 bootconfig.dramblocks = 1;
421 bootconfig.dram[0].address = memstart;
422 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
423
424 /*
425 * Set up the variables that define the availablilty of
426 * physical memory. For now, we're going to set
427 * physical_freestart to 0xa0200000 (where the kernel
428 * was loaded), and allocate the memory we need downwards.
429 * If we get too close to the L1 table that we set up, we
430 * will panic. We will update physical_freestart and
431 * physical_freeend later to reflect what pmap_bootstrap()
432 * wants to see.
433 *
434 * XXX pmap_bootstrap() needs an enema.
435 */
436 physical_start = bootconfig.dram[0].address;
437 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
438
439 physical_freestart = 0xa0009000UL;
440 physical_freeend = 0xa0200000UL;
441
442 physmem = (physical_end - physical_start) / PAGE_SIZE;
443
444 #ifdef VERBOSE_INIT_ARM
445 /* Tell the user about the memory */
446 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
447 physical_start, physical_end - 1);
448 #endif
449
450 /*
451 * Okay, the kernel starts 2MB in from the bottom of physical
452 * memory. We are going to allocate our bootstrap pages downwards
453 * from there.
454 *
455 * We need to allocate some fixed page tables to get the kernel
456 * going. We allocate one page directory and a number of page
457 * tables and store the physical addresses in the kernel_pt_table
458 * array.
459 *
460 * The kernel page directory must be on a 16K boundary. The page
461 * tables must be on 4K boundaries. What we do is allocate the
462 * page directory on the first 16K boundary that we encounter, and
463 * the page tables on 4K boundaries otherwise. Since we allocate
464 * at least 3 L2 page tables, we are guaranteed to encounter at
465 * least one 16K aligned region.
466 */
467
468 #ifdef VERBOSE_INIT_ARM
469 printf("Allocating page tables\n");
470 #endif
471
472 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
473
474 #ifdef VERBOSE_INIT_ARM
475 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
476 physical_freestart, free_pages, free_pages);
477 #endif
478
479 /* Define a macro to simplify memory allocation */
480 #define valloc_pages(var, np) \
481 alloc_pages((var).pv_pa, (np)); \
482 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
483
484 #define alloc_pages(var, np) \
485 physical_freeend -= ((np) * PAGE_SIZE); \
486 if (physical_freeend < physical_freestart) \
487 panic("initarm: out of memory"); \
488 (var) = physical_freeend; \
489 free_pages -= (np); \
490 memset((char *)(var), 0, ((np) * PAGE_SIZE));
491
492 loop1 = 0;
493 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
494 /* Are we 16KB aligned for an L1 ? */
495 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
496 && kernel_l1pt.pv_pa == 0) {
497 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
498 } else {
499 valloc_pages(kernel_pt_table[loop1],
500 L2_TABLE_SIZE / PAGE_SIZE);
501 ++loop1;
502 }
503 }
504
505 /* This should never be able to happen but better confirm that. */
506 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
507 panic("initarm: Failed to align the kernel page directory");
508
509 /*
510 * Allocate a page for the system page mapped to V0x00000000
511 * This page will just contain the system vectors and can be
512 * shared by all processes.
513 */
514 alloc_pages(systempage.pv_pa, 1);
515
516 /* Allocate stacks for all modes */
517 valloc_pages(irqstack, IRQ_STACK_SIZE);
518 valloc_pages(abtstack, ABT_STACK_SIZE);
519 valloc_pages(undstack, UND_STACK_SIZE);
520 valloc_pages(kernelstack, UPAGES);
521
522 /* Allocate enough pages for cleaning the Mini-Data cache. */
523 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
524 valloc_pages(minidataclean, 1);
525
526 #ifdef VERBOSE_INIT_ARM
527 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
528 irqstack.pv_va);
529 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
530 abtstack.pv_va);
531 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
532 undstack.pv_va);
533 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
534 kernelstack.pv_va);
535 #endif
536
537 /*
538 * XXX Defer this to later so that we can reclaim the memory
539 * XXX used by the RedBoot page tables.
540 */
541 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
542
543 /*
544 * Ok we have allocated physical pages for the primary kernel
545 * page tables
546 */
547
548 #ifdef VERBOSE_INIT_ARM
549 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
550 #endif
551
552 /*
553 * Now we start construction of the L1 page table
554 * We start by mapping the L2 page tables into the L1.
555 * This means that we can replace L1 mappings later on if necessary
556 */
557 l1pagetable = kernel_l1pt.pv_pa;
558
559 /* Map the L2 pages tables in the L1 page table */
560 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
561 &kernel_pt_table[KERNEL_PT_SYS]);
562 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
563 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
564 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
565 pmap_link_l2pt(l1pagetable, IQ80310_IOPXS_VBASE,
566 &kernel_pt_table[KERNEL_PT_IOPXS]);
567 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
568 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
569 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
570
571 /* update the top of the kernel VM */
572 pmap_curmaxkvaddr =
573 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
574
575 #ifdef VERBOSE_INIT_ARM
576 printf("Mapping kernel\n");
577 #endif
578
579 /* Now we fill in the L2 pagetable for the kernel static code/data */
580 {
581 extern char etext[], _end[];
582 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
583 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
584 u_int logical;
585
586 textsize = (textsize + PGOFSET) & ~PGOFSET;
587 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
588
589 logical = 0x00200000; /* offset of kernel in RAM */
590
591 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
592 physical_start + logical, textsize,
593 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
594 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
595 physical_start + logical, totalsize - textsize,
596 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
597 }
598
599 #ifdef VERBOSE_INIT_ARM
600 printf("Constructing L2 page tables\n");
601 #endif
602
603 /* Map the stack pages */
604 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
605 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
606 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
607 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
608 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
609 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
610 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
611 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
612
613 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
614 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
615
616 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
617 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
618 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
619 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
620 }
621
622 /* Map the Mini-Data cache clean area. */
623 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
624 minidataclean.pv_pa);
625
626 /* Map the vector page. */
627 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
628 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
629
630 /* Map the statically mapped devices. */
631 pmap_devmap_bootstrap(l1pagetable, iq80310_devmap);
632
633 /*
634 * Give the XScale global cache clean code an appropriately
635 * sized chunk of unmapped VA space starting at 0xff000000
636 * (our device mappings end before this address).
637 */
638 xscale_cache_clean_addr = 0xff000000U;
639
640 /*
641 * Now we have the real page tables in place so we can switch to them.
642 * Once this is done we will be running with the REAL kernel page
643 * tables.
644 */
645
646 /*
647 * Update the physical_freestart/physical_freeend/free_pages
648 * variables.
649 */
650 {
651 extern char _end[];
652
653 physical_freestart = physical_start +
654 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
655 KERNEL_BASE);
656 physical_freeend = physical_end;
657 free_pages =
658 (physical_freeend - physical_freestart) / PAGE_SIZE;
659 }
660
661 /* Switch tables */
662 #ifdef VERBOSE_INIT_ARM
663 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
664 physical_freestart, free_pages, free_pages);
665 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
666 #endif
667 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
668 cpu_setttb(kernel_l1pt.pv_pa);
669 cpu_tlb_flushID();
670 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
671
672 /*
673 * Moved from cpu_startup() as data_abort_handler() references
674 * this during uvm init
675 */
676 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
677
678 #ifdef VERBOSE_INIT_ARM
679 printf("done!\n");
680 #endif
681
682 #ifdef VERBOSE_INIT_ARM
683 printf("bootstrap done.\n");
684 #endif
685
686 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
687
688 /*
689 * Pages were allocated during the secondary bootstrap for the
690 * stacks for different CPU modes.
691 * We must now set the r13 registers in the different CPU modes to
692 * point to these stacks.
693 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
694 * of the stack memory.
695 */
696 #ifdef VERBOSE_INIT_ARM
697 printf("init subsystems: stacks ");
698 #endif
699
700 set_stackptr(PSR_IRQ32_MODE,
701 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
702 set_stackptr(PSR_ABT32_MODE,
703 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
704 set_stackptr(PSR_UND32_MODE,
705 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
706
707 /*
708 * Well we should set a data abort handler.
709 * Once things get going this will change as we will need a proper
710 * handler.
711 * Until then we will use a handler that just panics but tells us
712 * why.
713 * Initialisation of the vectors will just panic on a data abort.
714 * This just fills in a slightly better one.
715 */
716 #ifdef VERBOSE_INIT_ARM
717 printf("vectors ");
718 #endif
719 data_abort_handler_address = (u_int)data_abort_handler;
720 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
721 undefined_handler_address = (u_int)undefinedinstruction_bounce;
722
723 /* Initialise the undefined instruction handlers */
724 #ifdef VERBOSE_INIT_ARM
725 printf("undefined ");
726 #endif
727 undefined_init();
728
729 /* Load memory into UVM. */
730 #ifdef VERBOSE_INIT_ARM
731 printf("page ");
732 #endif
733 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
734 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
735 atop(physical_freestart), atop(physical_freeend),
736 VM_FREELIST_DEFAULT);
737
738 /* Boot strap pmap telling it where the kernel page table is */
739 #ifdef VERBOSE_INIT_ARM
740 printf("pmap ");
741 #endif
742 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
743
744 /* Setup the IRQ system */
745 #ifdef VERBOSE_INIT_ARM
746 printf("irq ");
747 #endif
748 iq80310_intr_init();
749
750 #ifdef VERBOSE_INIT_ARM
751 printf("done.\n");
752 #endif
753
754 #ifdef DDB
755 db_machine_init();
756 if (boothowto & RB_KDB)
757 Debugger();
758 #endif
759
760 /* We return the new stack pointer address */
761 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
762 }
763
764 void
765 consinit(void)
766 {
767 static const bus_addr_t comcnaddrs[] = {
768 IQ80310_UART2, /* com0 (J9) */
769 IQ80310_UART1, /* com1 (J10) */
770 };
771 static int consinit_called;
772
773 if (consinit_called != 0)
774 return;
775
776 consinit_called = 1;
777
778 /*
779 * Console devices are mapped VA==PA. Our devmap reflects
780 * this, so register it now so drivers can map the console
781 * device.
782 */
783 pmap_devmap_register(iq80310_devmap);
784
785 #if NCOM > 0
786 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
787 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
788 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
789 #else
790 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
791 #endif
792 }
793