1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Adjunct processor (AP) interfaces
5 * Copyright IBM Corp. 2017
7 * Author(s): Tony Krowiak <akrowia@linux.vnet.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
9 * Harald Freudenberger <freude@de.ibm.com>
12 #ifndef _ASM_S390_AP_H_
13 #define _ASM_S390_AP_H_
16 * The ap_qid_t identifier of an ap queue.
17 * If the AP facilities test (APFT) facility is available,
18 * card and queue index are 8 bit values, otherwise
19 * card index is 6 bit and queue index a 4 bit value.
21 typedef unsigned int ap_qid_t
;
23 #define AP_MKQID(_card, _queue) (((_card) & 0xff) << 8 | ((_queue) & 0xff))
24 #define AP_QID_CARD(_qid) (((_qid) >> 8) & 0xff)
25 #define AP_QID_QUEUE(_qid) ((_qid) & 0xff)
28 * struct ap_queue_status - Holds the AP queue status.
29 * @queue_empty: Shows if queue is empty
30 * @replies_waiting: Waiting replies
31 * @queue_full: Is 1 if the queue is full
32 * @irq_enabled: Shows if interrupts are enabled for the AP
33 * @response_code: Holds the 8 bit response code
35 * The ap queue status word is returned by all three AP functions
36 * (PQAP, NQAP and DQAP). There's a set of flags in the first
37 * byte, followed by a 1 byte response code.
39 struct ap_queue_status
{
40 unsigned int queue_empty
: 1;
41 unsigned int replies_waiting
: 1;
42 unsigned int queue_full
: 1;
43 unsigned int _pad1
: 4;
44 unsigned int irq_enabled
: 1;
45 unsigned int response_code
: 8;
46 unsigned int _pad2
: 16;
50 * ap_intructions_available() - Test if AP instructions are available.
52 * Returns true if the AP instructions are installed, otherwise false.
54 static inline bool ap_instructions_available(void)
56 register unsigned long reg0
asm ("0") = AP_MKQID(0, 0);
57 register unsigned long reg1
asm ("1") = 0;
58 register unsigned long reg2
asm ("2") = 0;
61 " .long 0xb2af0000\n" /* PQAP(TAPQ) */
65 : "+d" (reg1
), "+d" (reg2
)
72 * ap_tapq(): Test adjunct processor queue.
73 * @qid: The AP queue number
74 * @info: Pointer to queue descriptor
76 * Returns AP queue status structure.
78 static inline struct ap_queue_status
ap_tapq(ap_qid_t qid
, unsigned long *info
)
80 register unsigned long reg0
asm ("0") = qid
;
81 register struct ap_queue_status reg1
asm ("1");
82 register unsigned long reg2
asm ("2");
84 asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
85 : "=d" (reg1
), "=d" (reg2
)
94 * ap_test_queue(): Test adjunct processor queue.
95 * @qid: The AP queue number
96 * @tbit: Test facilities bit
97 * @info: Pointer to queue descriptor
99 * Returns AP queue status structure.
101 static inline struct ap_queue_status
ap_test_queue(ap_qid_t qid
,
106 qid
|= 1UL << 23; /* set T bit*/
107 return ap_tapq(qid
, info
);
111 * ap_pqap_rapq(): Reset adjunct processor queue.
112 * @qid: The AP queue number
114 * Returns AP queue status structure.
116 static inline struct ap_queue_status
ap_rapq(ap_qid_t qid
)
118 register unsigned long reg0
asm ("0") = qid
| (1UL << 24);
119 register struct ap_queue_status reg1
asm ("1");
122 ".long 0xb2af0000" /* PQAP(RAPQ) */
130 * ap_pqap_zapq(): Reset and zeroize adjunct processor queue.
131 * @qid: The AP queue number
133 * Returns AP queue status structure.
135 static inline struct ap_queue_status
ap_zapq(ap_qid_t qid
)
137 register unsigned long reg0
asm ("0") = qid
| (2UL << 24);
138 register struct ap_queue_status reg1
asm ("1");
141 ".long 0xb2af0000" /* PQAP(ZAPQ) */
149 * struct ap_config_info - convenience struct for AP crypto
150 * config info as returned by the ap_qci() function.
152 struct ap_config_info
{
153 unsigned int apsc
: 1; /* S bit */
154 unsigned int apxa
: 1; /* N bit */
155 unsigned int qact
: 1; /* C bit */
156 unsigned int rc8a
: 1; /* R bit */
157 unsigned char _reserved1
: 4;
158 unsigned char _reserved2
[3];
159 unsigned char Na
; /* max # of APs - 1 */
160 unsigned char Nd
; /* max # of Domains - 1 */
161 unsigned char _reserved3
[10];
162 unsigned int apm
[8]; /* AP ID mask */
163 unsigned int aqm
[8]; /* AP (usage) queue mask */
164 unsigned int adm
[8]; /* AP (control) domain mask */
165 unsigned char _reserved4
[16];
169 * ap_qci(): Get AP configuration data
171 * Returns 0 on success, or -EOPNOTSUPP.
173 static inline int ap_qci(struct ap_config_info
*config
)
175 register unsigned long reg0
asm ("0") = 4UL << 24;
176 register unsigned long reg1
asm ("1") = -EOPNOTSUPP
;
177 register struct ap_config_info
*reg2
asm ("2") = config
;
180 ".long 0xb2af0000\n" /* PQAP(QCI) */
185 : "d" (reg0
), "d" (reg2
)
192 * struct ap_qirq_ctrl - convenient struct for easy invocation
193 * of the ap_aqic() function. This struct is passed as GR1
194 * parameter to the PQAP(AQIC) instruction. For details please
195 * see the AR documentation.
197 struct ap_qirq_ctrl
{
198 unsigned int _res1
: 8;
199 unsigned int zone
: 8; /* zone info */
200 unsigned int ir
: 1; /* ir flag: enable (1) or disable (0) irq */
201 unsigned int _res2
: 4;
202 unsigned int gisc
: 3; /* guest isc field */
203 unsigned int _res3
: 6;
204 unsigned int gf
: 2; /* gisa format */
205 unsigned int _res4
: 1;
206 unsigned int gisa
: 27; /* gisa origin */
207 unsigned int _res5
: 1;
208 unsigned int isc
: 3; /* irq sub class */
212 * ap_aqic(): Control interruption for a specific AP.
213 * @qid: The AP queue number
214 * @qirqctrl: struct ap_qirq_ctrl (64 bit value)
215 * @ind: The notification indicator byte
217 * Returns AP queue status.
219 static inline struct ap_queue_status
ap_aqic(ap_qid_t qid
,
220 struct ap_qirq_ctrl qirqctrl
,
223 register unsigned long reg0
asm ("0") = qid
| (3UL << 24);
226 struct ap_qirq_ctrl qirqctrl
;
227 struct ap_queue_status status
;
229 register void *reg2
asm ("2") = ind
;
231 reg1
.qirqctrl
= qirqctrl
;
234 ".long 0xb2af0000" /* PQAP(AQIC) */
236 : "d" (reg0
), "d" (reg2
)
243 * union ap_qact_ap_info - used together with the
244 * ap_aqic() function to provide a convenient way
245 * to handle the ap info needed by the qact function.
247 union ap_qact_ap_info
{
251 unsigned int mode
: 3;
253 unsigned int cat
: 8;
255 unsigned char ver
[2];
260 * ap_qact(): Query AP combatibility type.
261 * @qid: The AP queue number
262 * @apinfo: On input the info about the AP queue. On output the
263 * alternate AP queue info provided by the qact function
264 * in GR2 is stored in.
266 * Returns AP queue status. Check response_code field for failures.
268 static inline struct ap_queue_status
ap_qact(ap_qid_t qid
, int ifbit
,
269 union ap_qact_ap_info
*apinfo
)
271 register unsigned long reg0
asm ("0") = qid
| (5UL << 24)
272 | ((ifbit
& 0x01) << 22);
275 struct ap_queue_status status
;
277 register unsigned long reg2
asm ("2");
279 reg1
.value
= apinfo
->val
;
282 ".long 0xb2af0000" /* PQAP(QACT) */
283 : "+d" (reg1
), "=d" (reg2
)
291 * ap_nqap(): Send message to adjunct processor queue.
292 * @qid: The AP queue number
293 * @psmid: The program supplied message identifier
294 * @msg: The message text
295 * @length: The message length
297 * Returns AP queue status structure.
298 * Condition code 1 on NQAP can't happen because the L bit is 1.
299 * Condition code 2 on NQAP also means the send is incomplete,
300 * because a segment boundary was reached. The NQAP is repeated.
302 static inline struct ap_queue_status
ap_nqap(ap_qid_t qid
,
303 unsigned long long psmid
,
304 void *msg
, size_t length
)
306 register unsigned long reg0
asm ("0") = qid
| 0x40000000UL
;
307 register struct ap_queue_status reg1
asm ("1");
308 register unsigned long reg2
asm ("2") = (unsigned long) msg
;
309 register unsigned long reg3
asm ("3") = (unsigned long) length
;
310 register unsigned long reg4
asm ("4") = (unsigned int) (psmid
>> 32);
311 register unsigned long reg5
asm ("5") = psmid
& 0xffffffff;
314 "0: .long 0xb2ad0042\n" /* NQAP */
316 : "+d" (reg0
), "=d" (reg1
), "+d" (reg2
), "+d" (reg3
)
317 : "d" (reg4
), "d" (reg5
)
323 * ap_dqap(): Receive message from adjunct processor queue.
324 * @qid: The AP queue number
325 * @psmid: Pointer to program supplied message identifier
326 * @msg: The message text
327 * @length: The message length
329 * Returns AP queue status structure.
330 * Condition code 1 on DQAP means the receive has taken place
331 * but only partially. The response is incomplete, hence the
333 * Condition code 2 on DQAP also means the receive is incomplete,
334 * this time because a segment boundary was reached. Again, the
336 * Note that gpr2 is used by the DQAP instruction to keep track of
337 * any 'residual' length, in case the instruction gets interrupted.
338 * Hence it gets zeroed before the instruction.
340 static inline struct ap_queue_status
ap_dqap(ap_qid_t qid
,
341 unsigned long long *psmid
,
342 void *msg
, size_t length
)
344 register unsigned long reg0
asm("0") = qid
| 0x80000000UL
;
345 register struct ap_queue_status reg1
asm ("1");
346 register unsigned long reg2
asm("2") = 0UL;
347 register unsigned long reg4
asm("4") = (unsigned long) msg
;
348 register unsigned long reg5
asm("5") = (unsigned long) length
;
349 register unsigned long reg6
asm("6") = 0UL;
350 register unsigned long reg7
asm("7") = 0UL;
354 "0: .long 0xb2ae0064\n" /* DQAP */
356 : "+d" (reg0
), "=d" (reg1
), "+d" (reg2
),
357 "+d" (reg4
), "+d" (reg5
), "+d" (reg6
), "+d" (reg7
)
359 *psmid
= (((unsigned long long) reg6
) << 32) + reg7
;
364 * Interface to tell the AP bus code that a configuration
365 * change has happened. The bus code should at least do
366 * an ap bus resource rescan.
368 #if IS_ENABLED(CONFIG_ZCRYPT)
369 void ap_bus_cfg_chg(void);
371 static inline void ap_bus_cfg_chg(void){};
374 #endif /* _ASM_S390_AP_H_ */