summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm/include/s390x/facility.h
blob: 00a1ced6538b2b1e3f074ff0f6855d8a49f39dfe (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
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright IBM Corp. 2024
 *
 * Authors:
 *  Hariharan Mari <hari55@linux.ibm.com>
 *
 * Get the facility bits with the STFLE instruction
 */

#ifndef SELFTEST_KVM_FACILITY_H
#define SELFTEST_KVM_FACILITY_H

#include <linux/bitops.h>

/* alt_stfle_fac_list[16] + stfle_fac_list[16] */
#define NB_STFL_DOUBLEWORDS 32

extern uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
extern bool stfle_flag;

static inline bool test_bit_inv(unsigned long nr, const unsigned long *ptr)
{
	return test_bit(nr ^ (BITS_PER_LONG - 1), ptr);
}

static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
{
	register unsigned long r0 asm("0") = nb_doublewords - 1;

	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
			: "+d" (r0)
			: "a" (fac)
			: "memory", "cc");
}

static inline void setup_facilities(void)
{
	stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
	stfle_flag = true;
}

static inline bool test_facility(int nr)
{
	if (!stfle_flag)
		setup_facilities();
	return test_bit_inv(nr, stfl_doublewords);
}

#endif