License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / arch / s390 / include / asm / facility.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
a0616cde
DH
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
c30f6828 11#include <generated/facilities.h>
a0616cde
DH
12#include <linux/string.h>
13#include <linux/preempt.h>
14#include <asm/lowcore.h>
15
6f5165e8 16#define MAX_FACILITY_BIT (sizeof(((struct lowcore *)0)->stfle_fac_list) * 8)
a0616cde 17
32089246
MM
18static inline int __test_facility(unsigned long nr, void *facilities)
19{
20 unsigned char *ptr;
21
22 if (nr >= MAX_FACILITY_BIT)
23 return 0;
24 ptr = (unsigned char *) facilities + (nr >> 3);
25 return (*ptr & (0x80 >> (nr & 7))) != 0;
26}
27
a0616cde
DH
28/*
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.
32 */
33static inline int test_facility(unsigned long nr)
34{
6ab6c31a
HC
35 unsigned long facilities_als[] = { FACILITIES_ALS };
36
37 if (__builtin_constant_p(nr) && nr < sizeof(facilities_als) * 8) {
38 if (__test_facility(nr, &facilities_als))
39 return 1;
40 }
32089246 41 return __test_facility(nr, &S390_lowcore.stfle_fac_list);
a0616cde
DH
42}
43
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
48 */
49static inline void stfle(u64 *stfle_fac_list, int size)
50{
51 unsigned long nr;
52
53 preempt_disable();
a0616cde 54 asm volatile(
9552a66f
HC
55 " stfl 0(0)\n"
56 : "=m" (S390_lowcore.stfl_fac_list));
a0616cde
DH
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;
62
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 */
68 }
69 memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
70 preempt_enable();
71}
72
73#endif /* __ASM_FACILITY_H */