ap_asm.h 5.4 KB

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