From nobody Tue May 23 13:23:23 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QQZl008jTz4CTTf; Tue, 23 May 2023 13:23:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QQZkz6hxGz3t5s; Tue, 23 May 2023 13:23:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684848203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LL7bD2mhQmadxEOcEYQ7eJM4/K095AXrzvyi1dd0xGE=; b=NqGEZFxQILOGWRKGulubAHS4WGf2C5Fb3rBjC7k6uQKHqexvpnevnIYZgyDoCNNaQ22Ira jlqMm5uvwM4VjlbaSxJ4iYyBewaQL+/h2YMVEOVhbBM1D1x6PnAm72+KdlSFqIIEvRYoJx WzAniyN9nTT6SSAeJoT0c9PVnW0vJy5BFyz0sh3wDwyE635dMZkzc7LS5c5tuxfC1irjnK k1FnM9GckRuqPUVcEkrf1IXP+pYzxZfcxN2my/ihmvCrZo+g0cmV9cQrkLRKlCK+foAcr1 4U0bxbGXNoBitLj/sOtPXnKY2hsFyDVgha7oky6jGmaEK4WmfcaOYT5vPyZ+iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684848203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LL7bD2mhQmadxEOcEYQ7eJM4/K095AXrzvyi1dd0xGE=; b=pjl8RgRzwlAxoblVjxV6gypAnG5u5SHc+cjbieB+6aM6LjyYhIWkvo50+rjD+3IBpFVlA9 nD/cF4jYMvGKSs7wHufG5SIE8XikHIjsLN0TeBK4QJKzg3sPM9L1b6VRlMKtmJ6kwtU08Z n3m9TVS+/2KTFGLqUdYEUPc3se4WCVvPYknqAqb+LP2cGXC1pMHUFJWF9iPXajDMHrdgUc +MelSQ9HNwwoStfXdSgHHdQ9JzqD9Y9BaZPirf5quFL9vEYI4aXvxr6bMkW+zDAOlrr9Rd pCPZZynpSvIo2ocfUpJDVHR+hpnN6VSotFY679QsdX8VecwGNi34exFRSJHEdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684848204; a=rsa-sha256; cv=none; b=nJPWfKDnEvWUMz9d9th83gnquWhcrGeGOw1dSVC8Hz/rFPQueQ+cXIRYJOiyi1n8yZ1GnP x2s87nj0snqVIqpj/uv5dAfhg+3jI4xhWopqeoHF3FdlA7ru7K5NClnrBD4pFbo1Y/XnO4 JYoROEyrJbqVJxs6OMIOYCn57p4m+1AtGraALJZchDZA+IlpUznp8uii+8xx/ECxAWbbkB CjWVLkYNj8kZRFyfsTGYKaJdYV3dHJmRICEtazGCYPSors1j7CncKlCXkUOd4U+hcy8keB 4A1S0GAHffo45iR7xX2C30xMtxAMnJsRog5AdQEseD0svpdKThpDeVW7sfY5Rg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QQZkz5m88z1276; Tue, 23 May 2023 13:23:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34NDNNB9016563; Tue, 23 May 2023 13:23:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34NDNNfb016562; Tue, 23 May 2023 13:23:23 GMT (envelope-from git) Date: Tue, 23 May 2023 13:23:23 GMT Message-Id: <202305231323.34NDNNfb016562@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 7245ffd10eda - main - riscv: MMU detection List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7245ffd10eda4ff604840350943d762f70657983 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=7245ffd10eda4ff604840350943d762f70657983 commit 7245ffd10eda4ff604840350943d762f70657983 Author: Mitchell Horne AuthorDate: 2023-05-22 23:53:43 +0000 Commit: Mitchell Horne CommitDate: 2023-05-23 13:19:26 +0000 riscv: MMU detection Detect and report the supported MMU for each CPU. Export the capabilities to the rest of the kernel and use it in pmap_bootstrap() to check for Sv48 support. Reviewed by: markj MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39814 --- sys/riscv/include/cpu.h | 8 ++++++++ sys/riscv/include/md_var.h | 1 + sys/riscv/riscv/identcpu.c | 30 ++++++++++++++++++++++++++++++ sys/riscv/riscv/pmap.c | 2 +- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/sys/riscv/include/cpu.h b/sys/riscv/include/cpu.h index b7d83aa0f25d..d99142bc3c93 100644 --- a/sys/riscv/include/cpu.h +++ b/sys/riscv/include/cpu.h @@ -83,6 +83,14 @@ /* SiFive marchid values */ #define MARCHID_SIFIVE_U7 MARCHID_COMMERCIAL(7) +/* + * MMU virtual-addressing modes. Support for each level implies the previous, + * so Sv48-enabled systems MUST support Sv39, etc. + */ +#define MMU_SV39 0x1 /* 3-level paging */ +#define MMU_SV48 0x2 /* 4-level paging */ +#define MMU_SV57 0x4 /* 5-level paging */ + extern char btext[]; extern char etext[]; diff --git a/sys/riscv/include/md_var.h b/sys/riscv/include/md_var.h index 890f569782a3..687ab9a3a77e 100644 --- a/sys/riscv/include/md_var.h +++ b/sys/riscv/include/md_var.h @@ -40,6 +40,7 @@ extern u_long elf_hwcap; extern register_t mvendorid; extern register_t marchid; extern register_t mimpid; +extern u_int mmu_caps; struct dumperinfo; struct minidumpstate; diff --git a/sys/riscv/riscv/identcpu.c b/sys/riscv/riscv/identcpu.c index d4ad8a1078b6..01e9fe9b4669 100644 --- a/sys/riscv/riscv/identcpu.c +++ b/sys/riscv/riscv/identcpu.c @@ -65,10 +65,13 @@ register_t mvendorid; /* The CPU's JEDEC vendor ID */ register_t marchid; /* The architecture ID */ register_t mimpid; /* The implementation ID */ +u_int mmu_caps; + struct cpu_desc { const char *cpu_mvendor_name; const char *cpu_march_name; u_int isa_extensions; /* Single-letter extensions. */ + u_int mmu_caps; }; struct cpu_desc cpu_desc[MAXCPU]; @@ -269,6 +272,20 @@ parse_riscv_isa(struct cpu_desc *desc, char *isa, int len) } #ifdef FDT +static void +parse_mmu_fdt(struct cpu_desc *desc, phandle_t node) +{ + char mmu[16]; + + desc->mmu_caps |= MMU_SV39; + if (OF_getprop(node, "mmu-type", mmu, sizeof(mmu)) > 0) { + if (strcmp(mmu, "riscv,sv48") == 0) + desc->mmu_caps |= MMU_SV48; + else if (strcmp(mmu, "riscv,sv57") == 0) + desc->mmu_caps |= MMU_SV48 | MMU_SV57; + } +} + static void identify_cpu_features_fdt(u_int cpu, struct cpu_desc *desc) { @@ -317,6 +334,9 @@ identify_cpu_features_fdt(u_int cpu, struct cpu_desc *desc) if (parse_riscv_isa(desc, isa, len) != 0) return; + /* Check MMU features. */ + parse_mmu_fdt(desc, node); + /* We are done. */ break; } @@ -356,6 +376,11 @@ update_global_capabilities(u_int cpu, struct cpu_desc *desc) /* Update the capabilities exposed to userspace via AT_HWCAP. */ UPDATE_CAP(elf_hwcap, (u_long)desc->isa_extensions); + /* + * MMU capabilities, e.g. Sv48. + */ + UPDATE_CAP(mmu_caps, desc->mmu_caps); + #undef UPDATE_CAP } @@ -429,6 +454,11 @@ printcpuinfo(u_int cpu) desc->cpu_mvendor_name, desc->cpu_march_name, hart); printf(" marchid=%#lx, mimpid=%#lx\n", marchid, mimpid); + printf(" MMU: %#b\n", desc->mmu_caps, + "\020" + "\01Sv39" + "\02Sv48" + "\03Sv57"); printf(" ISA: %#b\n", desc->isa_extensions, "\020" "\01Atomic" diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index 8d34dbc3637d..007ec1e678fc 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -704,7 +704,7 @@ pmap_bootstrap(vm_offset_t l1pt, vm_paddr_t kernstart, vm_size_t kernlen) mode = 0; TUNABLE_INT_FETCH("vm.pmap.mode", &mode); - if (mode == PMAP_MODE_SV48) { + if (mode == PMAP_MODE_SV48 && (mmu_caps & MMU_SV48) != 0) { /* * Enable SV48 mode: allocate an L0 page and set SV48 mode in * SATP. If the implementation does not provide SV48 mode,