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