ap_asm.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright IBM Corp. 2016
  4. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  5. *
  6. * Adjunct processor bus inline assemblies.
  7. */
  8. #ifndef _AP_ASM_H_
  9. #define _AP_ASM_H_
  10. #include <asm/isc.h>
  11. /**
  12. * ap_intructions_available() - Test if AP instructions are available.
  13. *
  14. * Returns 0 if the AP instructions are installed.
  15. */
  16. static inline int ap_instructions_available(void)
  17. {
  18. register unsigned long reg0 asm ("0") = AP_MKQID(0, 0);
  19. register unsigned long reg1 asm ("1") = -ENODEV;
  20. register unsigned long reg2 asm ("2") = 0UL;
  21. asm volatile(
  22. " .long 0xb2af0000\n" /* PQAP(TAPQ) */
  23. "0: la %1,0\n"
  24. "1:\n"
  25. EX_TABLE(0b, 1b)
  26. : "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc");
  27. return reg1;
  28. }
  29. /**
  30. * ap_tapq(): Test adjunct processor queue.
  31. * @qid: The AP queue number
  32. * @info: Pointer to queue descriptor
  33. *
  34. * Returns AP queue status structure.
  35. */
  36. static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info)
  37. {
  38. register unsigned long reg0 asm ("0") = qid;
  39. register struct ap_queue_status reg1 asm ("1");
  40. register unsigned long reg2 asm ("2") = 0UL;
  41. asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
  42. : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
  43. if (info)
  44. *info = reg2;
  45. return reg1;
  46. }
  47. /**
  48. * ap_pqap_rapq(): Reset adjunct processor queue.
  49. * @qid: The AP queue number
  50. *
  51. * Returns AP queue status structure.
  52. */
  53. static inline struct ap_queue_status ap_rapq(ap_qid_t qid)
  54. {
  55. register unsigned long reg0 asm ("0") = qid | 0x01000000UL;
  56. register struct ap_queue_status reg1 asm ("1");
  57. register unsigned long reg2 asm ("2") = 0UL;
  58. asm volatile(
  59. ".long 0xb2af0000" /* PQAP(RAPQ) */
  60. : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
  61. return reg1;
  62. }
  63. /**
  64. * ap_aqic(): Control interruption for a specific AP.
  65. * @qid: The AP queue number
  66. * @qirqctrl: struct ap_qirq_ctrl (64 bit value)
  67. * @ind: The notification indicator byte
  68. *
  69. * Returns AP queue status.
  70. */
  71. static inline struct ap_queue_status ap_aqic(ap_qid_t qid,
  72. struct ap_qirq_ctrl qirqctrl,
  73. void *ind)
  74. {
  75. register unsigned long reg0 asm ("0") = qid | (3UL << 24);
  76. register struct ap_qirq_ctrl reg1_in asm ("1") = qirqctrl;
  77. register struct ap_queue_status reg1_out asm ("1");
  78. register void *reg2 asm ("2") = ind;
  79. asm volatile(
  80. ".long 0xb2af0000" /* PQAP(AQIC) */
  81. : "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2)
  82. :
  83. : "cc");
  84. return reg1_out;
  85. }
  86. /**
  87. * ap_qci(): Get AP configuration data
  88. *
  89. * Returns 0 on success, or -EOPNOTSUPP.
  90. */
  91. static inline int ap_qci(void *config)
  92. {
  93. register unsigned long reg0 asm ("0") = 0x04000000UL;
  94. register unsigned long reg1 asm ("1") = -EINVAL;
  95. register void *reg2 asm ("2") = (void *) config;
  96. asm volatile(
  97. ".long 0xb2af0000\n" /* PQAP(QCI) */
  98. "0: la %1,0\n"
  99. "1:\n"
  100. EX_TABLE(0b, 1b)
  101. : "+d" (reg0), "+d" (reg1), "+d" (reg2)
  102. :
  103. : "cc", "memory");
  104. return reg1;
  105. }
  106. /*
  107. * union ap_qact_ap_info - used together with the
  108. * ap_aqic() function to provide a convenient way
  109. * to handle the ap info needed by the qact function.
  110. */
  111. union ap_qact_ap_info {
  112. unsigned long val;
  113. struct {
  114. unsigned int : 3;
  115. unsigned int mode : 3;
  116. unsigned int : 26;
  117. unsigned int cat : 8;
  118. unsigned int : 8;
  119. unsigned char ver[2];
  120. };
  121. };
  122. /**
  123. * ap_qact(): Query AP combatibility type.
  124. * @qid: The AP queue number
  125. * @apinfo: On input the info about the AP queue. On output the
  126. * alternate AP queue info provided by the qact function
  127. * in GR2 is stored in.
  128. *
  129. * Returns AP queue status. Check response_code field for failures.
  130. */
  131. static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit,
  132. union ap_qact_ap_info *apinfo)
  133. {
  134. register unsigned long reg0 asm ("0") = qid | (5UL << 24)
  135. | ((ifbit & 0x01) << 22);
  136. register unsigned long reg1_in asm ("1") = apinfo->val;
  137. register struct ap_queue_status reg1_out asm ("1");
  138. register unsigned long reg2 asm ("2") = 0;
  139. asm volatile(
  140. ".long 0xb2af0000" /* PQAP(QACT) */
  141. : "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2)
  142. : : "cc");
  143. apinfo->val = reg2;
  144. return reg1_out;
  145. }
  146. /**
  147. * ap_nqap(): Send message to adjunct processor queue.
  148. * @qid: The AP queue number
  149. * @psmid: The program supplied message identifier
  150. * @msg: The message text
  151. * @length: The message length
  152. *
  153. * Returns AP queue status structure.
  154. * Condition code 1 on NQAP can't happen because the L bit is 1.
  155. * Condition code 2 on NQAP also means the send is incomplete,
  156. * because a segment boundary was reached. The NQAP is repeated.
  157. */
  158. static inline struct ap_queue_status ap_nqap(ap_qid_t qid,
  159. unsigned long long psmid,
  160. void *msg, size_t length)
  161. {
  162. register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
  163. register struct ap_queue_status reg1 asm ("1");
  164. register unsigned long reg2 asm ("2") = (unsigned long) msg;
  165. register unsigned long reg3 asm ("3") = (unsigned long) length;
  166. register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
  167. register unsigned long reg5 asm ("5") = psmid & 0xffffffff;
  168. asm volatile (
  169. "0: .long 0xb2ad0042\n" /* NQAP */
  170. " brc 2,0b"
  171. : "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
  172. : "d" (reg4), "d" (reg5)
  173. : "cc", "memory");
  174. return reg1;
  175. }
  176. /**
  177. * ap_dqap(): Receive message from adjunct processor queue.
  178. * @qid: The AP queue number
  179. * @psmid: Pointer to program supplied message identifier
  180. * @msg: The message text
  181. * @length: The message length
  182. *
  183. * Returns AP queue status structure.
  184. * Condition code 1 on DQAP means the receive has taken place
  185. * but only partially. The response is incomplete, hence the
  186. * DQAP is repeated.
  187. * Condition code 2 on DQAP also means the receive is incomplete,
  188. * this time because a segment boundary was reached. Again, the
  189. * DQAP is repeated.
  190. * Note that gpr2 is used by the DQAP instruction to keep track of
  191. * any 'residual' length, in case the instruction gets interrupted.
  192. * Hence it gets zeroed before the instruction.
  193. */
  194. static inline struct ap_queue_status ap_dqap(ap_qid_t qid,
  195. unsigned long long *psmid,
  196. void *msg, size_t length)
  197. {
  198. register unsigned long reg0 asm("0") = qid | 0x80000000UL;
  199. register struct ap_queue_status reg1 asm ("1");
  200. register unsigned long reg2 asm("2") = 0UL;
  201. register unsigned long reg4 asm("4") = (unsigned long) msg;
  202. register unsigned long reg5 asm("5") = (unsigned long) length;
  203. register unsigned long reg6 asm("6") = 0UL;
  204. register unsigned long reg7 asm("7") = 0UL;
  205. asm volatile(
  206. "0: .long 0xb2ae0064\n" /* DQAP */
  207. " brc 6,0b\n"
  208. : "+d" (reg0), "=d" (reg1), "+d" (reg2),
  209. "+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7)
  210. : : "cc", "memory");
  211. *psmid = (((unsigned long long) reg6) << 32) + reg7;
  212. return reg1;
  213. }
  214. #endif /* _AP_ASM_H_ */