File: facility.h

package info (click to toggle)
linux 6.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,742,096 kB
  • sloc: ansic: 26,781,576; asm: 272,087; sh: 148,750; python: 79,244; makefile: 57,741; perl: 36,527; xml: 19,542; cpp: 5,911; yacc: 4,939; lex: 2,950; awk: 1,607; sed: 30; ruby: 25
file content (50 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download | duplicates (10)
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