Skip to content

Commit fe1236a

Browse files
a4lgAmanieu
authored andcommitted
RISC-V: Linux 6.15 riscv_hwprobe support
This commit adds support for `riscv_hwprobe` on the Linux kernel 6.15. It adds feature detection of 8 extensions (4 of them are new in this). Existing RISC-V Extensions: 1. "Zicntr" 2. "Zihpm" 3. "Zalrsc" 4. "Zaamo" New RISC-V Extensions: 5. "Zicbom" 6. "Zfbfmin" 7. "Zvfbfmin" 8. "Zvfbfwma"
1 parent e5fa4b0 commit fe1236a

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

crates/std_detect/src/detect/arch/riscv.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ features! {
6363
/// * Zve64x: `"zve64x"`
6464
/// * Zve64f: `"zve64f"`
6565
/// * Zve64d: `"zve64d"`
66+
/// * Zicbom: `"zicbom"`
6667
/// * Zicboz: `"zicboz"`
6768
/// * Zicntr: `"zicntr"`
6869
/// * Zicond: `"zicond"`
@@ -75,6 +76,7 @@ features! {
7576
/// * Zacas: `"zacas"`
7677
/// * Zawrs: `"zawrs"`
7778
/// * Zfa: `"zfa"`
79+
/// * Zfbfmin: `"zfbfmin"`
7880
/// * Zfh: `"zfh"`
7981
/// * Zfhmin: `"zfhmin"`
8082
/// * Zfinx: `"zfinx"`
@@ -99,6 +101,8 @@ features! {
99101
/// * Zkt: `"zkt"`
100102
/// * Zvbb: `"zvbb"`
101103
/// * Zvbc: `"zvbc"`
104+
/// * Zvfbfmin: `"zvfbfmin"`
105+
/// * Zvfbfwma: `"zvfbfwma"`
102106
/// * Zvfh: `"zvfh"`
103107
/// * Zvfhmin: `"zvfhmin"`
104108
/// * Zvkb: `"zvkb"`
@@ -173,6 +177,8 @@ features! {
173177
/// "Zihintpause" Extension for Pause Hint
174178
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zimop: "zimop";
175179
/// "Zimop" Extension for May-Be-Operations
180+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicbom: "zicbom";
181+
/// "Zicbom" Extension for Cache-Block Management Instructions
176182
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicboz: "zicboz";
177183
/// "Zicboz" Extension for Cache-Block Zero Instruction
178184
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicond: "zicond";
@@ -210,6 +216,8 @@ features! {
210216
/// "Zfhmin" Extension for Minimal Half-Precision Floating-Point
211217
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zfa: "zfa";
212218
/// "Zfa" Extension for Additional Floating-Point Instructions
219+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zfbfmin: "zfbfmin";
220+
/// "Zfbfmin" Extension for Scalar BF16 Converts
213221
214222
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zfinx: "zfinx";
215223
/// "Zfinx" Extension for Single-Precision Floating-Point in Integer Registers
@@ -289,6 +297,10 @@ features! {
289297
/// "Zvfh" Vector Extension for Half-Precision Floating-Point
290298
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvfhmin: "zvfhmin";
291299
/// "Zvfhmin" Vector Extension for Minimal Half-Precision Floating-Point
300+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvfbfmin: "zvfbfmin";
301+
/// "Zvfbfmin" Vector Extension for BF16 Converts
302+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvfbfwma: "zvfbfwma";
303+
/// "Zvfbfwma" Vector Extension for BF16 Widening Multiply-Add
292304
293305
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvbb: "zvbb";
294306
/// "Zvbb" Extension for Vector Basic Bit-Manipulation

crates/std_detect/src/detect/os/linux/riscv.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use super::super::riscv::imply_features;
1010
use super::auxvec;
1111
use crate::detect::{Feature, bit, cache};
1212

13-
// See <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/prctl.h?h=v6.14>
13+
// See <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/prctl.h?h=v6.15>
1414
// for runtime status query constants.
1515
const PR_RISCV_V_GET_CONTROL: libc::c_int = 70;
1616
const PR_RISCV_V_VSTATE_CTRL_ON: libc::c_int = 2;
1717
const PR_RISCV_V_VSTATE_CTRL_CUR_MASK: libc::c_int = 3;
1818

19-
// See <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/uapi/asm/hwprobe.h?h=v6.14>
19+
// See <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/uapi/asm/hwprobe.h?h=v6.15>
2020
// for riscv_hwprobe struct and hardware probing constants.
2121

2222
#[repr(C)]
@@ -83,6 +83,14 @@ const RISCV_HWPROBE_EXT_ZCMOP: u64 = 1 << 47;
8383
const RISCV_HWPROBE_EXT_ZAWRS: u64 = 1 << 48;
8484
// Excluded because it only reports the existence of `prctl`-based pointer masking control.
8585
// const RISCV_HWPROBE_EXT_SUPM: u64 = 1 << 49;
86+
const RISCV_HWPROBE_EXT_ZICNTR: u64 = 1 << 50;
87+
const RISCV_HWPROBE_EXT_ZIHPM: u64 = 1 << 51;
88+
const RISCV_HWPROBE_EXT_ZFBFMIN: u64 = 1 << 52;
89+
const RISCV_HWPROBE_EXT_ZVFBFMIN: u64 = 1 << 53;
90+
const RISCV_HWPROBE_EXT_ZVFBFWMA: u64 = 1 << 54;
91+
const RISCV_HWPROBE_EXT_ZICBOM: u64 = 1 << 55;
92+
const RISCV_HWPROBE_EXT_ZAAMO: u64 = 1 << 56;
93+
const RISCV_HWPROBE_EXT_ZALRSC: u64 = 1 << 57;
8694

8795
const RISCV_HWPROBE_KEY_CPUPERF_0: i64 = 5;
8896
const RISCV_HWPROBE_MISALIGNED_FAST: u64 = 3;
@@ -133,7 +141,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
133141
// Use auxiliary vector to enable single-letter ISA extensions.
134142
// The values are part of the platform-specific [asm/hwcap.h][hwcap]
135143
//
136-
// [hwcap]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/uapi/asm/hwcap.h?h=v6.14
144+
// [hwcap]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/uapi/asm/hwcap.h?h=v6.15
137145
let auxv = auxvec::auxv().expect("read auxvec"); // should not fail on RISC-V platform
138146
let mut has_i = bit::test(auxv.hwcap, (b'i' - b'a').into());
139147
#[allow(clippy::eq_op)]
@@ -221,12 +229,18 @@ pub(crate) fn detect_features() -> cache::Initializer {
221229
enable_feature(Feature::d, test(RISCV_HWPROBE_IMA_FD)); // F is implied.
222230
enable_feature(Feature::c, test(RISCV_HWPROBE_IMA_C));
223231

232+
enable_feature(Feature::zicntr, test(RISCV_HWPROBE_EXT_ZICNTR));
233+
enable_feature(Feature::zihpm, test(RISCV_HWPROBE_EXT_ZIHPM));
234+
224235
enable_feature(Feature::zihintntl, test(RISCV_HWPROBE_EXT_ZIHINTNTL));
225236
enable_feature(Feature::zihintpause, test(RISCV_HWPROBE_EXT_ZIHINTPAUSE));
226237
enable_feature(Feature::zimop, test(RISCV_HWPROBE_EXT_ZIMOP));
238+
enable_feature(Feature::zicbom, test(RISCV_HWPROBE_EXT_ZICBOM));
227239
enable_feature(Feature::zicboz, test(RISCV_HWPROBE_EXT_ZICBOZ));
228240
enable_feature(Feature::zicond, test(RISCV_HWPROBE_EXT_ZICOND));
229241

242+
enable_feature(Feature::zalrsc, test(RISCV_HWPROBE_EXT_ZALRSC));
243+
enable_feature(Feature::zaamo, test(RISCV_HWPROBE_EXT_ZAAMO));
230244
enable_feature(Feature::zawrs, test(RISCV_HWPROBE_EXT_ZAWRS));
231245
enable_feature(Feature::zacas, test(RISCV_HWPROBE_EXT_ZACAS));
232246
enable_feature(Feature::ztso, test(RISCV_HWPROBE_EXT_ZTSO));
@@ -255,6 +269,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
255269
enable_feature(Feature::zfh, test(RISCV_HWPROBE_EXT_ZFH));
256270
enable_feature(Feature::zfhmin, test(RISCV_HWPROBE_EXT_ZFHMIN));
257271
enable_feature(Feature::zfa, test(RISCV_HWPROBE_EXT_ZFA));
272+
enable_feature(Feature::zfbfmin, test(RISCV_HWPROBE_EXT_ZFBFMIN));
258273

259274
// Use prctl (if any) to determine whether the vector extension
260275
// is enabled on the current thread (assuming the entire process
@@ -290,6 +305,8 @@ pub(crate) fn detect_features() -> cache::Initializer {
290305

291306
enable_feature(Feature::zvfh, test(RISCV_HWPROBE_EXT_ZVFH));
292307
enable_feature(Feature::zvfhmin, test(RISCV_HWPROBE_EXT_ZVFHMIN));
308+
enable_feature(Feature::zvfbfmin, test(RISCV_HWPROBE_EXT_ZVFBFMIN));
309+
enable_feature(Feature::zvfbfwma, test(RISCV_HWPROBE_EXT_ZVFBFWMA));
293310
}
294311
is_v_set = true;
295312
};

crates/std_detect/src/detect/os/riscv.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ pub(crate) fn imply_features(mut value: cache::Initializer) -> cache::Initialize
105105
imply!(zvfh => zvfhmin); // functional
106106
imply!(zvfh => zve32f & zfhmin);
107107
imply!(zvfhmin => zve32f);
108+
imply!(zvfbfwma => zvfbfmin & zfbfmin);
109+
imply!(zvfbfmin => zve32f);
108110

109111
imply!(v => zve64d);
110112
imply!(zve64d => zve64f & d);
@@ -115,6 +117,7 @@ pub(crate) fn imply_features(mut value: cache::Initializer) -> cache::Initialize
115117
imply!(zfh => zfhmin);
116118
imply!(q => d);
117119
imply!(d | zfhmin | zfa => f);
120+
imply!(zfbfmin => f); // and some of (not all) "Zfh" instructions.
118121

119122
// Relatively complex implication rules from the "C" extension.
120123
imply!(c => zca);

crates/std_detect/tests/cpu-detection.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ fn riscv_linux() {
251251
println!("zihintntl: {}", is_riscv_feature_detected!("zihintntl"));
252252
println!("zihintpause: {}", is_riscv_feature_detected!("zihintpause"));
253253
println!("zimop: {}", is_riscv_feature_detected!("zimop"));
254+
println!("zicbom: {}", is_riscv_feature_detected!("zicbom"));
254255
println!("zicboz: {}", is_riscv_feature_detected!("zicboz"));
255256
println!("zicond: {}", is_riscv_feature_detected!("zicond"));
256257
println!("m: {}", is_riscv_feature_detected!("m"));
@@ -267,6 +268,7 @@ fn riscv_linux() {
267268
println!("zfh: {}", is_riscv_feature_detected!("zfh"));
268269
println!("zfhmin: {}", is_riscv_feature_detected!("zfhmin"));
269270
println!("zfa: {}", is_riscv_feature_detected!("zfa"));
271+
println!("zfbfmin: {}", is_riscv_feature_detected!("zfbfmin"));
270272
println!("zfinx: {}", is_riscv_feature_detected!("zfinx"));
271273
println!("zdinx: {}", is_riscv_feature_detected!("zdinx"));
272274
println!("zhinx: {}", is_riscv_feature_detected!("zhinx"));
@@ -303,6 +305,8 @@ fn riscv_linux() {
303305
println!("zve64d: {}", is_riscv_feature_detected!("zve64d"));
304306
println!("zvfh: {}", is_riscv_feature_detected!("zvfh"));
305307
println!("zvfhmin: {}", is_riscv_feature_detected!("zvfhmin"));
308+
println!("zvfbfmin: {}", is_riscv_feature_detected!("zvfbfmin"));
309+
println!("zvfbfwma: {}", is_riscv_feature_detected!("zvfbfwma"));
306310
println!("zvbb: {}", is_riscv_feature_detected!("zvbb"));
307311
println!("zvbc: {}", is_riscv_feature_detected!("zvbc"));
308312
println!("zvkb: {}", is_riscv_feature_detected!("zvkb"));

0 commit comments

Comments
 (0)