xref: /kvm-unit-tests/lib/s390x/asm/facility.h (revision cd719531ee2b3aae62a52cfe97aa6aa5286e4051)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2017 Red Hat Inc
4  *
5  * Authors:
6  *  David Hildenbrand <david@redhat.com>
7  */
8 #ifndef _ASMS390X_FACILITY_H_
9 #define _ASMS390X_FACILITY_H_
10 
11 #include <libcflat.h>
12 #include <asm/facility.h>
13 #include <asm/arch_def.h>
14 #include <bitops.h>
15 
16 #define NB_STFL_DOUBLEWORDS 32
17 extern uint64_t stfl_doublewords[];
18 
19 static inline bool test_facility(int nr)
20 {
21 	return test_bit_inv(nr, stfl_doublewords);
22 }
23 
24 static inline void stfl(void)
25 {
26 	asm volatile("	stfl	0(0)\n" : : : "memory");
27 }
28 
29 static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
30 {
31 	register unsigned long r0 asm("0") = nb_doublewords - 1;
32 
33 	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
34 		     : "+d" (r0) : "a" (fac) : "memory", "cc");
35 }
36 
37 static inline void setup_facilities(void)
38 {
39 	stfl();
40 	memcpy(stfl_doublewords, &lowcore.stfl, sizeof(lowcore.stfl));
41 	if (test_facility(7))
42 		stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
43 }
44 
45 #endif
46