blob: cd350345b3d25885c6cce02d8f357f387bdfbcc1 [file] [log] [blame]
Martin Schwidefsky0db78552016-09-21 12:48:54 +02001/*
2 * Copyright IBM Corp. 2016
3 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
4 *
5 * Adjunct processor bus inline assemblies.
6 */
7
8#ifndef _AP_ASM_H_
9#define _AP_ASM_H_
10
11#include <asm/isc.h>
12
13/**
14 * ap_intructions_available() - Test if AP instructions are available.
15 *
16 * Returns 0 if the AP instructions are installed.
17 */
18static inline int ap_instructions_available(void)
19{
20 register unsigned long reg0 asm ("0") = AP_MKQID(0, 0);
21 register unsigned long reg1 asm ("1") = -ENODEV;
22 register unsigned long reg2 asm ("2") = 0UL;
23
24 asm volatile(
25 " .long 0xb2af0000\n" /* PQAP(TAPQ) */
26 "0: la %1,0\n"
27 "1:\n"
28 EX_TABLE(0b, 1b)
29 : "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc");
30 return reg1;
31}
32
33/**
34 * ap_tapq(): Test adjunct processor queue.
35 * @qid: The AP queue number
36 * @info: Pointer to queue descriptor
37 *
38 * Returns AP queue status structure.
39 */
40static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info)
41{
42 register unsigned long reg0 asm ("0") = qid;
43 register struct ap_queue_status reg1 asm ("1");
44 register unsigned long reg2 asm ("2") = 0UL;
45
46 asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
47 : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
48 if (info)
49 *info = reg2;
50 return reg1;
51}
52
53/**
54 * ap_pqap_rapq(): Reset adjunct processor queue.
55 * @qid: The AP queue number
56 *
57 * Returns AP queue status structure.
58 */
59static inline struct ap_queue_status ap_rapq(ap_qid_t qid)
60{
61 register unsigned long reg0 asm ("0") = qid | 0x01000000UL;
62 register struct ap_queue_status reg1 asm ("1");
63 register unsigned long reg2 asm ("2") = 0UL;
64
65 asm volatile(
66 ".long 0xb2af0000" /* PQAP(RAPQ) */
67 : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
68 return reg1;
69}
70
71/**
Harald Freudenberger46fde9a2016-11-09 15:00:23 +010072 * ap_aqic(): Control interruption for a specific AP.
Martin Schwidefsky0db78552016-09-21 12:48:54 +020073 * @qid: The AP queue number
Harald Freudenberger46fde9a2016-11-09 15:00:23 +010074 * @qirqctrl: struct ap_qirq_ctrl (64 bit value)
Martin Schwidefsky0db78552016-09-21 12:48:54 +020075 * @ind: The notification indicator byte
76 *
77 * Returns AP queue status.
78 */
Harald Freudenberger46fde9a2016-11-09 15:00:23 +010079static inline struct ap_queue_status ap_aqic(ap_qid_t qid,
80 struct ap_qirq_ctrl qirqctrl,
81 void *ind)
Martin Schwidefsky0db78552016-09-21 12:48:54 +020082{
83 register unsigned long reg0 asm ("0") = qid | (3UL << 24);
Harald Freudenberger46fde9a2016-11-09 15:00:23 +010084 register struct ap_qirq_ctrl reg1_in asm ("1") = qirqctrl;
Martin Schwidefsky0db78552016-09-21 12:48:54 +020085 register struct ap_queue_status reg1_out asm ("1");
86 register void *reg2 asm ("2") = ind;
87
88 asm volatile(
89 ".long 0xb2af0000" /* PQAP(AQIC) */
90 : "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2)
91 :
92 : "cc");
93 return reg1_out;
94}
95
96/**
97 * ap_qci(): Get AP configuration data
98 *
99 * Returns 0 on success, or -EOPNOTSUPP.
100 */
101static inline int ap_qci(void *config)
102{
103 register unsigned long reg0 asm ("0") = 0x04000000UL;
104 register unsigned long reg1 asm ("1") = -EINVAL;
105 register void *reg2 asm ("2") = (void *) config;
106
107 asm volatile(
108 ".long 0xb2af0000\n" /* PQAP(QCI) */
109 "0: la %1,0\n"
110 "1:\n"
111 EX_TABLE(0b, 1b)
112 : "+d" (reg0), "+d" (reg1), "+d" (reg2)
113 :
Heiko Carstensd0350262016-12-13 13:24:03 +0100114 : "cc", "memory");
Martin Schwidefsky0db78552016-09-21 12:48:54 +0200115
116 return reg1;
117}
118
119/**
120 * ap_nqap(): Send message to adjunct processor queue.
121 * @qid: The AP queue number
122 * @psmid: The program supplied message identifier
123 * @msg: The message text
124 * @length: The message length
125 *
126 * Returns AP queue status structure.
127 * Condition code 1 on NQAP can't happen because the L bit is 1.
128 * Condition code 2 on NQAP also means the send is incomplete,
129 * because a segment boundary was reached. The NQAP is repeated.
130 */
131static inline struct ap_queue_status ap_nqap(ap_qid_t qid,
132 unsigned long long psmid,
133 void *msg, size_t length)
134{
Martin Schwidefsky0db78552016-09-21 12:48:54 +0200135 register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
136 register struct ap_queue_status reg1 asm ("1");
137 register unsigned long reg2 asm ("2") = (unsigned long) msg;
138 register unsigned long reg3 asm ("3") = (unsigned long) length;
139 register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
140 register unsigned long reg5 asm ("5") = psmid & 0xffffffff;
141
142 asm volatile (
143 "0: .long 0xb2ad0042\n" /* NQAP */
144 " brc 2,0b"
145 : "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
Heiko Carstens57c52ae2016-12-15 12:15:17 +0100146 : "d" (reg4), "d" (reg5)
147 : "cc", "memory");
Martin Schwidefsky0db78552016-09-21 12:48:54 +0200148 return reg1;
149}
150
151/**
152 * ap_dqap(): Receive message from adjunct processor queue.
153 * @qid: The AP queue number
154 * @psmid: Pointer to program supplied message identifier
155 * @msg: The message text
156 * @length: The message length
157 *
158 * Returns AP queue status structure.
159 * Condition code 1 on DQAP means the receive has taken place
160 * but only partially. The response is incomplete, hence the
161 * DQAP is repeated.
162 * Condition code 2 on DQAP also means the receive is incomplete,
163 * this time because a segment boundary was reached. Again, the
164 * DQAP is repeated.
165 * Note that gpr2 is used by the DQAP instruction to keep track of
166 * any 'residual' length, in case the instruction gets interrupted.
167 * Hence it gets zeroed before the instruction.
168 */
169static inline struct ap_queue_status ap_dqap(ap_qid_t qid,
170 unsigned long long *psmid,
171 void *msg, size_t length)
172{
Martin Schwidefsky0db78552016-09-21 12:48:54 +0200173 register unsigned long reg0 asm("0") = qid | 0x80000000UL;
174 register struct ap_queue_status reg1 asm ("1");
175 register unsigned long reg2 asm("2") = 0UL;
176 register unsigned long reg4 asm("4") = (unsigned long) msg;
177 register unsigned long reg5 asm("5") = (unsigned long) length;
178 register unsigned long reg6 asm("6") = 0UL;
179 register unsigned long reg7 asm("7") = 0UL;
180
181
182 asm volatile(
183 "0: .long 0xb2ae0064\n" /* DQAP */
184 " brc 6,0b\n"
185 : "+d" (reg0), "=d" (reg1), "+d" (reg2),
Heiko Carstens57c52ae2016-12-15 12:15:17 +0100186 "+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7)
187 : : "cc", "memory");
Martin Schwidefsky0db78552016-09-21 12:48:54 +0200188 *psmid = (((unsigned long long) reg6) << 32) + reg7;
189 return reg1;
190}
191
192#endif /* _AP_ASM_H_ */