Skip to content

Commit 2f2cd9f

Browse files
author
Alexandre Ghiti
committed
Merge patch series "riscv: Add bfloat16 instruction support"
Inochi Amaoto <[email protected]> says: Add description for the BFloat16 precision Floating-Point ISA extension, (Zfbfmin, Zvfbfmin, Zvfbfwma). which was ratified in commit 4dc23d62 ("Added Chapter title to BF16") of the riscv-isa-manual. * patches from https://lore.kernel.org/r/[email protected]: riscv: hwprobe: export bfloat16 ISA extension riscv: add ISA extension parsing for bfloat16 ISA extension dt-bindings: riscv: add bfloat16 ISA extension description Signed-off-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected]
2 parents d9708b1 + a4863e0 commit 2f2cd9f

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,18 @@ The following keys are defined:
248248
* :c:macro:`RISCV_HWPROBE_EXT_SUPM`: The Supm extension is supported as
249249
defined in version 1.0 of the RISC-V Pointer Masking extensions.
250250

251+
* :c:macro:`RISCV_HWPROBE_EXT_ZFBFMIN`: The Zfbfmin extension is supported as
252+
defined in the RISC-V ISA manual starting from commit 4dc23d6229de
253+
("Added Chapter title to BF16").
254+
255+
* :c:macro:`RISCV_HWPROBE_EXT_ZVFBFMIN`: The Zvfbfmin extension is supported as
256+
defined in the RISC-V ISA manual starting from commit 4dc23d6229de
257+
("Added Chapter title to BF16").
258+
259+
* :c:macro:`RISCV_HWPROBE_EXT_ZVFBFWMA`: The Zvfbfwma extension is supported as
260+
defined in the RISC-V ISA manual starting from commit 4dc23d6229de
261+
("Added Chapter title to BF16").
262+
251263
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to
252264
:c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was
253265
mistakenly classified as a bitmask rather than a value.

Documentation/devicetree/bindings/riscv/extensions.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ properties:
329329
instructions, as ratified in commit 056b6ff ("Zfa is ratified") of
330330
riscv-isa-manual.
331331

332+
- const: zfbfmin
333+
description:
334+
The standard Zfbfmin extension which provides minimal support for
335+
16-bit half-precision brain floating-point instructions, as ratified
336+
in commit 4dc23d62 ("Added Chapter title to BF16") of riscv-isa-manual.
337+
332338
- const: zfh
333339
description:
334340
The standard Zfh extension for 16-bit half-precision binary
@@ -525,6 +531,18 @@ properties:
525531
in commit 6f702a2 ("Vector extensions are now ratified") of
526532
riscv-v-spec.
527533

534+
- const: zvfbfmin
535+
description:
536+
The standard Zvfbfmin extension for minimal support for vectored
537+
16-bit half-precision brain floating-point instructions, as ratified
538+
in commit 4dc23d62 ("Added Chapter title to BF16") of riscv-isa-manual.
539+
540+
- const: zvfbfwma
541+
description:
542+
The standard Zvfbfwma extension for vectored half-precision brain
543+
floating-point widening multiply-accumulate instructions, as ratified
544+
in commit 4dc23d62 ("Added Chapter title to BF16") of riscv-isa-manual.
545+
528546
- const: zvfh
529547
description:
530548
The standard Zvfh extension for vectored half-precision
@@ -673,6 +691,33 @@ properties:
673691
then:
674692
contains:
675693
const: zca
694+
# Zfbfmin depends on F
695+
- if:
696+
contains:
697+
const: zfbfmin
698+
then:
699+
contains:
700+
const: f
701+
# Zvfbfmin depends on V or Zve32f
702+
- if:
703+
contains:
704+
const: zvfbfmin
705+
then:
706+
oneOf:
707+
- contains:
708+
const: v
709+
- contains:
710+
const: zve32f
711+
# Zvfbfwma depends on Zfbfmin and Zvfbfmin
712+
- if:
713+
contains:
714+
const: zvfbfwma
715+
then:
716+
allOf:
717+
- contains:
718+
const: zfbfmin
719+
- contains:
720+
const: zvfbfmin
676721

677722
allOf:
678723
# Zcf extension does not exist on rv64

arch/riscv/include/asm/hwcap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
#define RISCV_ISA_EXT_ZICCRSE 91
101101
#define RISCV_ISA_EXT_SVADE 92
102102
#define RISCV_ISA_EXT_SVADU 93
103+
#define RISCV_ISA_EXT_ZFBFMIN 94
104+
#define RISCV_ISA_EXT_ZVFBFMIN 95
105+
#define RISCV_ISA_EXT_ZVFBFWMA 96
103106

