1 /* $NetBSD: smdk2800_machdep.c,v 1.52 2024/02/20 23:36:01 andvar 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.52 2024/02/20 23:36:01 andvar 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
cpu_reboot(int howto,char * bootstr)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 DEVMAP_ENTRY(
316 SMDK2800_IO_AREA_VBASE,
317 S3C2800_PERIPHERALS,
318 S3C2800_PERIPHERALS_SIZE
319 ),
320 DEVMAP_ENTRY_END
321 };
322
323 #define ioreg_vaddr(pa) ((pa) - S3C2800_PERIPHERALS + SMDK2800_IO_AREA_VBASE)
324 #define ioreg32(pa) (*(volatile uint32_t *)ioreg_vaddr(pa))
325
326 /*
327 * vaddr_t initarm(...)
328 *
329 * Initial entry point on startup. This gets called before main() is
330 * entered.
331 * It should be responsible for setting up everything that must be
332 * in place when main is called.
333 * This includes
334 * Taking a copy of the boot configuration structure.
335 * Initialising the physical console so characters can be printed.
336 * Setting up page tables for the kernel
337 * Relocating the kernel to the bottom of physical memory
338 */
339
340 vaddr_t
initarm(void * arg)341 initarm(void *arg)
342 {
343 int loop;
344 int loop1;
345 u_int l1pagetable;
346 extern int etext __asm("_etext");
347 extern int end __asm("_end");
348 int progress_counter = 0;
349
350 #ifdef DO_MEMORY_DISK
351 vaddr_t md_root_start;
352 #define MD_ROOT_SIZE (MEMORY_DISK_ROOT_SIZE * DEV_BSIZE)
353 #endif
354
355 #define gpio8(reg) (*(volatile uint8_t *)(ioreg_vaddr(S3C2800_GPIO_BASE) + (reg)))
356
357 #define LEDSTEP() __LED(progress_counter++)
358
359 #define pdatc gpio8(GPIO_PDATC)
360 #define __LED(x) (pdatc = (pdatc & ~0x07) | (~(x) & 0x07))
361
362 LEDSTEP();
363 /*
364 * Heads up ... Setup the CPU / MMU / TLB functions
365 */
366 if (set_cpufuncs())
367 panic("CPU not recognized!");
368
369 LEDSTEP();
370
371
372 /* Disable all peripheral interrupts */
373 ioreg32(S3C2800_INTCTL_BASE + INTCTL_INTMSK) = 0;
374
375 consinit();
376 #ifdef VERBOSE_INIT_ARM
377 printf("consinit done\n");
378 #endif
379
380 #ifdef KGDB
381 LEDSTEP();
382 kgdb_port_init();
383 #endif
384 LEDSTEP();
385
386 #ifdef VERBOSE_INIT_ARM
387 /* Talk to the user */
388 printf("\nNetBSD/evbarm (SMDK2800) booting ...\n");
389 #endif
390
391 /*
392 * Ok we have the following memory map
393 *
394 * Physical Address Range Description
395 * ----------------------- ----------------------------------
396 * 0x00000000 - 0x00ffffff Intel flash Memory (16MB)
397 * 0x02000000 - 0x020fffff AMD flash Memory (1MB)
398 * or (depend on DIPSW setting)
399 * 0x00000000 - 0x000fffff AMD flash Memory (1MB)
400 * 0x02000000 - 0x02ffffff Intel flash Memory (16MB)
401 *
402 * 0x08000000 - 0x09ffffff SDRAM (32MB)
403 * 0x20000000 - 0x3fffffff PCI space
404 *
405 * The initarm() has the responsibility for creating the kernel
406 * page tables.
407 * It must also set up various memory pointers that are used
408 * by pmap etc.
409 */
410
411 /* Fake bootconfig structure for the benefit of pmap.c */
412 /* XXX must make the memory description h/w independent */
413 bootconfig.dramblocks = 1;
414 bootconfig.dram[0].address = SDRAM_START;
415 bootconfig.dram[0].pages = SDRAM_SIZE / PAGE_SIZE;
416
417 /*
418 * Set up the variables that define the availability of
419 * physical memory. For now, we're going to set
420 * physical_freestart to 0x08200000 (where the kernel
421 * was loaded), and allocate the memory we need downwards.
422 * If we get too close to the bottom of SDRAM, we
423 * will panic. We will update physical_freestart and
424 * physical_freeend later to reflect what pmap_bootstrap()
425 * wants to see.
426 *
427 * XXX pmap_bootstrap() needs an enema.
428 */
429 physical_start = bootconfig.dram[0].address;
430 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
431
432 #if DO_MEMORY_DISK
433 #ifdef MEMORY_DISK_ROOT_ROM
434 md_root_start = MEMORY_DISK_ROOT_ADDR;
435 boothowto |= RB_RDONLY;
436 #else
437 /* Reserve physmem for ram disk */
438 md_root_start = ((physical_end - MD_ROOT_SIZE) & ~(L1_S_SIZE-1));
439 printf("Reserve %ld bytes for memory disk\n",
440 physical_end - md_root_start);
441 /* copy fs contents */
442 memcpy((void *)md_root_start, (void *)MEMORY_DISK_ROOT_ADDR,
443 MD_ROOT_SIZE);
444 physical_end = md_root_start;
445 #endif
446 #endif
447
448 physical_freestart = 0x08000000UL; /* XXX */
449 physical_freeend = 0x08200000UL;
450
451 physmem = (physical_end - physical_start) / PAGE_SIZE;
452
453 #ifdef VERBOSE_INIT_ARM
454 /* Tell the user about the memory */
455 printf("physmemory: 0x%"PRIxPSIZE" pages at 0x%08lx -> 0x%08lx\n", physmem,
456 physical_start, physical_end - 1);
457 #endif
458
459 /*
460 * XXX
461 * Okay, the kernel starts 2MB in from the bottom of physical
462 * memory. We are going to allocate our bootstrap pages downwards
463 * from there.
464 *
465 * We need to allocate some fixed page tables to get the kernel
466 * going. We allocate one page directory and a number of page
467 * tables and store the physical addresses in the kernel_pt_table
468 * array.
469 *
470 * The kernel page directory must be on a 16K boundary. The page
471 * tables must be on 4K boundaries. What we do is allocate the
472 * page directory on the first 16K boundary that we encounter, and
473 * the page tables on 4K boundaries otherwise. Since we allocate
474 * at least 3 L2 page tables, we are guaranteed to encounter at
475 * least one 16K aligned region.
476 */
477
478 #ifdef VERBOSE_INIT_ARM
479 printf("Allocating page tables\n");
480 #endif
481
482 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
483
484 #ifdef VERBOSE_INIT_ARM
485 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
486 physical_freestart, free_pages, free_pages);
487 #endif
488
489 /* Define a macro to simplify memory allocation */
490 #define valloc_pages(var, np) \
491 alloc_pages((var).pv_pa, (np)); \
492 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
493
494 #define alloc_pages(var, np) \
495 physical_freeend -= ((np) * PAGE_SIZE); \
496 if (physical_freeend < physical_freestart) \
497 panic("initarm: out of memory"); \
498 (var) = physical_freeend; \
499 free_pages -= (np); \
500 memset((char *)(var), 0, ((np) * PAGE_SIZE));
501
502 loop1 = 0;
503 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
504 /* Are we 16KB aligned for an L1 ? */
505 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
506 && kernel_l1pt.pv_pa == 0) {
507 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
508 } else {
509 valloc_pages(kernel_pt_table[loop1],
510 L2_TABLE_SIZE / PAGE_SIZE);
511 ++loop1;
512 }
513 }
514
515 /* This should never be able to happen but better confirm that. */
516 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
517 panic("initarm: Failed to align the kernel page directory\n");
518
519 /*
520 * Allocate a page for the system page mapped to V0x00000000
521 * This page will just contain the system vectors and can be
522 * shared by all processes.
523 */
524 alloc_pages(systempage.pv_pa, 1);
525
526 /* Allocate stacks for all modes */
527 valloc_pages(irqstack, IRQ_STACK_SIZE);
528 valloc_pages(abtstack, ABT_STACK_SIZE);
529 valloc_pages(undstack, UND_STACK_SIZE);
530 valloc_pages(kernelstack, UPAGES);
531
532 #ifdef VERBOSE_INIT_ARM
533 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
534 irqstack.pv_va);
535 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
536 abtstack.pv_va);
537 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
538 undstack.pv_va);
539 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
540 kernelstack.pv_va);
541 #endif
542
543 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
544
545 LEDSTEP();
546
547 /*
548 * Ok we have allocated physical pages for the primary kernel
549 * page tables
550 */
551
552 #ifdef VERBOSE_INIT_ARM
553 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
554 #endif
555
556 /*
557 * Now we start construction of the L1 page table
558 * We start by mapping the L2 page tables into the L1.
559 * This means that we can replace L1 mappings later on if necessary
560 */
561 l1pagetable = kernel_l1pt.pv_pa;
562
563 /* Map the L2 pages tables in the L1 page table */
564 pmap_link_l2pt(l1pagetable, 0x00000000,
565 &kernel_pt_table[KERNEL_PT_SYS]);
566 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
567 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
568 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
569 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
570 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
571 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
572
573 /* update the top of the kernel VM */
574 pmap_curmaxkvaddr =
575 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
576
577 #ifdef VERBOSE_INIT_ARM
578 printf("Mapping kernel\n");
579 #endif
580
581 /* Now we fill in the L2 pagetable for the kernel static code/data */
582 {
583 size_t textsize = (uintptr_t)&etext - KERNEL_TEXT_BASE;
584 size_t totalsize = (uintptr_t)&end - KERNEL_TEXT_BASE;
585 u_int logical;
586
587 textsize = (textsize + PGOFSET) & ~PGOFSET;
588 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
589
590 logical = 0x00200000; /* offset of kernel in RAM */
591
592 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
593 physical_start + logical, textsize,
594 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
595 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
596 physical_start + logical, totalsize - textsize,
597 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
598 }
599
600 #ifdef VERBOSE_INIT_ARM
601 printf("Constructing L2 page tables\n");
602 #endif
603
604 /* Map the stack pages */
605 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
606 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
607 PTE_CACHE);
608 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
609 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
610 PTE_CACHE);
611 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
612 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
613 PTE_CACHE);
614 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
615 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
616
617 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
618 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
619
620 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
621 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
622 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
623 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
624 }
625
626 /* Map the vector page. */
627 #if 1
628 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
629 * cache-clean code there. */
630 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
631 VM_PROT_READ | VM_PROT_WRITE, PTE_NOCACHE);
632 #else
633 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
634 VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
635 #endif
636
637 #ifdef MEMORY_DISK_DYNAMIC
638 /* map MD root image */
639 pmap_map_chunk(l1pagetable, SMDK2800_MEMORY_DISK_VADDR, md_root_start,
640 MD_ROOT_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
641
642 md_root_setconf((void *)md_root_start, MD_ROOT_SIZE);
643 #endif /* MEMORY_DISK_DYNAMIC */
644 /*
645 * map integrated peripherals at same address in l1pagetable
646 * so that we can continue to use console.
647 */
648 pmap_devmap_bootstrap(l1pagetable, smdk2800_devmap);
649
650 /*
651 * Now we have the real page tables in place so we can switch to them.
652 * Once this is done we will be running with the REAL kernel page
653 * tables.
654 */
655
656 /*
657 * Update the physical_freestart/physical_freeend/free_pages
658 * variables.
659 */
660 {
661 physical_freestart = physical_start +
662 (((((uintptr_t)&end) + PGOFSET) & ~PGOFSET) - KERNEL_BASE);
663 physical_freeend = physical_end;
664 free_pages =
665 (physical_freeend - physical_freestart) / PAGE_SIZE;
666 }
667
668 /* Switch tables */
669 #ifdef VERBOSE_INIT_ARM
670 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
671 physical_freestart, free_pages, free_pages);
672 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
673 #endif
674 LEDSTEP();
675 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
676 cpu_setttb(kernel_l1pt.pv_pa, true);
677 cpu_tlb_flushID();
678 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
679
680 /*
681 * Moved from cpu_startup() as data_abort_handler() references
682 * this during uvm init
683 */
684 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
685
686 #ifdef VERBOSE_INIT_ARM
687 printf("done!\n");
688 #endif
689
690 #if 0
691 /*
692 * The IFPGA registers have just moved.
693 * Detach the diagnostic serial port and reattach at the new address.
694 */
695 plcomcndetach();
696 /*
697 * XXX this should only be done in main() but it useful to
698 * have output earlier ...
699 */
700 consinit();
701 #endif
702
703 LEDSTEP();
704 #ifdef VERBOSE_INIT_ARM
705 printf("bootstrap done.\n");
706 #endif
707
708 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
709
710 /*
711 * Pages were allocated during the secondary bootstrap for the
712 * stacks for different CPU modes.
713 * We must now set the r13 registers in the different CPU modes to
714 * point to these stacks.
715 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
716 * of the stack memory.
717 */
718 #ifdef VERBOSE_INIT_ARM
719 printf("init subsystems: stacks ");
720 #endif
721
722 set_stackptr(PSR_IRQ32_MODE,
723 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
724 set_stackptr(PSR_ABT32_MODE,
725 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
726 set_stackptr(PSR_UND32_MODE,
727 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
728
729 LEDSTEP();
730
731 /*
732 * Well we should set a data abort handler.
733 * Once things get going this will change as we will need a proper
734 * handler.
735 * Until then we will use a handler that just panics but tells us
736 * why.
737 * Initialisation of the vectors will just panic on a data abort.
738 * This just fills in a slightly better one.
739 */
740 #ifdef VERBOSE_INIT_ARM
741 printf("vectors ");
742 #endif
743 data_abort_handler_address = (u_int)data_abort_handler;
744 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
745 undefined_handler_address = (u_int)undefinedinstruction_bounce;
746
747 /* Initialise the undefined instruction handlers */
748 #ifdef VERBOSE_INIT_ARM
749 printf("undefined ");
750 #endif
751 undefined_init();
752
753 LEDSTEP();
754
755 /* Load memory into UVM. */
756 #ifdef VERBOSE_INIT_ARM
757 printf("page ");
758 #endif
759 uvm_md_init();
760 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
761 atop(physical_freestart), atop(physical_freeend),
762 VM_FREELIST_DEFAULT);
763
764 LEDSTEP();
765 /* Boot strap pmap telling it where managed kernel virtual memory is */
766 #ifdef VERBOSE_INIT_ARM
767 printf("pmap ");
768 #endif
769 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
770
771 LEDSTEP();
772
773 /* Setup the IRQ system */
774 #ifdef VERBOSE_INIT_ARM
775 printf("irq ");
776 #endif
777 /* XXX irq_init(); */
778
779 #ifdef VERBOSE_INIT_ARM
780 printf("done.\n");
781 #endif
782
783 #ifdef BOOTHOWTO_INIT
784 boothowto |= BOOTHOWTO_INIT;
785 #endif
786 {
787 uint8_t gpio = ~gpio8(GPIO_PDATF);
788
789 if (gpio & (1<<5)) /* SW3 */
790 boothowto ^= RB_SINGLE;
791 if (gpio & (1<<7)) /* SW7 */
792 boothowto ^= RB_KDB;
793 #ifdef VERBOSE_INIT_ARM
794 printf( "sw: %x boothowto: %x\n", gpio, boothowto );
795 #endif
796 }
797
798 #ifdef KGDB
799 if (boothowto & RB_KDB) {
800 kgdb_debug_init = 1;
801 kgdb_connect(1);
802 }
803 #endif
804
805 #ifdef DDB
806 db_machine_init();
807 if (boothowto & RB_KDB)
808 Debugger();
809 #endif
810
811 /* We return the new stack pointer address */
812 return kernelstack.pv_va + USPACE_SVC_STACK_TOP;
813 }
814
815 void
consinit(void)816 consinit(void)
817 {
818 static int consinit_done = 0;
819 bus_space_tag_t iot = &s3c2xx0_bs_tag;
820 int pclk;
821
822 if (consinit_done != 0)
823 return;
824
825 consinit_done = 1;
826
827 pmap_devmap_register(smdk2800_devmap);
828
829 s3c2800_clock_freq2(ioreg_vaddr(S3C2800_CLKMAN_BASE), NULL, NULL, &pclk);
830
831 #if NSSCOM > 0
832 #ifdef SSCOM0CONSOLE
833 if (0 == s3c2800_sscom_cnattach(iot, 0, comcnspeed,
834 pclk, comcnmode))
835 return;
836 #endif
837 #ifdef SSCOM1CONSOLE
838 if (0 == s3c2800_sscom_cnattach(iot, 1, comcnspeed,
839 pclk, comcnmode))
840 return;
841 #endif
842 #endif /* NSSCOM */
843 #if NCOM>0 && defined(CONCOMADDR)
844 if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
845 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
846 panic("can't init serial console @%x", CONCOMADDR);
847 return;
848 #endif
849
850 consinit_done = 0;
851 }
852
853
854 #ifdef KGDB
855
856 #if (NSSCOM > 0)
857
858 #ifdef KGDB_DEVNAME
859 const char kgdb_devname[] = KGDB_DEVNAME;
860 #else
861 const char kgdb_devname[] = "";
862 #endif
863
864 #ifndef KGDB_DEVMODE
865 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE|CSTOPB|PARENB))|CS8) /* 8N1 */
866 #endif
867 int kgdb_sscom_mode = KGDB_DEVMODE;
868
869 #endif /* NSSCOM */
870
871 void
kgdb_port_init(void)872 kgdb_port_init(void)
873 {
874 #if (NSSCOM > 0)
875 int unit = -1;
876 int pclk;
877
878 if (strcmp(kgdb_devname, "sscom0") == 0)
879 unit = 0;
880 else if (strcmp(kgdb_devname, "sscom1") == 0)
881 unit = 1;
882
883 if (unit >= 0) {
884 s3c2800_clock_freq2(ioreg_vaddr(S3C2800_CLKMAN_BASE),
885 NULL, NULL, &pclk);
886
887 s3c2800_sscom_kgdb_attach(&s3c2xx0_bs_tag,
888 unit, kgdb_rate, pclk, kgdb_sscom_mode);
889 }
890 #endif
891 }
892 #endif
893