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; 70bd08b22eSDeepak Gupta bool ext_zicfilp; 71*cf064a67SDeepak Gupta bool ext_zicfiss; 72b902ff29SWeiwei Li bool ext_zicond; 730228aca2SJason Chien bool ext_zihintntl; 74b902ff29SWeiwei Li bool ext_zihintpause; 7508241216SDaniel Henrique Barboza bool ext_zihpm; 766eab278dSLIU Zhiwei bool ext_zimop; 77197e4d29SLIU Zhiwei bool ext_zcmop; 7809c4e887SPalmer Dabbelt bool ext_ztso; 79b902ff29SWeiwei Li bool ext_smstateen; 80b902ff29SWeiwei Li bool ext_sstc; 81251dccc0SKaiwen Xue bool ext_smcntrpmf; 82b902ff29SWeiwei Li bool ext_svadu; 83b902ff29SWeiwei Li bool ext_svinval; 84b902ff29SWeiwei Li bool ext_svnapot; 85b902ff29SWeiwei Li bool ext_svpbmt; 865b876419SAlexandre Ghiti bool ext_svvptc; 87b902ff29SWeiwei Li bool ext_zdinx; 888caeda5bSRob Bradford bool ext_zaamo; 89b52d49e9SWeiwei Li bool ext_zacas; 90a60ce58fSLIU Zhiwei bool ext_zama16b; 91be4a8db7SLIU Zhiwei bool ext_zabha; 928caeda5bSRob Bradford bool ext_zalrsc; 93b902ff29SWeiwei Li bool ext_zawrs; 94a47842d1SChristoph Müllner bool ext_zfa; 954556fdaaSWeiwei Li bool ext_zfbfmin; 96b902ff29SWeiwei Li bool ext_zfh; 97b902ff29SWeiwei Li bool ext_zfhmin; 98b902ff29SWeiwei Li bool ext_zfinx; 99b902ff29SWeiwei Li bool ext_zhinx; 100b902ff29SWeiwei Li bool ext_zhinxmin; 101b902ff29SWeiwei Li bool ext_zve32f; 1029fb41a44SJason Chien bool ext_zve32x; 103b902ff29SWeiwei Li bool ext_zve64f; 104b902ff29SWeiwei Li bool ext_zve64d; 105e7dc5e16SJason Chien bool ext_zve64x; 10606028472SDickon Hood bool ext_zvbb; 107e13c7d3bSLawrence Hunter bool ext_zvbc; 108389b2e70SMax Chou bool ext_zvkb; 109767eb035SNazar Kazakov bool ext_zvkg; 110e972bf22SNazar Kazakov bool ext_zvkned; 111fcf19433SKiran Ostrolenk bool ext_zvknha; 112fcf19433SKiran Ostrolenk bool ext_zvknhb; 1138b045ff4SMax Chou bool ext_zvksed; 1142350881cSLawrence Hunter bool ext_zvksh; 1155ddbc83fSMax Chou bool ext_zvkt; 1167cdc8ddbSMax Chou bool ext_zvkn; 1177cdc8ddbSMax Chou bool ext_zvknc; 1187cdc8ddbSMax Chou bool ext_zvkng; 1198f913d10SMax Chou bool ext_zvks; 1208f913d10SMax Chou bool ext_zvksc; 1218f913d10SMax Chou bool ext_zvksg; 122b902ff29SWeiwei Li bool ext_zmmul; 1234556fdaaSWeiwei Li bool ext_zvfbfmin; 1244556fdaaSWeiwei Li bool ext_zvfbfwma; 125b902ff29SWeiwei Li bool ext_zvfh; 126b902ff29SWeiwei Li bool ext_zvfhmin; 127b902ff29SWeiwei Li bool ext_smaia; 128b902ff29SWeiwei Li bool ext_ssaia; 129b902ff29SWeiwei Li bool ext_sscofpmf; 130095fe72aSHimanshu Chauhan bool ext_smepmp; 131b902ff29SWeiwei Li bool rvv_ta_all_1s; 132b902ff29SWeiwei Li bool rvv_ma_all_1s; 13312f1e2ecSJason Chien bool rvv_vl_half_avl; 134b902ff29SWeiwei Li 135b902ff29SWeiwei Li uint32_t mvendorid; 136b902ff29SWeiwei Li uint64_t marchid; 137b902ff29SWeiwei Li uint64_t mimpid; 138b902ff29SWeiwei Li 1393b802226SDaniel Henrique Barboza /* Named features */ 1403b802226SDaniel Henrique Barboza bool ext_svade; 1413b802226SDaniel Henrique Barboza bool ext_zic64b; 1423b802226SDaniel Henrique Barboza 143a0952c15SDaniel Henrique Barboza /* 14468c9e54bSDaniel Henrique Barboza * Always 'true' booleans for named features 14568c9e54bSDaniel Henrique Barboza * TCG always implement/can't be user disabled, 14668c9e54bSDaniel Henrique Barboza * based on spec version. 147a0952c15SDaniel Henrique Barboza */ 1480c2d5f73SFea.Wang bool has_priv_1_13; 14968c9e54bSDaniel Henrique Barboza bool has_priv_1_12; 15068c9e54bSDaniel Henrique Barboza bool has_priv_1_11; 151a0952c15SDaniel Henrique Barboza 152b902ff29SWeiwei Li /* Vendor-specific custom extensions */ 153b902ff29SWeiwei Li bool ext_xtheadba; 154b902ff29SWeiwei Li bool ext_xtheadbb; 155b902ff29SWeiwei Li bool ext_xtheadbs; 156b902ff29SWeiwei Li bool ext_xtheadcmo; 157b902ff29SWeiwei Li bool ext_xtheadcondmov; 158b902ff29SWeiwei Li bool ext_xtheadfmemidx; 159b902ff29SWeiwei Li bool ext_xtheadfmv; 160b902ff29SWeiwei Li bool ext_xtheadmac; 161b902ff29SWeiwei Li bool ext_xtheadmemidx; 162b902ff29SWeiwei Li bool ext_xtheadmempair; 163b902ff29SWeiwei Li bool ext_xtheadsync; 164b902ff29SWeiwei Li bool ext_XVentanaCondOps; 165b902ff29SWeiwei Li 16669b3849bSRob Bradford uint32_t pmu_mask; 16704eb30a0SDaniel Henrique Barboza uint16_t vlenb; 168b902ff29SWeiwei Li uint16_t elen; 169b902ff29SWeiwei Li uint16_t cbom_blocksize; 170cc2bf69aSDaniel Henrique Barboza uint16_t cbop_blocksize; 171b902ff29SWeiwei Li uint16_t cboz_blocksize; 172b902ff29SWeiwei Li bool mmu; 173b902ff29SWeiwei Li bool pmp; 174b902ff29SWeiwei Li bool debug; 175b902ff29SWeiwei Li bool misa_w; 176b902ff29SWeiwei Li 177b902ff29SWeiwei Li bool short_isa_string; 178b902ff29SWeiwei Li 179b902ff29SWeiwei Li #ifndef CONFIG_USER_ONLY 180b902ff29SWeiwei Li RISCVSATPMap satp_mode; 181b902ff29SWeiwei Li #endif 182b902ff29SWeiwei Li }; 183b902ff29SWeiwei Li 184b902ff29SWeiwei Li typedef struct RISCVCPUConfig RISCVCPUConfig; 1852e8c1e02SChristoph Müllner 1862e8c1e02SChristoph Müllner /* Helper functions to test for extensions. */ 1872e8c1e02SChristoph Müllner always_true_p(const RISCVCPUConfig * cfg)1882e8c1e02SChristoph Müllnerstatic inline bool always_true_p(const RISCVCPUConfig *cfg __attribute__((__unused__))) 1892e8c1e02SChristoph Müllner { 1902e8c1e02SChristoph Müllner return true; 1912e8c1e02SChristoph Müllner } 1922e8c1e02SChristoph Müllner has_xthead_p(const RISCVCPUConfig * cfg)1932e8c1e02SChristoph Müllnerstatic inline bool has_xthead_p(const RISCVCPUConfig *cfg) 1942e8c1e02SChristoph Müllner { 1952e8c1e02SChristoph Müllner return cfg->ext_xtheadba || cfg->ext_xtheadbb || 1962e8c1e02SChristoph Müllner cfg->ext_xtheadbs || cfg->ext_xtheadcmo || 1972e8c1e02SChristoph Müllner cfg->ext_xtheadcondmov || 1982e8c1e02SChristoph Müllner cfg->ext_xtheadfmemidx || cfg->ext_xtheadfmv || 1992e8c1e02SChristoph Müllner cfg->ext_xtheadmac || cfg->ext_xtheadmemidx || 2002e8c1e02SChristoph Müllner cfg->ext_xtheadmempair || cfg->ext_xtheadsync; 2012e8c1e02SChristoph Müllner } 2022e8c1e02SChristoph Müllner 2032e8c1e02SChristoph Müllner #define MATERIALISE_EXT_PREDICATE(ext) \ 2042e8c1e02SChristoph Müllner static inline bool has_ ## ext ## _p(const RISCVCPUConfig *cfg) \ 2052e8c1e02SChristoph Müllner { \ 2062e8c1e02SChristoph Müllner return cfg->ext_ ## ext ; \ 2072e8c1e02SChristoph Müllner } 2082e8c1e02SChristoph Müllner 209318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadba) 210318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadbb) 211318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadbs) 212318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadcmo) 213318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadcondmov) 214318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadfmemidx) 215318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadfmv) 216318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadmac) 217318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadmemidx) 218318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadmempair) 219318df723SChristoph Müllner MATERIALISE_EXT_PREDICATE(xtheadsync) 2202e8c1e02SChristoph Müllner MATERIALISE_EXT_PREDICATE(XVentanaCondOps) 2212e8c1e02SChristoph Müllner 222b902ff29SWeiwei Li #endif 223