ap.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Adjunct processor (AP) interfaces
  4. *
  5. * Copyright IBM Corp. 2017
  6. *
  7. * Author(s): Tony Krowiak <akrowia@linux.vnet.ibm.com>
  8. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  9. * Harald Freudenberger <freude@de.ibm.com>
  10. */
  11. #ifndef _ASM_S390_AP_H_
  12. #define _ASM_S390_AP_H_
  13. /**
  14. * The ap_qid_t identifier of an ap queue.
  15. * If the AP facilities test (APFT) facility is available,
  16. * card and queue index are 8 bit values, otherwise
  17. * card index is 6 bit and queue index a 4 bit value.
  18. */
  19. typedef unsigned int ap_qid_t;
  20. #define AP_MKQID(_card, _queue) (((_card) & 0xff) << 8 | ((_queue) & 0xff))
  21. #define AP_QID_CARD(_qid) (((_qid) >> 8) & 0xff)
  22. #define AP_QID_QUEUE(_qid) ((_qid) & 0xff)
  23. /**
  24. * struct ap_queue_status - Holds the AP queue status.
  25. * @queue_empty: Shows if queue is empty
  26. * @replies_waiting: Waiting replies
  27. * @queue_full: Is 1 if the queue is full
  28. * @irq_enabled: Shows if interrupts are enabled for the AP
  29. * @response_code: Holds the 8 bit response code
  30. *
  31. * The ap queue status word is returned by all three AP functions
  32. * (PQAP, NQAP and DQAP). There's a set of flags in the first
  33. * byte, followed by a 1 byte response code.
  34. */
  35. struct ap_queue_status {
  36. unsigned int queue_empty : 1;
  37. unsigned int replies_waiting : 1;
  38. unsigned int queue_full : 1;
  39. unsigned int _pad1 : 4;
  40. unsigned int irq_enabled : 1;
  41. unsigned int response_code : 8;
  42. unsigned int _pad2 : 16;
  43. };
  44. /**
  45. * ap_intructions_available() - Test if AP instructions are available.
  46. *
  47. * Returns true if the AP instructions are installed, otherwise false.
  48. */
  49. static inline bool ap_instructions_available(void)
  50. {
  51. register unsigned long reg0 asm ("0") = AP_MKQID(0, 0);
  52. register unsigned long reg1 asm ("1") = 0;
  53. register unsigned long reg2 asm ("2") = 0;
  54. asm volatile(
  55. " .long 0xb2af0000\n" /* PQAP(TAPQ) */
  56. "0: la %0,1\n"
  57. "1:\n"
  58. EX_TABLE(0b, 1b)
  59. : "+d" (reg1), "+d" (reg2)
  60. : "d" (reg0)
  61. : "cc");
  62. return reg1 != 0;
  63. }
  64. /**
  65. * ap_tapq(): Test adjunct processor queue.
  66. * @qid: The AP queue number
  67. * @info: Pointer to queue descriptor
  68. *
  69. * Returns AP queue status structure.
  70. */
  71. static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info)
  72. {
  73. register unsigned long reg0 asm ("0") = qid;
  74. register struct ap_queue_status reg1 asm ("1");
  75. register unsigned long reg2 asm ("2");
  76. asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
  77. : "=d" (reg1), "=d" (reg2)
  78. : "d" (reg0)
  79. : "cc");
  80. if (info)
  81. *info = reg2;
  82. return reg1;
  83. }
  84. /**
  85. * ap_test_queue(): Test adjunct processor queue.
  86. * @qid: The AP queue number
  87. * @tbit: Test facilities bit
  88. * @info: Pointer to queue descriptor
  89. *
  90. * Returns AP queue status structure.
  91. */
  92. static inline struct ap_queue_status ap_test_queue(ap_qid_t qid,
  93. int tbit,
  94. unsigned long *info)
  95. {
  96. if (tbit)
  97. qid |= 1UL << 23; /* set T bit*/
  98. return ap_tapq(qid, info);
  99. }
  100. /**
  101. * ap_pqap_rapq(): Reset adjunct processor queue.
  102. * @qid: The AP queue number
  103. *
  104. * Returns AP queue status structure.
  105. */
  106. static inline struct ap_queue_status ap_rapq(ap_qid_t qid)
  107. {
  108. register unsigned long reg0 asm ("0") = qid | (1UL << 24);
  109. register struct ap_queue_status reg1 asm ("1");
  110. asm volatile(
  111. ".long 0xb2af0000" /* PQAP(RAPQ) */
  112. : "=d" (reg1)
  113. : "d" (reg0)
  114. : "cc");
  115. return reg1;
  116. }
  117. /**
  118. * ap_pqap_zapq(): Reset and zeroize adjunct processor queue.
  119. * @qid: The AP queue number
  120. *
  121. * Returns AP queue status structure.
  122. */
  123. static inline struct ap_queue_status ap_zapq(ap_qid_t qid)
  124. {
  125. register unsigned long reg0 asm ("0") = qid | (2UL << 24);
  126. register struct ap_queue_status reg1 asm ("1");
  127. asm volatile(
  128. ".long 0xb2af0000" /* PQAP(ZAPQ) */
  129. : "=d" (reg1)
  130. : "d" (reg0)
  131. : "cc");
  132. return reg1;
  133. }
  134. /**
  135. * struct ap_config_info - convenience struct for AP crypto
  136. * config info as returned by the ap_qci() function.
  137. */
  138. struct ap_config_info {
  139. unsigned int apsc : 1; /* S bit */
  140. unsigned int apxa : 1; /* N bit */
  141. unsigned int qact : 1; /* C bit */
  142. unsigned int rc8a : 1; /* R bit */
  143. unsigned char _reserved1 : 4;
  144. unsigned char _reserved2[3];
  145. unsigned char Na; /* max # of APs - 1 */
  146. unsigned char Nd; /* max # of Domains - 1 */
  147. unsigned char _reserved3[10];
  148. unsigned int apm[8]; /* AP ID mask */
  149. unsigned int aqm[8]; /* AP queue mask */
  150. unsigned int adm[8]; /* AP domain mask */
  151. unsigned char _reserved4[16];
  152. } __aligned(8);
  153. /**
  154. * ap_qci(): Get AP configuration data
  155. *
  156. * Returns 0 on success, or -EOPNOTSUPP.
  157. */
  158. static inline int ap_qci(struct ap_config_info *config)
  159. {
  160. register unsigned long reg0 asm ("0") = 4UL << 24;
  161. register unsigned long reg1 asm ("1") = -EOPNOTSUPP;
  162. register struct ap_config_info *reg2 asm ("2") = config;
  163. asm volatile(
  164. ".long 0xb2af0000\n" /* PQAP(QCI) */
  165. "0: la %0,0\n"
  166. "1:\n"
  167. EX_TABLE(0b, 1b)
  168. : "+d" (reg1)
  169. : "d" (reg0), "d" (reg2)
  170. : "cc", "memory");
  171. return reg1;
  172. }
  173. /*
  174. * struct ap_qirq_ctrl - convenient struct for easy invocation
  175. * of the ap_aqic() function. This struct is passed as GR1
  176. * parameter to the PQAP(AQIC) instruction. For details please
  177. * see the AR documentation.
  178. */
  179. struct ap_qirq_ctrl {
  180. unsigned int _res1 : 8;
  181. unsigned int zone : 8; /* zone info */
  182. unsigned int ir : 1; /* ir flag: enable (1) or disable (0) irq */
  183. unsigned int _res2 : 4;
  184. unsigned int gisc : 3; /* guest isc field */
  185. unsigned int _res3 : 6;
  186. unsigned int gf : 2; /* gisa format */
  187. unsigned int _res4 : 1;
  188. unsigned int gisa : 27; /* gisa origin */
  189. unsigned int _res5 : 1;
  190. unsigned int isc : 3; /* irq sub class */
  191. };
  192. /**
  193. * ap_aqic(): Control interruption for a specific AP.
  194. * @qid: The AP queue number
  195. * @qirqctrl: struct ap_qirq_ctrl (64 bit value)
  196. * @ind: The notification indicator byte
  197. *
  198. * Returns AP queue status.
  199. */
  200. static inline struct ap_queue_status ap_aqic(ap_qid_t qid,
  201. struct ap_qirq_ctrl qirqctrl,
  202. void *ind)
  203. {
  204. register unsigned long reg0 asm ("0") = qid | (3UL << 24);
  205. register union {
  206. unsigned long value;
  207. struct ap_qirq_ctrl qirqctrl;
  208. struct ap_queue_status status;
  209. } reg1 asm ("1");
  210. register void *reg2 asm ("2") = ind;
  211. reg1.qirqctrl = qirqctrl;
  212. asm volatile(
  213. ".long 0xb2af0000" /* PQAP(AQIC) */
  214. : "+d" (reg1)
  215. : "d" (reg0), "d" (reg2)
  216. : "cc");
  217. return reg1.status;
  218. }
  219. /*
  220. * union ap_qact_ap_info - used together with the
  221. * ap_aqic() function to provide a convenient way
  222. * to handle the ap info needed by the qact function.
  223. */
  224. union ap_qact_ap_info {
  225. unsigned long val;
  226. struct {
  227. unsigned int : 3;
  228. unsigned int mode : 3;
  229. unsigned int : 26;
  230. unsigned int cat : 8;
  231. unsigned int : 8;
  232. unsigned char ver[2];
  233. };
  234. };
  235. /**
  236. * ap_qact(): Query AP combatibility type.
  237. * @qid: The AP queue number
  238. * @apinfo: On input the info about the AP queue. On output the
  239. * alternate AP queue info provided by the qact function
  240. * in GR2 is stored in.
  241. *
  242. * Returns AP queue status. Check response_code field for failures.
  243. */
  244. static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit,
  245. union ap_qact_ap_info *apinfo)
  246. {
  247. register unsigned long reg0 asm ("0") = qid | (5UL << 24)
  248. | ((ifbit & 0x01) << 22);
  249. register union {
  250. unsigned long value;
  251. struct ap_queue_status status;
  252. } reg1 asm ("1");
  253. register unsigned long reg2 asm ("2");
  254. reg1.value = apinfo->val;
  255. asm volatile(
  256. ".long 0xb2af0000" /* PQAP(QACT) */
  257. : "+d" (reg1), "=d" (reg2)
  258. : "d" (reg0)
  259. : "cc");
  260. apinfo->val = reg2;
  261. return reg1.status;
  262. }
  263. /**
  264. * ap_nqap(): Send message to adjunct processor queue.
  265. * @qid: The AP queue number
  266. * @psmid: The program supplied message identifier
  267. * @msg: The message text
  268. * @length: The message length
  269. *
  270. * Returns AP queue status structure.
  271. * Condition code 1 on NQAP can't happen because the L bit is 1.
  272. * Condition code 2 on NQAP also means the send is incomplete,
  273. * because a segment boundary was reached. The NQAP is repeated.
  274. */
  275. static inline struct ap_queue_status ap_nqap(ap_qid_t qid,
  276. unsigned long long psmid,
  277. void *msg, size_t length)
  278. {
  279. register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
  280. register struct ap_queue_status reg1 asm ("1");
  281. register unsigned long reg2 asm ("2") = (unsigned long) msg;
  282. register unsigned long reg3 asm ("3") = (unsigned long) length;
  283. register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
  284. register unsigned long reg5 asm ("5") = psmid & 0xffffffff;
  285. asm volatile (
  286. "0: .long 0xb2ad0042\n" /* NQAP */
  287. " brc 2,0b"
  288. : "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
  289. : "d" (reg4), "d" (reg5)
  290. : "cc", "memory");
  291. return reg1;
  292. }
  293. /**
  294. * ap_dqap(): Receive message from adjunct processor queue.
  295. * @qid: The AP queue number
  296. * @psmid: Pointer to program supplied message identifier
  297. * @msg: The message text
  298. * @length: The message length
  299. *
  300. * Returns AP queue status structure.
  301. * Condition code 1 on DQAP means the receive has taken place
  302. * but only partially. The response is incomplete, hence the
  303. * DQAP is repeated.
  304. * Condition code 2 on DQAP also means the receive is incomplete,
  305. * this time because a segment boundary was reached. Again, the
  306. * DQAP is repeated.
  307. * Note that gpr2 is used by the DQAP instruction to keep track of
  308. * any 'residual' length, in case the instruction gets interrupted.
  309. * Hence it gets zeroed before the instruction.
  310. */
  311. static inline struct ap_queue_status ap_dqap(ap_qid_t qid,
  312. unsigned long long *psmid,
  313. void *msg, size_t length)
  314. {
  315. register unsigned long reg0 asm("0") = qid | 0x80000000UL;
  316. register struct ap_queue_status reg1 asm ("1");
  317. register unsigned long reg2 asm("2") = 0UL;
  318. register unsigned long reg4 asm("4") = (unsigned long) msg;
  319. register unsigned long reg5 asm("5") = (unsigned long) length;
  320. register unsigned long reg6 asm("6") = 0UL;
  321. register unsigned long reg7 asm("7") = 0UL;
  322. asm volatile(
  323. "0: .long 0xb2ae0064\n" /* DQAP */
  324. " brc 6,0b\n"
  325. : "+d" (reg0), "=d" (reg1), "+d" (reg2),
  326. "+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7)
  327. : : "cc", "memory");
  328. *psmid = (((unsigned long long) reg6) << 32) + reg7;
  329. return reg1;
  330. }
  331. #endif /* _ASM_S390_AP_H_ */