Skip to content

Commit b5bc00f

Browse files
brooniewilldeacon
authored andcommitted
arm64/sve: Put system wide vector length information into structs
With the introduction of SME we will have a second vector length in the system, enumerated and configured in a very similar fashion to the existing SVE vector length. While there are a few differences in how things are handled this is a relatively small portion of the overall code so in order to avoid code duplication we factor out We create two structs, one vl_info for the static hardware properties and one vl_config for the runtime configuration, with an array instantiated for each and update all the users to reference these. Some accessor functions are provided where helpful for readability, and the write to set the vector length is put into a function since the system register being updated needs to be chosen at compile time. This is a mostly mechanical replacement, further work will be required to actually make things generic, ensuring that we handle those places where there are differences properly. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 0423eed commit b5bc00f

File tree

7 files changed

+191
-94
lines changed

7 files changed

+191
-94
lines changed

arch/arm64/include/asm/fpsimd.h

Lines changed: 86 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ extern void sve_kernel_enable(const struct arm64_cpu_capabilities *__unused);
7777

7878
extern u64 read_zcr_features(void);
7979

80-
extern int __ro_after_init sve_max_vl;
81-
extern int __ro_after_init sve_max_virtualisable_vl;
82-
extern __ro_after_init DECLARE_BITMAP(sve_vq_map, SVE_VQ_MAX);
83-
8480
/*
8581
* Helpers to translate bit indices in sve_vq_map to VQ values (and
8682
* vice versa). This allows find_next_bit() to be used to find the
@@ -96,11 +92,27 @@ static inline unsigned int __bit_to_vq(unsigned int bit)
9692
return SVE_VQ_MAX - bit;
9793
}
9894

99-
/* Ensure vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX before calling this function */
100-
static inline bool sve_vq_available(unsigned int vq)
101-
{
102-
return test_bit(__vq_to_bit(vq), sve_vq_map);
103-
}
95+
96+
struct vl_info {
97+
enum vec_type type;
98+
const char *name; /* For display purposes */
99+
100+
/* Minimum supported vector length across all CPUs */
101+
int min_vl;
102+
103+
/* Maximum supported vector length across all CPUs */
104+
int max_vl;
105+
int max_virtualisable_vl;
106+
107+
/*
108+
* Set of available vector lengths,
109+
* where length vq encoded as bit __vq_to_bit(vq):
110+
*/
111+
DECLARE_BITMAP(vq_map, SVE_VQ_MAX);
112+
113+
/* Set of vector lengths present on at least one cpu: */
114+
DECLARE_BITMAP(vq_partial_map, SVE_VQ_MAX);
115+
};
104116

105117
#ifdef CONFIG_ARM64_SVE
106118

@@ -139,11 +151,63 @@ static inline void sve_user_enable(void)
139151
* Probing and setup functions.
140152
* Calls to these functions must be serialised with one another.
141153
*/
142-
extern void __init sve_init_vq_map(void);
143-
extern void sve_update_vq_map(void);
144-
extern int sve_verify_vq_map(void);
154+
enum vec_type;
155+
156+
extern void __init vec_init_vq_map(enum vec_type type);
157+
extern void vec_update_vq_map(enum vec_type type);
158+
extern int vec_verify_vq_map(enum vec_type type);
145159
extern void __init sve_setup(void);
146160

