xref: /kvm-unit-tests/lib/s390x/asm/facility.h (revision 6c9f99df2fa51f58bd6a8b6775810b7f249bd0d7)
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 _ASM_S390X_FACILITY_H_
9 #define _ASM_S390X_FACILITY_H_
10 
11 #include <libcflat.h>
12 #include <asm/facility.h>
13 #include <asm/arch_def.h>
14 
15 #define NB_STFL_DOUBLEWORDS 32
16 extern uint64_t stfl_doublewords[];
17 
18 static inline bool test_facility(int nr)
19 {
20 	return stfl_doublewords[nr / 64] & (0x8000000000000000UL >> (nr % 64));
21 }
22 
23 static inline void stfl(void)
24 {
25 	asm volatile("	stfl	0(0)\n" : : : "memory");
26 }
27 
28 static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
29 {
30 	register unsigned long r0 asm("0") = nb_doublewords - 1;
31 
32 	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
33 		     : "+d" (r0) : "a" (fac) : "memory", "cc");
34 }
35 
36 static inline void setup_facilities(void)
37 {
38 	struct lowcore *lc = NULL;
39 
40 	stfl();
41 	memcpy(stfl_doublewords, &lc->stfl, sizeof(lc->stfl));
42 	if (test_facility(7))
43 		stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
44 }
45 
46 #endif
47