ioasm.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Channel subsystem I/O instructions.
  4. */
  5. #include <linux/export.h>
  6. #include <asm/asm-extable.h>
  7. #include <asm/chpid.h>
  8. #include <asm/schid.h>
  9. #include <asm/crw.h>
  10. #include "ioasm.h"
  11. #include "orb.h"
  12. #include "cio.h"
  13. #include "cio_inject.h"
  14. static inline int __stsch(struct subchannel_id schid, struct schib *addr)
  15. {
  16. unsigned long r1 = *(unsigned int *)&schid;
  17. int ccode = -EIO;
  18. asm volatile(
  19. " lgr 1,%[r1]\n"
  20. " stsch %[addr]\n"
  21. "0: ipm %[cc]\n"
  22. " srl %[cc],28\n"
  23. "1:\n"
  24. EX_TABLE(0b, 1b)
  25. : [cc] "+&d" (ccode), [addr] "=Q" (*addr)
  26. : [r1] "d" (r1)
  27. : "cc", "1");
  28. return ccode;
  29. }
  30. int stsch(struct subchannel_id schid, struct schib *addr)
  31. {
  32. int ccode;
  33. ccode = __stsch(schid, addr);
  34. trace_s390_cio_stsch(schid, addr, ccode);
  35. return ccode;
  36. }
  37. EXPORT_SYMBOL(stsch);
  38. static inline int __msch(struct subchannel_id schid, struct schib *addr)
  39. {
  40. unsigned long r1 = *(unsigned int *)&schid;
  41. int ccode = -EIO;
  42. asm volatile(
  43. " lgr 1,%[r1]\n"
  44. " msch %[addr]\n"
  45. "0: ipm %[cc]\n"
  46. " srl %[cc],28\n"
  47. "1:\n"
  48. EX_TABLE(0b, 1b)
  49. : [cc] "+&d" (ccode)
  50. : [r1] "d" (r1), [addr] "Q" (*addr)
  51. : "cc", "1");
  52. return ccode;
  53. }
  54. int msch(struct subchannel_id schid, struct schib *addr)
  55. {
  56. int ccode;
  57. ccode = __msch(schid, addr);
  58. trace_s390_cio_msch(schid, addr, ccode);
  59. return ccode;
  60. }
  61. static inline int __tsch(struct subchannel_id schid, struct irb *addr)
  62. {
  63. unsigned long r1 = *(unsigned int *)&schid;
  64. int ccode;
  65. asm volatile(
  66. " lgr 1,%[r1]\n"
  67. " tsch %[addr]\n"
  68. " ipm %[cc]\n"
  69. " srl %[cc],28"
  70. : [cc] "=&d" (ccode), [addr] "=Q" (*addr)
  71. : [r1] "d" (r1)
  72. : "cc", "1");
  73. return ccode;
  74. }
  75. int tsch(struct subchannel_id schid, struct irb *addr)
  76. {
  77. int ccode;
  78. ccode = __tsch(schid, addr);
  79. trace_s390_cio_tsch(schid, addr, ccode);
  80. return ccode;
  81. }
  82. static inline int __ssch(struct subchannel_id schid, union orb *addr)
  83. {
  84. unsigned long r1 = *(unsigned int *)&schid;
  85. int ccode = -EIO;
  86. asm volatile(
  87. " lgr 1,%[r1]\n"
  88. " ssch %[addr]\n"
  89. "0: ipm %[cc]\n"
  90. " srl %[cc],28\n"
  91. "1:\n"
  92. EX_TABLE(0b, 1b)
  93. : [cc] "+&d" (ccode)
  94. : [r1] "d" (r1), [addr] "Q" (*addr)
  95. : "cc", "memory", "1");
  96. return ccode;
  97. }
  98. int ssch(struct subchannel_id schid, union orb *addr)
  99. {
  100. int ccode;
  101. ccode = __ssch(schid, addr);
  102. trace_s390_cio_ssch(schid, addr, ccode);
  103. return ccode;
  104. }
  105. EXPORT_SYMBOL(ssch);
  106. static inline int __csch(struct subchannel_id schid)
  107. {
  108. unsigned long r1 = *(unsigned int *)&schid;
  109. int ccode;
  110. asm volatile(
  111. " lgr 1,%[r1]\n"
  112. " csch\n"
  113. " ipm %[cc]\n"
  114. " srl %[cc],28\n"
  115. : [cc] "=&d" (ccode)
  116. : [r1] "d" (r1)
  117. : "cc", "1");
  118. return ccode;
  119. }
  120. int csch(struct subchannel_id schid)
  121. {
  122. int ccode;
  123. ccode = __csch(schid);
  124. trace_s390_cio_csch(schid, ccode);
  125. return ccode;
  126. }
  127. EXPORT_SYMBOL(csch);
  128. int tpi(struct tpi_info *addr)
  129. {
  130. int ccode;
  131. asm volatile(
  132. " tpi %[addr]\n"
  133. " ipm %[cc]\n"
  134. " srl %[cc],28"
  135. : [cc] "=&d" (ccode), [addr] "=Q" (*addr)
  136. :
  137. : "cc");
  138. trace_s390_cio_tpi(addr, ccode);
  139. return ccode;
  140. }
  141. int chsc(void *chsc_area)
  142. {
  143. typedef struct { char _[4096]; } addr_type;
  144. int cc = -EIO;
  145. asm volatile(
  146. " .insn rre,0xb25f0000,%[chsc_area],0\n"
  147. "0: ipm %[cc]\n"
  148. " srl %[cc],28\n"
  149. "1:\n"
  150. EX_TABLE(0b, 1b)
  151. : [cc] "+&d" (cc), "+m" (*(addr_type *)chsc_area)
  152. : [chsc_area] "d" (chsc_area)
  153. : "cc");
  154. trace_s390_cio_chsc(chsc_area, cc);
  155. return cc;
  156. }
  157. EXPORT_SYMBOL(chsc);
  158. static inline int __rsch(struct subchannel_id schid)
  159. {
  160. unsigned long r1 = *(unsigned int *)&schid;
  161. int ccode;
  162. asm volatile(
  163. " lgr 1,%[r1]\n"
  164. " rsch\n"
  165. " ipm %[cc]\n"
  166. " srl %[cc],28\n"
  167. : [cc] "=&d" (ccode)
  168. : [r1] "d" (r1)
  169. : "cc", "memory", "1");
  170. return ccode;
  171. }
  172. int rsch(struct subchannel_id schid)
  173. {
  174. int ccode;
  175. ccode = __rsch(schid);
  176. trace_s390_cio_rsch(schid, ccode);
  177. return ccode;
  178. }
  179. static inline int __hsch(struct subchannel_id schid)
  180. {
  181. unsigned long r1 = *(unsigned int *)&schid;
  182. int ccode;
  183. asm volatile(
  184. " lgr 1,%[r1]\n"
  185. " hsch\n"
  186. " ipm %[cc]\n"
  187. " srl %[cc],28\n"
  188. : [cc] "=&d" (ccode)
  189. : [r1] "d" (r1)
  190. : "cc", "1");
  191. return ccode;
  192. }
  193. int hsch(struct subchannel_id schid)
  194. {
  195. int ccode;
  196. ccode = __hsch(schid);
  197. trace_s390_cio_hsch(schid, ccode);
  198. return ccode;
  199. }
  200. EXPORT_SYMBOL(hsch);
  201. static inline int __xsch(struct subchannel_id schid)
  202. {
  203. unsigned long r1 = *(unsigned int *)&schid;
  204. int ccode;
  205. asm volatile(
  206. " lgr 1,%[r1]\n"
  207. " xsch\n"
  208. " ipm %[cc]\n"
  209. " srl %[cc],28\n"
  210. : [cc] "=&d" (ccode)
  211. : [r1] "d" (r1)
  212. : "cc", "1");
  213. return ccode;
  214. }
  215. int xsch(struct subchannel_id schid)
  216. {
  217. int ccode;
  218. ccode = __xsch(schid);
  219. trace_s390_cio_xsch(schid, ccode);
  220. return ccode;
  221. }
  222. static inline int __stcrw(struct crw *crw)
  223. {
  224. int ccode;
  225. asm volatile(
  226. " stcrw %[crw]\n"
  227. " ipm %[cc]\n"
  228. " srl %[cc],28\n"
  229. : [cc] "=&d" (ccode), [crw] "=Q" (*crw)
  230. :
  231. : "cc");
  232. return ccode;
  233. }
  234. static inline int _stcrw(struct crw *crw)
  235. {
  236. #ifdef CONFIG_CIO_INJECT
  237. if (static_branch_unlikely(&cio_inject_enabled)) {
  238. if (stcrw_get_injected(crw) == 0)
  239. return 0;
  240. }
  241. #endif
  242. return __stcrw(crw);
  243. }
  244. int stcrw(struct crw *crw)
  245. {
  246. int ccode;
  247. ccode = _stcrw(crw);
  248. trace_s390_cio_stcrw(crw, ccode);
  249. return ccode;
  250. }