Linux Audio

Check our new training course

Loading...
v6.2
  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
 13#include <linux/minmax.h>
 14#include <linux/string.h>
 15#include <linux/types.h>
 16#include <linux/preempt.h>
 17
 18#include <asm/lowcore.h>
 19
 20#define MAX_FACILITY_BIT (sizeof(stfle_fac_list) * 8)
 21
 22extern u64 stfle_fac_list[16];
 23extern u64 alt_stfle_fac_list[16];
 24
 25static inline void __set_facility(unsigned long nr, void *facilities)
 26{
 27	unsigned char *ptr = (unsigned char *) facilities;
 28
 29	if (nr >= MAX_FACILITY_BIT)
 30		return;
 31	ptr[nr >> 3] |= 0x80 >> (nr & 7);
 32}
 33
 34static inline void __clear_facility(unsigned long nr, void *facilities)
 35{
 36	unsigned char *ptr = (unsigned char *) facilities;
 37
 38	if (nr >= MAX_FACILITY_BIT)
 39		return;
 40	ptr[nr >> 3] &= ~(0x80 >> (nr & 7));
 41}
 42
 43static inline int __test_facility(unsigned long nr, void *facilities)
 44{
 45	unsigned char *ptr;
 46
 47	if (nr >= MAX_FACILITY_BIT)
 48		return 0;
 49	ptr = (unsigned char *) facilities + (nr >> 3);
 50	return (*ptr & (0x80 >> (nr & 7))) != 0;
 51}
 52
 53/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 54 * The test_facility function uses the bit ordering where the MSB is bit 0.
 55 * That makes it easier to query facility bits with the bit number as
 56 * documented in the Principles of Operation.
 57 */
 58static inline int test_facility(unsigned long nr)
 59{
 60	unsigned long facilities_als[] = { FACILITIES_ALS };
 61
 62	if (__builtin_constant_p(nr) && nr < sizeof(facilities_als) * 8) {
 63		if (__test_facility(nr, &facilities_als))
 64			return 1;
 
 
 
 65	}
 66	return __test_facility(nr, &stfle_fac_list);
 67}
 68
 69static inline unsigned long __stfle_asm(u64 *stfle_fac_list, int size)
 70{
 71	unsigned long reg0 = size - 1;
 72
 73	asm volatile(
 74		"	lgr	0,%[reg0]\n"
 75		"	.insn	s,0xb2b00000,%[list]\n" /* stfle */
 76		"	lgr	%[reg0],0\n"
 77		: [reg0] "+&d" (reg0), [list] "+Q" (*stfle_fac_list)
 78		:
 79		: "memory", "cc", "0");
 80	return reg0;
 81}
 82
 83/**
 84 * stfle - Store facility list extended
 85 * @stfle_fac_list: array where facility list can be stored
 86 * @size: size of passed in array in double words
 87 */
 88static inline void __stfle(u64 *stfle_fac_list, int size)
 89{
 90	unsigned long nr;
 91	u32 stfl_fac_list;
 92
 93	asm volatile(
 94		"	stfl	0(0)\n"
 95		: "=m" (S390_lowcore.stfl_fac_list));
 96	stfl_fac_list = S390_lowcore.stfl_fac_list;
 97	memcpy(stfle_fac_list, &stfl_fac_list, 4);
 98	nr = 4; /* bytes stored by stfl */
 99	if (stfl_fac_list & 0x01000000) {
100		/* More facility bits available with stfle */
101		nr = __stfle_asm(stfle_fac_list, size);
102		nr = min_t(unsigned long, (nr + 1) * 8, size * 8);
103	}
104	memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
105}
106
107static inline void stfle(u64 *stfle_fac_list, int size)
108{
109	preempt_disable();
110	__stfle(stfle_fac_list, size);
111	preempt_enable();
112}
 
 
 
 
 
 
113
114#endif /* __ASM_FACILITY_H */
v6.13.7
  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
 13#include <linux/minmax.h>
 14#include <linux/string.h>
 15#include <linux/types.h>
 16#include <linux/preempt.h>
 17#include <asm/alternative.h>
 18#include <asm/lowcore.h>
 19
 20#define MAX_FACILITY_BIT (sizeof(stfle_fac_list) * 8)
 21
 22extern u64 stfle_fac_list[16];
 
 23
 24static inline void __set_facility(unsigned long nr, void *facilities)
 25{
 26	unsigned char *ptr = (unsigned char *) facilities;
 27
 28	if (nr >= MAX_FACILITY_BIT)
 29		return;
 30	ptr[nr >> 3] |= 0x80 >> (nr & 7);
 31}
 32
 33static inline void __clear_facility(unsigned long nr, void *facilities)
 34{
 35	unsigned char *ptr = (unsigned char *) facilities;
 36
 37	if (nr >= MAX_FACILITY_BIT)
 38		return;
 39	ptr[nr >> 3] &= ~(0x80 >> (nr & 7));
 40}
 41
 42static __always_inline bool __test_facility(unsigned long nr, void *facilities)
 43{
 44	unsigned char *ptr;
 45
 46	if (nr >= MAX_FACILITY_BIT)
 47		return false;
 48	ptr = (unsigned char *) facilities + (nr >> 3);
 49	return (*ptr & (0x80 >> (nr & 7))) != 0;
 50}
 51
 52/*
 53 * __test_facility_constant() generates a single instruction branch. If the
 54 * tested facility is available (likely) the branch is patched into a nop.
 55 *
 56 * Do not use this function unless you know what you are doing. All users are
 57 * supposed to use test_facility() which will do the right thing.
 58 */
 59static __always_inline bool __test_facility_constant(unsigned long nr)
 60{
 61	asm goto(
 62		ALTERNATIVE("brcl 15,%l[l_no]", "brcl 0,0", ALT_FACILITY(%[nr]))
 63		:
 64		: [nr] "i" (nr)
 65		:
 66		: l_no);
 67	return true;
 68l_no:
 69	return false;
 70}
 71
 72/*
 73 * The test_facility function uses the bit ordering where the MSB is bit 0.
 74 * That makes it easier to query facility bits with the bit number as
 75 * documented in the Principles of Operation.
 76 */
 77static __always_inline bool test_facility(unsigned long nr)
 78{
 79	unsigned long facilities_als[] = { FACILITIES_ALS };
 80
 81	if (!__is_defined(__DECOMPRESSOR) && __builtin_constant_p(nr)) {
 82		if (nr < sizeof(facilities_als) * 8) {
 83			if (__test_facility(nr, &facilities_als))
 84				return true;
 85		}
 86		return __test_facility_constant(nr);
 87	}
 88	return __test_facility(nr, &stfle_fac_list);
 89}
 90
 91static inline unsigned long __stfle_asm(u64 *fac_list, int size)
 92{
 93	unsigned long reg0 = size - 1;
 94
 95	asm volatile(
 96		"	lgr	0,%[reg0]\n"
 97		"	.insn	s,0xb2b00000,%[list]\n" /* stfle */
 98		"	lgr	%[reg0],0\n"
 99		: [reg0] "+&d" (reg0), [list] "+Q" (*fac_list)
100		:
101		: "memory", "cc", "0");
102	return reg0;
103}
104
105/**
106 * stfle - Store facility list extended
107 * @fac_list: array where facility list can be stored
108 * @size: size of passed in array in double words
109 */
110static inline void __stfle(u64 *fac_list, int size)
111{
112	unsigned long nr;
113	u32 stfl_fac_list;
114
115	asm volatile(
116		"	stfl	0(0)\n"
117		: "=m" (get_lowcore()->stfl_fac_list));
118	stfl_fac_list = get_lowcore()->stfl_fac_list;
119	memcpy(fac_list, &stfl_fac_list, 4);
120	nr = 4; /* bytes stored by stfl */
121	if (stfl_fac_list & 0x01000000) {
122		/* More facility bits available with stfle */
123		nr = __stfle_asm(fac_list, size);
124		nr = min_t(unsigned long, (nr + 1) * 8, size * 8);
125	}
126	memset((char *)fac_list + nr, 0, size * 8 - nr);
127}
128
129static inline void stfle(u64 *fac_list, int size)
130{
131	preempt_disable();
132	__stfle(fac_list, size);
133	preempt_enable();
134}
135
136/**
137 * stfle_size - Actual size of the facility list as specified by stfle
138 * (number of double words)
139 */
140unsigned int stfle_size(void);
141
142#endif /* __ASM_FACILITY_H */