Skip to content

Commit 010e12a

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Move cpufeature.h macros into their own header
asm/cmpxchg.h will soon need riscv_has_extension_unlikely() macros and then needs to include asm/cpufeature.h which introduces a lot of header circular dependencies. So move the riscv_has_extension_XXX() macros into their own header which prevents such circular dependencies by including a restricted number of headers. Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Andrea Parri <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 8198375 commit 010e12a

File tree

2 files changed

+70
-57
lines changed

2 files changed

+70
-57
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright 2022-2024 Rivos, Inc
4+
*/
5+
6+
#ifndef _ASM_CPUFEATURE_MACROS_H
7+
#define _ASM_CPUFEATURE_MACROS_H
8+
9+
#include <asm/hwcap.h>
10+
#include <asm/alternative-macros.h>
11+
12+
#define STANDARD_EXT 0
13+
14+
bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned int bit);
15+
#define riscv_isa_extension_available(isa_bitmap, ext) \
16+
__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext)
17+
18+
static __always_inline bool __riscv_has_extension_likely(const unsigned long vendor,
19+
const unsigned long ext)
20+
{
21+
asm goto(ALTERNATIVE("j %l[l_no]", "nop", %[vendor], %[ext], 1)
22+
:
23+
: [vendor] "i" (vendor), [ext] "i" (ext)
24+
:
25+
: l_no);
26+
27+
return true;
28+
l_no:
29+
return false;
30+
}
31+
32+
static __always_inline bool __riscv_has_extension_unlikely(const unsigned long vendor,
33+
const unsigned long ext)
34+
{
35+
asm goto(ALTERNATIVE("nop", "j %l[l_yes]", %[vendor], %[ext], 1)
36+
:
37+
: [vendor] "i" (vendor), [ext] "i" (ext)
38+
:
39+
: l_yes);
40+
41+
return false;
42+
l_yes:
43+
return true;
44+
}
45+
46+
static __always_inline bool riscv_has_extension_unlikely(const unsigned long ext)
47+
{
48+
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");
49+
50+
if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE))
51+
return __riscv_has_extension_unlikely(STANDARD_EXT, ext);
52+
53+
return __riscv_isa_extension_available(NULL, ext);
54+
}
55+
56+
static __always_inline bool riscv_has_extension_likely(const unsigned long ext)
57+
{
58+
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");
59+
60+
if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE))
61+
return __riscv_has_extension_likely(STANDARD_EXT, ext);
62+
63+
return __riscv_isa_extension_available(NULL, ext);
64+
}
65+
66+
#endif /* _ASM_CPUFEATURE_MACROS_H */

arch/riscv/include/asm/cpufeature.h

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
#include <linux/bitmap.h>
1010
#include <linux/jump_label.h>
11+
#include <linux/kconfig.h>
12+
#include <linux/percpu-defs.h>
13+
#include <linux/threads.h>
1114
#include <asm/hwcap.h>
12-
#include <asm/alternative-macros.h>
13-
#include <asm/errno.h>
15+
#include <asm/cpufeature-macros.h>
1416

1517
/*
1618
* These are probed via a device_initcall(), via either the SBI or directly
@@ -103,61 +105,6 @@ extern const size_t riscv_isa_ext_count;
103105
extern bool riscv_isa_fallback;
104106

105107
unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
106-
107-
#define STANDARD_EXT 0
108-
109-
bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned int bit);
110-
#define riscv_isa_extension_available(isa_bitmap, ext) \
111-
__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext)
112-
113-
static __always_inline bool __riscv_has_extension_likely(const unsigned long vendor,
114-
const unsigned long ext)
115-
{
116-
asm goto(ALTERNATIVE("j %l[l_no]", "nop", %[vendor], %[ext], 1)
117-
:
118-
: [vendor] "i" (vendor), [ext] "i" (ext)
119-
:
120-
: l_no);
121-
122-
return true;
123-
l_no:
124-
return false;
125-
}
126-
127-
static __always_inline bool __riscv_has_extension_unlikely(const unsigned long vendor,
128-
const unsigned long ext)
129-
{
130-
asm goto(ALTERNATIVE("nop", "j %l[l_yes]", %[vendor], %[ext], 1)
131-
:
132-
: [vendor] "i" (vendor), [ext] "i" (ext)
133-
:
134-
: l_yes);
135-
136-
return false;
137-
l_yes:
138-
return true;
139-
}
140-
141-
static __always_inline bool riscv_has_extension_unlikely(const unsigned long ext)
142-
{
143-
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");
144-
145-
if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE))
146-
return __riscv_has_extension_unlikely(STANDARD_EXT, ext);
147-
148-
return __riscv_isa_extension_available(NULL, ext);
149-
}
150-
151-
static __always_inline bool riscv_has_extension_likely(const unsigned long ext)
152-
{
153-
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");
154-
155-
if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE))
156-
return __riscv_has_extension_likely(STANDARD_EXT, ext);
157-
158-
return __riscv_isa_extension_available(NULL, ext);
159-
}
160-
161108
static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsigned long ext)
162109
{
163110
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");

0 commit comments

Comments
 (0)