Skip to content

Commit ba4cd85

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
riscv: add ISA parsing for Zca, Zcf, Zcd and Zcb
The Zc* standard extension for code reduction introduces new extensions. This patch adds support for Zca, Zcf, Zcd and Zcb. Zce, Zcmt and Zcmp are left out of this patch since they are targeting microcontrollers/ embedded CPUs instead of application processors. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 625034a commit ba4cd85

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

arch/riscv/include/asm/hwcap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
#define RISCV_ISA_EXT_ZVE64F 78
8888
#define RISCV_ISA_EXT_ZVE64D 79
8989
#define RISCV_ISA_EXT_ZIMOP 80
90+
#define RISCV_ISA_EXT_ZCA 81
91+
#define RISCV_ISA_EXT_ZCB 82
92+
#define RISCV_ISA_EXT_ZCD 83
93+
#define RISCV_ISA_EXT_ZCF 84
9094

9195
#define RISCV_ISA_EXT_XLINUXENVCFG 127
9296

arch/riscv/kernel/cpufeature.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ static int riscv_ext_zicboz_validate(const struct riscv_isa_ext_data *data,
111111

112112
#define __RISCV_ISA_EXT_DATA(_name, _id) _RISCV_ISA_EXT_DATA(_name, _id, NULL, 0, NULL)
113113

114+
#define __RISCV_ISA_EXT_DATA_VALIDATE(_name, _id, _validate) \
115+
_RISCV_ISA_EXT_DATA(_name, _id, NULL, 0, _validate)
116+
114117
/* Used to declare pure "lasso" extension (Zk for instance) */
115118
#define __RISCV_ISA_EXT_BUNDLE(_name, _bundled_exts) \
116119
_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,
122125
#define __RISCV_ISA_EXT_SUPERSET_VALIDATE(_name, _id, _sub_exts, _validate) \
123126
_RISCV_ISA_EXT_DATA(_name, _id, _sub_exts, ARRAY_SIZE(_sub_exts), _validate)
124127

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+
125159
static const unsigned int riscv_zk_bundled_exts[] = {
126160
RISCV_ISA_EXT_ZBKB,
127161
RISCV_ISA_EXT_ZBKC,
@@ -236,6 +270,21 @@ static const unsigned int riscv_xlinuxenvcfg_exts[] = {
236270
RISCV_ISA_EXT_XLINUXENVCFG
237271
};
238272

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+
239288
/*
240289
* The canonical order of ISA extension names in the ISA string is defined in
241290
* chapter 27 of the unprivileged specification.
@@ -282,7 +331,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
282331
__RISCV_ISA_EXT_DATA(f, RISCV_ISA_EXT_f),
283332
__RISCV_ISA_EXT_DATA(d, RISCV_ISA_EXT_d),
284333
__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),
286335
__RISCV_ISA_EXT_SUPERSET(v, RISCV_ISA_EXT_v, riscv_v_exts),
287336
__RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_h),
288337
__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[] = {
301350
__RISCV_ISA_EXT_DATA(zfa, RISCV_ISA_EXT_ZFA),
302351
__RISCV_ISA_EXT_DATA(zfh, RISCV_ISA_EXT_ZFH),
303352
__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),
304357
__RISCV_ISA_EXT_DATA(zba, RISCV_ISA_EXT_ZBA),
305358
__RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB),
306359
__RISCV_ISA_EXT_DATA(zbc, RISCV_ISA_EXT_ZBC),

0 commit comments

Comments
 (0)