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