2 * Copyright IBM Corp. 1999, 2009
4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7 #ifndef __ASM_FACILITY_H
8 #define __ASM_FACILITY_H
10 #include <generated/facilities.h>
14 #include <linux/string.h>
15 #include <linux/preempt.h>
16 #include <asm/lowcore.h>
18 #define MAX_FACILITY_BIT (sizeof(((struct lowcore *)0)->stfle_fac_list) * 8)
20 static inline void __set_facility(unsigned long nr, void *facilities)
22 unsigned char *ptr = (unsigned char *) facilities;
24 if (nr >= MAX_FACILITY_BIT)
26 ptr[nr >> 3] |= 0x80 >> (nr & 7);
29 static inline void __clear_facility(unsigned long nr, void *facilities)
31 unsigned char *ptr = (unsigned char *) facilities;
33 if (nr >= MAX_FACILITY_BIT)
35 ptr[nr >> 3] &= ~(0x80 >> (nr & 7));
38 static inline int __test_facility(unsigned long nr, void *facilities)
42 if (nr >= MAX_FACILITY_BIT)
44 ptr = (unsigned char *) facilities + (nr >> 3);
45 return (*ptr & (0x80 >> (nr & 7))) != 0;
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.
53 static inline int test_facility(unsigned long nr)
55 unsigned long facilities_als[] = { FACILITIES_ALS };
57 if (__builtin_constant_p(nr) && nr < sizeof(facilities_als) * 8) {
58 if (__test_facility(nr, &facilities_als))
61 return __test_facility(nr, &S390_lowcore.stfle_fac_list);
64 static inline unsigned long __stfle_asm(u64 *stfle_fac_list, int size)
66 register unsigned long reg0 asm("0") = size - 1;
69 ".insn s,0xb2b00000,0(%1)" /* stfle */
71 : "a" (stfle_fac_list)
77 * stfle - Store facility list extended
78 * @stfle_fac_list: array where facility list can be stored
79 * @size: size of passed in array in double words
81 static inline void stfle(u64 *stfle_fac_list, int size)
88 : "=m" (S390_lowcore.stfl_fac_list));
89 nr = 4; /* bytes stored by stfl */
90 memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4);
91 if (S390_lowcore.stfl_fac_list & 0x01000000) {
92 /* More facility bits available with stfle */
93 nr = __stfle_asm(stfle_fac_list, size);
94 nr = min_t(unsigned long, (nr + 1) * 8, size * 8);
96 memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
100 #endif /* __ASSEMBLY__ */
101 #endif /* __ASM_FACILITY_H */