From nobody Mon Jun 12 13:50:24 2023 X-Original-To: dev-commits-src-branches@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 4QftNx0V47z4cGlJ; Mon, 12 Jun 2023 13:50:25 +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 4QftNw5G7Cz47ct; Mon, 12 Jun 2023 13:50:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686577824; 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=Bih89TTzTL1Dex8Z8+1+oPVP3uDT7Gl46hGRgJArKww=; b=dHoiNutGImsUJr7vOdysza1+oJ4E3eAGfX0O+hPs3XifnEFoN4GtZPJkq4lNgubuH7yX79 ZwACmzrYeYsl3nqfkLviSVg9QpTEcupqZR/nFKkxCx6/SAfYHJOvr6anwHTgo3UNHnCSRK GSWv23vbxe2YRVj2MZGipjfwUmdm4prFJEksNrlUFPpbKQ2FxRlhgPjtQXRyWVuhz4GfNM zTFrpriFglEKH+Qy1Eoqjbx6TR7f1/LSCAwltmSVY/Z0O7VNQJ7F230VQBFgNhyWHjS5Wl ihtLNsGdUz5x0lwyXCV99GTmvwLUtfSkYQK5nwh6aDGXGthzKC1MSXL+q6M3aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686577824; 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=Bih89TTzTL1Dex8Z8+1+oPVP3uDT7Gl46hGRgJArKww=; b=S6s4RMa2nKNdJktG0TNYfKwSOmcWmNpp+G26Axno6mmQNhla1plNy23w3tAE9OyVGFIVsK 4wUvSJDmrTZ+omXY2l7jFPLSQSBKp8zvfiqYDr+Qg37+fYKACM/roU8JbE3aaGt7ZctxHl hVbNllFw2yYMNubs5u6PvNjRL3xcHUJszBcrR7pENsbyGDrfkn1cx3Iqo1hQiwJxYGXV51 ogffNJArN5BHHvjLKIvGhDQoYOZ2Cwpmn+Yszy7tWbaQ5lB9DWoSXwJNDxyvydetVF7rg2 BLuEOQiB4/U78GUbESIPG2K9t5C7yYW8spEiVPHNWrjOKZElkJnZ6PlmnBgnpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686577824; a=rsa-sha256; cv=none; b=TZSnYtTA74raNoqFGxbKLzEpJIalpgQCpoQ/TEkpYhxK45+K+4TyWGWbwgVS3uu8BZ8MZb 1AdHgdak2AdrpxYplziXSLVWustiDZpIpSArV9O52RnTB6YDFeECM+PKEHN5bjwaJdyncF VdV/vdcN24QfuSwE0LTBX0+LChhMZmYVQjCHnb//xvLge/esxyRkDf2zI4FQ6+jOl3QScA fuOwE8Fcyo1GUraJpUiIa5kptrA64cHADTqqc9cHulc0MfbzZjWMG/JmVfwDa0R6NNVVl9 USnEjyYeE1CJtW/sPPSCIUVg/pghzc3p+kKeIK4BEH7NSbAAa9Q/ogjGcuewFA== 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 4QftNw4BTNzj2s; Mon, 12 Jun 2023 13:50:24 +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 35CDoOUC089429; Mon, 12 Jun 2023 13:50:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35CDoOFU089428; Mon, 12 Jun 2023 13:50:24 GMT (envelope-from git) Date: Mon, 12 Jun 2023 13:50:24 GMT Message-Id: <202306121350.35CDoOFU089428@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 3c236686822b - stable/13 - riscv: S-mode extension parsing List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 3c236686822bdf60a322e69f2a6ce0249f2eb8dc Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=3c236686822bdf60a322e69f2a6ce0249f2eb8dc commit 3c236686822bdf60a322e69f2a6ce0249f2eb8dc Author: Mitchell Horne AuthorDate: 2023-05-25 17:07:26 +0000 Commit: Mitchell Horne CommitDate: 2023-06-12 13:49:54 +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 (cherry picked from commit 8bebb786820f634d47522711b8cd56a66db3785d) --- 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 dafab6530024..a9a2542f70b6 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++; @@ -383,6 +416,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 } @@ -482,5 +519,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 }