npwr_fc_machdep.c revision 1.23 1 /* $NetBSD: npwr_fc_machdep.c,v 1.23 2018/09/21 12:04:10 skrll Exp $ */
2
3 /*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe and Steve C. Woodford 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 IQ80321 evaluation
72 * boards using RedBoot firmware.
73 */
74
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: npwr_fc_machdep.c,v 1.23 2018/09/21 12:04:10 skrll Exp $");
77
78 #include "opt_arm_debug.h"
79 #include "opt_console.h"
80 #include "opt_ddb.h"
81 #include "opt_kgdb.h"
82 #include "opt_pmap_debug.h"
83
84 #include <sys/param.h>
85 #include <sys/device.h>
86 #include <sys/systm.h>
87 #include <sys/kernel.h>
88 #include <sys/exec.h>
89 #include <sys/proc.h>
90 #include <sys/msgbuf.h>
91 #include <sys/reboot.h>
92 #include <sys/termios.h>
93 #include <sys/ksyms.h>
94
95 #include <uvm/uvm_extern.h>
96
97 #include <dev/cons.h>
98
99 #include <machine/db_machdep.h>
100 #include <ddb/db_sym.h>
101 #include <ddb/db_extern.h>
102
103 #include <machine/bootconfig.h>
104 #include <sys/bus.h>
105 #include <machine/cpu.h>
106 #include <machine/frame.h>
107 #include <arm/undefined.h>
108
109 #include <arm/arm32/machdep.h>
110
111 #include <arm/xscale/i80321reg.h>
112 #include <arm/xscale/i80321var.h>
113
114 #include <dev/pci/ppbreg.h>
115
116 #include <evbarm/iq80321/iq80321reg.h>
117 #include <evbarm/iq80321/iq80321var.h>
118 #include <evbarm/iq80321/obiovar.h>
119
120 #include "ksyms.h"
121
122 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
123 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
124 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
125
126 /*
127 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
128 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
129 */
130 #define KERNEL_VM_SIZE 0x0C000000
131
132 BootConfig bootconfig; /* Boot config storage */
133 char *boot_args = NULL;
134 char *boot_file = NULL;
135
136 vaddr_t physical_start;
137 vaddr_t physical_freestart;
138 vaddr_t physical_freeend;
139 vaddr_t physical_end;
140 u_int free_pages;
141
142 /*int debug_flags;*/
143 #ifndef PMAP_STATIC_L1S
144 int max_processes = 64; /* Default number */
145 #endif /* !PMAP_STATIC_L1S */
146
147 /* Physical and virtual addresses for some global pages */
148 pv_addr_t minidataclean;
149
150 paddr_t msgbufphys;
151
152 #ifdef PMAP_DEBUG
153 extern int pmap_debug_level;
154 #endif
155
156 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
157
158 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
159 #define KERNEL_PT_KERNEL_NUM 4
160
161 /* L2 table for mapping i80321 */
162 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
163
164 /* L2 tables for mapping kernel VM */
165 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
166 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
167 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
168
169 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
170
171 /* Prototypes */
172
173 void consinit(void);
174
175 #include "com.h"
176 #if NCOM > 0
177 #include <dev/ic/comreg.h>
178 #include <dev/ic/comvar.h>
179 #endif
180
181 /*
182 * Define the default console speed for the board. This is generally
183 * what the firmware provided with the board defaults to.
184 */
185 #ifndef CONSPEED
186 #define CONSPEED B115200
187 #endif /* ! CONSPEED */
188
189 #ifndef CONUNIT
190 #define CONUNIT 0
191 #endif
192
193 #ifndef CONMODE
194 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
195 #endif
196
197 int comcnspeed = CONSPEED;
198 int comcnmode = CONMODE;
199 int comcnunit = CONUNIT;
200
201 #if KGDB
202 #ifndef KGDB_DEVNAME
203 #error Must define KGDB_DEVNAME
204 #endif
205 const char kgdb_devname[] = KGDB_DEVNAME;
206
207 #ifndef KGDB_DEVADDR
208 #error Must define KGDB_DEVADDR
209 #endif
210 unsigned long kgdb_devaddr = KGDB_DEVADDR;
211
212 #ifndef KGDB_DEVRATE
213 #define KGDB_DEVRATE CONSPEED
214 #endif
215 int kgdb_devrate = KGDB_DEVRATE;
216
217 #ifndef KGDB_DEVMODE
218 #define KGDB_DEVMODE CONMODE
219 #endif
220 int kgdb_devmode = KGDB_DEVMODE;
221 #endif /* KGDB */
222
223 /*
224 * void cpu_reboot(int howto, char *bootstr)
225 *
226 * Reboots the system
227 *
228 * Deal with any syncing, unmounting, dumping and shutdown hooks,
229 * then reset the CPU.
230 */
231 void
232 cpu_reboot(int howto, char *bootstr)
233 {
234
235 /*
236 * If we are still cold then hit the air brakes
237 * and crash to earth fast
238 */
239 if (cold) {
240 doshutdownhooks();
241 pmf_system_shutdown(boothowto);
242 printf("The operating system has halted.\n");
243 printf("Please press any key to reboot.\n\n");
244 cngetc();
245 printf("rebooting...\n");
246 goto reset;
247 }
248
249 /* Disable console buffering */
250
251 /*
252 * If RB_NOSYNC was not specified sync the discs.
253 * Note: Unless cold is set to 1 here, syslogd will die during the
254 * unmount. It looks like syslogd is getting woken up only to find
255 * that it cannot page part of the binary in as the filesystem has
256 * been unmounted.
257 */
258 if (!(howto & RB_NOSYNC))
259 bootsync();
260
261 /* Say NO to interrupts */
262 splhigh();
263
264 /* Do a dump if requested. */
265 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
266 dumpsys();
267
268 /* Run any shutdown hooks */
269 doshutdownhooks();
270
271 pmf_system_shutdown(boothowto);
272
273 /* Make sure IRQ's are disabled */
274 IRQdisable;
275
276 if (howto & RB_HALT) {
277 printf("The operating system has halted.\n");
278 printf("Please press any key to reboot.\n\n");
279 cngetc();
280 }
281
282 printf("rebooting...\n\r");
283 reset:
284 /*
285 * Make really really sure that all interrupts are disabled,
286 * and poke the Internal Bus and Peripheral Bus reset lines.
287 */
288 (void) disable_interrupts(I32_bit|F32_bit);
289 *(volatile uint32_t *)(IQ80321_80321_VBASE + VERDE_ATU_BASE +
290 ATU_PCSR) = PCSR_RIB | PCSR_RPB;
291
292 /* ...and if that didn't work, just croak. */
293 printf("RESET FAILED!\n");
294 for (;;);
295 }
296
297 /* Static device mappings. */
298 static const struct pmap_devmap iq80321_devmap[] = {
299 /*
300 * Map the on-board devices VA == PA so that we can access them
301 * with the MMU on or off.
302 */
303 {
304 IQ80321_OBIO_BASE,
305 IQ80321_OBIO_BASE,
306 IQ80321_OBIO_SIZE,
307 VM_PROT_READ|VM_PROT_WRITE,
308 PTE_NOCACHE,
309 },
310
311 {
312 IQ80321_IOW_VBASE,
313 VERDE_OUT_XLATE_IO_WIN0_BASE,
314 VERDE_OUT_XLATE_IO_WIN_SIZE,
315 VM_PROT_READ|VM_PROT_WRITE,
316 PTE_NOCACHE,
317 },
318
319 {
320 IQ80321_80321_VBASE,
321 VERDE_PMMR_BASE,
322 VERDE_PMMR_SIZE,
323 VM_PROT_READ|VM_PROT_WRITE,
324 PTE_NOCACHE,
325 },
326
327 {
328 0,
329 0,
330 0,
331 0,
332 0,
333 }
334 };
335
336 /*
337 * u_int initarm(...)
338 *
339 * Initial entry point on startup. This gets called before main() is
340 * entered.
341 * It should be responsible for setting up everything that must be
342 * in place when main is called.
343 * This includes
344 * Taking a copy of the boot configuration structure.
345 * Initialising the physical console so characters can be printed.
346 * Setting up page tables for the kernel
347 * Relocating the kernel to the bottom of physical memory
348 */
349 u_int
350 initarm(void *arg)
351 {
352 extern vaddr_t xscale_cache_clean_addr;
353 #ifdef DIAGNOSTIC
354 extern vsize_t xscale_minidata_clean_size;
355 #endif
356 int loop;
357 int loop1;
358 u_int l1pagetable;
359 paddr_t memstart;
360 psize_t memsize;
361
362 /* Calibrate the delay loop. */
363 i80321_calibrate_delay();
364 i80321_hardclock_hook = NULL;
365
366 /*
367 * Since we map the on-board devices VA==PA, and the kernel
368 * is running VA==PA, it's possible for us to initialize
369 * the console now.
370 */
371 consinit();
372
373 #ifdef VERBOSE_INIT_ARM
374 /* Talk to the user */
375 printf("\nNetBSD/evbarm (NPWR_FC) booting ...\n");
376 #endif
377
378 /*
379 * Heads up ... Setup the CPU / MMU / TLB functions
380 */
381 if (set_cpufuncs())
382 panic("cpu not recognized!");
383
384 /*
385 * We are currently running with the MMU enabled and the
386 * entire address space mapped VA==PA, except for the
387 * first 64M of RAM is also double-mapped at 0xc0000000.
388 * There is an L1 page table at 0xa0004000.
389 */
390
391 /*
392 * Fetch the SDRAM start/size from the i80321 SDRAM configration
393 * registers.
394 */
395 i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
396 &memstart, &memsize);
397
398 #ifdef VERBOSE_INIT_ARM
399 printf("initarm: Configuring system ...\n");
400 #endif
401
402 /* Fake bootconfig structure for the benefit of pmap.c */
403 /* XXX must make the memory description h/w independent */
404 bootconfig.dramblocks = 1;
405 bootconfig.dram[0].address = memstart;
406 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
407
408 /*
409 * Set up the variables that define the availablilty of
410 * physical memory. For now, we're going to set
411 * physical_freestart to 0xa0200000 (where the kernel
412 * was loaded), and allocate the memory we need downwards.
413 * If we get too close to the L1 table that we set up, we
414 * will panic. We will update physical_freestart and
415 * physical_freeend later to reflect what pmap_bootstrap()
416 * wants to see.
417 *
418 * XXX pmap_bootstrap() needs an enema.
419 */
420 physical_start = bootconfig.dram[0].address;
421 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
422
423 physical_freestart = 0xa0009000UL;
424 physical_freeend = 0xa0200000UL;
425
426 physmem = (physical_end - physical_start) / PAGE_SIZE;
427
428 #ifdef VERBOSE_INIT_ARM
429 /* Tell the user about the memory */
430 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
431 physical_start, physical_end - 1);
432 #endif
433
434 /*
435 * Okay, the kernel starts 2MB in from the bottom of physical
436 * memory. We are going to allocate our bootstrap pages downwards
437 * from there.
438 *
439 * We need to allocate some fixed page tables to get the kernel
440 * going. We allocate one page directory and a number of page
441 * tables and store the physical addresses in the kernel_pt_table
442 * array.
443 *
444 * The kernel page directory must be on a 16K boundary. The page
445 * tables must be on 4K bounaries. What we do is allocate the
446 * page directory on the first 16K boundary that we encounter, and
447 * the page tables on 4K boundaries otherwise. Since we allocate
448 * at least 3 L2 page tables, we are guaranteed to encounter at
449 * least one 16K aligned region.
450 */
451
452 #ifdef VERBOSE_INIT_ARM
453 printf("Allocating page tables\n");
454 #endif
455
456 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
457
458 #ifdef VERBOSE_INIT_ARM
459 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
460 physical_freestart, free_pages, free_pages);
461 #endif
462
463 /* Define a macro to simplify memory allocation */
464 #define valloc_pages(var, np) \
465 alloc_pages((var).pv_pa, (np)); \
466 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
467
468 #define alloc_pages(var, np) \
469 physical_freeend -= ((np) * PAGE_SIZE); \
470 if (physical_freeend < physical_freestart) \
471 panic("initarm: out of memory"); \
472 (var) = physical_freeend; \
473 free_pages -= (np); \
474 memset((char *)(var), 0, ((np) * PAGE_SIZE));
475
476 loop1 = 0;
477 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
478 /* Are we 16KB aligned for an L1 ? */
479 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
480 && kernel_l1pt.pv_pa == 0) {
481 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
482 } else {
483 valloc_pages(kernel_pt_table[loop1],
484 L2_TABLE_SIZE / PAGE_SIZE);
485 ++loop1;
486 }
487 }
488
489 /* This should never be able to happen but better confirm that. */
490 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
491 panic("initarm: Failed to align the kernel page directory");
492
493 /*
494 * Allocate a page for the system page mapped to V0x00000000
495 * This page will just contain the system vectors and can be
496 * shared by all processes.
497 */
498 alloc_pages(systempage.pv_pa, 1);
499
500 /* Allocate stacks for all modes */
501 valloc_pages(irqstack, IRQ_STACK_SIZE);
502 valloc_pages(abtstack, ABT_STACK_SIZE);
503 valloc_pages(undstack, UND_STACK_SIZE);
504 valloc_pages(kernelstack, UPAGES);
505
506 /* Allocate enough pages for cleaning the Mini-Data cache. */
507 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
508 valloc_pages(minidataclean, 1);
509
510 #ifdef VERBOSE_INIT_ARM
511 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
512 irqstack.pv_va);
513 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
514 abtstack.pv_va);
515 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
516 undstack.pv_va);
517 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
518 kernelstack.pv_va);
519 #endif
520
521 /*
522 * XXX Defer this to later so that we can reclaim the memory
523 * XXX used by the RedBoot page tables.
524 */
525 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
526
527 /*
528 * Ok we have allocated physical pages for the primary kernel
529 * page tables
530 */
531
532 #ifdef VERBOSE_INIT_ARM
533 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
534 #endif
535
536 /*
537 * Now we start construction of the L1 page table
538 * We start by mapping the L2 page tables into the L1.
539 * This means that we can replace L1 mappings later on if necessary
540 */
541 l1pagetable = kernel_l1pt.pv_pa;
542
543 /* Map the L2 pages tables in the L1 page table */
544 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
545 &kernel_pt_table[KERNEL_PT_SYS]);
546 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
547 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
548 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
549 pmap_link_l2pt(l1pagetable, IQ80321_IOPXS_VBASE,
550 &kernel_pt_table[KERNEL_PT_IOPXS]);
551 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
552 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
553 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
554
555 /* update the top of the kernel VM */
556 pmap_curmaxkvaddr =
557 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
558
559 #ifdef VERBOSE_INIT_ARM
560 printf("Mapping kernel\n");
561 #endif
562
563 /* Now we fill in the L2 pagetable for the kernel static code/data */
564 {
565 extern char etext[], _end[];
566 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
567 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
568 u_int logical;
569
570 textsize = (textsize + PGOFSET) & ~PGOFSET;
571 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
572
573 logical = 0x00200000; /* offset of kernel in RAM */
574
575 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
576 physical_start + logical, textsize,
577 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
578 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
579 physical_start + logical, totalsize - textsize,
580 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
581 }
582
583 #ifdef VERBOSE_INIT_ARM
584 printf("Constructing L2 page tables\n");
585 #endif
586
587 /* Map the stack pages */
588 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
589 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
590 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
591 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
592 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
593 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
594 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
595 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
596
597 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
598 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
599
600 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
601 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
602 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
603 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
604 }
605
606 /* Map the Mini-Data cache clean area. */
607 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
608 minidataclean.pv_pa);
609
610 /* Map the vector page. */
611 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
612 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
613
614 /* Map the statically mapped devices. */
615 pmap_devmap_bootstrap(l1pagetable, iq80321_devmap);
616
617 /*
618 * Give the XScale global cache clean code an appropriately
619 * sized chunk of unmapped VA space starting at 0xff000000
620 * (our device mappings end before this address).
621 */
622 xscale_cache_clean_addr = 0xff000000U;
623
624 /*
625 * Now we have the real page tables in place so we can switch to them.
626 * Once this is done we will be running with the REAL kernel page
627 * tables.
628 */
629
630 /*
631 * Update the physical_freestart/physical_freeend/free_pages
632 * variables.
633 */
634 {
635 extern char _end[];
636
637 physical_freestart = physical_start +
638 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
639 KERNEL_BASE);
640 physical_freeend = physical_end;
641 free_pages =
642 (physical_freeend - physical_freestart) / PAGE_SIZE;
643 }
644
645 /* Switch tables */
646 #ifdef VERBOSE_INIT_ARM
647 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
648 physical_freestart, free_pages, free_pages);
649 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
650 #endif
651 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
652 cpu_setttb(kernel_l1pt.pv_pa, true);
653 cpu_tlb_flushID();
654 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
655
656 /*
657 * Moved from cpu_startup() as data_abort_handler() references
658 * this during uvm init
659 */
660 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
661
662 #ifdef VERBOSE_INIT_ARM
663 printf("done!\n");
664 #endif
665
666 #ifdef VERBOSE_INIT_ARM
667 printf("bootstrap done.\n");
668 #endif
669
670 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
671
672 /*
673 * Pages were allocated during the secondary bootstrap for the
674 * stacks for different CPU modes.
675 * We must now set the r13 registers in the different CPU modes to
676 * point to these stacks.
677 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
678 * of the stack memory.
679 */
680 #ifdef VERBOSE_INIT_ARM
681 printf("init subsystems: stacks ");
682 #endif
683
684 set_stackptr(PSR_IRQ32_MODE,
685 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
686 set_stackptr(PSR_ABT32_MODE,
687 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
688 set_stackptr(PSR_UND32_MODE,
689 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
690
691 /*
692 * Well we should set a data abort handler.
693 * Once things get going this will change as we will need a proper
694 * handler.
695 * Until then we will use a handler that just panics but tells us
696 * why.
697 * Initialisation of the vectors will just panic on a data abort.
698 * This just fills in a slighly better one.
699 */
700 #ifdef VERBOSE_INIT_ARM
701 printf("vectors ");
702 #endif
703 data_abort_handler_address = (u_int)data_abort_handler;
704 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
705 undefined_handler_address = (u_int)undefinedinstruction_bounce;
706
707 /* Initialise the undefined instruction handlers */
708 #ifdef VERBOSE_INIT_ARM
709 printf("undefined ");
710 #endif
711 undefined_init();
712
713 /* Load memory into UVM. */
714 #ifdef VERBOSE_INIT_ARM
715 printf("page ");
716 #endif
717 uvm_md_init();
718 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
719 atop(physical_freestart), atop(physical_freeend),
720 VM_FREELIST_DEFAULT);
721
722 /* Boot strap pmap telling it where the kernel page table is */
723 #ifdef VERBOSE_INIT_ARM
724 printf("pmap ");
725 #endif
726 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
727
728 /* Setup the IRQ system */
729 #ifdef VERBOSE_INIT_ARM
730 printf("irq ");
731 #endif
732 i80321_intr_init();
733
734 #ifdef VERBOSE_INIT_ARM
735 printf("done.\n");
736 #endif
737
738 #ifdef BOOTHOWTO
739 boothowto = BOOTHOWTO;
740 #endif
741
742 #ifdef DDB
743 db_machine_init();
744 if (boothowto & RB_KDB)
745 Debugger();
746 #endif
747
748 /* We return the new stack pointer address */
749 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
750 }
751
752 void
753 consinit(void)
754 {
755 static const bus_addr_t comcnaddrs[] = {
756 IQ80321_UART1, /* com0 */
757 };
758 static int consinit_called;
759
760 if (consinit_called != 0)
761 return;
762
763 consinit_called = 1;
764
765 /*
766 * Console devices are mapped VA==PA. Our devmap reflects
767 * this, so register it now so drivers can map the console
768 * device.
769 */
770 pmap_devmap_register(iq80321_devmap);
771
772 #if NCOM > 0
773 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
774 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
775 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
776 #else
777 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
778 #endif
779 #if KGDB
780 #if NCOM > 0
781 if (strcmp(kgdb_devname, "com") == 0) {
782 com_kgdb_attach(&obio_bs_tag, kgdb_devaddr, kgdb_devrate,
783 COM_FREQ, COM_TYPE_NORMAL, kgdb_devmode);
784 }
785 #endif /* NCOM > 0 */
786 #endif /* KGDB */
787 }
788