Linux 4.15.10
[linux/fpc-iii.git] / arch / s390 / include / asm / facility.h
blobf040644575b7104c27d770e4f5b42ca85134be1b
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright IBM Corp. 1999, 2009
5 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
6 */
8 #ifndef __ASM_FACILITY_H
9 #define __ASM_FACILITY_H
11 #include <generated/facilities.h>
12 #include <linux/string.h>
13 #include <linux/preempt.h>
14 #include <asm/lowcore.h>
16 #define MAX_FACILITY_BIT (sizeof(((struct lowcore *)0)->stfle_fac_list) * 8)
18 static inline int __test_facility(unsigned long nr, void *facilities)
20 unsigned char *ptr;
22 if (nr >= MAX_FACILITY_BIT)
23 return 0;
24 ptr = (unsigned char *) facilities + (nr >> 3);
25 return (*ptr & (0x80 >> (nr & 7))) != 0;
29 * The test_facility function uses the bit odering where the MSB is bit 0.
30 * That makes it easier to query facility bits with the bit number as
31 * documented in the Principles of Operation.
33 static inline int test_facility(unsigned long nr)
35 unsigned long facilities_als[] = { FACILITIES_ALS };
37 if (__builtin_constant_p(nr) && nr < sizeof(facilities_als) * 8) {
38 if (__test_facility(nr, &facilities_als))
39 return 1;
41 return __test_facility(nr, &S390_lowcore.stfle_fac_list);
44 /**
45 * stfle - Store facility list extended
46 * @stfle_fac_list: array where facility list can be stored
47 * @size: size of passed in array in double words
49 static inline void stfle(u64 *stfle_fac_list, int size)
51 unsigned long nr;
53 preempt_disable();
54 asm volatile(
55 " stfl 0(0)\n"
56 : "=m" (S390_lowcore.stfl_fac_list));
57 nr = 4; /* bytes stored by stfl */
58 memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4);
59 if (S390_lowcore.stfl_fac_list & 0x01000000) {
60 /* More facility bits available with stfle */
61 register unsigned long reg0 asm("0") = size - 1;
63 asm volatile(".insn s,0xb2b00000,0(%1)" /* stfle */
64 : "+d" (reg0)
65 : "a" (stfle_fac_list)
66 : "memory", "cc");
67 nr = (reg0 + 1) * 8; /* # bytes stored by stfle */
69 memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
70 preempt_enable();
73 #endif /* __ASM_FACILITY_H */