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