xref: /openbmc/linux/arch/s390/include/asm/airq.h (revision 7cc39531)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *    Copyright IBM Corp. 2002, 2007
4  *    Author(s): Ingo Adlung <adlung@de.ibm.com>
5  *		 Cornelia Huck <cornelia.huck@de.ibm.com>
6  *		 Arnd Bergmann <arndb@de.ibm.com>
7  *		 Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
8  */
9 
10 #ifndef _ASM_S390_AIRQ_H
11 #define _ASM_S390_AIRQ_H
12 
13 #include <linux/bit_spinlock.h>
14 #include <linux/dma-mapping.h>
15 #include <asm/tpi.h>
16 
17 struct airq_struct {
18 	struct hlist_node list;		/* Handler queueing. */
19 	void (*handler)(struct airq_struct *airq, struct tpi_info *tpi_info);
20 	u8 *lsi_ptr;			/* Local-Summary-Indicator pointer */
21 	u8 lsi_mask;			/* Local-Summary-Indicator mask */
22 	u8 isc;				/* Interrupt-subclass */
23 	u8 flags;
24 };
25 
26 #define AIRQ_PTR_ALLOCATED	0x01
27 
28 int register_adapter_interrupt(struct airq_struct *airq);
29 void unregister_adapter_interrupt(struct airq_struct *airq);
30 
31 /* Adapter interrupt bit vector */
32 struct airq_iv {
33 	unsigned long *vector;	/* Adapter interrupt bit vector */
34 	dma_addr_t vector_dma; /* Adapter interrupt bit vector dma */
35 	unsigned long *avail;	/* Allocation bit mask for the bit vector */
36 	unsigned long *bitlock;	/* Lock bit mask for the bit vector */
37 	unsigned long *ptr;	/* Pointer associated with each bit */
38 	unsigned int *data;	/* 32 bit value associated with each bit */
39 	unsigned long bits;	/* Number of bits in the vector */
40 	unsigned long end;	/* Number of highest allocated bit + 1 */
41 	unsigned long flags;	/* Allocation flags */
42 	spinlock_t lock;	/* Lock to protect alloc & free */
43 };
44 
45 #define AIRQ_IV_ALLOC		1	/* Use an allocation bit mask */
46 #define AIRQ_IV_BITLOCK		2	/* Allocate the lock bit mask */
47 #define AIRQ_IV_PTR		4	/* Allocate the ptr array */
48 #define AIRQ_IV_DATA		8	/* Allocate the data array */
49 #define AIRQ_IV_CACHELINE	16	/* Cacheline alignment for the vector */
50 #define AIRQ_IV_GUESTVEC	32	/* Vector is a pinned guest page */
51 
52 struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags,
53 			       unsigned long *vec);
54 void airq_iv_release(struct airq_iv *iv);
55 unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num);
56 void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num);
57 unsigned long airq_iv_scan(struct airq_iv *iv, unsigned long start,
58 			   unsigned long end);
59 
60 static inline unsigned long airq_iv_alloc_bit(struct airq_iv *iv)
61 {
62 	return airq_iv_alloc(iv, 1);
63 }
64 
65 static inline void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit)
66 {
67 	airq_iv_free(iv, bit, 1);
68 }
69 
70 static inline unsigned long airq_iv_end(struct airq_iv *iv)
71 {
72 	return iv->end;
73 }
74 
75 static inline void airq_iv_lock(struct airq_iv *iv, unsigned long bit)
76 {
77 	const unsigned long be_to_le = BITS_PER_LONG - 1;
78 	bit_spin_lock(bit ^ be_to_le, iv->bitlock);
79 }
80 
81 static inline void airq_iv_unlock(struct airq_iv *iv, unsigned long bit)
82 {
83 	const unsigned long be_to_le = BITS_PER_LONG - 1;
84 	bit_spin_unlock(bit ^ be_to_le, iv->bitlock);
85 }
86 
87 static inline void airq_iv_set_data(struct airq_iv *iv, unsigned long bit,
88 				    unsigned int data)
89 {
90 	iv->data[bit] = data;
91 }
92 
93 static inline unsigned int airq_iv_get_data(struct airq_iv *iv,
94 					    unsigned long bit)
95 {
96 	return iv->data[bit];
97 }
98 
99 static inline void airq_iv_set_ptr(struct airq_iv *iv, unsigned long bit,
100 				   unsigned long ptr)
101 {
102 	iv->ptr[bit] = ptr;
103 }
104 
105 static inline unsigned long airq_iv_get_ptr(struct airq_iv *iv,
106 					    unsigned long bit)
107 {
108 	return iv->ptr[bit];
109 }
110 
111 #endif /* _ASM_S390_AIRQ_H */
112