0001
0002
0003
0004
0005
0006
0007
0008 #ifndef __ASM_FACILITY_H
0009 #define __ASM_FACILITY_H
0010
0011 #include <asm/facility-defs.h>
0012
0013 #include <linux/minmax.h>
0014 #include <linux/string.h>
0015 #include <linux/types.h>
0016 #include <linux/preempt.h>
0017
0018 #include <asm/lowcore.h>
0019
0020 #define MAX_FACILITY_BIT (sizeof(stfle_fac_list) * 8)
0021
0022 extern u64 stfle_fac_list[16];
0023 extern u64 alt_stfle_fac_list[16];
0024
0025 static inline void __set_facility(unsigned long nr, void *facilities)
0026 {
0027 unsigned char *ptr = (unsigned char *) facilities;
0028
0029 if (nr >= MAX_FACILITY_BIT)
0030 return;
0031 ptr[nr >> 3] |= 0x80 >> (nr & 7);
0032 }
0033
0034 static inline void __clear_facility(unsigned long nr, void *facilities)
0035 {
0036 unsigned char *ptr = (unsigned char *) facilities;
0037
0038 if (nr >= MAX_FACILITY_BIT)
0039 return;
0040 ptr[nr >> 3] &= ~(0x80 >> (nr & 7));
0041 }
0042
0043 static inline int __test_facility(unsigned long nr, void *facilities)
0044 {
0045 unsigned char *ptr;
0046
0047 if (nr >= MAX_FACILITY_BIT)
0048 return 0;
0049 ptr = (unsigned char *) facilities + (nr >> 3);
0050 return (*ptr & (0x80 >> (nr & 7))) != 0;
0051 }
0052
0053
0054
0055
0056
0057
0058 static inline int test_facility(unsigned long nr)
0059 {
0060 unsigned long facilities_als[] = { FACILITIES_ALS };
0061
0062 if (__builtin_constant_p(nr) && nr < sizeof(facilities_als) * 8) {
0063 if (__test_facility(nr, &facilities_als))
0064 return 1;
0065 }
0066 return __test_facility(nr, &stfle_fac_list);
0067 }
0068
0069 static inline unsigned long __stfle_asm(u64 *stfle_fac_list, int size)
0070 {
0071 unsigned long reg0 = size - 1;
0072
0073 asm volatile(
0074 " lgr 0,%[reg0]\n"
0075 " .insn s,0xb2b00000,%[list]\n"
0076 " lgr %[reg0],0\n"
0077 : [reg0] "+&d" (reg0), [list] "+Q" (*stfle_fac_list)
0078 :
0079 : "memory", "cc", "0");
0080 return reg0;
0081 }
0082
0083
0084
0085
0086
0087
0088 static inline void __stfle(u64 *stfle_fac_list, int size)
0089 {
0090 unsigned long nr;
0091 u32 stfl_fac_list;
0092
0093 asm volatile(
0094 " stfl 0(0)\n"
0095 : "=m" (S390_lowcore.stfl_fac_list));
0096 stfl_fac_list = S390_lowcore.stfl_fac_list;
0097 memcpy(stfle_fac_list, &stfl_fac_list, 4);
0098 nr = 4;
0099 if (stfl_fac_list & 0x01000000) {
0100
0101 nr = __stfle_asm(stfle_fac_list, size);
0102 nr = min_t(unsigned long, (nr + 1) * 8, size * 8);
0103 }
0104 memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
0105 }
0106
0107 static inline void stfle(u64 *stfle_fac_list, int size)
0108 {
0109 preempt_disable();
0110 __stfle(stfle_fac_list, size);
0111 preempt_enable();
0112 }
0113
0114 #endif