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