Skip to content

Commit a5ea53d

Browse files
charlie-rivospalmer-dabbelt
authored andcommitted
riscv: hwprobe: Add thead vendor extension probing
Add a new hwprobe key "RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0" which allows userspace to probe for the new RISCV_ISA_VENDOR_EXT_XTHEADVECTOR vendor extension. This new key will allow userspace code to probe for which thead vendor extensions are supported. This API is modeled to be consistent with RISCV_HWPROBE_KEY_IMA_EXT_0. The bitmask returned will have each bit corresponding to a supported thead vendor extension of the cpumask set. Just like RISCV_HWPROBE_KEY_IMA_EXT_0, this allows a userspace program to determine all of the supported thead vendor extensions in one call. Signed-off-by: Charlie Jenkins <[email protected]> Reviewed-by: Evan Green <[email protected]> Tested-by: Yangyu Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent d863910 commit a5ea53d

File tree

8 files changed

+89
-3
lines changed

8 files changed

+89
-3
lines changed

arch/riscv/include/asm/hwprobe.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22
/*
3-
* Copyright 2023 Rivos, Inc
3+
* Copyright 2023-2024 Rivos, Inc
44
*/
55

66
#ifndef _ASM_HWPROBE_H
77
#define _ASM_HWPROBE_H
88

99
#include <uapi/asm/hwprobe.h>
1010

11-
#define RISCV_HWPROBE_MAX_KEY 10
11+
#define RISCV_HWPROBE_MAX_KEY 11
1212

1313
static inline bool riscv_hwprobe_key_is_valid(__s64 key)
1414
{
@@ -21,6 +21,7 @@ static inline bool hwprobe_key_is_bitmask(__s64 key)
2121
case RISCV_HWPROBE_KEY_BASE_BEHAVIOR:
2222
case RISCV_HWPROBE_KEY_IMA_EXT_0:
2323
case RISCV_HWPROBE_KEY_CPUPERF_0:
24+
case RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0:
2425
return true;
2526
}
2627

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_RISCV_VENDOR_EXTENSIONS_THEAD_HWPROBE_H
3+
#define _ASM_RISCV_VENDOR_EXTENSIONS_THEAD_HWPROBE_H
4+
5+
#include <linux/cpumask.h>
6+
7+
#include <uapi/asm/hwprobe.h>
8+
9+
#ifdef CONFIG_RISCV_ISA_VENDOR_EXT_THEAD
10+
void hwprobe_isa_vendor_ext_thead_0(struct riscv_hwprobe *pair, const struct cpumask *cpus);
11+
#else
12+
static inline void hwprobe_isa_vendor_ext_thead_0(struct riscv_hwprobe *pair,
13+
const struct cpumask *cpus)
14+
{
15+
pair->value = 0;
16+
}
17+
#endif
18+
19+
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright 2024 Rivos, Inc
4+
*/
5+
6+
#ifndef _ASM_RISCV_SYS_HWPROBE_H
7+
#define _ASM_RISCV_SYS_HWPROBE_H
8+
9+
#include <asm/cpufeature.h>
10+
11+
#define VENDOR_EXT_KEY(ext) \
12+
do { \
13+
if (__riscv_isa_extension_available(isainfo->isa, RISCV_ISA_VENDOR_EXT_##ext)) \
14+
pair->value |= RISCV_HWPROBE_VENDOR_EXT_##ext; \
15+
else \
16+
missing |= RISCV_HWPROBE_VENDOR_EXT_##ext; \
17+
} while (false)
18+
19+
/*
20+
* Loop through and record extensions that 1) anyone has, and 2) anyone
21+
* doesn't have.
22+
*
23+
* _extension_checks is an arbitrary C block to set the values of pair->value
24+
* and missing. It should be filled with VENDOR_EXT_KEY expressions.
25+
*/
26+
#define VENDOR_EXTENSION_SUPPORTED(pair, cpus, per_hart_vendor_bitmap, _extension_checks) \
27+
do { \
28+
int cpu; \
29+
u64 missing = 0; \
30+
for_each_cpu(cpu, (cpus)) { \
31+
struct riscv_isavendorinfo *isainfo = &(per_hart_vendor_bitmap)[cpu]; \
32+
_extension_checks \
33+
} \
34+
(pair)->value &= ~missing; \
35+
} while (false) \
36+
37+
#endif /* _ASM_RISCV_SYS_HWPROBE_H */

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22
/*
3-
* Copyright 2023 Rivos, Inc
3+
* Copyright 2023-2024 Rivos, Inc
44
*/
55

66
#ifndef _UAPI_ASM_HWPROBE_H
@@ -94,6 +94,7 @@ struct riscv_hwprobe {
9494
#define RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW 2
9595
#define RISCV_HWPROBE_MISALIGNED_VECTOR_FAST 3
9696
#define RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED 4
97+
#define RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0 11
9798
/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
9899

99100
/* Flags */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
3+
#define RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR (1 << 0)

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <asm/uaccess.h>
1616
#include <asm/unistd.h>
1717
#include <asm/vector.h>
18+
#include <asm/vendor_extensions/thead_hwprobe.h>
1819
#include <vdso/vsyscall.h>
1920

2021

@@ -286,6 +287,10 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
286287
pair->value = riscv_timebase;
287288
break;
288289

290+
case RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0:
291+
hwprobe_isa_vendor_ext_thead_0(pair, cpus);
292+
break;
293+
289294
/*
290295
* For forward compatibility, unknown keys don't fail the whole
291296
* call, but get their element key set to -1 and value set to 0

arch/riscv/kernel/vendor_extensions/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
obj-$(CONFIG_RISCV_ISA_VENDOR_EXT_ANDES) += andes.o
44
obj-$(CONFIG_RISCV_ISA_VENDOR_EXT_THEAD) += thead.o
5+
obj-$(CONFIG_RISCV_ISA_VENDOR_EXT_THEAD) += thead_hwprobe.o
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <asm/vendor_extensions/thead.h>
4+
#include <asm/vendor_extensions/thead_hwprobe.h>
5+
#include <asm/vendor_extensions/vendor_hwprobe.h>
6+
7+
#include <linux/cpumask.h>
8+
#include <linux/types.h>
9+
10+
#include <uapi/asm/hwprobe.h>
11+
#include <uapi/asm/vendor/thead.h>
12+
13+
void hwprobe_isa_vendor_ext_thead_0(struct riscv_hwprobe *pair, const struct cpumask *cpus)
14+
{
15+
VENDOR_EXTENSION_SUPPORTED(pair, cpus,
16+
riscv_isa_vendor_ext_list_thead.per_hart_isa_bitmap, {
17+
VENDOR_EXT_KEY(XTHEADVECTOR);
18+
});
19+
}

0 commit comments

Comments
 (0)