smdk2800_machdep.c revision 1.43.16.3 1 /* $NetBSD: smdk2800_machdep.c,v 1.43.16.3 2020/04/21 18:42:07 martin Exp $ */
2
3 /*
4 * Copyright (c) 2002, 2003, 2005 Fujitsu Component Limited
5 * Copyright (c) 2002, 2003, 2005 Genetec Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of The Fujitsu Component Limited nor the name of
17 * Genetec corporation may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21 * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25 * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 /*
36 * Copyright (c) 2001,2002 ARM Ltd
37 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. The name of the company may not be used to endorse or promote
48 * products derived from this software without specific prior written
49 * permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
53 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
54 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD
55 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
56 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
57 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
59 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
61 * POSSIBILITY OF SUCH DAMAGE.
62 *
63 */
64
65 /*
66 * Copyright (c) 1997,1998 Mark Brinicombe.
67 * Copyright (c) 1997,1998 Causality Limited.
68 * All rights reserved.
69 *
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
72 * are met:
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. All advertising materials mentioning features or use of this software
79 * must display the following acknowledgement:
80 * This product includes software developed by Mark Brinicombe
81 * for the NetBSD Project.
82 * 4. The name of the company nor the name of the author may be used to
83 * endorse or promote products derived from this software without specific
84 * prior written permission.
85 *
86 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
87 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
88 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
89 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
90 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
91 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
92 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
93 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
94 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
95 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
96 * SUCH DAMAGE.
97 *
98 * Machine dependent functions for kernel setup for integrator board
99 *
100 * Created : 24/11/97
101 */
102
103 /*
104 * Machine dependent functions for kernel setup for Samsung SMDK2800
105 * derived from integrator_machdep.c
106 */
107
108 #include <sys/cdefs.h>
109 __KERNEL_RCSID(0, "$NetBSD: smdk2800_machdep.c,v 1.43.16.3 2020/04/21 18:42:07 martin Exp $");
110
111 #include "opt_ddb.h"
112 #include "opt_console.h"
113 #include "opt_kgdb.h"
114 #include "opt_md.h"
115 #include "pci.h"
116
117 #include <sys/param.h>
118 #include <sys/device.h>
119 #include <sys/systm.h>
120 #include <sys/kernel.h>
121 #include <sys/exec.h>
122 #include <sys/proc.h>
123 #include <sys/msgbuf.h>
124 #include <sys/reboot.h>
125 #include <sys/termios.h>
126 #include <sys/ksyms.h>
127 #include <sys/bus.h>
128 #include <sys/cpu.h>
129 #include <sys/intr.h>
130
131 #include <uvm/uvm_extern.h>
132
133 #include <dev/cons.h>
134 #include <dev/md.h>
135
136 #include <machine/db_machdep.h>
137 #include <ddb/db_sym.h>
138 #include <ddb/db_extern.h>
139 #ifdef KGDB
140 #include <sys/kgdb.h>
141 #endif
142
143 #include <machine/bootconfig.h>
144 #include <arm/locore.h>
145 #include <arm/undefined.h>
146
147 #include <arm/arm32/machdep.h>
148
149 #include <arm/s3c2xx0/s3c2800reg.h>
150 #include <arm/s3c2xx0/s3c2800var.h>
151 #include <evbarm/smdk2xx0/smdk2800var.h>
152
153 #include "ksyms.h"
154
155 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
156 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
157 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
158
159 /*
160 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
161 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
162 */
163 #define KERNEL_VM_SIZE 0x0C000000
164
165 /* Memory disk support */
166 #if defined(MEMORY_DISK_DYNAMIC) && defined(MEMORY_DISK_ROOT_ADDR)
167 #define DO_MEMORY_DISK
168 /* We have memory disk image outside of the kernel on ROM. */
169 #ifdef MEMORY_DISK_ROOT_ROM
170 /* map the image directory and use read-only */
171 #else
172 /* copy the image to RAM */
173 #endif
174 #endif
175
176 BootConfig bootconfig; /* Boot config storage */
177 char *boot_args = NULL;
178 char *boot_file = NULL;
179
180 vaddr_t physical_start;
181 vaddr_t physical_freestart;
182 vaddr_t physical_freeend;
183 vaddr_t physical_end;
184 u_int free_pages;
185
186 /*int debug_flags;*/
187 #ifndef PMAP_STATIC_L1S
188 int max_processes = 64; /* Default number */
189 #endif /* !PMAP_STATIC_L1S */
190
191 paddr_t msgbufphys;
192
193 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
194 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
195 #define KERNEL_PT_KERNEL_NUM 2 /* L2 tables for mapping kernel VM */
196
197 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
198
199 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
200 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
201
202 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
203
204 /* Prototypes */
205
206 void consinit(void);
207 void kgdb_port_init(void);
208
209 /* A load of console goo. */
210 #include "vga.h"
211 #if NVGA > 0
212 #include <dev/ic/mc6845reg.h>
213 #include <dev/ic/pcdisplayvar.h>
214 #include <dev/ic/vgareg.h>
215 #include <dev/ic/vgavar.h>
216 #endif
217
218 #include "com.h"
219 #if NCOM > 0
220 #include <dev/ic/comreg.h>
221 #include <dev/ic/comvar.h>
222 #endif
223
224 #include "sscom.h"
225 #if NSSCOM > 0
226 #include "opt_sscom.h"
227 #include <arm/s3c2xx0/sscom_var.h>
228 #endif
229
230 /*
231 * Define the default console speed for the board. This is generally
232 * what the firmware provided with the board defaults to.
233 */
234 #ifndef CONSPEED
235 #define CONSPEED B115200 /* TTYDEF_SPEED */
236 #endif
237 #ifndef CONMODE
238 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
239 #endif
240
241 int comcnspeed = CONSPEED;
242 int comcnmode = CONMODE;
243
244 /*
245 * void cpu_reboot(int howto, char *bootstr)
246 *
247 * Reboots the system
248 *
249 * Deal with any syncing, unmounting, dumping and shutdown hooks,
250 * then reset the CPU.
251 */
252 void
253 cpu_reboot(int howto, char *bootstr)
254 {
255
256 cpu_reset_address_paddr = vtophys((u_int)s3c2800_softreset);
257
258 /*
259 * If we are still cold then hit the air brakes
260 * and crash to earth fast
261 */
262 if (cold) {
263 doshutdownhooks();
264 pmf_system_shutdown(boothowto);
265 printf("The operating system has halted.\n");
266 printf("Please press any key to reboot.\n\n");
267 cngetc();
268 printf("rebooting...\n");
269 cpu_reset();
270 /* NOTREACHED */
271 }
272 /* Disable console buffering */
273
274 /*
275 * If RB_NOSYNC was not specified sync the discs.
276 * Note: Unless cold is set to 1 here, syslogd will die during the
277 * unmount. It looks like syslogd is getting woken up only to find
278 * that it cannot page part of the binary in as the filesystem has
279 * been unmounted.
280 */
281 if (!(howto & RB_NOSYNC))
282 bootsync();
283
284 /* Say NO to interrupts */
285 splhigh();
286
287 /* Do a dump if requested. */
288 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
289 dumpsys();
290
291 /* Run any shutdown hooks */
292 doshutdownhooks();
293
294 pmf_system_shutdown(boothowto);
295
296 /* Make sure IRQ's are disabled */
297 IRQdisable;
298
299 if (howto & RB_HALT) {
300 printf("The operating system has halted.\n");
301 printf("Please press any key to reboot.\n\n");
302 cngetc();
303 }
304 printf("rebooting...\n");
305 cpu_reset();
306 /* NOTREACHED */
307 }
308
309 /*
310 * All built-in peripheral registers are statically mapped in start up
311 * routine. This table tells pmap subsystem about it, and to map them
312 * at the same position.
313 */
314 static const struct pmap_devmap smdk2800_devmap[] = {
315 {
316 SMDK2800_IO_AREA_VBASE,
317 S3C2800_PERIPHERALS,
318 S3C2800_PERIPHERALS_SIZE,
319 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
320 },
321 { 0, 0, 0, 0 }
322 };
323
324 #define ioreg_vaddr(pa) ((pa) - S3C2800_PERIPHERALS + SMDK2800_IO_AREA_VBASE)
325 #define ioreg32(pa) (*(volatile uint32_t *)ioreg_vaddr(pa))
326
327 /*
328 * vaddr_t initarm(...)
329 *
330 * Initial entry point on startup. This gets called before main() is
331 * entered.
332 * It should be responsible for setting up everything that must be
333 * in place when main is called.
334 * This includes
335 * Taking a copy of the boot configuration structure.
336 * Initialising the physical console so characters can be printed.
337 * Setting up page tables for the kernel
338 * Relocating the kernel to the bottom of physical memory
339 */
340
341 vaddr_t
342 initarm(void *arg)
343 {
344 int loop;
345 int loop1;
346 u_int l1pagetable;
347 extern int etext __asm("_etext");
348 extern int end __asm("_end");
349 int progress_counter = 0;
350
351 #ifdef DO_MEMORY_DISK
352 vaddr_t md_root_start;
353 #define MD_ROOT_SIZE (MEMORY_DISK_ROOT_SIZE * DEV_BSIZE)
354 #endif
355
356 #define gpio8(reg) (*(volatile uint8_t *)(ioreg_vaddr(S3C2800_GPIO_BASE) + (reg)))
357
358 #define LEDSTEP() __LED(progress_counter++)
359
360 #define pdatc gpio8(GPIO_PDATC)
361 #define __LED(x) (pdatc = (pdatc & ~0x07) | (~(x) & 0x07))
362
363 LEDSTEP();
364 /*
365 * Heads up ... Setup the CPU / MMU / TLB functions
366 */
367 if (set_cpufuncs())
368 panic("CPU not recognized!");
369
370 LEDSTEP();
371
372
373 /* Disable all peripheral interrupts */
374 ioreg32(S3C2800_INTCTL_BASE + INTCTL_INTMSK) = 0;
375
376 consinit();
377 #ifdef VERBOSE_INIT_ARM
378 printf("consinit done\n");
379 #endif
380
381 #ifdef KGDB
382 LEDSTEP();
383 kgdb_port_init();
384 #endif
385 LEDSTEP();
386
387 #ifdef VERBOSE_INIT_ARM
388 /* Talk to the user */
389 printf("\nNetBSD/evbarm (SMDK2800) booting ...\n");
390 #endif
391
392 /*
393 * Ok we have the following memory map
394 *
395 * Physical Address Range Description
396 * ----------------------- ----------------------------------
397 * 0x00000000 - 0x00ffffff Intel flash Memory (16MB)
398 * 0x02000000 - 0x020fffff AMD flash Memory (1MB)
399 * or (depend on DIPSW setting)
400 * 0x00000000 - 0x000fffff AMD flash Memory (1MB)
401 * 0x02000000 - 0x02ffffff Intel flash Memory (16MB)
402 *
403 * 0x08000000 - 0x09ffffff SDRAM (32MB)
404 * 0x20000000 - 0x3fffffff PCI space
405 *
406 * The initarm() has the responsibility for creating the kernel
407 * page tables.
408 * It must also set up various memory pointers that are used
409 * by pmap etc.
410 */
411
412 /* Fake bootconfig structure for the benefit of pmap.c */
413 /* XXX must make the memory description h/w independent */
414 bootconfig.dramblocks = 1;
415 bootconfig.dram[0].address = SDRAM_START;
416 bootconfig.dram[0].pages = SDRAM_SIZE / PAGE_SIZE;
417
418 /*
419 * Set up the variables that define the availablilty of
420 * physical memory. For now, we're going to set
421 * physical_freestart to 0x08200000 (where the kernel
422 * was loaded), and allocate the memory we need downwards.
423 * If we get too close to the bottom of SDRAM, we
424 * will panic. We will update physical_freestart and
425 * physical_freeend later to reflect what pmap_bootstrap()
426 * wants to see.
427 *
428 * XXX pmap_bootstrap() needs an enema.
429 */
430 physical_start = bootconfig.dram[0].address;
431 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
432
433 #if DO_MEMORY_DISK
434 #ifdef MEMORY_DISK_ROOT_ROM
435 md_root_start = MEMORY_DISK_ROOT_ADDR;
436 boothowto |= RB_RDONLY;
437 #else
438 /* Reserve physmem for ram disk */
439 md_root_start = ((physical_end - MD_ROOT_SIZE) & ~(L1_S_SIZE-1));
440 printf("Reserve %ld bytes for memory disk\n",
441 physical_end - md_root_start);
442 /* copy fs contents */
443 memcpy((void *)md_root_start, (void *)MEMORY_DISK_ROOT_ADDR,
444 MD_ROOT_SIZE);
445 physical_end = md_root_start;
446 #endif
447 #endif
448
449 physical_freestart = 0x08000000UL; /* XXX */
450 physical_freeend = 0x08200000UL;
451
452 physmem = (physical_end - physical_start) / PAGE_SIZE;
453
454 #ifdef VERBOSE_INIT_ARM
455 /* Tell the user about the memory */
456 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
457 physical_start, physical_end - 1);
458 #endif
459
460 /*
461 * XXX
462 * Okay, the kernel starts 2MB in from the bottom of physical
463 * memory. We are going to allocate our bootstrap pages downwards
464 * from there.
465 *
466 * We need to allocate some fixed page tables to get the kernel
467 * going. We allocate one page directory and a number of page
468 * tables and store the physical addresses in the kernel_pt_table
469 * array.
470 *
471 * The kernel page directory must be on a 16K boundary. The page
472 * tables must be on 4K boundaries. What we do is allocate the
473 * page directory on the first 16K boundary that we encounter, and
474 * the page tables on 4K boundaries otherwise. Since we allocate
475 * at least 3 L2 page tables, we are guaranteed to encounter at
476 * least one 16K aligned region.
477 */
478
479 #ifdef VERBOSE_INIT_ARM
480 printf("Allocating page tables\n");
481 #endif
482
483 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
484
485 #ifdef VERBOSE_INIT_ARM
486 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
487 physical_freestart, free_pages, free_pages);
488 #endif
489
490 /* Define a macro to simplify memory allocation */
491 #define valloc_pages(var, np) \
492 alloc_pages((var).pv_pa, (np)); \
493 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
494
495 #define alloc_pages(var, np) \
496 physical_freeend -= ((np) * PAGE_SIZE); \
497 if (physical_freeend < physical_freestart) \
498 panic("initarm: out of memory"); \
499 (var) = physical_freeend; \
500 free_pages -= (np); \
501 memset((char *)(var), 0, ((np) * PAGE_SIZE));
502
503 loop1 = 0;
504 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
505 /* Are we 16KB aligned for an L1 ? */
506 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
507 && kernel_l1pt.pv_pa == 0) {
508 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
509 } else {
510 valloc_pages(kernel_pt_table[loop1],
511 L2_TABLE_SIZE / PAGE_SIZE);
512 ++loop1;
513 }
514 }
515
516 /* This should never be able to happen but better confirm that. */
517 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
518 panic("initarm: Failed to align the kernel page directory\n");
519
520 /*
521 * Allocate a page for the system page mapped to V0x00000000
522 * This page will just contain the system vectors and can be
523 * shared by all processes.
524 */
525 alloc_pages(systempage.pv_pa, 1);
526
527 /* Allocate stacks for all modes */
528 valloc_pages(irqstack, IRQ_STACK_SIZE);
529 valloc_pages(abtstack, ABT_STACK_SIZE);
530 valloc_pages(undstack, UND_STACK_SIZE);
531 valloc_pages(kernelstack, UPAGES);
532
533 #ifdef VERBOSE_INIT_ARM
534 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
535 irqstack.pv_va);
536 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
537 abtstack.pv_va);
538 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
539 undstack.pv_va);
540 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
541 kernelstack.pv_va);
542 #endif
543
544 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
545
546 LEDSTEP();
547
548 /*
549 * Ok we have allocated physical pages for the primary kernel
550 * page tables
551 */
552
553 #ifdef VERBOSE_INIT_ARM
554 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
555 #endif
556
557 /*
558 * Now we start construction of the L1 page table
559 * We start by mapping the L2 page tables into the L1.
560 * This means that we can replace L1 mappings later on if necessary
561 */
562 l1pagetable = kernel_l1pt.pv_pa;
563
564 /* Map the L2 pages tables in the L1 page table */
565 pmap_link_l2pt(l1pagetable, 0x00000000,
566 &kernel_pt_table[KERNEL_PT_SYS]);
567 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
568 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
569 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
570 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
571 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
572 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
573
574 /* update the top of the kernel VM */
575 pmap_curmaxkvaddr =
576 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
577
578 #ifdef VERBOSE_INIT_ARM
579 printf("Mapping kernel\n");
580 #endif
581
582 /* Now we fill in the L2 pagetable for the kernel static code/data */
583 {
584 size_t textsize = (uintptr_t)&etext - KERNEL_TEXT_BASE;
585 size_t totalsize = (uintptr_t)&end - KERNEL_TEXT_BASE;
586 u_int logical;
587
588 textsize = (textsize + PGOFSET) & ~PGOFSET;
589 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
590
591 logical = 0x00200000; /* offset of kernel in RAM */
592
593 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
594 physical_start + logical, textsize,
595 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
596 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
597 physical_start + logical, totalsize - textsize,
598 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
599 }
600
601 #ifdef VERBOSE_INIT_ARM
602 printf("Constructing L2 page tables\n");
603 #endif
604
605 /* Map the stack pages */
606 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
607 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
608 PTE_CACHE);
609 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
610 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
611 PTE_CACHE);
612 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
613 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
614 PTE_CACHE);
615 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
616 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
617
618 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
619 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
620
621 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
622 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
623 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
624 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
625 }
626
627 /* Map the vector page. */
628 #if 1
629 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
630 * cache-clean code there. */
631 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
632 VM_PROT_READ | VM_PROT_WRITE, PTE_NOCACHE);
633 #else
634 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
635 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
636 #endif
637
638 #ifdef MEMORY_DISK_DYNAMIC
639 /* map MD root image */
640 pmap_map_chunk(l1pagetable, SMDK2800_MEMORY_DISK_VADDR, md_root_start,
641 MD_ROOT_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
642
643 md_root_setconf((void *)md_root_start, MD_ROOT_SIZE);
644 #endif /* MEMORY_DISK_DYNAMIC */
645 /*
646 * map integrated peripherals at same address in l1pagetable
647 * so that we can continue to use console.
648 */
649 pmap_devmap_bootstrap(l1pagetable, smdk2800_devmap);
650
651 /*
652 * Now we have the real page tables in place so we can switch to them.
653 * Once this is done we will be running with the REAL kernel page
654 * tables.
655 */
656
657 /*
658 * Update the physical_freestart/physical_freeend/free_pages
659 * variables.
660 */
661 {
662 physical_freestart = physical_start +
663 (((((uintptr_t)&end) + PGOFSET) & ~PGOFSET) - KERNEL_BASE);
664 physical_freeend = physical_end;
665 free_pages =
666 (physical_freeend - physical_freestart) / PAGE_SIZE;
667 }
668
669 /* Switch tables */
670 #ifdef VERBOSE_INIT_ARM
671 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
672 physical_freestart, free_pages, free_pages);
673 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
674 #endif
675 LEDSTEP();
676 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
677 cpu_setttb(kernel_l1pt.pv_pa, true);
678 cpu_tlb_flushID();
679 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
680
681 /*
682 * Moved from cpu_startup() as data_abort_handler() references
683 * this during uvm init
684 */
685 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
686
687 #ifdef VERBOSE_INIT_ARM
688 printf("done!\n");
689 #endif
690
691 #if 0
692 /*
693 * The IFPGA registers have just moved.
694 * Detach the diagnostic serial port and reattach at the new address.
695 */
696 plcomcndetach();
697 /*
698 * XXX this should only be done in main() but it useful to
699 * have output earlier ...
700 */
701 consinit();
702 #endif
703
704 LEDSTEP();
705 #ifdef VERBOSE_INIT_ARM
706 printf("bootstrap done.\n");
707 #endif
708
709 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
710
711 /*
712 * Pages were allocated during the secondary bootstrap for the
713 * stacks for different CPU modes.
714 * We must now set the r13 registers in the different CPU modes to
715 * point to these stacks.
716 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
717 * of the stack memory.
718 */
719 #ifdef VERBOSE_INIT_ARM
720 printf("init subsystems: stacks ");
721 #endif
722
723 set_stackptr(PSR_IRQ32_MODE,
724 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
725 set_stackptr(PSR_ABT32_MODE,
726 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
727 set_stackptr(PSR_UND32_MODE,
728 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
729
730 LEDSTEP();
731
732 /*
733 * Well we should set a data abort handler.
734 * Once things get going this will change as we will need a proper
735 * handler.
736 * Until then we will use a handler that just panics but tells us
737 * why.
738 * Initialisation of the vectors will just panic on a data abort.
739 * This just fills in a slightly better one.
740 */
741 #ifdef VERBOSE_INIT_ARM
742 printf("vectors ");
743 #endif
744 data_abort_handler_address = (u_int)data_abort_handler;
745 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
746 undefined_handler_address = (u_int)undefinedinstruction_bounce;
747
748 /* Initialise the undefined instruction handlers */
749 #ifdef VERBOSE_INIT_ARM
750 printf("undefined ");
751 #endif
752 undefined_init();
753
754 LEDSTEP();
755
756 /* Load memory into UVM. */
757 #ifdef VERBOSE_INIT_ARM
758 printf("page ");
759 #endif
760 uvm_md_init();
761 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
762 atop(physical_freestart), atop(physical_freeend),
763 VM_FREELIST_DEFAULT);
764
765 LEDSTEP();
766 /* Boot strap pmap telling it where managed kernel virtual memory is */
767 #ifdef VERBOSE_INIT_ARM
768 printf("pmap ");
769 #endif
770 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
771
772 LEDSTEP();
773
774 /* Setup the IRQ system */
775 #ifdef VERBOSE_INIT_ARM
776 printf("irq ");
777 #endif
778 /* XXX irq_init(); */
779
780 #ifdef VERBOSE_INIT_ARM
781 printf("done.\n");
782 #endif
783
784 #ifdef BOOTHOWTO_INIT
785 boothowto |= BOOTHOWTO_INIT;
786 #endif
787 {
788 uint8_t gpio = ~gpio8(GPIO_PDATF);
789
790 if (gpio & (1<<5)) /* SW3 */
791 boothowto ^= RB_SINGLE;
792 if (gpio & (1<<7)) /* SW7 */
793 boothowto ^= RB_KDB;
794 #ifdef VERBOSE_INIT_ARM
795 printf( "sw: %x boothowto: %x\n", gpio, boothowto );
796 #endif
797 }
798
799 #ifdef KGDB
800 if (boothowto & RB_KDB) {
801 kgdb_debug_init = 1;
802 kgdb_connect(1);
803 }
804 #endif
805
806 #ifdef DDB
807 db_machine_init();
808 if (boothowto & RB_KDB)
809 Debugger();
810 #endif
811
812 /* We return the new stack pointer address */
813 return kernelstack.pv_va + USPACE_SVC_STACK_TOP;
814 }
815
816 void
817 consinit(void)
818 {
819 static int consinit_done = 0;
820 bus_space_tag_t iot = &s3c2xx0_bs_tag;
821 int pclk;
822
823 if (consinit_done != 0)
824 return;
825
826 consinit_done = 1;
827
828 pmap_devmap_register(smdk2800_devmap);
829
830 s3c2800_clock_freq2(ioreg_vaddr(S3C2800_CLKMAN_BASE), NULL, NULL, &pclk);
831
832 #if NSSCOM > 0
833 #ifdef SSCOM0CONSOLE
834 if (0 == s3c2800_sscom_cnattach(iot, 0, comcnspeed,
835 pclk, comcnmode))
836 return;
837 #endif
838 #ifdef SSCOM1CONSOLE
839 if (0 == s3c2800_sscom_cnattach(iot, 1, comcnspeed,
840 pclk, comcnmode))
841 return;
842 #endif
843 #endif /* NSSCOM */
844 #if NCOM>0 && defined(CONCOMADDR)
845 if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
846 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
847 panic("can't init serial console @%x", CONCOMADDR);
848 return;
849 #endif
850
851 consinit_done = 0;
852 }
853
854
855 #ifdef KGDB
856
857 #if (NSSCOM > 0)
858
859 #ifdef KGDB_DEVNAME
860 const char kgdb_devname[] = KGDB_DEVNAME;
861 #else
862 const char kgdb_devname[] = "";
863 #endif
864
865 #ifndef KGDB_DEVMODE
866 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE|CSTOPB|PARENB))|CS8) /* 8N1 */
867 #endif
868 int kgdb_sscom_mode = KGDB_DEVMODE;
869
870 #endif /* NSSCOM */
871
872 void
873 kgdb_port_init(void)
874 {
875 #if (NSSCOM > 0)
876 int unit = -1;
877 int pclk;
878
879 if (strcmp(kgdb_devname, "sscom0") == 0)
880 unit = 0;
881 else if (strcmp(kgdb_devname, "sscom1") == 0)
882 unit = 1;
883
884 if (unit >= 0) {
885 s3c2800_clock_freq2(ioreg_vaddr(S3C2800_CLKMAN_BASE),
886 NULL, NULL, &pclk);
887
888 s3c2800_sscom_kgdb_attach(&s3c2xx0_bs_tag,
889 unit, kgdb_rate, pclk, kgdb_sscom_mode);
890 }
891 #endif
892 }
893 #endif
894