104107
#define RISCV_ISA_EXT_XLINUXENVCFG 127
105108

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ struct riscv_hwprobe {
7575
#define RISCV_HWPROBE_EXT_SUPM (1ULL << 49)
7676
#define RISCV_HWPROBE_EXT_ZICNTR (1ULL << 50)
7777
#define RISCV_HWPROBE_EXT_ZIHPM (1ULL << 51)
78+
#define RISCV_HWPROBE_EXT_ZFBFMIN (1ULL << 52)
79+
#define RISCV_HWPROBE_EXT_ZVFBFMIN (1ULL << 53)
80+
#define RISCV_HWPROBE_EXT_ZVFBFWMA (1ULL << 54)
7881
#define RISCV_HWPROBE_KEY_CPUPERF_0 5
7982
#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)
8083
#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)

arch/riscv/kernel/cpufeature.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned i
8080
}
8181
EXPORT_SYMBOL_GPL(__riscv_isa_extension_available);
8282

83+
static int riscv_ext_f_depends(const struct riscv_isa_ext_data *data,
84+
const unsigned long *isa_bitmap)
85+
{
86+
if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_f))
87+
return 0;
88+
89+
return -EPROBE_DEFER;
90+
}
91+
8392
static int riscv_ext_zicbom_validate(const struct riscv_isa_ext_data *data,
8493
const unsigned long *isa_bitmap)
8594
{
@@ -140,6 +149,28 @@ static int riscv_ext_zcf_validate(const struct riscv_isa_ext_data *data,
140149
return -EPROBE_DEFER;
141150
}
142151

152+
static int riscv_vector_f_validate(const struct riscv_isa_ext_data *data,
153+
const unsigned long *isa_bitmap)
154+
{
155+
if (!IS_ENABLED(CONFIG_RISCV_ISA_V))
156+
return -EINVAL;
157+
158+
if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZVE32F))
159+
return 0;
160+
161+
return -EPROBE_DEFER;
162+
}
163+
164+
static int riscv_ext_zvfbfwma_validate(const struct riscv_isa_ext_data *data,
165+
const unsigned long *isa_bitmap)
166+
{
167+
if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZFBFMIN) &&
168+
__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZVFBFMIN))
169+
return 0;
170+
171+
return -EPROBE_DEFER;
172+
}
173+
143174
static int riscv_ext_svadu_validate(const struct riscv_isa_ext_data *data,
144175
const unsigned long *isa_bitmap)
145176
{
@@ -345,6 +376,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
345376
__RISCV_ISA_EXT_DATA(zacas, RISCV_ISA_EXT_ZACAS),
346377
__RISCV_ISA_EXT_DATA(zawrs, RISCV_ISA_EXT_ZAWRS),
347378
__RISCV_ISA_EXT_DATA(zfa, RISCV_ISA_EXT_ZFA),
379+
__RISCV_ISA_EXT_DATA_VALIDATE(zfbfmin, RISCV_ISA_EXT_ZFBFMIN, riscv_ext_f_depends),
348380
__RISCV_ISA_EXT_DATA(zfh, RISCV_ISA_EXT_ZFH),
349381
__RISCV_ISA_EXT_DATA(zfhmin, RISCV_ISA_EXT_ZFHMIN),
350382
__RISCV_ISA_EXT_DATA(zca, RISCV_ISA_EXT_ZCA),
@@ -377,6 +409,9 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
377409
__RISCV_ISA_EXT_SUPERSET(zve64d, RISCV_ISA_EXT_ZVE64D, riscv_zve64d_exts),
378410
__RISCV_ISA_EXT_SUPERSET(zve64f, RISCV_ISA_EXT_ZVE64F, riscv_zve64f_exts),
379411
__RISCV_ISA_EXT_SUPERSET(zve64x, RISCV_ISA_EXT_ZVE64X, riscv_zve64x_exts),
412+
__RISCV_ISA_EXT_DATA_VALIDATE(zvfbfmin, RISCV_ISA_EXT_ZVFBFMIN, riscv_vector_f_validate),
413+
__RISCV_ISA_EXT_DATA_VALIDATE(zvfbfwma, RISCV_ISA_EXT_ZVFBFWMA,
414+
riscv_ext_zvfbfwma_validate),
380415
__RISCV_ISA_EXT_DATA(zvfh, RISCV_ISA_EXT_ZVFH),
381416
__RISCV_ISA_EXT_DATA(zvfhmin, RISCV_ISA_EXT_ZVFHMIN),
382417
__RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB),

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,
134134
EXT_KEY(ZVE64D);
135135
EXT_KEY(ZVE64F);
136136
EXT_KEY(ZVE64X);
137+
EXT_KEY(ZVFBFMIN);
138+
EXT_KEY(ZVFBFWMA);
137139
EXT_KEY(ZVFH);
138140
EXT_KEY(ZVFHMIN);
139141
EXT_KEY(ZVKB);
@@ -150,6 +152,7 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,
150152
EXT_KEY(ZCD);
151153
EXT_KEY(ZCF);
152154
EXT_KEY(ZFA);
155+
EXT_KEY(ZFBFMIN);
153156
EXT_KEY(ZFH);
154157
EXT_KEY(ZFHMIN);
155158
}

0 commit comments

Comments
 (0)