Module Name: src Committed By: skrll Date: Sun Oct 16 06:14:54 UTC 2022
Modified Files: src/sys/arch/riscv/include: machdep.h vmparam.h src/sys/arch/riscv/riscv: genassym.cf locore.S riscv_machdep.c Log Message: Map the DTB using VM_KERNEL_DTB_BASE and CONSADDR using VM_KERNEL_IO_BASE To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/include/machdep.h cvs rdiff -u -r1.12 -r1.13 src/sys/arch/riscv/include/vmparam.h cvs rdiff -u -r1.12 -r1.13 src/sys/arch/riscv/riscv/genassym.cf cvs rdiff -u -r1.38 -r1.39 src/sys/arch/riscv/riscv/locore.S cvs rdiff -u -r1.20 -r1.21 src/sys/arch/riscv/riscv/riscv_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/riscv/include/machdep.h diff -u src/sys/arch/riscv/include/machdep.h:1.2 src/sys/arch/riscv/include/machdep.h:1.3 --- src/sys/arch/riscv/include/machdep.h:1.2 Wed Sep 28 06:05:28 2022 +++ src/sys/arch/riscv/include/machdep.h Sun Oct 16 06:14:53 2022 @@ -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_ */ Index: src/sys/arch/riscv/include/vmparam.h diff -u src/sys/arch/riscv/include/vmparam.h:1.12 src/sys/arch/riscv/include/vmparam.h:1.13 --- src/sys/arch/riscv/include/vmparam.h:1.12 Sat Oct 15 06:07:04 2022 +++ src/sys/arch/riscv/include/vmparam.h Sun Oct 16 06:14:53 2022 @@ -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) Index: src/sys/arch/riscv/riscv/genassym.cf diff -u src/sys/arch/riscv/riscv/genassym.cf:1.12 src/sys/arch/riscv/riscv/genassym.cf:1.13 --- src/sys/arch/riscv/riscv/genassym.cf:1.12 Tue Sep 20 07:18:23 2022 +++ src/sys/arch/riscv/riscv/genassym.cf Sun Oct 16 06:14:53 2022 @@ -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_KERN 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 Index: src/sys/arch/riscv/riscv/locore.S diff -u src/sys/arch/riscv/riscv/locore.S:1.38 src/sys/arch/riscv/riscv/locore.S:1.39 --- src/sys/arch/riscv/riscv/locore.S:1.38 Sun Oct 16 06:03:14 2022 +++ src/sys/arch/riscv/riscv/locore.S Sun Oct 16 06:14:53 2022 @@ -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 Index: src/sys/arch/riscv/riscv/riscv_machdep.c diff -u src/sys/arch/riscv/riscv/riscv_machdep.c:1.20 src/sys/arch/riscv/riscv/riscv_machdep.c:1.21 --- src/sys/arch/riscv/riscv/riscv_machdep.c:1.20 Sat Oct 15 06:41:43 2022 +++ src/sys/arch/riscv/riscv/riscv_machdep.c Sun Oct 16 06:14:53 2022 @@ -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));