summaryrefslogtreecommitdiffstats
path: root/arch/powerpc/include/asm/cpu_has_feature.h
blob: 0efabccd820cf2552dd84302b72403905f959be6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __ASM_POWERPC_CPU_HAS_FEATURE_H
#define __ASM_POWERPC_CPU_HAS_FEATURE_H

#ifndef __ASSEMBLY__

#include <linux/bug.h>
#include <asm/cputable.h>

static __always_inline bool early_cpu_has_feature(unsigned long feature)
{
	return !!((CPU_FTRS_ALWAYS & feature) ||
		  (CPU_FTRS_POSSIBLE & cur_cpu_spec->cpu_features & feature));
}

#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
#include <linux/jump_label.h>

#define NUM_CPU_FTR_KEYS	BITS_PER_LONG

extern struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS];

static __always_inline bool cpu_has_feature(unsigned long feature)
{
	int i;

#ifndef __clang__ /* clang can't cope with this */
	BUILD_BUG_ON(!__builtin_constant_p(feature));
#endif

#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
	if (!static_key_feature_checks_initialized) {
		printk("Warning! cpu_has_feature() used prior to jump label init!\n");
		dump_stack();
		return early_cpu_has_feature(feature);
	}
#endif

	if (CPU_FTRS_ALWAYS & feature)
		return true;

	if (!(CPU_FTRS_POSSIBLE & feature))
		return false;

	i = __builtin_ctzl(feature);
	return static_branch_likely(&cpu_feature_keys[i]);
}
#else
static __always_inline bool cpu_has_feature(unsigned long feature)
{
	return early_cpu_has_feature(feature);
}
#endif

#endif /* __ASSEMBLY__ */
#endif /* __ASM_POWERPC_CPU_HAS_FEATURE_H */