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