iq80310_machdep.c revision 1.93 1 /* $NetBSD: iq80310_machdep.c,v 1.93 2020/04/18 11:00:39 skrll 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.93 2020/04/18 11:00:39 skrll Exp $");
77
78 #include "opt_arm_debug.h"
79 #include "opt_console.h"
80 #include "opt_ddb.h"
81
82 #include <sys/param.h>
83 #include <sys/device.h>
84 #include <sys/systm.h>
85 #include <sys/kernel.h>
86 #include <sys/exec.h>
87 #include <sys/proc.h>
88 #include <sys/msgbuf.h>
89 #include <sys/reboot.h>
90 #include <sys/termios.h>
91 #include <sys/ksyms.h>
92 #include <sys/bus.h>
93 #include <sys/cpu.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 <arm/locore.h>
105 #include <arm/undefined.h>
106
107 #include <arm/arm32/machdep.h>
108
109 #include <arm/xscale/i80312reg.h>
110 #include <arm/xscale/i80312var.h>
111
112 #include <dev/pci/ppbreg.h>
113
114 #include <evbarm/iq80310/iq80310reg.h>
115 #include <evbarm/iq80310/iq80310var.h>
116 #include <evbarm/iq80310/obiovar.h>
117
118 #include "ksyms.h"
119
120 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
121 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
122 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
123
124 /*
125 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
126 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
127 */
128 #define KERNEL_VM_SIZE 0x0C000000
129
130 BootConfig bootconfig; /* Boot config storage */
131 char *boot_args = NULL;
132 char *boot_file = NULL;
133
134 vaddr_t physical_start;
135 vaddr_t physical_freestart;
136 vaddr_t physical_freeend;
137 vaddr_t physical_end;
138 u_int free_pages;
139
140 /*int debug_flags;*/
141 #ifndef PMAP_STATIC_L1S
142 int max_processes = 64; /* Default number */
143 #endif /* !PMAP_STATIC_L1S */
144
145 pv_addr_t minidataclean;
146
147 paddr_t msgbufphys;
148
149 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
150
151 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
152 #define KERNEL_PT_KERNEL_NUM 4
153
154 /* L2 table for mapping i80312 */
155 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
156
157 /* L2 tables for mapping kernel VM */
158 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
159 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
160 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
161
162 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
163
164 /* Prototypes */
165
166 void consinit(void);
167
168 #include "com.h"
169 #if NCOM > 0
170 #include <dev/ic/comreg.h>
171 #include <dev/ic/comvar.h>
172 #endif
173
174 /*
175 * Define the default console speed for the board. This is generally
176 * what the firmware provided with the board defaults to.
177 */
178 #ifndef CONSPEED
179 #define CONSPEED B115200
180 #endif /* ! CONSPEED */
181
182 #ifndef CONUNIT
183 #define CONUNIT 0
184 #endif
185
186 #ifndef CONMODE
187 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
188 #endif
189
190 int comcnspeed = CONSPEED;
191 int comcnmode = CONMODE;
192 int comcnunit = CONUNIT;
193
194 /*
195 * void cpu_reboot(int howto, char *bootstr)
196 *
197 * Reboots the system
198 *
199 * Deal with any syncing, unmounting, dumping and shutdown hooks,
200 * then reset the CPU.
201 */
202 void
203 cpu_reboot(int howto, char *bootstr)
204 {
205
206 /*
207 * If we are still cold then hit the air brakes
208 * and crash to earth fast
209 */
210 if (cold) {
211 doshutdownhooks();
212 pmf_system_shutdown(boothowto);
213 printf("The operating system has halted.\n");
214 printf("Please press any key to reboot.\n\n");
215 cngetc();
216 printf("rebooting...\n");
217 cpu_reset();
218 /*NOTREACHED*/
219 }
220
221 /* Disable console buffering */
222
223 /*
224 * If RB_NOSYNC was not specified sync the discs.
225 * Note: Unless cold is set to 1 here, syslogd will die during the
226 * unmount. It looks like syslogd is getting woken up only to find
227 * that it cannot page part of the binary in as the filesystem has
228 * been unmounted.
229 */
230 if (!(howto & RB_NOSYNC))
231 bootsync();
232
233 /* Say NO to interrupts */
234 splhigh();
235
236 /* Do a dump if requested. */
237 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
238 dumpsys();
239
240 /* Run any shutdown hooks */
241 doshutdownhooks();
242
243 pmf_system_shutdown(boothowto);
244
245 /* Make sure IRQ's are disabled */
246 IRQdisable;
247
248 if (howto & RB_HALT) {
249 iq80310_7seg('.', '.');
250 printf("The operating system has halted.\n");
251 printf("Please press any key to reboot.\n\n");
252 cngetc();
253 }
254
255 printf("rebooting...\n");
256 cpu_reset();
257 /*NOTREACHED*/
258 }
259
260 /* Static device mappings. */
261 static const struct pmap_devmap iq80310_devmap[] = {
262 /*
263 * Map the on-board devices VA == PA so that we can access them
264 * with the MMU on or off.
265 */
266 {
267 IQ80310_OBIO_BASE,
268 IQ80310_OBIO_BASE,
269 IQ80310_OBIO_SIZE,
270 VM_PROT_READ|VM_PROT_WRITE,
271 PTE_NOCACHE,
272 },
273 {
274 IQ80310_PIOW_VBASE,
275 I80312_PCI_XLATE_PIOW_BASE,
276 I80312_PCI_XLATE_IOSIZE,
277 VM_PROT_READ|VM_PROT_WRITE,
278 PTE_NOCACHE,
279 },
280 {
281 IQ80310_SIOW_VBASE,
282 I80312_PCI_XLATE_SIOW_BASE,
283 I80312_PCI_XLATE_IOSIZE,
284 VM_PROT_READ|VM_PROT_WRITE,
285 PTE_NOCACHE,
286 },
287 {
288 IQ80310_80312_VBASE,
289 I80312_PMMR_BASE,
290 I80312_PMMR_SIZE,
291 VM_PROT_READ|VM_PROT_WRITE,
292 PTE_NOCACHE,
293 },
294
295 {
296 0,
297 0,
298 0,
299 0,
300 0,
301 }
302 };
303
304 /*
305 * vaddr_t initarm(...)
306 *
307 * Initial entry point on startup. This gets called before main() is
308 * entered.
309 * It should be responsible for setting up everything that must be
310 * in place when main is called.
311 * This includes
312 * Taking a copy of the boot configuration structure.
313 * Initialising the physical console so characters can be printed.
314 * Setting up page tables for the kernel
315 * Relocating the kernel to the bottom of physical memory
316 */
317 vaddr_t
318 initarm(void *arg)
319 {
320 extern vaddr_t xscale_cache_clean_addr;
321 #ifdef DIAGNOSTIC
322 extern vsize_t xscale_minidata_clean_size;
323 #endif
324 int loop;
325 int loop1;
326 u_int l1pagetable;
327 paddr_t memstart;
328 psize_t memsize;
329
330 /*
331 * Clear out the 7-segment display. Whee, the first visual
332 * indication that we're running kernel code.
333 */
334 iq80310_7seg(' ', ' ');
335
336 /*
337 * Heads up ... Setup the CPU / MMU / TLB functions
338 */
339 if (set_cpufuncs())
340 panic("CPU not recognized!");
341
342 /* Calibrate the delay loop. */
343 iq80310_calibrate_delay();
344
345 /*
346 * Since we map the on-board devices VA==PA, and the kernel
347 * is running VA==PA, it's possible for us to initialize
348 * the console now.
349 */
350 consinit();
351
352 #ifdef VERBOSE_INIT_ARM
353 /* Talk to the user */
354 printf("\nNetBSD/evbarm (IQ80310) booting ...\n");
355 #endif
356
357 /*
358 * Reset the secondary PCI bus. RedBoot doesn't stop devices
359 * on the PCI bus before handing us control, so we have to
360 * do this.
361 *
362 * XXX This is arguably a bug in RedBoot, and doing this reset
363 * XXX could be problematic in the future if we encounter an
364 * XXX application where the PPB in the i80312 is used as a
365 * XXX PPB.
366 */
367 {
368 uint32_t reg;
369
370 #ifdef VERBOSE_INIT_ARM
371 printf("Resetting secondary PCI bus...\n");
372 #endif
373 reg = bus_space_read_4(&obio_bs_tag,
374 I80312_PMMR_BASE + I80312_PPB_BASE, PCI_BRIDGE_CONTROL_REG);
375 bus_space_write_4(&obio_bs_tag,
376 I80312_PMMR_BASE + I80312_PPB_BASE, PCI_BRIDGE_CONTROL_REG,
377 reg | PCI_BRIDGE_CONTROL_SECBR);
378 delay(10 * 1000); /* 10ms enough? */
379 bus_space_write_4(&obio_bs_tag,
380 I80312_PMMR_BASE + I80312_PPB_BASE, PCI_BRIDGE_CONTROL_REG,
381 reg);
382 }
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 i80312 SDRAM configuration
393 * registers.
394 */
395 i80312_sdram_bounds(&obio_bs_tag, I80312_PMMR_BASE + I80312_MEM_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 boundaries. 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, IQ80310_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, iq80310_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 slightly 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 managed kernel virtual memory 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 iq80310_intr_init();
733
734 #ifdef VERBOSE_INIT_ARM
735 printf("done.\n");
736 #endif
737
738 #ifdef DDB
739 db_machine_init();
740 if (boothowto & RB_KDB)
741 Debugger();
742 #endif
743
744 /* We return the new stack pointer address */
745 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
746 }
747
748 void
749 consinit(void)
750 {
751 static const bus_addr_t comcnaddrs[] = {
752 IQ80310_UART2, /* com0 (J9) */
753 IQ80310_UART1, /* com1 (J10) */
754 };
755 static int consinit_called;
756
757 if (consinit_called != 0)
758 return;
759
760 consinit_called = 1;
761
762 /*
763 * Console devices are mapped VA==PA. Our devmap reflects
764 * this, so register it now so drivers can map the console
765 * device.
766 */
767 pmap_devmap_register(iq80310_devmap);
768
769 #if NCOM > 0
770 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
771 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
772 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
773 #else
774 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
775 #endif
776 }
777