xref: /kvm-unit-tests/lib/s390x/asm/facility.h (revision 28f482bdae7bbbd0ff967eef8514de264eb6bc38)
1 /*
2  * Copyright (c) 2017 Red Hat Inc
3  *
4  * Authors:
5  *  David Hildenbrand <david@redhat.com>
6  *
7  * This code is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Library General Public License version 2.
9  */
10 #ifndef _ASM_S390X_FACILITY_H_
11 #define _ASM_S390X_FACILITY_H_
12 
13 #include <libcflat.h>
14 #include <asm/facility.h>
15 #include <asm/arch_def.h>
16 
17 #define NR_STFL_BYTES 256
18 extern uint8_t stfl_bytes[];
19 
20 static inline bool test_facility(int nr)
21 {
22 	return stfl_bytes[nr / 8] & (0x80U >> (nr % 8));
23 }
24 
25 static inline void stfl(void)
26 {
27 	asm volatile("	stfl	0(0)\n");
28 }
29 
30 static inline void stfle(uint8_t *fac, unsigned int len)
31 {
32 	register unsigned long r0 asm("0") = len - 1;
33 
34 	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
35 		     : "+d" (r0) : "a" (fac) : "memory", "cc");
36 }
37 
38 static inline void setup_facilities(void)
39 {
40 	struct lowcore *lc = NULL;
41 
42 	stfl();
43 	memcpy(stfl_bytes, &lc->stfl, sizeof(lc->stfl));
44 	if (test_facility(7))
45 		stfle(stfl_bytes, NR_STFL_BYTES);
46 }
47 
48 #endif
49