Commit | Line | Data |
---|---|---|
a0616cde DH |
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 | ||
c30f6828 HC |
10 | #include <generated/facilities.h> |
11 | ||
12 | #ifndef __ASSEMBLY__ | |
13 | ||
a0616cde DH |
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 | ||
32089246 MM |
20 | static inline int __test_facility(unsigned long nr, void *facilities) |
21 | { | |
22 | unsigned char *ptr; | |
23 | ||
24 | if (nr >= MAX_FACILITY_BIT) | |
25 | return 0; | |
26 | ptr = (unsigned char *) facilities + (nr >> 3); | |
27 | return (*ptr & (0x80 >> (nr & 7))) != 0; | |
28 | } | |
29 | ||
a0616cde DH |
30 | /* |
31 | * The test_facility function uses the bit odering where the MSB is bit 0. | |
32 | * That makes it easier to query facility bits with the bit number as | |
33 | * documented in the Principles of Operation. | |
34 | */ | |
35 | static inline int test_facility(unsigned long nr) | |
36 | { | |
6ab6c31a HC |
37 | unsigned long facilities_als[] = { FACILITIES_ALS }; |
38 | ||
39 | if (__builtin_constant_p(nr) && nr < sizeof(facilities_als) * 8) { | |
40 | if (__test_facility(nr, &facilities_als)) | |
41 | return 1; | |
42 | } | |
32089246 | 43 | return __test_facility(nr, &S390_lowcore.stfle_fac_list); |
a0616cde DH |
44 | } |
45 | ||
46 | /** | |
47 | * stfle - Store facility list extended | |
48 | * @stfle_fac_list: array where facility list can be stored | |
49 | * @size: size of passed in array in double words | |
50 | */ | |
51 | static inline void stfle(u64 *stfle_fac_list, int size) | |
52 | { | |
53 | unsigned long nr; | |
54 | ||
55 | preempt_disable(); | |
a0616cde | 56 | asm volatile( |
9552a66f HC |
57 | " stfl 0(0)\n" |
58 | : "=m" (S390_lowcore.stfl_fac_list)); | |
a0616cde DH |
59 | nr = 4; /* bytes stored by stfl */ |
60 | memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4); | |
61 | if (S390_lowcore.stfl_fac_list & 0x01000000) { | |
62 | /* More facility bits available with stfle */ | |
63 | register unsigned long reg0 asm("0") = size - 1; | |
64 | ||
65 | asm volatile(".insn s,0xb2b00000,0(%1)" /* stfle */ | |
66 | : "+d" (reg0) | |
67 | : "a" (stfle_fac_list) | |
68 | : "memory", "cc"); | |
69 | nr = (reg0 + 1) * 8; /* # bytes stored by stfle */ | |
70 | } | |
71 | memset((char *) stfle_fac_list + nr, 0, size * 8 - nr); | |
72 | preempt_enable(); | |
73 | } | |
74 | ||
c30f6828 | 75 | #endif /* __ASSEMBLY__ */ |
a0616cde | 76 | #endif /* __ASM_FACILITY_H */ |