diff options
| author | skrll <skrll@NetBSD.org> | 2022-10-16 06:14:53 +0000 |
|---|---|---|
| committer | skrll <skrll@NetBSD.org> | 2022-10-16 06:14:53 +0000 |
| commit | a1dee93bd68de2fd5e9e5cb16b2d19d9272bb405 (patch) | |
| tree | ddd4b2895334326d242000da6ef418285664b5a4 /sys | |
| parent | c2ea5e7d106a278af41b5fe3601ca10acd9217c8 (diff) | |
Map the DTB using VM_KERNEL_DTB_BASE and CONSADDR using VM_KERNEL_IO_BASE
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arch/riscv/include/machdep.h | 6 | ||||
| -rw-r--r-- | sys/arch/riscv/include/vmparam.h | 8 | ||||
| -rw-r--r-- | sys/arch/riscv/riscv/genassym.cf | 6 | ||||
| -rw-r--r-- | sys/arch/riscv/riscv/locore.S | 24 | ||||
| -rw-r--r-- | sys/arch/riscv/riscv/riscv_machdep.c | 9 |
5 files changed, 35 insertions, 18 deletions
diff --git a/sys/arch/riscv/include/machdep.h b/sys/arch/riscv/include/machdep.h index ddcf5004bcc..f0cd5473d5e 100644 --- a/sys/arch/riscv/include/machdep.h +++ b/sys/arch/riscv/include/machdep.h @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.h,v 1.2 2022/09/28 06:05:28 skrll Exp $ */ +/* $NetBSD: machdep.h,v 1.3 2022/10/16 06:14:53 skrll Exp $ */ /*- * Copyright (c) 2022 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #define _RISCV_MACHDEP_H_ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.h,v 1.2 2022/09/28 06:05:28 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.h,v 1.3 2022/10/16 06:14:53 skrll Exp $"); #include <sys/proc.h> #include <sys/lwp.h> @@ -63,7 +63,7 @@ void uartputc(int); int uartgetc(void); paddr_t init_mmu(paddr_t); -void init_riscv(register_t, vaddr_t); +void init_riscv(register_t, paddr_t); #endif /* _RISCV_MACHDEP_H_ */ diff --git a/sys/arch/riscv/include/vmparam.h b/sys/arch/riscv/include/vmparam.h index 2138806a675..92c875da7a3 100644 --- a/sys/arch/riscv/include/vmparam.h +++ b/sys/arch/riscv/include/vmparam.h @@ -1,4 +1,4 @@ -/* $NetBSD: vmparam.h,v 1.12 2022/10/15 06:07:04 skrll Exp $ */ +/* $NetBSD: vmparam.h,v 1.13 2022/10/16 06:14:53 skrll Exp $ */ /*- * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc. @@ -129,9 +129,11 @@ #define VM_KERNEL_BASE VM_MIN_KERNEL_ADDRESS #define VM_KERNEL_SIZE 0x2000000 /* 32 MiB (8 / 16 megapages) */ #define VM_KERNEL_DTB_BASE (VM_KERNEL_BASE + VM_KERNEL_SIZE) -#define VM_KERNEL_DTB_SIZE 0x2000000 /* 32 MiB (8 / 16 megapages) */ +#define VM_KERNEL_DTB_SIZE 0x1000000 /* 16 MiB (4 / 8 megapages) */ +#define VM_KERNEL_IO_BASE (VM_KERNEL_DTB_BASE + VM_KERNEL_DTB_SIZE) +#define VM_KERNEL_IO_SIZE 0x1000000 /* 16 MiB (4 / 8 megapages) */ -#define VM_KERNEL_RESERVED (VM_KERNEL_SIZE + VM_KERNEL_DTB_SIZE) +#define VM_KERNEL_RESERVED (VM_KERNEL_SIZE + VM_KERNEL_DTB_SIZE + VM_KERNEL_IO_SIZE) #define VM_KERNEL_VM_BASE (VM_MIN_KERNEL_ADDRESS + VM_KERNEL_RESERVED) #define VM_KERNEL_VM_SIZE (VM_MAX_KERNEL_ADDRESS - VM_KERNEL_VM_BASE) diff --git a/sys/arch/riscv/riscv/genassym.cf b/sys/arch/riscv/riscv/genassym.cf index 031c11fec7f..9181a593dd4 100644 --- a/sys/arch/riscv/riscv/genassym.cf +++ b/sys/arch/riscv/riscv/genassym.cf @@ -1,4 +1,4 @@ -# $NetBSD: genassym.cf,v 1.12 2022/09/20 07:18:23 skrll Exp $ +# $NetBSD: genassym.cf,v 1.13 2022/10/16 06:14:53 skrll Exp $ #- # Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -184,6 +184,10 @@ define VM_MIN_KERNEL_ADDRESS VM_MIN_KERNEL_ADDRESS define VM_MAX_KERNEL_ADDRESS VM_MAX_KERNEL_ADDRESS define VM_KERNEL_BASE VM_KERNEL_BASE define VM_KERNEL_SIZE VM_KERNEL_SIZE +define VM_KERNEL_DTB_BASE VM_KERNEL_DTB_BASE +define VM_KERNEL_DTB_SIZE VM_KERNEL_DTB_SIZE +define VM_KERNEL_IO_BASE VM_KERNEL_IO_BASE +define VM_KERNEL_IO_BASE VM_KERNEL_IO_BASE define USPACE USPACE ifdef XSEGSHIFT diff --git a/sys/arch/riscv/riscv/locore.S b/sys/arch/riscv/riscv/locore.S index 0da0d671b1f..efbd17d2997 100644 --- a/sys/arch/riscv/riscv/locore.S +++ b/sys/arch/riscv/riscv/locore.S @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.38 2022/10/16 06:03:14 skrll Exp $ */ +/* $NetBSD: locore.S,v 1.39 2022/10/16 06:14:53 skrll Exp $ */ /*- * Copyright (c) 2014, 2022 The NetBSD Foundation, Inc. @@ -227,6 +227,7 @@ ENTRY_NP(start) VPRINTS("\n\r") #endif // _LP64 + // kernel VA li t1, ((VM_MIN_KERNEL_ADDRESS >> SEGSHIFT) & (NPDEPG - 1)) * SZREG add s9, s2, t1 @@ -257,9 +258,16 @@ ENTRY_NP(start) addi s5, s5, -1 // count down segment bnez s5, 1b // loop if more + // DTB VA + li t1, ((VM_KERNEL_DTB_BASE >> SEGSHIFT) & (NPDEPG - 1)) * SZREG + add s9, s2, t1 + li s7, PTE_KERN | PTE_R | PTE_W - // DTB physical address + // + // Fill in the PDE for the DTB. Only do one - if any more are required + // they will be mapped in later. + // mv s0, s11 srli s0, s0, SEGSHIFT // round down to NBSEG, and shift in slli s0, s0, (SEGSHIFT - PGSHIFT + PTE_PPN_SHIFT) // ... to PPN @@ -271,10 +279,14 @@ ENTRY_NP(start) VPRINTXNL(s0) REG_S s0, 0(s9) - add s9, s9, SZREG // advance to next PDE slot #ifdef CONSADDR - ld s0, .Lconsaddr + li t1, ((VM_KERNEL_IO_BASE >> SEGSHIFT) & (NPDEPG - 1)) * SZREG + add s9, s2, t1 + + // Fill in the PDE for CONSADDR. + ld t0, .Lconsaddr + mv s0, t0 srli s0, s0, SEGSHIFT // round down to NBSEG, and shift in slli s0, s0, (SEGSHIFT - PGSHIFT + PTE_PPN_SHIFT) // ... to PPN or s0, s0, s7 @@ -285,7 +297,6 @@ ENTRY_NP(start) VPRINTXNL(s0) REG_S s0, 0(s9) - add s9, s9, SZREG // advance to next PDE slot #endif li a0, 'P' @@ -364,8 +375,7 @@ vstart: // Now we should ready to start initializing the kernel. mv a0, s10 // hartid - mv a1, t0 // vdtb - //mv a1, s11 // dtb (physical) + mv a1, s11 // dtb (physical) li s0, 0 // zero frame pointer call _C_LABEL(init_riscv) // do MD startup diff --git a/sys/arch/riscv/riscv/riscv_machdep.c b/sys/arch/riscv/riscv/riscv_machdep.c index 8d1d276243b..45ea67756ad 100644 --- a/sys/arch/riscv/riscv/riscv_machdep.c +++ b/sys/arch/riscv/riscv/riscv_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: riscv_machdep.c,v 1.20 2022/10/15 06:41:43 simonb Exp $ */ +/* $NetBSD: riscv_machdep.c,v 1.21 2022/10/16 06:14:53 skrll Exp $ */ /*- * Copyright (c) 2014, 2019, 2022 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include "opt_riscv_debug.h" #include <sys/cdefs.h> -__RCSID("$NetBSD: riscv_machdep.c,v 1.20 2022/10/15 06:41:43 simonb Exp $"); +__RCSID("$NetBSD: riscv_machdep.c,v 1.21 2022/10/16 06:14:53 skrll Exp $"); #include <sys/param.h> @@ -431,14 +431,15 @@ parse_bi_bootargs(char *args) void -init_riscv(register_t hartid, vaddr_t vdtb) +init_riscv(register_t hartid, paddr_t dtb) { /* set temporally to work printf()/panic() even before consinit() */ cn_tab = &earlycons; /* Load FDT */ - void *fdt_data = (void *)vdtb; + const vaddr_t dtbva = VM_KERNEL_DTB_BASE + (dtb & (NBSEG - 1)); + void *fdt_data = (void *)dtbva; int error = fdt_check_header(fdt_data); if (error != 0) panic("fdt_check_header failed: %s", fdt_strerror(error)); |
