xref: /qemu/target/riscv/cpu_cfg.h (revision 8b7b9c5c)
1 /*
2  * QEMU RISC-V CPU CFG
3  *
4  * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
5  * Copyright (c) 2017-2018 SiFive, Inc.
6  * Copyright (c) 2021-2023 PLCT Lab
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2 or later, as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef RISCV_CPU_CFG_H
22 #define RISCV_CPU_CFG_H
23 
24 /*
25  * map is a 16-bit bitmap: the most significant set bit in map is the maximum
26  * satp mode that is supported. It may be chosen by the user and must respect
27  * what qemu implements (valid_1_10_32/64) and what the hw is capable of
28  * (supported bitmap below).
29  *
30  * init is a 16-bit bitmap used to make sure the user selected a correct
31  * configuration as per the specification.
32  *
33  * supported is a 16-bit bitmap used to reflect the hw capabilities.
34  */
35 typedef struct {
36     uint16_t map, init, supported;
37 } RISCVSATPMap;
38 
39 struct RISCVCPUConfig {
40     bool ext_zba;
41     bool ext_zbb;
42     bool ext_zbc;
43     bool ext_zbkb;
44     bool ext_zbkc;
45     bool ext_zbkx;
46     bool ext_zbs;
47     bool ext_zca;
48     bool ext_zcb;
49     bool ext_zcd;
50     bool ext_zce;
51     bool ext_zcf;
52     bool ext_zcmp;
53     bool ext_zcmt;
54     bool ext_zk;
55     bool ext_zkn;
56     bool ext_zknd;
57     bool ext_zkne;
58     bool ext_zknh;
59     bool ext_zkr;
60     bool ext_zks;
61     bool ext_zksed;
62     bool ext_zksh;
63     bool ext_zkt;
64     bool ext_ifencei;
65     bool ext_icsr;
66     bool ext_icbom;
67     bool ext_icboz;
68     bool ext_zicond;
69     bool ext_zihintntl;
70     bool ext_zihintpause;
71     bool ext_smstateen;
72     bool ext_sstc;
73     bool ext_svadu;
74     bool ext_svinval;
75     bool ext_svnapot;
76     bool ext_svpbmt;
77     bool ext_zdinx;
78     bool ext_zawrs;
79     bool ext_zfa;
80     bool ext_zfbfmin;
81     bool ext_zfh;
82     bool ext_zfhmin;
83     bool ext_zfinx;
84     bool ext_zhinx;
85     bool ext_zhinxmin;
86     bool ext_zve32f;
87     bool ext_zve64f;
88     bool ext_zve64d;
89     bool ext_zvbb;
90     bool ext_zvbc;
91     bool ext_zvkg;
92     bool ext_zvkned;
93     bool ext_zvknha;
94     bool ext_zvknhb;
95     bool ext_zvksed;
96     bool ext_zvksh;
97     bool ext_zmmul;
98     bool ext_zvfbfmin;
99     bool ext_zvfbfwma;
100     bool ext_zvfh;
101     bool ext_zvfhmin;
102     bool ext_smaia;
103     bool ext_ssaia;
104     bool ext_sscofpmf;
105     bool rvv_ta_all_1s;
106     bool rvv_ma_all_1s;
107 
108     uint32_t mvendorid;
109     uint64_t marchid;
110     uint64_t mimpid;
111 
112     /* Vendor-specific custom extensions */
113     bool ext_xtheadba;
114     bool ext_xtheadbb;
115     bool ext_xtheadbs;
116     bool ext_xtheadcmo;
117     bool ext_xtheadcondmov;
118     bool ext_xtheadfmemidx;
119     bool ext_xtheadfmv;
120     bool ext_xtheadmac;
121     bool ext_xtheadmemidx;
122     bool ext_xtheadmempair;
123     bool ext_xtheadsync;
124     bool ext_XVentanaCondOps;
125 
126     uint8_t pmu_num;
127     char *priv_spec;
128     char *user_spec;
129     char *bext_spec;
130     char *vext_spec;
131     uint16_t vlen;
132     uint16_t elen;
133     uint16_t cbom_blocksize;
134     uint16_t cboz_blocksize;
135     bool mmu;
136     bool pmp;
137     bool epmp;
138     bool debug;
139     bool misa_w;
140 
141     bool short_isa_string;
142 
143 #ifndef CONFIG_USER_ONLY
144     RISCVSATPMap satp_mode;
145 #endif
146 };
147 
148 typedef struct RISCVCPUConfig RISCVCPUConfig;
149 
150 /* Helper functions to test for extensions.  */
151 
152 static inline bool always_true_p(const RISCVCPUConfig *cfg __attribute__((__unused__)))
153 {
154     return true;
155 }
156 
157 static inline bool has_xthead_p(const RISCVCPUConfig *cfg)
158 {
159     return cfg->ext_xtheadba || cfg->ext_xtheadbb ||
160            cfg->ext_xtheadbs || cfg->ext_xtheadcmo ||
161            cfg->ext_xtheadcondmov ||
162            cfg->ext_xtheadfmemidx || cfg->ext_xtheadfmv ||
163            cfg->ext_xtheadmac || cfg->ext_xtheadmemidx ||
164            cfg->ext_xtheadmempair || cfg->ext_xtheadsync;
165 }
166 
167 #define MATERIALISE_EXT_PREDICATE(ext) \
168     static inline bool has_ ## ext ## _p(const RISCVCPUConfig *cfg) \
169     { \
170         return cfg->ext_ ## ext ; \
171     }
172 
173 MATERIALISE_EXT_PREDICATE(xtheadba)
174 MATERIALISE_EXT_PREDICATE(xtheadbb)
175 MATERIALISE_EXT_PREDICATE(xtheadbs)
176 MATERIALISE_EXT_PREDICATE(xtheadcmo)
177 MATERIALISE_EXT_PREDICATE(xtheadcondmov)
178 MATERIALISE_EXT_PREDICATE(xtheadfmemidx)
179 MATERIALISE_EXT_PREDICATE(xtheadfmv)
180 MATERIALISE_EXT_PREDICATE(xtheadmac)
181 MATERIALISE_EXT_PREDICATE(xtheadmemidx)
182 MATERIALISE_EXT_PREDICATE(xtheadmempair)
183 MATERIALISE_EXT_PREDICATE(xtheadsync)
184 MATERIALISE_EXT_PREDICATE(XVentanaCondOps)
185 
186 #endif
187