From nobody Thu May 25 17:11:40 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 4QRvjT0sTKz4WSN8; Thu, 25 May 2023 17:11:41 +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 4QRvjT02thz3lpC; Thu, 25 May 2023 17:11:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685034701; 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=Uo6fK29/flEPjauqgUmhRF3FkDsFqK/UUAoOioqY8EY=; b=mqbiwQ0UXOHi3pWz80cJeB7ohg30gDCFS23NL1XAasMTFcD2I6nOQLrhlSCFHDgKjAjPGJ Z6Hi9XuFP5Jj3Jf9gvVPVSjK0SIkirT7xfmjKlC5XBZ/8wir3NbrszNCY0d+jQQMNJZef+ ddzgBW8cGfJymyiZGf1wSKNpgIwPh22ATM/F1ib4B1f/NUVQ/IJayK7EEg+B2IYqMeuZuv uvnI3cB1kg5gS4YA9aumVYPgZXjvAohAbX2AoVH1KynYsmTgNiwpXobRdjsixLbpLadmh0 5xO9d0J4D2P1qFJ37F51Wb4PD7apn1k1v7+g3W0vOVt75VW7DD7vyXZJW89KBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685034701; 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=Uo6fK29/flEPjauqgUmhRF3FkDsFqK/UUAoOioqY8EY=; b=eeIJYxJevy0Fig03awjJfDcCMhTCjoOnN5oBWq5iOpIyaeTwjn19k4bUlcZJJKaSjEzycq 2w2eM950pyEafqA2fDp4EDl+7AhzkAQ5pkwWrTP2H0iSHo7i82qDO4D/LkZPeOE1jryqps 35hzELDPYHUaXMokRElGE1m+l/OfUriV84R4vfth2xwUs+wnPloUJ+6T0tWu9B2GnoCJs+ X2qt/l/N6NfPXct7WC9PJhJ2aLmbpemqXSx69QNICsGqJIQ4GGugUwvNsqxDfQSaM7+bxd jxNV0SRhDSWlygi19h1q0e3FeZagCuK/KA8gVgjUfpSqu6PSg3oSLDOO8H0CoA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685034701; a=rsa-sha256; cv=none; b=IdLQeRNK7PSVHXzpZC3UoFT4+8WLITToF2GG1RBt3zMM5qrv20sfQkFnlrEZTj2yyPci1d BOTj1ssjh9AYoC9VBGeTaTi7TvoowcZm+b52Xma2D5aFhG7kATYtEIXs0b6d5LhzQ+rYlk pLuue0jXicV5Wy1SnVieyLgGAgiGluaoojsUFrlGoLOre1yT5QHJm1hxN5OSxKKOYirBI0 qOr7DJfv+k9pWMKOaPHPhmLDDnRyAcjdvExhWvH5g5iSPmznbxLdjE0DeydctTY9kDQhPb tk+WN+OMJQsv1ng6itn61zfxT/vY/Qf70cixs0a0TduGO2p4UcfPeQDijOVw0w== 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 4QRvjS5wvRzYBw; Thu, 25 May 2023 17:11:40 +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 34PHBelB041661; Thu, 25 May 2023 17:11:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34PHBec4041660; Thu, 25 May 2023 17:11:40 GMT (envelope-from git) Date: Thu, 25 May 2023 17:11:40 GMT Message-Id: <202305251711.34PHBec4041660@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: 8bebb786820f - main - riscv: S-mode extension parsing 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: 8bebb786820f634d47522711b8cd56a66db3785d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=8bebb786820f634d47522711b8cd56a66db3785d commit 8bebb786820f634d47522711b8cd56a66db3785d Author: Mitchell Horne AuthorDate: 2023-05-25 17:07:26 +0000 Commit: Mitchell Horne CommitDate: 2023-05-25 17:07:26 +0000 riscv: S-mode extension parsing There are now several Supervisor-mode extensions that have entered the 'ratified' status, so begin parsing and reporting a few of these. Recognize the following extensions: - Sstc: stimecmp/vstimecmp CSR - Svnapot: NAPOT* translation contiguity - Svpbmt: page-based memory types - Svinval: fine-grained TLB invalidation instructions - Sscofpmf: performance counter overflow *i.e. "naturally aligned power-of-2" page granularity For now, provide globals for Sstc and Sscofpmf, as we will make use of these in the near future. Plus, update the copyright statement after my recent work on this file. Reviewed by: jhb MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D40240 --- sys/riscv/include/md_var.h | 4 ++++ sys/riscv/riscv/identcpu.c | 53 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/sys/riscv/include/md_var.h b/sys/riscv/include/md_var.h index 687ab9a3a77e..9951c838a2e6 100644 --- a/sys/riscv/include/md_var.h +++ b/sys/riscv/include/md_var.h @@ -42,6 +42,10 @@ extern register_t marchid; extern register_t mimpid; extern u_int mmu_caps; +/* Supervisor-mode extension support */ +extern bool has_sstc; +extern bool has_sscofpmf; + struct dumperinfo; struct minidumpstate; diff --git a/sys/riscv/riscv/identcpu.c b/sys/riscv/riscv/identcpu.c index b68cc5c78352..a57d5139e0cc 100644 --- a/sys/riscv/riscv/identcpu.c +++ b/sys/riscv/riscv/identcpu.c @@ -1,6 +1,10 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause + * * Copyright (c) 2015-2016 Ruslan Bukin * All rights reserved. + * Copyright (c) 2022 Mitchell Horne + * Copyright (c) 2023 The FreeBSD Foundation * * Portions of this software were developed by SRI International and the * University of Cambridge Computer Laboratory under DARPA/AFRL contract @@ -10,6 +14,9 @@ * Computer Laboratory as part of the CTSRD Project, with support from the * UK Higher Education Innovation Fund (HEIF). * + * Portions of this software were developed by Mitchell Horne + * under sponsorship from the FreeBSD Foundation. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -67,11 +74,21 @@ register_t mimpid; /* The implementation ID */ u_int mmu_caps; +/* Supervisor-mode extension support. */ +bool __read_frequently has_sstc; +bool __read_frequently has_sscofpmf; + struct cpu_desc { const char *cpu_mvendor_name; const char *cpu_march_name; u_int isa_extensions; /* Single-letter extensions. */ u_int mmu_caps; + u_int smode_extensions; +#define SV_SSTC (1 << 0) +#define SV_SVNAPOT (1 << 1) +#define SV_SVPBMT (1 << 2) +#define SV_SVINVAL (1 << 3) +#define SV_SSCOFPMF (1 << 4) }; struct cpu_desc cpu_desc[MAXCPU]; @@ -131,13 +148,29 @@ static const struct { #define ISA_PREFIX_LEN (sizeof(ISA_PREFIX) - 1) static __inline int -parse_ext_s(struct cpu_desc *desc __unused, char *isa, int idx, int len) +parse_ext_s(struct cpu_desc *desc, char *isa, int idx, int len) { +#define CHECK_S_EXT(str, flag) \ + do { \ + if (strncmp(&isa[idx], (str), \ + MIN(strlen(str), len - idx)) == 0) { \ + desc->smode_extensions |= flag; \ + return (idx + strlen(str)); \ + } \ + } while (0) + + /* Check for known/supported extensions. */ + CHECK_S_EXT("sstc", SV_SSTC); + CHECK_S_EXT("svnapot", SV_SVNAPOT); + CHECK_S_EXT("svpbmt", SV_SVPBMT); + CHECK_S_EXT("svinval", SV_SVINVAL); + CHECK_S_EXT("sscofpmf", SV_SSCOFPMF); + +#undef CHECK_S_EXT + /* * Proceed to the next multi-letter extension or the end of the * string. - * - * TODO: parse these once we gain support */ while (isa[idx] != '_' && idx < len) { idx++; @@ -381,6 +414,10 @@ update_global_capabilities(u_int cpu, struct cpu_desc *desc) */ UPDATE_CAP(mmu_caps, desc->mmu_caps); + /* Supervisor-mode extension support. */ + UPDATE_CAP(has_sstc, (desc->smode_extensions & SV_SSTC) != 0); + UPDATE_CAP(has_sscofpmf, (desc->smode_extensions & SV_SSCOFPMF) != 0); + #undef UPDATE_CAP } @@ -480,5 +517,15 @@ printcpuinfo(u_int cpu) "\15Mult/Div"); } + if (SHOULD_PRINT(smode_extensions)) { + printf(" S-mode Extensions: %#b\n", desc->smode_extensions, + "\020" + "\01Sstc" + "\02Svnapot" + "\03Svpbmt" + "\04Svinval" + "\05Sscofpmf"); + } + #undef SHOULD_PRINT }