1b902ff29SWeiwei Li /* 2b902ff29SWeiwei Li * QEMU RISC-V CPU CFG 3b902ff29SWeiwei Li * 4b902ff29SWeiwei Li * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu 5b902ff29SWeiwei Li * Copyright (c) 2017-2018 SiFive, Inc. 6b902ff29SWeiwei Li * Copyright (c) 2021-2023 PLCT Lab 7b902ff29SWeiwei Li * 8b902ff29SWeiwei Li * This program is free software; you can redistribute it and/or modify it 9b902ff29SWeiwei Li * under the terms and conditions of the GNU General Public License, 10b902ff29SWeiwei Li * version 2 or later, as published by the Free Software Foundation. 11b902ff29SWeiwei Li * 12b902ff29SWeiwei Li * This program is distributed in the hope it will be useful, but WITHOUT 13b902ff29SWeiwei Li * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14b902ff29SWeiwei Li * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15b902ff29SWeiwei Li * more details. 16b902ff29SWeiwei Li * 17b902ff29SWeiwei Li * You should have received a copy of the GNU General Public License along with 18b902ff29SWeiwei Li * this program. If not, see <http://www.gnu.org/licenses/>. 19b902ff29SWeiwei Li */ 20b902ff29SWeiwei Li 21b902ff29SWeiwei Li #ifndef RISCV_CPU_CFG_H 22b902ff29SWeiwei Li #define RISCV_CPU_CFG_H 23b902ff29SWeiwei Li 24b902ff29SWeiwei Li /* 25b902ff29SWeiwei Li * map is a 16-bit bitmap: the most significant set bit in map is the maximum 26b902ff29SWeiwei Li * satp mode that is supported. It may be chosen by the user and must respect 27b902ff29SWeiwei Li * what qemu implements (valid_1_10_32/64) and what the hw is capable of 28b902ff29SWeiwei Li * (supported bitmap below). 29b902ff29SWeiwei Li * 30b902ff29SWeiwei Li * init is a 16-bit bitmap used to make sure the user selected a correct 31b902ff29SWeiwei Li * configuration as per the specification. 32b902ff29SWeiwei Li * 33b902ff29SWeiwei Li * supported is a 16-bit bitmap used to reflect the hw capabilities. 34b902ff29SWeiwei Li */ 35b902ff29SWeiwei Li typedef struct { 36b902ff29SWeiwei Li uint16_t map, init, supported; 37b902ff29SWeiwei Li } RISCVSATPMap; 38b902ff29SWeiwei Li 39b902ff29SWeiwei Li struct RISCVCPUConfig { 40b902ff29SWeiwei Li bool ext_zba; 41b902ff29SWeiwei Li bool ext_zbb; 42b902ff29SWeiwei Li bool ext_zbc; 43b902ff29SWeiwei Li bool ext_zbkb; 44b902ff29SWeiwei Li bool ext_zbkc; 45b902ff29SWeiwei Li bool ext_zbkx; 46b902ff29SWeiwei Li bool ext_zbs; 47b902ff29SWeiwei Li bool ext_zca; 48b902ff29SWeiwei Li bool ext_zcb; 49b902ff29SWeiwei Li bool ext_zcd; 50b902ff29SWeiwei Li bool ext_zce; 51b902ff29SWeiwei Li bool ext_zcf; 52b902ff29SWeiwei Li bool ext_zcmp; 53b902ff29SWeiwei Li bool ext_zcmt; 54b902ff29SWeiwei Li bool ext_zk; 55b902ff29SWeiwei Li bool ext_zkn; 56b902ff29SWeiwei Li bool ext_zknd; 57b902ff29SWeiwei Li bool ext_zkne; 58b902ff29SWeiwei Li bool ext_zknh; 59b902ff29SWeiwei Li bool ext_zkr; 60b902ff29SWeiwei Li bool ext_zks; 61b902ff29SWeiwei Li bool ext_zksed; 62b902ff29SWeiwei Li bool ext_zksh; 63b902ff29SWeiwei Li bool ext_zkt; 6412b12a14SDaniel Henrique Barboza bool ext_zifencei; 65c0040993SDaniel Henrique Barboza bool ext_zicntr; 66960b389bSDaniel Henrique Barboza bool ext_zicsr; 67a326a2b0SDaniel Henrique Barboza bool ext_zicbom; 68cc2bf69aSDaniel Henrique Barboza bool ext_zicbop; 69e57039ddSDaniel Henrique Barboza bool ext_zicboz; 70b902ff29SWeiwei Li bool ext_zicond; 710228aca2SJason Chien bool ext_zihintntl; 72b902ff29SWeiwei Li bool ext_zihintpause; 7308241216SDaniel Henrique Barboza bool ext_zihpm; 7409c4e887SPalmer Dabbelt bool ext_ztso; 75b902ff29SWeiwei Li bool ext_smstateen; 76b902ff29SWeiwei Li bool ext_sstc; 77b902ff29SWeiwei Li bool ext_svadu; 78b902ff29SWeiwei Li bool ext_svinval; 79b902ff29SWeiwei Li bool ext_svnapot; 80b902ff29SWeiwei Li bool ext_svpbmt; 81b902ff29SWeiwei Li bool ext_zdinx; 828caeda5bSRob Bradford bool ext_zaamo; 83b52d49e9SWeiwei Li bool ext_zacas; 848caeda5bSRob Bradford bool ext_zalrsc; 85b902ff29SWeiwei Li bool ext_zawrs; 86a47842d1SChristoph Müllner bool ext_zfa; 874556fdaaSWeiwei Li bool ext_zfbfmin; 88b902ff29SWeiwei Li bool ext_zfh; 89b902ff29SWeiwei Li bool ext_zfhmin; 90b902ff29SWeiwei Li bool ext_zfinx; 91b902ff29SWeiwei Li bool ext_zhinx; 92b902ff29SWeiwei Li bool ext_zhinxmin; 93b902ff29SWeiwei Li bool ext_zve32f; 949fb41a44SJason Chien bool ext_zve32x; 95b902ff29SWeiwei Li bool ext_zve64f; 96b902ff29SWeiwei Li bool ext_zve64d; 97*e7dc5e16SJason Chien bool ext_zve64x; 9806028472SDickon Hood bool ext_zvbb; 99e13c7d3bSLawrence Hunter bool ext_zvbc; 100389b2e70SMax Chou bool ext_zvkb; 101767eb035SNazar Kazakov bool ext_zvkg; 102e972bf22SNazar Kazakov bool ext_zvkned; 103fcf19433SKiran Ostrolenk bool ext_zvknha; 104fcf19433SKiran Ostrolenk bool ext_zvknhb; 1058b045ff4SMax Chou bool ext_zvksed; 1062350881cSLawrence Hunter bool ext_zvksh; 1075ddbc83fSMax Chou bool ext_zvkt; 1087cdc8ddbSMax Chou bool ext_zvkn; 1097cdc8ddbSMax Chou bool ext_zvknc; 1107cdc8ddbSMax Chou bool ext_zvkng; 1118f913d10SMax Chou bool ext_zvks; 1128f913d10SMax Chou bool ext_zvksc; 1138f913d10SMax Chou bool ext_zvksg; 114b902ff29SWeiwei Li bool ext_zmmul; 1154556fdaaSWeiwei Li bool ext_zvfbfmin; 1164556fdaaSWeiwei Li bool ext_zvfbfwma; 117b902ff29SWeiwei Li bool ext_zvfh; 118b902ff29SWeiwei Li bool ext_zvfhmin; 119b902ff29SWeiwei Li bool ext_smaia; 120b902ff29SWeiwei Li bool ext_ssaia; 121b902ff29SWeiwei Li bool ext_sscofpmf; 122095fe72aSHimanshu Chauhan bool ext_smepmp; 123b902ff29SWeiwei Li bool rvv_ta_all_1s; 124b902ff29SWeiwei Li bool rvv_ma_all_1s; 125b902ff29SWeiwei Li 126b902ff29SWeiwei Li uint32_t mvendorid; 127b902ff29SWeiwei Li uint64_t marchid; 128b902ff29SWeiwei Li uint64_t mimpid; 129b902ff29SWeiwei Li 1303b802226SDaniel Henrique Barboza /* Named features */ 1313b802226SDaniel Henrique Barboza bool ext_svade; 1323b802226SDaniel Henrique Barboza bool ext_zic64b; 1333b802226SDaniel Henrique Barboza 134a0952c15SDaniel Henrique Barboza /* 13568c9e54bSDaniel Henrique Barboza * Always 'true' booleans for named features 13668c9e54bSDaniel Henrique Barboza * TCG always implement/can't be user disabled, 13768c9e54bSDaniel Henrique Barboza * based on spec version. 138a0952c15SDaniel Henrique Barboza */ 13968c9e54bSDaniel Henrique Barboza bool has_priv_1_12; 14068c9e54bSDaniel Henrique Barboza bool has_priv_1_11; 141a0952c15SDaniel Henrique Barboza 142b902ff29SWeiwei Li /* Vendor-specific custom extensions */ 143b902ff29SWeiwei Li bool ext_xtheadba; 144b902ff29SWeiwei Li bool ext_xtheadbb; 145b902ff29SWeiwei Li bool ext_xtheadbs; 146b902ff29SWeiwei Li bool ext_xtheadcmo; 147b902ff29SWeiwei Li bool ext_xtheadcondmov; 148b902ff29SWeiwei Li bool ext_xtheadfmemidx; 149b902ff29SWeiwei Li bool ext_xtheadfmv; 150b902ff29SWeiwei Li bool ext_xtheadmac; 151b902ff29SWeiwei Li bool ext_xtheadmemidx; 152b902ff29SWeiwei Li bool ext_xtheadmempair; 153b902ff29SWeiwei Li bool ext_xtheadsync; 154b902ff29SWeiwei Li bool ext_XVentanaCondOps; 155b902ff29SWeiwei Li 15669b3849bSRob Bradford uint32_t pmu_mask; 15704eb30a0SDaniel Henrique Barboza uint16_t vlenb; 158b902ff29SWeiwei Li uint16_t elen; 159b902ff29SWeiwei Li uint16_t cbom_blocksize; 160cc2bf69aSDaniel Henrique Barboza uint16_t cbop_blocksize; 161b902ff29SWeiwei Li uint16_t cboz_blocksize; 162b902ff29SWeiwei Li bool mmu; 163b902ff29SWeiwei Li bool pmp; 164b902ff29SWeiwei Li bool debug; 165b902ff29SWeiwei Li bool misa_w; 166b902ff29SWeiwei Li 167b902ff29SWeiwei Li bool short_isa_string; 168b902ff29SWeiwei Li 169b902ff29SWeiwei Li #ifndef CONFIG_USER_ONLY 170b902ff29SWeiwei Li RISCVSATPMap satp_mode; 171b902ff29SWeiwei Li #endif 172b902ff29SWeiwei Li }; 173b902ff29SWeiwei Li 174b902ff29SWeiwei Li typedef struct RISCVCPUConfig RISCVCPUConfig; 1752e8c1e02SChristoph Müllner 1762e8c1e02SChristoph Müllner /* Helper functions to test for extensions. */ 1772e8c1e02SChristoph Müllner always_true_p(const RISCVCPUConfig * cfg)1782e8c1e02SChristoph Müllnerstatic inline bool always_true_p(const RISCVCPUConfig *cfg __attribute__((__unused__))) 1792e8c1e02SChristoph Müllner { 1802e8c1e02SChristoph Müllner return true; 1812e8c1e02SChristoph Müllner } 1822e8c1e02SChristoph Müllner has_xthead_p(const RISCVCPUConfig * cfg)1832e8c1e02SChristoph Müllnerstatic inline bool has_xthead_p(const RISCVCPUConfig *cfg) 1842e8c1e02SChristoph Müllner { 1852e8c1e02SChristoph Müllner return cfg->ext_xtheadba || cfg->ext_xtheadbb || 1862e8c1e02SChristoph Müllner cfg->ext_xtheadbs || cfg->ext_xtheadcmo || 1872e8c1e02SChristoph Müllner cfg->ext_xtheadcondmov || 1882e8c1e02SChristoph Müllner cfg->ext_xtheadfmemidx || cfg->ext_xtheadfmv || 1892e8c1e02SChristoph Müllner cfg->ext_xtheadmac || cfg->ext_xtheadmemidx || 1902e8c1e02SChristoph Müllner cfg->ext_xtheadmempair || cfg->ext_xtheadsync; 1912e8c1e02SChristoph Müllner } 1922e8c1e02SChristoph Müllner 1932e8c1e02SChristoph Müllner #define MATERIALISE_EXT_PREDICATE(ext) \ 1942e8c1e02SChristoph Müllner static inline bool has_ ## ext ## _p(const RISCVCPUConfig *cfg) \ 1952e8c1e02SChristoph Müllner { \ 1962e8c1e02SChristoph Müllner return cfg->ext_ ## ext ; \ 1972e8c1e02SChristoph Müllner } 1982e8c1e02SChristoph Müllner 199318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadba) 200318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadbb) 201318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadbs) 202318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadcmo) 203318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadcondmov) 204318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadfmemidx) 205318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadfmv) 206318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadmac) 207318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadmemidx) 208318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadmempair) 209318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadsync) 2102e8c1e02SChristoph Müllner MATERIALISE_EXT_PREDICATE(XVentanaCondOps) 2112e8c1e02SChristoph Müllner 212b902ff29SWeiwei Li #endif 213