• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright IBM Corp. 1999, 2009
3  *
4  * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
5  */
6 
7 #ifndef __ASM_FACILITY_H
8 #define __ASM_FACILITY_H
9 
10 #include <linux/string.h>
11 #include <linux/preempt.h>
12 #include <asm/lowcore.h>
13 
14 #define MAX_FACILITY_BIT (256*8)	/* stfle_fac_list has 256 bytes */
15 
__set_facility(unsigned long nr,void * facilities)16 static inline void __set_facility(unsigned long nr, void *facilities)
17 {
18 	unsigned char *ptr = (unsigned char *) facilities;
19 
20 	if (nr >= MAX_FACILITY_BIT)
21 		return;
22 	ptr[nr >> 3] |= 0x80 >> (nr & 7);
23 }
24 
__clear_facility(unsigned long nr,void * facilities)25 static inline void __clear_facility(unsigned long nr, void *facilities)
26 {
27 	unsigned char *ptr = (unsigned char *) facilities;
28 
29 	if (nr >= MAX_FACILITY_BIT)
30 		return;
31 	ptr[nr >> 3] &= ~(0x80 >> (nr & 7));
32 }
33 
__test_facility(unsigned long nr,void * facilities)34 static inline int __test_facility(unsigned long nr, void *facilities)
35 {
36 	unsigned char *ptr;
37 
38 	if (nr >= MAX_FACILITY_BIT)
39 		return 0;
40 	ptr = (unsigned char *) facilities + (nr >> 3);
41 	return (*ptr & (0x80 >> (nr & 7))) != 0;
42 }
43 
44 /*
45  * The test_facility function uses the bit odering where the MSB is bit 0.
46  * That makes it easier to query facility bits with the bit number as
47  * documented in the Principles of Operation.
48  */
test_facility(unsigned long nr)49 static inline int test_facility(unsigned long nr)
50 {
51 	return __test_facility(nr, &S390_lowcore.stfle_fac_list);
52 }
53 
__stfle_asm(u64 * stfle_fac_list,int size)54 static inline unsigned long __stfle_asm(u64 *stfle_fac_list, int size)
55 {
56 	register unsigned long reg0 asm("0") = size - 1;
57 
58 	asm volatile(
59 		".insn s,0xb2b00000,0(%1)" /* stfle */
60 		: "+d" (reg0)
61 		: "a" (stfle_fac_list)
62 		: "memory", "cc");
63 	return reg0;
64 }
65 
66 /**
67  * stfle - Store facility list extended
68  * @stfle_fac_list: array where facility list can be stored
69  * @size: size of passed in array in double words
70  */
stfle(u64 * stfle_fac_list,int size)71 static inline void stfle(u64 *stfle_fac_list, int size)
72 {
73 	unsigned long nr;
74 
75 	preempt_disable();
76 	asm volatile(
77 		"	.insn s,0xb2b10000,0(0)\n" /* stfl */
78 		"0:\n"
79 		EX_TABLE(0b, 0b)
80 		: "+m" (S390_lowcore.stfl_fac_list));
81 	nr = 4; /* bytes stored by stfl */
82 	memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4);
83 	if (S390_lowcore.stfl_fac_list & 0x01000000) {
84 		/* More facility bits available with stfle */
85 		nr = __stfle_asm(stfle_fac_list, size);
86 		nr = min_t(unsigned long, (nr + 1) * 8, size * 8);
87 	}
88 	memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
89 	preempt_enable();
90 }
91 
92 #endif /* __ASM_FACILITY_H */
93