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