161+
extern __ro_after_init struct vl_info vl_info[ARM64_VEC_MAX];
162+
163+
static inline void write_vl(enum vec_type type, u64 val)
164+
{
165+
u64 tmp;
166+
167+
switch (type) {
168+
#ifdef CONFIG_ARM64_SVE
169+
case ARM64_VEC_SVE:
170+
tmp = read_sysreg_s(SYS_ZCR_EL1) & ~ZCR_ELx_LEN_MASK;
171+
write_sysreg_s(tmp | val, SYS_ZCR_EL1);
172+
break;
173+
#endif
174+
default:
175+
WARN_ON_ONCE(1);
176+
break;
177+
}
178+
}
179+
180+
static inline int vec_max_vl(enum vec_type type)
181+
{
182+
return vl_info[type].max_vl;
183+
}
184+
185+
static inline int vec_max_virtualisable_vl(enum vec_type type)
186+
{
187+
return vl_info[type].max_virtualisable_vl;
188+
}
189+
190+
static inline int sve_max_vl(void)
191+
{
192+
return vec_max_vl(ARM64_VEC_SVE);
193+
}
194+
195+
static inline int sve_max_virtualisable_vl(void)
196+
{
197+
return vec_max_virtualisable_vl(ARM64_VEC_SVE);
198+
}
199+
200+
/* Ensure vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX before calling this function */
201+
static inline bool vq_available(enum vec_type type, unsigned int vq)
202+
{
203+
return test_bit(__vq_to_bit(vq), vl_info[type].vq_map);
204+
}
205+
206+
static inline bool sve_vq_available(unsigned int vq)
207+
{
208+
return vq_available(ARM64_VEC_SVE, vq);
209+
}
210+
147211
#else /* ! CONFIG_ARM64_SVE */
148212

149213
static inline void sve_alloc(struct task_struct *task) { }
@@ -161,14 +225,21 @@ static inline int sve_get_current_vl(void)
161225
return -EINVAL;
162226
}
163227

228+
static inline int sve_max_vl(void)
229+
{
230+
return -EINVAL;
231+
}
232+
233+
static inline bool sve_vq_available(unsigned int vq) { return false; }
234+
164235
static inline void sve_user_disable(void) { BUILD_BUG(); }
165236
static inline void sve_user_enable(void) { BUILD_BUG(); }
166237

167238
#define sve_cond_update_zcr_vq(val, reg) do { } while (0)
168239

169-
static inline void sve_init_vq_map(void) { }
170-
static inline void sve_update_vq_map(void) { }
171-
static inline int sve_verify_vq_map(void) { return 0; }
240+
static inline void vec_init_vq_map(enum vec_type t) { }
241+
static inline void vec_update_vq_map(enum vec_type t) { }
242+
static inline int vec_verify_vq_map(enum vec_type t) { return 0; }
172243
static inline void sve_setup(void) { }
173244

174245
#endif /* ! CONFIG_ARM64_SVE */

arch/arm64/include/asm/processor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ struct debug_info {
115115
#endif
116116
};
117117

118+
enum vec_type {
119+
ARM64_VEC_SVE = 0,
120+
ARM64_VEC_MAX,
121+
};
122+
118123
struct cpu_context {
119124
unsigned long x19;
120125
unsigned long x20;

arch/arm64/kernel/cpufeature.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ void __init init_cpu_features(struct cpuinfo_arm64 *info)
941941

942942
if (id_aa64pfr0_sve(info->reg_id_aa64pfr0)) {
943943
init_cpu_ftr_reg(SYS_ZCR_EL1, info->reg_zcr);
944-
sve_init_vq_map();
944+
vec_init_vq_map(ARM64_VEC_SVE);
945945
}
946946

947947
if (id_aa64pfr1_mte(info->reg_id_aa64pfr1))
@@ -1175,7 +1175,7 @@ void update_cpu_features(int cpu,
11751175
/* Probe vector lengths, unless we already gave up on SVE */
11761176
if (id_aa64pfr0_sve(read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1)) &&
11771177
!system_capabilities_finalized())
1178-
sve_update_vq_map();
1178+
vec_update_vq_map(ARM64_VEC_SVE);
11791179
}
11801180

11811181
/*
@@ -2739,7 +2739,7 @@ static void verify_sve_features(void)
27392739
unsigned int safe_len = safe_zcr & ZCR_ELx_LEN_MASK;
27402740
unsigned int len = zcr & ZCR_ELx_LEN_MASK;
27412741

2742-
if (len < safe_len || sve_verify_vq_map()) {
2742+
if (len < safe_len || vec_verify_vq_map(ARM64_VEC_SVE)) {
27432743
pr_crit("CPU%d: SVE: vector length support mismatch\n",
27442744
smp_processor_id());
27452745
cpu_die_early();

0 commit comments

Comments
 (0)