Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge patch series "riscv: Add bfloat16 instruction support"

Inochi Amaoto <inochiama@gmail.com> 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/20250213003849.147358-1-inochiama@gmail.com:
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 <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20250213003849.147358-1-inochiama@gmail.com

+101
+12
Documentation/arch/riscv/hwprobe.rst
··· 248 248 * :c:macro:`RISCV_HWPROBE_EXT_SUPM`: The Supm extension is supported as 249 249 defined in version 1.0 of the RISC-V Pointer Masking extensions. 250 250 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 + 251 263 * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to 252 264 :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was 253 265 mistakenly classified as a bitmask rather than a value.
+45
Documentation/devicetree/bindings/riscv/extensions.yaml
··· 329 329 instructions, as ratified in commit 056b6ff ("Zfa is ratified") of 330 330 riscv-isa-manual. 331 331 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 + 332 338 - const: zfh 333 339 description: 334 340 The standard Zfh extension for 16-bit half-precision binary ··· 531 525 in commit 6f702a2 ("Vector extensions are now ratified") of 532 526 riscv-v-spec. 533 527 528 + - const: zvfbfmin 529 + description: 530 + The standard Zvfbfmin extension for minimal support for vectored 531 + 16-bit half-precision brain floating-point instructions, as ratified 532 + in commit 4dc23d62 ("Added Chapter title to BF16") of riscv-isa-manual. 533 + 534 + - const: zvfbfwma 535 + description: 536 + The standard Zvfbfwma extension for vectored half-precision brain 537 + floating-point widening multiply-accumulate instructions, as ratified 538 + in commit 4dc23d62 ("Added Chapter title to BF16") of riscv-isa-manual. 539 + 534 540 - const: zvfh 535 541 description: 536 542 The standard Zvfh extension for vectored half-precision ··· 691 673 then: 692 674 contains: 693 675 const: zca 676 + # Zfbfmin depends on F 677 + - if: 678 + contains: 679 + const: zfbfmin 680 + then: 681 + contains: 682 + const: f 683 + # Zvfbfmin depends on V or Zve32f 684 + - if: 685 + contains: 686 + const: zvfbfmin 687 + then: 688 + oneOf: 689 + - contains: 690 + const: v 691 + - contains: 692 + const: zve32f 693 + # Zvfbfwma depends on Zfbfmin and Zvfbfmin 694 + - if: 695 + contains: 696 + const: zvfbfwma 697 + then: 698 + allOf: 699 + - contains: 700 + const: zfbfmin 701 + - contains: 702 + const: zvfbfmin 694 703 695 704 allOf: 696 705 # Zcf extension does not exist on rv64
+3
arch/riscv/include/asm/hwcap.h
··· 100 100 #define RISCV_ISA_EXT_ZICCRSE 91 101 101 #define RISCV_ISA_EXT_SVADE 92 102 102 #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 103 106 104 107 #define RISCV_ISA_EXT_XLINUXENVCFG 127 105 108
+3
arch/riscv/include/uapi/asm/hwprobe.h
··· 75 75 #define RISCV_HWPROBE_EXT_SUPM (1ULL << 49) 76 76 #define RISCV_HWPROBE_EXT_ZICNTR (1ULL << 50) 77 77 #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) 78 81 #define RISCV_HWPROBE_KEY_CPUPERF_0 5 79 82 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) 80 83 #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)
+35
arch/riscv/kernel/cpufeature.c
··· 80 80 } 81 81 EXPORT_SYMBOL_GPL(__riscv_isa_extension_available); 82 82 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 + 83 92 static int riscv_ext_zicbom_validate(const struct riscv_isa_ext_data *data, 84 93 const unsigned long *isa_bitmap) 85 94 { ··· 144 135 145 136 if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZCA) && 146 137 __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_f)) 138 + return 0; 139 + 140 + return -EPROBE_DEFER; 141 + } 142 + 143 + static int riscv_vector_f_validate(const struct riscv_isa_ext_data *data, 144 + const unsigned long *isa_bitmap) 145 + { 146 + if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) 147 + return -EINVAL; 148 + 149 + if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZVE32F)) 150 + return 0; 151 + 152 + return -EPROBE_DEFER; 153 + } 154 + 155 + static int riscv_ext_zvfbfwma_validate(const struct riscv_isa_ext_data *data, 156 + const unsigned long *isa_bitmap) 157 + { 158 + if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZFBFMIN) && 159 + __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZVFBFMIN)) 147 160 return 0; 148 161 149 162 return -EPROBE_DEFER; ··· 376 345 __RISCV_ISA_EXT_DATA(zacas, RISCV_ISA_EXT_ZACAS), 377 346 __RISCV_ISA_EXT_DATA(zawrs, RISCV_ISA_EXT_ZAWRS), 378 347 __RISCV_ISA_EXT_DATA(zfa, RISCV_ISA_EXT_ZFA), 348 + __RISCV_ISA_EXT_DATA_VALIDATE(zfbfmin, RISCV_ISA_EXT_ZFBFMIN, riscv_ext_f_depends), 379 349 __RISCV_ISA_EXT_DATA(zfh, RISCV_ISA_EXT_ZFH), 380 350 __RISCV_ISA_EXT_DATA(zfhmin, RISCV_ISA_EXT_ZFHMIN), 381 351 __RISCV_ISA_EXT_DATA(zca, RISCV_ISA_EXT_ZCA), ··· 409 377 __RISCV_ISA_EXT_SUPERSET(zve64d, RISCV_ISA_EXT_ZVE64D, riscv_zve64d_exts), 410 378 __RISCV_ISA_EXT_SUPERSET(zve64f, RISCV_ISA_EXT_ZVE64F, riscv_zve64f_exts), 411 379 __RISCV_ISA_EXT_SUPERSET(zve64x, RISCV_ISA_EXT_ZVE64X, riscv_zve64x_exts), 380 + __RISCV_ISA_EXT_DATA_VALIDATE(zvfbfmin, RISCV_ISA_EXT_ZVFBFMIN, riscv_vector_f_validate), 381 + __RISCV_ISA_EXT_DATA_VALIDATE(zvfbfwma, RISCV_ISA_EXT_ZVFBFWMA, 382 + riscv_ext_zvfbfwma_validate), 412 383 __RISCV_ISA_EXT_DATA(zvfh, RISCV_ISA_EXT_ZVFH), 413 384 __RISCV_ISA_EXT_DATA(zvfhmin, RISCV_ISA_EXT_ZVFHMIN), 414 385 __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB),
+3
arch/riscv/kernel/sys_hwprobe.c
··· 134 134 EXT_KEY(ZVE64D); 135 135 EXT_KEY(ZVE64F); 136 136 EXT_KEY(ZVE64X); 137 + EXT_KEY(ZVFBFMIN); 138 + EXT_KEY(ZVFBFWMA); 137 139 EXT_KEY(ZVFH); 138 140 EXT_KEY(ZVFHMIN); 139 141 EXT_KEY(ZVKB); ··· 152 150 EXT_KEY(ZCD); 153 151 EXT_KEY(ZCF); 154 152 EXT_KEY(ZFA); 153 + EXT_KEY(ZFBFMIN); 155 154 EXT_KEY(ZFH); 156 155 EXT_KEY(ZFHMIN); 157 156 }