2023-05-23 12:35:33 +03:00
|
|
|
/*
|
|
|
|
* QEMU RISC-V CPU CFG
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
|
|
|
|
* Copyright (c) 2017-2018 SiFive, Inc.
|
|
|
|
* Copyright (c) 2021-2023 PLCT Lab
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RISCV_CPU_CFG_H
|
|
|
|
#define RISCV_CPU_CFG_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* map is a 16-bit bitmap: the most significant set bit in map is the maximum
|
|
|
|
* satp mode that is supported. It may be chosen by the user and must respect
|
|
|
|
* what qemu implements (valid_1_10_32/64) and what the hw is capable of
|
|
|
|
* (supported bitmap below).
|
|
|
|
*
|
|
|
|
* init is a 16-bit bitmap used to make sure the user selected a correct
|
|
|
|
* configuration as per the specification.
|
|
|
|
*
|
|
|
|
* supported is a 16-bit bitmap used to reflect the hw capabilities.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uint16_t map, init, supported;
|
|
|
|
} RISCVSATPMap;
|
|
|
|
|
|
|
|
struct RISCVCPUConfig {
|
|
|
|
bool ext_zba;
|
|
|
|
bool ext_zbb;
|
|
|
|
bool ext_zbc;
|
|
|
|
bool ext_zbkb;
|
|
|
|
bool ext_zbkc;
|
|
|
|
bool ext_zbkx;
|
|
|
|
bool ext_zbs;
|
|
|
|
bool ext_zca;
|
|
|
|
bool ext_zcb;
|
|
|
|
bool ext_zcd;
|
|
|
|
bool ext_zce;
|
|
|
|
bool ext_zcf;
|
|
|
|
bool ext_zcmp;
|
|
|
|
bool ext_zcmt;
|
|
|
|
bool ext_zk;
|
|
|
|
bool ext_zkn;
|
|
|
|
bool ext_zknd;
|
|
|
|
bool ext_zkne;
|
|
|
|
bool ext_zknh;
|
|
|
|
bool ext_zkr;
|
|
|
|
bool ext_zks;
|
|
|
|
bool ext_zksed;
|
|
|
|
bool ext_zksh;
|
|
|
|
bool ext_zkt;
|
2023-10-12 19:46:01 +03:00
|
|
|
bool ext_zifencei;
|
target/riscv: add zicntr extension flag for TCG
zicntr is the Base Counters and Timers extension described in chapter 12
of the unprivileged spec. It describes support for RDCYCLE, RDTIME and
RDINSTRET.
QEMU already implements it in TCG way before it was a discrete
extension. zicntr is part of the RVA22 profile, so let's add it to QEMU
to make the future profile implementation flag complete. Given than it
represents an already existing feature, default it to 'true' for all
CPUs.
For TCG, we need a way to disable zicntr if the user wants to. This is
done by restricting access to the CYCLE, TIME, and INSTRET counters via
the 'ctr()' predicate when we're about to access them.
Disabling zicntr happens via the command line or if its dependency,
zicsr, happens to be disabled. We'll check for zicsr during realize()
and, in case it's absent, disable zicntr. However, if the user was
explicit about having zicntr support, error out instead of disabling it.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20231023153927.435083-2-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2023-10-23 18:39:24 +03:00
|
|
|
bool ext_zicntr;
|
2023-10-12 19:46:02 +03:00
|
|
|
bool ext_zicsr;
|
2023-10-12 19:46:03 +03:00
|
|
|
bool ext_zicbom;
|
2023-12-18 15:53:13 +03:00
|
|
|
bool ext_zicbop;
|
2023-10-12 19:46:04 +03:00
|
|
|
bool ext_zicboz;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool ext_zicond;
|
target/riscv: Add Zihintntl extension ISA string to DTS
RVA23 Profiles states:
The RVA23 profiles are intended to be used for 64-bit application
processors that will run rich OS stacks from standard binary OS
distributions and with a substantial number of third-party binary user
applications that will be supported over a considerable length of time
in the field.
The chapter 4 of the unprivileged spec introduces the Zihintntl extension
and Zihintntl is a mandatory extension presented in RVA23 Profiles, whose
purpose is to enable application and operating system portability across
different implementations. Thus the DTS should contain the Zihintntl ISA
string in order to pass to software.
The unprivileged spec states:
Like any HINTs, these instructions may be freely ignored. Hence, although
they are described in terms of cache-based memory hierarchies, they do not
mandate the provision of caches.
These instructions are encoded with non-used opcode, e.g. ADD x0, x0, x2,
which QEMU already supports, and QEMU does not emulate cache. Therefore
these instructions can be considered as a no-op, and we only need to add
a new property for the Zihintntl extension.
Reviewed-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Jason Chien <jason.chien@sifive.com>
Message-ID: <20230726074049.19505-2-jason.chien@sifive.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2023-07-26 10:40:46 +03:00
|
|
|
bool ext_zihintntl;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool ext_zihintpause;
|
2023-10-23 18:39:26 +03:00
|
|
|
bool ext_zihpm;
|
2024-02-07 15:22:54 +03:00
|
|
|
bool ext_ztso;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool ext_smstateen;
|
|
|
|
bool ext_sstc;
|
|
|
|
bool ext_svadu;
|
|
|
|
bool ext_svinval;
|
|
|
|
bool ext_svnapot;
|
|
|
|
bool ext_svpbmt;
|
|
|
|
bool ext_zdinx;
|
2024-01-23 14:10:28 +03:00
|
|
|
bool ext_zaamo;
|
2023-12-07 18:32:30 +03:00
|
|
|
bool ext_zacas;
|
2024-01-23 14:10:28 +03:00
|
|
|
bool ext_zalrsc;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool ext_zawrs;
|
2023-07-10 10:12:43 +03:00
|
|
|
bool ext_zfa;
|
2023-06-15 09:32:57 +03:00
|
|
|
bool ext_zfbfmin;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool ext_zfh;
|
|
|
|
bool ext_zfhmin;
|
|
|
|
bool ext_zfinx;
|
|
|
|
bool ext_zhinx;
|
|
|
|
bool ext_zhinxmin;
|
|
|
|
bool ext_zve32f;
|
2024-03-28 05:23:10 +03:00
|
|
|
bool ext_zve32x;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool ext_zve64f;
|
|
|
|
bool ext_zve64d;
|
2024-03-28 05:23:11 +03:00
|
|
|
bool ext_zve64x;
|
2023-07-11 19:59:07 +03:00
|
|
|
bool ext_zvbb;
|
2023-07-11 19:59:03 +03:00
|
|
|
bool ext_zvbc;
|
2023-10-26 18:18:10 +03:00
|
|
|
bool ext_zvkb;
|
2023-07-11 19:59:11 +03:00
|
|
|
bool ext_zvkg;
|
2023-07-11 19:59:08 +03:00
|
|
|
bool ext_zvkned;
|
2023-07-11 19:59:09 +03:00
|
|
|
bool ext_zvknha;
|
|
|
|
bool ext_zvknhb;
|
2023-07-11 19:59:14 +03:00
|
|
|
bool ext_zvksed;
|
2023-07-11 19:59:10 +03:00
|
|
|
bool ext_zvksh;
|
2023-10-26 18:18:08 +03:00
|
|
|
bool ext_zvkt;
|
2023-10-26 18:18:13 +03:00
|
|
|
bool ext_zvkn;
|
|
|
|
bool ext_zvknc;
|
|
|
|
bool ext_zvkng;
|
2023-10-26 18:18:15 +03:00
|
|
|
bool ext_zvks;
|
|
|
|
bool ext_zvksc;
|
|
|
|
bool ext_zvksg;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool ext_zmmul;
|
2023-06-15 09:32:57 +03:00
|
|
|
bool ext_zvfbfmin;
|
|
|
|
bool ext_zvfbfwma;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool ext_zvfh;
|
|
|
|
bool ext_zvfhmin;
|
|
|
|
bool ext_smaia;
|
|
|
|
bool ext_ssaia;
|
|
|
|
bool ext_sscofpmf;
|
2023-10-19 09:55:46 +03:00
|
|
|
bool ext_smepmp;
|
2023-05-23 12:35:33 +03:00
|
|
|
bool rvv_ta_all_1s;
|
|
|
|
bool rvv_ma_all_1s;
|
|
|
|
|
|
|
|
uint32_t mvendorid;
|
|
|
|
uint64_t marchid;
|
|
|
|
uint64_t mimpid;
|
|
|
|
|
2024-02-16 01:39:51 +03:00
|
|
|
/* Named features */
|
|
|
|
bool ext_svade;
|
|
|
|
bool ext_zic64b;
|
|
|
|
|
target/riscv: add remaining named features
The RVA22U64 and RVA22S64 profiles mandates certain extensions that,
until now, we were implying that they were available.
We can't do this anymore since named features also has a riscv,isa
entry. Let's add them to riscv_cpu_named_features[].
Instead of adding one bool for each named feature that we'll always
implement, i.e. can't be turned off, add a 'ext_always_enabled' bool in
cpu->cfg. This bool will be set to 'true' in TCG accel init, and all
named features will point to it. This also means that KVM won't see
these features as always enable, which is our intention.
If any accelerator adds support to disable one of these features, we'll
have to promote them to regular extensions and allow users to disable it
via command line.
After this patch, here's the riscv,isa from a buildroot using the
'rva22s64' CPU:
# cat /proc/device-tree/cpus/cpu@0/riscv,isa
rv64imafdc_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_
zicntr_zicsr_zifencei_zihintpause_zihpm_za64rs_zfhmin_zca_zcd_zba_zbb_
zbs_zkt_ssccptr_sscounterenw_sstvala_sstvecd_svade_svinval_svpbmt#
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Message-ID: <20240215223955.969568-4-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2024-02-16 01:39:52 +03:00
|
|
|
/*
|
2024-03-12 23:32:14 +03:00
|
|
|
* Always 'true' booleans for named features
|
|
|
|
* TCG always implement/can't be user disabled,
|
|
|
|
* based on spec version.
|
target/riscv: add remaining named features
The RVA22U64 and RVA22S64 profiles mandates certain extensions that,
until now, we were implying that they were available.
We can't do this anymore since named features also has a riscv,isa
entry. Let's add them to riscv_cpu_named_features[].
Instead of adding one bool for each named feature that we'll always
implement, i.e. can't be turned off, add a 'ext_always_enabled' bool in
cpu->cfg. This bool will be set to 'true' in TCG accel init, and all
named features will point to it. This also means that KVM won't see
these features as always enable, which is our intention.
If any accelerator adds support to disable one of these features, we'll
have to promote them to regular extensions and allow users to disable it
via command line.
After this patch, here's the riscv,isa from a buildroot using the
'rva22s64' CPU:
# cat /proc/device-tree/cpus/cpu@0/riscv,isa
rv64imafdc_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_
zicntr_zicsr_zifencei_zihintpause_zihpm_za64rs_zfhmin_zca_zcd_zba_zbb_
zbs_zkt_ssccptr_sscounterenw_sstvala_sstvecd_svade_svinval_svpbmt#
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Message-ID: <20240215223955.969568-4-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2024-02-16 01:39:52 +03:00
|
|
|
*/
|
2024-06-06 16:54:50 +03:00
|
|
|
bool has_priv_1_13;
|
2024-03-12 23:32:14 +03:00
|
|
|
bool has_priv_1_12;
|
|
|
|
bool has_priv_1_11;
|
target/riscv: add remaining named features
The RVA22U64 and RVA22S64 profiles mandates certain extensions that,
until now, we were implying that they were available.
We can't do this anymore since named features also has a riscv,isa
entry. Let's add them to riscv_cpu_named_features[].
Instead of adding one bool for each named feature that we'll always
implement, i.e. can't be turned off, add a 'ext_always_enabled' bool in
cpu->cfg. This bool will be set to 'true' in TCG accel init, and all
named features will point to it. This also means that KVM won't see
these features as always enable, which is our intention.
If any accelerator adds support to disable one of these features, we'll
have to promote them to regular extensions and allow users to disable it
via command line.
After this patch, here's the riscv,isa from a buildroot using the
'rva22s64' CPU:
# cat /proc/device-tree/cpus/cpu@0/riscv,isa
rv64imafdc_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_
zicntr_zicsr_zifencei_zihintpause_zihpm_za64rs_zfhmin_zca_zcd_zba_zbb_
zbs_zkt_ssccptr_sscounterenw_sstvala_sstvecd_svade_svinval_svpbmt#
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Message-ID: <20240215223955.969568-4-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2024-02-16 01:39:52 +03:00
|
|
|
|
2023-05-23 12:35:33 +03:00
|
|
|
/* Vendor-specific custom extensions */
|
|
|
|
bool ext_xtheadba;
|
|
|
|
bool ext_xtheadbb;
|
|
|
|
bool ext_xtheadbs;
|
|
|
|
bool ext_xtheadcmo;
|
|
|
|
bool ext_xtheadcondmov;
|
|
|
|
bool ext_xtheadfmemidx;
|
|
|
|
bool ext_xtheadfmv;
|
|
|
|
bool ext_xtheadmac;
|
|
|
|
bool ext_xtheadmemidx;
|
|
|
|
bool ext_xtheadmempair;
|
|
|
|
bool ext_xtheadsync;
|
|
|
|
bool ext_XVentanaCondOps;
|
|
|
|
|
2023-10-31 18:37:16 +03:00
|
|
|
uint32_t pmu_mask;
|
2024-01-22 19:10:55 +03:00
|
|
|
uint16_t vlenb;
|
2023-05-23 12:35:33 +03:00
|
|
|
uint16_t elen;
|
|
|
|
uint16_t cbom_blocksize;
|
2023-12-18 15:53:13 +03:00
|
|
|
uint16_t cbop_blocksize;
|
2023-05-23 12:35:33 +03:00
|
|
|
uint16_t cboz_blocksize;
|
|
|
|
bool mmu;
|
|
|
|
bool pmp;
|
|
|
|
bool debug;
|
|
|
|
bool misa_w;
|
|
|
|
|
|
|
|
bool short_isa_string;
|
|
|
|
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
RISCVSATPMap satp_mode;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct RISCVCPUConfig RISCVCPUConfig;
|
2023-06-12 14:10:28 +03:00
|
|
|
|
|
|
|
/* Helper functions to test for extensions. */
|
|
|
|
|
|
|
|
static inline bool always_true_p(const RISCVCPUConfig *cfg __attribute__((__unused__)))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool has_xthead_p(const RISCVCPUConfig *cfg)
|
|
|
|
{
|
|
|
|
return cfg->ext_xtheadba || cfg->ext_xtheadbb ||
|
|
|
|
cfg->ext_xtheadbs || cfg->ext_xtheadcmo ||
|
|
|
|
cfg->ext_xtheadcondmov ||
|
|
|
|
cfg->ext_xtheadfmemidx || cfg->ext_xtheadfmv ||
|
|
|
|
cfg->ext_xtheadmac || cfg->ext_xtheadmemidx ||
|
|
|
|
cfg->ext_xtheadmempair || cfg->ext_xtheadsync;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MATERIALISE_EXT_PREDICATE(ext) \
|
|
|
|
static inline bool has_ ## ext ## _p(const RISCVCPUConfig *cfg) \
|
|
|
|
{ \
|
|
|
|
return cfg->ext_ ## ext ; \
|
|
|
|
}
|
|
|
|
|
2023-06-12 14:10:34 +03:00
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadba)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadbb)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadbs)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadcmo)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadcondmov)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadfmemidx)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadfmv)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadmac)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadmemidx)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadmempair)
|
|
|
|
MATERIALISE_EXT_PREDICATE(xtheadsync)
|
2023-06-12 14:10:28 +03:00
|
|
|
MATERIALISE_EXT_PREDICATE(XVentanaCondOps)
|
|
|
|
|
2023-05-23 12:35:33 +03:00
|
|
|
#endif
|