@@ -111,6 +111,9 @@ static int riscv_ext_zicboz_validate(const struct riscv_isa_ext_data *data,
111
111
112
112
#define __RISCV_ISA_EXT_DATA (_name , _id ) _RISCV_ISA_EXT_DATA(_name, _id, NULL, 0, NULL)
113
113
114
+ #define __RISCV_ISA_EXT_DATA_VALIDATE (_name , _id , _validate ) \
115
+ _RISCV_ISA_EXT_DATA(_name, _id, NULL, 0, _validate)
116
+
114
117
/* Used to declare pure "lasso" extension (Zk for instance) */
115
118
#define __RISCV_ISA_EXT_BUNDLE (_name , _bundled_exts ) \
116
119
_RISCV_ISA_EXT_DATA(_name, RISCV_ISA_EXT_INVALID, _bundled_exts, \
@@ -122,6 +125,37 @@ static int riscv_ext_zicboz_validate(const struct riscv_isa_ext_data *data,
122
125
#define __RISCV_ISA_EXT_SUPERSET_VALIDATE (_name , _id , _sub_exts , _validate ) \
123
126
_RISCV_ISA_EXT_DATA(_name, _id, _sub_exts, ARRAY_SIZE(_sub_exts), _validate)
124
127
128
+ static int riscv_ext_zca_depends (const struct riscv_isa_ext_data * data ,
129
+ const unsigned long * isa_bitmap )
130
+ {
131
+ if (__riscv_isa_extension_available (isa_bitmap , RISCV_ISA_EXT_ZCA ))
132
+ return 0 ;
133
+
134
+ return - EPROBE_DEFER ;
135
+ }
136
+ static int riscv_ext_zcd_validate (const struct riscv_isa_ext_data * data ,
137
+ const unsigned long * isa_bitmap )
138
+ {
139
+ if (__riscv_isa_extension_available (isa_bitmap , RISCV_ISA_EXT_ZCA ) &&
140
+ __riscv_isa_extension_available (isa_bitmap , RISCV_ISA_EXT_d ))
141
+ return 0 ;
142
+
143
+ return - EPROBE_DEFER ;
144
+ }
145
+
146
+ static int riscv_ext_zcf_validate (const struct riscv_isa_ext_data * data ,
147
+ const unsigned long * isa_bitmap )
148
+ {
149
+ if (IS_ENABLED (CONFIG_64BIT ))
150
+ return - EINVAL ;
151
+
152
+ if (__riscv_isa_extension_available (isa_bitmap , RISCV_ISA_EXT_ZCA ) &&
153
+ __riscv_isa_extension_available (isa_bitmap , RISCV_ISA_EXT_f ))
154
+ return 0 ;
155
+
156
+ return - EPROBE_DEFER ;
157
+ }
158
+
125
159
static const unsigned int riscv_zk_bundled_exts [] = {
126
160
RISCV_ISA_EXT_ZBKB ,
127
161
RISCV_ISA_EXT_ZBKC ,
@@ -236,6 +270,21 @@ static const unsigned int riscv_xlinuxenvcfg_exts[] = {
236
270
RISCV_ISA_EXT_XLINUXENVCFG
237
271
};
238
272
273
+ /*
274
+ * Zc* spec states that:
275
+ * - C always implies Zca
276
+ * - C+F implies Zcf (RV32 only)
277
+ * - C+D implies Zcd
278
+ *
279
+ * These extensions will be enabled and then validated depending on the
280
+ * availability of F/D RV32.
281
+ */
282
+ static const unsigned int riscv_c_exts [] = {
283
+ RISCV_ISA_EXT_ZCA ,
284
+ RISCV_ISA_EXT_ZCF ,
285
+ RISCV_ISA_EXT_ZCD ,
286
+ };
287
+
239
288
/*
240
289
* The canonical order of ISA extension names in the ISA string is defined in
241
290
* chapter 27 of the unprivileged specification.
@@ -282,7 +331,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
282
331
__RISCV_ISA_EXT_DATA (f , RISCV_ISA_EXT_f ),
283
332
__RISCV_ISA_EXT_DATA (d , RISCV_ISA_EXT_d ),
284
333
__RISCV_ISA_EXT_DATA (q , RISCV_ISA_EXT_q ),
285
- __RISCV_ISA_EXT_DATA (c , RISCV_ISA_EXT_c ),
334
+ __RISCV_ISA_EXT_SUPERSET (c , RISCV_ISA_EXT_c , riscv_c_exts ),
286
335
__RISCV_ISA_EXT_SUPERSET (v , RISCV_ISA_EXT_v , riscv_v_exts ),
287
336
__RISCV_ISA_EXT_DATA (h , RISCV_ISA_EXT_h ),
288
337
__RISCV_ISA_EXT_SUPERSET_VALIDATE (zicbom , RISCV_ISA_EXT_ZICBOM , riscv_xlinuxenvcfg_exts ,
@@ -301,6 +350,10 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
301
350
__RISCV_ISA_EXT_DATA (zfa , RISCV_ISA_EXT_ZFA ),
302
351
__RISCV_ISA_EXT_DATA (zfh , RISCV_ISA_EXT_ZFH ),
303
352
__RISCV_ISA_EXT_DATA (zfhmin , RISCV_ISA_EXT_ZFHMIN ),
353
+ __RISCV_ISA_EXT_DATA (zca , RISCV_ISA_EXT_ZCA ),
354
+ __RISCV_ISA_EXT_DATA_VALIDATE (zcb , RISCV_ISA_EXT_ZCB , riscv_ext_zca_depends ),
355
+ __RISCV_ISA_EXT_DATA_VALIDATE (zcd , RISCV_ISA_EXT_ZCD , riscv_ext_zcd_validate ),
356
+ __RISCV_ISA_EXT_DATA_VALIDATE (zcf , RISCV_ISA_EXT_ZCF , riscv_ext_zcf_validate ),
304
357
__RISCV_ISA_EXT_DATA (zba , RISCV_ISA_EXT_ZBA ),
305
358
__RISCV_ISA_EXT_DATA (zbb , RISCV_ISA_EXT_ZBB ),
306
359
__RISCV_ISA_EXT_DATA (zbc , RISCV_ISA_EXT_ZBC ),
0 commit comments